|
5 | 5 |
|
6 | 6 | import glob |
7 | 7 | import os |
| 8 | +import platform |
8 | 9 | import re |
9 | 10 | import shutil |
10 | 11 | import stat |
| 12 | +import tempfile |
11 | 13 | import time |
12 | 14 | from pathlib import Path |
13 | 15 | from subprocess import PIPE, STDOUT |
14 | 16 |
|
| 17 | +import common |
15 | 18 | from common import ( |
16 | 19 | EMBUILDER, |
17 | 20 | RunnerCore, |
@@ -177,31 +180,32 @@ def test_aaa_normal(self): |
177 | 180 |
|
178 | 181 | @with_env_modify({'EM_CONFIG': None}) |
179 | 182 | def test_firstrun(self): |
180 | | - default_config = EM_CONFIG |
| 183 | + default_config = path_from_root('.emscripten') |
181 | 184 | output = self.do([EMCC, '-v']) |
182 | 185 | self.assertContained('emcc: warning: config file not found: %s. You can create one by hand or run `emcc --generate-config`' % default_config, output) |
183 | 186 |
|
184 | | - temp_bin = os.path.abspath('bin') |
185 | | - os.mkdir(temp_bin) |
186 | | - |
187 | | - def make_new_executable(name): |
188 | | - utils.write_file(os.path.join(temp_bin, name), '') |
189 | | - make_executable(os.path.join(temp_bin, name)) |
| 187 | + try: |
| 188 | + temp_bin = tempfile.mkdtemp() |
190 | 189 |
|
191 | | - make_new_executable('wasm-ld') |
192 | | - make_new_executable('node') |
| 190 | + def make_new_executable(name): |
| 191 | + utils.write_file(os.path.join(temp_bin, name), '') |
| 192 | + make_executable(os.path.join(temp_bin, name)) |
193 | 193 |
|
194 | | - with env_modify({'PATH': temp_bin + os.pathsep + os.environ['PATH']}): |
195 | | - output = self.do([EMCC, '--generate-config']) |
| 194 | + make_new_executable('wasm-ld') |
| 195 | + make_new_executable('node') |
196 | 196 |
|
197 | | - config_data = utils.read_file(default_config) |
| 197 | + with env_modify({'PATH': temp_bin + os.pathsep + os.environ['PATH']}): |
| 198 | + output = self.do([EMCC, '--generate-config']) |
| 199 | + finally: |
| 200 | + shutil.rmtree(temp_bin) |
| 201 | + config_data = utils.read_file(default_config) |
198 | 202 |
|
199 | 203 | self.assertContained('An Emscripten settings file has been generated at:', output) |
200 | 204 | self.assertContained(default_config, output) |
201 | 205 | self.assertContained('It contains our best guesses for the important paths, which are:', output) |
202 | 206 | self.assertContained('LLVM_ROOT', output) |
203 | 207 | self.assertContained('NODE_JS', output) |
204 | | - if not utils.WINDOWS: |
| 208 | + if platform.system() != 'Windows': |
205 | 209 | # os.chmod can't make files executable on Windows |
206 | 210 | self.assertIdentical(temp_bin, re.search("^ *LLVM_ROOT *= (.*)$", output, re.M).group(1)) |
207 | 211 | possible_nodes = [os.path.join(temp_bin, 'node')] |
@@ -520,13 +524,29 @@ def test_emcc_cache_flag(self, use_response_files, relative): |
520 | 524 |
|
521 | 525 | def test_emconfig(self): |
522 | 526 | restore_and_set_up() |
523 | | - create_file('custom_config', get_basic_config()) |
| 527 | + |
| 528 | + fd, custom_config_filename = tempfile.mkstemp(prefix='.emscripten_config_') |
| 529 | + |
| 530 | + orig_config = utils.read_file(EM_CONFIG) |
| 531 | + |
| 532 | + # Move the ~/.emscripten to a custom location. |
| 533 | + with os.fdopen(fd, "w") as f: |
| 534 | + f.write(get_basic_config()) |
524 | 535 |
|
525 | 536 | # Make a syntax error in the original config file so that attempting to access it would fail. |
526 | | - utils.write_file(EM_CONFIG, 'asdfasdfasdfasdf\n') |
| 537 | + utils.write_file(EM_CONFIG, 'asdfasdfasdfasdf\n\'\'\'' + orig_config) |
| 538 | + |
| 539 | + temp_dir = tempfile.mkdtemp(prefix='emscripten_temp_') |
| 540 | + |
| 541 | + with common.chdir(temp_dir): |
| 542 | + self.run_process([EMCC, '--em-config', custom_config_filename] + MINIMAL_HELLO_WORLD + ['-O2']) |
| 543 | + result = self.run_js('a.out.js') |
| 544 | + |
| 545 | + self.assertContained('hello, world!', result) |
527 | 546 |
|
528 | | - self.run_process([EMCC, '--em-config', 'custom_config'] + MINIMAL_HELLO_WORLD) |
529 | | - self.assertContained('hello, world!', self.run_js('a.out.js')) |
| 547 | + # Clean up created temp files. |
| 548 | + os.remove(custom_config_filename) |
| 549 | + shutil.rmtree(temp_dir) |
530 | 550 |
|
531 | 551 | def test_emcc_ports(self): |
532 | 552 | restore_and_set_up() |
|
0 commit comments