aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/file_packager.py43
-rw-r--r--tools/js-optimizer.js39
-rw-r--r--tools/settings_template_readonly.py47
-rw-r--r--tools/shared.py26
4 files changed, 127 insertions, 28 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 64a21386..e5a9025d 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -46,6 +46,8 @@ CRUNCH_OUTPUT_SUFFIX = '.crn'
DDS_HEADER_SIZE = 128
+AV_WORKAROUND = 0 # Set to 1 to randomize file order and add some padding, to work around silly av false positives
+
data_files = []
in_preload = False
in_embed = False
@@ -136,8 +138,8 @@ def was_seen(name):
return False
data_files = filter(lambda file_: not was_seen(file_['name']), data_files)
-# Randomize order, to get around silly fake antivirus positivies
-random.shuffle(data_files)
+if AV_WORKAROUND:
+ random.shuffle(data_files)
# Apply plugins
for file_ in data_files:
@@ -222,6 +224,7 @@ if has_preloaded:
file_['data_start'] = start
curr = open(file_['localname'], 'rb').read()
file_['data_end'] = start + len(curr)
+ if AV_WORKAROUND: curr += '\x00'
print >> sys.stderr, 'bundling', file_['name'], file_['localname'], file_['data_start'], file_['data_end']
start += len(curr)
data.write(curr)
@@ -318,18 +321,46 @@ if has_preloaded:
});
''' % use_data
- code += '''
+ code += r'''
+ if (!Module.expectedDataFileDownloads) {
+ Module.expectedDataFileDownloads = 0;
+ Module.finishedDataFileDownloads = 0;
+ }
+ Module.expectedDataFileDownloads++;
+
var dataFile = new XMLHttpRequest();
dataFile.onprogress = function(event) {
+ var url = '%s';
if (event.loaded && event.total) {
- Module.setStatus('Downloading data... (' + event.loaded + '/' + event.total + ')');
- } else {
+ if (!dataFile.addedTotal) {
+ dataFile.addedTotal = true;
+ if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
+ Module.dataFileDownloads[url] = {
+ loaded: event.loaded,
+ total: event.total
+ };
+ } else {
+ Module.dataFileDownloads[url].loaded = event.loaded;
+ }
+ var total = 0;
+ var loaded = 0;
+ var num = 0;
+ for (var download in Module.dataFileDownloads) {
+ var data = Module.dataFileDownloads[download];
+ total += data.total;
+ loaded += data.loaded;
+ num++;
+ }
+ total = Math.ceil(total * Module.expectedDataFileDownloads/num);
+ Module.setStatus('Downloading data... (' + loaded + '/' + total + ')');
+ } else if (!Module.dataFileDownloads) {
Module.setStatus('Downloading data...');
}
}
dataFile.open('GET', '%s', true);
dataFile.responseType = 'arraybuffer';
dataFile.onload = function() {
+ Module.finishedDataFileDownloads++;
var arrayBuffer = dataFile.response;
assert(arrayBuffer, 'Loading data file failed.');
var byteArray = new Uint8Array(arrayBuffer);
@@ -339,7 +370,7 @@ if has_preloaded:
Module['addRunDependency']('datafile_%s');
dataFile.send(null);
if (Module['setStatus']) Module['setStatus']('Downloading...');
- ''' % (os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target), use_data, data_target) # use basename because from the browser's point of view, we need to find the datafile in the same dir as the html file
+ ''' % (data_target, os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target), use_data, data_target) # use basename because from the browser's point of view, we need to find the datafile in the same dir as the html file
if pre_run:
print '''
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index e1cfbe65..5dac36f0 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -26,15 +26,30 @@ if (ENVIRONMENT_IS_NODE) {
var nodeFS = require('fs');
var nodePath = require('path');
- read = function(filename) {
- filename = nodePath['normalize'](filename);
- var ret = nodeFS['readFileSync'](filename).toString();
- // The path is absolute if the normalized version is the same as the resolved.
- if (!ret && filename != nodePath['resolve'](filename)) {
- filename = path.join(__dirname, '..', 'src', filename);
- ret = nodeFS['readFileSync'](filename).toString();
+ if (!nodeFS.existsSync) {
+ nodeFS.existsSync = function(path) {
+ try {
+ return !!nodeFS.readFileSync(path);
+ } catch(e) {
+ return false;
+ }
+ }
+ }
+
+ function find(filename) {
+ var prefixes = [nodePath.join(__dirname, '..', 'src'), process.cwd()];
+ for (var i = 0; i < prefixes.length; ++i) {
+ var combined = nodePath.join(prefixes[i], filename);
+ if (nodeFS.existsSync(combined)) {
+ return combined;
+ }
}
- return ret;
+ return filename;
+ }
+
+ read = function(filename) {
+ var absolute = find(filename);
+ return nodeFS['readFileSync'](absolute).toString();
};
load = function(f) {
@@ -98,14 +113,6 @@ if (typeof print === 'undefined') {
}
// *** Environment setup code ***
-// Fix read for our location
-read = function(filename) {
- // The path is absolute if the normalized version is the same as the resolved.
- filename = path.normalize(filename);
- if (filename != path.resolve(filename)) filename = path.join(__dirname, '..', 'src', filename);
- return fs.readFileSync(filename).toString();
-}
-
var uglify = require('../tools/eliminator/node_modules/uglify-js');
var fs = require('fs');
var path = require('path');
diff --git a/tools/settings_template_readonly.py b/tools/settings_template_readonly.py
new file mode 100644
index 00000000..45a30569
--- /dev/null
+++ b/tools/settings_template_readonly.py
@@ -0,0 +1,47 @@
+# This file will be copied to ~/.emscripten if that file doesn't exist. Or, this is that copy.
+# IMPORTANT: Edit the *copy* with the right paths!
+# Note: If you put paths relative to the home directory, do not forget os.path.expanduser
+
+import os
+
+# this helps projects using emscripten find it
+EMSCRIPTEN_ROOT = os.path.expanduser(os.getenv('EMSCRIPTEN') or '/opt/emscripten')
+LLVM_ROOT = os.path.expanduser(os.getenv('LLVM') or '/usr/bin')
+
+# See below for notes on which JS engine(s) you need
+NODE_JS = 'node'
+SPIDERMONKEY_ENGINE = [
+ os.path.expanduser(os.getenv('SPIDERMONKEY') or 'js'), '-m', '-n']
+V8_ENGINE = os.path.expanduser(os.getenv('V8') or 'd8')
+
+JAVA = 'java'
+
+TEMP_DIR = '/tmp' # You will need to modify this on Windows
+
+#CLOSURE_COMPILER = '..' # define this to not use the bundled version
+
+########################################################################################################
+
+
+# Pick the JS engine to use for running the compiler. This engine must exist, or
+# nothing can be compiled.
+#
+# Recommendation: If you already have node installed, use that. Otherwise, build v8 or
+# spidermonkey from source. Any of these three is fine, as long as it's
+# a recent version (especially for v8 and spidermonkey).
+
+COMPILER_ENGINE = NODE_JS
+#COMPILER_ENGINE = V8_ENGINE
+#COMPILER_ENGINE = SPIDERMONKEY_ENGINE
+
+
+# All JS engines to use when running the automatic tests. Not all the engines in this list
+# must exist (if they don't, they will be skipped in the test runner).
+#
+# Recommendation: If you already have node installed, use that. If you can, also build
+# spidermonkey from source as well to get more test coverage (node can't
+# run all the tests due to node issue 1669). v8 is currently not recommended
+# here because of v8 issue 1822.
+
+JS_ENGINES = [NODE_JS, SPIDERMONKEY_ENGINE]
+
diff --git a/tools/shared.py b/tools/shared.py
index fa06f958..2fc894d0 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -20,7 +20,7 @@ if '\n' in EM_CONFIG:
else:
CONFIG_FILE = os.path.expanduser(EM_CONFIG)
if not os.path.exists(CONFIG_FILE):
- shutil.copy(path_from_root('settings.py'), CONFIG_FILE)
+ shutil.copy(path_from_root('tools', 'settings_template_readonly.py'), CONFIG_FILE)
print >> sys.stderr, '''
==============================================================================
Welcome to Emscripten!
@@ -110,7 +110,7 @@ def check_sanity(force=False):
try:
subprocess.call([JAVA, '-version'], stdout=PIPE, stderr=PIPE)
except:
- print >> sys.stderr, 'WARNING: java does not seem to exist, required for closure compiler. -O2 and above will fail. You need to define JAVA in ~/.emscripten (see settings.py)'
+ print >> sys.stderr, 'WARNING: java does not seem to exist, required for closure compiler. -O2 and above will fail. You need to define JAVA in ~/.emscripten'
if not os.path.exists(CLOSURE_COMPILER):
print >> sys.stderr, 'WARNING: Closure compiler (%s) does not exist, check the paths in %s. -O2 and above will fail' % (CLOSURE_COMPILER, EM_CONFIG)
@@ -520,6 +520,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
def make(args, stdout=None, stderr=None, env=None):
if env is None:
env = Building.get_building_env()
+ #args += ['VERBOSE=1']
Popen(args, stdout=stdout, stderr=stderr, env=env).communicate()
@staticmethod
@@ -557,9 +558,17 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
if configure: # Useful in debugging sometimes to comment this out (and the lines below up to and including the |link| call)
Building.configure(configure + configure_args, stdout=open(os.path.join(project_dir, 'configure_'), 'w'),
stderr=open(os.path.join(project_dir, 'configure_err'), 'w'), env=env)
- for i in range(2): # workaround for some build systems that need to be run twice to succeed (e.g. poppler)
- Building.make(make + make_args, stdout=open(os.path.join(project_dir, 'make_' + str(i)), 'w'),
- stderr=open(os.path.join(project_dir, 'make_err' + str(i)), 'w'), env=env)
+ def open_make_out(i, mode='r'):
+ return open(os.path.join(project_dir, 'make_' + str(i)), mode)
+
+ def open_make_err(i, mode='r'):
+ return open(os.path.join(project_dir, 'make_err' + str(i)), mode)
+
+ for i in range(2): # FIXME: Sad workaround for some build systems that need to be run twice to succeed (e.g. poppler)
+ with open_make_out(i, 'w') as make_out:
+ with open_make_err(i, 'w') as make_err:
+ Building.make(make + make_args, stdout=make_out,
+ stderr=make_err, env=env)
try:
if cache is not None:
cache[cache_name] = []
@@ -568,7 +577,12 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
cache[cache_name].append((basename, open(f, 'rb').read()))
break
except:
- if i > 0: raise Exception('could not build library ' + name)
+ if i > 0:
+ # Due to the ugly hack above our best guess is to output the first run
+ with open_make_err(0) as ferr:
+ for line in ferr:
+ sys.stderr.write(line)
+ raise Exception('could not build library ' + name)
if old_dir:
os.chdir(old_dir)
return generated_libs