forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
bootstrap.py
script which takes care of post-checkout tasks (em…
…scripten-core#19736) This script is only present is git checkout of emscripten and not in emsdk or other packaged versions. When run with no arguments this script ensures that all the post-checkout steps required by emscripten have been run and are up-to-date with the current checkout. It does this by comparing `.stamp` files in the `out` directory with the timestamps of inputs files such as `package.json`. When `emcc` is run, and bootstrap.py is present it is run in `check` mode which will cause the compiler to error if the one or more of the bootstrap commands needs to be run (e.g. if package.json was modified).
- Loading branch information
Showing
11 changed files
with
242 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
# Copyright 2020 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. | ||
# | ||
# Entry point for running python scripts on UNIX systems. | ||
# | ||
# Automatically generated by `create_entry_points.py`; DO NOT EDIT. | ||
# | ||
# To make modifications to this file, edit `tools/run_python.sh` and then run | ||
# `tools/maint/create_entry_points.py` | ||
|
||
# $PYTHON -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal | ||
# of cpython used in cross compilation via setup.py. | ||
unset _PYTHON_SYSCONFIGDATA_NAME | ||
|
||
if [ -z "$PYTHON" ]; then | ||
PYTHON=$EMSDK_PYTHON | ||
fi | ||
|
||
if [ -z "$PYTHON" ]; then | ||
PYTHON=$(command -v python3 2> /dev/null) | ||
fi | ||
|
||
if [ -z "$PYTHON" ]; then | ||
PYTHON=$(command -v python 2> /dev/null) | ||
fi | ||
|
||
if [ -z "$PYTHON" ]; then | ||
echo 'unable to find python in $PATH' | ||
exit 1 | ||
fi | ||
|
||
exec "$PYTHON" -E "$0.py" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
:: Entry point for running python scripts on windows systems. | ||
:: | ||
:: Automatically generated by `create_entry_points.py`; DO NOT EDIT. | ||
:: | ||
:: To make modifications to this file, edit `tools/run_python.bat` and then run | ||
:: `tools/maint/create_entry_points.py` | ||
|
||
:: N.b. In Windows .bat scripts, the ':' character cannot appear inside any if () blocks, | ||
:: or there will be a parsing error. | ||
|
||
:: All env. vars specified in this file are to be local only to this script. | ||
@setlocal | ||
:: -E will not ignore _PYTHON_SYSCONFIGDATA_NAME an internal | ||
:: of cpython used in cross compilation via setup.py. | ||
@set _PYTHON_SYSCONFIGDATA_NAME= | ||
@set EM_PY=%EMSDK_PYTHON% | ||
@if "%EM_PY%"=="" ( | ||
set EM_PY=python | ||
) | ||
|
||
:: Work around Windows bug https://github.com/microsoft/terminal/issues/15212 : If this | ||
:: script is invoked via enclosing the invocation in quotes via PATH lookup, then %~f0 and | ||
:: %~dp0 expansions will not work. | ||
:: So first try if %~dp0 might work, and if not, manually look up this script from PATH. | ||
@if exist %~f0 ( | ||
set MYDIR=%~dp0 | ||
goto FOUND_MYDIR | ||
) | ||
@for %%I in (%~n0.bat) do ( | ||
@if exist %%~$PATH:I ( | ||
set MYDIR=%%~dp$PATH:I | ||
) else ( | ||
echo Fatal Error! Due to a Windows bug, we are unable to locate the path to %~n0.bat. | ||
echo To help this issue, try removing unnecessary quotes in the invocation of emcc, | ||
echo or add Emscripten directory to PATH. | ||
echo See github.com/microsoft/terminal/issues/15212 and | ||
echo github.com/emscripten-core/emscripten/issues/19207 for more details. | ||
) | ||
) | ||
:FOUND_MYDIR | ||
|
||
:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a | ||
:: shared stdin handle from the parent process, and that parent process stdin handle is in | ||
:: a certain state, running python.exe might hang here. To work around this, if | ||
:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid | ||
:: sharing the parent's stdin handle to it, avoiding the hang. | ||
|
||
:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel, | ||
:: even when the python executable above did succeed and quit with errorlevel 0 above. | ||
:: On Windows 8 and newer, this issue has not been observed. It is possible that this | ||
:: issue is related to the above python bug, but this has not been conclusively confirmed, | ||
:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known | ||
:: workaround this issue, which is to explicitly quit the calling process with the previous | ||
:: errorlevel from the above command. | ||
|
||
:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from | ||
:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that | ||
:: would throw off the parsing of the cmdline arg. | ||
@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" ( | ||
@if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( | ||
goto NORMAL | ||
) else ( | ||
goto NORMAL_EXIT | ||
) | ||
) else ( | ||
@if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" ( | ||
goto MUTE_STDIN | ||
) else ( | ||
goto MUTE_STDIN_EXIT | ||
) | ||
) | ||
|
||
:NORMAL_EXIT | ||
@"%EM_PY%" -E "%MYDIR%%~n0.py" %* | ||
@exit %ERRORLEVEL% | ||
|
||
:MUTE_STDIN | ||
@"%EM_PY%" -E "%MYDIR%%~n0.py" %* < NUL | ||
@exit /b %ERRORLEVEL% | ||
|
||
:MUTE_STDIN_EXIT | ||
@"%EM_PY%" -E "%MYDIR%%~n0.py" %* < NUL | ||
@exit %ERRORLEVEL% | ||
|
||
:NORMAL | ||
@"%EM_PY%" -E "%MYDIR%%~n0.py" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python3 | ||
"""Bootstrap script for emscripten developers / git users. | ||
After checking out emscripten there are certain steps that need to be | ||
taken before it can be used. This script enumerates and automates | ||
these steps and is able to run just the steps that are needed based | ||
on the timestamps of various input files (kind of like a dumb version | ||
of a Makefile). | ||
""" | ||
import argparse | ||
import os | ||
import shutil | ||
import sys | ||
|
||
__rootdir__ = os.path.dirname(os.path.abspath(__file__)) | ||
sys.path.insert(0, __rootdir__) | ||
|
||
STAMP_DIR = os.path.join(__rootdir__, 'out') | ||
|
||
from tools import shared, utils | ||
|
||
actions = [ | ||
('npm packages', 'package.json', [shutil.which('npm'), 'ci']), | ||
# TODO(sbc): Remove the checked in entry point files and have them | ||
# built on demand by this step. | ||
('create entry points', 'tools/maint/create_entry_points.py', [sys.executable, 'tools/maint/create_entry_points.py']), | ||
('git submodules', 'test/third_party/posixtestsuite/', [shutil.which('git'), 'submodule', 'update', '--init']), | ||
] | ||
|
||
|
||
def get_stamp_file(action_name): | ||
return os.path.join(STAMP_DIR, action_name.replace(' ', '_') + '.stamp') | ||
|
||
|
||
def check(): | ||
for name, filename, _ in actions: | ||
stamp_file = get_stamp_file(name) | ||
filename = utils.path_from_root(filename) | ||
if not os.path.exists(stamp_file) or os.path.getmtime(filename) > os.path.getmtime(stamp_file): | ||
utils.exit_with_error(f'emscripten setup is not complete ("{name}" is out-of-date). Run bootstrap.py to update') | ||
|
||
|
||
def main(args): | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument('-v', '--verbose', action='store_true', help='verbose', default=False) | ||
parser.add_argument('-n', '--dry-run', action='store_true', help='dry run', default=False) | ||
args = parser.parse_args() | ||
|
||
for name, filename, cmd in actions: | ||
stamp_file = get_stamp_file(name) | ||
filename = utils.path_from_root(filename) | ||
if os.path.exists(stamp_file) and os.path.getmtime(filename) <= os.path.getmtime(stamp_file): | ||
print('Up-to-date: %s' % name) | ||
continue | ||
print('Out-of-date: %s' % name) | ||
if args.dry_run: | ||
print(' (skipping: dry run) -> %s' % ' '.join(cmd)) | ||
return | ||
print(' -> %s' % ' '.join(cmd)) | ||
shared.run_process(cmd, cwd=utils.path_from_root()) | ||
utils.safe_ensure_dirs(STAMP_DIR) | ||
utils.write_file(stamp_file, 'Timestamp file created by bootstrap.py') | ||
|
||
|
||
if __name__ == '__main__': | ||
main(sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
'''.split() | ||
|
||
entry_points = ''' | ||
bootstrap | ||
emar | ||
embuilder | ||
emcmake | ||
|