Skip to content

Commit

Permalink
Keep same order of files for amalgamation
Browse files Browse the repository at this point in the history
According to the documentation glob returns files in arbitrary order.
Let's sort paths to keep the same order of files for amalgamation.

Signed-off-by: Denis Efremov <denis.e.efremov@oracle.com>
  • Loading branch information
evdenis authored and athre0z committed Feb 4, 2024
1 parent 15e38ac commit 58f8c65
Showing 1 changed file with 8 additions and 13 deletions.
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

0 comments on commit 58f8c65

Please sign in to comment.