diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 0714d0280..6e106c0b9 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -4,6 +4,9 @@ matrix:
- ubuntu2204
- macos
bazel: [6.x, 7.x]
+ bcr_variant:
+ - tests/bcr/go_work
+ - tests/bcr/go_mod
tasks:
ubuntu2204:
name: Ubuntu 22.04 with WORKSPACE
@@ -39,11 +42,12 @@ tasks:
name: BCR test module
platform: ${{ platform }}
bazel: ${{ bazel }}
- working_directory: tests/bcr
+ working_directory: ${{ bcr_variant }}
shell_commands:
# Regenerate the BUILD files for the test module using Gazelle.
# Also verify -repo_config are generated correctly in gazelle.bash
- rm pkg/BUILD.bazel proto/BUILD.bazel
+ - touch pkg/BUILD.bazel proto/BUILD.bazel
- bazel run //:gazelle -- update pkg proto
- bazel run //:gazelle -- pkg proto
build_targets:
@@ -59,7 +63,7 @@ tasks:
name: BCR test on Windows
platform: windows
bazel: ${{ bazel }}
- working_directory: tests/bcr
+ working_directory: ${{ bcr_variant }}
shell_commands:
# Regenerate the BUILD file for the test module using Gazelle.
# Also verify -repo_config are generated correctly in gazelle.bash
diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml
index 5ebe41093..e08fd1dff 100644
--- a/.bcr/presubmit.yml
+++ b/.bcr/presubmit.yml
@@ -1,5 +1,5 @@
bcr_test_module:
- module_path: tests/bcr
+ module_path: tests/bcr/go_mod
matrix:
platform:
- debian10
diff --git a/.gitignore b/.gitignore
index bea0af6e4..856a26b60 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,11 +2,11 @@
/bazel-bin
/bazel-out
/bazel-testlogs
-/tests/bcr/bazel-bcr
-/tests/bcr/bazel-bin
-/tests/bcr/bazel-out
-/tests/bcr/bazel-testlogs
-/tests/bcr/MODULE.bazel.lock
+/tests/bcr/*/bazel-go_*
+/tests/bcr/*/bazel-bin
+/tests/bcr/*/bazel-out
+/tests/bcr/*/bazel-testlogs
+/tests/bcr/*/MODULE.bazel.lock
MODULE.bazel.lock
.DS_STORE
.ijwb/
diff --git a/cmd/fetch_repo/BUILD.bazel b/cmd/fetch_repo/BUILD.bazel
index f0ffdb009..4e089c907 100644
--- a/cmd/fetch_repo/BUILD.bazel
+++ b/cmd/fetch_repo/BUILD.bazel
@@ -7,6 +7,7 @@ go_library(
"fetch_repo.go",
"go_mod_download.go",
"module.go",
+ "path.go",
"vcs.go",
],
importpath = "github.com/bazelbuild/bazel-gazelle/cmd/fetch_repo",
@@ -40,6 +41,7 @@ filegroup(
"fetch_repo_test.go",
"go_mod_download.go",
"module.go",
+ "path.go",
"vcs.go",
],
visibility = ["//visibility:public"],
diff --git a/cmd/fetch_repo/fetch_repo.go b/cmd/fetch_repo/fetch_repo.go
index f494bf81a..7646be916 100644
--- a/cmd/fetch_repo/fetch_repo.go
+++ b/cmd/fetch_repo/fetch_repo.go
@@ -34,6 +34,7 @@ import (
var (
// Common flags
importpath = flag.String("importpath", "", "Go importpath to the repository fetch")
+ path = flag.String("path", "", "absolute or relative path to a local go module")
dest = flag.String("dest", "", "destination directory")
// Repository flags
@@ -54,9 +55,11 @@ func main() {
log.SetPrefix("fetch_repo: ")
flag.Parse()
- if *importpath == "" {
- log.Fatal("-importpath must be set")
+
+ if *importpath == "" && *path == "" {
+ log.Fatal("-importpath or -path must be set")
}
+
if *dest == "" {
log.Fatal("-dest must be set")
}
@@ -64,7 +67,29 @@ func main() {
log.Fatal("fetch_repo does not accept positional arguments")
}
- if *version != "" {
+ if *path != "" {
+ if *importpath != "" {
+ log.Fatal("-importpath must not be set")
+ }
+ if *remote != "" {
+ log.Fatal("-remote must not be set in module path mode")
+ }
+ if *cmd != "" {
+ log.Fatal("-vcs must not be set in module path mode")
+ }
+ if *rev != "" {
+ log.Fatal("-rev must not be set in module path mode")
+ }
+ if *version != "" {
+ log.Fatal("-version must not be set in module path mode")
+ }
+ if *sum != "" {
+ log.Fatal("-sum must not be set in module path mode")
+ }
+ if err := moduleFromPath(*path, *dest); err != nil {
+ log.Fatal(err)
+ }
+ } else if *version != "" {
if *remote != "" {
log.Fatal("-remote must not be set in module mode")
}
diff --git a/cmd/fetch_repo/module.go b/cmd/fetch_repo/module.go
index 353d007a9..dab2fab97 100644
--- a/cmd/fetch_repo/module.go
+++ b/cmd/fetch_repo/module.go
@@ -17,8 +17,9 @@ package main
import (
"fmt"
- "golang.org/x/mod/sumdb/dirhash"
"os"
+
+ "golang.org/x/mod/sumdb/dirhash"
)
func fetchModule(dest, importpath, version, sum string) error {
@@ -33,7 +34,6 @@ func fetchModule(dest, importpath, version, sum string) error {
// so we create a dummy module in the current directory (which should be
// empty).
w, err := os.OpenFile("go.mod", os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o666)
-
if err != nil {
return fmt.Errorf("error creating temporary go.mod: %v", err)
}
@@ -46,7 +46,7 @@ func fetchModule(dest, importpath, version, sum string) error {
return fmt.Errorf("error closing temporary go.mod: %v", err)
}
- var dl = GoModDownloadResult{}
+ dl := GoModDownloadResult{}
err = runGoModDownload(&dl, dest, importpath, version)
os.Remove("go.mod")
if err != nil {
diff --git a/cmd/fetch_repo/path.go b/cmd/fetch_repo/path.go
new file mode 100644
index 000000000..0dcc4318f
--- /dev/null
+++ b/cmd/fetch_repo/path.go
@@ -0,0 +1,37 @@
+/* Copyright 2019 The Bazel Authors. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package main
+
+import (
+ "fmt"
+ "os/exec"
+)
+
+func moduleFromPath(from string, dest string) error {
+ err := copyTree(dest, from)
+ if err != nil {
+ return err
+ }
+
+ cmd := exec.Command(findGoPath(), "mod", "download", "-json", "-modcacherw")
+ cmd.Dir = dest
+
+ output, err := cmd.CombinedOutput()
+ if err != nil {
+ return fmt.Errorf("error running '%v': %v in %s. Output: %s", cmd.Args, err, dest, string(output))
+ }
+ return nil
+}
diff --git a/def.bzl b/def.bzl
index f348273ee..afba7e429 100644
--- a/def.bzl
+++ b/def.bzl
@@ -12,13 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+load(
+ "@bazel_gazelle_is_bazel_module//:defs.bzl",
+ "GAZELLE_IS_BAZEL_MODULE",
+)
load(
"@bazel_skylib//lib:shell.bzl",
"shell",
)
load(
- "@bazel_gazelle_is_bazel_module//:defs.bzl",
- "GAZELLE_IS_BAZEL_MODULE",
+ "//internal:gazelle_binary.bzl",
+ _gazelle_binary = "gazelle_binary_wrapper",
)
load(
"//internal:go_repository.bzl",
@@ -29,10 +33,6 @@ load(
_git_repository = "git_repository",
_http_archive = "http_archive",
)
-load(
- "//internal:gazelle_binary.bzl",
- _gazelle_binary = "gazelle_binary_wrapper",
-)
load(
"//internal/generationtest:generationtest.bzl",
_gazelle_generation_test = "gazelle_generation_test",
diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel
index a9937108b..6ce4ede3f 100644
--- a/docs/BUILD.bazel
+++ b/docs/BUILD.bazel
@@ -5,8 +5,8 @@ resulting documentation markdown files, to prevent users trying to load()
the stardoc repository, which is not a dependency users should install.
"""
-load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
# gazelle:ignore
diff --git a/internal/bzlmod/BUILD.bazel b/internal/bzlmod/BUILD.bazel
index 2bac102aa..20dd82709 100644
--- a/internal/bzlmod/BUILD.bazel
+++ b/internal/bzlmod/BUILD.bazel
@@ -30,6 +30,9 @@ bzl_library(
name = "go_mod",
srcs = ["go_mod.bzl"],
visibility = ["//:__subpackages__"],
+ deps = [
+ ":semver",
+ ],
)
bzl_library(
diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl
index e0bd42841..140465860 100644
--- a/internal/bzlmod/go_deps.bzl
+++ b/internal/bzlmod/go_deps.bzl
@@ -13,14 +13,14 @@
# limitations under the License.
load("//internal:go_repository.bzl", "go_repository")
-load(":go_mod.bzl", "deps_from_go_mod", "sums_from_go_mod")
load(
":default_gazelle_overrides.bzl",
"DEFAULT_BUILD_EXTRA_ARGS_BY_PATH",
"DEFAULT_BUILD_FILE_GENERATION_BY_PATH",
"DEFAULT_DIRECTIVES_BY_PATH",
)
-load(":semver.bzl", "semver")
+load(":go_mod.bzl", "deps_from_go_mod", "go_work_from_label", "sums_from_go_mod", "sums_from_go_work")
+load(":semver.bzl", "semver", "COMPARES_HIGHEST_SENTINEL")
load(
":utils.bzl",
"drop_nones",
@@ -276,6 +276,45 @@ _go_repository_config = repository_rule(
},
)
+def check_for_version_conflict(version, previous, module_tag, module_name_to_go_dot_mod_label, conflict_printer):
+ """
+ Check if duplicate modules have different versions, and fail with a useful error message if they do.
+
+ Args:
+ version: The version of the module.
+ previous: The previous module object.
+ module_tag: The module tag.
+ module_name_to_go_dot_mod_label: A dictionary mapping module paths to go.mod labels.
+ conflict_printer: a printer function to use for printing the error message, generally either print or fail.
+ """
+
+ if not previous or version == previous.version:
+ # no previous module, so no possible error OR
+ # version is the same, skip because we won't error
+ return
+
+ if hasattr(module_tag, "local_path"):
+ # overrides are not considered for version conflicts
+ return
+
+ # When using go.work, duplicate dependency versions are possible.
+ # This can cause issues, so we fail with a hopefully actionable error.
+ current_label = module_tag._parent_label
+
+ previous_label = previous.module_tag._parent_label
+
+ corrective_measure = """To correct this:
+ 1. ensure that '{}' in all go.mod files is the same version.
+ 2. in the folders where you made changes run: bazel run @rules_go//go -- mod tidy
+ 3. at the workspace root run: bazel run @rules_go//go -- work sync.""".format(module_tag.path)
+
+ message = """Multiple versions of {} found:
+ - {} contains: {}
+ - {} contains: {}
+{}""".format(module_tag.path, current_label, module_tag.version, previous_label, previous.module_tag.version, corrective_measure)
+
+ conflict_printer(message)
+
def _noop(_):
pass
@@ -344,9 +383,40 @@ def _go_deps_impl(module_ctx):
", ".join([str(tag.go_mod) for tag in module.tags.from_file]),
),
)
+
additional_module_tags = []
+ from_file_tags = []
+ module_name_to_go_dot_mod_label = {}
+
for from_file_tag in module.tags.from_file:
- module_path, module_tags_from_go_mod, go_mod_replace_map = deps_from_go_mod(module_ctx, from_file_tag.go_mod)
+ if bool(from_file_tag.go_work) == bool(from_file_tag.go_mod):
+ fail("go_deps.from_file tag must have either go_work or go_mod attribute, but not both.")
+
+ if from_file_tag.go_mod:
+ from_file_tags.append(from_file_tag)
+ elif from_file_tag.go_work:
+ if module.is_root != True:
+ fail("go_deps.from_file(go_work = '{}') tag can only be used from a root module but: '{}' is not a root module.".format(from_file_tag.go_work, module.name))
+
+ go_work = go_work_from_label(module_ctx, from_file_tag.go_work)
+
+ # this ensures go.work replacements are considered
+ additional_module_tags += [
+ with_replaced_or_new_fields(tag, _is_dev_dependency = False)
+ for tag in go_work.module_tags
+ ]
+
+ for entry, new_sum in sums_from_go_work(module_ctx, from_file_tag.go_work).items():
+ _safe_insert_sum(sums, entry, new_sum)
+
+ replace_map.update(go_work.replace_map)
+ from_file_tags = from_file_tags + go_work.from_file_tags
+ else:
+ fail("Either \"go_mod\" or \"go_work\" must be specified in \"go_deps.from_file\" tags.")
+
+ for from_file_tag in from_file_tags:
+ module_path, module_tags_from_go_mod, go_mod_replace_map, module_name = deps_from_go_mod(module_ctx, from_file_tag.go_mod)
+ module_name_to_go_dot_mod_label[module_name] = from_file_tag.go_mod
# Collect the relative path of the root module's go.mod file if it lives in the main
# repository.
@@ -363,7 +433,10 @@ def _go_deps_impl(module_ctx):
]
if module.is_root or getattr(module_ctx, "is_isolated", False):
- replace_map.update(go_mod_replace_map)
+ # for the replace_map, first in wins
+ for mod_path, mod in go_mod_replace_map.items():
+ if not mod_path in replace_map:
+ replace_map[mod_path] = mod
else:
# Register this Bazel module as providing the specified Go module. It participates
# in version resolution using its registry version, which uses a relaxed variant of
@@ -406,12 +479,11 @@ def _go_deps_impl(module_ctx):
# transitive dependencies have also been declared - we may end up
# resolving them to higher versions, but only compatible ones.
paths = {}
+
for module_tag in module.tags.module + additional_module_tags:
- if module_tag.path in paths:
- fail("Duplicate Go module path \"{}\" in module \"{}\".".format(module_tag.path, module.name))
if module_tag.path in bazel_deps:
continue
- paths[module_tag.path] = None
+
raw_version = _canonicalize_raw_version(module_tag.version)
# For modules imported from a go.sum, we know which ones are direct
@@ -427,11 +499,30 @@ def _go_deps_impl(module_ctx):
root_module_direct_deps[_repo_name(module_tag.path)] = None
version = semver.to_comparable(raw_version)
+ previous = paths.get(module_tag.path)
+
+ fail_on_version_conflict = any([x.fail_on_version_conflict for x in module.tags.from_file])
+
+ conflict_printer = fail if fail_on_version_conflict else print
+ check_for_version_conflict(version, previous, module_tag, module_name_to_go_dot_mod_label, conflict_printer)
+ paths[module_tag.path] = struct(version = version, module_tag = module_tag)
+
if module_tag.path not in module_resolutions or version > module_resolutions[module_tag.path].version:
+ to_path = None
+ local_path = None
+
+ if module_tag.path in replace_map:
+ replacement = replace_map[module_tag.path]
+
+ to_path = replacement.to_path
+ local_path = replacement.local_path
+
module_resolutions[module_tag.path] = struct(
repo_name = _repo_name(module_tag.path),
version = version,
raw_version = raw_version,
+ to_path = to_path,
+ local_path = local_path,
)
_fail_on_unmatched_overrides(archive_overrides.keys(), module_resolutions, "archive_overrides")
@@ -506,7 +597,6 @@ def _go_deps_impl(module_ctx):
# Do not create a go_repository for a dep shared with the non-isolated instance of
# go_deps.
continue
-
go_repository_args = {
"name": module.repo_name,
"importpath": path,
@@ -526,6 +616,12 @@ def _go_deps_impl(module_ctx):
"patches": _get_patches(path, archive_overrides),
"patch_args": _get_patch_args(path, archive_overrides),
})
+ elif module.local_path:
+ go_repository_args.update({
+ # the version is now meaningless
+ "version": None,
+ "local_path": module.local_path,
+ })
else:
go_repository_args.update({
"sum": _get_sum_from_module(path, module, sums),
@@ -580,13 +676,17 @@ def _get_sum_from_module(path, module, sums):
entry = (module.replace, module.raw_version)
if entry not in sums:
- fail("No sum for {}@{} found".format(path, module.raw_version))
+ if module.raw_version == COMPARES_HIGHEST_SENTINEL:
+ # replacement have no sums, so we can skip this
+ return None
+ elif module.local_path== None:
+ fail("No sum for {}@{} from {} found. You may need to run: bazel run @rules_go//go -- mod tidy".format(path, module.raw_version, "parent-label-todo")) #module.parent_label))
return sums[entry]
def _safe_insert_sum(sums, entry, new_sum):
if entry in sums and new_sum != sums[entry]:
- fail("Multiple mismatching sums for {}@{} found.".format(entry[0], entry[1]))
+ fail("Multiple mismatching sums for {}@{} found: {} vs {}".format(entry[0], entry[1], new_sum, sums[entry]))
sums[entry] = new_sum
def _canonicalize_raw_version(raw_version):
@@ -607,7 +707,12 @@ _config_tag = tag_class(
_from_file_tag = tag_class(
attrs = {
- "go_mod": attr.label(mandatory = True),
+ "go_mod": attr.label(mandatory = False),
+ "go_work": attr.label(mandatory = False),
+ "fail_on_version_conflict": attr.bool(
+ default = True,
+ doc = "Fail if duplicate modules have different versions",
+ ),
},
)
@@ -622,6 +727,10 @@ _module_tag = tag_class(
),
"build_naming_convention": attr.string(doc = """Removed, do not use""", default = ""),
"build_file_proto_mode": attr.string(doc = """Removed, do not use""", default = ""),
+ "local_path": attr.string(
+ doc = """For when a module is replaced by one residing in a local directory path """,
+ mandatory = False,
+ ),
},
)
diff --git a/internal/bzlmod/go_mod.bzl b/internal/bzlmod/go_mod.bzl
index 59e134670..80556543f 100644
--- a/internal/bzlmod/go_mod.bzl
+++ b/internal/bzlmod/go_mod.bzl
@@ -12,10 +12,141 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+load(":semver.bzl", "COMPARES_HIGHEST_SENTINEL")
+
visibility([
"//tests/bzlmod/...",
])
+def _validate_go_version(path, state, tokens, line_no):
+ if len(tokens) == 1:
+ fail("{}:{}: expected another token after 'go'".format(path, line_no))
+ if state["go"] != None:
+ fail("{}:{}: unexpected second 'go' directive".format(path, line_no))
+ if len(tokens) > 2:
+ fail("{}:{}: unexpected token '{}' after '{}'".format(path, line_no, tokens[2], tokens[1]))
+
+def use_spec_to_label(repo_name, use_directive):
+ if use_directive.startswith("../") or "/../" in use_directive or use_directive.endswith("/.."):
+ fail("go.work use directive: '{}' contains '..' which is not currently supported.".format(use_directive))
+
+ if use_directive.startswith("/"):
+ fail("go.work use directive: '{}' is an absolute path, which is not currently supported.".format(use_directive))
+
+ if use_directive.startswith("./"):
+ use_directive = use_directive[2:]
+
+ if use_directive.endswith("/"):
+ use_directive = use_directive[:-1]
+
+ return Label("@@{}//{}:go.mod".format(repo_name, use_directive))
+
+def go_work_from_label(module_ctx, go_work_label):
+ """Loads deps from a go.work file"""
+ go_work_path = module_ctx.path(go_work_label)
+ go_work_content = module_ctx.read(go_work_path)
+ go_work = parse_go_work(go_work_content, go_work_label)
+
+ return _relativize_replace_paths(go_work, go_work_path)
+
+def parse_go_work(content, go_work_label):
+ # see: https://go.dev/ref/mod#go-work-file
+
+ # Valid directive values understood by this parser never contain tabs or
+ # carriage returns, so we can simplify the parsing below by canonicalizing
+ # whitespace upfront.
+ content = content.replace("\t", " ").replace("\r", " ")
+
+ state = {
+ "go": None,
+ "use": [],
+ "replace": {},
+ }
+
+ current_directive = None
+ for line_no, line in enumerate(content.splitlines(), 1):
+ tokens, _ = _tokenize_line(line, go_work_label.name, line_no)
+
+ if not tokens:
+ continue
+
+ if current_directive:
+ if tokens[0] == ")":
+ current_directive = None
+ elif current_directive == "use":
+ state["use"].append(tokens[0])
+ elif current_directive == "replace":
+ _parse_replace_directive(state, tokens, go_work_label.name, line_no)
+ else:
+ fail("{}:{}: unexpected directive '{}'".format(go_work_label.name, line_no, current_directive))
+ elif tokens[0] == "go":
+ _validate_go_version(go_work_label.name, state, tokens, line_no)
+ go = tokens[1]
+ elif tokens[0] == "replace":
+ if tokens[1] == "(":
+ current_directive = tokens[0]
+ continue
+ else:
+ _parse_replace_directive(state, tokens[1:], go_work_label.name, line_no)
+ elif tokens[0] == "use":
+ if len(tokens) != 2:
+ fail("{}:{}: expected path or block in 'use' directive".format(go_work_label.name, line_no))
+ elif tokens[1] == "(":
+ current_directive = tokens[0]
+ continue
+ else:
+ state["use"].append(tokens[1])
+ else:
+ fail("{}:{}: unexpected directive '{}'".format(go_work_label.name, line_no, tokens[0]))
+
+ major, minor = go.split(".")[:2]
+
+ go_mods = [use_spec_to_label(go_work_label.workspace_name, use) for use in state["use"]]
+ from_file_tags = [struct(go_mod = go_mod, _is_dev_dependency = False) for go_mod in go_mods]
+
+ module_tags = [struct(version = mod.version, path = mod.to_path, _parent_label = go_work_label, local_path = mod.local_path, indirect = False) for mod in state["replace"].values()]
+
+ return struct(
+ go = (int(major), int(minor)),
+ from_file_tags = from_file_tags,
+ replace_map = state["replace"],
+ module_tags = module_tags,
+ use = state["use"],
+ )
+
+# this exists because we are unable to create a path object in unit tests, we
+# must do this as a post-process step or we cannot unit test go_mod parsing
+def _relativize_replace_paths(go_mod, go_mod_path):
+ new_replace_map = {}
+
+ for key in go_mod.replace_map:
+ value = go_mod.replace_map[key]
+
+ local_path = value.local_path
+
+ if local_path:
+ # drop the go.mod from the path, to get the directory
+ directory = go_mod_path.dirname
+
+ # now that we have the directory, we can use the use replace directive to get the full path
+ local_path = str(directory.get_child(local_path))
+
+ new_replace_map[key] = struct(
+ from_version = value.from_version,
+ to_path = value.to_path,
+ version = value.version,
+ local_path = local_path,
+ )
+
+ new_go_mod = {
+ attr: getattr(go_mod, attr)
+ for attr in dir(go_mod)
+ if not type(getattr(go_mod, attr)) == 'builtin_function_or_method'
+ }
+
+ new_go_mod["replace_map"] = new_replace_map
+ return struct(**new_go_mod)
+
def deps_from_go_mod(module_ctx, go_mod_label):
"""Loads the entries from a go.mod file.
@@ -33,6 +164,7 @@ def deps_from_go_mod(module_ctx, go_mod_label):
go_mod_path = module_ctx.path(go_mod_label)
go_mod_content = module_ctx.read(go_mod_path)
go_mod = parse_go_mod(go_mod_content, go_mod_path)
+ go_mod = _relativize_replace_paths(go_mod, go_mod_path)
if go_mod.go[0] != 1 or go_mod.go[1] < 17:
# go.mod files only include entries for all transitive dependencies as
@@ -45,9 +177,11 @@ def deps_from_go_mod(module_ctx, go_mod_label):
path = require.path,
version = require.version,
indirect = require.indirect,
+ local_path = None,
+ _parent_label = go_mod_label,
))
- return go_mod.module, deps, go_mod.replace_map
+ return go_mod.module, deps, go_mod.replace_map, go_mod.module
def parse_go_mod(content, path):
# See https://go.dev/ref/mod#go-mod-file.
@@ -79,13 +213,8 @@ def parse_go_mod(content, path):
# The 'go' directive only has a single-line form and is thus parsed
# here rather than in _parse_directive.
if tokens[0] == "go":
- if len(tokens) == 1:
- fail("{}:{}: expected another token after 'go'".format(path, line_no))
- if state["go"] != None:
- fail("{}:{}: unexpected second 'go' directive".format(path, line_no))
+ _validate_go_version(path, state, tokens, line_no)
state["go"] = tokens[1]
- if len(tokens) > 2:
- fail("{}:{}: unexpected token '{}' after '{}'".format(path, line_no, tokens[2], tokens[1]))
if tokens[1] == "(":
current_directive = tokens[0]
@@ -139,37 +268,52 @@ def _parse_directive(state, directive, tokens, comment, path, line_no):
indirect = comment == "indirect",
))
elif directive == "replace":
- # A replace directive might use a local file path beginning with ./ or ../
- # These are not supported with gazelle~go_deps.
- if (len(tokens) == 3 and tokens[2][0] == ".") or (len(tokens) > 3 and tokens[3][0] == "."):
- fail("{}:{}: local file path not supported in replace directive: '{}'".format(path, line_no, tokens[2]))
-
- # replacements key off of the from_path
- from_path = tokens[0]
-
- # pattern: replace from_path => to_path to_version
- if len(tokens) == 4 and tokens[1] == "=>":
- state["replace"][from_path] = struct(
- from_version = None,
- to_path = tokens[2],
- version = _canonicalize_raw_version(tokens[3]),
- )
- # pattern: replace from_path from_version => to_path to_version
- elif len(tokens) == 5 and tokens[2] == "=>":
- state["replace"][from_path] = struct(
- from_version = _canonicalize_raw_version(tokens[1]),
- to_path = tokens[3],
- version = _canonicalize_raw_version(tokens[4]),
- )
- else:
- fail(
- "{}:{}: replace directive must follow pattern: ".format(path, line_no) +
- "'replace from_path from_version => to_path to_version' or " +
- "'replace from_path => to_path to_version'"
- )
+ _parse_replace_directive(state, tokens, path, line_no)
# TODO: Handle exclude.
+def _parse_replace_directive(state, tokens, path, line_no):
+ # replacements key off of the from_path
+ from_path = tokens[0]
+
+ # pattern: replace from_path => to_path to_version
+ if len(tokens) == 4 and tokens[1] == "=>":
+ state["replace"][from_path] = struct(
+ from_version = None,
+ to_path = tokens[2],
+ local_path = None,
+ version = _canonicalize_raw_version(tokens[3]),
+ )
+
+ # pattern: replace from_path from_version => to_path to_version
+ elif len(tokens) == 5 and tokens[2] == "=>":
+ state["replace"][from_path] = struct(
+ from_version = _canonicalize_raw_version(tokens[1]),
+ to_path = tokens[3],
+ version = _canonicalize_raw_version(tokens[4]),
+ local_path = None,
+ )
+
+ # pattern: replace from_path from_version => file_path
+ elif len(tokens) == 4 and tokens[2] == "=>":
+ state["replace"][from_path] = struct(
+ from_version = _canonicalize_raw_version(tokens[1]),
+ to_path = from_path,
+ local_path = tokens[3],
+ version = COMPARES_HIGHEST_SENTINEL
+ )
+
+ # pattern: replace from_path => to_path
+ elif len(tokens) == 3 and tokens[1] == "=>":
+ state["replace"][from_path] = struct(
+ from_version = None,
+ to_path = from_path,
+ local_path = tokens[2],
+ version = COMPARES_HIGHEST_SENTINEL
+ )
+ else:
+ fail("{}:{}: unexpected tokens '{}'".format(path, line_no, tokens))
+
def _tokenize_line(line, path, line_no):
tokens = []
r = line
@@ -240,16 +384,55 @@ def sums_from_go_mod(module_ctx, go_mod_label):
"""
_check_go_mod_name(go_mod_label.name)
- # We go through a Label so that the module extension is restarted if go.sum
+ return parse_sumfile(module_ctx, go_mod_label, "go.sum")
+
+def sums_from_go_work(module_ctx, go_work_label):
+ """Loads the entries from a go.work.sum file given a go.work label.
+
+ Args:
+ module_ctx: a https://bazel.build/rules/lib/module_ctx object
+ passed from the MODULE.bazel call.
+ go_work_label: a Label for a `go.work` file. This label is used
+ to find the associated `go.work.sum` file.
+
+ Returns:
+ A Dict[(string, string) -> (string)] is returned where each entry
+ is defined by a Go Module's sum:
+ (path, version) -> (sum)
+ """
+ _check_go_work_name(go_work_label.name)
+
+ # next we need to test if the go.work.sum file exists, this is a little tricky so we use an indirect approach:
+
+ # 1. convert go_work_label into a path
+ go_work_path = module_ctx.path(go_work_label)
+
+ # 2. use the go_work_path to create a path for the heisen go.work.sum file
+ maybe_go_work_sum_path = go_work_path.dirname.get_child("go.work.sum")
+
+ # 3. check for its existence
+ if maybe_go_work_sum_path.exists:
+ return parse_sumfile(module_ctx, go_work_label, "go.work.sum")
+ else:
+ # 4. if go.work.sum does not exist, we should watch it in case it appears in the future
+ if hasattr(module_ctx, "watch"):
+ # module_ctx.watch_tree is only available in bazel >= 7.1
+ module_ctx.watch(maybe_go_work_sum_path)
+
+ # 5. return an empty dict as no sum file was found
+ return {}
+
+def parse_sumfile(module_ctx, label, sumfile):
+ # We go through a Label so that the module extension is restarted if the sumfile
# changes. We have to use a canonical label as we may not have visibility
- # into the module that provides the go.sum.
- go_sum_label = Label("@@{}//{}:{}".format(
- go_mod_label.workspace_name,
- go_mod_label.package,
- "go.sum",
+ # into the module that provides the sumfile
+ sum_label = Label("@@{}//{}:{}".format(
+ label.workspace_name,
+ label.package,
+ sumfile,
))
- go_sum_content = module_ctx.read(go_sum_label)
- return parse_go_sum(go_sum_content)
+
+ return parse_go_sum(module_ctx.read(sum_label))
def parse_go_sum(content):
hashes = {}
@@ -264,6 +447,10 @@ def _check_go_mod_name(name):
if name != "go.mod":
fail("go_deps.from_file requires a 'go.mod' file, not '{}'".format(name))
+def _check_go_work_name(name):
+ if name != "go.work":
+ fail("go_deps.from_file requires a 'go.work' file, not '{}'".format(name))
+
def _canonicalize_raw_version(raw_version):
if raw_version.startswith("v"):
return raw_version[1:]
diff --git a/internal/bzlmod/non_module_deps.bzl b/internal/bzlmod/non_module_deps.bzl
index 1a97eb7ec..d7572c263 100644
--- a/internal/bzlmod/non_module_deps.bzl
+++ b/internal/bzlmod/non_module_deps.bzl
@@ -12,6 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+load(
+ "@bazel_gazelle_go_repository_config//:go_env.bzl",
+ "GO_ENV",
+)
+load(
+ "@go_host_compatible_sdk_label//:defs.bzl",
+ "HOST_COMPATIBLE_SDK",
+)
load(
"//internal:go_repository_cache.bzl",
"go_repository_cache",
@@ -28,14 +36,6 @@ load(
"//internal/bzlmod:utils.bzl",
"extension_metadata",
)
-load(
- "@go_host_compatible_sdk_label//:defs.bzl",
- "HOST_COMPATIBLE_SDK",
-)
-load(
- "@bazel_gazelle_go_repository_config//:go_env.bzl",
- "GO_ENV",
-)
visibility("//")
diff --git a/internal/bzlmod/semver.bzl b/internal/bzlmod/semver.bzl
index d79a4f4bf..2ae030840 100644
--- a/internal/bzlmod/semver.bzl
+++ b/internal/bzlmod/semver.bzl
@@ -17,10 +17,10 @@ visibility([
])
# Compares lower than any non-numeric identifier.
-_COMPARES_LOWEST_SENTINEL = ""
+COMPARES_LOWEST_SENTINEL = ""
# Compares higher than any valid non-numeric identifier (containing only [A-Za-z0-9-]).
-_COMPARES_HIGHEST_SENTINEL = "{"
+COMPARES_HIGHEST_SENTINEL = "{"
def _identifier_to_comparable(ident, *, numeric_only):
if not ident:
@@ -33,7 +33,9 @@ def _identifier_to_comparable(ident, *, numeric_only):
# "Identifiers consisting of only digits are compared numerically."
# 11.4.3:
# "Numeric identifiers always have lower precedence than non-numeric identifiers."
- return (_COMPARES_LOWEST_SENTINEL, int(ident))
+ return (COMPARES_LOWEST_SENTINEL, int(ident))
+ elif ident == COMPARES_HIGHEST_SENTINEL:
+ return (ident,)
elif numeric_only:
fail("Expected a numeric identifier, got: " + ident)
else:
@@ -64,10 +66,10 @@ def _semver_to_comparable(v, *, relaxed = False):
else:
# 11.3:
# "When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version."
- prerelease = [(_COMPARES_HIGHEST_SENTINEL,)]
+ prerelease = [(COMPARES_HIGHEST_SENTINEL,)]
release = release_str.split(".")
- if not relaxed and len(release) != 3:
+ if not v == COMPARES_HIGHEST_SENTINEL and not relaxed and len(release) != 3:
fail("Semantic version strings must have exactly three dot-separated components, got: " + v)
return (
diff --git a/internal/extend_docs.bzl b/internal/extend_docs.bzl
index 7fc16068e..3ea4a8640 100644
--- a/internal/extend_docs.bzl
+++ b/internal/extend_docs.bzl
@@ -109,11 +109,11 @@ includes the proto package name, as well as source names, imports, and options.
[proto.Package]: https://godoc.org/github.com/bazelbuild/bazel-gazelle/language/proto#Package
"""
-load("gazelle_binary.bzl", _gazelle_binary = "gazelle_binary")
load(
"//internal/generationtest:generationtest.bzl",
_gazelle_generation_test = "gazelle_generation_test",
)
+load("gazelle_binary.bzl", _gazelle_binary = "gazelle_binary")
gazelle_binary = _gazelle_binary
diff --git a/internal/go_repository.bzl b/internal/go_repository.bzl
index d7e74f90e..627a1f9e3 100644
--- a/internal/go_repository.bzl
+++ b/internal/go_repository.bzl
@@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "read_user_netrc", "use_netrc")
load("//internal:common.bzl", "env_execute", "executable_extension")
load("//internal:go_repository_cache.bzl", "read_cache_env")
-load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "read_user_netrc", "use_netrc")
_DOC = """
`go_repository` downloads a Go project and generates build files with Gazelle
@@ -133,7 +133,9 @@ def _go_repository_impl(ctx):
if generate:
gazelle_path = ctx.path(Label(_gazelle))
- if ctx.attr.urls:
+ if ctx.attr.local_path:
+ pass
+ elif ctx.attr.urls:
# HTTP mode
for key in ("commit", "tag", "vcs", "remote", "version", "sum", "replace"):
if getattr(ctx.attr, key):
@@ -178,7 +180,7 @@ def _go_repository_impl(ctx):
for key in ("urls", "strip_prefix", "type", "sha256", "commit", "tag", "vcs", "remote"):
if getattr(ctx.attr, key):
fail("cannot specify both version and %s" % key)
- if not ctx.attr.sum:
+ if ctx.attr.version and not ctx.attr.sum:
fail("if version is specified, sum must also be")
fetch_path = ctx.attr.replace if ctx.attr.replace else ctx.attr.importpath
@@ -193,16 +195,18 @@ def _go_repository_impl(ctx):
env = read_cache_env(ctx, go_env_cache)
env_keys = [
+ # keep sorted
+
# Respect user proxy and sumdb settings for privacy.
# TODO(jayconrod): gazelle in go_repository mode should probably
# not go out to the network at all. This means *the build*
# goes out to the network. We tolerate this for downloading
# archives, but finding module roots is a bit much.
- "GOPROXY",
"GONOPROXY",
+ "GONOSUMDB",
"GOPRIVATE",
+ "GOPROXY",
"GOSUMDB",
- "GONOSUMDB",
# PATH is needed to locate git and other vcs tools.
"PATH",
@@ -211,19 +215,23 @@ def _go_repository_impl(ctx):
"HOME",
# Settings below are used by vcs tools.
- "SSH_AUTH_SOCK",
- "SSL_CERT_FILE",
- "SSL_CERT_DIR",
- "HTTP_PROXY",
+ "GIT_CONFIG",
+ "GIT_CONFIG_COUNT",
+ "GIT_CONFIG_GLOBAL",
+ "GIT_CONFIG_NOSYSTEM",
+ "GIT_CONFIG_SYSTEM",
+ "GIT_SSH",
+ "GIT_SSH_COMMAND",
+ "GIT_SSL_CAINFO",
"HTTPS_PROXY",
+ "HTTP_PROXY",
"NO_PROXY",
+ "SSH_AUTH_SOCK",
+ "SSL_CERT_DIR",
+ "SSL_CERT_FILE",
"http_proxy",
"https_proxy",
"no_proxy",
- "GIT_SSL_CAINFO",
- "GIT_SSH",
- "GIT_SSH_COMMAND",
- "GIT_CONFIG_COUNT",
]
# Git allows passing configuration through environmental variables, this will be picked
@@ -244,6 +252,32 @@ def _go_repository_impl(ctx):
env.update({k: ctx.os.environ[k] for k in env_keys if k in ctx.os.environ})
+ if ctx.attr.local_path:
+ local_path_env = dict(env)
+ local_path_env["GOSUMDB"] = "off"
+
+ # Override external GO111MODULE, because it is needed by module mode, no-op in repository mode
+ local_path_env["GO111MODULE"] = "on"
+
+ if hasattr(ctx, "watch_tree"):
+ # https://github.com/bazelbuild/bazel/commit/fffa0affebbacf1961a97ef7cd248be64487d480
+ ctx.watch_tree(ctx.attr.local_path)
+ else:
+ print("""
+ WARNING: go.mod replace directives to module paths is only supported in bazel 7.1.0-rc1 or later,
+ Because of this changes to %s will not be detected by your version of Bazel.""" % ctx.attr.local_path)
+
+ command = [fetch_repo, "--path", ctx.attr.local_path, "--dest", ctx.path("")]
+ result = env_execute(
+ ctx,
+ command,
+ environment = local_path_env,
+ timeout = _GO_REPOSITORY_TIMEOUT,
+ )
+
+ if result.return_code:
+ fail(command)
+
if fetch_repo_args:
# Disable sumdb in fetch_repo. In module mode, the sum is a mandatory
# attribute of go_repository, so we don't need to look it up.
@@ -260,9 +294,7 @@ def _go_repository_impl(ctx):
timeout = _GO_REPOSITORY_TIMEOUT,
)
if result.return_code:
- fail("failed to fetch %s: %s" % (ctx.name, result.stderr))
- if ctx.attr.debug_mode and result.stderr:
- print("fetch_repo: " + result.stderr)
+ fail("%s: %s" % (ctx.name, result.stderr))
# Repositories are fetched. Determine if build file generation is needed.
build_file_names = ctx.attr.build_file_name.split(",")
@@ -314,7 +346,7 @@ def _go_repository_impl(ctx):
"-repo_config",
repo_config,
]
- if ctx.attr.version:
+ if ctx.attr.version or ctx.attr.local_path:
cmd.append("-go_repository_module_mode")
if ctx.attr.build_file_name:
cmd.extend(["-build_file_name", ctx.attr.build_file_name])
@@ -428,6 +460,11 @@ go_repository = repository_rule(
doc = _AUTH_PATTERN_DOC,
),
+ # Attributes for a module that should be loaded from the local file system.
+ "local_path": attr.string(
+ doc = """ If specified, `go_repository` will load the module from this local directory""",
+ ),
+
# Attributes for a module that should be downloaded with the Go toolchain.
"version": attr.string(
doc = """If specified, `go_repository` will download the module at this version
diff --git a/internal/go_repository_tools_srcs.bzl b/internal/go_repository_tools_srcs.bzl
index 218f380c4..0a2c4033d 100644
--- a/internal/go_repository_tools_srcs.bzl
+++ b/internal/go_repository_tools_srcs.bzl
@@ -12,6 +12,7 @@ GO_REPOSITORY_TOOLS_SRCS = [
Label("//cmd/fetch_repo:fetch_repo.go"),
Label("//cmd/fetch_repo:go_mod_download.go"),
Label("//cmd/fetch_repo:module.go"),
+ Label("//cmd/fetch_repo:path.go"),
Label("//cmd/fetch_repo:vcs.go"),
Label("//cmd/gazelle:BUILD.bazel"),
Label("//cmd/gazelle:diff.go"),
diff --git a/repository.md b/repository.md
index b5c2eb926..5fa4f192d 100644
--- a/repository.md
+++ b/repository.md
@@ -102,9 +102,9 @@ git_repository(
go_repository(name, auth_patterns, build_config, build_directives, build_external, build_extra_args,
build_file_generation, build_file_name, build_file_proto_mode, build_naming_convention,
- build_tags, canonical_id, commit, debug_mode, importpath, patch_args, patch_cmds,
- patch_tool, patches, remote, replace, repo_mapping, sha256, strip_prefix, sum, tag,
- type, urls, vcs, version)
+ build_tags, canonical_id, commit, debug_mode, importpath, local_path, patch_args,
+ patch_cmds, patch_tool, patches, remote, replace, repo_mapping, sha256, strip_prefix,
+ sum, tag, type, urls, vcs, version)
`go_repository` downloads a Go project and generates build files with Gazelle
@@ -187,6 +187,7 @@ go_repository(
| commit | If the repository is downloaded using a version control tool, this is the commit or revision to check out. With git, this would be a sha1 commit id. `commit` and `tag` may not both be set. | String | optional | `""` |
| debug_mode | Enables logging of fetch_repo and Gazelle output during succcesful runs. Gazelle can be noisy so this defaults to `False`. However, setting to `True` can be useful for debugging build failures and unexpected behavior for the given rule. | Boolean | optional | `False` |
| importpath | The Go import path that matches the root directory of this repository.
In module mode (when `version` is set), this must be the module path. If neither `urls` nor `remote` is specified, `go_repository` will automatically find the true path of the module, applying import path redirection.
If build files are generated for this repository, libraries will have their `importpath` attributes prefixed with this `importpath` string. | String | required | |
+| local_path | If specified, `go_repository` will load the module from this local directory | String | optional | `""` |
| patch_args | Arguments passed to the patch tool when applying patches. | List of strings | optional | `["-p0"]` |
| patch_cmds | Commands to run in the repository after patches are applied. | List of strings | optional | `[]` |
| patch_tool | The patch tool used to apply `patches`. If this is specified, Bazel will use the specifed patch tool instead of the Bazel-native patch implementation. | String | optional | `""` |
diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel
index e2ebfeaf6..17f1aa607 100644
--- a/tests/BUILD.bazel
+++ b/tests/BUILD.bazel
@@ -3,7 +3,6 @@ load(
"gazelle_binary",
"gazelle_generation_test",
)
-
load("//tests:tools.bzl", "get_binary")
# Exclude this entire directly from having anything gnerated by Gazelle. That
diff --git a/tests/bcr/go.sum b/tests/bcr/go.sum
deleted file mode 100644
index ee03e8091..000000000
--- a/tests/bcr/go.sum
+++ /dev/null
@@ -1,54 +0,0 @@
-github.com/DataDog/sketches-go v1.4.1 h1:j5G6as+9FASM2qC36lvpvQAj9qsv/jUs3FtO8CwZNAY=
-github.com/DataDog/sketches-go v1.4.1/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk=
-github.com/bazelbuild/bazel-gazelle v0.30.0 h1:q9XLWQSCA5NZPJ98WFqicHkq6fxrDPnfvMO1XycQBMg=
-github.com/bazelbuild/bazel-gazelle v0.30.0/go.mod h1:6RxhjM1v/lTpD3JlMpKUCcdus4tvdqsqdfbjYi+czYs=
-github.com/bazelbuild/rules_go v0.39.1 h1:wkJLUDx59dntWMghuL8++GteoU1To6sRoKJXuyFtmf8=
-github.com/bazelbuild/rules_go v0.39.1/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU=
-github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
-github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
-github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
-github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
-github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
-github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
-github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
-github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/envoyproxy/protoc-gen-validate v1.0.1 h1:kt9FtLiooDc0vbwTLhdg3dyNX1K9Qwa1EK9LcD4jVUQ=
-github.com/envoyproxy/protoc-gen-validate v1.0.1/go.mod h1:0vj8bNkYbSTNS2PIyH87KZaeN4x9zpL9Qt8fQC7d+vs=
-github.com/fmeum/dep_on_gazelle v1.0.0 h1:7gEtQ2CoD77tYca+1iUnKjIBUZ4mX7mZwjdWp3uuN/E=
-github.com/fmeum/dep_on_gazelle v1.0.0/go.mod h1:VYCjwfsyRHOJL8oenaEjhIzgM7Oj70iTxgJ2RfXbYr0=
-github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
-github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
-github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
-github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
-github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
-github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
-github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 h1:SJ+NtwL6QaZ21U+IrK7d0gGgpjGGvd2kz+FzTHVzdqI=
-github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2/go.mod h1:Tv1PlzqC9t8wNnpPdctvtSUOPUUg4SHeE6vR1Ir2hmg=
-github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
-github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
-github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
-github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
-github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
-github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
-golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
-google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
-google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
-google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
-google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
-google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
-google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/tests/bcr/.bazelignore b/tests/bcr/go_mod/.bazelignore
similarity index 100%
rename from tests/bcr/.bazelignore
rename to tests/bcr/go_mod/.bazelignore
diff --git a/tests/bcr/.bazelrc b/tests/bcr/go_mod/.bazelrc
similarity index 100%
rename from tests/bcr/.bazelrc
rename to tests/bcr/go_mod/.bazelrc
diff --git a/tests/bcr/.bazelversion b/tests/bcr/go_mod/.bazelversion
similarity index 100%
rename from tests/bcr/.bazelversion
rename to tests/bcr/go_mod/.bazelversion
diff --git a/tests/bcr/BUILD.bazel b/tests/bcr/go_mod/BUILD.bazel
similarity index 100%
rename from tests/bcr/BUILD.bazel
rename to tests/bcr/go_mod/BUILD.bazel
diff --git a/tests/bcr/MODULE.bazel b/tests/bcr/go_mod/MODULE.bazel
similarity index 98%
rename from tests/bcr/MODULE.bazel
rename to tests/bcr/go_mod/MODULE.bazel
index 68d51d810..858a52782 100644
--- a/tests/bcr/MODULE.bazel
+++ b/tests/bcr/go_mod/MODULE.bazel
@@ -1,11 +1,11 @@
module(
- name = "gazelle_bcr_tests",
+ name = "gazelle_bcr_go_mod_tests",
)
bazel_dep(name = "gazelle", version = "")
local_path_override(
module_name = "gazelle",
- path = "../..",
+ path = "../../..",
)
bazel_dep(name = "test_dep", version = "1.0.0")
@@ -138,6 +138,7 @@ use_repo(
# "in_gopkg_yaml_v3",
# Only used for testing.
"bazel_gazelle_go_repository_config",
+ "org_example_hello",
)
# Use an isolated usage to bring in Go tools from the tools package with their own dependency
diff --git a/tests/bcr/WORKSPACE b/tests/bcr/go_mod/WORKSPACE
similarity index 100%
rename from tests/bcr/WORKSPACE
rename to tests/bcr/go_mod/WORKSPACE
diff --git a/tests/bcr/WORKSPACE.bzlmod b/tests/bcr/go_mod/WORKSPACE.bzlmod
similarity index 100%
rename from tests/bcr/WORKSPACE.bzlmod
rename to tests/bcr/go_mod/WORKSPACE.bzlmod
diff --git a/tests/bcr/go.mod b/tests/bcr/go_mod/go.mod
similarity index 59%
rename from tests/bcr/go.mod
rename to tests/bcr/go_mod/go.mod
index d4f1957f5..030865263 100644
--- a/tests/bcr/go.mod
+++ b/tests/bcr/go_mod/go.mod
@@ -1,25 +1,35 @@
// This will stop go mod from descending into this directory.
-module github.com/bazelbuild/bazel-gazelle/tests/bcr
+module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_mod
-go 1.19
+go 1.21.5
// Validate go.mod replace directives can be properly used:
replace github.com/bmatcuk/doublestar/v4 => github.com/bmatcuk/doublestar v1.3.4
require (
+ example.org/hello v1.0.0
github.com/DataDog/sketches-go v1.4.1
+ github.com/bazelbuild/buildtools v0.0.0-20230317132445-9c3c1fc0106e
github.com/bazelbuild/rules_go v0.39.1
github.com/bmatcuk/doublestar/v4 v4.6.0
github.com/cloudflare/circl v1.3.7
github.com/envoyproxy/protoc-gen-validate v1.0.1
github.com/fmeum/dep_on_gazelle v1.0.0
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2
+ github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.15.0
- google.golang.org/protobuf v1.32.0
)
require (
github.com/bazelbuild/bazel-gazelle v0.30.0 // indirect
+ github.com/davecgh/go-spew v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
+ golang.org/x/text v0.9.0 // indirect
+ google.golang.org/protobuf v1.32.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
+ rsc.io/quote v1.5.2 // indirect
+ rsc.io/sampler v1.3.0 // indirect
)
+
+replace example.org/hello => ../../fixtures/hello
diff --git a/tests/bcr/go_mod/go.sum b/tests/bcr/go_mod/go.sum
new file mode 100644
index 000000000..9e6056a54
--- /dev/null
+++ b/tests/bcr/go_mod/go.sum
@@ -0,0 +1,128 @@
+cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/DataDog/sketches-go v1.4.1 h1:j5G6as+9FASM2qC36lvpvQAj9qsv/jUs3FtO8CwZNAY=
+github.com/DataDog/sketches-go v1.4.1/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk=
+github.com/bazelbuild/bazel-gazelle v0.30.0 h1:q9XLWQSCA5NZPJ98WFqicHkq6fxrDPnfvMO1XycQBMg=
+github.com/bazelbuild/bazel-gazelle v0.30.0/go.mod h1:6RxhjM1v/lTpD3JlMpKUCcdus4tvdqsqdfbjYi+czYs=
+github.com/bazelbuild/buildtools v0.0.0-20230317132445-9c3c1fc0106e h1:XmPu4mXICgdGnC5dXGjUGbwUD/kUmS0l5Aop3LaevBM=
+github.com/bazelbuild/buildtools v0.0.0-20230317132445-9c3c1fc0106e/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo=
+github.com/bazelbuild/rules_go v0.39.1 h1:wkJLUDx59dntWMghuL8++GteoU1To6sRoKJXuyFtmf8=
+github.com/bazelbuild/rules_go v0.39.1/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU=
+github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
+github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
+github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
+github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
+github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
+github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
+github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
+github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
+github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
+github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
+github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/envoyproxy/protoc-gen-validate v1.0.1 h1:kt9FtLiooDc0vbwTLhdg3dyNX1K9Qwa1EK9LcD4jVUQ=
+github.com/envoyproxy/protoc-gen-validate v1.0.1/go.mod h1:0vj8bNkYbSTNS2PIyH87KZaeN4x9zpL9Qt8fQC7d+vs=
+github.com/fmeum/dep_on_gazelle v1.0.0 h1:7gEtQ2CoD77tYca+1iUnKjIBUZ4mX7mZwjdWp3uuN/E=
+github.com/fmeum/dep_on_gazelle v1.0.0/go.mod h1:VYCjwfsyRHOJL8oenaEjhIzgM7Oj70iTxgJ2RfXbYr0=
+github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
+github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
+github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
+github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
+github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
+github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
+github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
+github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
+github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
+github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 h1:SJ+NtwL6QaZ21U+IrK7d0gGgpjGGvd2kz+FzTHVzdqI=
+github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2/go.mod h1:Tv1PlzqC9t8wNnpPdctvtSUOPUUg4SHeE6vR1Ir2hmg=
+github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
+github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
+github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
+github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
+golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
+golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
+golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
+google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
+google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
+google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
+google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
+google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
+google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
+google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
+google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
+google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
+google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
+gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+rsc.io/quote v1.5.2 h1:w5fcysjrx7yqtD/aO+QwRjYZOKnaM9Uh2b40tElTs3Y=
+rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
+rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
+rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
diff --git a/tests/bcr/patches/BUILD.bazel b/tests/bcr/go_mod/patches/BUILD.bazel
similarity index 100%
rename from tests/bcr/patches/BUILD.bazel
rename to tests/bcr/go_mod/patches/BUILD.bazel
diff --git a/tests/bcr/patches/buildtools.patch b/tests/bcr/go_mod/patches/buildtools.patch
similarity index 100%
rename from tests/bcr/patches/buildtools.patch
rename to tests/bcr/go_mod/patches/buildtools.patch
diff --git a/tests/bcr/patches/testify.patch b/tests/bcr/go_mod/patches/testify.patch
similarity index 100%
rename from tests/bcr/patches/testify.patch
rename to tests/bcr/go_mod/patches/testify.patch
diff --git a/tests/bcr/pkg/BUILD.bazel b/tests/bcr/go_mod/pkg/BUILD.bazel
similarity index 97%
rename from tests/bcr/pkg/BUILD.bazel
rename to tests/bcr/go_mod/pkg/BUILD.bazel
index 383211102..ab8a846cd 100644
--- a/tests/bcr/pkg/BUILD.bazel
+++ b/tests/bcr/go_mod/pkg/BUILD.bazel
@@ -6,7 +6,7 @@ go_library(
"platform_lib_unix.go",
"platform_lib_windows.go",
],
- importpath = "github.com/bazelbuild/bazel-gazelle/tests/bcr/pkg",
+ importpath = "github.com/bazelbuild/bazel-gazelle/tests/bcr/go_mod/pkg",
visibility = ["//visibility:public"],
deps = select({
"@my_rules_go//go/platform:aix": [
@@ -61,5 +61,6 @@ go_test(
"@com_github_google_safetext//yamltemplate",
"@com_github_stretchr_testify//require:go_default_library",
"@my_rules_go//go/runfiles",
+ "@org_example_hello//:hello",
],
)
diff --git a/tests/bcr/pkg/data/BUILD.bazel b/tests/bcr/go_mod/pkg/data/BUILD.bazel
similarity index 93%
rename from tests/bcr/pkg/data/BUILD.bazel
rename to tests/bcr/go_mod/pkg/data/BUILD.bazel
index ac9a2c939..115252d98 100644
--- a/tests/bcr/pkg/data/BUILD.bazel
+++ b/tests/bcr/go_mod/pkg/data/BUILD.bazel
@@ -4,6 +4,6 @@ go_library(
name = "data",
srcs = ["data.go"],
data = ["@bazel_gazelle_go_repository_config//:WORKSPACE"],
- importpath = "github.com/bazelbuild/bazel-gazelle/tests/bcr/pkg/data",
+ importpath = "github.com/bazelbuild/bazel-gazelle/tests/bcr/go_mod/pkg/data",
visibility = ["//visibility:public"],
)
diff --git a/tests/bcr/pkg/data/data.go b/tests/bcr/go_mod/pkg/data/data.go
similarity index 100%
rename from tests/bcr/pkg/data/data.go
rename to tests/bcr/go_mod/pkg/data/data.go
diff --git a/tests/bcr/pkg/pkg_test.go b/tests/bcr/go_mod/pkg/pkg_test.go
similarity index 87%
rename from tests/bcr/pkg/pkg_test.go
rename to tests/bcr/go_mod/pkg/pkg_test.go
index a1ae8cdad..05d873a84 100644
--- a/tests/bcr/pkg/pkg_test.go
+++ b/tests/bcr/go_mod/pkg/pkg_test.go
@@ -5,8 +5,9 @@ import (
"os"
"testing"
+ "example.org/hello"
"github.com/DataDog/sketches-go/ddsketch"
- "github.com/bazelbuild/bazel-gazelle/tests/bcr/pkg/data"
+ "github.com/bazelbuild/bazel-gazelle/tests/bcr/go_mod/pkg/data"
"github.com/bazelbuild/buildtools/labels"
"github.com/bazelbuild/rules_go/go/runfiles"
"github.com/bmatcuk/doublestar/v4"
@@ -77,3 +78,9 @@ func TestArchiveOverrideUsed(t *testing.T) {
func TestArchiveOverrideWithPatch(t *testing.T) {
require.Equal(t, labels.Patched, "hello")
}
+
+func TestGodModReplaceToFilePath(t *testing.T) {
+ // This test is used to validate that the go.mod replace directive is being used to replace
+ // the module path with a file path.
+ require.Equal(t, "Hello, world.", hello.Hello())
+}
diff --git a/tests/bcr/pkg/platform_lib_unix.go b/tests/bcr/go_mod/pkg/platform_lib_unix.go
similarity index 100%
rename from tests/bcr/pkg/platform_lib_unix.go
rename to tests/bcr/go_mod/pkg/platform_lib_unix.go
diff --git a/tests/bcr/pkg/platform_lib_windows.go b/tests/bcr/go_mod/pkg/platform_lib_windows.go
similarity index 100%
rename from tests/bcr/pkg/platform_lib_windows.go
rename to tests/bcr/go_mod/pkg/platform_lib_windows.go
diff --git a/tests/bcr/proto/BUILD.bazel b/tests/bcr/go_mod/proto/BUILD.bazel
similarity index 100%
rename from tests/bcr/proto/BUILD.bazel
rename to tests/bcr/go_mod/proto/BUILD.bazel
index d1621cc20..104a26064 100644
--- a/tests/bcr/proto/BUILD.bazel
+++ b/tests/bcr/go_mod/proto/BUILD.bazel
@@ -1,6 +1,6 @@
-load("@my_rules_proto//proto:defs.bzl", "proto_library")
load("@my_rules_go//go:def.bzl", "go_test")
load("@my_rules_go//proto:def.bzl", "go_proto_library")
+load("@my_rules_proto//proto:defs.bzl", "proto_library")
proto_library(
name = "foo_proto",
diff --git a/tests/bcr/proto/foo.proto b/tests/bcr/go_mod/proto/foo.proto
similarity index 100%
rename from tests/bcr/proto/foo.proto
rename to tests/bcr/go_mod/proto/foo.proto
diff --git a/tests/bcr/proto/foo_test.go b/tests/bcr/go_mod/proto/foo_test.go
similarity index 100%
rename from tests/bcr/proto/foo_test.go
rename to tests/bcr/go_mod/proto/foo_test.go
diff --git a/tests/bcr/test_dep/BUILD.bazel b/tests/bcr/go_mod/test_dep/BUILD.bazel
similarity index 100%
rename from tests/bcr/test_dep/BUILD.bazel
rename to tests/bcr/go_mod/test_dep/BUILD.bazel
diff --git a/tests/bcr/test_dep/MODULE.bazel b/tests/bcr/go_mod/test_dep/MODULE.bazel
similarity index 99%
rename from tests/bcr/test_dep/MODULE.bazel
rename to tests/bcr/go_mod/test_dep/MODULE.bazel
index c2278edf2..340ade58b 100644
--- a/tests/bcr/test_dep/MODULE.bazel
+++ b/tests/bcr/go_mod/test_dep/MODULE.bazel
@@ -28,7 +28,6 @@ go_deps.module_override(
],
path = "github.com/stretchr/testify",
)
-
go_deps.module(
indirect = True,
path = "gopkg.in/yaml.v3",
@@ -36,10 +35,10 @@ go_deps.module(
version = "v3.0.1",
)
go_deps.gazelle_override(
- path = "gopkg.in/yaml.v3",
directives = [
"gazelle:go_naming_convention import",
],
+ path = "gopkg.in/yaml.v3",
)
go_deps.module(
indirect = True,
diff --git a/tests/bcr/test_dep/WORKSPACE b/tests/bcr/go_mod/test_dep/WORKSPACE
similarity index 100%
rename from tests/bcr/test_dep/WORKSPACE
rename to tests/bcr/go_mod/test_dep/WORKSPACE
diff --git a/tests/bcr/test_dep/patches/BUILD.bazel b/tests/bcr/go_mod/test_dep/patches/BUILD.bazel
similarity index 100%
rename from tests/bcr/test_dep/patches/BUILD.bazel
rename to tests/bcr/go_mod/test_dep/patches/BUILD.bazel
diff --git a/tests/bcr/test_dep/patches/testify.patch b/tests/bcr/go_mod/test_dep/patches/testify.patch
similarity index 100%
rename from tests/bcr/test_dep/patches/testify.patch
rename to tests/bcr/go_mod/test_dep/patches/testify.patch
diff --git a/tests/bcr/test_dep/test.go b/tests/bcr/go_mod/test_dep/test.go
similarity index 100%
rename from tests/bcr/test_dep/test.go
rename to tests/bcr/go_mod/test_dep/test.go
diff --git a/tests/bcr/tools/BUILD.bazel b/tests/bcr/go_mod/tools/BUILD.bazel
similarity index 100%
rename from tests/bcr/tools/BUILD.bazel
rename to tests/bcr/go_mod/tools/BUILD.bazel
diff --git a/tests/bcr/tools/go.mod b/tests/bcr/go_mod/tools/go.mod
similarity index 92%
rename from tests/bcr/tools/go.mod
rename to tests/bcr/go_mod/tools/go.mod
index 29249d341..30eec8274 100644
--- a/tests/bcr/tools/go.mod
+++ b/tests/bcr/go_mod/tools/go.mod
@@ -1,4 +1,4 @@
-module github.com/bazelbuild/bazel-gazelle/tests/bcr/tools
+module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_mod/tools
go 1.21.0
diff --git a/tests/bcr/tools/go.sum b/tests/bcr/go_mod/tools/go.sum
similarity index 100%
rename from tests/bcr/tools/go.sum
rename to tests/bcr/go_mod/tools/go.sum
diff --git a/tests/bcr/tools/tools.go b/tests/bcr/go_mod/tools/tools.go
similarity index 100%
rename from tests/bcr/tools/tools.go
rename to tests/bcr/go_mod/tools/tools.go
diff --git a/tests/bcr/go_work/.bazelignore b/tests/bcr/go_work/.bazelignore
new file mode 100644
index 000000000..777d432da
--- /dev/null
+++ b/tests/bcr/go_work/.bazelignore
@@ -0,0 +1 @@
+test_dep
diff --git a/tests/bcr/go_work/.bazelrc b/tests/bcr/go_work/.bazelrc
new file mode 100644
index 000000000..7ccbf79fb
--- /dev/null
+++ b/tests/bcr/go_work/.bazelrc
@@ -0,0 +1,6 @@
+common --enable_bzlmod
+common --experimental_isolated_extension_usages
+common --lockfile_mode=update
+common --enable_platform_specific_config
+# Required by abseil-cpp on macOS with Bazel 6.
+common:macos --host_cxxopt=-std=c++14
diff --git a/tests/bcr/go_work/.bazelversion b/tests/bcr/go_work/.bazelversion
new file mode 100644
index 000000000..a8907c025
--- /dev/null
+++ b/tests/bcr/go_work/.bazelversion
@@ -0,0 +1 @@
+7.0.2
diff --git a/tests/bcr/go_work/BUILD.bazel b/tests/bcr/go_work/BUILD.bazel
new file mode 100644
index 000000000..8b3d89b76
--- /dev/null
+++ b/tests/bcr/go_work/BUILD.bazel
@@ -0,0 +1,5 @@
+load("@gazelle//:def.bzl", "gazelle")
+
+# gazelle:go_naming_convention import
+# gazelle:go_naming_convention_external import
+gazelle(name = "gazelle")
diff --git a/tests/bcr/go_work/MODULE.bazel b/tests/bcr/go_work/MODULE.bazel
new file mode 100644
index 000000000..0e4220acb
--- /dev/null
+++ b/tests/bcr/go_work/MODULE.bazel
@@ -0,0 +1,151 @@
+module(
+ name = "gazelle_bcr_go_work_tests",
+)
+
+bazel_dep(name = "gazelle", version = "")
+local_path_override(
+ module_name = "gazelle",
+ path = "../../..",
+)
+
+bazel_dep(name = "test_dep", version = "1.0.0")
+local_path_override(
+ module_name = "test_dep",
+ path = "test_dep",
+)
+
+bazel_dep(name = "protobuf", version = "23.1", repo_name = "my_protobuf")
+bazel_dep(name = "rules_go", version = "0.44.0", repo_name = "my_rules_go")
+bazel_dep(name = "rules_proto", version = "6.0.0-rc2", repo_name = "my_rules_proto")
+
+go_sdk = use_extension("@my_rules_go//go:extensions.bzl", "go_sdk")
+
+# This bazel_dep provides the Go dependency github.com/cloudflare/circl, which requires custom
+# patches beyond what Gazelle can generate.
+bazel_dep(name = "circl", version = "1.3.7")
+
+go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
+go_deps.config(
+ go_env = {
+ "GOPRIVATE": "example.com/*",
+ },
+)
+
+# Validate a full go workspace
+go_deps.from_file(go_work = "//:go.work")
+go_deps.gazelle_default_attributes(
+ build_file_generation = "on",
+ directives = [
+ "gazelle:proto disable",
+ ],
+)
+
+# By defining `gazelle_default_attributes`, we also must individually
+# specify certain overrides from internal/bzlmod/default_gazelle_overrides.bzl
+#
+# "build_file_generation" defaults to "on" because we provided a "gazelle_override"
+# (which contains either directives or build extra args).
+go_deps.gazelle_override(
+ directives = [
+ "gazelle:build_file_name BUILD.bazel",
+ "gazelle:build_file_proto_mode disable_global",
+ ],
+ path = "github.com/google/safetext",
+)
+go_deps.gazelle_override(
+ directives = [
+ "gazelle:build_file_name BUILD.bazel",
+ ],
+ path = "github.com/envoyproxy/protoc-gen-validate",
+)
+
+# Verify that the gazelle:go_naming_convention directive in an override is
+# respected.
+go_deps.module(
+ path = "github.com/stretchr/testify",
+ sum = "h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=",
+ version = "v1.8.4",
+)
+go_deps.gazelle_override(
+ directives = [
+ "gazelle:go_naming_convention go_default_library",
+ ],
+ path = "github.com/stretchr/testify",
+)
+
+# Apply a patch to test the `module_override` tags.
+go_deps.module_override(
+ patch_strip = 1,
+ patches = [
+ "//patches:testify.patch",
+ ],
+ path = "github.com/stretchr/testify",
+)
+
+# Test an archive override from a known archive.
+go_deps.gazelle_override(
+ directives = [
+ "gazelle:go_naming_convention go_default_library",
+ ],
+ path = "github.com/bazelbuild/buildtools",
+)
+go_deps.archive_override(
+ patch_strip = 1,
+ patches = [
+ "//patches:buildtools.patch",
+ ],
+ path = "github.com/bazelbuild/buildtools",
+ sha256 = "05d7c3d2bd3cc0b02d15672fefa0d6be48c7aebe459c1c99dced7ac5e598508f",
+ strip_prefix = "buildtools-ae8e3206e815d086269eb208b01f300639a4b194",
+ urls = [
+ "https://github.com/bazelbuild/buildtools/archive/ae8e3206e815d086269eb208b01f300639a4b194.tar.gz",
+ ],
+)
+
+# Transitive dependencies have to be listed here explicitly.
+go_deps.module(
+ indirect = True,
+ path = "gopkg.in/yaml.v3",
+ sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=",
+ version = "v3.0.1",
+)
+go_deps.gazelle_override(
+ directives = [
+ # Verify that the build naming convention is picked up by Gazelle when it
+ # emits references to this repo.
+ "gazelle:go_naming_convention go_default_library",
+ ],
+ path = "gopkg.in/yaml.v3",
+)
+go_deps.module(
+ indirect = True,
+ path = "github.com/davecgh/go-spew",
+ sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=",
+ version = "v1.1.1",
+)
+use_repo(
+ go_deps,
+ "com_github_99designs_gqlgen",
+ "com_github_bazelbuild_buildtools",
+ "com_github_bmatcuk_doublestar_v4",
+ "com_github_datadog_sketches_go",
+ "com_github_envoyproxy_protoc_gen_validate",
+ "com_github_fmeum_dep_on_gazelle",
+ "com_github_google_safetext",
+ "com_github_stretchr_testify",
+ "org_golang_google_protobuf",
+ "org_golang_x_sys",
+ # Only used for testing.
+ "bazel_gazelle_go_repository_config",
+ "org_example_hello",
+)
+
+# Use an isolated usage to bring in Go tools from the tools package with their own dependency
+# closure.
+go_tools = use_extension("@gazelle//:extensions.bzl", "go_deps", isolate = True)
+go_tools.from_file(go_mod = "//tools:go.mod")
+use_repo(
+ go_tools,
+ buildtools = "com_github_bazelbuild_buildtools",
+ gqlgen = "com_github_99designs_gqlgen",
+)
diff --git a/tests/bcr/go_work/WORKSPACE b/tests/bcr/go_work/WORKSPACE
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/bcr/go_work/WORKSPACE.bzlmod b/tests/bcr/go_work/WORKSPACE.bzlmod
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/bcr/go_work/go.work b/tests/bcr/go_work/go.work
new file mode 100644
index 000000000..effa2ce4b
--- /dev/null
+++ b/tests/bcr/go_work/go.work
@@ -0,0 +1,9 @@
+go 1.21
+
+use (
+ ./pkg
+ ./tools
+ ./proto
+)
+
+replace example.org/hello => ../../fixtures/hello
diff --git a/tests/bcr/go_work/patches/BUILD.bazel b/tests/bcr/go_work/patches/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/bcr/go_work/patches/buildtools.patch b/tests/bcr/go_work/patches/buildtools.patch
new file mode 100644
index 000000000..1c75d4e39
--- /dev/null
+++ b/tests/bcr/go_work/patches/buildtools.patch
@@ -0,0 +1,13 @@
+diff --git a/labels/labels.go b/labels/labels.go
+index 7564621..aba07c0 100644
+--- a/labels/labels.go
++++ b/labels/labels.go
+@@ -23,6 +23,8 @@ import (
+ "strings"
+ )
+
++const Patched = "hello"
++
+ // Label represents a Bazel target label.
+ type Label struct {
+ Repository string // Repository of the target, can be empty if the target belongs to the current repository
diff --git a/tests/bcr/go_work/patches/testify.patch b/tests/bcr/go_work/patches/testify.patch
new file mode 100644
index 000000000..cf1075eeb
--- /dev/null
+++ b/tests/bcr/go_work/patches/testify.patch
@@ -0,0 +1,13 @@
+diff --git a/require/require.go b/require/require.go
+index a6e1b7c..bc21879 100644
+--- a/require/require.go
++++ b/require/require.go
+@@ -12,6 +12,8 @@ import (
+ time "time"
+ )
+
++const Hello = "hello"
++
+ // Condition uses a Comparison to assert a complex condition.
+ func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
+ if h, ok := t.(tHelper); ok {
diff --git a/tests/bcr/go_work/pkg/BUILD.bazel b/tests/bcr/go_work/pkg/BUILD.bazel
new file mode 100644
index 000000000..21333bf5b
--- /dev/null
+++ b/tests/bcr/go_work/pkg/BUILD.bazel
@@ -0,0 +1,66 @@
+load("@my_rules_go//go:def.bzl", "go_library", "go_test")
+
+go_library(
+ name = "pkg",
+ srcs = [
+ "platform_lib_unix.go",
+ "platform_lib_windows.go",
+ ],
+ importpath = "github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work/pkg",
+ visibility = ["//visibility:public"],
+ deps = select({
+ "@my_rules_go//go/platform:aix": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:android": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:darwin": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:dragonfly": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:freebsd": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:illumos": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:ios": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:linux": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:netbsd": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:openbsd": [
+ "@org_golang_x_sys//unix",
+ ],
+ "@my_rules_go//go/platform:solaris": [
+ "@org_golang_x_sys//unix",
+ ],
+ "//conditions:default": [],
+ }),
+)
+
+go_test(
+ name = "pkg_test",
+ srcs = ["pkg_test.go"],
+ embed = [":pkg"],
+ deps = [
+ "//pkg/data",
+ "@circl//dh/x25519",
+ "@com_github_bazelbuild_buildtools//labels:go_default_library",
+ "@com_github_bmatcuk_doublestar_v4//:doublestar",
+ "@com_github_datadog_sketches_go//ddsketch",
+ "@com_github_envoyproxy_protoc_gen_validate//validate",
+ "@com_github_fmeum_dep_on_gazelle//:dep_on_gazelle",
+ "@com_github_google_safetext//yamltemplate",
+ "@com_github_stretchr_testify//require:go_default_library",
+ "@my_rules_go//go/runfiles",
+ "@org_example_hello//:hello",
+ ],
+)
diff --git a/tests/bcr/go_work/pkg/data/BUILD.bazel b/tests/bcr/go_work/pkg/data/BUILD.bazel
new file mode 100644
index 000000000..2d507569b
--- /dev/null
+++ b/tests/bcr/go_work/pkg/data/BUILD.bazel
@@ -0,0 +1,9 @@
+load("@my_rules_go//go:def.bzl", "go_library")
+
+go_library(
+ name = "data",
+ srcs = ["data.go"],
+ data = ["@bazel_gazelle_go_repository_config//:WORKSPACE"],
+ importpath = "github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work/pkg/data",
+ visibility = ["//visibility:public"],
+)
diff --git a/tests/bcr/go_work/pkg/data/data.go b/tests/bcr/go_work/pkg/data/data.go
new file mode 100644
index 000000000..300ef2783
--- /dev/null
+++ b/tests/bcr/go_work/pkg/data/data.go
@@ -0,0 +1,3 @@
+package data
+
+const RepoConfigRlocationPath = "bazel_gazelle_go_repository_config/WORKSPACE"
diff --git a/tests/bcr/go_work/pkg/go.mod b/tests/bcr/go_work/pkg/go.mod
new file mode 100644
index 000000000..2222e404d
--- /dev/null
+++ b/tests/bcr/go_work/pkg/go.mod
@@ -0,0 +1,33 @@
+module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work/pkg
+
+go 1.21.5
+
+require (
+ example.org/hello v0.0.0-00010101000000-000000000000
+ github.com/DataDog/sketches-go v1.4.4
+ github.com/bazelbuild/buildtools v0.0.0-20240207142252-03bf520394af
+ github.com/bazelbuild/rules_go v0.44.0
+ github.com/bmatcuk/doublestar/v4 v4.6.1
+ github.com/cloudflare/circl v1.3.7
+ github.com/envoyproxy/protoc-gen-validate v1.0.4
+ github.com/fmeum/dep_on_gazelle v1.0.0
+ github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f
+ github.com/stretchr/testify v1.8.4
+ golang.org/x/sys v0.17.0
+)
+
+require (
+ github.com/bazelbuild/bazel-gazelle v0.30.0 // indirect
+ github.com/davecgh/go-spew v1.1.1 // indirect
+ github.com/google/uuid v1.3.0 // indirect
+ github.com/pborman/uuid v1.2.1 // indirect
+ github.com/pmezard/go-difflib v1.0.0 // indirect
+ golang.org/x/text v0.14.0 // indirect
+ google.golang.org/protobuf v1.32.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
+ rsc.io/quote v1.5.2 // indirect
+ rsc.io/sampler v1.3.0 // indirect
+)
+
+// Validate go.mod replace directives can be properly used:
+replace github.com/bmatcuk/doublestar/v4 => github.com/bmatcuk/doublestar v1.3.4
diff --git a/tests/bcr/go_work/pkg/go.sum b/tests/bcr/go_work/pkg/go.sum
new file mode 100644
index 000000000..c5d9f6e1b
--- /dev/null
+++ b/tests/bcr/go_work/pkg/go.sum
@@ -0,0 +1,126 @@
+cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/DataDog/sketches-go v1.4.4 h1:dF52vzXRFSPOj2IjXSWLvXq3jubL4CI69kwYjJ1w5Z8=
+github.com/DataDog/sketches-go v1.4.4/go.mod h1:XR0ns2RtEEF09mDKXiKZiQg+nfZStrq1ZuL1eezeZe0=
+github.com/bazelbuild/bazel-gazelle v0.30.0 h1:q9XLWQSCA5NZPJ98WFqicHkq6fxrDPnfvMO1XycQBMg=
+github.com/bazelbuild/bazel-gazelle v0.30.0/go.mod h1:6RxhjM1v/lTpD3JlMpKUCcdus4tvdqsqdfbjYi+czYs=
+github.com/bazelbuild/buildtools v0.0.0-20240207142252-03bf520394af h1:wycIfuqZJzkloRT+fcazTM3NjvAMyAi1qC2QXmEZP4s=
+github.com/bazelbuild/buildtools v0.0.0-20240207142252-03bf520394af/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo=
+github.com/bazelbuild/rules_go v0.44.0 h1:uJStI9o5obVWSwquy9WxKNWfZxf2sKA2rpEsX6x5RVM=
+github.com/bazelbuild/rules_go v0.44.0/go.mod h1:z7Y8GZ90V4mwgYizbNbEQKmOmx93Q3Btcel4vX7pXoc=
+github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
+github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
+github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
+github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
+github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
+github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
+github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
+github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
+github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
+github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
+github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
+github.com/fmeum/dep_on_gazelle v1.0.0 h1:7gEtQ2CoD77tYca+1iUnKjIBUZ4mX7mZwjdWp3uuN/E=
+github.com/fmeum/dep_on_gazelle v1.0.0/go.mod h1:VYCjwfsyRHOJL8oenaEjhIzgM7Oj70iTxgJ2RfXbYr0=
+github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
+github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
+github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
+github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
+github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
+github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
+github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
+github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f h1:o2yGZLlsOj5H5uvtQNEdi6DeA0GbUP3lm0gWW5RvY0s=
+github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f/go.mod h1:H3K1Iu/utuCfa10JO+GsmKUYSWi7ug57Rk6GaDRHaaQ=
+github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
+github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
+github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
+golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
+golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
+golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
+google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
+google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
+google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
+google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
+google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
+google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
+google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
+google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
+google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+rsc.io/quote v1.5.2 h1:w5fcysjrx7yqtD/aO+QwRjYZOKnaM9Uh2b40tElTs3Y=
+rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
+rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
+rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
diff --git a/tests/bcr/go_work/pkg/pkg_test.go b/tests/bcr/go_work/pkg/pkg_test.go
new file mode 100644
index 000000000..e81dcc076
--- /dev/null
+++ b/tests/bcr/go_work/pkg/pkg_test.go
@@ -0,0 +1,86 @@
+package pkg
+
+import (
+ "crypto/rand"
+ "os"
+ "testing"
+
+ "example.org/hello"
+ "github.com/DataDog/sketches-go/ddsketch"
+ "github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work/pkg/data"
+ "github.com/bazelbuild/buildtools/labels"
+ "github.com/bazelbuild/rules_go/go/runfiles"
+ "github.com/bmatcuk/doublestar/v4"
+ "github.com/cloudflare/circl/dh/x25519"
+ "github.com/fmeum/dep_on_gazelle"
+ "github.com/google/safetext/yamltemplate"
+ "github.com/stretchr/testify/require"
+
+ _ "github.com/envoyproxy/protoc-gen-validate/validate"
+)
+
+func TestReplace(t *testing.T) {
+ // doublestar.StandardOS does NOT exist in doublestar/v4
+ // See: https://pkg.go.dev/github.com/bmatcuk/doublestar#OS
+ // If we are able to initialize this variable, it validates that the dependency is properly
+ // being replaced with github.com/bmatcuk/doublestar@v1.3.4
+ _ = doublestar.StandardOS
+}
+
+func TestPatch(t *testing.T) {
+ // a patch is used to add this constant.
+ require.Equal(t, "hello", require.Hello)
+}
+
+func TestBuildFileGeneration(t *testing.T) {
+ // github.com/google/safetext@v0.0.0-20220905092116-b49f7bc46da2 requires overwriting the BUILD
+ // files it provides as well as directives.
+ yamltemplate.HTMLEscapeString("foo")
+}
+
+func TestGeneratedFilesPreferredOverProtos(t *testing.T) {
+ _, _ = ddsketch.NewDefaultDDSketch(0.01)
+}
+
+func TestPlatformDependentDep(t *testing.T) {
+ PlatformDependentFunction()
+}
+
+func TestNoGoRepositoryForRulesGoAndGazelle(t *testing.T) {
+ path, err := runfiles.Rlocation(data.RepoConfigRlocationPath)
+ require.NoError(t, err)
+ config, err := os.ReadFile(path)
+ require.NoError(t, err)
+
+ content := string(config)
+ require.NotContains(t, content, "com_github_bazelbuild_rules_go")
+ require.NotContains(t, content, "com_github_bazelbuild_bazel_gazelle")
+ require.Contains(t, content, "module_name = \"rules_go\"")
+ require.Contains(t, content, "module_name = \"gazelle\"")
+}
+
+func TestIndirectlyUseGazelle(t *testing.T) {
+ dep_on_gazelle.MakeLabel("foo", "bar", "baz")
+}
+
+func TestBazelDepUsedAsGoDep(t *testing.T) {
+ var public, secret x25519.Key
+ _, err := rand.Read(secret[:])
+ require.NoError(t, err)
+ x25519.KeyGen(&public, &secret)
+}
+
+func TestArchiveOverrideUsed(t *testing.T) {
+ label := labels.Parse("@com_github_bazelbuild_buildtools//labels:labels")
+ require.NotEmpty(t, label)
+}
+
+func TestArchiveOverrideWithPatch(t *testing.T) {
+ require.Equal(t, labels.Patched, "hello")
+}
+
+func TestGodModReplaceToFilePath(t *testing.T) {
+ // This test is used to validate that the go.mod replace directive is being used to replace
+ // the module path with a file path.
+ require.Equal(t, "Hello, world.", hello.Hello())
+}
diff --git a/tests/bcr/go_work/pkg/platform_lib_unix.go b/tests/bcr/go_work/pkg/platform_lib_unix.go
new file mode 100644
index 000000000..e23e36ac2
--- /dev/null
+++ b/tests/bcr/go_work/pkg/platform_lib_unix.go
@@ -0,0 +1,10 @@
+//go:build unix
+
+package pkg
+
+import "golang.org/x/sys/unix"
+
+func PlatformDependentFunction() string {
+ home, _ := unix.Getenv("HOME")
+ return home
+}
diff --git a/tests/bcr/go_work/pkg/platform_lib_windows.go b/tests/bcr/go_work/pkg/platform_lib_windows.go
new file mode 100644
index 000000000..28034acda
--- /dev/null
+++ b/tests/bcr/go_work/pkg/platform_lib_windows.go
@@ -0,0 +1,7 @@
+//go:build windows
+
+package pkg
+
+func PlatformDependentFunction() string {
+ return "C:\\Users\\gopher"
+}
diff --git a/tests/bcr/go_work/proto/BUILD.bazel b/tests/bcr/go_work/proto/BUILD.bazel
new file mode 100644
index 000000000..104a26064
--- /dev/null
+++ b/tests/bcr/go_work/proto/BUILD.bazel
@@ -0,0 +1,31 @@
+load("@my_rules_go//go:def.bzl", "go_test")
+load("@my_rules_go//proto:def.bzl", "go_proto_library")
+load("@my_rules_proto//proto:defs.bzl", "proto_library")
+
+proto_library(
+ name = "foo_proto",
+ srcs = ["foo.proto"],
+ visibility = ["//visibility:public"],
+ deps = [
+ "@my_protobuf//:timestamp_proto",
+ "@my_protobuf//:type_proto",
+ ],
+)
+
+go_proto_library(
+ name = "foo_go_proto",
+ importpath = "github.com/bazelbuild/bazel-gazelle/tests/bcr/proto/foo",
+ proto = ":foo_proto",
+ visibility = ["//visibility:public"],
+)
+
+go_test(
+ name = "proto_test",
+ srcs = ["foo_test.go"],
+ deps = [
+ ":foo_go_proto",
+ "@org_golang_google_protobuf//types/known/sourcecontextpb",
+ "@org_golang_google_protobuf//types/known/timestamppb",
+ "@org_golang_google_protobuf//types/known/typepb",
+ ],
+)
diff --git a/tests/bcr/go_work/proto/foo.proto b/tests/bcr/go_work/proto/foo.proto
new file mode 100644
index 000000000..b4674e4f7
--- /dev/null
+++ b/tests/bcr/go_work/proto/foo.proto
@@ -0,0 +1,12 @@
+syntax = "proto3";
+
+option go_package = "github.com/bazelbuild/bazel-gazelle/tests/bcr/proto/foo";
+
+import "google/protobuf/timestamp.proto";
+import "google/protobuf/type.proto";
+
+message Foo {
+ string name = 1;
+ google.protobuf.Timestamp last_updated = 2;
+ google.protobuf.Type type = 3;
+}
diff --git a/tests/bcr/go_work/proto/foo_test.go b/tests/bcr/go_work/proto/foo_test.go
new file mode 100644
index 000000000..ee5bd456b
--- /dev/null
+++ b/tests/bcr/go_work/proto/foo_test.go
@@ -0,0 +1,23 @@
+package proto
+
+import (
+ "testing"
+
+ "github.com/bazelbuild/bazel-gazelle/tests/bcr/proto/foo"
+ "google.golang.org/protobuf/types/known/sourcecontextpb"
+ "google.golang.org/protobuf/types/known/timestamppb"
+ "google.golang.org/protobuf/types/known/typepb"
+)
+
+func TestWellKnownTypes(t *testing.T) {
+ var foo foo.Foo
+ foo.Name = "foo"
+ foo.Type = &typepb.Type{
+ Name: "my_type",
+ SourceContext: &sourcecontextpb.SourceContext{},
+ }
+ foo.LastUpdated = ×tamppb.Timestamp{
+ Seconds: 12345,
+ Nanos: 67890,
+ }
+}
diff --git a/tests/bcr/go_work/proto/go.mod b/tests/bcr/go_work/proto/go.mod
new file mode 100644
index 000000000..344688491
--- /dev/null
+++ b/tests/bcr/go_work/proto/go.mod
@@ -0,0 +1,2 @@
+module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work/proto
+go 1.21.5
diff --git a/tests/bcr/go_work/test_dep/BUILD.bazel b/tests/bcr/go_work/test_dep/BUILD.bazel
new file mode 100644
index 000000000..a4ab157c1
--- /dev/null
+++ b/tests/bcr/go_work/test_dep/BUILD.bazel
@@ -0,0 +1,8 @@
+load("@rules_go//go:def.bzl", "go_test")
+
+go_test(
+ name = "test",
+ srcs = ["test.go"],
+ visibility = ["//visibility:public"],
+ deps = ["@com_github_stretchr_testify//require"],
+)
diff --git a/tests/bcr/go_work/test_dep/MODULE.bazel b/tests/bcr/go_work/test_dep/MODULE.bazel
new file mode 100644
index 000000000..340ade58b
--- /dev/null
+++ b/tests/bcr/go_work/test_dep/MODULE.bazel
@@ -0,0 +1,49 @@
+module(
+ name = "test_dep",
+ version = "1.0.0",
+)
+
+bazel_dep(name = "rules_go", version = "0.41.0")
+bazel_dep(name = "gazelle", version = "0.31.0")
+
+# An isolated extension usage does not share any tags with any other usage and results in a
+# completely separate set of repos. We explicitly use different directives and patches here to
+# verify that they do not interfere with those of the root test module.
+go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps", isolate = True)
+go_deps.module(
+ path = "github.com/stretchr/testify",
+ sum = "h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=",
+ version = "v1.8.0",
+)
+go_deps.gazelle_override(
+ directives = [
+ "gazelle:go_naming_convention import",
+ ],
+ path = "github.com/stretchr/testify",
+)
+go_deps.module_override(
+ patch_strip = 1,
+ patches = [
+ "//patches:testify.patch",
+ ],
+ path = "github.com/stretchr/testify",
+)
+go_deps.module(
+ indirect = True,
+ path = "gopkg.in/yaml.v3",
+ sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=",
+ version = "v3.0.1",
+)
+go_deps.gazelle_override(
+ directives = [
+ "gazelle:go_naming_convention import",
+ ],
+ path = "gopkg.in/yaml.v3",
+)
+go_deps.module(
+ indirect = True,
+ path = "github.com/davecgh/go-spew",
+ sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=",
+ version = "v1.1.1",
+)
+use_repo(go_deps, "com_github_stretchr_testify")
diff --git a/tests/bcr/go_work/test_dep/WORKSPACE b/tests/bcr/go_work/test_dep/WORKSPACE
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/bcr/go_work/test_dep/go.mod b/tests/bcr/go_work/test_dep/go.mod
new file mode 100644
index 000000000..389c77c0c
--- /dev/null
+++ b/tests/bcr/go_work/test_dep/go.mod
@@ -0,0 +1,11 @@
+module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work/test_dep
+
+go 1.21.5
+
+require github.com/stretchr/testify v1.8.4
+
+require (
+ github.com/davecgh/go-spew v1.1.1 // indirect
+ github.com/pmezard/go-difflib v1.0.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
+)
diff --git a/tests/bcr/go_work/test_dep/go.sum b/tests/bcr/go_work/test_dep/go.sum
new file mode 100644
index 000000000..fa4b6e682
--- /dev/null
+++ b/tests/bcr/go_work/test_dep/go.sum
@@ -0,0 +1,10 @@
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/tests/bcr/go_work/test_dep/patches/BUILD.bazel b/tests/bcr/go_work/test_dep/patches/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/bcr/go_work/test_dep/patches/testify.patch b/tests/bcr/go_work/test_dep/patches/testify.patch
new file mode 100644
index 000000000..4c8db505e
--- /dev/null
+++ b/tests/bcr/go_work/test_dep/patches/testify.patch
@@ -0,0 +1,13 @@
+diff --git a/require/require.go b/require/require.go
+index a6e1b7c..bc21879 100644
+--- a/require/require.go
++++ b/require/require.go
+@@ -12,6 +12,8 @@ import (
+ time "time"
+ )
+
++const Hello = "not_hello"
++
+ // Condition uses a Comparison to assert a complex condition.
+ func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
+ if h, ok := t.(tHelper); ok {
diff --git a/tests/bcr/go_work/test_dep/test.go b/tests/bcr/go_work/test_dep/test.go
new file mode 100644
index 000000000..586b5deac
--- /dev/null
+++ b/tests/bcr/go_work/test_dep/test.go
@@ -0,0 +1,13 @@
+package main
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestPatch(t *testing.T) {
+ // A patch is used to add this constant with a value that differs from that patched into the
+ // root module's version of this dep.
+ require.Equal(t, "not_hello", require.Hello)
+}
diff --git a/tests/bcr/go_work/tools/BUILD.bazel b/tests/bcr/go_work/tools/BUILD.bazel
new file mode 100644
index 000000000..dd60391b6
--- /dev/null
+++ b/tests/bcr/go_work/tools/BUILD.bazel
@@ -0,0 +1,10 @@
+# Verify that the tools builds.
+alias(
+ name = "gqlgen",
+ actual = "@gqlgen",
+)
+
+alias(
+ name = "buildifier",
+ actual = "@buildtools//buildifier",
+)
diff --git a/tests/bcr/go_work/tools/go.mod b/tests/bcr/go_work/tools/go.mod
new file mode 100644
index 000000000..4cc88570d
--- /dev/null
+++ b/tests/bcr/go_work/tools/go.mod
@@ -0,0 +1,26 @@
+module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work/tools
+
+go 1.21.0
+
+require (
+ github.com/99designs/gqlgen v0.17.40
+ github.com/bazelbuild/buildtools v0.0.0-20240207142252-03bf520394af
+)
+
+require (
+ github.com/agnivade/levenshtein v1.1.1 // indirect
+ github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
+ github.com/golang/protobuf v1.5.0 // indirect
+ github.com/google/uuid v1.3.0 // indirect
+ github.com/russross/blackfriday/v2 v2.1.0 // indirect
+ github.com/sosodev/duration v1.1.0 // indirect
+ github.com/urfave/cli/v2 v2.25.5 // indirect
+ github.com/vektah/gqlparser/v2 v2.5.10 // indirect
+ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
+ golang.org/x/mod v0.10.0 // indirect
+ golang.org/x/sys v0.17.0 // indirect
+ golang.org/x/text v0.9.0 // indirect
+ golang.org/x/tools v0.9.3 // indirect
+ google.golang.org/protobuf v1.32.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
+)
diff --git a/tests/bcr/go_work/tools/go.sum b/tests/bcr/go_work/tools/go.sum
new file mode 100644
index 000000000..589dc7022
--- /dev/null
+++ b/tests/bcr/go_work/tools/go.sum
@@ -0,0 +1,134 @@
+cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+github.com/99designs/gqlgen v0.17.40 h1:/l8JcEVQ93wqIfmH9VS1jsAkwm6eAF1NwQn3N+SDqBY=
+github.com/99designs/gqlgen v0.17.40/go.mod h1:b62q1USk82GYIVjC60h02YguAZLqYZtvWml8KkhJps4=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
+github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
+github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
+github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
+github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
+github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
+github.com/bazelbuild/buildtools v0.0.0-20240207142252-03bf520394af h1:wycIfuqZJzkloRT+fcazTM3NjvAMyAi1qC2QXmEZP4s=
+github.com/bazelbuild/buildtools v0.0.0-20240207142252-03bf520394af/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo=
+github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
+github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
+github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
+github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
+github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
+github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
+github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g=
+github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
+github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
+github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
+github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
+github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
+github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
+github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
+github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
+github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
+github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
+github.com/hashicorp/golang-lru/v2 v2.0.3 h1:kmRrRLlInXvng0SmLxmQpQkpbYAvcXm7NPDrgxJa9mE=
+github.com/hashicorp/golang-lru/v2 v2.0.3/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
+github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
+github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
+github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
+github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
+github.com/sosodev/duration v1.1.0 h1:kQcaiGbJaIsRqgQy7VGlZrVw1giWO+lDoX3MCPnpVO4=
+github.com/sosodev/duration v1.1.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
+github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
+github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
+github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
+github.com/vektah/gqlparser/v2 v2.5.10 h1:6zSM4azXC9u4Nxy5YmdmGu4uKamfwsdKTwp5zsEealU=
+github.com/vektah/gqlparser/v2 v2.5.10/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc=
+github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
+github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
+go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
+golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
+golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
+golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
+golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
+golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
+golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
+golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM=
+golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
+google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
+google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
+google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
+google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
+google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
+google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
+google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
+google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/tests/bcr/go_work/tools/tools.go b/tests/bcr/go_work/tools/tools.go
new file mode 100644
index 000000000..c6650a8b6
--- /dev/null
+++ b/tests/bcr/go_work/tools/tools.go
@@ -0,0 +1,12 @@
+//go:build tools
+
+// Follows the best practice from https://github.com/golang/go/issues/25922#issuecomment-1038394599
+// to keep Go tools referenced in go.mod in a way that doesn't have `go mod tidy` remove them.
+
+package tools
+
+import (
+ _ "github.com/99designs/gqlgen"
+ _ "github.com/99designs/gqlgen/graphql/introspection"
+ _ "github.com/bazelbuild/buildtools/buildifier"
+)
diff --git a/tests/bzlmod/go_mod_test.bzl b/tests/bzlmod/go_mod_test.bzl
index c4287074a..c05ba03a1 100644
--- a/tests/bzlmod/go_mod_test.bzl
+++ b/tests/bzlmod/go_mod_test.bzl
@@ -1,5 +1,5 @@
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
-load("//internal/bzlmod:go_mod.bzl", "parse_go_mod", "parse_go_sum")
+load("//internal/bzlmod:go_mod.bzl", "parse_go_mod", "parse_go_sum", "parse_go_work", "use_spec_to_label")
_GO_MOD_CONTENT = """ go 1.18
@@ -14,6 +14,7 @@ github.com/bmatcuk/doublestar/v4 v4.0.2 // indirect
replace github.com/go-fsnotify/fsnotify => github.com/fsnotify/fsnotify v1.4.2
replace github.com/bmatcuk/doublestar/v4 v4.0.2 => github.com/bmatcuk/doublestar/v4 v4.0.3
+replace example.org/hello => ../fixtures/hello
module github.com/bazelbuild/bazel-gazelle
@@ -30,8 +31,9 @@ _EXPECTED_GO_MOD_PARSE_RESULT = struct(
go = (1, 18),
module = "github.com/bazelbuild/bazel-gazelle",
replace_map = {
- "github.com/go-fsnotify/fsnotify": struct(from_version = None, to_path = "github.com/fsnotify/fsnotify", version = "1.4.2"),
- "github.com/bmatcuk/doublestar/v4": struct(from_version = "4.0.2", to_path = "github.com/bmatcuk/doublestar/v4", version = "4.0.3"),
+ "github.com/go-fsnotify/fsnotify": struct(local_path = None, from_version = None, to_path = "github.com/fsnotify/fsnotify", version = "1.4.2"),
+ "github.com/bmatcuk/doublestar/v4": struct(local_path = None, from_version = "4.0.2", to_path = "github.com/bmatcuk/doublestar/v4", version = "4.0.3"),
+ "example.org/hello": struct(local_path = "../fixtures/hello", from_version = None, to_path = "example.org/hello", version = "{"),
},
require = (
struct(indirect = False, path = "github.com/bazelbuild/buildtools", version = "v0.0.0-20220531122519-a43aed7014c8"),
@@ -64,6 +66,17 @@ _EXPECTED_GO_MOD_21_PARSE_RESULT = struct(
require = (),
)
+def _use_spec_to_label_test_impl(ctx):
+ env = unittest.begin(ctx)
+
+ asserts.equals(env, Label("@@org_example//go_mod_one:go.mod"), use_spec_to_label("org_example", "./go_mod_one"))
+ asserts.equals(env, Label("@@org_example//go_mod_one:go.mod"), use_spec_to_label("org_example", "./go_mod_one/"))
+ asserts.equals(env, Label("@@org_example//bar/go_mod_one:go.mod"), use_spec_to_label("org_example", "./bar/go_mod_one"))
+
+ return unittest.end(env)
+
+use_spec_test = unittest.make(_use_spec_to_label_test_impl)
+
def _go_mod_21_test_impl(ctx):
env = unittest.begin(ctx)
asserts.equals(env, _EXPECTED_GO_MOD_21_PARSE_RESULT, parse_go_mod(_GO_MOD_21_CONTENT, "/go.mod"))
@@ -91,10 +104,55 @@ def _go_sum_test_impl(ctx):
go_sum_test = unittest.make(_go_sum_test_impl)
+_GO_WORK_CONTENT = """go 1.18
+use ./go_mod_one
+use (
+ ./foo/go_mod_two
+ ./bar/baz/go_mod_three
+)
+
+replace github.com/go-fsnotify/fsnotify => github.com/fsnotify/fsnotify v1.4.2
+replace github.com/bmatcuk/doublestar/v4 v4.0.2 => github.com/bmatcuk/doublestar/v4 v4.0.3
+replace example.org/hello => ../fixtures/hello
+"""
+
+_EXPECTED_GO_WORK_PARSE_RESULT = struct(
+ go = (1, 18),
+ from_file_tags = [
+ struct(_is_dev_dependency = False, go_mod = Label("//go_mod_one:go.mod")),
+ struct(_is_dev_dependency = False, go_mod = Label("//foo/go_mod_two:go.mod")),
+ struct(_is_dev_dependency = False, go_mod = Label("//bar/baz/go_mod_three:go.mod")),
+ ],
+ module_tags = [
+ struct(indirect = False, _parent_label = Label("//:go.work"), local_path = None, path = "github.com/fsnotify/fsnotify", version = "1.4.2"),
+ struct(indirect = False, _parent_label = Label("//:go.work"), local_path = None, path = "github.com/bmatcuk/doublestar/v4", version = "4.0.3"),
+ struct(indirect = False, _parent_label = Label("//:go.work"), local_path = "../fixtures/hello", path = "example.org/hello", version = "{"),
+ ],
+ replace_map = {
+ "github.com/go-fsnotify/fsnotify": struct(local_path = None, from_version = None, to_path = "github.com/fsnotify/fsnotify", version = "1.4.2"),
+ "github.com/bmatcuk/doublestar/v4": struct(local_path = None, from_version = "4.0.2", to_path = "github.com/bmatcuk/doublestar/v4", version = "4.0.3"),
+ "example.org/hello": struct(local_path = "../fixtures/hello", from_version = None, to_path = "example.org/hello", version = "{"),
+ },
+ use = [
+ "./go_mod_one",
+ "./foo/go_mod_two",
+ "./bar/baz/go_mod_three",
+ ],
+)
+
+def _go_work_test_impl(ctx):
+ env = unittest.begin(ctx)
+ asserts.equals(env, _EXPECTED_GO_WORK_PARSE_RESULT, parse_go_work(_GO_WORK_CONTENT, Label("@@//:go.work")))
+ return unittest.end(env)
+
+go_work_test = unittest.make(_go_work_test_impl)
+
def go_mod_test_suite(name):
unittest.suite(
name,
go_mod_test,
go_mod_21_test,
go_sum_test,
+ go_work_test,
+ use_spec_test,
)
diff --git a/tests/bzlmod/utils_test.bzl b/tests/bzlmod/utils_test.bzl
index 99239822f..87cd9f98b 100644
--- a/tests/bzlmod/utils_test.bzl
+++ b/tests/bzlmod/utils_test.bzl
@@ -11,7 +11,7 @@ _EXPECT_REPLACED_STRUCT = struct(
direct = True,
path = "github.com/bazelbuild/buildtools",
replace = "path/to/add/replace",
- version = "v1.2.2"
+ version = "v1.2.2",
)
def _with_replaced_or_new_fields_test_impl(ctx):
diff --git a/tests/cli/env_variables_test.bzl b/tests/cli/env_variables_test.bzl
index fe55c6eb9..3e3312040 100644
--- a/tests/cli/env_variables_test.bzl
+++ b/tests/cli/env_variables_test.bzl
@@ -1,5 +1,5 @@
-load("@bazel_skylib//rules:analysis_test.bzl", "analysis_test")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest")
+load("@bazel_skylib//rules:analysis_test.bzl", "analysis_test")
load("//:def.bzl", "gazelle")
def _invalid_var_failure_test_impl(ctx):
diff --git a/tests/fixtures/hello/go.mod b/tests/fixtures/hello/go.mod
new file mode 100644
index 000000000..cecdf0530
--- /dev/null
+++ b/tests/fixtures/hello/go.mod
@@ -0,0 +1,10 @@
+module example.com/hello
+
+go 1.21
+
+require rsc.io/quote v1.5.2
+
+require (
+ golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
+ rsc.io/sampler v1.3.0 // indirect
+)
diff --git a/tests/fixtures/hello/go.sum b/tests/fixtures/hello/go.sum
new file mode 100644
index 000000000..4a8bcd704
--- /dev/null
+++ b/tests/fixtures/hello/go.sum
@@ -0,0 +1,6 @@
+golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
+golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+rsc.io/quote v1.5.2 h1:w5fcysjrx7yqtD/aO+QwRjYZOKnaM9Uh2b40tElTs3Y=
+rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
+rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
+rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
diff --git a/tests/fixtures/hello/hello.go b/tests/fixtures/hello/hello.go
new file mode 100644
index 000000000..83891ff60
--- /dev/null
+++ b/tests/fixtures/hello/hello.go
@@ -0,0 +1,7 @@
+package hello
+
+import "rsc.io/quote"
+
+func Hello() string {
+ return quote.Hello()
+}
diff --git a/tests/fixtures/hello/hello_test.go b/tests/fixtures/hello/hello_test.go
new file mode 100644
index 000000000..b01b58f6e
--- /dev/null
+++ b/tests/fixtures/hello/hello_test.go
@@ -0,0 +1,10 @@
+package hello
+
+import "testing"
+
+func TestHello(t *testing.T) {
+ want := "Hello, world."
+ if got := Hello(); got != want {
+ t.Errorf("Hello() = %q, want %q", got, want)
+ }
+}