From 8266419d3ea1b3468ce7a809a360586faee19d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Tue, 10 Sep 2013 17:18:04 +0300 Subject: [PATCH] Add emsdk_env.bat to create a mechanism of how to set up all environment variables required for a setup, not just PATH. --- emsdk | 63 ++++++++++++++++++++++++++++++++++++++++----------- emsdk.bat | 5 ++-- emsdk_env.bat | 2 ++ 3 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 emsdk_env.bat diff --git a/emsdk b/emsdk index 1165b60..b26bb26 100644 --- a/emsdk +++ b/emsdk @@ -618,6 +618,49 @@ def currently_active_sdk(): return sdk return None +def currently_active_tools(): + active_tools = [] + for tool in tools: + if tool.is_active(): + active_tools += [tool] + return active_tools + +# Returns a string that should be added to PATH to get the given tools. +def path_additions(tools_to_activate): + # These directories should be added to PATH + path_add = get_required_path(tools_to_activate) + # These already exist. + existing_path = os.environ['PATH'].replace('\\', '/').split(ENVPATH_SEPARATOR) + new_path = [item for item in path_add if item not in existing_path] + return ENVPATH_SEPARATOR.join(new_path) + +def construct_env_windows(tools_to_activate, permanent): + add_to_path = path_additions(tools_to_activate) + if len(add_to_path) > 0: + add_to_path = add_to_path + ';' + newpath = add_to_path + '%PATH%' + +# Dont permanently add to PATH, since this will break the whole system if there are more than 1024 chars in PATH. +# (SETX truncates to set only 1024 chars) +# if permanent: +# print 'SETX PATH "' + newpath + '"' +# else: + + print 'SET PATH=' + newpath + print '' + for tool in tools_to_activate: + if hasattr(tool, 'activated_env'): + (key, value) = parse_key_value(tool.activated_env) + value = value.replace('%installation_dir%', sdk_path(tool.installation_dir())) + if permanent: + print 'SETX ' + key + ' "' + value + '"' + else: + print 'SET ' + key + '=' + value + +def construct_env(tools_to_activate, permanent): + if WINDOWS: + construct_env_windows(tools_to_activate, permanent) + def main(): load_dot_emscripten() load_sdk_manifest() @@ -699,20 +742,14 @@ def main(): if tool == None: print "Error: No tool or SDK found by name '" + sys.argv[2] + "'." return 1 + tools_to_activate = [tool] + tool.recursive_dependencies() - # These directories should be added to PATH - path_add = get_required_path(tools_to_activate) - # These already exist. - existing_path = os.environ['PATH'].replace('\\', '/').split(ENVPATH_SEPARATOR) - #print str(existing_path) - new_path = [item for item in path_add if item not in existing_path] -# print existing_path - # print set(path_add) - #uniq = list(set(existing_path) - set(path_add)) - #print uniq - #new_path = path_add + - print ENVPATH_SEPARATOR.join(new_path) - + print path_additions(tools_to_activate) + + return 0 + elif cmd == 'construct_env': + tools_to_activate = currently_active_tools() + construct_env(tools_to_activate, len(sys.argv) >= 3 and 'perm' in sys.argv[2]) return 0 elif cmd == 'update': update_emsdk() diff --git a/emsdk.bat b/emsdk.bat index 05c4828..430a2ea 100644 --- a/emsdk.bat +++ b/emsdk.bat @@ -2,12 +2,13 @@ :: Find python from an explicit location relative to the Emscripten SDK. IF EXIST "%~dp0python\2.7.5.1_32bit\python.exe" ( - "%~dp0python\2.7.5.1_32bit\python" "%~dp0\emsdk" %* + call "%~dp0python\2.7.5.1_32bit\python" "%~dp0\emsdk" %* GOTO end ) :: As last resort, access from PATH. -python "%~dp0\emsdk" %* +call python "%~dp0\emsdk" %* GOTO end :end +@echo on diff --git a/emsdk_env.bat b/emsdk_env.bat new file mode 100644 index 0000000..62bbfea --- /dev/null +++ b/emsdk_env.bat @@ -0,0 +1,2 @@ +call emsdk construct_env %* > emsdk_set_env.bat +call emsdk_set_env.bat