Skip to content

Commit 0558e35

Browse files
chore: teach update_cpp_jsonnet.sh to pull a named release version
1 parent cb4d16f commit 0558e35

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

MODULE.bazel

+15-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,28 @@ http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "ht
55
# NB: update_cpp_jsonnet.sh looks for these.
66
CPP_JSONNET_SHA256 = "e7d14d8ad65dc334b9a9f3bd1c542a82b3b80029860a8d78fd829b23d0e9845b"
77
CPP_JSONNET_GITHASH = "5a4e8e34cc1fe841bdebb983646b9b9ae8fa8ca4"
8+
CPP_JSONNET_RELEASE_VERSION = ""
9+
10+
CPP_JSONNET_STRIP_PREFIX = (
11+
"jsonnet-" + (
12+
CPP_JSONNET_RELEASE_VERSION if CPP_JSONNET_RELEASE_VERSION else CPP_JSONNET_GITHASH
13+
)
14+
)
15+
CPP_JSONNET_URL = (
16+
"https://github.com/google/jsonnet/releases/download/%s/jsonnet-%s.tar.gz" % (
17+
CPP_JSONNET_RELEASE_VERSION,
18+
CPP_JSONNET_RELEASE_VERSION,
19+
) if CPP_JSONNET_RELEASE_VERSION else "https://github.com/google/jsonnet/archive/%s.tar.gz" % CPP_JSONNET_GITHASH
20+
)
821

922
# We don't use a normal bazel_dep reference for the cpp_jsonnet module,
1023
# because we want to pin to the specific jsonnet commit (which might not
1124
# even exactly match a released version).
1225
http_archive(
1326
name = "cpp_jsonnet",
1427
sha256 = CPP_JSONNET_SHA256,
15-
strip_prefix = "jsonnet-%s" % CPP_JSONNET_GITHASH,
16-
urls = ["https://github.com/google/jsonnet/archive/%s.tar.gz" % CPP_JSONNET_GITHASH],
28+
strip_prefix = CPP_JSONNET_STRIP_PREFIX,
29+
urls = [CPP_JSONNET_URL],
1730
)
1831

1932
bazel_dep(name = "gazelle", version = "0.41.0", repo_name = "bazel_gazelle")

bazel/repositories.bzl

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ load(
66
# NB: update_cpp_jsonnet.sh looks for these.
77
CPP_JSONNET_SHA256 = "e7d14d8ad65dc334b9a9f3bd1c542a82b3b80029860a8d78fd829b23d0e9845b"
88
CPP_JSONNET_GITHASH = "5a4e8e34cc1fe841bdebb983646b9b9ae8fa8ca4"
9+
CPP_JSONNET_RELEASE_VERSION = ""
10+
11+
CPP_JSONNET_STRIP_PREFIX = (
12+
"jsonnet-" + (
13+
CPP_JSONNET_RELEASE_VERSION if CPP_JSONNET_RELEASE_VERSION else CPP_JSONNET_GITHASH
14+
)
15+
)
16+
CPP_JSONNET_URL = (
17+
"https://github.com/google/jsonnet/releases/download/%s/jsonnet-%s.tar.gz" % (
18+
CPP_JSONNET_RELEASE_VERSION,
19+
CPP_JSONNET_RELEASE_VERSION,
20+
) if CPP_JSONNET_RELEASE_VERSION else "https://github.com/google/jsonnet/archive/%s.tar.gz" % CPP_JSONNET_GITHASH
21+
)
922

1023
def jsonnet_go_repositories():
1124
http_archive(
@@ -28,6 +41,6 @@ def jsonnet_go_repositories():
2841
http_archive(
2942
name = "cpp_jsonnet",
3043
sha256 = CPP_JSONNET_SHA256,
31-
strip_prefix = "jsonnet-%s" % CPP_JSONNET_GITHASH,
32-
urls = ["https://github.com/google/jsonnet/archive/%s.tar.gz" % CPP_JSONNET_GITHASH],
44+
strip_prefix = CPP_JSONNET_STRIP_PREFIX,
45+
urls = [CPP_JSONNET_URL],
3346
)

update_cpp_jsonnet.sh

+21-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,34 @@ set -e
66
set -x
77

88
cd cpp-jsonnet
9-
git checkout master
10-
git pull
11-
hash=$(git rev-parse HEAD)
9+
git remote update --prune
10+
11+
if [[ $# -gt 0 ]]; then
12+
WANT_VERSION_NAME="$1"
13+
WANT_VERSION_REF=refs/tags/"$WANT_VERSION_NAME"
14+
else
15+
WANT_VERSION_NAME=
16+
WANT_VERSION_REF=refs/remotes/origin/master
17+
fi
18+
19+
hash="$(git rev-parse "$WANT_VERSION_REF")"
20+
git checkout "$hash"
21+
22+
if [[ -z "$WANT_VERSION_NAME" ]]; then
23+
ARCHIVE_URL="https://github.com/google/jsonnet/archive/${hash}.tar.gz"
24+
else
25+
ARCHIVE_URL="https://github.com/google/jsonnet/releases/download/${WANT_VERSION_NAME}/jsonnet-${WANT_VERSION_NAME}.tar.gz"
26+
fi
27+
1228
cd ..
1329
go run cmd/dumpstdlibast/dumpstdlibast.go cpp-jsonnet/stdlib/std.jsonnet > astgen/stdast.go
1430

15-
sha256=$(curl -fL https://github.com/google/jsonnet/archive/$hash.tar.gz | shasum -a 256 | awk '{print $1}')
31+
sha256=$(curl -fL "${ARCHIVE_URL}" | shasum -a 256 | awk '{print $1}')
1632

1733
sed -i.bak \
1834
-e "s/CPP_JSONNET_SHA256 = .*/CPP_JSONNET_SHA256 = \"$sha256\"/;" \
1935
-e "s/CPP_JSONNET_GITHASH = .*/CPP_JSONNET_GITHASH = \"$hash\"/;" \
36+
-e "s/CPP_JSONNET_RELEASE_VERSION = .*/CPP_JSONNET_RELEASE_VERSION = \"$WANT_VERSION_NAME\"/;" \
2037
bazel/repositories.bzl MODULE.bazel
2138

2239
# NB: macOS sed doesn't support -i without arg. This is the easy workaround.

0 commit comments

Comments
 (0)