From 467b86c590a3b43e71566d98a322a1ee7d7d9c2a Mon Sep 17 00:00:00 2001 From: Diyou Date: Wed, 10 Jun 2026 01:49:30 +0200 Subject: [PATCH 1/6] Add logic to use a relative search path with -print-file-name + Test --- emcc.py | 9 +++++++-- test/test_other.py | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/emcc.py b/emcc.py index f770f4a539b06..20984151ff8bd 100644 --- a/emcc.py +++ b/emcc.py @@ -264,8 +264,13 @@ def main(args): print_file_name = [a for a in args if a.startswith(('-print-file-name=', '--print-file-name='))] if print_file_name: - libname = print_file_name[-1].split('=')[1] - system_libpath = cache.get_lib_dir(absolute=True) + arg = print_file_name[-1] + libname = arg.split('=')[1] + index = args.index(arg) + if index >= 1: + system_libpath = os.path.abspath(args[0]) + else: + system_libpath = cache.get_lib_dir(absolute=True) fullpath = os.path.join(system_libpath, libname) if os.path.isfile(fullpath): print(fullpath) diff --git a/test/test_other.py b/test/test_other.py index b833da904979b..d72f91c2bd3b3 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -776,6 +776,13 @@ def test_print_file_name(self, args): settings.MEMORY64 = int('-m64' in args) self.assertContained(cache.get_lib_name('libc.a'), str(filename)) + @crossplatform + def test_print_file_name_relative(self): + output = self.run_process([EMCC, '-print-file-name=emcc'], stdout=PIPE).stdout + output_relative = self.run_process([EMCC, path_from_root(), '-print-file-name=emcc'], stdout=PIPE).stdout + self.assertNotExists(output.rstrip()) + self.assertExists(output_relative.rstrip()) + def test_emar_em_config_flag(self): # Test that the --em-config flag is accepted but not passed down do llvm-ar. # We expand this in case the EM_CONFIG is ~/.emscripten (default) From c6a1cdac92f5cd126fb23955522f7abd06909670 Mon Sep 17 00:00:00 2001 From: Diyou Date: Wed, 10 Jun 2026 15:19:04 +0200 Subject: [PATCH 2/6] Add quotes to the search path in the test Hopefully prevents the CI fail --- test/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_other.py b/test/test_other.py index d72f91c2bd3b3..bece3ad114eff 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -779,7 +779,7 @@ def test_print_file_name(self, args): @crossplatform def test_print_file_name_relative(self): output = self.run_process([EMCC, '-print-file-name=emcc'], stdout=PIPE).stdout - output_relative = self.run_process([EMCC, path_from_root(), '-print-file-name=emcc'], stdout=PIPE).stdout + output_relative = self.run_process([EMCC, shlex.quote(path_from_root()), '-print-file-name=emcc'], stdout=PIPE).stdout self.assertNotExists(output.rstrip()) self.assertExists(output_relative.rstrip()) From 3c4477912b5ef54e834417b3b26f4410cdd218e8 Mon Sep 17 00:00:00 2001 From: Diyou Date: Wed, 10 Jun 2026 17:07:20 +0200 Subject: [PATCH 3/6] Add -resource-dir flag handling in emcc.py This reverts the initial changes in favor of -resource-dir --- emcc.py | 13 ++++++------- test/test_other.py | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/emcc.py b/emcc.py index 20984151ff8bd..4fe1a94003add 100644 --- a/emcc.py +++ b/emcc.py @@ -262,15 +262,14 @@ def main(args): print(compiler_rt.get_path(absolute=True)) return 0 + resource_dir = [a for a in args if a.startswith(('-resource-dir=', '--resource-dir='))] + if resource_dir: + resource_dir = resource_dir[-1].split('=')[1] + print_file_name = [a for a in args if a.startswith(('-print-file-name=', '--print-file-name='))] if print_file_name: - arg = print_file_name[-1] - libname = arg.split('=')[1] - index = args.index(arg) - if index >= 1: - system_libpath = os.path.abspath(args[0]) - else: - system_libpath = cache.get_lib_dir(absolute=True) + libname = print_file_name[-1].split('=')[1] + system_libpath = resource_dir or cache.get_lib_dir(absolute=True) fullpath = os.path.join(system_libpath, libname) if os.path.isfile(fullpath): print(fullpath) diff --git a/test/test_other.py b/test/test_other.py index bece3ad114eff..e03c72a0e4dc0 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -777,9 +777,9 @@ def test_print_file_name(self, args): self.assertContained(cache.get_lib_name('libc.a'), str(filename)) @crossplatform - def test_print_file_name_relative(self): + def test_print_file_name_with_resource_dir(self): output = self.run_process([EMCC, '-print-file-name=emcc'], stdout=PIPE).stdout - output_relative = self.run_process([EMCC, shlex.quote(path_from_root()), '-print-file-name=emcc'], stdout=PIPE).stdout + output_relative = self.run_process([EMCC, '-resource-dir=' + path_from_root(), '-print-file-name=emcc'], stdout=PIPE).stdout self.assertNotExists(output.rstrip()) self.assertExists(output_relative.rstrip()) From bc15a28aa2d314e2d1175d31d7ec19de55176cfc Mon Sep 17 00:00:00 2001 From: Diyou Date: Wed, 10 Jun 2026 18:18:51 +0200 Subject: [PATCH 4/6] Use agnostic substitution in test_print_file_name_with_resource_dir --- test/test_other.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index e03c72a0e4dc0..f8b8f63ee766c 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -778,8 +778,9 @@ def test_print_file_name(self, args): @crossplatform def test_print_file_name_with_resource_dir(self): - output = self.run_process([EMCC, '-print-file-name=emcc'], stdout=PIPE).stdout - output_relative = self.run_process([EMCC, '-resource-dir=' + path_from_root(), '-print-file-name=emcc'], stdout=PIPE).stdout + file = Path(EMCC).stem + output = self.run_process([EMCC, f'-print-file-name={file}'], stdout=PIPE).stdout + output_relative = self.run_process([EMCC, '-resource-dir=' + path_from_root(), f'-print-file-name={file}'], stdout=PIPE).stdout self.assertNotExists(output.rstrip()) self.assertExists(output_relative.rstrip()) From e0f8ab08a2816613416c07e740ef6af3cdd8387c Mon Sep 17 00:00:00 2001 From: Diyou Date: Wed, 10 Jun 2026 18:31:30 +0200 Subject: [PATCH 5/6] Let the print_file_name evaluation handle resource-dir +Remove white space --- emcc.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/emcc.py b/emcc.py index 4fe1a94003add..dddbdb197cb4f 100644 --- a/emcc.py +++ b/emcc.py @@ -262,14 +262,14 @@ def main(args): print(compiler_rt.get_path(absolute=True)) return 0 - resource_dir = [a for a in args if a.startswith(('-resource-dir=', '--resource-dir='))] - if resource_dir: - resource_dir = resource_dir[-1].split('=')[1] - print_file_name = [a for a in args if a.startswith(('-print-file-name=', '--print-file-name='))] if print_file_name: libname = print_file_name[-1].split('=')[1] - system_libpath = resource_dir or cache.get_lib_dir(absolute=True) + resource_dir = [a for a in args if a.startswith(('-resource-dir=', '--resource-dir='))] + if resource_dir: + system_libpath = resource_dir[-1].split('=')[1] + else: + system_libpath = cache.get_lib_dir(absolute=True) fullpath = os.path.join(system_libpath, libname) if os.path.isfile(fullpath): print(fullpath) From afe5e7934b3e9b6bc729623021bd599d1c78933f Mon Sep 17 00:00:00 2001 From: Diyou Date: Wed, 10 Jun 2026 19:26:22 +0200 Subject: [PATCH 6/6] Test file with file extension --- test/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_other.py b/test/test_other.py index f8b8f63ee766c..8b4bb8fe182be 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -778,7 +778,7 @@ def test_print_file_name(self, args): @crossplatform def test_print_file_name_with_resource_dir(self): - file = Path(EMCC).stem + file = Path(EMCC).name output = self.run_process([EMCC, f'-print-file-name={file}'], stdout=PIPE).stdout output_relative = self.run_process([EMCC, '-resource-dir=' + path_from_root(), f'-print-file-name={file}'], stdout=PIPE).stdout self.assertNotExists(output.rstrip())