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

package default visibility does not appear in the --output=xml query result of a rule target #17402

Closed
linzhp opened this issue Feb 3, 2023 · 4 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Core Skyframe, bazel query, BEP, options parsing, bazelrc type: bug

Comments

@linzhp
Copy link
Contributor

linzhp commented Feb 3, 2023

Description of the bug:

When we have something like package(default_visibility=["//visibility:public"]) at the top of a build file, and the targets in the build file does not have visibility attribute defined, Bazel query result has visibility in all file targets but not rule targets.

This affects the availability to calculate target hash from query result like this, because we want the target hash to change when visibility of a target changes

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  1. Create a workspace like this:
-- WORKSPACE --
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "dd926a88a564a9246713a9c00b35315f54cbd46b31a26d5d8fb264c07045f05d",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.38.1/rules_go-v0.38.1.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.38.1/rules_go-v0.38.1.zip",
    ],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.19.5")
-- BUILD.bazel --
-- foo/BUILD.bazel --
load("@io_bazel_rules_go//go:def.bzl", "go_library")

package(default_visibility=["//visibility:public"])

go_library(
    name = "foo",
    importpath = "example.com/foo",
    srcs = ["foo.go"],
)
-- foo/foo.go --
package foo
  1. Run bazel query --output=xml //foo:all-targets:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<query version="2">
    <source-file location="/private/tmp/visibility/foo/BUILD.bazel:1:1" name="//foo:BUILD.bazel">
        <visibility-label name="//visibility:public"/>
    </source-file>
    <rule class="go_library" location="/private/tmp/visibility/foo/BUILD.bazel:5:11" name="//foo:foo">
        <string name="name" value="foo"/>
        <string name="generator_name" value="foo"/>
        <string name="generator_function" value="go_library_macro"/>
        <string name="generator_location" value="foo/BUILD.bazel:5:11"/>
        <list name="srcs">
            <label value="//foo:foo.go"/>
        </list>
        <string name="importpath" value="example.com/foo"/>
        <rule-input name="//foo:foo.go"/>
        <rule-input name="@bazel_tools//tools/allowlists/function_transition_allowlist:function_transition_allowlist"/>
        <rule-input name="@io_bazel_rules_go//:go_context_data"/>
    </rule>
    <source-file location="/private/tmp/visibility/foo/foo.go:1:1" name="//foo:foo.go">
        <visibility-label name="//visibility:public"/>
    </source-file>
</query>

Which operating system are you running Bazel on?

macOS

What is the output of bazel info release?

release 6.0.0-homebrew

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@sgowroji sgowroji added type: bug untriaged team-Core Skyframe, bazel query, BEP, options parsing, bazelrc labels Feb 3, 2023
@haxorz haxorz added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Feb 6, 2023
@haxorz
Copy link
Contributor

haxorz commented Feb 6, 2023

Try additionally passing --xml:default_values. I did that on a simpler example and it worked for me.

This affects the availability to calculate target hash from query result like #7962 (comment), because we want the target hash to change when visibility of a target changes

Ack. I appreciate the context :)

You may be interested in --proto:include_synthetic_attribute_hash.

@haxorz haxorz changed the title package default visibility does not appear in the query result of a rule target package default visibility does not appear in the --output=xml query result of a rule target Feb 6, 2023
@linzhp
Copy link
Contributor Author

linzhp commented Feb 7, 2023

Thanks --xml:default_values works

@haxorz
Copy link
Contributor

haxorz commented Feb 7, 2023

I'm inclined to close this as WAI. WDYT?

Maybe the documentation for https://bazel.build/query/language#xml-defaultvalues could give this behavior as an example?

@linzhp
Copy link
Contributor Author

linzhp commented Feb 7, 2023

That would be helpful

@linzhp linzhp closed this as completed Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Core Skyframe, bazel query, BEP, options parsing, bazelrc type: bug
Projects
None yet
Development

No branches or pull requests

3 participants