From 22f36517f1b4988598318a02666510d2858ba1b2 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Fri, 23 Aug 2024 15:07:15 -0400 Subject: [PATCH] Adjust gazelle for upcoming rules_go changes --- internal/gazelle_binary.bzl | 19 +++++++++++-------- language/go/def.bzl | 12 ++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/internal/gazelle_binary.bzl b/internal/gazelle_binary.bzl index fa1187c7a..3b3dc6091 100644 --- a/internal/gazelle_binary.bzl +++ b/internal/gazelle_binary.bzl @@ -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), @@ -49,12 +50,12 @@ 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, @@ -62,14 +63,16 @@ var languages = []language.Language{{ 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, ), ] diff --git a/language/go/def.bzl b/language/go/def.bzl index 4e6356225..3ca22297d 100644 --- a/language/go/def.bzl +++ b/language/go/def.bzl @@ -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 = outputs, 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,