Improve support for registering environment variables and PATH on 'emsdk activate'. Add machinery for hiding old sdk tools and sdks.
This commit is contained in:
@@ -1 +1 @@
|
|||||||
@cmd /k call emsdk_add_path.bat
|
@cmd /k call emsdk_env.bat
|
||||||
|
|||||||
87
emsdk
87
emsdk
@@ -61,6 +61,7 @@ def win_get_active_environment_variable(key):
|
|||||||
return win_get_environment_variable(key, True)
|
return win_get_environment_variable(key, True)
|
||||||
|
|
||||||
def win_set_environment_variable(key, value, system=True):
|
def win_set_environment_variable(key, value, system=True):
|
||||||
|
# print >> sys.stderr, 'set ' + str(key) + '=' + str(value) + ', in system=' + str(system)
|
||||||
previous_value = win_get_environment_variable(key, system)
|
previous_value = win_get_environment_variable(key, system)
|
||||||
if previous_value == value:
|
if previous_value == value:
|
||||||
return # No need to elevate UAC for nothing to set the same value, skip.
|
return # No need to elevate UAC for nothing to set the same value, skip.
|
||||||
@@ -441,9 +442,12 @@ JS_ENGINES = [NODE_JS]
|
|||||||
print cfg
|
print cfg
|
||||||
|
|
||||||
path_add = get_required_path(active_tools)
|
path_add = get_required_path(active_tools)
|
||||||
print "To conveniently access the selected set of tools from the command line, consider adding the following directories to PATH, or call '" + ('' if WINDOWS else 'source ') + os.path.relpath(sdk_path('emsdk_add_path')) + "' to do this for you."
|
if WINDOWS:
|
||||||
print ''
|
print 'The appropriate environment variables have also been set in registry.'
|
||||||
print ' ' + ENVPATH_SEPARATOR.join(path_add)
|
else:
|
||||||
|
print "To conveniently access the selected set of tools from the command line, consider adding the following directories to PATH, or call '" + ('' if WINDOWS else 'source ') + os.path.relpath(sdk_path('emsdk_add_path')) + "' to do this for you."
|
||||||
|
print ''
|
||||||
|
print ' ' + ENVPATH_SEPARATOR.join(path_add)
|
||||||
|
|
||||||
def find_msbuild_dir():
|
def find_msbuild_dir():
|
||||||
if 'ProgramFiles' in os.environ and os.environ['ProgramFiles']:
|
if 'ProgramFiles' in os.environ and os.environ['ProgramFiles']:
|
||||||
@@ -770,12 +774,16 @@ def load_sdk_manifest():
|
|||||||
for tool in manifest['tools']:
|
for tool in manifest['tools']:
|
||||||
t = Tool(tool)
|
t = Tool(tool)
|
||||||
if t.compatible_with_this_os():
|
if t.compatible_with_this_os():
|
||||||
|
if not hasattr(t, 'is_old'):
|
||||||
|
t.is_old = False
|
||||||
tools.append(t)
|
tools.append(t)
|
||||||
|
|
||||||
for sdk_str in manifest['sdks']:
|
for sdk_str in manifest['sdks']:
|
||||||
sdk = Tool(sdk_str)
|
sdk = Tool(sdk_str)
|
||||||
sdk.id = "sdk"
|
sdk.id = "sdk"
|
||||||
if sdk.compatible_with_this_os():
|
if sdk.compatible_with_this_os():
|
||||||
|
if not hasattr(sdk, 'is_old'):
|
||||||
|
sdk.is_old = False
|
||||||
sdks.append(sdk)
|
sdks.append(sdk)
|
||||||
|
|
||||||
def install(): # TODO: Add parameter to choose which SDK to install.
|
def install(): # TODO: Add parameter to choose which SDK to install.
|
||||||
@@ -828,11 +836,19 @@ def set_active_tools(tools_to_activate):
|
|||||||
|
|
||||||
generate_dot_emscripten(tools_to_activate)
|
generate_dot_emscripten(tools_to_activate)
|
||||||
|
|
||||||
# Apply environment variables.
|
# Apply environment variables to global all users section.
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
|
# Individual env. vars
|
||||||
for tool in tools_to_activate:
|
for tool in tools_to_activate:
|
||||||
tool.win_activate_env_vars(True)
|
tool.win_activate_env_vars(True)
|
||||||
|
|
||||||
|
# PATH variable
|
||||||
|
newpath = adjusted_path(tools_to_activate)
|
||||||
|
if len(newpath) < 1024:
|
||||||
|
win_set_environment_variable('PATH', newpath, system=True)
|
||||||
|
else:
|
||||||
|
print >> sys.stderr, 'ERROR! The current PATH is too large (more than 1024 characters), unable to add Emscripten environment to PATH via command-line! Please do this via the system user interface.'
|
||||||
|
|
||||||
def currently_active_sdk():
|
def currently_active_sdk():
|
||||||
for sdk in reversed(sdks):
|
for sdk in reversed(sdks):
|
||||||
if sdk.is_active():
|
if sdk.is_active():
|
||||||
@@ -846,20 +862,27 @@ def currently_active_tools():
|
|||||||
active_tools += [tool]
|
active_tools += [tool]
|
||||||
return active_tools
|
return active_tools
|
||||||
|
|
||||||
# Returns a string that should be added to PATH to get the given tools.
|
# http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order
|
||||||
def path_additions(tools_to_activate):
|
def unique_items(seq):
|
||||||
|
seen = set()
|
||||||
|
seen_add = seen.add
|
||||||
|
return [ x for x in seq if x not in seen and not seen_add(x)]
|
||||||
|
|
||||||
|
# Looks at the current PATH and adds and removes entries so that the PATH reflects
|
||||||
|
# the set of given active tools.
|
||||||
|
def adjusted_path(tools_to_activate):
|
||||||
# These directories should be added to PATH
|
# These directories should be added to PATH
|
||||||
path_add = get_required_path(tools_to_activate)
|
path_add = get_required_path(tools_to_activate)
|
||||||
# These already exist.
|
# These already exist.
|
||||||
existing_path = os.environ['PATH'].replace('\\', '/').split(ENVPATH_SEPARATOR)
|
existing_path = os.environ['PATH'].replace('\\', '/').split(ENVPATH_SEPARATOR)
|
||||||
|
emsdk_root_path = emsdk_path()
|
||||||
|
existing_path = [item for item in existing_path if not item.startswith(emsdk_root_path)]
|
||||||
new_path = [item for item in path_add if item not in existing_path]
|
new_path = [item for item in path_add if item not in existing_path]
|
||||||
return ENVPATH_SEPARATOR.join(new_path)
|
return ENVPATH_SEPARATOR.join(unique_items(existing_path + new_path))
|
||||||
|
|
||||||
def construct_env_windows(tools_to_activate, permanent):
|
def construct_env_windows(tools_to_activate, permanent):
|
||||||
add_to_path = path_additions(tools_to_activate)
|
env_string = ''
|
||||||
if len(add_to_path) > 0:
|
newpath = adjusted_path(tools_to_activate)
|
||||||
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.
|
# 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)
|
# (SETX truncates to set only 1024 chars)
|
||||||
@@ -867,20 +890,20 @@ def construct_env_windows(tools_to_activate, permanent):
|
|||||||
# print 'SETX PATH "' + newpath + '"'
|
# print 'SETX PATH "' + newpath + '"'
|
||||||
# else:
|
# else:
|
||||||
|
|
||||||
print 'SET PATH=' + newpath
|
env_string += 'SET PATH=' + newpath + '\n'
|
||||||
print ''
|
|
||||||
for tool in tools_to_activate:
|
for tool in tools_to_activate:
|
||||||
if hasattr(tool, 'activated_env'):
|
if hasattr(tool, 'activated_env'):
|
||||||
(key, value) = parse_key_value(tool.activated_env)
|
(key, value) = parse_key_value(tool.activated_env)
|
||||||
value = tool.expand_vars(value)
|
value = tool.expand_vars(value)
|
||||||
if permanent:
|
if permanent:
|
||||||
print 'SETX ' + key + ' "' + value + '"'
|
env_string += 'SETX ' + key + ' "' + value + '"\n'
|
||||||
else:
|
else:
|
||||||
print 'SET ' + key + '=' + value
|
env_string += 'SET ' + key + '=' + value + '\n'
|
||||||
|
return env_string
|
||||||
|
|
||||||
def construct_env(tools_to_activate, permanent):
|
def construct_env(tools_to_activate, permanent):
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
construct_env_windows(tools_to_activate, permanent)
|
return construct_env_windows(tools_to_activate, permanent)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
load_dot_emscripten()
|
load_dot_emscripten()
|
||||||
@@ -897,8 +920,9 @@ def main():
|
|||||||
print ' emsdk: Available commands:'
|
print ' emsdk: Available commands:'
|
||||||
|
|
||||||
print '''
|
print '''
|
||||||
emsdk list - Lists all available SDKs and tools and their
|
emsdk list [--old] - Lists all available SDKs and tools and their
|
||||||
current installation status.
|
current installation status. With the --old
|
||||||
|
parameter, also historical versions are shown.
|
||||||
|
|
||||||
emsdk update - Fetches a list of updates from the net (but
|
emsdk update - Fetches a list of updates from the net (but
|
||||||
does not install them)
|
does not install them)
|
||||||
@@ -906,20 +930,14 @@ def main():
|
|||||||
emsdk install <tool/sdk> - Downloads and installs the given tool or SDK.
|
emsdk install <tool/sdk> - Downloads and installs the given tool or SDK.
|
||||||
emsdk uninstall <tool/sdk> - Removes the given tool or SDK from disk.
|
emsdk uninstall <tool/sdk> - Removes the given tool or SDK from disk.
|
||||||
|
|
||||||
emsdk activate <tool/sdk> - Activates the given tool or SDK as the
|
emsdk activate <tool/sdk> - Permanently activates the given tool or SDK as
|
||||||
default tool for the current user.
|
the default tool in the system environment.'''
|
||||||
|
|
||||||
emsdk active_path [tool/sdk] - A helper command to report the directories
|
|
||||||
that should be added to PATH to use the
|
|
||||||
given tool or SDK. If no tool/sdk is
|
|
||||||
specified, reports the directive for the
|
|
||||||
currently active SDK. '''
|
|
||||||
|
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
print '''
|
print '''
|
||||||
emcmdprompt.bat - Spawns a new command prompt that has the tool
|
emcmdprompt.bat - Spawns a new command prompt window with the
|
||||||
directories of all currently active tools
|
Emscripten environment active.'''
|
||||||
added to PATH. '''
|
|
||||||
return 1
|
return 1
|
||||||
cmd = sys.argv[1]
|
cmd = sys.argv[1]
|
||||||
|
|
||||||
@@ -933,9 +951,12 @@ def main():
|
|||||||
|
|
||||||
if cmd == 'list':
|
if cmd == 'list':
|
||||||
print ''
|
print ''
|
||||||
|
show_old = len(sys.argv) >= 3 and sys.argv[2] == '--old'
|
||||||
if len(tools) > 0:
|
if len(tools) > 0:
|
||||||
print 'The following individual tools exist:'
|
print 'The following individual tools exist:'
|
||||||
for tool in tools:
|
for tool in tools:
|
||||||
|
if tool.is_old and not show_old:
|
||||||
|
continue
|
||||||
if tool.can_be_installed() == True:
|
if tool.can_be_installed() == True:
|
||||||
installed = '\tINSTALLED' if tool.is_installed() else ''
|
installed = '\tINSTALLED' if tool.is_installed() else ''
|
||||||
else:
|
else:
|
||||||
@@ -963,7 +984,7 @@ def main():
|
|||||||
tool = find_tool(sys.argv[i])
|
tool = find_tool(sys.argv[i])
|
||||||
tools_to_activate += [tool]
|
tools_to_activate += [tool]
|
||||||
|
|
||||||
print path_additions(tools_to_activate)
|
print adjusted_path(tools_to_activate)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
elif cmd == 'construct_env':
|
elif cmd == 'construct_env':
|
||||||
@@ -988,6 +1009,10 @@ def main():
|
|||||||
return 1
|
return 1
|
||||||
tools_to_activate += [tool]
|
tools_to_activate += [tool]
|
||||||
set_active_tools(tools_to_activate)
|
set_active_tools(tools_to_activate)
|
||||||
|
|
||||||
|
if WINDOWS:
|
||||||
|
env_string = construct_env(tools_to_activate, False)
|
||||||
|
open('emsdk_set_env.bat', 'w').write(env_string)
|
||||||
return 0
|
return 0
|
||||||
elif cmd == 'install':
|
elif cmd == 'install':
|
||||||
if len(sys.argv) <= 2:
|
if len(sys.argv) <= 2:
|
||||||
@@ -1010,7 +1035,7 @@ def main():
|
|||||||
return 1
|
return 1
|
||||||
tool.uninstall()
|
tool.uninstall()
|
||||||
else:
|
else:
|
||||||
print "Unknown command '" + cmd + "' given!"
|
print "Unknown command '" + cmd + "' given! Type 'emsdk help' to get a list of commands."
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -30,3 +30,11 @@
|
|||||||
@set EMSDK_PY=
|
@set EMSDK_PY=
|
||||||
@set PATH=%PREVPATH%
|
@set PATH=%PREVPATH%
|
||||||
@set PREVPATH=
|
@set PREVPATH=
|
||||||
|
|
||||||
|
:: python is not able to set environment variables to the parent calling process, so
|
||||||
|
:: therefore have it craft a .bat file, which we invoke after finishing python execution,
|
||||||
|
:: to set up the environment variables
|
||||||
|
@IF EXIST emsdk_set_env.bat (
|
||||||
|
@CALL emsdk_set_env.bat > NUL
|
||||||
|
@DEL /F /Q emsdk_set_env.bat
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user