diff --git a/assets/amalgamate.py b/assets/amalgamate.py index b471d8e7..4ef633c4 100755 --- a/assets/amalgamate.py +++ b/assets/amalgamate.py @@ -2,7 +2,6 @@ from pathlib import Path from typing import List, Set -from glob import glob from shutil import rmtree import os @@ -19,20 +18,16 @@ FILE_HEADER = ['// DO NOT EDIT. This file is auto-generated by `amalgamate.py`.', ''] -# Python versions before 3.10 don't have the root_dir argument for glob, so we -# crudely emulate it here. -def glob_in_dir( - pattern: str, +def find_files( + pattern: re.Pattern, root_dir: Path, ): - cwd = os.getcwd() root_dir = root_dir.resolve() - os.chdir(root_dir) - try: - for path in glob(pattern, recursive=True): - yield Path(root_dir) / path - finally: - os.chdir(cwd) + paths = [] + for root, dirs, files in os.walk(root_dir): + paths.extend([Path(root) / name for name in files if pattern.match(name)]) + + return sorted(paths) def find_include_path( @@ -107,7 +102,7 @@ def merge_sources(*, source_dir: Path, covered_headers: Set[Path]): '', ] - for source_file in glob_in_dir('**/*.c', source_dir): + for source_file in find_files(re.compile('[\w-]+\.c'), source_dir): print(f'Processing source file "{source_file}"') # Print some comments to show where the code is from.