Use a wrapper script for running emsdk.py (#292)
This change moves the python code for emsdk into a file ending in .py. This script is then run via emsdk.bat on windows or emsdk (a shell script) on non-windows. This avoid the #!/bin/sh at the top of the python script and the "exec" hack on the first line that re-runs it under python. Hopefully this preserves the intent of #273 without jumping through so many hoops.
This commit is contained in:
2
.flake8
2
.flake8
@@ -1,3 +1,3 @@
|
||||
[flake8]
|
||||
ignore = E111,E114,E501,E261,E266,E121,E402,E241,E701
|
||||
filename = emsdk
|
||||
filename = emsdk.py
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
@SET EMSDK_PY=python
|
||||
|
||||
:end
|
||||
@call %EMSDK_PY% "%~dp0\emsdk" %*
|
||||
@call %EMSDK_PY% "%~dp0\emsdk.py" %*
|
||||
|
||||
@set EMSDK_PY=
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright 2019 The Emscripten Authors. All rights reserved.
|
||||
# Emscripten is available under two separate licenses, the MIT license and the
|
||||
# University of Illinois/NCSA Open Source License. Both these licenses can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
"""Provides a way to run a script on the preferred Python version"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def which(program):
|
||||
for path in [""] + os.environ.get("PATH", "").split(os.pathsep):
|
||||
exe_file = os.path.join(path, program)
|
||||
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
|
||||
# in case of pyenv we might have `python3` command available, but it's just a stub
|
||||
# https://github.com/emscripten-core/emscripten/issues/8792
|
||||
p = subprocess.Popen([exe_file, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
p.communicate()
|
||||
if p.returncode == 0:
|
||||
return exe_file
|
||||
return None
|
||||
|
||||
# Look for the best choice for python, favours Python3 over Python2
|
||||
# In case of Windows it uses always python that was used for this script
|
||||
if sys.platform in ["linux", "linux2", "darwin"]:
|
||||
python = which("python3") or which("python") or sys.executable
|
||||
else:
|
||||
python = sys.executable
|
||||
|
||||
sys.exit(subprocess.call([python] + sys.argv[1:]))
|
||||
4
test.py
4
test.py
@@ -33,7 +33,7 @@ def failing_call_with_output(cmd, expected):
|
||||
assert expected in stdout, 'call did not have the right output'
|
||||
|
||||
def hack_emsdk(marker, replacement):
|
||||
src = open('emsdk').read()
|
||||
src = open('emsdk.py').read()
|
||||
assert marker in src
|
||||
src = src.replace(marker, replacement)
|
||||
name = '__test_emsdk'
|
||||
@@ -89,7 +89,7 @@ print('update')
|
||||
check_call('./emsdk update-tags')
|
||||
|
||||
print('test latest-releases-upstream')
|
||||
check_call('python2 ./emsdk install latest-upstream')
|
||||
check_call('python2 ./emsdk.py install latest-upstream')
|
||||
check_call('./emsdk activate latest-upstream')
|
||||
test_lib_building('upstream', use_asmjs_optimizer=False)
|
||||
assert open(os.path.expanduser('~/.emscripten')).read().count('LLVM_ROOT') == 1
|
||||
|
||||
Reference in New Issue
Block a user