Skip to content

Commit cb6d2eb

Browse files
authored
Allow using the search path from -resource-dir with emcc -print-file-name (#27082)
This allows emcc to change the search path when running it like: `emcc -resource-dir=... -print-file-name=...` which mimics the upstream clang behavior.
1 parent 23ec527 commit cb6d2eb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

emcc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ def main(args):
265265
print_file_name = [a for a in args if a.startswith(('-print-file-name=', '--print-file-name='))]
266266
if print_file_name:
267267
libname = print_file_name[-1].split('=')[1]
268-
system_libpath = cache.get_lib_dir(absolute=True)
268+
resource_dir = [a for a in args if a.startswith(('-resource-dir=', '--resource-dir='))]
269+
if resource_dir:
270+
system_libpath = resource_dir[-1].split('=')[1]
271+
else:
272+
system_libpath = cache.get_lib_dir(absolute=True)
269273
fullpath = os.path.join(system_libpath, libname)
270274
if os.path.isfile(fullpath):
271275
print(fullpath)

test/test_other.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,14 @@ def test_print_file_name(self, args):
776776
settings.MEMORY64 = int('-m64' in args)
777777
self.assertContained(cache.get_lib_name('libc.a'), str(filename))
778778

779+
@crossplatform
780+
def test_print_file_name_with_resource_dir(self):
781+
file = Path(EMCC).name
782+
output = self.run_process([EMCC, f'-print-file-name={file}'], stdout=PIPE).stdout
783+
output_relative = self.run_process([EMCC, '-resource-dir=' + path_from_root(), f'-print-file-name={file}'], stdout=PIPE).stdout
784+
self.assertNotExists(output.rstrip())
785+
self.assertExists(output_relative.rstrip())
786+
779787
def test_emar_em_config_flag(self):
780788
# Test that the --em-config flag is accepted but not passed down do llvm-ar.
781789
# We expand this in case the EM_CONFIG is ~/.emscripten (default)

0 commit comments

Comments
 (0)