Skip to content

Commit 14d40a4

Browse files
committed
Fix path to licence-checker on Bazel 7
1 parent 99749cc commit 14d40a4

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

licence-checker/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package(default_visibility = ["//visibility:public"])
66

77
load("@lowrisc_misc_linters_pip//:requirements.bzl", "requirement")
8+
load("@rules_python//python:py_binary.bzl", "py_binary")
89

910
py_binary(
1011
name = "licence-checker",

rules/licence-checker-runner.template.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
44
# SPDX-License-Identifier: Apache-2.0
55

6+
# Remember the runfiles dir since this is what paths like "@@LICENCE_CHECKER@@"
7+
# and "@@CONFIG@@" are relative to once we `cd` elsewhere.
8+
RUNFILES_DIR="$PWD"
9+
610
WORKSPACE="@@WORKSPACE@@"
711

812
if [[ ! -z "${WORKSPACE}" ]]; then
@@ -16,4 +20,4 @@ else
1620
exit 1
1721
fi
1822

19-
"@@LICENCE_CHECKER@@" --config="@@CONFIG@@" "$@"
23+
"${RUNFILES_DIR}/@@LICENCE_CHECKER@@" --config="${RUNFILES_DIR}/@@CONFIG@@" "$@"

rules/rules.bzl

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,20 @@ def _licence_check_impl(ctx):
1818
},
1919
)
2020

21-
# Hack to make Bazel build the checker correctly.
22-
#
23-
# Bazel py_binaries require a .runfiles directory to be present, but for
24-
# some reason or another it does not provide a good way to extract those
25-
# for building as a dependency from a PyInfo provider.
26-
#
27-
# https://github.com/bazelbuild/bazel/issues/7357
28-
checker = ctx.actions.declare_file(ctx.label.name + ".checker-witness")
29-
ctx.actions.run_shell(
30-
tools = [ctx.executable.licence_check],
31-
outputs = [checker],
32-
command = 'touch "{}"'.format(checker.path),
33-
)
34-
3521
workspace = ctx.file.workspace.path if ctx.file.workspace else ""
3622
script = ctx.actions.declare_file(ctx.label.name + ".bash")
3723
ctx.actions.expand_template(
3824
template = ctx.file._runner,
3925
output = script,
4026
substitutions = {
41-
"@@LICENCE_CHECKER@@": ctx.executable.licence_check.path,
42-
"@@CONFIG@@": config.path,
27+
"@@LICENCE_CHECKER@@": ctx.executable.licence_check.short_path,
28+
"@@CONFIG@@": config.short_path,
4329
"@@WORKSPACE@@": workspace,
4430
},
4531
is_executable = True,
4632
)
4733

48-
files = [config, checker]
34+
files = [config]
4935
if ctx.file.workspace:
5036
files.append(ctx.file.workspace)
5137

0 commit comments

Comments
 (0)