Skip to content

Commit

Permalink
Add deterministic prefix in Library.get_flags() (NFC) (emscripten-cor…
Browse files Browse the repository at this point in the history
…e#23225)

This factors duplicate routines to add deterministic prefix paths out to
`Library.get_cflags()`. Suggested in

emscripten-core#23222 (comment).
  • Loading branch information
aheejin authored Dec 20, 2024
1 parent 4cbcb26 commit 74d95fb
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,9 @@ def get_files(self):
def generate_ninja(self, build_dir, libname):
ensure_sysroot()
utils.safe_ensure_dirs(build_dir)
self.build_dir = build_dir

cflags = self.get_cflags()
if self.deterministic_paths:
source_dir = utils.path_from_root()
relative_source_dir = os.path.relpath(source_dir, build_dir)
cflags += [f'-ffile-prefix-map={source_dir}={DETERMINISITIC_PREFIX}',
f'-ffile-prefix-map={relative_source_dir}={DETERMINISITIC_PREFIX}',
f'-fdebug-compilation-dir={DETERMINISITIC_PREFIX}']
asflags = get_base_cflags(preprocess=False)
input_files = self.get_files()
ninja_file = os.path.join(build_dir, 'build.ninja')
Expand All @@ -492,17 +487,11 @@ def build_objects(self, build_dir):
with the `cflags` returned by `self.get_cflags()`.
"""
batch_inputs = int(os.environ.get('EMCC_BATCH_BUILD', '1'))
self.build_dir = build_dir
batches = {}
commands = []
objects = set()
cflags = self.get_cflags()
if self.deterministic_paths:
source_dir = utils.path_from_root()
if batch_inputs:
relative_source_dir = os.path.relpath(source_dir, build_dir)
cflags += [f'-ffile-prefix-map={relative_source_dir}={DETERMINISITIC_PREFIX}']
cflags += [f'-ffile-prefix-map={source_dir}={DETERMINISITIC_PREFIX}',
f'-fdebug-compilation-dir={DETERMINISITIC_PREFIX}']
case_insensitive = is_case_insensitive(build_dir)
for src in self.get_files():
ext = shared.suffix(src)
Expand Down Expand Up @@ -611,6 +600,12 @@ def get_cflags(self):
if self.includes:
cflags += ['-I' + utils.path_from_root(i) for i in self._inherit_list('includes')]

if self.deterministic_paths:
source_dir = utils.path_from_root()
relative_source_dir = os.path.relpath(source_dir, self.build_dir)
cflags += [f'-ffile-prefix-map={relative_source_dir}={DETERMINISITIC_PREFIX}']
cflags += [f'-ffile-prefix-map={source_dir}={DETERMINISITIC_PREFIX}',
f'-fdebug-compilation-dir={DETERMINISITIC_PREFIX}']
return cflags

def get_base_name_prefix(self):
Expand Down

0 comments on commit 74d95fb

Please sign in to comment.