Skip to content

Commit e28fb3f

Browse files
authored
Add (optional) post-commit git hook for running bootstrap script (#22632)
Once installed this script will automatically bootstrap emscripten on each branch checkout. Use `./bootstrap -i/--install-post-checkout` to install the script. We could consider doing this automatically too as a followup if folks end up liking this solution. Fixes: #22550
1 parent 0aa6ad4 commit e28fb3f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

bootstrap.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,21 @@ def main(args):
5757
parser = argparse.ArgumentParser(description=__doc__)
5858
parser.add_argument('-v', '--verbose', action='store_true', help='verbose', default=False)
5959
parser.add_argument('-n', '--dry-run', action='store_true', help='dry run', default=False)
60+
parser.add_argument('-i', '--install-post-checkout', action='store_true', help='install post checkout script', default=False)
6061
args = parser.parse_args()
6162

63+
if args.install_post_checkout:
64+
if not os.path.exists(utils.path_from_root('.git')):
65+
print('--install-post-checkout requires git checkout')
66+
return 1
67+
68+
src = utils.path_from_root('tools/maint/post-checkout')
69+
dst = utils.path_from_root('.git/hooks')
70+
if not os.path.exists(dst):
71+
os.mkdir(dst)
72+
shutil.copy(src, dst)
73+
return 0
74+
6275
for name, deps, cmd in actions:
6376
if check_deps(name, deps):
6477
print('Up-to-date: %s' % name)
@@ -67,11 +80,12 @@ def main(args):
6780
stamp_file = get_stamp_file(name)
6881
if args.dry_run:
6982
print(' (skipping: dry run) -> %s' % ' '.join(cmd))
70-
return
83+
continue
7184
print(' -> %s' % ' '.join(cmd))
7285
shared.run_process(cmd, cwd=utils.path_from_root())
7386
utils.safe_ensure_dirs(STAMP_DIR)
7487
utils.write_file(stamp_file, 'Timestamp file created by bootstrap.py')
88+
return 0
7589

7690

7791
if __name__ == '__main__':

tools/maint/post-checkout

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# Git post-checkout script that takes care of running emscirpten's
4+
# bootstrap script when changing branches.
5+
#
6+
# The bootstrap script itself is smart enough to basically do nothing unless
7+
# one of the relevant files was updated (e.g. package.json).
8+
9+
# Test for the existence of the bootstrap script itself to handle branches
10+
# that predate its existence.
11+
test -f ./bootstrap && exec ./bootstrap

0 commit comments

Comments
 (0)