diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-03-16 10:48:45 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-03-16 10:48:45 -0700 |
commit | 04961832c66b1381838f7e6f94a3463b145b16fb (patch) | |
tree | da3e9ce4f382ce6a8a880f6ab769ab806767a1fe | |
parent | 1a1d011c9ba70ffe40b312fd3367b2b843ca257a (diff) |
allow preloading/embedding of entire directories using emcc
-rwxr-xr-x | emcc | 26 | ||||
-rwxr-xr-x | tests/runner.py | 5 |
2 files changed, 31 insertions, 0 deletions
@@ -203,6 +203,8 @@ Options that are modified or new in %s include: to access the file in the current directory with the same basename as given here (that is, just the filename, without a path to it). + If a directory is passed here, its entire + contents will be embedded. --preload-file <name> A file to preload before running the compiled code asynchronously. Otherwise similar to --embed-file, except that this @@ -214,6 +216,8 @@ Options that are modified or new in %s include: to load (IMG_Load), but they will not be available as normal data files (if you need the alternative, change the suffix). + If a directory is passed here, its entire + contents will be preloaded. --ignore-dynamic-linking Normally emcc will treat dynamic linking like static linking, by linking in the code from the dynamic library. This fails if the same @@ -752,6 +756,26 @@ try: if DEBUG: print >> sys.stderr, 'emcc: setting up files' code = '' + # Sanity checks + for filename in embed_files: + assert filename not in preload_files, 'Cannot both embed and preload file %s' % filename + + # Expand directories + def add(filename, dirname, names): + for name in names: + combined = os.path.join(dirname, name) + if filename in embed_files: + embed_files.append(combined) + else: + preload_files.append(combined) + for filename in embed_files + preload_files: + if os.path.isdir(filename): + os.path.walk(filename, add, filename) + for source in [embed_files, preload_files]: + if filename in source: + source.remove(filename) + + # Set up folders partial_dirs = [] for filename in embed_files + preload_files: dirname = os.path.dirname(filename) @@ -763,11 +787,13 @@ try: code += '''FS.createFolder('/%s', '%s', true, false);\n''' % (os.path.sep.join(parts[:i-1]), parts[-1]) partial_dirs.append(partial) + # Embed for filename in embed_files: if filename.endswith(IMAGE_SUFFIXES): print >> sys.stderr, 'emcc: warning: embedding file %s, but not making sure it decodes synchronously. consider using --preload-file' % filename code += '''FS.createDataFile('/', '%s', %s, true, true);\n''' % (os.path.basename(filename), str(map(ord, open(filename, 'rb').read()))) + # Preload counter = 0 for filename in preload_files: varname = 'filePreload%d' % counter diff --git a/tests/runner.py b/tests/runner.py index 4fc8cfa9..66aa63b4 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6275,9 +6275,14 @@ f.close() } ''')) + # by individual files Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'subdirr/data1.txt', '--preload-file', 'subdirr/data2.txt', '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should see two cool numbers', '/report_result?1') + # by directory + Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'subdirr', '-o', 'page.html']).communicate() + self.run_browser('page.html', 'You should see two cool numbers', '/report_result?1') + def test_emcc_sdl_image(self): # load an image file, get pixel data shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.jpg')) |