Example #1
0
 def get_parts(file: str) -> Parts:
     # This is effectively creating a Directed Acyclic Graph of all files
     # and their #includes, which we later sort by dependency order.
     content = read_file(os.path.join('..', file))
     lines = content.splitlines()
     include_lines = filter(lambda t: t.startswith('#include "'), lines)
     include_files = list(
         map(lambda i: i.replace('#include ', '').replace('"', ''),
             include_lines))
     include_files = list(map(lambda f: get_file_name(f), include_files))
     return Parts(file, include_files)
Example #2
0
    def get_all_files(directory: str) -> List[str]:
        all_files = []
        abs = os.path.abspath(directory)
        relative = get_file_name(abs)

        for root, directories, files in os.walk(directory):
            for file in files:
                if file.endswith('.h'):
                    file_text = os.path.join(root, file)
                    file_text = file_text.replace('./', relative + '/')
                    all_files.append(file_text)
        all_files.sort()
        return all_files
Example #3
0
 def depends_on(file1: Parts, file2: Parts) -> bool:
     file2_name = get_file_name(file2.file)
     return file2_name in file1.include_files
Example #4
0
 def test_get_file_name(self) -> None:
     self.assertEqual('file.txt', get_file_name('directory/file.txt'))
     self.assertEqual('file.txt', get_file_name('file.txt'))