Skip to content

Commit 4b76531

Browse files
authored
Make debug info in ports deterministic. NFC (#23777)
See #23741
1 parent db261e8 commit 4b76531

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

tools/ports/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def build_port(src_dir, output_path, port_name, includes=[], flags=[], cxxflags=
190190
if ext in ('.c', '.cpp') and not any((excluded in f) for excluded in exclude_files):
191191
srcs.append(os.path.join(root, f))
192192

193-
cflags = system_libs.get_base_cflags() + ['-O2', '-I' + src_dir] + flags
193+
cflags = system_libs.get_base_cflags(build_dir) + ['-O2', '-I' + src_dir] + flags
194194
for include in includes:
195195
cflags.append('-I' + include)
196196

tools/system_libs.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
# A (fake) deterministic emscripten path to use in __FILE__ macro and debug info
4646
# to produce reproducible builds across platforms.
47-
DETERMINISITIC_PREFIX = '/emsdk/emscripten'
47+
DETERMINISTIC_PREFIX = '/emsdk/emscripten'
4848

4949

5050
def files_in_path(path, filenames):
@@ -58,7 +58,7 @@ def glob_in_path(path, glob_pattern, excludes=()):
5858
return sorted(f for f in files if os.path.basename(f) not in excludes)
5959

6060

61-
def get_base_cflags(force_object_files=False, preprocess=True):
61+
def get_base_cflags(build_dir, force_object_files=False, preprocess=True):
6262
# Always build system libraries with debug information. Non-debug builds
6363
# will ignore this at link time because we link with `-strip-debug`.
6464
flags = ['-g', '-sSTRICT', '-Werror']
@@ -70,6 +70,12 @@ def get_base_cflags(force_object_files=False, preprocess=True):
7070
flags += ['-DEMSCRIPTEN_DYNAMIC_LINKING']
7171
if settings.MEMORY64:
7272
flags += ['-Wno-experimental', '-sMEMORY64=' + str(settings.MEMORY64)]
73+
74+
source_dir = utils.path_from_root()
75+
relative_source_dir = os.path.relpath(source_dir, build_dir)
76+
flags += [f'-ffile-prefix-map={source_dir}={DETERMINISTIC_PREFIX}',
77+
f'-ffile-prefix-map={relative_source_dir}={DETERMINISTIC_PREFIX}',
78+
f'-fdebug-compilation-dir={DETERMINISTIC_PREFIX}']
7379
return flags
7480

7581

@@ -462,7 +468,7 @@ def generate_ninja(self, build_dir, libname):
462468
self.build_dir = build_dir
463469

464470
cflags = self.get_cflags()
465-
asflags = get_base_cflags(preprocess=False)
471+
asflags = get_base_cflags(self.build_dir, preprocess=False)
466472
input_files = self.get_files()
467473
ninja_file = os.path.join(build_dir, 'build.ninja')
468474
create_ninja_file(input_files, ninja_file, libname, cflags, asflags=asflags, customize_build_flags=self.customize_build_cmd)
@@ -491,7 +497,7 @@ def build_objects(self, build_dir):
491497
# .s files are processed directly by the assembler. In this case we can't pass
492498
# pre-processor flags such as `-I` and `-D` but we still want core flags such as
493499
# `-sMEMORY64`.
494-
cmd += get_base_cflags(preprocess=False)
500+
cmd += get_base_cflags(self.build_dir, preprocess=False)
495501
else:
496502
cmd += cflags
497503
cmd = self.customize_build_cmd(cmd, src)
@@ -581,16 +587,10 @@ def get_cflags(self):
581587
Override and add any flags as needed to handle new variations.
582588
"""
583589
cflags = self._inherit_list('cflags')
584-
cflags += get_base_cflags(force_object_files=self.force_object_files)
590+
cflags += get_base_cflags(self.build_dir, force_object_files=self.force_object_files)
585591

586592
if self.includes:
587593
cflags += ['-I' + utils.path_from_root(i) for i in self._inherit_list('includes')]
588-
589-
source_dir = utils.path_from_root()
590-
relative_source_dir = os.path.relpath(source_dir, self.build_dir)
591-
cflags += [f'-ffile-prefix-map={source_dir}={DETERMINISITIC_PREFIX}',
592-
f'-ffile-prefix-map={relative_source_dir}={DETERMINISITIC_PREFIX}',
593-
f'-fdebug-compilation-dir={DETERMINISITIC_PREFIX}']
594594
return cflags
595595

596596
def get_base_name_prefix(self):

0 commit comments

Comments
 (0)