From 2b2add48545101de5776c9b26701245c43a8fcb0 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 14 May 2012 20:32:56 -0400 Subject: [PATCH] Add the em-config tool This tool is useful to use in shell scripts, etc in order to access variables defined in the ~/.emscripten file without depending on the details on how to read and parse it. --- em-config | 24 ++++++++++++++++++++++++ tests/runner.py | 17 +++++++++++++++++ tools/shared.py | 1 + 3 files changed, 42 insertions(+) create mode 100755 em-config diff --git a/em-config b/em-config new file mode 100755 index 000000000..dee399ed9 --- /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 a1a3425a9..106ea94c7 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 c864f6235..b8dc8221f 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')