Skip to content

Commit

Permalink
fix(bzlmod): allow passing build_extra_args in gazelle_override (#1648)
Browse files Browse the repository at this point in the history
* fix(bzlmod): allow build_extra_args in gazelle_override

* bump MODULE.bazel.lock

* add DEFAULT_BUILD_EXTRA_ARGS_BY_PATH

* fix return statement in _get_build_extra_args

* bazel mod deps

* pr comments: remove empty line in _get_build_extra_args

* bazel mod deps in tests/bcr
  • Loading branch information
casuallyhostile authored Oct 28, 2023
1 parent e74436e commit d8369a6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
6 changes: 6 additions & 0 deletions internal/bzlmod/default_gazelle_overrides.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ DEFAULT_DIRECTIVES_BY_PATH = {
"gazelle:proto disable",
],
}

DEFAULT_BUILD_EXTRA_ARGS_BY_PATH = {
"github.com/census-instrumentation/opencensus-proto": [
"-exclude=src",
],
}
15 changes: 15 additions & 0 deletions internal/bzlmod/go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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",
)
Expand Down Expand Up @@ -75,6 +76,12 @@ def _get_build_file_generation(path, gazelle_overrides):

return DEFAULT_BUILD_FILE_GENERATION_BY_PATH.get(path, "auto")

def _get_build_extra_args(path, gazelle_overrides):
override = gazelle_overrides.get(path)
if override:
return override.build_extra_args
return DEFAULT_BUILD_EXTRA_ARGS_BY_PATH.get(path, [])

def _get_directives(path, gazelle_overrides):
override = gazelle_overrides.get(path)
if override:
Expand Down Expand Up @@ -131,6 +138,7 @@ def _process_gazelle_override(gazelle_override_tag):
return struct(
directives = gazelle_override_tag.directives,
build_file_generation = gazelle_override_tag.build_file_generation,
build_extra_args = gazelle_override_tag.build_extra_args,
)

def _process_module_override(module_override_tag):
Expand Down Expand Up @@ -374,6 +382,7 @@ def _go_deps_impl(module_ctx):
"importpath": path,
"build_directives": _get_directives(path, gazelle_overrides),
"build_file_generation": _get_build_file_generation(path, gazelle_overrides),
"build_extra_args": _get_build_extra_args(path, gazelle_overrides),
"patches": _get_patches(path, module_overrides),
"patch_args": _get_patch_args(path, module_overrides),
}
Expand Down Expand Up @@ -527,6 +536,12 @@ _gazelle_override_tag = tag_class(
"on",
],
),
"build_extra_args": attr.string_list(
default = [],
doc = """
A list of additional command line arguments to pass to Gazelle when generating build files.
""",
),
"directives": attr.string_list(
doc = """Gazelle configuration directives to use for this Go module's external repository.
Expand Down
Loading

0 comments on commit d8369a6

Please sign in to comment.