Skip to content

Commit

Permalink
move the rpmbuild toolchain definition to //toolchains/rpm. (#514)
Browse files Browse the repository at this point in the history
* move the rpmbuild toolchain to toolchains/rpm
* update CODEOWNERS
  • Loading branch information
aiuto authored Feb 16, 2022
1 parent ddc5018 commit 7f55dcc
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 86 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion distro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```

Expand Down Expand Up @@ -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")


Expand Down
4 changes: 2 additions & 2 deletions examples/prebuilt_rpmbuild/local/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
)
2 changes: 1 addition & 1 deletion pkg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion pkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```

Expand Down
6 changes: 3 additions & 3 deletions pkg/legacy/rpm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
"""

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/rpm_pfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"],
)
2 changes: 1 addition & 1 deletion tests/rpm/toolchain_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
63 changes: 0 additions & 63 deletions toolchains/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
76 changes: 76 additions & 0 deletions toolchains/rpm/BUILD
Original file line number Diff line number Diff line change
@@ -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",
)
4 changes: 2 additions & 2 deletions toolchains/BUILD.tpl → toolchains/rpm/BUILD.tpl
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
)
6 changes: 3 additions & 3 deletions toolchains/rpmbuild.bzl → toolchains/rpm/rpmbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ 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"),
)]

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")
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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")

0 comments on commit 7f55dcc

Please sign in to comment.