diff --git a/.aspect/bazelrc/bazel7.bazelrc b/.aspect/bazelrc/bazel7.bazelrc index 212c26e..dbd40ee 100644 --- a/.aspect/bazelrc/bazel7.bazelrc +++ b/.aspect/bazelrc/bazel7.bazelrc @@ -1,8 +1,12 @@ # Speed up all builds by not checking if external repository files have been modified. # Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java#L244 -build --noexperimental_check_external_repository_files -fetch --noexperimental_check_external_repository_files -query --noexperimental_check_external_repository_files +common --noexperimental_check_external_repository_files + +# Don't report when the root module's lower bound for a dependency happens to be less than the resolved version. +# This is expected and should NOT prompt an engineer to update our lower bound to match. +# WARNING: For repository 'aspect_bazel_lib', the root module requires module version aspect_bazel_lib@1.30.2, +# but got aspect_bazel_lib@1.31.2 in the resolved dependency graph. +common --check_direct_dependencies=off # Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs. # Save time on Sandbox creation and deletion when many of the same kind of action run during the diff --git a/.aspect/bazelrc/convenience.bazelrc b/.aspect/bazelrc/convenience.bazelrc index c674569..796675a 100644 --- a/.aspect/bazelrc/convenience.bazelrc +++ b/.aspect/bazelrc/convenience.bazelrc @@ -3,7 +3,7 @@ build --keep_going # Output test errors to stderr so users don't have to `cat` or open test failure log files when test -# fail. This makes the log noiser in exchange for reducing the time-to-feedback on test failures for +# fail. This makes the log noisier in exchange for reducing the time-to-feedback on test failures for # users. # Docs: https://bazel.build/docs/user-manual#test-output test --test_output=errors diff --git a/.aspect/bazelrc/correctness.bazelrc b/.aspect/bazelrc/correctness.bazelrc index a599f6d..f381062 100644 --- a/.aspect/bazelrc/correctness.bazelrc +++ b/.aspect/bazelrc/correctness.bazelrc @@ -68,7 +68,7 @@ build --incompatible_default_to_explicit_init_py common --incompatible_disallow_empty_glob # Always download coverage files for tests from the remote cache. By default, coverage files are not -# downloaded on test result cahce hits when --remote_download_minimal is enabled, making it impossible +# downloaded on test result cache hits when --remote_download_minimal is enabled, making it impossible # to generate a full coverage report. # Docs: https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs # detching remote cache results diff --git a/.bazelrc b/.bazelrc index 383386a..2d3524b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,5 +1,5 @@ # Import Aspect bazelrc presets -try-import %workspace%/.aspect/bazelrc/local/bazel7.bazelrc # will only work in bazel7+ +try-import %workspace%/.aspect/bazelrc/bazel7.bazelrc # will only work in bazel7+ import %workspace%/.aspect/bazelrc/bazel6.bazelrc # will only work in bazel6+ import %workspace%/.aspect/bazelrc/convenience.bazelrc import %workspace%/.aspect/bazelrc/correctness.bazelrc @@ -7,7 +7,9 @@ import %workspace%/.aspect/bazelrc/debug.bazelrc import %workspace%/.aspect/bazelrc/performance.bazelrc # Specific project flags go here if we have some +common --incompatible_enable_proto_toolchain_resolution +# inside the rules project we build from source common --extra_toolchains=//cmd:bazeldnf-host-toolchain # Load any settings & overrides specific to the current user from `.bazelrc.user`. diff --git a/.bazelversion b/.bazelversion index f22d756..35907cd 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.5.0 +7.x diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0c48c7e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +docs/*.md linguist-generated=true + +# Configuration for 'git archive' +# see https://git-scm.com/docs/git-archive/2.40.0#ATTRIBUTES +# Exclude a bunch of paths to save some disk space +e2e export-ignore +.aspect export-ignore +.github export-ignore +pkg/*/testdata export-ignore +tools/release export-ignore + diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 82326bb..0d9a092 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -45,8 +45,8 @@ jobs: import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc - version: 7.x bazelrc: | - import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc + import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -64,3 +64,55 @@ jobs: import %workspace%/../../.github/workflows/ci.bazelrc ${{ matrix.version.bazelrc }} - run: cd e2e/bazel-workspace && USE_BAZEL_VERSION=${{ matrix.version.version }} bazelisk build //... + + e2e-bzlmod-matrix: + strategy: + matrix: + version: [6.x, 7.x] + path: + - bazel-bzlmod + - bazel-bzlmod-non-legacy-mode + - bazel-bzlmod-lock-file + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: bazel-contrib/setup-bazel@0.8.5 + with: + # Avoid downloading Bazel every time. + bazelisk-cache: true + # Keep a disk-cache + disk-cache: true + # Share repository cache between workflows. + repository-cache: true + # enable some flags for CI + bazelrc: | + import %workspace%/../../.aspect/bazelrc/ci.bazelrc + import %workspace%/../../.github/workflows/ci.bazelrc + - run: cd e2e/${{ matrix.path }} && USE_BAZEL_VERSION=${{ matrix.version }} bazelisk build //... + + e2e-bzlmod-build-toolchain-matrix: + strategy: + matrix: + config: + - version: 6.x + flags: + - version: 7.x + flags: --incompatible_enable_proto_toolchain_resolution + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: bazel-contrib/setup-bazel@0.8.5 + with: + # Avoid downloading Bazel every time. + bazelisk-cache: true + # Keep a disk-cache + disk-cache: true + # Share repository cache between workflows. + repository-cache: true + # enable some flags for CI + bazelrc: | + import %workspace%/../../.aspect/bazelrc/ci.bazelrc + import %workspace%/../../.github/workflows/ci.bazelrc + - run: cd e2e/bazel-bzlmod-toolchain-from-source && USE_BAZEL_VERSION=${{ matrix.config.version }} bazelisk build //... ${{ matrix.config.flags }} 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} < release_notes.txt + + - name: Release + uses: softprops/action-gh-release@v1 with: - body_path: dist/releasenote.txt - tag_name: ${{ inputs.release_version }} + prerelease: true + # Use GH feature to populate the changelog automatically + generate_release_notes: true + body_path: release_notes.txt files: | - dist/bazeldnf-* + artifacts/* + bazeldnf-*.tar.gz + fail_on_unmatched_files: true diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh new file mode 100755 index 0000000..d6d032d --- /dev/null +++ b/.github/workflows/release_prep.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail +set -x + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# Set by GH actions, see +# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables + +# The prefix is chosen to match what GitHub generates for source archives +PREFIX="bazeldnf-${GITHUB_REF_NAME}" +ARCHIVE="bazeldnf-${GITHUB_REF_NAME}.tar.gz" +ARCHIVE_TMP=$(mktemp) + +# NB: configuration for 'git archive' is in /.gitattributes +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 files +tar --file $ARCHIVE_TMP --delete ${PREFIX}/tools/version.bzl +tar --file $ARCHIVE_TMP --delete ${PREFIX}/tools/integrity.bzl + +mkdir -p ${PREFIX}/tools + +PREFIX=$PREFIX ${SCRIPT_DIR}/generate_tools_versions.sh + +INTEGRITY=$(jq \ + --from-file .github/workflows/integrity.jq \ + --arg PREFIX "bazeldnf-${GITHUB_REF_NAME}-" \ + --slurp \ + --raw-input artifacts/*.sha256 \ +) + +cat >${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 = "${GITHUB_REF_NAME:1}") +\`\`\` + +This will register a prebuilt bazeldnf + +[Bzlmod]: https://bazel.build/build/bzlmod + +## Using WORKSPACE + +\`\`\`starlark +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "bazeldnf", + sha256 = "${SHA}", + strip_prefix = "${PREFIX}", + url = "https://github.com/${REPO_URL}/releases/download/${GITHUB_REF_NAME}/${ARCHIVE}", +) + +load( + "@bazeldnf//bazeldnf:repositories.bzl", + "bazeldnf_dependencies", +) + +bazeldnf_dependencies() +\`\`\` +EOF diff --git a/.gitignore b/.gitignore index 6a795a8..0540e9e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,12 @@ dist cmd/cmd .bazelrc.user +# release artifacts +artifacts +bazeldnf-v* + # temporary files from MODULE.bazel MODULE.bazel.lock + +# this is where we store the release artifacts, so we can ignore it +tools/release/latest diff --git a/BUILD.bazel b/BUILD.bazel index 90e6c1f..b33ac0f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,15 +1,37 @@ -load("@bazel_gazelle//:def.bzl", "gazelle") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@buildifier_prebuilt//:rules.bzl", "buildifier") +load("@gazelle//:def.bzl", "gazelle", "gazelle_binary") load("@rules_pkg//pkg:tar.bzl", "pkg_tar") load("//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") +gazelle_binary( + name = "gazelle_binary", + languages = [ + "@bazel_skylib_gazelle_plugin//bzl", + "@gazelle//language/go", + "@gazelle//language/proto", + ], +) + # gazelle:prefix github.com/rmohr/bazeldnf # gazelle:resolve go github.com/bazelbuild/buildtools/build @com_github_bazelbuild_buildtools//build:go_default_library # gazelle:resolve go github.com/bazelbuild/buildtools/edit @com_github_bazelbuild_buildtools//edit:go_default_library -gazelle(name = "gazelle") +gazelle( + name = "gazelle", + args = [ + "-exclude", + "pkg/bazel/testdata", + ], + gazelle = "//:gazelle_binary", +) gazelle( name = "gazelle.check", + args = [ + "-exclude", + "pkg/bazel/testdata", + ], + gazelle = "//:gazelle_binary", mode = "diff", ) @@ -61,3 +83,34 @@ cc_library( name = "bar", srcs = ["//:something_libs/usr/lib64"], ) + +bzl_library( + name = "build_deps", + srcs = ["build_deps.bzl"], + visibility = ["//visibility:public"], + deps = ["@gazelle//:deps"], +) + +bzl_library( + name = "def", + srcs = ["def.bzl"], + visibility = ["//visibility:public"], + deps = ["@bazeldnf//bazeldnf:defs"], +) + +bzl_library( + name = "deps", + srcs = ["deps.bzl"], + visibility = ["//visibility:public"], + deps = [ + "@bazeldnf//bazeldnf:defs", + "@bazeldnf//bazeldnf:deps", + ], +) + +bzl_library( + name = "test_deps", + srcs = ["test_deps.bzl"], + visibility = ["//visibility:public"], + deps = ["@bazeldnf//bazeldnf:defs"], +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..7768f0a --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,52 @@ +"bazelndf dependencies" + +module( + name = "bazeldnf", + version = "v0.5.9", + compatibility_level = 0, +) + +bazeldnf = use_extension("//bazeldnf:extensions.bzl", "bazeldnf") +bazeldnf.toolchain() +use_repo(bazeldnf, "bazeldnf_toolchains") + +# registers toolchain for consumers of the repo +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.14.0") + +# dependenices for building bazeldnf +bazel_dep(name = "gazelle", version = "0.37.0") +bazel_dep(name = "rules_go", version = "0.49.0") + +go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") +go_deps.from_file(go_mod = "//:go.mod") +use_repo( + go_deps, + "com_github_bazelbuild_buildtools", + "com_github_crillab_gophersat", + "com_github_onsi_gomega", + "com_github_sassoftware_go_rpmutils", + "com_github_sirupsen_logrus", + "com_github_spf13_cobra", + "io_k8s_sigs_yaml", + "org_golang_x_crypto", +) + +# deps only needed for the repo internals +bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True) +bazel_dep(name = "aspect_bazel_lib", version = "2.8.1", dev_dependency = True) +bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) +bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True) +bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True) +bazel_dep(name = "rules_proto", version = "6.0.0", dev_dependency = True) +bazel_dep(name = "rules_java", version = "7.9.0", dev_dependency = True) +bazel_dep(name = "protobuf", version = "27.3", dev_dependency = True) +bazel_dep(name = "toolchains_protoc", version = "0.3.2", dev_dependency = True) + +register_toolchains( + "//tools/toolchains:all", + dev_dependency = True, +) diff --git a/Makefile b/Makefile index e5a250d..ff1de7a 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,12 @@ all: gazelle buildifier deps-update: - bazelisk run //:gazelle -- update-repos -from_file=go.mod -to_macro=build_deps.bzl%bazeldnf_build_dependencies bazelisk run //:gazelle gazelle: bazelisk run //:gazelle -test: gazelle e2e +test: gazelle buildifier e2e bazelisk build //... && bazelisk test //... buildifier: @@ -16,7 +15,7 @@ buildifier: gofmt: gofmt -w pkg/.. cmd/.. -e2e: +e2e-workspace: @for version in 5.x 6.x 7.x; do \ ( \ cd e2e/bazel-workspace && \ @@ -25,6 +24,49 @@ e2e: ) \ done +e2e-bzlmod: + @for version in 6.x 7.x; do \ + ( \ + cd e2e/bazel-bzlmod && \ + echo "Testing $$version with bzlmod" > /dev/stderr && \ + USE_BAZEL_VERSION=$$version bazelisk --batch build //...\ + ) \ + done + +e2e-bzlmod-non-legacy-mode: + @for version in 6.x 7.x; do \ + ( \ + cd e2e/bazel-bzlmod-non-legacy-mode && \ + echo "Testing $$version with bzlmod with non-legacy mode" > /dev/stderr && \ + USE_BAZEL_VERSION=$$version bazelisk --batch build //...\ + ) \ + done + +e2e-bazel-bzlmod-lock-file: + @for version in 6.x 7.x; do \ + ( \ + cd e2e/bazel-bzlmod-lock-file && \ + echo "Testing $$version with bzlmod with lock file" > /dev/stderr && \ + USE_BAZEL_VERSION=$$version bazelisk --batch build //...\ + ) \ + done + +e2e-bzlmod-build-toolchain-6.x: + ( \ + cd e2e/bazel-bzlmod-toolchain-from-source && \ + USE_BAZEL_VERSION=6.x bazelisk --batch build //... \ + ) + +e2e-bzlmod-build-toolchain-7.x: + ( \ + cd e2e/bazel-bzlmod-toolchain-from-source && \ + USE_BAZEL_VERSION=7.x bazelisk --batch build //... --incompatible_enable_proto_toolchain_resolution \ + ) + +e2e-bzlmod-build-toolchain: e2e-bzlmod-build-toolchain-6.x e2e-bzlmod-build-toolchain-7.x + +e2e: e2e-workspace e2e-bzlmod e2e-bzlmod-build-toolchain e2e-bzlmod-non-legacy-mode + fmt: gofmt buildifier .PHONY: gazelle test deps-update buildifier gofmt fmt e2e diff --git a/WORKSPACE b/WORKSPACE index 3a97edf..e69de29 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,120 +0,0 @@ -workspace(name = "bazeldnf") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "bazel_skylib", - sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - ], -) - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -http_archive( - name = "com_google_protobuf", - sha256 = "930c2c3b5ecc6c9c12615cf5ad93f1cd6e12d0aba862b572e076259970ac3a53", - strip_prefix = "protobuf-3.21.12", - urls = [ - "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.21.12.tar.gz", - ], -) - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - -http_archive( - name = "io_bazel_rules_go", - sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", - ], -) - -http_archive( - name = "bazel_gazelle", - sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", - ], -) - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") -load("//:build_deps.bzl", "bazeldnf_build_dependencies") -load("//bazeldnf:deps.bzl", "bazeldnf_dependencies") - -# gazelle:repository_macro build_deps.bzl%bazeldnf_build_dependencies -bazeldnf_build_dependencies() - -bazeldnf_dependencies() - -go_rules_dependencies() - -go_register_toolchains(version = "1.19.2") - -gazelle_dependencies() - -load(":test_deps.bzl", "bazeldnf_test_dependencies") - -bazeldnf_test_dependencies() - -http_archive( - name = "rules_pkg", - sha256 = "cad05f864a32799f6f9022891de91ac78f30e0fa07dc68abac92a628121b5b11", - urls = [ - "https://github.com/bazelbuild/rules_pkg/releases/download/1.0.0/rules_pkg-1.0.0.tar.gz", - ], -) - -load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") - -rules_pkg_dependencies() - -http_archive( - name = "buildifier_prebuilt", - sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e", - strip_prefix = "buildifier-prebuilt-6.4.0", - urls = [ - "http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz", - ], -) - -load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") - -buildifier_prebuilt_deps() - -load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") - -buildifier_prebuilt_register_toolchains() - -http_archive( - name = "aspect_bazel_lib", - sha256 = "6d758a8f646ecee7a3e294fbe4386daafbe0e5966723009c290d493f227c390b", - strip_prefix = "bazel-lib-2.7.7", - url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.7/bazel-lib-v2.7.7.tar.gz", -) - -load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains") - -# Required bazel-lib dependencies - -aspect_bazel_lib_dependencies() - -# Register bazel-lib toolchains - -aspect_bazel_lib_register_toolchains() - -load("@bazeldnf//bazeldnf:toolchain.bzl", "bazeldnf_prebuilt_register_toolchains") - -bazeldnf_prebuilt_register_toolchains( - name = "bazeldnf_prebuilt", - register_toolchains = False, -) diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 0000000..868d8e9 --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1,13 @@ +workspace(name = "bazeldnf") + +load(":test_deps.bzl", "bazeldnf_test_dependencies") + +bazeldnf_test_dependencies() + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar") + +http_jar( + name = "protobuf-java", + integrity = "sha256-0C+GOpCj/8d9Xu7AMcGOV58wx8uY8/OoFP6LiMQ9O8g=", + urls = ["https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.27.3/protobuf-java-4.27.3.jar"], +) diff --git a/bazeldnf/BUILD.bazel b/bazeldnf/BUILD.bazel index a467dd9..b4c5df6 100644 --- a/bazeldnf/BUILD.bazel +++ b/bazeldnf/BUILD.bazel @@ -1,9 +1,75 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # this directory contains the public API from bazeldnf, anything on this directory # should be buildable withtout dev dependencies # # bazeldnf toolchain type toolchain_type( + name = "toolchain_type", + visibility = ["//visibility:public"], +) + +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + visibility = ["//visibility:public"], + deps = [ + "//internal:bazeldnf", + "//internal:rpm", + "//internal:rpmtree", + "//internal:xattrs", + ], +) + +bzl_library( + name = "deps", + srcs = ["deps.bzl"], + visibility = ["//visibility:public"], + deps = [":repositories"], +) + +bzl_library( + name = "extensions", + srcs = ["extensions.bzl"], + visibility = ["//visibility:public"], + deps = [ + ":repositories", + "//internal:rpm", + "@bazel_features//:features", + ], +) + +bzl_library( + name = "repositories", + srcs = ["repositories.bzl"], + visibility = ["//visibility:public"], + deps = [ + ":platforms", + "//bazeldnf/private:toolchains_repo", + "//tools:integrity", + "//tools:version", + "@bazel_tools//tools/build_defs/repo:http.bzl", + "@bazel_tools//tools/build_defs/repo:utils.bzl", + ], +) + +exports_files( + [ + "defs.bzl", + "deps.bzl", + ], + visibility = ["//:__subpackages__"], +) + +bzl_library( + name = "platforms", + srcs = ["platforms.bzl"], + visibility = ["//visibility:public"], +) + +bzl_library( name = "toolchain", + srcs = ["toolchain.bzl"], visibility = ["//visibility:public"], ) diff --git a/bazeldnf/defs.bzl b/bazeldnf/defs.bzl index 4680e46..c85c74b 100644 --- a/bazeldnf/defs.bzl +++ b/bazeldnf/defs.bzl @@ -3,20 +3,25 @@ Public API to use bazeldnf from other repositories """ load( - "@bazeldnf//internal:bazeldnf.bzl", + "//internal:bazeldnf.bzl", _bazeldnf = "bazeldnf", ) load( - "@bazeldnf//internal:rpmtree.bzl", + "//internal:rpm.bzl", + _rpm = "rpm", +) +load( + "//internal:rpmtree.bzl", _rpmtree = "rpmtree", _tar2files = "tar2files", ) load( - "@bazeldnf//internal:xattrs.bzl", + "//internal:xattrs.bzl", _xattrs = "xattrs", ) bazeldnf = _bazeldnf +rpm = _rpm rpmtree = _rpmtree tar2files = _tar2files xattrs = _xattrs diff --git a/bazeldnf/deps.bzl b/bazeldnf/deps.bzl index a46b0a3..e29247b 100644 --- a/bazeldnf/deps.bzl +++ b/bazeldnf/deps.bzl @@ -1,77 +1,12 @@ """bazeldnf public dependency for WORKSPACE""" load( - "@bazel_tools//tools/build_defs/repo:http.bzl", - "http_archive", - "http_file", + "//bazeldnf:repositories.bzl", + _bazeldnf_dependencies = "bazeldnf_dependencies", + _bazeldnf_register_toolchains = "bazeldnf_register_toolchains", ) -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load( - "@bazeldnf//internal:rpm.bzl", - _rpm = "rpm", -) - -rpm = _rpm -def bazeldnf_dependencies(): - """bazeldnf dependencies when consuming the repo externally""" - maybe( - http_archive, - name = "bazel_skylib", - sha256 = "f24ab666394232f834f74d19e2ff142b0af17466ea0c69a3f4c276ee75f6efce", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", - ], - ) - maybe( - http_archive, - name = "platforms", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", - "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", - ], - sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", - ) - http_file( - name = "bazeldnf-linux-amd64", - executable = True, - sha256 = "7e1035d8bd2f25b787b04843f4d6a05e7cdbd3995926497c2a587e52da6262a8", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-amd64"], - ) - http_file( - name = "bazeldnf-linux-arm64", - executable = True, - sha256 = "d954b785bfd79dbbd66a2f3df02b0d3a51f1fed4508a6d88fda13a9d24c878cc", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-arm64"], - ) - http_file( - name = "bazeldnf-darwin-amd64", - executable = True, - sha256 = "92afc7f6475981adf9ae32b563b051869d433d8d8c9666e28a1c1c6e840394cd", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-darwin-amd64"], - ) - http_file( - name = "bazeldnf-darwin-arm64", - executable = True, - sha256 = "c5e99ed72448026ee63259a0a28440f8b43a125414fa312edbd569c2976515a3", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-darwin-arm64"], - ) - http_file( - name = "bazeldnf-linux-ppc64", - executable = True, - sha256 = "9d5337c1afe4bab858742718ac4c230d9ca368299cb97c50078eef14ae180922", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-ppc64"], - ) - http_file( - name = "bazeldnf-linux-ppc64le", - executable = True, - sha256 = "7ea4db00947914bc1c51e8f042fe220a3167c65815c487eccd0c541ecfa78aa1", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-ppc64le"], - ) - http_file( - name = "bazeldnf-linux-s390x", - executable = True, - sha256 = "09aa4abcb1d85da11642889826b982ef90547eb32099fc8177456c92f66a4cfd", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-s390x"], - ) +def bazeldnf_dependencies(name = "bazeldnf", **kwargs): + """bazeldnf dependencies when consuming bazeldnf through WORKSPACE""" + _bazeldnf_dependencies() + _bazeldnf_register_toolchains(name = name, **kwargs) diff --git a/bazeldnf/extensions.bzl b/bazeldnf/extensions.bzl new file mode 100644 index 0000000..942f76f --- /dev/null +++ b/bazeldnf/extensions.bzl @@ -0,0 +1,206 @@ +"""Extensions for bzlmod. + +Installs the bazeldnf toolchain. + +based on: https://github.com/bazel-contrib/rules-template/blob/0dadcb716f06f672881681155fe6d9ff6fc4a4f4/mylang/extensions.bzl +""" + +load("@bazel_features//:features.bzl", "bazel_features") +load("//internal:rpm.bzl", rpm_repository = "rpm") +load(":repositories.bzl", "bazeldnf_register_toolchains") + +_ALIAS_TEMPLATE = """\ +alias( + name = "{name}", + actual = "@{name}//rpm", + visibility = ["//visibility:public"], +) +""" + +def _alias_repository_impl(repository_ctx): + """Creates a repository that aliases other repositories.""" + repository_ctx.file("WORKSPACE", "") + for rpm in repository_ctx.attr.rpms: + repo_name = rpm.repo_name + repository_ctx.file("%s/BUILD.bazel" % repo_name, _ALIAS_TEMPLATE.format(name = repo_name)) + +_alias_repository = repository_rule( + implementation = _alias_repository_impl, + attrs = { + "rpms": attr.label_list(), + }, +) + +_DEFAULT_NAME = "bazeldnf" + +def _handle_lock_file(lock_file, module_ctx): + content = module_ctx.read(lock_file) + lock_file_json = json.decode(content) + name = lock_file_json.get("name", lock_file.name.rsplit(".json", 1)[0]) + + rpms = [] + + for rpm in lock_file_json.get("rpms", []): + rpm_name = rpm.pop("name", None) + if not rpm_name: + urls = rpm.get("urls", []) + if len(urls) < 1: + fail("invalid entry in %s for %s" % (lock_file, rpm_name)) + rpm_name = urls[0].rsplit("/", 1)[-1] + rpm_repository(name = rpm_name, **rpm) + rpms.append(rpm_name) + + _alias_repository( + name = name, + rpms = ["@@%s//rpm" % x for x in rpms], + ) + + return name + +def _toolchain_extension(module_ctx): + repos = [] + + for mod in module_ctx.modules: + for toolchain in mod.tags.toolchain: + if toolchain.name != _DEFAULT_NAME and not mod.is_root: + fail("""\ + Only the root module may override the default name for the bazeldnf toolchain. + This prevents conflicting registrations in the global namespace of external repos. + """) + if mod.is_root and toolchain.disable: + break + bazeldnf_register_toolchains( + name = toolchain.name, + register = False, + ) + if mod.is_root: + repos.append(toolchain.name + "_toolchains") + + legacy = True + name = "bazeldnf_rpms" + for config in mod.tags.config: + if not config.legacy_mode: + legacy = False + name = config.name or name + if config.lock_file: + repos.append(_handle_lock_file(config.lock_file, module_ctx)) + + rpms = [] + + for rpm in mod.tags.rpm: + rpm_repository( + name = rpm.name, + urls = rpm.urls, + sha256 = rpm.sha256, + integrity = rpm.integrity, + ) + + if mod.is_root and legacy: + repos.append(rpm.name) + else: + rpms.append(rpm.name) + + if not legacy and rpms: + _alias_repository( + name = name, + rpms = ["@@%s//rpm" % x for x in rpms], + ) + repos.append(name) + + kwargs = {} + if bazel_features.external_deps.extension_metadata_has_reproducible: + kwargs["reproducible"] = True + + if module_ctx.root_module_has_non_dev_dependency: + kwargs["root_module_direct_deps"] = repos + kwargs["root_module_direct_dev_deps"] = [] + else: + kwargs["root_module_direct_deps"] = [] + kwargs["root_module_direct_dev_deps"] = repos + + return module_ctx.extension_metadata(**kwargs) + +_toolchain_tag = 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, + ), + "disable": attr.bool(default = False), + }, + doc = "Allows registering a prebuilt bazeldnf toolchain", +) + +_rpm_tag = tag_class( + attrs = { + "name": attr.string(doc = "Name of the generated repository"), + "urls": attr.string_list(doc = "URLs from which to download the RPM file"), + "sha256": attr.string(doc = """\ +The expected SHA-256 of the file downloaded. +This must match the SHA-256 of the file downloaded. +_It is a security risk to omit the SHA-256 as remote files can change._ +At best omitting this field will make your build non-hermetic. +It is optional to make development easier but either this attribute or +`integrity` should be set before shipping. +"""), + "integrity": attr.string(doc = """\ +Expected checksum in Subresource Integrity format of the file downloaded. +This must match the checksum of the file downloaded. +_It is a security risk to omit the checksum as remote files can change._ +At best omitting this field will make your build non-hermetic. +It is optional to make development easier but either this attribute or +`sha256` should be set before shipping. +"""), + }, + doc = "Allows registering a Bazel repository wrapping an RPM file", +) + +_config_tag = tag_class( + attrs = { + "legacy_mode": attr.bool( + default = True, + doc = """\ +If true, the module is loaded in legacy mode and exposes one Bazel repository \ +per rpm entry in this invocation of the bazel extension. +""", + ), + "name": attr.string( + doc = "Name of the generated proxy repository", + default = "bazeldnf_rpms", + ), + "lock_file": attr.label( + doc = """\ +Label of the JSON file that contains the RPMs to expose, there's no legacy mode \ +for RPMs defined by a lock file. + +The lock file content is as: +```json + { + "name": "optional name for the proxy repository, defaults to the file name", + "rpms": [ + { + "name": "", + "urls": ["", ...], + "sha256": "", + "integrity": "" + } + ] + } +``` +""", + allow_single_file = [".json"], + ), + }, +) + +bazeldnf = module_extension( + implementation = _toolchain_extension, + tag_classes = { + "toolchain": _toolchain_tag, + "rpm": _rpm_tag, + "config": _config_tag, + }, +) diff --git a/bazeldnf/platforms.bzl b/bazeldnf/platforms.bzl new file mode 100644 index 0000000..8860f88 --- /dev/null +++ b/bazeldnf/platforms.bzl @@ -0,0 +1,48 @@ +"Platforms definition for this repository" + +# Add more platforms as needed to mirror all the binaries +# published by the upstream project. +PLATFORMS = { + "darwin-amd64": struct( + compatible_with = [ + "@platforms//os:osx", + "@platforms//cpu:x86_64", + ], + ), + "darwin-arm64": struct( + compatible_with = [ + "@platforms//os:osx", + "@platforms//cpu:arm64", + ], + ), + "linux-amd64": struct( + compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + ), + "linux-arm64": struct( + compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:arm64", + ], + ), + "linux-ppc64": struct( + compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:ppc", + ], + ), + "linux-ppc64le": struct( + compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:ppc", + ], + ), + "linux-s390x": struct( + compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:s390x", + ], + ), +} diff --git a/bazeldnf/private/BUILD.bazel b/bazeldnf/private/BUILD.bazel new file mode 100644 index 0000000..4e46498 --- /dev/null +++ b/bazeldnf/private/BUILD.bazel @@ -0,0 +1,8 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "toolchains_repo", + srcs = ["toolchains_repo.bzl"], + visibility = ["//bazeldnf:__subpackages__"], + deps = ["//bazeldnf:platforms"], +) diff --git a/bazeldnf/private/toolchains_repo.bzl b/bazeldnf/private/toolchains_repo.bzl new file mode 100644 index 0000000..ad30b26 --- /dev/null +++ b/bazeldnf/private/toolchains_repo.bzl @@ -0,0 +1,57 @@ +"""Create a repository to hold the toolchains + +This follows guidance here: +https://docs.bazel.build/versions/main/skylark/deploying.html#registering-toolchains +" +Note that in order to resolve toolchains in the analysis phase +Bazel needs to analyze all toolchain targets that are registered. +Bazel will not need to analyze all targets referenced by toolchain.toolchain attribute. +If in order to register toolchains you need to perform complex computation in the repository, +consider splitting the repository with toolchain targets +from the repository with _toolchain targets. +Former will be always fetched, +and the latter will only be fetched when user actually needs to build code. +" +The "complex computation" in our case is simply downloading large artifacts. +This guidance tells us how to avoid that: we put the toolchain targets in the alias repository +with only the toolchain attribute pointing into the platform-specific repositories. +""" + +load("//bazeldnf:platforms.bzl", "PLATFORMS") + +def _toolchains_repo_impl(repository_ctx): + build_content = """# Generated by toolchains_repo.bzl +# +# These can be registered in the workspace file or passed to --extra_toolchains flag. +# By default all these toolchains are registered by the bazeldnf_register_toolchains macro +# so you don't normally need to interact with these targets. + +""" + + for [platform, meta] in PLATFORMS.items(): + build_content += """ +# Declare a toolchain Bazel will select for running the tool in an action +# on the execution platform. +toolchain( + name = "{platform}_toolchain", + exec_compatible_with = {compatible_with}, + toolchain = "@{user_repository_name}_{platform}//:bazeldnf_toolchain", + toolchain_type = "@bazeldnf//bazeldnf:toolchain_type", +) +""".format( + platform = platform, + user_repository_name = repository_ctx.attr.user_repository_name, + compatible_with = meta.compatible_with, + ) + + # Base BUILD file for this repository + repository_ctx.file("BUILD.bazel", build_content) + +toolchains_repo = repository_rule( + _toolchains_repo_impl, + doc = """Creates a repository with toolchain definitions for all known platforms + which can be registered or selected.""", + attrs = { + "user_repository_name": attr.string(doc = "what the user chose for the base name"), + }, +) diff --git a/bazeldnf/repositories.bzl b/bazeldnf/repositories.bzl new file mode 100644 index 0000000..f1424e3 --- /dev/null +++ b/bazeldnf/repositories.bzl @@ -0,0 +1,119 @@ +"""Declare runtime dependencies + +These are needed for local dev, and users must install them as well. +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:platforms.bzl", "PLATFORMS") +load("//bazeldnf/private:toolchains_repo.bzl", "toolchains_repo") +load("//tools:integrity.bzl", "INTEGRITY") +load("//tools:version.bzl", "REPO_URL", "VERSION") + +def http_archive(name, **kwargs): + maybe(_http_archive, name = name, **kwargs) + +# WARNING: any changes in this function may be BREAKING CHANGES for users +# because we'll fetch a dependency which may be different from one that +# they were previously fetching later in their WORKSPACE setup, and now +# ours took precedence. Such breakages are challenging for users, so any +# changes in this function should be marked as BREAKING in the commit message +# and released only in semver majors. +# This is all fixed by bzlmod, so we just tolerate it for now. +def bazeldnf_dependencies(): + http_archive( + name = "bazel_skylib", + sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", + ], + ) + http_archive( + name = "platforms", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", + ], + sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", + ) + +######## +# Remaining content of the file is only used to support toolchains. +######## +_DOC = "Fetch external tools needed for bazeldnf toolchain" +_ATTRS = { + "tool": attr.string(mandatory = True), +} + +def _bazeldnf_repo_impl(repository_ctx): + build_content = """# Generated by bazeldnf/repositories.bzl +load("@bazeldnf//bazeldnf:toolchain.bzl", "bazeldnf_toolchain") + +bazeldnf_toolchain( + name = "bazeldnf_toolchain", + tool = "@{0}//file", +) +""".format( + repository_ctx.attr.tool, + ) + + # Base BUILD file for this repository + repository_ctx.file("BUILD.bazel", build_content) + +bazeldnf_repositories = repository_rule( + _bazeldnf_repo_impl, + doc = _DOC, + attrs = _ATTRS, +) + +# Wrapper macro around everything above, this is the primary API +def bazeldnf_register_toolchains(name, register = True, **kwargs): + """Convenience macro for users which does typical setup. + + - create a repository for each built-in platform like "bazeldnf_linux_amd64" - + this repository is lazily fetched when node is needed for that platform. + - TODO: create a convenience repository for the host platform like "bazeldnf_host" + - create a repository exposing toolchains for each platform like "bazeldnf_platforms" + - register a toolchain pointing at each platform + Users can avoid this macro and do these steps themselves, if they want more control. + Args: + name: base name for all created repos, like "bazeldnf1_14" + register: whether to call through to native.register_toolchains. + Should be True for WORKSPACE users, but false when used under bzlmod extension + **kwargs: passed to each node_repositories call + """ + for platform in PLATFORMS.keys(): + name_ = "prebuilt-%s-%s" % (name, platform) + fname = "bazeldnf-{0}-{1}".format( + VERSION, + platform, + ) + integrity = INTEGRITY.get(platform, INTEGRITY.get(fname, None)) + if integrity == None: + print("WARNING: integrity checksum for {0} or {1} not found in INTEGRITY".format(fname, platform)) # buildifier: disable=print + continue + url = "https://github.com/{repo_url}/releases/download/{version}/{file_name}".format( + file_name = fname, + repo_url = REPO_URL, + version = VERSION, + ) + http_file( + name = name_, + sha256 = integrity, + executable = True, + url = url, + ) + bazeldnf_repositories( + name = "%s_%s" % (name, platform), + tool = name_, + **kwargs + ) + if register: + native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform)) + + toolchains_repo( + name = name + "_toolchains", + user_repository_name = name, + ) diff --git a/bazeldnf/toolchain.bzl b/bazeldnf/toolchain.bzl index 1d85fdb..d624709 100644 --- a/bazeldnf/toolchain.bzl +++ b/bazeldnf/toolchain.bzl @@ -3,7 +3,7 @@ def _bazeldnf_toolchain(ctx): return [ platform_common.ToolchainInfo( - _tool = ctx.executable.tool, + _tool = ctx.file.tool, ), ] @@ -13,84 +13,10 @@ bazeldnf_toolchain = rule( "tool": attr.label( allow_single_file = True, mandatory = True, - cfg = "exec", - executable = True, doc = "bazeldnf executable", ), }, provides = [platform_common.ToolchainInfo], ) -PLATFORMS = [ - "linux-amd64", - "linux-arm64", - "linux-ppc64", - "linux-ppc64le", - "linux-s390x", - "darwin-amd64", - "darwin-arm64", -] - -BAZELDNF_TOOLCHAIN = "@bazeldnf//bazeldnf:toolchain" - -def declare_toolchain(toolchain_prefix, os, arch): # buildifier: disable=unnamed-macro - """Create the custom and native toolchain for a platform - - Args: - toolchain_prefix: The tool the toolchain is being used for - os: The OS the toolchain is compatible with - arch: The arch the toolchain is compatible with - """ - - name = "%s-%s" % (os, arch) - bazeldnf_toolchain( - name = name, - tool = "@%s-%s//file" % (toolchain_prefix, name), - ) - - if os == "darwin": - os = "osx" - if arch == "amd64": - arch = "x86_64" - if arch == "ppc64": - arch = "ppc" - - native.toolchain( - name = name + "-toolchain", - toolchain_type = "@bazeldnf//bazeldnf:toolchain", - exec_compatible_with = [ - "@platforms//os:%s" % os, - "@platforms//cpu:%s" % arch, - ], - toolchain = name, - ) - -def _bazeldnf_prebuilt_setup_impl(repo_ctx): - toolchain_prefix = repo_ctx.attr.toolchain_prefix - build_bzl = 'load("@bazeldnf//bazeldnf:toolchain.bzl", "declare_toolchain")' - - for plat in PLATFORMS: - os, arch = plat.split("-") - build_bzl += '\ndeclare_toolchain( toolchain_prefix = "{toolchain_prefix}", os = "{os}", arch = "{arch}")'.format( - toolchain_prefix = toolchain_prefix, - os = os, - arch = arch, - ) - repo_ctx.file("BUILD.bazel", build_bzl) - -_bazeldnf_prebuilt_setup = repository_rule( - implementation = _bazeldnf_prebuilt_setup_impl, - attrs = { - "toolchain_prefix": attr.string(), - }, -) - -def bazeldnf_prebuilt_register_toolchains(name, toolchain_prefix = "bazeldnf", register_toolchains = True): - _bazeldnf_prebuilt_setup( - name = name, - toolchain_prefix = toolchain_prefix, - ) - - if register_toolchains: - toolchains = ["@%s//:%s-toolchain" % (name, x) for x in PLATFORMS] - native.register_toolchains(*toolchains) +BAZELDNF_TOOLCHAIN = "@bazeldnf//bazeldnf:toolchain_type" diff --git a/cmd/BUILD.bazel b/cmd/BUILD.bazel index 1921280..ee71840 100644 --- a/cmd/BUILD.bazel +++ b/cmd/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("@rules_go//go:def.bzl", "go_binary", "go_library") load("//bazeldnf:toolchain.bzl", "bazeldnf_toolchain") go_library( @@ -35,10 +35,10 @@ go_library( "//pkg/sat", "//pkg/xattr", "@com_github_bazelbuild_buildtools//build:go_default_library", - "@com_github_sassoftware_go_rpmutils//:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", - "@com_github_spf13_cobra//:go_default_library", - "@org_golang_x_crypto//openpgp:go_default_library", + "@com_github_sassoftware_go_rpmutils//:go-rpmutils", + "@com_github_sirupsen_logrus//:logrus", + "@com_github_spf13_cobra//:cobra", + "@org_golang_x_crypto//openpgp", ], ) @@ -57,5 +57,5 @@ bazeldnf_toolchain( toolchain( name = "bazeldnf-host-toolchain", toolchain = ":host-toolchain", - toolchain_type = "//bazeldnf:toolchain", + toolchain_type = "//bazeldnf:toolchain_type", ) diff --git a/cmd/template/BUILD.bazel b/cmd/template/BUILD.bazel index 424dbc2..34205e9 100644 --- a/cmd/template/BUILD.bazel +++ b/cmd/template/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@rules_go//go:def.bzl", "go_library") go_library( name = "template", diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel new file mode 100644 index 0000000..1e72287 --- /dev/null +++ b/docs/BUILD.bazel @@ -0,0 +1,23 @@ +load("@stardoc//stardoc:stardoc.bzl", "stardoc") + +stardoc( + name = "defs", + out = "defs.md", + input = "//bazeldnf:defs.bzl", + deps = [ + "//internal:bazeldnf", + "//internal:rpm", + "//internal:rpmtree", + "//internal:xattrs", + ], +) + +stardoc( + name = "deps", + out = "deps.md", + input = "//bazeldnf:deps.bzl", + deps = [ + "//bazeldnf:repositories", + "@bazel_tools//tools/build_defs/repo:cache.bzl", + ], +) diff --git a/e2e/bazel-bzlmod-lock-file/.bazelrc b/e2e/bazel-bzlmod-lock-file/.bazelrc new file mode 100644 index 0000000..b69c65e --- /dev/null +++ b/e2e/bazel-bzlmod-lock-file/.bazelrc @@ -0,0 +1,17 @@ +# Import Aspect bazelrc presets +try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc +import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc +import %workspace%/../../.aspect/bazelrc/convenience.bazelrc +import %workspace%/../../.aspect/bazelrc/correctness.bazelrc +import %workspace%/../../.aspect/bazelrc/debug.bazelrc +import %workspace%/../../.aspect/bazelrc/performance.bazelrc + +common --enable_bzlmod + +# Specific project flags go here if we have some + +# Load any settings & overrides specific to the current user from `.bazelrc.user`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/../../.bazelrc.user diff --git a/e2e/bazel-bzlmod-lock-file/BUILD.bazel b/e2e/bazel-bzlmod-lock-file/BUILD.bazel new file mode 100644 index 0000000..19407b7 --- /dev/null +++ b/e2e/bazel-bzlmod-lock-file/BUILD.bazel @@ -0,0 +1,37 @@ +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +bazeldnf( + name = "bazeldnf", +) + +rpmtree( + name = "something", + rpms = [ + "@bazeldnf-rpms//libvirt-libs", + "@bazeldnf-rpms//libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + "@rpms-with-no-name-attribute//libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + ], +) + +tar2files( + name = "something_libs", + files = { + "/usr/lib64": [ + "libvirt.so.0", + "libvirt.so.0.6001.0", + ], + }, + tar = ":something", + visibility = ["//visibility:public"], +) + +pkg_tar( + name = "whatever", + deps = [":something"], +) + +cc_library( + name = "bar", + srcs = ["//:something_libs/usr/lib64"], +) diff --git a/e2e/bazel-bzlmod-lock-file/MODULE.bazel b/e2e/bazel-bzlmod-lock-file/MODULE.bazel new file mode 100644 index 0000000..314effc --- /dev/null +++ b/e2e/bazel-bzlmod-lock-file/MODULE.bazel @@ -0,0 +1,20 @@ +"example MODULE.bazel to test bzlmod integration for bazeldnf with a prebuilt toolchain" + +module(name = "example-bazeldnf-with-bzlmod-lock-file") + +bazel_dep(name = "bazeldnf") +local_path_override( + module_name = "bazeldnf", + path = "../..", +) + +bazel_dep(name = "rules_pkg", version = "1.0.1") + +bazeldnf = use_extension("@bazeldnf//bazeldnf:extensions.bzl", "bazeldnf") +bazeldnf.config(lock_file = "//:rpms.json") +bazeldnf.config(lock_file = "//:rpms-with-no-name-attribute.json") +use_repo( + bazeldnf, + "bazeldnf-rpms", + "rpms-with-no-name-attribute", +) diff --git a/e2e/bazel-bzlmod-lock-file/WORKSPACE.bzlmod b/e2e/bazel-bzlmod-lock-file/WORKSPACE.bzlmod new file mode 100644 index 0000000..e69de29 diff --git a/e2e/bazel-bzlmod-lock-file/rpms-with-no-name-attribute.json b/e2e/bazel-bzlmod-lock-file/rpms-with-no-name-attribute.json new file mode 100644 index 0000000..0f59f68 --- /dev/null +++ b/e2e/bazel-bzlmod-lock-file/rpms-with-no-name-attribute.json @@ -0,0 +1,12 @@ +{ + "rpms": [ + { + "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" + ] + + } + ] +} diff --git a/e2e/bazel-bzlmod-lock-file/rpms.json b/e2e/bazel-bzlmod-lock-file/rpms.json new file mode 100644 index 0000000..b6f2859 --- /dev/null +++ b/e2e/bazel-bzlmod-lock-file/rpms.json @@ -0,0 +1,21 @@ +{ + "name": "bazeldnf-rpms", + "rpms": [ + { + "name": "libvirt-libs", + "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" + ] + + }, + { + "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" + ] + } + ] +} diff --git a/e2e/bazel-bzlmod-non-legacy-mode/.bazelrc b/e2e/bazel-bzlmod-non-legacy-mode/.bazelrc new file mode 100644 index 0000000..b69c65e --- /dev/null +++ b/e2e/bazel-bzlmod-non-legacy-mode/.bazelrc @@ -0,0 +1,17 @@ +# Import Aspect bazelrc presets +try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc +import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc +import %workspace%/../../.aspect/bazelrc/convenience.bazelrc +import %workspace%/../../.aspect/bazelrc/correctness.bazelrc +import %workspace%/../../.aspect/bazelrc/debug.bazelrc +import %workspace%/../../.aspect/bazelrc/performance.bazelrc + +common --enable_bzlmod + +# Specific project flags go here if we have some + +# Load any settings & overrides specific to the current user from `.bazelrc.user`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/../../.bazelrc.user diff --git a/e2e/bazel-bzlmod-non-legacy-mode/BUILD.bazel b/e2e/bazel-bzlmod-non-legacy-mode/BUILD.bazel new file mode 100644 index 0000000..768c7a2 --- /dev/null +++ b/e2e/bazel-bzlmod-non-legacy-mode/BUILD.bazel @@ -0,0 +1,36 @@ +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +bazeldnf( + name = "bazeldnf", +) + +rpmtree( + name = "something", + rpms = [ + "@bazeldnf_rpms//libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + "@bazeldnf_rpms//libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + ], +) + +tar2files( + name = "something_libs", + files = { + "/usr/lib64": [ + "libvirt.so.0", + "libvirt.so.0.6001.0", + ], + }, + tar = ":something", + visibility = ["//visibility:public"], +) + +pkg_tar( + name = "whatever", + deps = [":something"], +) + +cc_library( + name = "bar", + srcs = ["//:something_libs/usr/lib64"], +) diff --git a/e2e/bazel-bzlmod-non-legacy-mode/MODULE.bazel b/e2e/bazel-bzlmod-non-legacy-mode/MODULE.bazel new file mode 100644 index 0000000..916e7ce --- /dev/null +++ b/e2e/bazel-bzlmod-non-legacy-mode/MODULE.bazel @@ -0,0 +1,31 @@ +"example MODULE.bazel to test bzlmod integration for bazeldnf with a prebuilt toolchain" + +module(name = "example-bazeldnf-with-bzlmod-non-legacy-mode") + +bazel_dep(name = "bazeldnf") +local_path_override( + module_name = "bazeldnf", + path = "../..", +) + +bazel_dep(name = "rules_pkg", version = "1.0.1") + +bazeldnf = use_extension("@bazeldnf//bazeldnf:extensions.bzl", "bazeldnf") +bazeldnf.config(legacy_mode = False) +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-bzlmod-non-legacy-mode/WORKSPACE.bzlmod b/e2e/bazel-bzlmod-non-legacy-mode/WORKSPACE.bzlmod new file mode 100644 index 0000000..e69de29 diff --git a/e2e/bazel-bzlmod-toolchain-from-source/.bazelrc b/e2e/bazel-bzlmod-toolchain-from-source/.bazelrc new file mode 100644 index 0000000..c123ab2 --- /dev/null +++ b/e2e/bazel-bzlmod-toolchain-from-source/.bazelrc @@ -0,0 +1,17 @@ +# Import Aspect bazelrc presets +try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc +import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc +import %workspace%/../../.aspect/bazelrc/convenience.bazelrc +import %workspace%/../../.aspect/bazelrc/correctness.bazelrc +import %workspace%/../../.aspect/bazelrc/debug.bazelrc +import %workspace%/../../.aspect/bazelrc/performance.bazelrc + +# Specific project flags go here if we have some +common --enable_bzlmod +common --extra_toolchains=@bazeldnf//cmd:bazeldnf-host-toolchain + +# Load any settings & overrides specific to the current user from `.bazelrc.user`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/../../.bazelrc.user diff --git a/e2e/bazel-bzlmod-toolchain-from-source/BUILD.bazel b/e2e/bazel-bzlmod-toolchain-from-source/BUILD.bazel new file mode 100644 index 0000000..48e40e6 --- /dev/null +++ b/e2e/bazel-bzlmod-toolchain-from-source/BUILD.bazel @@ -0,0 +1,36 @@ +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +bazeldnf( + name = "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", + ], +) + +tar2files( + name = "something_libs", + files = { + "/usr/lib64": [ + "libvirt.so.0", + "libvirt.so.0.6001.0", + ], + }, + tar = ":something", + visibility = ["//visibility:public"], +) + +pkg_tar( + name = "whatever", + deps = [":something"], +) + +cc_library( + name = "bar", + srcs = ["//:something_libs/usr/lib64"], +) diff --git a/e2e/bazel-bzlmod-toolchain-from-source/MODULE.bazel b/e2e/bazel-bzlmod-toolchain-from-source/MODULE.bazel new file mode 100644 index 0000000..0ab6549 --- /dev/null +++ b/e2e/bazel-bzlmod-toolchain-from-source/MODULE.bazel @@ -0,0 +1,52 @@ +"example MODULE.bazel to test bzlmod integration for bazeldnf with a prebuilt toolchain" + +module(name = "example-bazeldnf-bzlmod-toolchain-from-source") + +bazel_dep(name = "bazeldnf", dev_dependency = True) +local_path_override( + module_name = "bazeldnf", + path = "../..", +) + +bazel_dep(name = "rules_pkg", version = "1.0.1") +bazel_dep(name = "rules_go", version = "0.49.0", repo_name = "rules_go") +bazel_dep(name = "gazelle", version = "0.37.0") +bazel_dep(name = "toolchains_protoc", version = "0.3.2") + +go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") +go_deps.from_file(go_mod = "@bazeldnf//:go.mod") +use_repo( + go_deps, + "com_github_bazelbuild_buildtools", + "com_github_crillab_gophersat", + "com_github_onsi_gomega", + "com_github_sassoftware_go_rpmutils", + "com_github_sirupsen_logrus", + "com_github_spf13_cobra", + "io_k8s_sigs_yaml", + "org_golang_x_crypto", +) + +bazeldnf = use_extension("@bazeldnf//bazeldnf:extensions.bzl", "bazeldnf") +bazeldnf.toolchain(disable = True) +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, + "libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + "libvirt-libs-6.1.0-2.fc32.x86_64.rpm", +) diff --git a/e2e/bazel-bzlmod-toolchain-from-source/WORKSPACE b/e2e/bazel-bzlmod-toolchain-from-source/WORKSPACE new file mode 100644 index 0000000..e69de29 diff --git a/e2e/bazel-bzlmod/.bazelrc b/e2e/bazel-bzlmod/.bazelrc new file mode 100644 index 0000000..b69c65e --- /dev/null +++ b/e2e/bazel-bzlmod/.bazelrc @@ -0,0 +1,17 @@ +# Import Aspect bazelrc presets +try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc +import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc +import %workspace%/../../.aspect/bazelrc/convenience.bazelrc +import %workspace%/../../.aspect/bazelrc/correctness.bazelrc +import %workspace%/../../.aspect/bazelrc/debug.bazelrc +import %workspace%/../../.aspect/bazelrc/performance.bazelrc + +common --enable_bzlmod + +# Specific project flags go here if we have some + +# Load any settings & overrides specific to the current user from `.bazelrc.user`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/../../.bazelrc.user diff --git a/e2e/bazel-bzlmod/BUILD.bazel b/e2e/bazel-bzlmod/BUILD.bazel new file mode 100644 index 0000000..48e40e6 --- /dev/null +++ b/e2e/bazel-bzlmod/BUILD.bazel @@ -0,0 +1,36 @@ +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +bazeldnf( + name = "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", + ], +) + +tar2files( + name = "something_libs", + files = { + "/usr/lib64": [ + "libvirt.so.0", + "libvirt.so.0.6001.0", + ], + }, + tar = ":something", + visibility = ["//visibility:public"], +) + +pkg_tar( + name = "whatever", + deps = [":something"], +) + +cc_library( + name = "bar", + srcs = ["//:something_libs/usr/lib64"], +) diff --git a/e2e/bazel-bzlmod/MODULE.bazel b/e2e/bazel-bzlmod/MODULE.bazel new file mode 100644 index 0000000..2b67e15 --- /dev/null +++ b/e2e/bazel-bzlmod/MODULE.bazel @@ -0,0 +1,34 @@ +"example MODULE.bazel to test bzlmod integration for bazeldnf with a prebuilt toolchain" + +module(name = "example-bazeldnf-with-bzlmod") + +bazel_dep(name = "bazeldnf") +local_path_override( + module_name = "bazeldnf", + path = "../..", +) + +bazel_dep(name = "rules_pkg", version = "1.0.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, + "libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + "libvirt-libs-6.1.0-2.fc32.x86_64.rpm", +) diff --git a/e2e/bazel-bzlmod/WORKSPACE.bzlmod b/e2e/bazel-bzlmod/WORKSPACE.bzlmod new file mode 100644 index 0000000..e69de29 diff --git a/e2e/bazel-workspace/WORKSPACE b/e2e/bazel-workspace/WORKSPACE index 2e6ce02..c748172 100644 --- a/e2e/bazel-workspace/WORKSPACE +++ b/e2e/bazel-workspace/WORKSPACE @@ -1,23 +1,27 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - local_repository( name = "bazeldnf", path = "../../", ) -load("@bazeldnf//bazeldnf:deps.bzl", "bazeldnf_dependencies") +load( + "@bazeldnf//bazeldnf:repositories.bzl", + "bazeldnf_dependencies", + "bazeldnf_register_toolchains", +) bazeldnf_dependencies() -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() +bazeldnf_register_toolchains( + name = "bazeldnf_prebuilt", +) # dependencies for integration tests load("@bazeldnf//:test_deps.bzl", "bazeldnf_test_dependencies") bazeldnf_test_dependencies() +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + http_archive( name = "rules_pkg", sha256 = "cad05f864a32799f6f9022891de91ac78f30e0fa07dc68abac92a628121b5b11", @@ -29,7 +33,3 @@ http_archive( load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies() - -load("@bazeldnf//bazeldnf:toolchain.bzl", "bazeldnf_prebuilt_register_toolchains") - -bazeldnf_prebuilt_register_toolchains(name = "bazeldnf_prebuilt") diff --git a/go.mod b/go.mod index 6514216..fcddc6c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/rmohr/bazeldnf go 1.19 require ( - github.com/bazelbuild/buildtools v0.0.0-20230127124510-cf446296fb76 + github.com/bazelbuild/buildtools v0.0.0-20240823132350-3488089d3661 github.com/crillab/gophersat v1.3.1 github.com/onsi/gomega v1.26.0 github.com/sassoftware/go-rpmutils v0.2.0 diff --git a/go.sum b/go.sum index f75c35d..bd57843 100644 --- a/go.sum +++ b/go.sum @@ -1,41 +1,15 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/bazelbuild/buildtools v0.0.0-20230127124510-cf446296fb76 h1:DQ4RKicYtQ0KmtM6+PhBbMhd+qaazxi/8FuZoD7a1Zo= -github.com/bazelbuild/buildtools v0.0.0-20230127124510-cf446296fb76/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/bazelbuild/buildtools v0.0.0-20240823132350-3488089d3661 h1:acJJwAuD2t36RHnvxf3oh9lhg5LISUYXunx+om2ONZw= +github.com/bazelbuild/buildtools v0.0.0-20240823132350-3488089d3661/go.mod h1:yBQGNvRAGhcBTxe4MHiW3Ul7DwoBim4XsKUaXnW1LWc= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/crillab/gophersat v1.3.1 h1:l4fgnEMmy1+b7pn3nvPwj1ja3Z9MgXE4hUIl9TU8v+M= github.com/crillab/gophersat v1.3.1/go.mod h1:S91tHga1PCZzYhCkStwZAhvp1rCc+zqtSi55I+vDWGc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -48,7 +22,6 @@ github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q= github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rmohr/go-rpmutils v0.1.2-0.20201215123907-5acf7436c00d h1:IPm+rJWi7P9mkoFQjloDEGThxlM71dzDrC2DZSjgnL8= github.com/rmohr/go-rpmutils v0.1.2-0.20201215123907-5acf7436c00d/go.mod h1:+IkA78IVx67OWHxozgXevwH3PECuQI13uwsEV80ar/U= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -63,63 +36,24 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= -go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20221012134737-56aed061732a h1:NmSIgad6KjE6VvHciPZuNRTKxGhlPfD6OA87W/PLkqg= golang.org/x/crypto v0.0.0-20221012134737-56aed061732a/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= @@ -129,7 +63,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/hack/prepare-release.sh b/hack/prepare-release.sh deleted file mode 100755 index 664bdec..0000000 --- a/hack/prepare-release.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash - -set -e -o pipefail -u - -echo >&2 "Preparing bazeldnf ${VERSION} release" - -BASE_DIR="$( - cd "$(dirname "$BASH_SOURCE[0]")/../" - pwd -)" - -rm -rf dist -mkdir -p dist - -function build_arch() { - os=$1 - arch=$2 - - bazel build --platforms=@io_bazel_rules_go//go/toolchain:${os}_${arch} //cmd - cp -L bazel-bin/cmd/cmd_/cmd dist/bazeldnf-${VERSION}-${os}-${arch} -} - -function write_arch() { - os=$1 - arch=$2 - - DIGEST=$(sha256sum dist/bazeldnf-${VERSION}-${os}-${arch} | cut -d " " -f 1) - cat <>bazeldnf/deps.bzl - http_file( - name = "bazeldnf-${os}-${arch}", - executable = True, - sha256 = "${DIGEST}", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/${VERSION}/bazeldnf-${VERSION}-${os}-${arch}"], - ) -EOT - -} - -build_arch linux amd64 -build_arch linux arm64 -build_arch darwin amd64 -build_arch darwin arm64 -build_arch linux ppc64 -build_arch linux ppc64le -build_arch linux s390x - -cat <bazeldnf/deps.bzl -"""bazeldnf public dependency for WORKSPACE""" - -load( - "@bazel_tools//tools/build_defs/repo:http.bzl", - "http_archive", - "http_file", -) -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load( - "@bazeldnf//internal:rpm.bzl", - _rpm = "rpm", -) - -rpm = _rpm - -def bazeldnf_dependencies(): - """bazeldnf dependencies when consuming the repo externally""" - maybe( - http_archive, - name = "bazel_skylib", - sha256 = "f24ab666394232f834f74d19e2ff142b0af17466ea0c69a3f4c276ee75f6efce", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", - ], - ) - maybe( - http_archive, - name = "platforms", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", - "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", - ], - sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", - ) -EOT - -write_arch linux amd64 -write_arch linux arm64 -write_arch darwin amd64 -write_arch darwin arm64 -write_arch linux ppc64 -write_arch linux ppc64le -write_arch linux s390x - -git commit -a -m "Bump prebuilt binary references for ${VERSION}" - -git tag ${VERSION} - -git archive --format tar.gz HEAD >./dist/bazeldnf-${VERSION}.tar.gz - -DIGEST=$(sha256sum dist/bazeldnf-${VERSION}.tar.gz | cut -d " " -f 1) - -cat <>./dist/releasenote.txt -\`\`\`python -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "bazeldnf", - sha256 = "${DIGEST}", - urls = [ - "https://github.com/rmohr/bazeldnf/releases/download/${VERSION}/bazeldnf-${VERSION}.tar.gz", - ], -) - -load("@bazeldnf//bazeldnf:deps.bzl", "bazeldnf_dependencies") - -bazeldnf_dependencies() -\`\`\` -EOT - -# Only update the README if we don't build a release candidate -if [[ "${VERSION}" != *"-rc"* ]]; then - - lead='^$' - tail='^$' - sed -i -e "/$lead/,/$tail/{ /$lead/{p; r dist/releasenote.txt - }; /$tail/p; d }" README.md - - git commit -a -m "Bump install instructions for readme in ${VERSION}" -fi diff --git a/internal/BUILD.bazel b/internal/BUILD.bazel index 3ec3633..1cf40ab 100644 --- a/internal/BUILD.bazel +++ b/internal/BUILD.bazel @@ -1 +1,33 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + exports_files(["runner.bash.template"]) + +bzl_library( + name = "bazeldnf", + srcs = ["bazeldnf.bzl"], + visibility = ["//:__subpackages__"], + deps = [ + "@bazel_skylib//lib:shell", + ], +) + +bzl_library( + name = "rpm", + srcs = ["rpm.bzl"], + visibility = ["//:__subpackages__"], + deps = ["@bazel_tools//tools/build_defs/repo:utils.bzl"], +) + +bzl_library( + name = "rpmtree", + srcs = ["rpmtree.bzl"], + visibility = ["//:__subpackages__"], + deps = ["//bazeldnf:toolchain"], +) + +bzl_library( + name = "xattrs", + srcs = ["xattrs.bzl"], + visibility = ["//:__subpackages__"], + deps = ["//bazeldnf:toolchain"], +) diff --git a/internal/rpm.bzl b/internal/rpm.bzl index 429d519..d619883 100644 --- a/internal/rpm.bzl +++ b/internal/rpm.bzl @@ -41,7 +41,6 @@ def _rpm_impl(ctx): _rpm_attrs = { "urls": attr.string_list(), - "strip_prefix": attr.string(), "sha256": attr.string(), "integrity": attr.string(), } diff --git a/pkg/api/BUILD.bazel b/pkg/api/BUILD.bazel index 00f5c7c..703d702 100644 --- a/pkg/api/BUILD.bazel +++ b/pkg/api/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@rules_go//go:def.bzl", "go_library") go_library( name = "api", diff --git a/pkg/api/bazeldnf/BUILD.bazel b/pkg/api/bazeldnf/BUILD.bazel index c738eac..3176fe7 100644 --- a/pkg/api/bazeldnf/BUILD.bazel +++ b/pkg/api/bazeldnf/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@rules_go//go:def.bzl", "go_library") go_library( name = "bazeldnf", diff --git a/pkg/bazel/BUILD.bazel b/pkg/bazel/BUILD.bazel index a80fd3a..be333c8 100644 --- a/pkg/bazel/BUILD.bazel +++ b/pkg/bazel/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "bazel", @@ -20,6 +20,6 @@ go_test( deps = [ "//pkg/api", "//pkg/api/bazeldnf", - "@com_github_onsi_gomega//:go_default_library", + "@com_github_onsi_gomega//:gomega", ], ) diff --git a/pkg/ldd/BUILD.bazel b/pkg/ldd/BUILD.bazel index 0016fef..f160881 100644 --- a/pkg/ldd/BUILD.bazel +++ b/pkg/ldd/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@rules_go//go:def.bzl", "go_library") go_library( name = "ldd", diff --git a/pkg/order/BUILD.bazel b/pkg/order/BUILD.bazel index 9d62287..ea1d828 100644 --- a/pkg/order/BUILD.bazel +++ b/pkg/order/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "order", @@ -7,7 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/rpm", - "@com_github_sassoftware_go_rpmutils//cpio:go_default_library", + "@com_github_sassoftware_go_rpmutils//cpio", ], ) @@ -15,5 +15,5 @@ go_test( name = "order_test", srcs = ["order_test.go"], embed = [":order"], - deps = ["@com_github_onsi_gomega//:go_default_library"], + deps = ["@com_github_onsi_gomega//:gomega"], ) diff --git a/pkg/reducer/BUILD.bazel b/pkg/reducer/BUILD.bazel index 96b24b5..9678537 100644 --- a/pkg/reducer/BUILD.bazel +++ b/pkg/reducer/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@rules_go//go:def.bzl", "go_library") go_library( name = "reducer", @@ -12,6 +12,6 @@ go_library( "//pkg/api", "//pkg/api/bazeldnf", "//pkg/repo", - "@com_github_sirupsen_logrus//:go_default_library", + "@com_github_sirupsen_logrus//:logrus", ], ) diff --git a/pkg/repo/BUILD.bazel b/pkg/repo/BUILD.bazel index d7070fd..4ce6534 100644 --- a/pkg/repo/BUILD.bazel +++ b/pkg/repo/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "repo", @@ -13,8 +13,8 @@ go_library( "//pkg/api", "//pkg/api/bazeldnf", "//pkg/rpm", - "@com_github_sirupsen_logrus//:go_default_library", - "@io_k8s_sigs_yaml//:go_default_library", + "@com_github_sirupsen_logrus//:logrus", + "@io_k8s_sigs_yaml//:yaml", ], ) diff --git a/pkg/rpm/BUILD.bazel b/pkg/rpm/BUILD.bazel index dcadfc7..a541b3b 100644 --- a/pkg/rpm/BUILD.bazel +++ b/pkg/rpm/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "rpm", @@ -12,9 +12,9 @@ go_library( deps = [ "//pkg/api", "//pkg/xattr", - "@com_github_sassoftware_go_rpmutils//:go_default_library", - "@com_github_sassoftware_go_rpmutils//cpio:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", + "@com_github_sassoftware_go_rpmutils//:go-rpmutils", + "@com_github_sassoftware_go_rpmutils//cpio", + "@com_github_sirupsen_logrus//:logrus", ], ) @@ -28,6 +28,6 @@ go_test( embed = [":rpm"], deps = [ "//pkg/api", - "@com_github_onsi_gomega//:go_default_library", + "@com_github_onsi_gomega//:gomega", ], ) diff --git a/pkg/sat/BUILD.bazel b/pkg/sat/BUILD.bazel index 5b3d298..1f41a51 100644 --- a/pkg/sat/BUILD.bazel +++ b/pkg/sat/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "sat", @@ -9,10 +9,10 @@ go_library( "//pkg/api", "//pkg/reducer", "//pkg/rpm", - "@com_github_crillab_gophersat//bf:go_default_library", - "@com_github_crillab_gophersat//explain:go_default_library", - "@com_github_crillab_gophersat//maxsat:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", + "@com_github_crillab_gophersat//bf", + "@com_github_crillab_gophersat//explain", + "@com_github_crillab_gophersat//maxsat", + "@com_github_sirupsen_logrus//:logrus", ], ) @@ -23,6 +23,6 @@ go_test( embed = [":sat"], deps = [ "//pkg/api", - "@com_github_onsi_gomega//:go_default_library", + "@com_github_onsi_gomega//:gomega", ], ) diff --git a/pkg/xattr/BUILD.bazel b/pkg/xattr/BUILD.bazel index de1588c..a166a7f 100644 --- a/pkg/xattr/BUILD.bazel +++ b/pkg/xattr/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "xattr", @@ -12,5 +12,5 @@ go_test( srcs = ["xattr_test.go"], data = glob(["testdata/**"]), embed = [":xattr"], - deps = ["@com_github_onsi_gomega//:go_default_library"], + deps = ["@com_github_onsi_gomega//:gomega"], ) diff --git a/test_deps.bzl b/test_deps.bzl index 1c788f1..8f22b65 100644 --- a/test_deps.bzl +++ b/test_deps.bzl @@ -1,6 +1,6 @@ "bazeldnf repo integration test dependencies" -load("@bazeldnf//bazeldnf:deps.bzl", "rpm") +load("@bazeldnf//bazeldnf:defs.bzl", "rpm") def bazeldnf_test_dependencies(): rpm( diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel new file mode 100644 index 0000000..21c8b59 --- /dev/null +++ b/tools/BUILD.bazel @@ -0,0 +1,13 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "integrity", + srcs = ["integrity.bzl"], + visibility = ["//visibility:public"], +) + +bzl_library( + name = "version", + srcs = ["version.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tools/integrity.bzl b/tools/integrity.bzl new file mode 100644 index 0000000..81b6e9c --- /dev/null +++ b/tools/integrity.bzl @@ -0,0 +1,11 @@ +"Generated during release by release_prep.sh, using integrity.jq" + +INTEGRITY = { + "darwin-amd64": "92afc7f6475981adf9ae32b563b051869d433d8d8c9666e28a1c1c6e840394cd", + "darwin-arm64": "c5e99ed72448026ee63259a0a28440f8b43a125414fa312edbd569c2976515a3", + "linux-amd64": "7e1035d8bd2f25b787b04843f4d6a05e7cdbd3995926497c2a587e52da6262a8", + "linux-arm64": "d954b785bfd79dbbd66a2f3df02b0d3a51f1fed4508a6d88fda13a9d24c878cc", + "linux-ppc64": "9d5337c1afe4bab858742718ac4c230d9ca368299cb97c50078eef14ae180922", + "linux-ppc64le": "7ea4db00947914bc1c51e8f042fe220a3167c65815c487eccd0c541ecfa78aa1", + "linux-s390x": "09aa4abcb1d85da11642889826b982ef90547eb32099fc8177456c92f66a4cfd", +} diff --git a/tools/release/BUILD.bazel b/tools/release/BUILD.bazel new file mode 100644 index 0000000..04733b7 --- /dev/null +++ b/tools/release/BUILD.bazel @@ -0,0 +1,17 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load(":defs.bzl", "build_for_all_platforms") + +build_for_all_platforms(name = "release") + +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + visibility = ["//visibility:public"], + deps = [ + "//bazeldnf:platforms", + "//tools:version", + "@aspect_bazel_lib//lib:copy_file", + "@aspect_bazel_lib//lib:transitions", + "@aspect_bazel_lib//lib:write_source_files", + ], +) diff --git a/tools/release/defs.bzl b/tools/release/defs.bzl new file mode 100644 index 0000000..d2e8e30 --- /dev/null +++ b/tools/release/defs.bzl @@ -0,0 +1,63 @@ +"Make releases for platforms supported by bazeldnf" + +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("//bazeldnf:platforms.bzl", "PLATFORMS") +load("//tools:version.bzl", "VERSION") + +# buildozer: disable=function-docstring +def build_for_platform(name, value): + # define a target platform first because we may not have one + native.platform( + name = name, + constraint_values = value.compatible_with, + visibility = ["//visibility:public"], + ) + + # create a binary for the target platform + build = "bazeldnf_{}_build".format(name) + platform_transition_filegroup( + name = build, + srcs = ["@bazeldnf//cmd"], + target_platform = ":{}".format(name), + ) + + _version = VERSION + + if _version.startswith("v"): + _version = _version[1:] + + artifact = "bazeldnf-v{version}-{platform}".format( + version = _version, + platform = name, + ) + copy_file( + name = "copy_{}".format(build), + src = build, + out = artifact, + ) + + # compuate the sha256 of the binary + hashes( + name = "{}.sha256".format(artifact), + src = artifact, + ) + + return [artifact, "{}.sha256".format(artifact)] + +# buildozer: disable=function-docstring +def build_for_all_platforms(name, **kwargs): + outs = [] + + for k, v in PLATFORMS.items(): + outs.extend(build_for_platform(name = k, value = v)) + + write_source_files( + name = name, + files = dict([["latest/{}".format(x), ":{0}".format(x)] for x in outs]), + diff_test = False, + check_that_out_file_exists = False, + **kwargs + ) diff --git a/tools/toolchains/BUILD.bazel b/tools/toolchains/BUILD.bazel new file mode 100644 index 0000000..33ba248 --- /dev/null +++ b/tools/toolchains/BUILD.bazel @@ -0,0 +1,9 @@ +load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") + +proto_lang_toolchain( + name = "protoc_java_toolchain", + command_line = "--java_out=%s", + progress_message = "Generating Java proto_library %{label}", + runtime = "@protobuf-java//jar", + toolchain_type = "@rules_java//java/proto:toolchain_type", +) diff --git a/tools/version.bzl b/tools/version.bzl new file mode 100644 index 0000000..4a47875 --- /dev/null +++ b/tools/version.bzl @@ -0,0 +1,5 @@ +"Generated during release generate_tools_prebuilts.sh" + +VERSION = "v0.5.9" + +REPO_URL = "rmohr/bazeldnf"