Skip to content

Commit

Permalink
Adjust gazelle for upcoming rules_go changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbarsky committed Aug 23, 2024
1 parent 2b326f8 commit f3c3c79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
19 changes: 11 additions & 8 deletions internal/gazelle_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ var languages = []language.Language{{
{lang_calls},
}}
"""
lang_imports = [format_import(d[GoArchive].data.importpath) for d in ctx.attr.languages]
lang_calls = [format_call(d[GoArchive].data.importpath) for d in ctx.attr.languages]
languages = ctx.attr.languages
lang_imports = [format_import(d[GoArchive].data.importpath) for d in languages]
lang_calls = [format_call(d[GoArchive].data.importpath) for d in languages]
langs_content = langs_content_tpl.format(
lang_imports = "\n\t".join(lang_imports),
lang_calls = ",\n\t".join(lang_calls),
Expand All @@ -49,27 +50,29 @@ var languages = []language.Language{{
library = go.new_library(go, is_main = True)
attr = struct(
srcs = [struct(files = [langs_file])],
deps = ctx.attr.languages,
deps = languages,
embed = [ctx.attr._srcs],
)
source = go.library_to_source(go, attr, library, ctx.coverage_instrumented())

archive, executable, runfiles = go.binary(
archive, executable, _ = go.binary(
go,
name = ctx.label.name,
source = source,
version_file = ctx.version_file,
info_file = ctx.info_file,
)

files = [executable]

return [
library,
source,
archive,
OutputGroupInfo(compilation_outputs = [archive.data.file]),
DefaultInfo(
files = depset([executable]),
runfiles = runfiles,
files = depset(files),
runfiles = ctx.runfiles(files).merge_all(
[lang[DefaultInfo].default_runfiles for lang in languages]
),
executable = executable,
),
]
Expand Down
12 changes: 8 additions & 4 deletions language/go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ load("@io_bazel_rules_go//go:def.bzl", "go_context")

def _std_package_list_impl(ctx):
go = go_context(ctx)
package_list = go.sdk.package_list
outputs = [ctx.outputs.out]

args = ctx.actions.args()
args.add_all([go.package_list, ctx.outputs.out])
args.add_all([package_list, ctx.outputs.out])

ctx.actions.run(
inputs = [go.package_list],
outputs = [ctx.outputs.out],
inputs = [package_list],
outputs = output,
executable = ctx.executable._gen_std_package_list,
arguments = [args],
mnemonic = "GoStdPackageList",
)
return [DefaultInfo(files = depset([ctx.outputs.out]))]
return [DefaultInfo(files = depset(outputs))]

std_package_list = rule(
implementation = _std_package_list_impl,
Expand Down

0 comments on commit f3c3c79

Please sign in to comment.