From: Teemu Murtola Date: Wed, 1 Jul 2015 03:36:49 +0000 (+0300) Subject: Minor include sorting changes X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=84fa371acd30024cfad09f704d92e87fd3f1ea5a;p=alexxy%2Fgromacs.git Minor include sorting changes Make the include sorter sort files based on the basename of the file, i.e., not including the extension into the string sort. This fixes an unintuitive behavior that causes changes in the include order if a '-' <-> '_' replacement is done for a file name (because '-' and '_' are on different sides of '.' in ASCII). Change-Id: Icd4bf58b0d60178e33f6840f24adb1e4108fb92a --- diff --git a/docs/doxygen/includesorter.py b/docs/doxygen/includesorter.py index 15de986446..71e59de680 100755 --- a/docs/doxygen/includesorter.py +++ b/docs/doxygen/includesorter.py @@ -174,6 +174,23 @@ class GroupedSorter(object): return IncludeGroup.gmx_test return IncludeGroup.gmx_general + def _split_path(self, path): + """Split include path into sortable compoments. + + Plain string on the full path in the #include directive causes some + unintuitive behavior, so this splits the path into a tuple at + points that allow more natural sorting: primary sort criterion is the + directory name, followed by the basename (without extension) of the + included file. + """ + path_components = list(os.path.split(path)) + path_components[1] = os.path.splitext(path_components[1]) + return tuple(path_components) + + def _join_path(self, path_components): + """Reconstruct path from the return value of _split_path.""" + return os.path.join(path_components[0], ''.join(path_components[1])) + def get_sortable_object(self, include): """Produce a sortable, opaque object for an include. @@ -210,7 +227,7 @@ class GroupedSorter(object): including_file = include.get_including_file() group = self._get_gmx_group(including_file, included_file) path = self._get_path(included_file, group, including_file) - return (group, os.path.split(path), include) + return (group, self._split_path(path), include) def format_include(self, obj, prev): """Format an #include directive after sorting.""" @@ -228,9 +245,9 @@ class GroupedSorter(object): match = re.match(include_re, line) assert match if include.is_system(): - path = '<{0}>'.format(os.path.join(obj[1][0], obj[1][1])) + path = '<{0}>'.format(self._join_path(obj[1])) else: - path = '"{0}"'.format(os.path.join(obj[1][0], obj[1][1])) + path = '"{0}"'.format(self._join_path(obj[1])) result.append('{0}{1}{2}\n'.format(match.group('head'), path, match.group('tail'))) return result diff --git a/src/gromacs/listed-forces/bonded.cpp b/src/gromacs/listed-forces/bonded.cpp index 59a86026f0..7804b0c5ec 100644 --- a/src/gromacs/listed-forces/bonded.cpp +++ b/src/gromacs/listed-forces/bonded.cpp @@ -59,8 +59,8 @@ #include "gromacs/math/vec.h" #include "gromacs/pbcutil/ishift.h" #include "gromacs/pbcutil/mshift.h" -#include "gromacs/pbcutil/pbc-simd.h" #include "gromacs/pbcutil/pbc.h" +#include "gromacs/pbcutil/pbc-simd.h" #include "gromacs/simd/simd.h" #include "gromacs/simd/simd_math.h" #include "gromacs/simd/vector_operations.h" diff --git a/src/gromacs/mdlib/clincs.cpp b/src/gromacs/mdlib/clincs.cpp index aa36491198..3e0f68c0b4 100644 --- a/src/gromacs/mdlib/clincs.cpp +++ b/src/gromacs/mdlib/clincs.cpp @@ -55,8 +55,8 @@ #include "gromacs/legacyheaders/types/commrec.h" #include "gromacs/math/units.h" #include "gromacs/math/vec.h" -#include "gromacs/pbcutil/pbc-simd.h" #include "gromacs/pbcutil/pbc.h" +#include "gromacs/pbcutil/pbc-simd.h" #include "gromacs/simd/simd.h" #include "gromacs/simd/simd_math.h" #include "gromacs/simd/vector_operations.h" diff --git a/src/programs/mdrun/md.cpp b/src/programs/mdrun/md.cpp index f137273195..92c8335fbd 100644 --- a/src/programs/mdrun/md.cpp +++ b/src/programs/mdrun/md.cpp @@ -46,8 +46,8 @@ #include "gromacs/domdec/domdec.h" #include "gromacs/domdec/domdec_network.h" -#include "gromacs/ewald/pme-load-balancing.h" #include "gromacs/ewald/pme.h" +#include "gromacs/ewald/pme-load-balancing.h" #include "gromacs/fileio/filenm.h" #include "gromacs/fileio/mdoutf.h" #include "gromacs/fileio/trajectory_writing.h" diff --git a/src/testutils/tests/refdata_tests.cpp b/src/testutils/tests/refdata_tests.cpp index 61c948359b..ec09562459 100644 --- a/src/testutils/tests/refdata_tests.cpp +++ b/src/testutils/tests/refdata_tests.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -45,8 +45,8 @@ #include -#include #include +#include namespace {