diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2013-06-13 21:54:11 +0300 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-06-13 21:54:34 +0300 |
commit | 15b236a68796330670aa7795e3907a1f956f127e (patch) | |
tree | 1d06ddbdeb0f81efcdbcd0372217ec4443584cd5 /tools/file_packager.py | |
parent | 886e3158cf5d95a2c2721e5eb9a1c3ac4461f805 (diff) |
Report debug diagnostics in file packager if EMCC_DEBUG=1. Make file packager skip all path components that have a path starting with '.', like ('.git/xxx/yyy/'), or the filename starts with '.', or the file is a Win32 hidden file. Explicitly specified files on the command line are always packaged, even if they start with '.' or are hidden. Add unit tests to check that it works.
Diffstat (limited to 'tools/file_packager.py')
-rw-r--r-- | tools/file_packager.py | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py index 1443d165..1025207d 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -39,7 +39,7 @@ TODO: You can also provide .crn files yourself, pre-crunched. With this o to dds files in the browser, exactly the same as if this tool compressed them. ''' -import os, sys, shutil, random, uuid +import os, sys, shutil, random, uuid, ctypes import shared from shared import Compression, execute, suffix, unsuffixed @@ -50,6 +50,8 @@ if len(sys.argv) == 1: See the source for more details.''' sys.exit(0) +emcc_debug = os.environ.get('EMCC_DEBUG') + data_target = sys.argv[1] IMAGE_SUFFIXES = ('.jpg', '.png', '.bmp') @@ -150,6 +152,32 @@ function assert(check, msg) { } ''' +# Win32 code to test whether the given file has the hidden property set. +def has_hidden_attribute(filepath): + if sys.platform != 'win32': + return False + + try: + attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(filepath)) + assert attrs != -1 + result = bool(attrs & 2) + except (AttributeError, AssertionError): + result = False + return result + +# The packager should never preload/embed any directories that have a component starting with '.' in them, +# or if the file is hidden (Win32). Note that this filter ONLY applies to directories. Explicitly specified single files +# are always preloaded/embedded, even if they start with a '.'. +def should_ignore(filename): + if has_hidden_attribute(filename): + return True + + components = filename.replace('\\\\', '/').replace('\\', '/').split('/') + for c in components: + if c.startswith('.'): + return True + return False + # Expand directories into individual files def add(arg, dirname, names): # rootpathsrc: The path name of the root directory on the local FS we are adding to emscripten virtual FS. @@ -158,8 +186,12 @@ def add(arg, dirname, names): for name in names: fullname = os.path.join(dirname, name) if not os.path.isdir(fullname): - dstpath = os.path.join(rootpathdst, os.path.relpath(fullname, rootpathsrc)) # Convert source filename relative to root directory of target FS. - data_files.append({ 'srcpath': fullname, 'dstpath': dstpath, 'mode': mode }) + if should_ignore(fullname): + if emcc_debug: + print >> sys.stderr, 'Skipping hidden file "' + fullname + '" from inclusion in the emscripten virtual file system.' + else: + dstpath = os.path.join(rootpathdst, os.path.relpath(fullname, rootpathsrc)) # Convert source filename relative to root directory of target FS. + data_files.append({ 'srcpath': fullname, 'dstpath': dstpath, 'mode': mode }) for file_ in data_files: if os.path.isdir(file_['srcpath']): @@ -171,6 +203,8 @@ for file_ in data_files: if file_['dstpath'].endswith('/'): # If user has submitted a directory name as the destination but omitted the destination filename, use the filename from source file file_['dstpath'] = file_['dstpath'] + os.path.basename(file_['srcpath']) if file_['dstpath'].startswith('./'): file_['dstpath'] = file_['dstpath'][2:] # remove redundant ./ prefix + if emcc_debug: + print >> sys.stderr, 'Packaging file "' + file_['srcpath'] + '" to VFS in path "' + file_['dstpath'] + '".' # Remove duplicates (can occur naively, for example preload dir/, preload dir/subdir/) seen = {} |