Skip to content

Commit d936b1e

Browse files
committed
Add deterministic prefix in Library.get_flags() (NFC)
This factors duplicate routines to add deterministic prefix paths out to `Library.get_cflags()`. Suggested in emscripten-core#23222 (comment).
1 parent 971d4f6 commit d936b1e

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

tools/system_libs.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,9 @@ def get_files(self):
471471
def generate_ninja(self, build_dir, libname):
472472
ensure_sysroot()
473473
utils.safe_ensure_dirs(build_dir)
474+
self.batch_inputs = True
474475

475476
cflags = self.get_cflags()
476-
if self.deterministic_paths:
477-
source_dir = utils.path_from_root()
478-
relative_source_dir = os.path.relpath(source_dir, build_dir)
479-
cflags += [f'-ffile-prefix-map={source_dir}={DETERMINISITIC_PREFIX}',
480-
f'-ffile-prefix-map={relative_source_dir}={DETERMINISITIC_PREFIX}',
481-
f'-fdebug-compilation-dir={DETERMINISITIC_PREFIX}']
482477
asflags = get_base_cflags(preprocess=False)
483478
input_files = self.get_files()
484479
ninja_file = os.path.join(build_dir, 'build.ninja')
@@ -491,18 +486,11 @@ def build_objects(self, build_dir):
491486
By default, this builds all the source files returned by `self.get_files()`,
492487
with the `cflags` returned by `self.get_cflags()`.
493488
"""
494-
batch_inputs = int(os.environ.get('EMCC_BATCH_BUILD', '1'))
489+
self.batch_inputs = int(os.environ.get('EMCC_BATCH_BUILD', '1'))
495490
batches = {}
496491
commands = []
497492
objects = set()
498493
cflags = self.get_cflags()
499-
if self.deterministic_paths:
500-
source_dir = utils.path_from_root()
501-
if batch_inputs:
502-
relative_source_dir = os.path.relpath(source_dir, build_dir)
503-
cflags += [f'-ffile-prefix-map={relative_source_dir}={DETERMINISITIC_PREFIX}']
504-
cflags += [f'-ffile-prefix-map={source_dir}={DETERMINISITIC_PREFIX}',
505-
f'-fdebug-compilation-dir={DETERMINISITIC_PREFIX}']
506494
case_insensitive = is_case_insensitive(build_dir)
507495
for src in self.get_files():
508496
ext = shared.suffix(src)
@@ -537,7 +525,7 @@ def build_objects(self, build_dir):
537525
object_uuid += 1
538526
o = os.path.join(build_dir, f'{object_basename}__{object_uuid}.o')
539527
commands.append(cmd + [src, '-o', o])
540-
elif batch_inputs:
528+
elif self.batch_inputs:
541529
# Use relative paths to reduce the length of the command line.
542530
# This allows to avoid switching to a response file as often.
543531
src = os.path.relpath(src, build_dir)
@@ -547,7 +535,7 @@ def build_objects(self, build_dir):
547535
commands.append(cmd + [src, '-o', o])
548536
objects.add(o)
549537

550-
if batch_inputs:
538+
if self.batch_inputs:
551539
# Choose a chunk size that is large enough to avoid too many subprocesses
552540
# but not too large to avoid task starvation.
553541
# For now the heuristic is to split inputs by 2x number of cores.
@@ -611,6 +599,13 @@ def get_cflags(self):
611599
if self.includes:
612600
cflags += ['-I' + utils.path_from_root(i) for i in self._inherit_list('includes')]
613601

602+
if self.deterministic_paths:
603+
source_dir = utils.path_from_root()
604+
if self.batch_inputs:
605+
relative_source_dir = os.path.relpath(source_dir, build_dir)
606+
cflags += [f'-ffile-prefix-map={relative_source_dir}={DETERMINISITIC_PREFIX}']
607+
cflags += [f'-ffile-prefix-map={source_dir}={DETERMINISITIC_PREFIX}',
608+
f'-fdebug-compilation-dir={DETERMINISITIC_PREFIX}']
614609
return cflags
615610

616611
def get_base_name_prefix(self):

0 commit comments

Comments
 (0)