From 7f55dcc759f5b4d7a7e24d785998c59e446fd5fb Mon Sep 17 00:00:00 2001 From: aiuto Date: Tue, 15 Feb 2022 19:55:59 -0500 Subject: [PATCH] move the rpmbuild toolchain definition to //toolchains/rpm. (#514) * move the rpmbuild toolchain to toolchains/rpm * update CODEOWNERS --- CODEOWNERS | 1 + WORKSPACE | 2 +- distro/BUILD | 2 +- docs/latest.md | 4 +- examples/prebuilt_rpmbuild/local/BUILD | 4 +- pkg/BUILD | 2 +- pkg/README.md | 2 +- pkg/legacy/rpm.bzl | 6 +- pkg/rpm_pfg.bzl | 6 +- tests/rpm/toolchain_tests.bzl | 2 +- toolchains/BUILD | 63 ----------------- toolchains/rpm/BUILD | 76 +++++++++++++++++++++ toolchains/{ => rpm}/BUILD.tpl | 4 +- toolchains/{ => rpm}/rpmbuild.bzl | 6 +- toolchains/{ => rpm}/rpmbuild_configure.bzl | 6 +- 15 files changed, 100 insertions(+), 86 deletions(-) create mode 100644 toolchains/rpm/BUILD rename toolchains/{ => rpm}/BUILD.tpl (62%) rename toolchains/{ => rpm}/rpmbuild.bzl (90%) rename toolchains/{ => rpm}/rpmbuild_configure.bzl (91%) diff --git a/CODEOWNERS b/CODEOWNERS index 09884d3d..1963edf4 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -7,6 +7,7 @@ /pkg/rpm/ @nacl /pkg/tests/rpm/ @nacl /legacy/tests/rpm @nacl +/toolchains/rpm @nacl /pkg/deb.bzl @aiuto @dannysullivan @jylinv0 /pkg/private/deb/ @aiuto @dannysullivan @jylinv0 diff --git a/WORKSPACE b/WORKSPACE index 6daa5cb6..5810d9ce 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -29,7 +29,7 @@ bazel_skylib_workspace() load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # Find rpmbuild if it exists. -load("@rules_pkg//toolchains:rpmbuild_configure.bzl", "find_system_rpmbuild") +load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") find_system_rpmbuild( name = "rules_pkg_rpmbuild", diff --git a/distro/BUILD b/distro/BUILD index bcbfb77c..afbc67c7 100644 --- a/distro/BUILD +++ b/distro/BUILD @@ -43,8 +43,8 @@ pkg_tar( "//pkg/private/tar:standard_package", "//pkg/private/zip:standard_package", "//pkg/releasing:standard_package", - "//toolchains:standard_package", "//toolchains/git:standard_package", + "//toolchains/rpm:standard_package", ], extension = "tar.gz", # It is all source code, so make it read-only. diff --git a/docs/latest.md b/docs/latest.md index 1e14c846..9be34c78 100755 --- a/docs/latest.md +++ b/docs/latest.md @@ -174,7 +174,7 @@ toolchain add the following stanza to WORKSPACE: ``` # Find rpmbuild if it exists. -load("@rules_pkg//toolchains:rpmbuild_configure.bzl", "find_system_rpmbuild") +load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") find_system_rpmbuild(name="rules_pkg_rpmbuild") ``` @@ -712,7 +712,7 @@ find to convenient to use the one provided with their system. To enable that toolchain add the following stanza to WORKSPACE: # Find rpmbuild if it exists. - load("@rules_pkg//toolchains:rpmbuild_configure.bzl", "find_system_rpmbuild") + load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") find_system_rpmbuild(name="rules_pkg_rpmbuild") diff --git a/examples/prebuilt_rpmbuild/local/BUILD b/examples/prebuilt_rpmbuild/local/BUILD index 608aa5fb..7c273bf6 100644 --- a/examples/prebuilt_rpmbuild/local/BUILD +++ b/examples/prebuilt_rpmbuild/local/BUILD @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@rules_pkg//toolchains:rpmbuild.bzl", "rpmbuild_toolchain") +load("@rules_pkg//toolchains/rpm:rpmbuild.bzl", "rpmbuild_toolchain") rpmbuild_toolchain( name = "prebuilt_rpmbuild", @@ -23,5 +23,5 @@ rpmbuild_toolchain( toolchain( name = "local_rpmbuild", toolchain = ":prebuilt_rpmbuild", - toolchain_type = "@rules_pkg//toolchains:rpmbuild_toolchain_type", + toolchain_type = "@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type", ) diff --git a/pkg/BUILD b/pkg/BUILD index a9385c6e..58043709 100644 --- a/pkg/BUILD +++ b/pkg/BUILD @@ -53,7 +53,7 @@ py_binary( python_version = "PY3", srcs_version = "PY3", target_compatible_with = select({ - "//toolchains:have_rpmbuild": [], + "//toolchains/rpm:have_rpmbuild": [], "//conditions:default": [":not_compatible"], }), visibility = ["//visibility:public"], diff --git a/pkg/README.md b/pkg/README.md index 1dcc3b9f..acde9c3d 100644 --- a/pkg/README.md +++ b/pkg/README.md @@ -30,7 +30,7 @@ WORKSPACE to use one installed on your system: ```python # Find rpmbuild provided on your system. -load("@rules_pkg//toolchains:rpmbuild_configure.bzl", "find_system_rpmbuild") +load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") find_system_rpmbuild(name = "rules_pkg_rpmbuild") ``` diff --git a/pkg/legacy/rpm.bzl b/pkg/legacy/rpm.bzl index c35cb83c..3211bbdc 100644 --- a/pkg/legacy/rpm.bzl +++ b/pkg/legacy/rpm.bzl @@ -21,7 +21,7 @@ find to convenient to use the one provided with their system. To enable that toolchain add the following stanza to WORKSPACE: # Find rpmbuild if it exists. - load("@rules_pkg//toolchains:rpmbuild_configure.bzl", "find_system_rpmbuild") + load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") find_system_rpmbuild(name="rules_pkg_rpmbuild") """ @@ -45,7 +45,7 @@ def _pkg_rpm_impl(ctx): print("rpmbuild_path is deprecated. See the README for instructions on how" + " to migrate to toolchains") else: - toolchain = ctx.toolchains["@rules_pkg//toolchains:rpmbuild_toolchain_type"].rpmbuild + toolchain = ctx.toolchains["@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type"].rpmbuild if not toolchain.valid: fail("The rpmbuild_toolchain is not properly configured: " + toolchain.name) @@ -198,7 +198,7 @@ pkg_rpm = rule( executable = False, outputs = _pkg_rpm_outputs, implementation = _pkg_rpm_impl, - toolchains = ["@rules_pkg//toolchains:rpmbuild_toolchain_type"], + toolchains = ["@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type"], ) # buildifier: disable=no-effect diff --git a/pkg/rpm_pfg.bzl b/pkg/rpm_pfg.bzl index ef0db1c5..4ee6583a 100644 --- a/pkg/rpm_pfg.bzl +++ b/pkg/rpm_pfg.bzl @@ -20,7 +20,7 @@ toolchain add the following stanza to WORKSPACE: ``` # Find rpmbuild if it exists. -load("@rules_pkg//toolchains:rpmbuild_configure.bzl", "find_system_rpmbuild") +load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") find_system_rpmbuild(name="rules_pkg_rpmbuild") ``` """ @@ -225,7 +225,7 @@ def _pkg_rpm_impl(ctx): print("rpmbuild_path is deprecated. See the README for instructions on how" + " to migrate to toolchains") else: - toolchain = ctx.toolchains["@rules_pkg//toolchains:rpmbuild_toolchain_type"].rpmbuild + toolchain = ctx.toolchains["@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type"].rpmbuild if not toolchain.valid: fail("The rpmbuild_toolchain is not properly configured: " + toolchain.name) @@ -1008,5 +1008,5 @@ pkg_rpm = rule( executable = False, implementation = _pkg_rpm_impl, provides = [PackageArtifactInfo], - toolchains = ["@rules_pkg//toolchains:rpmbuild_toolchain_type"], + toolchains = ["@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type"], ) diff --git a/tests/rpm/toolchain_tests.bzl b/tests/rpm/toolchain_tests.bzl index bac7b997..0f6a499a 100644 --- a/tests/rpm/toolchain_tests.bzl +++ b/tests/rpm/toolchain_tests.bzl @@ -15,7 +15,7 @@ """Tests for rpmbuild toolchain type.""" load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") -load("//toolchains:rpmbuild.bzl", "rpmbuild_toolchain") +load("//toolchains/rpm:rpmbuild.bzl", "rpmbuild_toolchain") # Generic negative test boilerplate def _generic_neg_test_impl(ctx): diff --git a/toolchains/BUILD b/toolchains/BUILD index f871983e..cdd15e46 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -11,66 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -"""toolchain to wrap an rpmbuild binary. - -Type: @rules_pkg//toolchains:rpmbuild_toolchain_type - -Toolchains: -- rpmbuild_missing_toolchain: provides a fallback toolchain for exec plaforms - where rpmbuild might not be available. - -- rpmbuild_auto_toolchain: a toolchain that uses the installed rpmbuild. See - rpmbuild_configure.bzl%find_system_rpmbuild for usage. -""" - -load("//toolchains:rpmbuild.bzl", "is_rpmbuild_available", "rpmbuild_toolchain") - -filegroup( - name = "standard_package", - srcs = glob([ - "*", - ]), - visibility = ["//distro:__pkg__"], -) - -exports_files( - glob(["*"]), - visibility = ["//visibility:public"], -) - -# Expose the availabilty of an actual rpmbuild as a config_setting, so we can -# select() on it. -config_setting( - name = "have_rpmbuild", - flag_values = { - ":is_rpmbuild_available": "1", - }, - visibility = ["//visibility:public"], -) - -# Expose the availabilty of an actual rpmbuild as a feature flag, so we can -# create a config_setting from it. -is_rpmbuild_available( - name = "is_rpmbuild_available", - visibility = ["//:__subpackages__"], -) - -toolchain_type( - name = "rpmbuild_toolchain_type", - visibility = ["//visibility:public"], -) - -# rpmbuild_missing_toolchain provides a fallback toolchain so that toolchain -# resolution can succeed even on platforms that do not have a working rpmbuild. -# If this toolchain is selected, the constraint ":have_rpmbuild" will not be -# satistifed. -rpmbuild_toolchain( - name = "no_rpmbuild", -) - -toolchain( - name = "rpmbuild_missing_toolchain", - toolchain = ":no_rpmbuild", - toolchain_type = ":rpmbuild_toolchain_type", -) diff --git a/toolchains/rpm/BUILD b/toolchains/rpm/BUILD new file mode 100644 index 00000000..5a3ff7d2 --- /dev/null +++ b/toolchains/rpm/BUILD @@ -0,0 +1,76 @@ +# Copyright 2020 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""toolchain to wrap an rpmbuild binary. + +Type: @rules_pkg//toolchains/rpm:rpmbuild_toolchain_type + +Toolchains: +- rpmbuild_missing_toolchain: provides a fallback toolchain for exec plaforms + where rpmbuild might not be available. + +- rpmbuild_auto_toolchain: a toolchain that uses the installed rpmbuild. See + rpmbuild_configure.bzl%find_system_rpmbuild for usage. +""" + +load("//toolchains/rpm:rpmbuild.bzl", "is_rpmbuild_available", "rpmbuild_toolchain") + +filegroup( + name = "standard_package", + srcs = glob([ + "*", + ]), + visibility = ["//distro:__pkg__"], +) + +exports_files( + glob(["*"]), + visibility = ["//visibility:public"], +) + +# Expose the availabilty of an actual rpmbuild as a config_setting, so we can +# select() on it. +config_setting( + name = "have_rpmbuild", + flag_values = { + ":is_rpmbuild_available": "1", + }, + visibility = ["//visibility:public"], +) + +# Expose the availabilty of an actual rpmbuild as a feature flag, so we can +# create a config_setting from it. +is_rpmbuild_available( + name = "is_rpmbuild_available", + visibility = ["//:__subpackages__"], +) + +toolchain_type( + name = "rpmbuild_toolchain_type", + visibility = ["//visibility:public"], +) + +# rpmbuild_missing_toolchain provides a fallback toolchain so that toolchain +# resolution can succeed even on platforms that do not have a working rpmbuild. +# If this toolchain is selected, the constraint ":have_rpmbuild" will not be +# satistifed. +rpmbuild_toolchain( + name = "no_rpmbuild", +) + +toolchain( + name = "rpmbuild_missing_toolchain", + toolchain = ":no_rpmbuild", + toolchain_type = ":rpmbuild_toolchain_type", +) diff --git a/toolchains/BUILD.tpl b/toolchains/rpm/BUILD.tpl similarity index 62% rename from toolchains/BUILD.tpl rename to toolchains/rpm/BUILD.tpl index f563d764..ca4b2187 100644 --- a/toolchains/BUILD.tpl +++ b/toolchains/rpm/BUILD.tpl @@ -1,5 +1,5 @@ # This content is generated by {GENERATOR} -load("@rules_pkg//toolchains:rpmbuild.bzl", "rpmbuild_toolchain") +load("@rules_pkg//toolchains/rpm:rpmbuild.bzl", "rpmbuild_toolchain") rpmbuild_toolchain( name = "rpmbuild_auto", @@ -10,5 +10,5 @@ rpmbuild_toolchain( toolchain( name = "rpmbuild_auto_toolchain", toolchain = ":rpmbuild_auto", - toolchain_type = "@rules_pkg//toolchains:rpmbuild_toolchain_type", + toolchain_type = "@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type", ) diff --git a/toolchains/rpmbuild.bzl b/toolchains/rpm/rpmbuild.bzl similarity index 90% rename from toolchains/rpmbuild.bzl rename to toolchains/rpm/rpmbuild.bzl index 2d4e627d..3aa0ea04 100644 --- a/toolchains/rpmbuild.bzl +++ b/toolchains/rpm/rpmbuild.bzl @@ -59,7 +59,7 @@ rpmbuild_toolchain = rule( # Expose the presence of an rpmbuild in the resolved toolchain as a flag. def _is_rpmbuild_available_impl(ctx): - toolchain = ctx.toolchains["@rules_pkg//toolchains:rpmbuild_toolchain_type"].rpmbuild + toolchain = ctx.toolchains["@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type"].rpmbuild return [config_common.FeatureFlagInfo( value = ("1" if toolchain.valid else "0"), )] @@ -67,8 +67,8 @@ def _is_rpmbuild_available_impl(ctx): is_rpmbuild_available = rule( implementation = _is_rpmbuild_available_impl, attrs = {}, - toolchains = ["@rules_pkg//toolchains:rpmbuild_toolchain_type"], + toolchains = ["@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type"], ) def rpmbuild_register_toolchains(): - native.register_toolchains("@rules_pkg//toolchains:rpmbuild_missing_toolchain") + native.register_toolchains("@rules_pkg//toolchains/rpm:rpmbuild_missing_toolchain") diff --git a/toolchains/rpmbuild_configure.bzl b/toolchains/rpm/rpmbuild_configure.bzl similarity index 91% rename from toolchains/rpmbuild_configure.bzl rename to toolchains/rpm/rpmbuild_configure.bzl index f188b282..f50a9ad8 100644 --- a/toolchains/rpmbuild_configure.bzl +++ b/toolchains/rpm/rpmbuild_configure.bzl @@ -18,9 +18,9 @@ def _write_build(rctx, path, version): path = "" rctx.template( "BUILD", - Label("//toolchains:BUILD.tpl"), + Label("//toolchains/rpm:BUILD.tpl"), substitutions = { - "{GENERATOR}": "@rules_pkg//toolchains/rpmbuild_configure.bzl%find_system_rpmbuild", + "{GENERATOR}": "@rules_pkg//toolchains/rpm/rpmbuild_configure.bzl%find_system_rpmbuild", "{RPMBUILD_PATH}": str(path), "{RPMBUILD_VERSION}": version, }, @@ -60,4 +60,4 @@ def find_system_rpmbuild(name, verbose=False): _find_system_rpmbuild(name=name, verbose=verbose) native.register_toolchains( "@%s//:rpmbuild_auto_toolchain" % name, - "@rules_pkg//toolchains:rpmbuild_missing_toolchain") + "@rules_pkg//toolchains/rpm:rpmbuild_missing_toolchain")