aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-02 11:59:38 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-08-02 11:59:38 -0700
commitc147db72f6001054e8a4cb3c6a14a60bc6df5239 (patch)
tree2c61e8964961ab9293fe1ba90b14a6a3da8bd544
parentafc5f4c379d036394345728a03b264fa0dca64d3 (diff)
infer relative paths in file packager only when not told explicit src and dest paths, and fix test_preload_file
-rwxr-xr-xtests/runner.py8
-rw-r--r--tools/file_packager.py21
2 files changed, 16 insertions, 13 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 9f037164..61fde26f 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -12717,7 +12717,7 @@ Press any key to continue.'''
open(absolute_src_path2, 'w').write('''load me right before running the code please''')
def make_main(path):
- print path
+ print 'make main at', path
open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(self.with_report_result(r'''
#include <stdio.h>
#include <string.h>
@@ -12755,14 +12755,14 @@ Press any key to continue.'''
for test in test_cases:
(srcpath, dstpath) = test
+ print 'Testing', srcpath, dstpath
make_main(dstpath)
- print srcpath
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', srcpath, '-o', 'page.html']).communicate()
self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1')
# By absolute path
- make_main(absolute_src_path)
+ make_main('somefile.txt') # absolute becomes relative
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', absolute_src_path, '-o', 'page.html']).communicate()
self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1')
@@ -12822,7 +12822,7 @@ Press any key to continue.'''
# Should still work with -o subdir/..
- make_main(absolute_src_path)
+ make_main('somefile.txt') # absolute becomes relative
try:
os.mkdir(os.path.join(self.get_dir(), 'dirrey'))
except:
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 0097c473..136da609 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -122,8 +122,6 @@ for arg in sys.argv[1:]:
srcpath, dstpath = arg.split('@') # User is specifying destination filename explicitly.
else:
srcpath = dstpath = arg # Use source path as destination path.
- if os.path.isabs(dstpath):
- print >> sys.stderr, 'Warning: Embedding an absolute file/directory name "' + dstpath + '" to the virtual filesystem. The file will be made available in the path "' + dstpath + '", and not in the root of the generated file system. Use the explicit syntax --preload-file srcpath@dstpath to specify the target location the absolute source path should be directed to.'
if os.path.isfile(srcpath) or os.path.isdir(srcpath):
data_files.append({ 'srcpath': srcpath, 'dstpath': dstpath, 'mode': mode })
else:
@@ -201,13 +199,18 @@ data_files = filter(lambda file_: not os.path.isdir(file_['srcpath']), data_file
# Absolutize paths, and check that they make sense
curr_abspath = os.path.abspath(os.getcwd())
for file_ in data_files:
- path = file_['dstpath']
- abspath = os.path.abspath(path)
- if DEBUG: print >> sys.stderr, path, abspath, curr_abspath
- if not abspath.startswith(curr_abspath):
- print >> sys.stderr, 'Error: Embedding "%s" which is below the current directory. This is invalid since the current directory becomes the root that the generated code will see' % path
- sys.exit(1)
- file_['dstpath'] = abspath[len(curr_abspath)+1:]
+ if file_['srcpath'] == file_['dstpath']:
+ # This file was not defined with src@dst, so we inferred the destination from the source. In that case,
+ # we require that the destination not be under the current location
+ path = file_['dstpath']
+ abspath = os.path.abspath(path)
+ if DEBUG: print >> sys.stderr, path, abspath, curr_abspath
+ if not abspath.startswith(curr_abspath):
+ print >> sys.stderr, 'Error: Embedding "%s" which is below the current directory. This is invalid since the current directory becomes the root that the generated code will see' % path
+ sys.exit(1)
+ file_['dstpath'] = abspath[len(curr_abspath)+1:]
+ if os.path.isabs(path):
+ print >> sys.stderr, 'Warning: Embedding an absolute file/directory name "' + path + '" to the virtual filesystem. The file will be made available in the relative path "' + file_['dstpath'] + '". You can use the explicit syntax --preload-file srcpath@dstpath to explicitly specify the target location the absolute source path should be directed to.'
for file_ in data_files:
file_['dstpath'] = file_['dstpath'].replace(os.path.sep, '/') # name in the filesystem, native and emulated