Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gazelle_runner: allow usage of transitive runfiles #1686

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _gazelle_runner_impl(ctx):
runfiles = ctx.runfiles(files = [
ctx.executable.gazelle,
go_tool,
] + ([repo_config] if repo_config else [])).merge(
] + ctx.files._bash_runfile_helpers + ([repo_config] if repo_config else [])).merge(
ctx.attr.gazelle[DefaultInfo].default_runfiles,
)
for d in ctx.attr.data:
Expand Down Expand Up @@ -152,6 +152,9 @@ _gazelle_runner = rule(
"extra_args": attr.string_list(),
"data": attr.label_list(allow_files = True),
"env": attr.string_dict(),
"_bash_runfile_helpers": attr.label(
default = "@bazel_tools//tools/bash/runfiles",
),
"_repo_config": attr.label(
default = "@bazel_gazelle_go_repository_config//:WORKSPACE" if GAZELLE_IS_BAZEL_MODULE else None,
allow_single_file = True,
Expand Down
14 changes: 13 additions & 1 deletion internal/gazelle.bash.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \

@@GENERATED_MESSAGE@@

set -euo pipefail
# --- begin runfiles.bash initialization v3 ---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already loaded this library in line 15. What does this duplication achieve?

# Copy-pasted from the Bazel Bash runfiles library v3.
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v3 ---

# Export runfile vars so sub-processes can access them
runfiles_export_envvars
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invoked in line 113. Do we have to move it to an earlier line?


GAZELLE_PATH=@@GAZELLE_PATH@@
ARGS=@@ARGS@@
Expand Down