Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bazel/rules_toolchain
1 result
Show changes
Commits on Source (3)
# [1.0.0-alpha.10](https://git.gitlab.arm.com/bazel/rules_toolchain/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2023-12-13)
### Features
- make `which` mandatory ([274d2c9](https://git.gitlab.arm.com/bazel/rules_toolchain/commit/274d2c96991ea897a76055527561e5346402792a))
# [1.0.0-alpha.9](https://git.gitlab.arm.com/bazel/rules_toolchain/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2023-12-13)
### Bug Fixes
......
module(
name = "rules_toolchain",
version = "1.0.0-alpha.9",
version = "1.0.0-alpha.10",
bazel_compatibility = [
">=7.0.0",
],
......
......@@ -9,7 +9,12 @@ Add the following to `MODULE.bazel`:
```py
which = use_repo_rule("@rules_toolchain//toolchain/local/which:defs.bzl", "toolchain_local_which")
which(
name = "echo",
name = "which",
)
resolved = use_repo_rule("@rules_toolchain//toolchain/resolved:defs.bzl", "toolchain_resolved")
resolved(
name = "resolved",
toolchain_type = "//toolchain/echo:type",
)
```
......@@ -29,7 +34,7 @@ toolchain_type(
# No `exec_compatible_with` constraints are needed as a local binary is always compatible with the execution platform
toolchain(
name = "local",
toolchain = "@echo//:echo",
toolchain = "@which//:echo",
toolchain_type = ":type",
)
......@@ -37,7 +42,7 @@ toolchain(
# bazel run -- //toolchain/echo:resolved
alias(
name = "resolved",
actual = "@echo//:resolved",
actual = "@resolved",
)
# Performs a execution test of the binary
......
......@@ -15,14 +15,13 @@ local_path_override(
which = use_repo_rule("@rules_toolchain//toolchain/local/which:defs.bzl", "toolchain_local_which")
which(
name = "echo",
toolchain_type = "//toolchain/echo:type",
name = "which-echo",
)
resolved = use_repo_rule("@rules_toolchain//toolchain/resolved:defs.bzl", "toolchain_resolved")
resolved(
name = "resolved",
name = "resolved-echo",
toolchain_type = "//toolchain/echo:type",
)
......
{
"lockFileVersion": 3,
"moduleFileHash": "b5e5212db85ac60ce843baccd184e5d16937d6d310b430f73224a70d9bf8cfa1",
"moduleFileHash": "3c21bacae5326234a6afdf5d19ca2491b22cb87d53c9c262c9ede6b26281c4d0",
"flags": {
"cmdRegistries": [
"https://bcr.bazel.build/"
......@@ -37,8 +37,8 @@
"column": 0
},
"imports": {
"echo": "echo",
"resolved": "resolved",
"which-echo": "which-echo",
"resolved-echo": "resolved-echo",
"fixture-amd64-linux-gnu": "fixture-amd64-linux-gnu",
"fixture-arm64-linux-gnu": "fixture-arm64-linux-gnu",
"fixture-arm-linux-musl": "fixture-arm-linux-musl",
......@@ -51,8 +51,7 @@
{
"tagName": "@rules_toolchain//toolchain/local/which:defs.bzl%toolchain_local_which",
"attributeValues": {
"toolchain_type": "//toolchain/echo:type",
"name": "echo"
"name": "which-echo"
},
"devDependency": false,
"location": {
......@@ -65,12 +64,12 @@
"tagName": "@rules_toolchain//toolchain/resolved:defs.bzl%toolchain_resolved",
"attributeValues": {
"toolchain_type": "//toolchain/echo:type",
"name": "resolved"
"name": "resolved-echo"
},
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 24,
"line": 23,
"column": 9
}
},
......@@ -82,7 +81,7 @@
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 33,
"line": 32,
"column": 8
}
},
......@@ -94,7 +93,7 @@
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 37,
"line": 36,
"column": 8
}
},
......@@ -106,7 +105,7 @@
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 41,
"line": 40,
"column": 8
}
},
......@@ -118,7 +117,7 @@
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 45,
"line": 44,
"column": 8
}
},
......@@ -130,7 +129,7 @@
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 49,
"line": 48,
"column": 8
}
},
......@@ -148,7 +147,7 @@
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 55,
"line": 54,
"column": 7
}
}
......@@ -162,7 +161,7 @@
"usingModule": "<root>",
"location": {
"file": "@@//:MODULE.bazel",
"line": 65,
"line": 64,
"column": 23
},
"imports": {
......@@ -179,7 +178,7 @@
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 66,
"line": 65,
"column": 15
}
}
......@@ -848,24 +847,23 @@
"moduleExtensions": {
"//:MODULE.bazel%_repo_rules": {
"general": {
"bzlTransitiveDigest": "0/0JKbXjdx0+MCsL4hbq33HmaZLsejCHZ1wZeOcD9Es=",
"bzlTransitiveDigest": "DcS7hkCR97tWU6RFIoqiRZfRyhn8MoWr0X40xcNtOZg=",
"accumulatedFileDigests": {},
"envVariables": {},
"generatedRepoSpecs": {
"echo": {
"which-echo": {
"bzlFile": "@@rules_toolchain~override//toolchain/local/which:repository.bzl",
"ruleClassName": "which",
"attributes": {
"toolchain_type": "@@//toolchain/echo:type",
"name": "_main~_repo_rules~echo"
"name": "_main~_repo_rules~which-echo"
}
},
"resolved": {
"resolved-echo": {
"bzlFile": "@@rules_toolchain~override//toolchain/resolved:repository.bzl",
"ruleClassName": "resolved",
"attributes": {
"toolchain_type": "@@//toolchain/echo:type",
"name": "_main~_repo_rules~resolved"
"name": "_main~_repo_rules~resolved-echo"
}
},
"fixture-amd64-linux-gnu": {
......
......@@ -9,7 +9,7 @@ toolchain_type(
toolchain(
name = "local",
toolchain = "@echo//:echo",
toolchain = "@which-echo",
toolchain_type = ":type",
)
......@@ -29,7 +29,7 @@ toolchain(
alias(
name = "resolved",
actual = "@echo//:resolved",
actual = "@resolved-echo",
)
toolchain_test(
......@@ -41,5 +41,5 @@ toolchain_test(
build_test(
name = "entrypoint",
targets = ["@echo//:entrypoint"],
targets = ["@which-echo//:entrypoint"],
)
load("@rules_toolchain//toolchain/symlink/path:defs.bzl", "toolchain_symlink_path")
load("//:resolved.bzl", "resolved")
package(default_visibility = ["//visibility:public"])
exports_files(["entrypoint"])
toolchain_symlink_path(
name = "{{name}}",
name = "{{target}}",
basename = "{{basename}}",
path = "{{path}}",
tags = ["no-remote"],
variable = "{{variable}}",
)
resolved(
name = "resolved",
basename = "{{basename}}",
toolchain_type = "{{toolchain_type}}",
)
load("//toolchain/local/select:resolve.bzl", resolve = "value")
load("//toolchain:resolved.bzl", _ATTRS = "ATTRS")
visibility("//toolchain/...")
......@@ -15,45 +14,28 @@ Consuming this target as a toolchain is trivial:
toolchain(
name = "local",
toolchain = "@echo",
toolchain_type = ":type",
)
```
"""
ATTRS = _ATTRS | {
ATTRS = {
"program": attr.string(
doc = "The name of the binary to find on `PATH`.",
),
"target": attr.string(
doc = "The name of the Bazel target to expose around the binary.",
),
"basename": attr.string(
doc = "The basename for the symlink, which defaults to `program`",
),
"variable": attr.string(
doc = "The variable name for Make or the execution environment.",
),
"mandatory": attr.bool(
doc = "Determines if the tool must exist locally",
default = False,
),
"resolved": attr.label(
doc = "The tepmlate that is expanded into the `resolved.bzl`.",
default = "//toolchain/resolved:resolved.tmpl.bzl",
allow_single_file = True,
),
"build": attr.label(
doc = "The template that is expanded into the `BUILD.bazel`.",
default = ":BUILD.tmpl.bazel",
allow_single_file = True,
),
"stub": attr.label_keyed_string_dict(
doc = "An executable to use when the local binary is not found on `PATH`.",
default = {
":stub.bat": "windows",
":stub.sh": "//conditions:default",
},
allow_files = [".bat", ".sh"],
allow_empty = False,
cfg = "exec",
),
"entrypoint": attr.label_keyed_string_dict(
doc = "An executable entrypoint template for hermetic rulesets.",
default = {
......@@ -74,21 +56,15 @@ ATTRS = _ATTRS | {
}
def implementation(rctx):
program = rctx.attr.program or rctx.attr.name.rsplit("~", 1)[1]
program = rctx.attr.program or rctx.attr.name.rsplit("~", 1)[1].removeprefix("which-")
target = rctx.attr.target or rctx.attr.name.rsplit("~", 1)[1]
basename = rctx.attr.basename or program
stub = resolve(rctx.attr.stub)
variable = rctx.attr.variable or basename.upper()
entrypoint = resolve(rctx.attr.entrypoint)
path = rctx.which(program)
if not path:
if rctx.attr.mandatory:
fail("Cannot find `{}` on `PATH`".format(program))
path = rctx.path(stub)
rctx.template("resolved.bzl", rctx.attr.resolved, {
"{{toolchain_type}}": str(rctx.attr.toolchain_type),
"{{basename}}": basename,
}, executable = False)
fail("Cannot find `{}` on `PATH`".format(program))
_, extension = rctx.path(entrypoint).basename.rsplit(".", 1)
rctx.template("entrypoint.{}".format(extension), entrypoint, {
......@@ -98,12 +74,11 @@ def implementation(rctx):
rctx.symlink(rctx.attr.launcher, "entrypoint")
rctx.template("BUILD.bazel", rctx.attr.build, {
"{{name}}": rctx.attr.target or program,
"{{target}}": target,
"{{program}}": program,
"{{basename}}": basename,
"{{path}}": str(path.realpath),
"{{variable}}": rctx.attr.variable or program.upper(),
"{{toolchain_type}}": str(rctx.attr.toolchain_type),
"{{variable}}": variable,
}, executable = False)
which = repository_rule(
......
echo off
:: Enable Batch extensions
verify other 2>nul
setlocal EnableExtensions
if errorlevel 1 (
echo "Failed to enable extensions"
exit /b 120
)
:: Variables
for /f %%i in ("%0") do set "STEM=%%~ni"
:: Execute!
(
echo.Usage: %0 %*
echo.
echo.This is a stub executable that is provided when the `%STEM%` binary is not found on %%PATH%%:
echo.
echo. %PATH%
echo.
echo.It will always exit with a failure code. Either:
echo.
echo.- Install the required binary locally
echo.- Setup a hermetic toolchain for the binary
) >&2
exit /b 126
\ No newline at end of file
#! /bin/sh
cat <<EOF >&2
Usage: ${0} ${@}
This is a stub executable that is provided when the \`${0##*/}\` binary is not found on \${PATH}:
${PATH}
It will always exit with a failure code. Either:
- Install the required binary locally
- Setup a hermetic toolchain for the binary
EOF
exit 126
load("//:resolved.bzl", "resolved")
resolved(
name = "resolved",
name = "{{target}}",
basename = "{{basename}}",
toolchain_type = "{{toolchain_type}}",
visibility = ["//visibility:public"],
......
......@@ -17,6 +17,9 @@ toolchain_resolved(
"""
ATTRS = _ATTRS | {
"target": attr.string(
doc = "The name of the Bazel target for the `resolved` rule.",
),
"resolved": attr.label(
doc = "The template that is expanded into the `resolved.bzl`.",
default = Label(":resolved.tmpl.bzl"),
......@@ -33,6 +36,7 @@ def implementation(rctx):
substitutions = {
"{{toolchain_type}}": str(rctx.attr.toolchain_type),
"{{basename}}": str(rctx.attr.basename),
"{{target}}": rctx.attr.target or rctx.attr.name.rsplit("~", 1)[1],
}
rctx.template("resolved.bzl", rctx.attr.resolved, substitutions, executable = False)
rctx.template("BUILD.bazel", rctx.attr.build, substitutions, executable = False)
......