diff --git a/MODULE.bazel b/MODULE.bazel index 9b066740..bfc24807 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,6 +8,7 @@ module( bazel_dep(name = "gazelle", version = "0.38.0") bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_go", version = "0.50.0") +bazel_dep(name = "rules_pkg", version = "0.10.1") bazel_dep(name = "aspect_rules_js", version = "1.42.3") go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") diff --git a/deb/BUILD b/deb/BUILD new file mode 100644 index 00000000..a74f52b5 --- /dev/null +++ b/deb/BUILD @@ -0,0 +1,52 @@ +load("@rules_pkg//pkg:deb.bzl", "pkg_deb") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +config_setting( + name = "stamp_detect", + values = {"stamp": "1"}, +) + +genrule( + name = "parse_version", + outs = ["version.txt"], + cmd_bash = select({ + ":stamp_detect": "sed -ne 's#^STABLE_VERSION v##p' bazel-out/stable-status.txt > $@", + "//conditions:default": "echo 0.0.0 > $@", + }), + cmd_bat = "echo 0.0.0 >> $@", + stamp = True, +) + +ARCHES = ["amd64", "arm64"] + +[ + pkg_tar( + name = "bazelisk-{}_tar".format(arch), + out = "bazelisk-{}.tar".format(arch), + srcs = ["//:bazelisk-linux-{}".format(arch)], + remap_paths = {"bazelisk-linux_{}".format(arch): "bazelisk"}, + package_dir = "/usr/bin", + stamp = -1, + symlinks = {"bazel": "bazelisk"}, + ) + for arch in ARCHES +] + +[ + pkg_deb( + name = "bazelisk-{}_deb".format(arch), + architecture = arch, + conflicts = ["bazel"], + data = ":bazelisk-{}_tar".format(arch), + description_file = ":description.txt", + homepage = "https://github.com/bazelbuild/bazelisk", + license = "Apache-2.0", + maintainer = "The Bazel Authors ", + out = "bazelisk-{}.deb".format(arch), + package = "bazelisk", + section = "contrib/devel", + version_file = ":version.txt", + visibility = ["//visibility:public"], + ) + for arch in ARCHES +] diff --git a/deb/description.txt b/deb/description.txt new file mode 100644 index 00000000..db7080da --- /dev/null +++ b/deb/description.txt @@ -0,0 +1,6 @@ +A user-friendly launcher for Bazel + Bazelisk is a wrapper for Bazel written in Go. It automatically picks a good + version of Bazel given your current working directory, downloads it from the + official server (if required) and then transparently passes through all + command-line arguments to the real Bazel binary. You can call it just like you + would call Bazel. diff --git a/stamp.sh b/stamp.sh index 9aa8d0ff..6042cfd0 100755 --- a/stamp.sh +++ b/stamp.sh @@ -1,10 +1,11 @@ #!/bin/bash -# Use the first tag that points to the current HEAD -# if no tag is found, the latest git commit is used as a fallback +# Use the first tag that points to the current HEAD. If no tag is found, the +# summary given by `git describe` is used as a fallback (it contains the most +# recent tag name, the number of commits since, and the short git hash). CURRENT_TAG=$(git tag -l --points-at HEAD | head -n1) -CURRENT_COMMIT=$(git rev-parse HEAD) +CURRENT_COMMIT=$(git describe --tags HEAD) echo "STABLE_VERSION ${CURRENT_TAG:-$CURRENT_COMMIT}" # rules_nodejs expects to read from volatile-status.txt