Skip to content

Commit 32e12c5

Browse files
authored
Only allow absolute paths for EM_CONFIG/EM_CACHE, etc. (#23402)
Allowing relative paths here breaks when emcc is run as a subprocess in a different directory. This happens in when building system libraries in batch build mode. One alternative to doing this would be convert all these paths to absolute paths when we read them and then re-export them with those different values for our sub-processes, but that seems more complex and error prone than just requiring them to be absolute in the first place. I'm also not sure it makes much sense to use relative paths here since if the environment contains a relative path then the compiler cannot be used from different directories. e.g. ``` $ export EM_CACHE=foo $ emcc hello.c $ cd foo && emcc foo.c # confusingly would use a different cache ``` Fixes: #23374
1 parent bcad96d commit 32e12c5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

test/test_other.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15385,6 +15385,11 @@ def test_rust_integration_basics(self):
1538515385
}''')
1538615386
self.do_runf('main.cpp', 'Hello from rust!', emcc_args=[lib])
1538715387

15388+
def test_relative_em_cache(self):
15389+
with env_modify({'EM_CACHE': 'foo'}):
15390+
err = self.expect_fail([EMCC, '-c', test_file('hello_world.c')])
15391+
self.assertContained('emcc: error: environment variable EM_CACHE must be an absolute path: foo', err)
15392+
1538815393
@crossplatform
1538915394
def test_create_cache_directory(self):
1539015395
if config.FROZEN_CACHE:

tools/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ def parse_config_file():
134134
if env_value in ('', '0'):
135135
env_value = None
136136
# Unlike the other keys these two should always be lists.
137-
if key in ('JS_ENGINES', 'WASM_ENGINES'):
137+
if env_var in ('EM_JS_ENGINES', 'EM_WASM_ENGINES'):
138138
env_value = env_value.split(',')
139+
if env_var in ('EM_CONFIG', 'EM_CACHE', 'EM_PORTS', 'EM_LLVM_ROOT', 'EM_BINARYEN_ROOT'):
140+
if not os.path.isabs(env_value):
141+
exit_with_error(f'environment variable {env_var} must be an absolute path: {env_value}')
139142
globals()[key] = env_value
140143
elif key in config:
141144
globals()[key] = config[key]

0 commit comments

Comments
 (0)