aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-01 11:02:01 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-10-01 11:02:01 -0700
commit5a7de50f0089421508e3bd94bfda21e661135d37 (patch)
tree53509664741b6b235308e1638c5db106eb6ab026
parent375982d9c18ec64764c9ab14406e5712493e2cb3 (diff)
fix file paths with --embed, fixes #597
-rwxr-xr-xtests/runner.py32
-rw-r--r--tools/file_packager.py2
2 files changed, 33 insertions, 1 deletions
diff --git a/tests/runner.py b/tests/runner.py
index b64d8056..cd2e2bd6 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7361,6 +7361,38 @@ f.close()
Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--embed-file', 'somefile.txt', '--embed-file', 'somefile.txt']).communicate()
self.assertContained('|hello from a file wi|', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+ def test_embed_file_dup(self):
+ try_delete(os.path.join(self.get_dir(), 'tst'))
+ os.mkdir(os.path.join(self.get_dir(), 'tst'))
+ os.mkdir(os.path.join(self.get_dir(), 'tst', 'test1'))
+ os.mkdir(os.path.join(self.get_dir(), 'tst', 'test2'))
+
+ open(os.path.join(self.get_dir(), 'tst', 'aa.txt'), 'w').write('''frist''')
+ open(os.path.join(self.get_dir(), 'tst', 'test1', 'aa.txt'), 'w').write('''sacond''')
+ open(os.path.join(self.get_dir(), 'tst', 'test2', 'aa.txt'), 'w').write('''thard''')
+ open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(r'''
+ #include <stdio.h>
+ #include <string.h>
+ void print_file(const char *name) {
+ FILE *f = fopen(name, "r");
+ char buf[100];
+ memset(buf, 0, 100);
+ fread(buf, 1, 20, f);
+ buf[20] = 0;
+ fclose(f);
+ printf("|%s|\n", buf);
+ }
+ int main() {
+ print_file("tst/aa.txt");
+ print_file("tst/test1/aa.txt");
+ print_file("tst/test2/aa.txt");
+ return 0;
+ }
+ ''')
+
+ Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--embed-file', 'tst']).communicate()
+ self.assertContained('|frist|\n|sacond|\n|thard|\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+
def test_multidynamic_link(self):
# Linking the same dynamic library in will error, normally, since we statically link it, causing dupe symbols
# A workaround is to use --ignore-dynamic-linking, see emcc --help for details
diff --git a/tools/file_packager.py b/tools/file_packager.py
index a764b746..9bf781e4 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -252,7 +252,7 @@ for file_ in data_files:
filename = file_['name']
if file_['mode'] == 'embed':
# Embed
- code += '''Module['FS_createDataFile']('/', '%s', %s, true, true);\n''' % (os.path.basename(filename), str(map(ord, open(file_['localname'], 'rb').read())))
+ code += '''Module['FS_createDataFile']('/%s', '%s', %s, true, true);\n''' % (os.path.dirname(filename), os.path.basename(filename), str(map(ord, open(file_['localname'], 'rb').read())))
elif file_['mode'] == 'preload':
# Preload
varname = 'filePreload%d' % counter