Skip to content

Commit 1238631

Browse files
authored
fix --valid-abspath on paths that are not trivially valid. this broke in a refactoring. improve tests to prevent that happening again (#5854)
1 parent 2616d04 commit 1238631

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

emcc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,6 @@ def uniquename(name):
575575
def in_temp(name):
576576
return os.path.join(temp_dir, os.path.basename(name))
577577

578-
def in_directory(root, child):
579-
# make both path absolute
580-
root = os.path.realpath(root)
581-
child = os.path.realpath(child)
582-
583-
# return true, if the common prefix of both is equal to directory
584-
# e.g. /a/b/c/d.rst and directory is /a/b, the common prefix is /a/b
585-
return os.path.commonprefix([root, child]) == root
586-
587578
# Parses the essential suffix of a filename, discarding Unix-style version numbers in the name. For example for 'libz.so.1.2.8' returns '.so'
588579
def filename_type_suffix(filename):
589580
for i in reversed(filename.split('.')[1:]):
@@ -2693,6 +2684,15 @@ def is_valid_abspath(options, path_name):
26932684
if shared.path_from_root().replace('\\', '/') in path_name.replace('\\', '/'):
26942685
return True
26952686

2687+
def in_directory(root, child):
2688+
# make both path absolute
2689+
root = os.path.realpath(root)
2690+
child = os.path.realpath(child)
2691+
2692+
# return true, if the common prefix of both is equal to directory
2693+
# e.g. /a/b/c/d.rst and directory is /a/b, the common prefix is /a/b
2694+
return os.path.commonprefix([root, child]) == root
2695+
26962696
for valid_abspath in options.valid_abspaths:
26972697
if in_directory(valid_abspath, path_name):
26982698
return True

tests/test_other.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,16 @@ def test_valid_abspath(self):
34453445
out, err = process.communicate()
34463446
assert(warning not in err)
34473447

3448+
def test_valid_abspath_2(self):
3449+
if WINDOWS:
3450+
abs_include_path = 'C:\\nowhere\\at\\all'
3451+
else:
3452+
abs_include_path = '/nowhere/at/all'
3453+
cmd = [PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '--valid-abspath', abs_include_path,'-I%s' % abs_include_path]
3454+
print(' '.join(cmd))
3455+
subprocess.check_call(cmd)
3456+
self.assertContained('hello, world!', run_js('a.out.js'))
3457+
34483458
def test_warn_dylibs(self):
34493459
shared_suffixes = ['.so', '.dylib', '.dll']
34503460

0 commit comments

Comments
 (0)