-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install_prereqs: Use Bazelisk environ.bzl: Use workaround for attr.string_list() from Anzu Co-authored-by: Jeremy Nimmer <[email protected]>
- Loading branch information
1 parent
955245e
commit f3c5497
Showing
10 changed files
with
53 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# When bazelisk in use, this dotfile specifies which version of Bazel should be | ||
# used to build and test. | ||
USE_BAZEL_VERSION=6.4.0 | ||
USE_BAZEL_VERSION=7.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Import base-level build configuration. | ||
import %workspace%/../default.bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# When bazelisk in use, this dotfile specifies which version of Bazel should be | ||
# used to build and test. | ||
USE_BAZEL_VERSION=6.4.0 | ||
USE_BAZEL_VERSION=7.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# When bazelisk in use, this dotfile specifies which version of Bazel should be | ||
# used to build and test. | ||
USE_BAZEL_VERSION=6.4.0 | ||
USE_BAZEL_VERSION=7.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# When bazelisk in use, this dotfile specifies which version of Bazel should be | ||
# used to build and test. | ||
USE_BAZEL_VERSION=6.4.0 | ||
USE_BAZEL_VERSION=7.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# When bazelisk in use, this dotfile specifies which version of Bazel should be | ||
# used to build and test. | ||
USE_BAZEL_VERSION=6.4.0 | ||
USE_BAZEL_VERSION=7.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,46 @@ | ||
# -*- python -*- | ||
# -*- mode: python -*- | ||
# vi: set ft=python : | ||
|
||
def _environment_repository_impl(repo_ctx): | ||
environ = { | ||
envvar: repo_ctx.os.environ.get(envvar, "") | ||
for envvar in repo_ctx.attr._envvars | ||
} | ||
repo_ctx.file( | ||
# Write out a repository that contains: | ||
# - An empty BUILD file, to define a package. | ||
# - An environ.bzl file with variable assignments for each ENV_NAMES item. | ||
def _impl(repository_ctx): | ||
envvars = repository_ctx.attr.envvars | ||
bzl_content = [] | ||
for key in envvars: | ||
value = repository_ctx.os.environ.get(key, "") | ||
bzl_content.append("{}='{}'\n".format(key, value)) | ||
repository_ctx.file( | ||
"BUILD.bazel", | ||
content = "# Empty build file to mark repository root.\n", | ||
content = "\n", | ||
executable = False, | ||
) | ||
repo_ctx.file( | ||
repository_ctx.file( | ||
"environ.bzl", | ||
content = "\n".join([ | ||
"{}=\"{}\"".format(name, value) | ||
for name, value in environ.items() | ||
]), | ||
content = "".join(bzl_content), | ||
executable = False, | ||
) | ||
|
||
def environment_repository(name, envvars): | ||
_string_list = attr.string_list() | ||
|
||
def environment_repository(name = None, envvars = []): | ||
"""Provide specific environment variables for use in a WORKSPACE file. | ||
The `envvars` are the environment variables to provide. | ||
Example: | ||
environ_repository(name = "foo", envvars = ["BAR", "BAZ"]) | ||
load("@foo//:environ.bzl", "BAR", "BAZ") | ||
print(BAR) | ||
""" | ||
rule = repository_rule( | ||
implementation = _impl, | ||
attrs = { | ||
"_envvars": attr.string_list(default = envvars), | ||
"envvars": _string_list, | ||
}, | ||
implementation = _environment_repository_impl, | ||
environ = envvars, | ||
local = True, | ||
environ = envvars, | ||
) | ||
rule( | ||
name = name, | ||
envvars = envvars, | ||
) | ||
rule(name = name) |