diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/file_packager.py | 40 | ||||
-rw-r--r-- | tools/shared.py | 13 |
2 files changed, 45 insertions, 8 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py index 1443d165..99180b93 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) +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 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 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 = {} diff --git a/tools/shared.py b/tools/shared.py index 8a172d9c..b212a9cc 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -295,7 +295,7 @@ def check_node_version(): # we re-check sanity when the settings are changed) # We also re-check sanity and clear the cache when the version changes -EMSCRIPTEN_VERSION = '1.4.9' +EMSCRIPTEN_VERSION = '1.5.0' def generate_sanity(): return EMSCRIPTEN_VERSION + '|' + get_llvm_target() @@ -454,9 +454,12 @@ EMSCRIPTEN_TEMP_DIR = configuration.EMSCRIPTEN_TEMP_DIR DEBUG_CACHE = configuration.DEBUG_CACHE CANONICAL_TEMP_DIR = configuration.CANONICAL_TEMP_DIR -level = logging.DEBUG if os.environ.get('EMCC_DEBUG') else logging.INFO -logging.basicConfig(level=level, format='%(levelname)-8s %(name)s: %(message)s') - +logging.basicConfig(format='%(levelname)-8s %(name)s: %(message)s') +def set_logging(): + logger = logging.getLogger() + logger.setLevel(logging.DEBUG if os.environ.get('EMCC_DEBUG') else logging.INFO) +set_logging() + if not EMSCRIPTEN_TEMP_DIR: EMSCRIPTEN_TEMP_DIR = tempfile.mkdtemp(prefix='emscripten_temp_', dir=configuration.TEMP_DIR) def clean_temp(): @@ -1091,7 +1094,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e @staticmethod def can_build_standalone(): - return not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE + return not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE and not Settings.EXPORT_ALL @staticmethod def can_use_unsafe_opts(): |