From 0916a06d66f46cda1edcfea87a8a6cdcdeb18341 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Mon, 15 Jul 2024 14:54:50 +0200 Subject: [PATCH] wip --- .bazelrc | 5 +- .gitattributes | 10 +- .github/workflows/action.yml | 1 - .github/workflows/build_assets.sh | 10 ++ .github/workflows/generate_tools_versions.sh | 16 ++ .github/workflows/release.yml | 3 +- .github/workflows/release_prep.sh | 39 +++-- .gitignore | 5 + BUILD.bazel | 4 +- MODULE.bazel | 32 +++- Makefile | 4 +- WORKSPACE | 4 - bazeldnf/extensions.bzl | 133 +++++++++++++++-- {tools => bazeldnf}/platforms.bzl | 0 bazeldnf/private/prebuilts.bzl | 15 -- bazeldnf/private/toolchains_repo.bzl | 2 +- bazeldnf/repositories.bzl | 9 +- e2e/bazel-6-bzlmod/BUILD.bazel | 4 +- e2e/bazel-6-bzlmod/MODULE.bazel | 22 +++ e2e/bazel-6-bzlmod/WORKSPACE | 4 - e2e/bazel-7-bzlmod/BUILD.bazel | 4 +- e2e/bazel-7-bzlmod/MODULE.bazel | 22 +++ e2e/bazel-7-bzlmod/MODULE.bazel.lock | 145 +------------------ internal/rpm.bzl | 9 +- pkg/rpm/BUILD.bazel | 5 +- pkg/rpm/tar_test.go | 6 +- {bazeldnf/private => tools}/integrity.bzl | 8 +- tools/release/defs.bzl | 4 +- tools/version.bzl | 16 +- 29 files changed, 290 insertions(+), 251 deletions(-) create mode 100755 .github/workflows/build_assets.sh create mode 100755 .github/workflows/generate_tools_versions.sh rename {tools => bazeldnf}/platforms.bzl (100%) delete mode 100644 bazeldnf/private/prebuilts.bzl rename {bazeldnf/private => tools}/integrity.bzl (89%) diff --git a/.bazelrc b/.bazelrc index 15a1728..237a58d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -9,10 +9,7 @@ import %workspace%/.aspect/bazelrc/performance.bazelrc # Specific project flags go here if we have some common --incompatible_enable_proto_toolchain_resolution -# register toolchains with prebuilts -common:prebuilt-toolchain --extra_toolchains=@bazeldnf_toolchains//:all - -common:built-toolchain --extra_toolchains=//cmd:bazeldnf-host-toolchain +common --extra_toolchains=//cmd:bazeldnf-host-toolchain common --enable_bzlmod diff --git a/.gitattributes b/.gitattributes index 3a04bff..d4a5939 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,11 +2,7 @@ docs/*.md linguist-generated=true # Configuration for 'git archive' # see https://git-scm.com/docs/git-archive/2.40.0#ATTRIBUTES -# Exclude a bungh of paths to save some disk space +# Exclude a bunch of paths to save some disk space e2e export-ignore -.aspect export-ignore -.github export-ignore -hack export-ignore - -# Substitution for the _VERSION_PRIVATE placeholder -tools/version.bzl export-subst +.aspect +.github diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 60628dc..1b396ef 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -30,7 +30,6 @@ jobs: repository-cache: true bazelrc: | import %workspace%/.github/workflows/ci.bazelrc - common --config=built-toolchain - run: bazel build //... && bazel test //... diff --git a/.github/workflows/build_assets.sh b/.github/workflows/build_assets.sh new file mode 100755 index 0000000..5ca3c2c --- /dev/null +++ b/.github/workflows/build_assets.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail +set -x + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +${SCRIPT_DIR}/generate_tools_versions.sh + +bazel run //tools/release diff --git a/.github/workflows/generate_tools_versions.sh b/.github/workflows/generate_tools_versions.sh new file mode 100755 index 0000000..131b874 --- /dev/null +++ b/.github/workflows/generate_tools_versions.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail +set -x + +# Set by GH actions, see +# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables +REPO_URL="${GITHUB_REPOSITORY:-rmohr/bazeldnf}" +OUT=${PREFIX:-.}/tools/version.bzl +cat > ${OUT} < /dev/null && pwd ) # Set by GH actions, see # https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables -TAG=${GITHUB_REF_NAME} + # The prefix is chosen to match what GitHub generates for source archives -PREFIX="bazeldnf-${TAG:1}" -ARCHIVE="bazeldnf-$TAG.tar.gz" +PREFIX="bazeldnf-${GITHUB_REF_NAME}" +ARCHIVE="bazeldnf-${GITHUB_REF_NAME}.tar.gz" ARCHIVE_TMP=$(mktemp) -REPO_URL="${GITHUB_REPOSITORY:-rmohr/bazeldnf}" - # NB: configuration for 'git archive' is in /.gitattributes -git archive --format=tar --prefix=${PREFIX}/ --worktree-attributes ${TAG} > $ARCHIVE_TMP +git archive --format=tar --prefix=${PREFIX}/ --worktree-attributes ${GITHUB_REF_NAME} > $ARCHIVE_TMP ############ # Patch up the archive to have integrity hashes for built binaries that we downloaded in the GHA workflow. # Now that we've run `git archive` we are free to pollute the working directory. -# Delete the placeholder file -tar --file $ARCHIVE_TMP --delete ${PREFIX}/bazeldnf/private/prebuilts.bzl +# Delete the placeholder files +tar --file $ARCHIVE_TMP --delete ${PREFIX}/tools/version.bzl +tar --file $ARCHIVE_TMP --delete ${PREFIX}/tools/integrity.bzl # Add trailing newlines to sha256 files. They were built with # https://github.com/aspect-build/bazel-lib/blob/main/tools/release/hashes.bzl @@ -29,22 +31,23 @@ for sha in $(ls artifacts/*.sha256); do done mkdir -p ${PREFIX}/tools -cat >${PREFIX}/tools/prebuilts.bzl <${PREFIX}/tools/integrity.bzl < $ARCHIVE SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') +# Set by GH actions, see +# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables +REPO_URL="${GITHUB_REPOSITORY:-rmohr/bazeldnf}" + cat << EOF ## Using [Bzlmod] with Bazel 6: Add to your \`MODULE.bazel\` file: \`\`\`starlark -bazel_dep(name = "bazeldnf", version = "${TAG:1}") +bazel_dep(name = "bazeldnf", version = "${GITHUB_REF_NAME:1}") \`\`\` This will register a prebuilt bazeldnf @@ -73,7 +80,7 @@ http_archive( name = "bazeldnf", sha256 = "${SHA}", strip_prefix = "${PREFIX}", - url = "https://github.com/${REPO_URL}/releases/download/${TAG}/${ARCHIVE}", + url = "https://github.com/${REPO_URL}/releases/download/${GITHUB_REF_NAME}/${ARCHIVE}", ) load( diff --git a/.gitignore b/.gitignore index 2d21d9b..b82ab72 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,8 @@ dist cmd/cmd .bazelrc.user tools/release +artifacts +bazeldnf-v* + +# ignore by now +MODULE.bazel.lock diff --git a/BUILD.bazel b/BUILD.bazel index 0be275f..82fbcfd 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -27,8 +27,8 @@ bazeldnf( rpmtree( name = "something", rpms = [ - "@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm", - "@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm", + "@bazeldnf-dev-rpms//:libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + "@bazeldnf-dev-rpms//:libvirt-devel-6.1.0-2.fc32.x86_64.rpm", ], ) diff --git a/MODULE.bazel b/MODULE.bazel index 42e9601..5f87eb5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,12 +8,16 @@ module( bazeldnf = use_extension("//bazeldnf:extensions.bzl", "bazeldnf") bazeldnf.toolchain() -use_repo(bazeldnf, "bazeldnf_toolchains") +use_repo( + bazeldnf, + "bazeldnf_toolchains", +) register_toolchains("@bazeldnf_toolchains//:all") bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "bazel_features", version = "1.13.0") bazel_dep(name = "gazelle", version = "0.37.0", dev_dependency = True) bazel_dep(name = "rules_go", version = "0.49.0", dev_dependency = True, repo_name = "io_bazel_rules_go") @@ -41,3 +45,29 @@ use_repo( "io_k8s_sigs_yaml", "org_golang_x_crypto", ) + +bazeldnf_dev = use_extension("//bazeldnf:extensions.bzl", "bazeldnf", dev_dependency = True) +bazeldnf_dev.alias( + name = "bazeldnf-dev-rpms", + dev_dependency = True, +) +bazeldnf_dev.rpm( + name = "libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + sha256 = "3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", + urls = [ + "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + "https://storage.googleapis.com/builddeps/3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", + ], +) +bazeldnf_dev.rpm( + name = "libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + sha256 = "2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", + urls = [ + "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + "https://storage.googleapis.com/builddeps/2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", + ], +) +use_repo( + bazeldnf_dev, + "bazeldnf-dev-rpms", +) diff --git a/Makefile b/Makefile index 5027d49..3d94e1f 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ gazelle: bazelisk run //:gazelle test: gazelle - bazelisk build --config=built-toolchain //... && bazelisk test --config=built-toolchain //... + bazelisk build //... && bazelisk test //... buildifier: bazelisk run //:buildifier @@ -18,7 +18,9 @@ gofmt: e2e: (cd e2e/bazel-5 && bazelisk build //...) (cd e2e/bazel-6 && bazelisk build //...) + (cd e2e/bazel-6-bzlmod && bazelisk build //...) (cd e2e/bazel-7 && bazelisk build //...) + (cd e2e/bazel-7-bzlmod && bazelisk build //...) fmt: gofmt buildifier diff --git a/WORKSPACE b/WORKSPACE index bd85c77..17f90d8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,5 +1 @@ workspace(name = "bazeldnf") - -load(":test_deps.bzl", "bazeldnf_test_dependencies") - -bazeldnf_test_dependencies() diff --git a/bazeldnf/extensions.bzl b/bazeldnf/extensions.bzl index fa6f4d5..233bdcd 100644 --- a/bazeldnf/extensions.bzl +++ b/bazeldnf/extensions.bzl @@ -5,20 +5,78 @@ Installs the bazeldnf toolchain. based on: https://github.com/bazel-contrib/rules-template/blob/0dadcb716f06f672881681155fe6d9ff6fc4a4f4/mylang/extensions.bzl """ -load("//tools:version.bzl", "VERSION") +load("@bazel_features//:features.bzl", "bazel_features") +load("//bazeldnf/private:toolchains_repo.bzl", "toolchains_repo") +load("//internal:rpm.bzl", rpm_repository = "rpm") load(":repositories.bzl", "bazeldnf_register_toolchains") +_ALIAS_TEMPLATE = """\ +alias( + name = "{name}", + actual = "@{actual}//rpm", + visibility = ["//visibility:public"], +) +""" + +def _proxy_repo_impl(repository_ctx): + aliases = [ + _ALIAS_TEMPLATE.format( + name = v, + actual = k.workspace_name, + ) + for k, v in repository_ctx.attr.rpms.items() + ] + repository_ctx.file("WORKSPACE", "workspace(name = \"{name}\")".format(name = repository_ctx.name)) + repository_ctx.file("BUILD.bazel", "\n".join(aliases)) + +_proxy_repo = repository_rule( + implementation = _proxy_repo_impl, + attrs = { + "rpms": attr.label_keyed_string_dict(), + }, +) + _DEFAULT_NAME = "bazeldnf" -bazeldnf_toolchain = tag_class(attrs = { - "name": attr.string(doc = """\ -Base name for generated repositories, allowing more than one bazeldnf toolchain to be registered. -Overriding the default is only permitted in the root module. -""", default = _DEFAULT_NAME), -}) +def _handle_rpms(alias, mod, module_ctx): + if not mod.tags.rpm: + return {} + + rpms = [] + + for rpm in mod.tags.rpm: + name = rpm.name + + if not rpm.urls: + fail("urls must be specified for %s" % name) + + if not name: + url = rpm.urls[0] + + # expect the url to be something like host/name-{version}-{release}.{arch}.rpm + name, _, _ = url.rsplit("-", 2) + name = name.rsplit("/", 1)[-1] + + rpm_repository( + name = name, + urls = rpm.urls, + sha256 = rpm.sha256, + integrity = rpm.integrity, + ) + + rpms.append(name) + + _proxy_repo( + name = alias, + rpms = dict([["@@%s" % x, x] for x in rpms]), + ) + + return rpms def _toolchain_extension(module_ctx): - registrations = {} + repos = {} + dev_repos = {} + for mod in module_ctx.modules: for toolchain in mod.tags.toolchain: if toolchain.name != _DEFAULT_NAME and not mod.is_root: @@ -26,15 +84,60 @@ def _toolchain_extension(module_ctx): Only the root module may override the default name for the bazeldnf toolchain. This prevents conflicting registrations in the global namespace of external repos. """) - registrations[toolchain.name] = 1 - for name in registrations.keys(): - bazeldnf_register_toolchains( - name = name, - register = False, - ) + bazeldnf_register_toolchains( + name = toolchain.name, + register = False, + ) + if mod.is_root: + repos["%s_toolchains" % toolchain.name] = 1 + + alias = "%s-rpms" % _DEFAULT_NAME + dev_dependency = False + for _alias in mod.tags.alias: + alias = _alias.name + dev_dependency = _alias.dev_dependency + + rpms = _handle_rpms(alias, mod, module_ctx) + if rpms: + if not dev_dependency: + repos[alias] = 1 + else: + dev_repos[alias] = 1 + + kwargs = { + "root_module_direct_deps": repos.keys(), + "root_module_direct_dev_deps": dev_repos.keys(), + } + + # once we move to bazel 7 this becomes True by default + if bazel_features.external_deps.extension_metadata_has_reproducible: + kwargs["reproducible"] = True + + return module_ctx.extension_metadata(**kwargs) + +bazeldnf_toolchain = tag_class(attrs = { + "name": attr.string(doc = """\ +Base name for generated repositories, allowing more than one bazeldnf toolchain to be registered. +Overriding the default is only permitted in the root module. +""", default = _DEFAULT_NAME), +}) + +rpm_tag = tag_class(attrs = { + "integrity": attr.string(doc = "Subresource Integrity (SRI) hash of the RPM file"), + "name": attr.string(doc = "Exposed name for the RPM Bazel repository, defaults to extract from the first url"), + "sha256": attr.string(doc = "SHA256 hash of the RPM file"), + "urls": attr.string_list(doc = "URLs of the RPM file to download from"), +}) bazeldnf = module_extension( implementation = _toolchain_extension, - tag_classes = {"toolchain": bazeldnf_toolchain}, + tag_classes = { + "toolchain": bazeldnf_toolchain, + "rpm": rpm_tag, + "alias": tag_class(attrs = { + "name": attr.string(doc = "The name of the alias repository"), + "dev_dependency": attr.bool(doc = "Whether the alias repository is a dev dependency", default = False), + }), + }, ) diff --git a/tools/platforms.bzl b/bazeldnf/platforms.bzl similarity index 100% rename from tools/platforms.bzl rename to bazeldnf/platforms.bzl diff --git a/bazeldnf/private/prebuilts.bzl b/bazeldnf/private/prebuilts.bzl deleted file mode 100644 index 3d99298..0000000 --- a/bazeldnf/private/prebuilts.bzl +++ /dev/null @@ -1,15 +0,0 @@ -"""Expose prebuilt binaries for bazeldnf.""" - -VERSION = "v0.5.9" - -REPO_URL = "rmohr/bazeldnf" - -PREBUILTS = { - "linux-amd64": "7e1035d8bd2f25b787b04843f4d6a05e7cdbd3995926497c2a587e52da6262a8", - "linux-arm64": "d954b785bfd79dbbd66a2f3df02b0d3a51f1fed4508a6d88fda13a9d24c878cc", - "darwin-amd64": "92afc7f6475981adf9ae32b563b051869d433d8d8c9666e28a1c1c6e840394cd", - "darwin-arm64": "c5e99ed72448026ee63259a0a28440f8b43a125414fa312edbd569c2976515a3", - "linux-ppc64": "9d5337c1afe4bab858742718ac4c230d9ca368299cb97c50078eef14ae180922", - "linux-ppc64le": "7ea4db00947914bc1c51e8f042fe220a3167c65815c487eccd0c541ecfa78aa1", - "linux-s390x": "09aa4abcb1d85da11642889826b982ef90547eb32099fc8177456c92f66a4cfd", -} diff --git a/bazeldnf/private/toolchains_repo.bzl b/bazeldnf/private/toolchains_repo.bzl index bdeb749..10c5796 100644 --- a/bazeldnf/private/toolchains_repo.bzl +++ b/bazeldnf/private/toolchains_repo.bzl @@ -17,7 +17,7 @@ This guidance tells us how to avoid that: we put the toolchain targets in the al with only the toolchain attribute pointing into the platform-specific repositories. """ -load("@bazeldnf//tools:platforms.bzl", "PLATFORMS") +load("@bazeldnf//bazeldnf:platforms.bzl", "PLATFORMS") def _toolchains_repo_impl(repository_ctx): build_content = """# Generated by toolchains_repo.bzl diff --git a/bazeldnf/repositories.bzl b/bazeldnf/repositories.bzl index 6f88e1b..badf0ad 100644 --- a/bazeldnf/repositories.bzl +++ b/bazeldnf/repositories.bzl @@ -6,9 +6,10 @@ See https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file", _http_archive = "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("//bazeldnf/private:prebuilts.bzl", "PREBUILTS", "REPO_URL", "VERSION") load("//bazeldnf/private:toolchains_repo.bzl", "toolchains_repo") -load("//tools:platforms.bzl", "PLATFORMS") +load("//tools:integrity.bzl", "PREBUILTS") +load("//tools:version.bzl", "VERSION", "REPO_URL") +load(":platforms.bzl", "PLATFORMS") def http_archive(name, **kwargs): maybe(_http_archive, name = name, **kwargs) @@ -61,7 +62,7 @@ bazeldnf_toolchain( # Base BUILD file for this repository repository_ctx.file("BUILD.bazel", build_content) -bazeldnf_repositories = repository_rule( +bazeldnf_prebuilt_repository = repository_rule( _bazeldnf_repo_impl, doc = _DOC, attrs = _ATTRS, @@ -100,7 +101,7 @@ def bazeldnf_register_toolchains(name, register = True, **kwargs): executable = True, url = url, ) - bazeldnf_repositories( + bazeldnf_prebuilt_repository( name = "%s_%s" % (name, platform), tool = name_, **kwargs diff --git a/e2e/bazel-6-bzlmod/BUILD.bazel b/e2e/bazel-6-bzlmod/BUILD.bazel index 48e40e6..ee04228 100644 --- a/e2e/bazel-6-bzlmod/BUILD.bazel +++ b/e2e/bazel-6-bzlmod/BUILD.bazel @@ -8,8 +8,8 @@ bazeldnf( rpmtree( name = "something", rpms = [ - "@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm", - "@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm", + "@bazeldnf-rpms//:libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + "@bazeldnf-rpms//:libvirt-devel-6.1.0-2.fc32.x86_64.rpm", ], ) diff --git a/e2e/bazel-6-bzlmod/MODULE.bazel b/e2e/bazel-6-bzlmod/MODULE.bazel index 3ce46bb..75e7ba9 100644 --- a/e2e/bazel-6-bzlmod/MODULE.bazel +++ b/e2e/bazel-6-bzlmod/MODULE.bazel @@ -13,3 +13,25 @@ local_path_override( bazel_dep(name = "rules_pkg", version = "0.10.1", dev_dependency = True) bazel_dep(name = "bazel_skylib", version = "1.7.1") + +bazeldnf = use_extension("@bazeldnf//bazeldnf:extensions.bzl", "bazeldnf") +bazeldnf.rpm( + name = "libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + sha256 = "3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", + urls = [ + "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + "https://storage.googleapis.com/builddeps/3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", + ], +) +bazeldnf.rpm( + name = "libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + sha256 = "2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", + urls = [ + "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + "https://storage.googleapis.com/builddeps/2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", + ], +) +use_repo( + bazeldnf, + "bazeldnf-rpms", +) diff --git a/e2e/bazel-6-bzlmod/WORKSPACE b/e2e/bazel-6-bzlmod/WORKSPACE index 01f0ffc..e69de29 100644 --- a/e2e/bazel-6-bzlmod/WORKSPACE +++ b/e2e/bazel-6-bzlmod/WORKSPACE @@ -1,4 +0,0 @@ -# dependencies for integration tests -load("@bazeldnf//:test_deps.bzl", "bazeldnf_test_dependencies") - -bazeldnf_test_dependencies() diff --git a/e2e/bazel-7-bzlmod/BUILD.bazel b/e2e/bazel-7-bzlmod/BUILD.bazel index 48e40e6..ee04228 100644 --- a/e2e/bazel-7-bzlmod/BUILD.bazel +++ b/e2e/bazel-7-bzlmod/BUILD.bazel @@ -8,8 +8,8 @@ bazeldnf( rpmtree( name = "something", rpms = [ - "@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm", - "@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm", + "@bazeldnf-rpms//:libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + "@bazeldnf-rpms//:libvirt-devel-6.1.0-2.fc32.x86_64.rpm", ], ) diff --git a/e2e/bazel-7-bzlmod/MODULE.bazel b/e2e/bazel-7-bzlmod/MODULE.bazel index f81329d..7d661e2 100644 --- a/e2e/bazel-7-bzlmod/MODULE.bazel +++ b/e2e/bazel-7-bzlmod/MODULE.bazel @@ -13,3 +13,25 @@ local_path_override( bazel_dep(name = "rules_pkg", version = "0.10.1", dev_dependency = True) bazel_dep(name = "bazel_skylib", version = "1.7.1") + +bazeldnf = use_extension("@bazeldnf//bazeldnf:extensions.bzl", "bazeldnf") +bazeldnf.rpm( + name = "libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + sha256 = "3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", + urls = [ + "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + "https://storage.googleapis.com/builddeps/3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", + ], +) +bazeldnf.rpm( + name = "libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + sha256 = "2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", + urls = [ + "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + "https://storage.googleapis.com/builddeps/2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", + ], +) +use_repo( + bazeldnf, + "bazeldnf-rpms", +) diff --git a/e2e/bazel-7-bzlmod/MODULE.bazel.lock b/e2e/bazel-7-bzlmod/MODULE.bazel.lock index 3d3bc51..47a9f1f 100644 --- a/e2e/bazel-7-bzlmod/MODULE.bazel.lock +++ b/e2e/bazel-7-bzlmod/MODULE.bazel.lock @@ -8,7 +8,8 @@ "https://bcr.bazel.build/modules/apple_support/1.5.0/MODULE.bazel": "50341a62efbc483e8a2a6aec30994a58749bd7b885e18dd96aa8c33031e558ef", "https://bcr.bazel.build/modules/apple_support/1.5.0/source.json": "eb98a7627c0bc486b57f598ad8da50f6625d974c8f723e9ea71bd39f709c9862", "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", - "https://bcr.bazel.build/modules/bazel_features/1.11.0/source.json": "c9320aa53cd1c441d24bd6b716da087ad7e4ff0d9742a9884587596edfe53015", + "https://bcr.bazel.build/modules/bazel_features/1.13.0/MODULE.bazel": "c14c33c7c3c730612bdbe14ebbb5e61936b6f11322ea95a6e91cd1ba962f94df", + "https://bcr.bazel.build/modules/bazel_features/1.13.0/source.json": "b01f6aaaf93527ff4267421ef416debbd89b3166b70af5c89400c6a95a89c133", "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", "https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686", "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", @@ -95,148 +96,6 @@ ] } }, - "@@bazeldnf~//bazeldnf:extensions.bzl%bazeldnf": { - "general": { - "bzlTransitiveDigest": "LZdt4XllyCA9ms8TgTJGh7S4PPwrAXXsFyT1RDX1a2A=", - "usagesDigest": "U23uxGn0x59BoKWhvQoJ3teLzfxGEhedrfketKvCj8I=", - "recordedFileInputs": {}, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "bazeldnf_darwin-amd64": { - "bzlFile": "@@bazeldnf~//bazeldnf:repositories.bzl", - "ruleClassName": "bazeldnf_repositories", - "attributes": { - "tool": "prebuilt-bazeldnf-darwin-amd64" - } - }, - "bazeldnf_darwin-arm64": { - "bzlFile": "@@bazeldnf~//bazeldnf:repositories.bzl", - "ruleClassName": "bazeldnf_repositories", - "attributes": { - "tool": "prebuilt-bazeldnf-darwin-arm64" - } - }, - "prebuilt-bazeldnf-linux-ppc64le": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "7ea4db00947914bc1c51e8f042fe220a3167c65815c487eccd0c541ecfa78aa1", - "executable": true, - "url": "https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-ppc64le" - } - }, - "prebuilt-bazeldnf-linux-arm64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "d954b785bfd79dbbd66a2f3df02b0d3a51f1fed4508a6d88fda13a9d24c878cc", - "executable": true, - "url": "https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-arm64" - } - }, - "prebuilt-bazeldnf-linux-s390x": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "09aa4abcb1d85da11642889826b982ef90547eb32099fc8177456c92f66a4cfd", - "executable": true, - "url": "https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-s390x" - } - }, - "bazeldnf_linux-s390x": { - "bzlFile": "@@bazeldnf~//bazeldnf:repositories.bzl", - "ruleClassName": "bazeldnf_repositories", - "attributes": { - "tool": "prebuilt-bazeldnf-linux-s390x" - } - }, - "bazeldnf_linux-ppc64le": { - "bzlFile": "@@bazeldnf~//bazeldnf:repositories.bzl", - "ruleClassName": "bazeldnf_repositories", - "attributes": { - "tool": "prebuilt-bazeldnf-linux-ppc64le" - } - }, - "prebuilt-bazeldnf-darwin-amd64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "92afc7f6475981adf9ae32b563b051869d433d8d8c9666e28a1c1c6e840394cd", - "executable": true, - "url": "https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-darwin-amd64" - } - }, - "bazeldnf_linux-arm64": { - "bzlFile": "@@bazeldnf~//bazeldnf:repositories.bzl", - "ruleClassName": "bazeldnf_repositories", - "attributes": { - "tool": "prebuilt-bazeldnf-linux-arm64" - } - }, - "prebuilt-bazeldnf-linux-amd64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "7e1035d8bd2f25b787b04843f4d6a05e7cdbd3995926497c2a587e52da6262a8", - "executable": true, - "url": "https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-amd64" - } - }, - "prebuilt-bazeldnf-linux-ppc64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "9d5337c1afe4bab858742718ac4c230d9ca368299cb97c50078eef14ae180922", - "executable": true, - "url": "https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-ppc64" - } - }, - "bazeldnf_linux-ppc64": { - "bzlFile": "@@bazeldnf~//bazeldnf:repositories.bzl", - "ruleClassName": "bazeldnf_repositories", - "attributes": { - "tool": "prebuilt-bazeldnf-linux-ppc64" - } - }, - "bazeldnf_toolchains": { - "bzlFile": "@@bazeldnf~//bazeldnf/private:toolchains_repo.bzl", - "ruleClassName": "toolchains_repo", - "attributes": { - "user_repository_name": "bazeldnf" - } - }, - "prebuilt-bazeldnf-darwin-arm64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "c5e99ed72448026ee63259a0a28440f8b43a125414fa312edbd569c2976515a3", - "executable": true, - "url": "https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-darwin-arm64" - } - }, - "bazeldnf_linux-amd64": { - "bzlFile": "@@bazeldnf~//bazeldnf:repositories.bzl", - "ruleClassName": "bazeldnf_repositories", - "attributes": { - "tool": "prebuilt-bazeldnf-linux-amd64" - } - } - }, - "recordedRepoMappingEntries": [ - [ - "bazeldnf~", - "bazel_tools", - "bazel_tools" - ], - [ - "bazeldnf~", - "bazeldnf", - "bazeldnf~" - ] - ] - } - }, "@@platforms//host:extension.bzl%host_platform": { "general": { "bzlTransitiveDigest": "xelQcPZH8+tmuOHVjL9vDxMnnQNMlwj0SlvgoqBkm4U=", diff --git a/internal/rpm.bzl b/internal/rpm.bzl index 429d519..2871ea9 100644 --- a/internal/rpm.bzl +++ b/internal/rpm.bzl @@ -20,13 +20,15 @@ _HTTP_FILE_BUILD = """ package(default_visibility = ["//visibility:public"]) filegroup( name = "rpm", - srcs = ["downloaded"], + srcs = ["{downloaded_file_path}"], ) """ def _rpm_impl(ctx): if ctx.attr.urls: - downloaded_file_path = "downloaded" + downloaded_file_path = ctx.attr.name + if not downloaded_file_path.endswith(".rpm"): + downloaded_file_path = "%s.rpm" % downloaded_file_path download_info = ctx.download( url = ctx.attr.urls, output = "rpm/" + downloaded_file_path, @@ -36,12 +38,11 @@ def _rpm_impl(ctx): else: fail("urls must be specified") ctx.file("WORKSPACE", "workspace(name = \"{name}\")".format(name = ctx.name)) - ctx.file("rpm/BUILD", _HTTP_FILE_BUILD.format(downloaded_file_path)) + ctx.file("rpm/BUILD", _HTTP_FILE_BUILD.format(downloaded_file_path = downloaded_file_path)) return update_attrs(ctx.attr, _rpm_attrs.keys(), {"sha256": download_info.sha256}) _rpm_attrs = { "urls": attr.string_list(), - "strip_prefix": attr.string(), "sha256": attr.string(), "integrity": attr.string(), } diff --git a/pkg/rpm/BUILD.bazel b/pkg/rpm/BUILD.bazel index 7391d26..b014b6e 100644 --- a/pkg/rpm/BUILD.bazel +++ b/pkg/rpm/BUILD.bazel @@ -24,8 +24,11 @@ go_test( "rpm_test.go", "tar_test.go", ], - data = ["@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm"], + data = ["@bazeldnf-dev-rpms//:libvirt-libs-6.1.0-2.fc32.x86_64.rpm"], embed = [":rpm"], + env = { + "TEST_RPM": "$(rlocationpath @bazeldnf-dev-rpms//:libvirt-libs-6.1.0-2.fc32.x86_64.rpm)", + }, deps = [ "//pkg/api", "@com_github_onsi_gomega//:gomega", diff --git a/pkg/rpm/tar_test.go b/pkg/rpm/tar_test.go index d4a58ea..9307bad 100644 --- a/pkg/rpm/tar_test.go +++ b/pkg/rpm/tar_test.go @@ -23,7 +23,7 @@ func TestRPMToTar(t *testing.T) { }{ { name: "should convert a RPM to tar and keep all entries", - rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), "libvirt-libs-6.1.0-2.fc32.x86_64.rpm/rpm/downloaded"), + rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), os.Getenv("TEST_RPM")), wantErr: false, expectedHeaders: []*tar.Header{ {Name: "./etc/libvirt/libvirt-admin.conf", Size: 450, Mode: 33188}, @@ -92,7 +92,7 @@ func TestTar2Files(t *testing.T) { }{ { name: "should extract a symlink from a tar archive", - rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), "libvirt-libs-6.1.0-2.fc32.x86_64.rpm/rpm/downloaded"), + rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), os.Getenv("TEST_RPM")), wantErr: false, expectedFiles: []*fileInfo{ {Name: "libvirt.so.0", Size: 19}, @@ -101,7 +101,7 @@ func TestTar2Files(t *testing.T) { }, { name: "should extract multiple files from a tar archive", - rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), "libvirt-libs-6.1.0-2.fc32.x86_64.rpm/rpm/downloaded"), + rpm: filepath.Join(os.Getenv("TEST_SRCDIR"), os.Getenv("TEST_RPM")), wantErr: false, expectedFiles: []*fileInfo{ {Name: "libvirt-admin.conf", Size: 450}, diff --git a/bazeldnf/private/integrity.bzl b/tools/integrity.bzl similarity index 89% rename from bazeldnf/private/integrity.bzl rename to tools/integrity.bzl index 7ddece3..870b9a2 100644 --- a/bazeldnf/private/integrity.bzl +++ b/tools/integrity.bzl @@ -1,10 +1,10 @@ -"Integrity files for download" +"""Expose prebuilt binaries integrities for bazeldnf.""" -INTEGRITY = { - "darwin-amd64": "92afc7f6475981adf9ae32b563b051869d433d8d8c9666e28a1c1c6e840394cd", - "darwin-arm64": "c5e99ed72448026ee63259a0a28440f8b43a125414fa312edbd569c2976515a3", +PREBUILTS = { "linux-amd64": "7e1035d8bd2f25b787b04843f4d6a05e7cdbd3995926497c2a587e52da6262a8", "linux-arm64": "d954b785bfd79dbbd66a2f3df02b0d3a51f1fed4508a6d88fda13a9d24c878cc", + "darwin-amd64": "92afc7f6475981adf9ae32b563b051869d433d8d8c9666e28a1c1c6e840394cd", + "darwin-arm64": "c5e99ed72448026ee63259a0a28440f8b43a125414fa312edbd569c2976515a3", "linux-ppc64": "9d5337c1afe4bab858742718ac4c230d9ca368299cb97c50078eef14ae180922", "linux-ppc64le": "7ea4db00947914bc1c51e8f042fe220a3167c65815c487eccd0c541ecfa78aa1", "linux-s390x": "09aa4abcb1d85da11642889826b982ef90547eb32099fc8177456c92f66a4cfd", diff --git a/tools/release/defs.bzl b/tools/release/defs.bzl index 24f8e61..fcde958 100644 --- a/tools/release/defs.bzl +++ b/tools/release/defs.bzl @@ -4,7 +4,7 @@ load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file") load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") load("@aspect_bazel_lib//tools/release:hashes.bzl", "hashes") -load("//tools:platforms.bzl", "PLATFORMS") +load("//bazeldnf:platforms.bzl", "PLATFORMS") load("//tools:version.bzl", "VERSION") # buildozer: disable=function-docstring @@ -24,7 +24,7 @@ def build_for_platform(name, value): target_platform = ":{}".format(name), ) - artifact = "bazeldnf-v{version}-{platform}".format(version = VERSION, platform = name) + artifact = "bazeldnf-{version}-{platform}".format(version = VERSION, platform = name) copy_file( name = "copy_{}".format(build), src = build, diff --git a/tools/version.bzl b/tools/version.bzl index de32177..63f335b 100644 --- a/tools/version.bzl +++ b/tools/version.bzl @@ -1,15 +1,5 @@ -"version information. replaced with stamped info with each release" +"Generated during release generate_tools_prebuilts.sh" -# Automagically "stamped" by git during `git archive` thanks to `export-subst` line in .gitattributes. -# See https://git-scm.com/docs/git-archive#Documentation/git-archive.txt-export-subst -_VERSION_PRIVATE = "$Format:%(describe:tags)$" +VERSION = "v0.6.0-rc6" -VERSION = "0.5.9" if _VERSION_PRIVATE.startswith("$Format") else _VERSION_PRIVATE.replace("v", "", 1) - -# Whether rules_py is a pre-release, and therefore has no release artifacts to download. -# NB: When GitHub runs `git archive` to serve a source archive file, -# it honors our .gitattributes and stamps this file, e.g. -# _VERSION_PRIVATE = "v2.0.3-7-g57bfe2c1" -# From https://git-scm.com/docs/git-describe: -# > The "g" prefix stands for "git" -IS_PRERELEASE = VERSION == "0.0.0" or VERSION.find("g") >= 0 +REPO_URL = "rmohr/bazeldnf"