Skip to content

Commit b9bfdbc

Browse files
authored
Remove EMSCRIPTEN_ROOT from config file (emscripten-core#7254)
This was previously used by external tools to find emscripten. A better way to do that is to look for `emcc` in PATH or check for EMSCRIPTEN_ROOT in the environment. Hopefully once we are the only parser of our config file we can nail it down a little and remove the `exec`. As well as being cleaner this will also allow the config file to know where it is via __file__ which allows for the config to include relative paths(useful for installing toolchains with fix local config files).
1 parent 914cb76 commit b9bfdbc

File tree

8 files changed

+27
-47
lines changed

8 files changed

+27
-47
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252
# persistent workspace and to avoid any confusion with that version
5353
# we are trying to test.
5454
rm -r ~/emsdk-master/emscripten/
55-
echo EMSCRIPTEN_ROOT="'~/emscripten/'" >> ~/.emscripten
5655
echo BINARYEN_ROOT="''" >> ~/.emscripten
5756
- run:
5857
name: embuilder build ALL

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ RUN cd /root/ \
1515
&& ./emsdk install latest \
1616
&& ./emsdk activate latest \
1717
&& popd \
18-
&& echo EMSCRIPTEN_ROOT="'/root/emscripten/'" >> .emscripten \
1918
&& echo BINARYEN_ROOT="''" >> .emscripten
2019

2120
ARG TEST_TARGET

site/source/docs/building_from_source/configuring_emscripten_settings.rst

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The settings file is created the first time a user runs :ref:`emcc <emccdoc>` (o
2727
You should get a ``Welcome to Emscripten!`` message. Behind the scenes, Emscripten generates a file called ``.emscripten`` in your home folder.
2828

2929

30-
Emscripten makes a "best guess" at the correct locations for tools and updates the file appropriately. Where possible it will look for "system" apps (like Python and Java) and infer the location of the ``EMSCRIPTEN_ROOT`` (where :ref:`emcc <emccdoc>` is located) from the location of the command prompt.
30+
Emscripten makes a "best guess" at the correct locations for tools and updates the file appropriately. Where possible it will look for "system" apps (like Python and Java).
3131

3232
The file will probably not include the link to :term:`Fastcomp` (``LLVM_ROOT``) as a manual source build can create this anywhere.
3333

@@ -49,9 +49,9 @@ Compiler configuration file-format
4949

5050
.. note:: While the syntax is identical, the appearance of the default **.emscripten** file created by *emcc* is quite different than that created by :ref:`emsdk <compiler-configuration-file>`. This is because *emsdk* manages multiple target environments, and where possible hard codes the locations of those tools when a new environment is activated. The default file, by contrast, is managed by the user — and is designed to make that task as easy as possible.
5151

52-
The file simply assigns paths to a number of *variables* representing the main tools used by Emscripten. For example, if the user cloned Emscripten to the **C:/Users/username/Documents/GitHub/emscripten** directory, then the file would have the line: ::
52+
The file simply assigns paths to a number of *variables* representing the main tools used by Emscripten. For example, if the user installed python to the **C:/Python27/** directory, then the file might have the line: ::
5353

54-
EMSCRIPTEN_ROOT = 'C:/Users/username/Documents/GitHub/emscripten'
54+
PTYHON = 'C:\\Python27\\python2.exe'
5555
5656

5757
The default *emcc* configuration file often gets the paths from environment variables if defined. If no variable is defined the system will also attempt to find "system executables". For example: ::
@@ -76,13 +76,6 @@ The compiler configuration file can be edited with the text editor of your choic
7676

7777
#. Edit the variable ``TEMP_DIR`` to point to a valid path on your local system, e.g. ``TEMP_DIR = '/tmp'`` (``TEMP_DIR = 'c:/tmp'`` on Windows), and create that folder on the local filesystem if it doesn't exist.
7878

79-
#. You *may* need to edit the variable ``EMSCRIPTEN_ROOT`` to point to the Emscripten root folder, e.g.:
80-
81-
::
82-
83-
EMSCRIPTEN_ROOT = os.path.expanduser(os.getenv('EMSCRIPTEN', '/home/ubuntu/yourpath/emscripten')) # directory
84-
85-
8679
.. comment .. The settings are now correct in the configuration file, but the paths and environment variables are not set in the command prompt/terminal. **HamishW** Follow up with Jukka on this.
8780
8881
After setting those paths, run ``emcc`` again. It should again perform the sanity checks to test the specified paths. There are further validation tests available at :ref:`verifying-the-emscripten-environment`.

site/source/docs/tools_reference/emsdk.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ Below are typical **.emscripten** files created by *emsdk*. Note the variable na
9797
LLVM_ROOT='C:/Program Files/Emscripten/clang/e1.21.0_64bit'
9898
NODE_JS='C:/Program Files/Emscripten/node/0.10.17_64bit/node.exe'
9999
PYTHON='C:/Program Files/Emscripten/python/2.7.5.3_64bit/python.exe'
100-
EMSCRIPTEN_ROOT='C:/Program Files/Emscripten/emscripten/1.21.0'
101100
JAVA='C:/Program Files/Emscripten/java/7.45_64bit/bin/java.exe'
102101
V8_ENGINE = ''
103102
TEMP_DIR = 'c:/users/hamis_~1/appdata/local/temp'
@@ -113,7 +112,6 @@ Below are typical **.emscripten** files created by *emsdk*. Note the variable na
113112
SPIDERMONKEY_ENGINE = ''
114113
NODE_JS = 'nodejs'
115114
LLVM_ROOT='/home/ubuntu/emsdk_portable/clang/fastcomp/build_incoming_64/bin'
116-
EMSCRIPTEN_ROOT='/home/ubuntu/emsdk_portable/emscripten/incoming'
117115
V8_ENGINE = ''
118116
TEMP_DIR = '/tmp'
119117
COMPILER_ENGINE = NODE_JS

tests/test_other.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ def test_emcc_generate_config(self):
108108
run_process([PYTHON, compiler, '--generate-config', config_path])
109109
assert os.path.exists(config_path), 'A config file should have been created at %s' % config_path
110110
config_contents = open(config_path).read()
111-
self.assertContained('EMSCRIPTEN_ROOT', config_contents)
112111
self.assertContained('LLVM_ROOT', config_contents)
113112
os.remove(config_path)
114113

tests/test_sanity.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def make_executable(name):
169169
self.assertNotContained('}}}', config_file)
170170
self.assertContained('{{{', template_file)
171171
self.assertContained('}}}', template_file)
172-
for content in ['EMSCRIPTEN_ROOT', 'LLVM_ROOT', 'NODE_JS', 'TEMP_DIR', 'COMPILER_ENGINE', 'JS_ENGINES']:
172+
for content in ['LLVM_ROOT', 'NODE_JS', 'TEMP_DIR', 'COMPILER_ENGINE', 'JS_ENGINES']:
173173
self.assertContained(content, config_file)
174174

175175
# The guessed config should be ok
@@ -258,17 +258,6 @@ def test_llvm(self):
258258
output = self.check_working(EMCC)
259259
assert LLVM_WARNING not in output, output
260260

261-
def test_emscripten_root(self):
262-
# The correct path
263-
restore_and_set_up()
264-
add_to_config("EMSCRIPTEN_ROOT = '%s'" % path_from_root())
265-
self.check_working(EMCC)
266-
267-
# The correct path with extra stuff
268-
restore_and_set_up()
269-
add_to_config("EMSCRIPTEN_ROOT = '%s'" % (path_from_root() + os.path.sep))
270-
self.check_working(EMCC)
271-
272261
def test_llvm_fastcomp(self):
273262
WARNING = 'fastcomp in use, but LLVM has not been built with the JavaScript backend as a target'
274263
WARNING2 = 'you can fall back to the older (pre-fastcomp) compiler core, although that is not recommended, see http://kripken.github.io/emscripten-site/docs/building_from_source/LLVM-Backend.html'

tools/settings_template_readonly.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
# This file will be edited (the {{{ }}} things), and then ~/.emscripten created with the result, if ~/.emscripten doesn't exist.
1+
# This file will be edited (the {{{ }}} things), and then ~/.emscripten created
2+
# with the result, if ~/.emscripten doesn't exist.
23

3-
# Note: If you put paths relative to the home directory, do not forget os.path.expanduser
4+
# Note: If you put paths relative to the home directory, do not forget
5+
# os.path.expanduser
46

5-
# Note: On Windows, remember to escape backslashes! I.e. EMSCRIPTEN_ROOT='c:\emscripten\' is not valid, but EMSCRIPTEN_ROOT='c:\\emscripten\\' and EMSCRIPTEN_ROOT='c:/emscripten/' are.
7+
# Note: On Windows, remember to escape backslashes! I.e. PYTHON='c:\Python27\'
8+
# is not valid, but PYTHON='c:\\Python27\\' and PYTHON='c:/Python27/'
9+
# are.
610

711
import os
812

9-
# this helps projects using emscripten find it
10-
EMSCRIPTEN_ROOT = os.path.expanduser(os.getenv('EMSCRIPTEN', '{{{ EMSCRIPTEN_ROOT }}}')) # directory
1113
LLVM_ROOT = os.path.expanduser(os.getenv('LLVM', '{{{ LLVM_ROOT }}}')) # directory
1214
BINARYEN_ROOT = os.path.expanduser(os.getenv('BINARYEN', '')) # if not set, we will use it from ports
1315

1416
# If not specified, defaults to sys.executable.
1517
#PYTHON = 'python'
1618

17-
# Add this if you have manually built the JS optimizer executable (in Emscripten/tools/optimizer) and want to run it from a custom location.
18-
# Alternatively, you can set this as the environment variable EMSCRIPTEN_NATIVE_OPTIMIZER.
19-
# EMSCRIPTEN_NATIVE_OPTIMIZER='/path/to/custom/optimizer(.exe)'
19+
# Add this if you have manually built the JS optimizer executable (in
20+
# Emscripten/tools/optimizer) and want to run it from a custom location.
21+
# Alternatively, you can set this as the environment variable
22+
# EMSCRIPTEN_NATIVE_OPTIMIZER.
23+
#EMSCRIPTEN_NATIVE_OPTIMIZER='/path/to/custom/optimizer(.exe)'
2024

2125
# See below for notes on which JS engine(s) you need
2226
NODE_JS = os.path.expanduser(os.getenv('NODE', '{{{ NODE }}}')) # executable
@@ -29,7 +33,7 @@
2933

3034
#CLOSURE_COMPILER = '..' # define this to not use the bundled version
3135

32-
########################################################################################################
36+
################################################################################
3337

3438

3539
# Pick the JS engine to use for running the compiler. This engine must exist, or
@@ -41,10 +45,11 @@
4145
COMPILER_ENGINE = NODE_JS
4246

4347

44-
# All JS engines to use when running the automatic tests. Not all the engines in this list
45-
# must exist (if they don't, they will be skipped in the test runner).
48+
# All JS engines to use when running the automatic tests. Not all the engines in
49+
# this list must exist (if they don't, they will be skipped in the test runner).
4650
#
47-
# Recommendation: If you already have node installed, use that. If you can, also build
48-
# spidermonkey from source as well to get more test coverage.
51+
# Recommendation: If you already have node installed, use that. If you can, also
52+
# build spidermonkey from source as well to get more test
53+
# coverage.
4954

5055
JS_ENGINES = [NODE_JS] # add this if you have spidermonkey installed too, SPIDERMONKEY_ENGINE]

tools/shared.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ def check_call(cmd, *args, **kw):
175175
def generate_config(path, first_time=False):
176176
# Note: repr is used to ensure the paths are escaped correctly on Windows.
177177
# The full string is replaced so that the template stays valid Python.
178-
config_file = open(path_from_root('tools', 'settings_template_readonly.py')).read().split('\n')
179-
config_file = config_file[1:] # remove "this file will be copied..."
178+
config_file = open(path_from_root('tools', 'settings_template_readonly.py')).read().splitlines()
179+
config_file = config_file[3:] # remove the initial comment
180180
config_file = '\n'.join(config_file)
181181
# autodetect some default paths
182-
config_file = config_file.replace('\'{{{ EMSCRIPTEN_ROOT }}}\'', repr(__rootpath__))
183182
llvm_root = os.path.dirname(find_executable('llvm-dis') or '/usr/bin/llvm-dis')
184183
config_file = config_file.replace('\'{{{ LLVM_ROOT }}}\'', repr(llvm_root))
185184

@@ -207,13 +206,12 @@ def generate_config(path, first_time=False):
207206
208207
LLVM_ROOT = %s
209208
NODE_JS = %s
210-
EMSCRIPTEN_ROOT = %s
211209
212210
Please edit the file if any of those are incorrect.
213211
214212
This command will now exit. When you are done editing those paths, re-run it.
215213
==============================================================================
216-
''' % (path, abspath, llvm_root, node, __rootpath__), file=sys.stderr)
214+
''' % (path, abspath, llvm_root, node), file=sys.stderr)
217215

218216

219217
# Emscripten configuration is done through the --em-config command line option or
@@ -243,9 +241,9 @@ def generate_config(path, first_time=False):
243241

244242
if EM_CONFIG and not os.path.isfile(EM_CONFIG):
245243
if EM_CONFIG.startswith('-'):
246-
raise Exception('Passed --em-config without an argument. Usage: --em-config /path/to/.emscripten or --em-config EMSCRIPTEN_ROOT=/path/;LLVM_ROOT=/path;...')
244+
exit_with_error('Passed --em-config without an argument. Usage: --em-config /path/to/.emscripten or --em-config LLVM_ROOT=/path;...')
247245
if '=' not in EM_CONFIG:
248-
raise Exception('File ' + EM_CONFIG + ' passed to --em-config does not exist!')
246+
exit_with_error('File ' + EM_CONFIG + ' passed to --em-config does not exist!')
249247
else:
250248
EM_CONFIG = EM_CONFIG.replace(';', '\n') + '\n'
251249

0 commit comments

Comments
 (0)