Skip to content

Commit fd08e9a

Browse files
authored
Error (don't just warn) on unknown architecture (#935)
Also, add tests for unknown architecture and wrong bitness and add a mechanism (`EMSDK_ARCH`) to override the architecture assumed by emsdk.
1 parent 95162d5 commit fd08e9a

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

emsdk.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def errlog(msg):
6767
print(msg, file=sys.stderr)
6868

6969

70+
def exit_with_error(msg):
71+
errlog('error: %s' % msg)
72+
sys.exit(1)
73+
74+
7075
MINGW = False
7176
MSYS = False
7277
if os.getenv('MSYSTEM'):
@@ -111,20 +116,18 @@ def errlog(msg):
111116
else:
112117
ENVPATH_SEPARATOR = ':'
113118

114-
ARCH = 'unknown'
115119
# platform.machine() may return AMD64 on windows, so standardize the case.
116-
machine = platform.machine().lower()
120+
machine = os.getenv('EMSDK_ARCH', platform.machine().lower())
117121
if machine.startswith('x64') or machine.startswith('amd64') or machine.startswith('x86_64'):
118122
ARCH = 'x86_64'
119123
elif machine.endswith('86'):
120124
ARCH = 'x86'
121125
elif machine.startswith('aarch64') or machine.lower().startswith('arm64'):
122126
ARCH = 'aarch64'
123-
elif platform.machine().startswith('arm'):
127+
elif machine.startswith('arm'):
124128
ARCH = 'arm'
125129
else:
126-
errlog("Warning: unknown machine architecture " + machine)
127-
errlog()
130+
exit_with_error('unknown machine architecture: ' + machine)
128131

129132
# Don't saturate all cores to not steal the whole system, but be aggressive.
130133
CPU_CORES = int(os.environ.get('EMSDK_NUM_CORES', max(multiprocessing.cpu_count() - 1, 1)))
@@ -2131,8 +2134,7 @@ def find_sdk(name):
21312134

21322135

21332136
def is_os_64bit():
2134-
# http://stackoverflow.com/questions/2208828/detect-64bit-os-windows-in-python
2135-
return platform.machine().endswith('64')
2137+
return ARCH.endswith('64')
21362138

21372139

21382140
def find_latest_version():
@@ -2269,11 +2271,6 @@ def load_file_index_list(filename):
22692271
return sorted(items, key=version_key)
22702272

22712273

2272-
def exit_with_error(msg):
2273-
errlog('error: %s' % msg)
2274-
sys.exit(1)
2275-
2276-
22772274
# Load the json info for emscripten-releases.
22782275
def load_releases_info():
22792276
if not hasattr(load_releases_info, 'cached_info'):

test/test.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None, e
5252

5353
if expected:
5454
for x in listify(expected):
55-
assert x in stdout, 'call had the right output: ' + stdout + '\n[[[' + x + ']]]'
55+
assert x in stdout, 'expected output missing: ' + stdout + '\n[[[' + x + ']]]'
5656
if unexpected:
5757
for x in listify(unexpected):
58-
assert x not in stdout, 'call had the wrong output: ' + stdout + '\n[[[' + x + ']]]'
58+
assert x not in stdout, 'unexpected output present: ' + stdout + '\n[[[' + x + ']]]'
5959

6060

61-
def failing_call_with_output(cmd, expected):
62-
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
61+
def failing_call_with_output(cmd, expected, env=None):
62+
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, env=env)
6363
stdout, stderr = proc.communicate()
6464
if WINDOWS:
6565
print('warning: skipping part of failing_call_with_output() due to error codes not being propagated (see #592)')
@@ -137,6 +137,20 @@ def setUp(self):
137137
run_emsdk('install latest')
138138
run_emsdk('activate latest')
139139

140+
def test_unknown_arch(self):
141+
env = os.environ.copy()
142+
env['EMSDK_ARCH'] = 'mips'
143+
failing_call_with_output(emsdk + ' install latest',
144+
expected='unknown machine architecture: mips',
145+
env=env)
146+
147+
def test_wrong_bitness(self):
148+
env = os.environ.copy()
149+
env['EMSDK_ARCH'] = 'x86'
150+
failing_call_with_output(emsdk + ' install sdk-latest-64bit',
151+
expected='is only provided for 64-bit OSe',
152+
env=env)
153+
140154
def test_already_installed(self):
141155
# Test we don't re-download unnecessarily
142156
checked_call_with_output(emsdk + ' install latest', expected='already installed', unexpected='Downloading:')
@@ -251,11 +265,15 @@ def test_update_no_git(self):
251265
if not filename.startswith('.') and not os.path.isdir(filename):
252266
shutil.copy2(filename, os.path.join(temp_dir, filename))
253267

254-
os.chdir(temp_dir)
255-
run_emsdk('update')
268+
olddir = os.getcwd()
269+
try:
270+
os.chdir(temp_dir)
271+
run_emsdk('update')
256272

257-
print('second time')
258-
run_emsdk('update')
273+
print('second time')
274+
run_emsdk('update')
275+
finally:
276+
os.chdir(olddir)
259277

260278
def test_install_arbitrary(self):
261279
# Test that its possible to install arbrary emscripten-releases SDKs
@@ -278,6 +296,7 @@ def test_keep_downloads(self):
278296
# With EMSDK_KEEP_DOWNLOADS the downloading should happen on the first
279297
# install of 2.0.28, and again when we install 2.0.29, but not on the
280298
# second install of 2.0.28 because the zip should already be local.
299+
shutil.rmtree('zips')
281300
checked_call_with_output(emsdk + ' install 2.0.28', expected='Downloading:', env=env)
282301
checked_call_with_output(emsdk + ' install 2.0.29', expected='Downloading:', env=env)
283302
checked_call_with_output(emsdk + ' install 2.0.28', expected='already downloaded, skipping', unexpected='Downloading:', env=env)

0 commit comments

Comments
 (0)