bazel-gazelle icon indicating copy to clipboard operation
bazel-gazelle copied to clipboard

wrong `embedsrcs` are added when embedsrcs is coming from a rule

Open Links2004 opened this issue 1 year ago • 0 comments

What version of gazelle are you using?

0.39.1

What version of rules_go are you using?

0.50.1

What version of Bazel are you using?

7.4.0

Does this issue reproduce with the latest releases of all the above?

yes

What operating system and processor architecture are you using?

linux amd64

What did you do?

MODULE.bazel:

...
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
    name = "jfrog-cli",
    sha256 = "b3c92f70b75e7b05948ef70f015511928b986bd04ed60d90bb2fedcc62f1ea02",
    url = "https://releases.jfrog.io/artifactory/jfrog-cli/v2-jf/2.66.0/jfrog-cli-linux-amd64/jf",
)

BUILD.bazel:

load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_go//go:def.bzl", "go_binary", "go_library")

copy_file(
    name = "jf",
    src = "@jfrog-cli//file:file",
    out = "jf",
)

go_library(
    name = "download_test_lib",
    srcs = ["main.go"],
    embedsrcs = [
        ":jf",  #keep
    ],
    importpath = "local.test/download_test",
    visibility = ["//visibility:private"],
    deps = ["@com_github_rs_zerolog//log"],
)

go_binary(
    name = "download_test",
    embed = [":download_test_lib"],
    visibility = ["//visibility:public"],
)

main.go:

package main

import (
	_ "embed"
)

//go:embed jf
var test_data []byte

func main() {
	fmt.Printf("len: %d\n", len(test_data))
}

What did you expect to see?

running bazel run //:gazelle will not modify the embedsrcs.

What did you see instead?

running bazel run //:gazelle will modify the embedsrcs which breaks the build.

go_library(
    name = "download_test_lib",
    srcs = ["main.go"],
    embedsrcs = [
        ":jf",  #keep
        "jf",
    ],
    importpath = "local.test/download_test",
    visibility = ["//visibility:private"],
    deps = ["@com_github_rs_zerolog//log"],
)

Links2004 avatar Oct 28 '24 10:10 Links2004