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

fix: pass visibility attribute for gazelle macro to resulting sh_binary #1340

Merged
merged 5 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions bazel-gh1339_fix_gazelle_visibility_attr
3 changes: 3 additions & 0 deletions def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def gazelle(name, **kwargs):
kwargs["extra_args"] = kwargs["args"]
kwargs.pop("args")

visibility = kwargs.pop("visibility", default = None)

tags_set = {t: "" for t in kwargs.pop("tags", [])}
tags_set["manual"] = ""
tags = [k for k in tags_set.keys()]
Expand All @@ -149,4 +151,5 @@ def gazelle(name, **kwargs):
name = name,
srcs = [runner_name],
tags = tags,
visibility = visibility,
achew22 marked this conversation as resolved.
Show resolved Hide resolved
)
6 changes: 6 additions & 0 deletions tests/visibility_attr/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("//:def.bzl", "gazelle")

gazelle(
name = "gazelle",
visibility = ["//tests/visibility_attr:__subpackages__"],
)
17 changes: 17 additions & 0 deletions tests/visibility_attr/child/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sh_binary(
name = "print_gazelle",
srcs = ["print_gazelle.sh"],
data = ["//tests/visibility_attr:gazelle"],
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)

sh_test(
name = "print_gazelle_test",
srcs = ["print_gazelle_test.sh"],
data = [":print_gazelle"],
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)
18 changes: 18 additions & 0 deletions tests/visibility_attr/child/print_gazelle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# --- begin runfiles.bash initialization v2 ---
achew22 marked this conversation as resolved.
Show resolved Hide resolved
# Copy-pasted from the Bazel Bash runfiles library v2.
set -o nounset -o pipefail; 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 -o errexit
# --- end runfiles.bash initialization v2 ---

gazelle_location=bazel_gazelle/tests/visibility_attr/gazelle
gazelle="$(rlocation "${gazelle_location}")" || \
(echo >&2 "Failed to locate ${gazelle_location}" && exit 1)

echo "${gazelle}"
24 changes: 24 additions & 0 deletions tests/visibility_attr/child/print_gazelle_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -o nounset -o pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
# shellcheck disable=SC1090
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 -o errexit
# --- end runfiles.bash initialization v2 ---

# MARK - Locate Deps

print_gazelle_location=bazel_gazelle/tests/visibility_attr/child/print_gazelle
print_gazelle="$(rlocation "${print_gazelle_location}")" || \
(echo >&2 "Failed to locate ${print_gazelle_location}" && exit 1)

# MARK - Test

output="$("${print_gazelle}")"
[[ "${output}" =~ "gazelle" ]] || (echo >&2 "Did not find 'gazelle' in output."; exit 1)