Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace update_bazel_workspace.sh with a python script #1271

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bazel/revisions.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is automatically updated by emsdk/scripts/update_bazel_workspace.sh
# This file is automatically updated by emsdk/scripts/update_bazel_workspace.py
# DO NOT MODIFY

EMSCRIPTEN_TAGS = {
Expand Down
4 changes: 3 additions & 1 deletion scripts/create_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def main(args):
f.write(json.dumps(release_info, indent=2))
f.write('\n')

subprocess.check_call([os.path.join(script_dir, 'update_bazel_workspace.sh')], cwd=root_dir)
subprocess.check_call(
[sys.executable, os.path.join(script_dir, 'update_bazel_workspace.py')],
cwd=root_dir)

branch_name = 'version_' + new_version

Expand Down
69 changes: 69 additions & 0 deletions scripts/update_bazel_workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
# This script will update emsdk/bazel/revisons.bzl to the latest version of
# emscripten. It reads emsdk/emscripten-releases-tags.json to get the latest
# version number. Then, it downloads the prebuilts for that version and computes
# the sha256sum for the archive. It then puts all this information into the
# emsdk/bazel/revisions.bzl file.

import hashlib
import json
import os
import requests
import sys

STORAGE_URL = 'https://storage.googleapis.com/webassembly/emscripten-releases-builds'

EMSDK_ROOT = os.path.dirname(os.path.dirname(__file__))
RELEASES_TAGS_FILE = EMSDK_ROOT + '/emscripten-releases-tags.json'
BAZEL_REVISIONS_FILE = EMSDK_ROOT + '/bazel/revisions.bzl'


def get_latest_info():
with open(RELEASES_TAGS_FILE) as f:
info = json.load(f)
latest = info['aliases']['latest']
return latest, info['releases'][latest]


def get_sha(platform, archive_fmt, latest_hash, arch_suffix=''):
r = requests.get(f'{STORAGE_URL}/{platform}/{latest_hash}/wasm-binaries{arch_suffix}.{archive_fmt}')
r.raise_for_status()
print(f'Fetching {r.url}')
h = hashlib.new('sha256')
for chunk in r.iter_content(chunk_size=1024):
h.update(chunk)
return h.hexdigest()


def revisions_item(version, latest_hash):
return f'''\
"{version}": struct(
hash = "{latest_hash}",
sha_linux = "{get_sha('linux', 'tbz2', latest_hash)}",
sha_mac = "{get_sha('mac', 'tbz2', latest_hash)}",
sha_mac_arm64 = "{get_sha('mac', 'tbz2', latest_hash, '-arm64')}",
sha_win = "{get_sha('win', 'zip', latest_hash)}",
),
'''


def insert_revision(item):
with open(BAZEL_REVISIONS_FILE, 'r') as f:
lines = f.readlines()

lines.insert(lines.index('EMSCRIPTEN_TAGS = {\n') + 1, item)

with open(BAZEL_REVISIONS_FILE, 'w') as f:
f.write(''.join(lines))


def main(argv):
version, latest_hash = get_latest_info()
item = revisions_item(version, latest_hash)
print('inserting item:')
print(item)
insert_revision(item)


if __name__ == '__main__':
sys.exit(main(sys.argv))
73 changes: 0 additions & 73 deletions scripts/update_bazel_workspace.sh

This file was deleted.

2 changes: 1 addition & 1 deletion test/test_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ HASH=$(grep "\"${VER}\"" emscripten-releases-tags.json \
| grep -v latest \
| cut -f4 -d\")

FAILMSG="!!! scripts/update_bazel_toolchain.sh needs to be run !!!"
FAILMSG="!!! scripts/update_bazel_workspace.py needs to be run !!!"

# Ensure the WORKSPACE file is up to date with the latest version.
grep ${VER} bazel/revisions.bzl || (echo ${FAILMSG} && false)
Expand Down
2 changes: 1 addition & 1 deletion test/test_bazel_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ HASH=$(grep "\"${VER}\"" emscripten-releases-tags.json \
| grep -v latest \
| cut -f4 -d\")

FAILMSG="!!! scripts/update_bazel_toolchain.sh needs to be run !!!"
FAILMSG="!!! scripts/update_bazel_workspace.py needs to be run !!!"

# Ensure the WORKSPACE file is up to date with the latest version.
grep ${VER} bazel/revisions.bzl || (echo ${FAILMSG} && false)
Expand Down