aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xem-config24
-rwxr-xr-xtests/runner.py17
-rw-r--r--tools/shared.py1
3 files changed, 42 insertions, 0 deletions
diff --git a/em-config b/em-config
new file mode 100755
index 00000000..dee399ed
--- /dev/null
+++ b/em-config
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+'''
+This is a helper tool which is designed to make it possible
+for other apps to read emscripten's configuration variables
+in a unified way. Usage:
+
+ em-config VAR_NAME
+
+This tool prints the value of the variable to stdout if one
+is found, or exits with 1 if the variable does not exist.
+'''
+
+import os, sys, re
+from tools import shared
+
+if len(sys.argv) != 2 or \
+ not re.match(r"^[\w\W_][\w\W_\d]*$", sys.argv[1]) or \
+ not (sys.argv[1] in dir(shared)):
+ print 'Usage: em-config VAR_NAME'
+ exit(1)
+
+print eval('shared.' + sys.argv[1])
+
diff --git a/tests/runner.py b/tests/runner.py
index a1a3425a..106ea94c 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -6094,6 +6094,23 @@ def process(filename):
'''
self.do_run(src, 'hello, world!\ncleanup\nExit Status: 118')
+ def test_emconfig(self):
+ output = Popen(['python', EMCONFIG, 'LLVM_ROOT'], stdout=PIPE, stderr=PIPE).communicate()[0]
+ assert output == LLVM_ROOT + "\n"
+ invalid = 'Usage: em-config VAR_NAME\n'
+ # Don't accept variables that do not exist
+ output = Popen(['python', EMCONFIG, 'VAR_WHICH_DOES_NOT_EXIST'], stdout=PIPE, stderr=PIPE).communicate()[0]
+ assert output == invalid
+ # Don't accept no arguments
+ output = Popen(['python', EMCONFIG], stdout=PIPE, stderr=PIPE).communicate()[0]
+ assert output == invalid
+ # Don't accept more than one variable
+ output = Popen(['python', EMCONFIG, 'LLVM_ROOT', 'EMCC'], stdout=PIPE, stderr=PIPE).communicate()[0]
+ assert output == invalid
+ # Don't accept arbitrary python code
+ output = Popen(['python', EMCONFIG, 'sys.argv[1]'], stdout=PIPE, stderr=PIPE).communicate()[0]
+ assert output == invalid
+
# Generate tests for everything
def make_run(fullname, name=-1, compiler=-1, llvm_opts=0, embetter=0, quantum_size=0, typed_arrays=0, emcc_args=None):
diff --git a/tools/shared.py b/tools/shared.py
index c864f623..b8dc8221 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -125,6 +125,7 @@ EMAR = path_from_root('emar')
EMLD = path_from_root('emld')
EMRANLIB = path_from_root('emranlib')
EMLIBTOOL = path_from_root('emlibtool')
+EMCONFIG = path_from_root('em-config')
EMMAKEN = path_from_root('tools', 'emmaken.py')
AUTODEBUGGER = path_from_root('tools', 'autodebugger.py')
BINDINGS_GENERATOR = path_from_root('tools', 'bindings_generator.py')