Skip to content

Commit

Permalink
Fix path to licence-checker on Bazel 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnrt committed Aug 23, 2024
1 parent d9b602a commit 546c772
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
1 change: 1 addition & 0 deletions licence-checker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package(default_visibility = ["//visibility:public"])

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

py_binary(
name = "licence-checker",
Expand Down
6 changes: 5 additions & 1 deletion rules/licence-checker-runner.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Remember the runfiles dir since this is what paths like "@@LICENCE_CHECKER@@"
# and "@@CONFIG@@" are relative to once we `cd` elsewhere.
RUNFILES_DIR="$PWD"

WORKSPACE="@@WORKSPACE@@"

if [[ ! -z "${WORKSPACE}" ]]; then
Expand All @@ -16,4 +20,4 @@ else
exit 1
fi

"@@LICENCE_CHECKER@@" --config="@@CONFIG@@" "$@"
"${RUNFILES_DIR}/@@LICENCE_CHECKER@@" --config="${RUNFILES_DIR}/@@CONFIG@@" "$@"
22 changes: 4 additions & 18 deletions rules/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,20 @@ def _licence_check_impl(ctx):
},
)

# Hack to make Bazel build the checker correctly.
#
# Bazel py_binaries require a .runfiles directory to be present, but for
# some reason or another it does not provide a good way to extract those
# for building as a dependency from a PyInfo provider.
#
# https://github.com/bazelbuild/bazel/issues/7357
checker = ctx.actions.declare_file(ctx.label.name + ".checker-witness")
ctx.actions.run_shell(
tools = [ctx.executable.licence_check],
outputs = [checker],
command = 'touch "{}"'.format(checker.path),
)

workspace = ctx.file.workspace.path if ctx.file.workspace else ""
script = ctx.actions.declare_file(ctx.label.name + ".bash")
ctx.actions.expand_template(
template = ctx.file._runner,
output = script,
substitutions = {
"@@LICENCE_CHECKER@@": ctx.executable.licence_check.path,
"@@CONFIG@@": config.path,
"@@LICENCE_CHECKER@@": ctx.executable.licence_check.short_path,
"@@CONFIG@@": config.short_path,
"@@WORKSPACE@@": workspace,
},
is_executable = True,
)

files = [config, checker]
files = [config]
if ctx.file.workspace:
files.append(ctx.file.workspace)

Expand Down Expand Up @@ -78,7 +64,7 @@ licence_check_attrs = {
),
"licence_check": attr.label(
default = "//licence-checker",
cfg = "host",
cfg = "exec",
executable = True,
doc = "The licence checker executable",
),
Expand Down

0 comments on commit 546c772

Please sign in to comment.