MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / generate_config

Function generate_config

tools/config.py:172–207  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

170
171
172def generate_config(path):
173 if os.path.exists(path):
174 exit_with_error(f'config file already exists: `{path}`')
175
176 # Note: repr is used to ensure the paths are escaped correctly on Windows.
177 # The full string is replaced so that the template stays valid Python.
178
179 config_data = utils.read_file(path_from_root('tools/config_template.py'))
180 config_data = config_data.splitlines()[3:] # remove the initial comment
181 config_data = '\n'.join(config_data) + '\n'
182 # autodetect some default paths
183 llvm_root = os.path.dirname(shutil.which('wasm-ld') or '/usr/bin/wasm-ld')
184 config_data = config_data.replace("'{{{ LLVM_ROOT }}}'", repr(llvm_root))
185
186 binaryen_root = os.path.dirname(os.path.dirname(shutil.which('wasm-opt') or '/usr/local/bin/wasm-opt'))
187 config_data = config_data.replace("'{{{ BINARYEN_ROOT }}}'", repr(binaryen_root))
188
189 node = shutil.which('node') or shutil.which('nodejs') or 'node'
190 config_data = config_data.replace("'{{{ NODE }}}'", repr(node))
191
192 # write
193 utils.write_file(path, config_data)
194
195 print('''\
196An Emscripten settings file has been generated at:
197
198 %s
199
200It contains our best guesses for the important paths, which are:
201
202 LLVM_ROOT = %s
203 BINARYEN_ROOT = %s
204 NODE_JS = %s
205
206Please edit the file if any of those are incorrect.\
207''' % (path, llvm_root, binaryen_root, node), file=sys.stderr)
208
209
210def find_config_file():

Callers 1

initFunction · 0.85

Calls 6

exit_with_errorFunction · 0.85
path_from_rootFunction · 0.85
existsMethod · 0.80
write_fileMethod · 0.80
printFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected