Skip to content
Snippets Groups Projects

fix(core): header includes are not properly sorted

Merged Flavien BRIDAULT requested to merge 39-core-header-includes-are-not-properly-sorted into dev
All threads resolved!
1 file
+ 18
25
Compare changes
  • Side-by-side
  • Inline
+ 18
25
@@ -12,33 +12,26 @@ g_modules = []
def find_current_library(path):
# Just assert first for 'src' or 'include'
match = re.search('(?:(?:include\/)|(?:src\/)).*', path)
if match is None:
repo_root = common.get_repo_root()
if os.path.commonpath([repo_root, path]) != repo_root:
raise RuntimeError('Wrong call, the requested file is not located inside the project repository.')
cur_path = path
found = False
while cur_path != repo_root:
if os.path.exists(os.path.join(cur_path, 'CMakeLists.txt')):
cur_path = os.path.join(cur_path, 'CMakeLists.txt')
found = True
break
cur_path = os.path.normpath(os.path.join(cur_path, '..'))
if not found:
raise Exception('lib path not found')
# Here we split so we have for instance
# /home/fbridault/dev/f4s-sandbox/src/f4s/SrcLib/core/fwDataCamp/include/fwMedDataCamp/DicomSeries.hpp
# split into
# ['/home/fbridault/dev/f4s-sandbox/src/f4s/SrcLib/core/fwDataCamp/', 'include/fwMedDataCamp/DicomSeries.hpp']
split_by_inc = path.split('include/')
# If something has been split, that means we have an include
if len(split_by_inc) > 1:
lib_path = split_by_inc
else:
lib_path = path.split('src/')
# Now we take the second last element (we start from the end because 'include' or 'src' may appear multiple times)
lib = lib_path[-2]
lib_name = lib.split('/')[-2]
if lib_name == "tu":
# If we have a unit test, for instance '/home/fbridault/dev/f4s-sandbox/src/f4s/SrcLib/io/fwCsvIO/test/tu/CsvReaderTest.hpp'
# We will get 'tu' instead of the library name and thus we have to skip '/test/tu'
lib_name = lib.split('/')[-4]
# We have kept '/home/fbridault/dev/f4s-sandbox/src/f4s/SrcLib/core/fwDataCamp/'
# We take the second last element split by '/', so in this case 'fwDataCamp'
# Now we take the second last element (last element is 'CMakeLists.txt')
lib_name = cur_path.split('/')[-2]
return lib_name
Loading