aboutsummaryrefslogtreecommitdiff
path: root/tools/file_packager.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/file_packager.py')
-rw-r--r--tools/file_packager.py40
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 = {}