Skip to content

Commit

Permalink
Add (optional) post-commit git hook for running bootstrap script (#22632
Browse files Browse the repository at this point in the history
)

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
  • Loading branch information
sbc100 authored Sep 26, 2024
1 parent 0aa6ad4 commit e28fb3f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,21 @@ 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)
parser.add_argument('-i', '--install-post-checkout', action='store_true', help='install post checkout script', default=False)
args = parser.parse_args()

if args.install_post_checkout:
if not os.path.exists(utils.path_from_root('.git')):
print('--install-post-checkout requires git checkout')
return 1

src = utils.path_from_root('tools/maint/post-checkout')
dst = utils.path_from_root('.git/hooks')
if not os.path.exists(dst):
os.mkdir(dst)
shutil.copy(src, dst)
return 0

for name, deps, cmd in actions:
if check_deps(name, deps):
print('Up-to-date: %s' % name)
Expand All @@ -67,11 +80,12 @@ def main(args):
stamp_file = get_stamp_file(name)
if args.dry_run:
print(' (skipping: dry run) -> %s' % ' '.join(cmd))
return
continue
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')
return 0


if __name__ == '__main__':
Expand Down
11 changes: 11 additions & 0 deletions tools/maint/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# Git post-checkout script that takes care of running emscirpten's
# bootstrap script when changing branches.
#
# The bootstrap script itself is smart enough to basically do nothing unless
# one of the relevant files was updated (e.g. package.json).

# Test for the existence of the bootstrap script itself to handle branches
# that predate its existence.
test -f ./bootstrap && exec ./bootstrap

0 comments on commit e28fb3f

Please sign in to comment.