fix: fix bzl_library breakage created with load from @local_config_platform in copy rules (#242)

This commit is contained in:
Greg Magolan 2022-09-13 20:37:24 -07:00 committed by GitHub
parent e376f9a733
commit be5c9d06bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 44 deletions

View File

@ -35,10 +35,3 @@ go_rules_dependencies()
go_register_toolchains(version = "1.17.2")
gazelle_dependencies()
# buildifier: disable=bzl-visibility
load("//lib/private:local_config_platform.bzl", "local_config_platform")
local_config_platform(
name = "local_config_platform",
)

View File

@ -176,6 +176,7 @@ bzl_library(
srcs = ["repositories.bzl"],
deps = [
"//lib/private:jq_toolchain",
"//lib/private:local_config_platform",
"//lib/private:yq_toolchain",
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",

View File

@ -19,7 +19,7 @@ exports_files(
bzl_library(
name = "copy_common",
srcs = ["copy_common.bzl"],
deps = ["@local_config_platform//:constraints"],
deps = ["@aspect_bazel_lib_local_config_platform//:constraints"],
)
bzl_library(
@ -116,6 +116,11 @@ bzl_library(
deps = ["//lib:stamping"],
)
bzl_library(
name = "local_config_platform",
srcs = ["local_config_platform.bzl"],
)
bzl_library(
name = "write_source_file",
srcs = ["write_source_file.bzl"],

View File

@ -1,6 +1,6 @@
"Helpers for copy rules"
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
load("@aspect_bazel_lib_local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
# Hints for Bazel spawn strategy
COPY_EXECUTION_REQUIREMENTS = {

View File

@ -1,49 +1,27 @@
"""Work-around for getting a bzl_library for @local_config_platform//:constraints.bzl load
For internal use only
"""local_config_platform repository rule
"""
load(":repo_utils.bzl", "repo_utils")
def _impl(rctx):
rctx.file("BUILD.bazel", """load(':constraints.bzl', 'HOST_CONSTRAINTS')
rctx.file("constraints.bzl", content = rctx.read(rctx.attr._constraints_bzl))
rctx.file("BUILD.bazel", content = rctx.read(rctx.attr._build_bazel) + """
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
package(default_visibility = ['//visibility:public'])
platform(name = 'host',
# Auto-detected host platform constraints.
constraint_values = HOST_CONSTRAINTS,
)
bzl_library(
name = "constraints",
srcs = ["constraints.bzl"],
visibility = ["//visibility:public"],
)
""")
# TODO: we can detect the host CPU in the future as well if needed;
# see the repo_utils.platform(rctx) function for an example of this
if repo_utils.is_darwin(rctx):
rctx.file("constraints.bzl", content = """HOST_CONSTRAINTS = [
'@platforms//cpu:x86_64',
'@platforms//os:osx',
]
""")
elif repo_utils.is_windows(rctx):
rctx.file("constraints.bzl", content = """HOST_CONSTRAINTS = [
'@platforms//cpu:x86_64',
'@platforms//os:windows',
]
""")
else:
rctx.file("constraints.bzl", content = """HOST_CONSTRAINTS = [
'@platforms//cpu:x86_64',
'@platforms//os:linux',
]
""")
local_config_platform = repository_rule(
implementation = _impl,
doc = """Generates a copy of the auto-generated @local_config_platform repository with an added bzl_library.
This is useful for rules that want to load `HOST_CONSTRAINTS` from `@local_config_platform//:constraints.bzl` and
also want to use stardoc for generating documentation.
""",
attrs = {
"_constraints_bzl": attr.label(default = "@local_config_platform//:constraints.bzl"),
"_build_bazel": attr.label(default = "@local_config_platform//:BUILD.bazel"),
},
)

View File

@ -4,6 +4,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archi
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//lib/private:jq_toolchain.bzl", "JQ_PLATFORMS", "jq_host_alias_repo", "jq_platform_repo", "jq_toolchains_repo", _DEFAULT_JQ_VERSION = "DEFAULT_JQ_VERSION")
load("//lib/private:yq_toolchain.bzl", "YQ_PLATFORMS", "yq_host_alias_repo", "yq_platform_repo", "yq_toolchains_repo", _DEFAULT_YQ_VERSION = "DEFAULT_YQ_VERSION")
load("//lib/private:local_config_platform.bzl", "local_config_platform")
# Don't wrap later calls with maybe() as that prevents renovate from parsing our deps
def http_archive(name, **kwargs):
@ -20,6 +21,10 @@ def aspect_bazel_lib_dependencies():
],
)
local_config_platform(
name = "aspect_bazel_lib_local_config_platform",
)
# Re-export the default versions
DEFAULT_JQ_VERSION = _DEFAULT_JQ_VERSION
DEFAULT_YQ_VERSION = _DEFAULT_YQ_VERSION