Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep same order of files for amalgamation #481

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions assets/amalgamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from pathlib import Path
from typing import List, Set
from glob import glob
from shutil import rmtree

import os
Expand All @@ -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(
Expand Down Expand Up @@ -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.
Expand Down
Loading