From 564f82048774e8f18253258eeb4ee6f9874c1909 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Mon, 18 Nov 2024 11:09:13 -0500 Subject: [PATCH] Merge GoLibrary and GoSource providers (#4030) **What type of PR is this?** Code simplification **What does this PR do? Why is it needed?** These providers are 1:1, and we always create a library followed by `source_from_library`. Merging them allows to remove the `library` field from `GoSource` as well as the the `resolve` field, since we don't need to smuggle the closure between the providers anymore. If we do this, we will also need to fix up Gazelle. We can either have a patch in this repo so CI passes and then followup with the Gazelle fix, or somehow shim the API until we release new versions in lockstep. Open to ideas how to best do this. **Which issues(s) does this PR fix?** One step toward https://github.com/bazelbuild/rules_go/issues/2578 Fixes # **Other notes for review** --- docs/go/core/rules.bzl | 6 +- docs/go/core/rules.md | 32 ++-- extras/gomock.bzl | 16 +- go/core.rst | 3 +- go/def.bzl | 20 ++- go/nogo.rst | 3 +- go/private/actions/archive.bzl | 32 ++-- go/private/actions/stdlib.bzl | 11 +- go/private/context.bzl | 142 ++++++++++++------ go/private/providers.bzl | 16 +- go/private/rules/binary.bzl | 28 ++-- go/private/rules/cross.bzl | 2 - go/private/rules/library.bzl | 34 ++--- go/private/rules/nogo.bzl | 23 ++- go/private/rules/source.bzl | 24 ++- go/private/rules/test.bzl | 137 +++++++++-------- go/private/rules/transition.bzl | 5 +- go/providers.rst | 45 ++---- go/toolchains.rst | 89 ++++++----- proto/compiler.bzl | 16 +- proto/core.rst | 15 +- proto/def.bzl | 27 ++-- tests/core/go_binary/many_deps.bzl | 13 +- .../go_path/pkg/lib/generated_embeded.bzl | 12 +- tests/core/go_proto_library/README.rst | 2 +- tests/extras/gomock/README.rst | 6 +- tests/legacy/providers/test.bzl | 4 +- 27 files changed, 395 insertions(+), 368 deletions(-) diff --git a/docs/go/core/rules.bzl b/docs/go/core/rules.bzl index 1dea269e92..8fdb90e2b2 100644 --- a/docs/go/core/rules.bzl +++ b/docs/go/core/rules.bzl @@ -3,9 +3,8 @@ [Bourne shell tokenization]: https://docs.bazel.build/versions/master/be/common-definitions.html#sh-tokenization [Gazelle]: https://github.com/bazelbuild/bazel-gazelle [GoArchive]: /go/providers.rst#GoArchive - [GoLibrary]: /go/providers.rst#GoLibrary [GoPath]: /go/providers.rst#GoPath - [GoSource]: /go/providers.rst#GoSource + [GoInfo]: /go/providers.rst#GoInfo [build constraints]: https://golang.org/pkg/go/build/#hdr-Build_Constraints [cc_library deps]: https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library.deps [cgo]: http://golang.org/cmd/cgo/ @@ -51,9 +50,8 @@ sufficient to match the capabilities of the normal go tools. - [Bourne shell tokenization] - [Gazelle] - [GoArchive] -- [GoLibrary] - [GoPath] -- [GoSource] +- [GoInfo] - [build constraints]: - [cc_library deps] - [cgo] diff --git a/docs/go/core/rules.md b/docs/go/core/rules.md index 13bbfdd84f..6122f83305 100644 --- a/docs/go/core/rules.md +++ b/docs/go/core/rules.md @@ -5,9 +5,8 @@ [Bourne shell tokenization]: https://docs.bazel.build/versions/master/be/common-definitions.html#sh-tokenization [Gazelle]: https://github.com/bazelbuild/bazel-gazelle [GoArchive]: /go/providers.rst#GoArchive - [GoLibrary]: /go/providers.rst#GoLibrary [GoPath]: /go/providers.rst#GoPath - [GoSource]: /go/providers.rst#GoSource + [GoInfo]: /go/providers.rst#GoInfo [build constraints]: https://golang.org/pkg/go/build/#hdr-Build_Constraints [cc_library deps]: https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library.deps [cgo]: http://golang.org/cmd/cgo/ @@ -53,9 +52,8 @@ sufficient to match the capabilities of the normal go tools. - [Bourne shell tokenization] - [Gazelle] - [GoArchive] -- [GoLibrary] - [GoPath] -- [GoSource] +- [GoInfo] - [build constraints]: - [cc_library deps] - [cgo] @@ -136,8 +134,6 @@ This builds an executable from a set of source files, ***Note:*** `name` should be the same as the desired name of the generated binary.

**Providers:** @@ -156,8 +152,8 @@ This builds an executable from a set of source files, | cppopts | List of flags to add to the C/C++ preprocessor command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo = True. | List of strings | optional | [] | | cxxopts | List of flags to add to the C++ compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo = True. | List of strings | optional | [] | | data | List of files needed by this rule at run-time. This may include data files needed or other programs that may be executed. The [bazel] package may be used to locate run files; they may appear in different places depending on the operating system and environment. See [data dependencies] for more information on data files. | List of labels | optional | [] | -| deps | List of Go libraries this package imports directly. These may be go_library rules or compatible rules with the [GoLibrary] provider. | List of labels | optional | [] | -| embed | List of Go libraries whose sources should be compiled together with this binary's sources. Labels listed here must name go_library, go_proto_library, or other compatible targets with the [GoLibrary] and [GoSource] providers. Embedded libraries must all have the same importpath, which must match the importpath for this go_binary if one is specified. At most one embedded library may have cgo = True, and the embedding binary may not also have cgo = True. See [Embedding] for more information. | List of labels | optional | [] | +| deps | List of Go libraries this package imports directly. These may be go_library rules or compatible rules with the [GoInfo] provider. | List of labels | optional | [] | +| embed | List of Go libraries whose sources should be compiled together with this binary's sources. Labels listed here must name go_library, go_proto_library, or other compatible targets with the [GoInfo] provider. Embedded libraries must all have the same importpath, which must match the importpath for this go_binary if one is specified. At most one embedded library may have cgo = True, and the embedding binary may not also have cgo = True. See [Embedding] for more information. | List of labels | optional | [] | | embedsrcs | The list of files that may be embedded into the compiled package using //go:embed directives. All files must be in the same logical directory or a subdirectory as source files. All source files containing //go:embed directives must be in the same logical directory. It's okay to mix static and generated source files and static and generated embeddable files. | List of labels | optional | [] | | env | Environment variables to set when the binary is executed with bazel run. The values (but not keys) are subject to [location expansion](https://docs.bazel.build/versions/main/skylark/macros.html) but not full [make variable expansion](https://docs.bazel.build/versions/main/be/make-variables.html). | Dictionary: String -> String | optional | {} | | gc_goopts | List of flags to add to the Go compilation command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] | @@ -193,8 +189,6 @@ This wraps an executable built by `go_binary` to cross compile it of the golang SDK.

**Providers:** @@ -228,8 +222,7 @@ This builds a Go library from a set of source files that are all part of or `go_default_library`, with the old naming convention.

**Providers:** @@ -247,8 +240,8 @@ This builds a Go library from a set of source files that are all part of | cppopts | List of flags to add to the C/C++ preprocessor command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo = True. | List of strings | optional | [] | | cxxopts | List of flags to add to the C++ compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo = True. | List of strings | optional | [] | | data | List of files needed by this rule at run-time. This may include data files needed or other programs that may be executed. The [bazel] package may be used to locate run files; they may appear in different places depending on the operating system and environment. See [data dependencies] for more information on data files. | List of labels | optional | [] | -| deps | List of Go libraries this package imports directly. These may be go_library rules or compatible rules with the [GoLibrary] provider. | List of labels | optional | [] | -| embed | List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name go_library, go_proto_library, or other compatible targets with the [GoLibrary] and [GoSource] providers. Embedded libraries must have the same importpath as the embedding library. At most one embedded library may have cgo = True, and the embedding library may not also have cgo = True. See [Embedding] for more information. | List of labels | optional | [] | +| deps | List of Go libraries this package imports directly. These may be go_library rules or compatible rules with the [GoInfo] provider. | List of labels | optional | [] | +| embed | List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name go_library, go_proto_library, or other compatible targets with the [GoInfo] provider. Embedded libraries must have the same importpath as the embedding library. At most one embedded library may have cgo = True, and the embedding library may not also have cgo = True. See [Embedding] for more information. | List of labels | optional | [] | | embedsrcs | The list of files that may be embedded into the compiled package using //go:embed directives. All files must be in the same logical directory or a subdirectory as source files. All source files containing //go:embed directives must be in the same logical directory. It's okay to mix static and generated source files and static and generated embeddable files. | List of labels | optional | [] | | gc_goopts | List of flags to add to the Go compilation command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] | | importmap | The actual import path of this library. By default, this is importpath. This is mostly only visible to the compiler and linker, but it may also be seen in stack traces. This must be unique among packages passed to the linker. It may be set to something different than importpath to prevent conflicts between multiple packages with the same path (for example, from different vendor directories). | String | optional | "" | @@ -343,8 +336,7 @@ This declares a set of source files and related dependencies that can be embedde This is used as a way of easily declaring a common set of sources re-used in multiple rules.

**Providers:** @@ -355,8 +347,8 @@ This declares a set of source files and related dependencies that can be embedde | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | data | List of files needed by this rule at run-time. This may include data files needed or other programs that may be executed. The [bazel] package may be used to locate run files; they may appear in different places depending on the operating system and environment. See [data dependencies] for more information on data files. | List of labels | optional | [] | -| deps | List of Go libraries this source list imports directly. These may be go_library rules or compatible rules with the [GoLibrary] provider. | List of labels | optional | [] | -| embed | List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name go_library, go_proto_library, or other compatible targets with the [GoLibrary] and [GoSource] providers. Embedded libraries must have the same importpath as the embedding library. At most one embedded library may have cgo = True, and the embedding library may not also have cgo = True. See [Embedding] for more information. | List of labels | optional | [] | +| deps | List of Go libraries this source list imports directly. These may be go_library rules or compatible rules with the [GoInfo] provider. | List of labels | optional | [] | +| embed | List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name go_library, go_proto_library, or other compatible targets with the [GoInfo] provider. Embedded libraries must have the same importpath as the embedding library. At most one embedded library may have cgo = True, and the embedding library may not also have cgo = True. See [Embedding] for more information. | List of labels | optional | [] | | gc_goopts | List of flags to add to the Go compilation command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] | | srcs | The list of Go source files that are compiled to create the package. The following file types are permitted: .go, .c, .s, .syso, .S, .h. The files may contain Go-style [build constraints]. | List of labels | optional | [] | @@ -418,8 +410,8 @@ This builds a set of tests that can be run with `bazel test`.

| cppopts | List of flags to add to the C/C++ preprocessor command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo = True. | List of strings | optional | [] | | cxxopts | List of flags to add to the C++ compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo = True. | List of strings | optional | [] | | data | List of files needed by this rule at run-time. This may include data files needed or other programs that may be executed. The [bazel] package may be used to locate run files; they may appear in different places depending on the operating system and environment. See [data dependencies] for more information on data files. | List of labels | optional | [] | -| deps | List of Go libraries this test imports directly. These may be go_library rules or compatible rules with the [GoLibrary] provider. | List of labels | optional | [] | -| embed | List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name go_library, go_proto_library, or other compatible targets with the [GoLibrary] and [GoSource] providers. Embedded libraries must have the same importpath as the embedding library. At most one embedded library may have cgo = True, and the embedding library may not also have cgo = True. See [Embedding] for more information. | List of labels | optional | [] | +| deps | List of Go libraries this test imports directly. These may be go_library rules or compatible rules with the [GoInfo] provider. | List of labels | optional | [] | +| embed | List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name go_library, go_proto_library, or other compatible targets with the [GoInfo] provider. Embedded libraries must have the same importpath as the embedding library. At most one embedded library may have cgo = True, and the embedding library may not also have cgo = True. See [Embedding] for more information. | List of labels | optional | [] | | embedsrcs | The list of files that may be embedded into the compiled package using //go:embed directives. All files must be in the same logical directory or a subdirectory as source files. All source files containing //go:embed directives must be in the same logical directory. It's okay to mix static and generated source files and static and generated embeddable files. | List of labels | optional | [] | | env | Environment variables to set for the test execution. The values (but not keys) are subject to [location expansion](https://docs.bazel.build/versions/main/skylark/macros.html) but not full [make variable expansion](https://docs.bazel.build/versions/main/be/make-variables.html). | Dictionary: String -> String | optional | {} | | env_inherit | Environment variables to inherit from the external environment. | List of strings | optional | [] | diff --git a/extras/gomock.bzl b/extras/gomock.bzl index 9381ca6c79..b73881fdcd 100644 --- a/extras/gomock.bzl +++ b/extras/gomock.bzl @@ -25,7 +25,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("//go/private:common.bzl", "GO_TOOLCHAIN", "GO_TOOLCHAIN_LABEL") load("//go/private:context.bzl", "go_context") -load("//go/private:providers.bzl", "GoLibrary") +load("//go/private:providers.bzl", "GoInfo") load("//go/private/rules:wrappers.bzl", go_binary = "go_binary_macro") _MOCKGEN_TOOL = Label("//extras/gomock:mockgen") @@ -36,10 +36,10 @@ def _gomock_source_impl(ctx): # In Source mode, it's not necessary to pass through a library, as the only thing we use it for is setting up # the relative file locations. Forcing users to pass a library makes it difficult in the case where a mock should - # be included as part of that same library, as it results in a dependency loop (GoMock -> GoLibrary -> GoMock). + # be included as part of that same library, as it results in a dependency loop (GoMock -> GoInfo -> GoMock). # Allowing users to pass an importpath directly bypasses this issue. # See the test case in //tests/extras/gomock/source_with_importpath for an example. - importpath = ctx.attr.source_importpath if ctx.attr.source_importpath else ctx.attr.library[GoLibrary].importmap + importpath = ctx.attr.source_importpath if ctx.attr.source_importpath else ctx.attr.library[GoInfo].importmap # create GOPATH and copy source into GOPATH go_path_prefix = "gopath" @@ -113,7 +113,7 @@ _gomock_source = rule( attrs = { "library": attr.label( doc = "The target the Go library where this source file belongs", - providers = [GoLibrary], + providers = [GoInfo], mandatory = False, ), "source_importpath": attr.string( @@ -257,7 +257,7 @@ def _gomock_reflect(name, library, out, mockgen_tool, **kwargs): def _gomock_prog_gen_impl(ctx): args = ["-prog_only"] - args.append(ctx.attr.library[GoLibrary].importpath) + args.append(ctx.attr.library[GoInfo].importpath) args.append(",".join(ctx.attr.interfaces)) cmd = ctx.file.mockgen_tool @@ -280,7 +280,7 @@ _gomock_prog_gen = rule( attrs = { "library": attr.label( doc = "The target the Go library is at to look for the interfaces in. When this is set and source is not set, mockgen will use its reflect code to generate the mocks. If source is set, its dependencies will be included in the GOPATH that mockgen will be run in.", - providers = [GoLibrary], + providers = [GoInfo], mandatory = True, ), "out": attr.output( @@ -313,7 +313,7 @@ def _gomock_prog_exec_impl(ctx): # annoyingly, the interfaces join has to go after the importpath so we can't # share those. - args.append(ctx.attr.library[GoLibrary].importpath) + args.append(ctx.attr.library[GoInfo].importpath) args.append(",".join(ctx.attr.interfaces)) ctx.actions.run_shell( @@ -337,7 +337,7 @@ _gomock_prog_exec = rule( attrs = { "library": attr.label( doc = "The target the Go library is at to look for the interfaces in. When this is set and source is not set, mockgen will use its reflect code to generate the mocks. If source is set, its dependencies will be included in the GOPATH that mockgen will be run in.", - providers = [GoLibrary], + providers = [GoInfo], mandatory = True, ), "out": attr.output( diff --git a/go/core.rst b/go/core.rst index e81f4fd448..03fddb4d02 100644 --- a/go/core.rst +++ b/go/core.rst @@ -5,9 +5,8 @@ Core Go rules .. _Bourne shell tokenization: https://docs.bazel.build/versions/master/be/common-definitions.html#sh-tokenization .. _Gazelle: https://github.com/bazelbuild/bazel-gazelle .. _GoArchive: providers.rst#GoArchive -.. _GoLibrary: providers.rst#GoLibrary .. _GoPath: providers.rst#GoPath -.. _GoSource: providers.rst#GoSource +.. _GoInfo: providers.rst#GoInfo .. _build constraints: https://golang.org/pkg/go/build/#hdr-Build_Constraints .. _cc_library deps: https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library.deps .. _cgo: http://golang.org/cmd/cgo/ diff --git a/go/def.bzl b/go/def.bzl index 008f8d8151..2edb23e1bf 100644 --- a/go/def.bzl +++ b/go/def.bzl @@ -29,6 +29,7 @@ load( load( "//go/private:context.bzl", _go_context = "go_context", + _new_go_info = "new_go_info", ) load( "//go/private:go_toolchain.bzl", @@ -38,10 +39,9 @@ load( "//go/private:providers.bzl", _GoArchive = "GoArchive", _GoArchiveData = "GoArchiveData", - _GoLibrary = "GoLibrary", + _GoInfo = "GoInfo", _GoPath = "GoPath", _GoSDK = "GoSDK", - _GoSource = "GoSource", ) load( "//go/private/rules:cross.bzl", @@ -134,11 +134,19 @@ go_tool_library = _go_tool_library go_toolchain = _go_toolchain nogo = _nogo -# See go/providers.rst#GoLibrary for full documentation. -GoLibrary = _GoLibrary +# This provider is deprecated and will be removed in a future release. +# Use GoInfo instead. +GoLibrary = _GoInfo -# See go/providers.rst#GoSource for full documentation. -GoSource = _GoSource +# This provider is deprecated and will be removed in a future release. +# Use GoInfo instead. +GoSource = _GoInfo + +# See go/providers.rst#GoInfo for full documentation. +GoInfo = _GoInfo + +# See go/toolchains.rst#new_go_info for full documentation. +new_go_info = _new_go_info # See go/providers.rst#GoPath for full documentation. GoPath = _GoPath diff --git a/go/nogo.rst b/go/nogo.rst index e27eca87f8..e150afc3b7 100644 --- a/go/nogo.rst +++ b/go/nogo.rst @@ -8,8 +8,7 @@ .. _go_library: /docs/go/core/rules.md#go_library .. _analysis: https://godoc.org/golang.org/x/tools/go/analysis .. _Analyzer: https://godoc.org/golang.org/x/tools/go/analysis#Analyzer -.. _GoLibrary: providers.rst#GoLibrary -.. _GoSource: providers.rst#GoSource +.. _GoInfo: providers.rst#GoInfo .. _GoArchive: providers.rst#GoArchive .. _vet: https://golang.org/cmd/vet/ .. _golangci-lint: https://github.com/golangci/golangci-lint diff --git a/go/private/actions/archive.bzl b/go/private/actions/archive.bzl index 2ac957045f..481035439d 100644 --- a/go/private/actions/archive.bzl +++ b/go/private/actions/archive.bzl @@ -43,7 +43,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d if source == None: fail("source is a required parameter") - testfilter = getattr(source.library, "testfilter", None) + testfilter = getattr(source, "testfilter", None) pre_ext = "" if go.mode.linkmode == LINKMODE_C_ARCHIVE: pre_ext = "_" # avoid collision with go_binary output file with .a extension @@ -53,17 +53,17 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d pre_ext = ".external" if _recompile_suffix: pre_ext += _recompile_suffix - out_lib = go.declare_file(go, name = source.library.name, ext = pre_ext + ".a") + out_lib = go.declare_file(go, name = source.name, ext = pre_ext + ".a") # store export information for compiling dependent packages separately - out_export = go.declare_file(go, name = source.library.name, ext = pre_ext + ".x") + out_export = go.declare_file(go, name = source.name, ext = pre_ext + ".x") out_cgo_export_h = None # set if cgo used in c-shared or c-archive mode nogo = get_nogo(go) if nogo: - out_facts = go.declare_file(go, name = source.library.name, ext = pre_ext + ".facts") - out_nogo_log = go.declare_file(go, name = source.library.name, ext = pre_ext + ".nogo.log") - out_nogo_validation = go.declare_file(go, name = source.library.name, ext = pre_ext + ".nogo") + out_facts = go.declare_file(go, name = source.name, ext = pre_ext + ".facts") + out_nogo_log = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo.log") + out_nogo_validation = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo") else: out_facts = None out_nogo_log = None @@ -78,8 +78,8 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode))) runfiles = source.runfiles.merge_all(files) - importmap = "main" if source.library.is_main else source.library.importmap - importpath, _ = effective_importpath_pkgpath(source.library) + importmap = "main" if source.is_main else source.importmap + importpath, _ = effective_importpath_pkgpath(source) if source.cgo and not go.mode.pure: # TODO(jayconrod): do we need to do full Bourne tokenization here? @@ -157,15 +157,13 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d # may be mutable. For now, new copied fields are private (named with # a leading underscore) since they may change in the future. - # GoLibrary fields - name = source.library.name, - label = source.library.label, - importpath = source.library.importpath, - importmap = source.library.importmap, - importpath_aliases = source.library.importpath_aliases, - pathtype = source.library.pathtype, - - # GoSource fields + # GoInfo fields + name = source.name, + label = source.label, + importpath = source.importpath, + importmap = source.importmap, + importpath_aliases = source.importpath_aliases, + pathtype = source.pathtype, srcs = tuple(source.srcs), _cover = source.cover, _embedsrcs = tuple(source.embedsrcs), diff --git a/go/private/actions/stdlib.bzl b/go/private/actions/stdlib.bzl index b731047b5a..09f199d45f 100644 --- a/go/private/actions/stdlib.bzl +++ b/go/private/actions/stdlib.bzl @@ -18,6 +18,10 @@ load( "GO_TOOLCHAIN_LABEL", "SUPPORTS_PATH_MAPPING_REQUIREMENT", ) +load( + "//go/private:context.bzl", + "new_go_info", +) load( "//go/private:mode.bzl", "LINKMODE_NORMAL", @@ -38,12 +42,11 @@ def emit_stdlib(go): Otherwise, the standard library will be compiled for the target. Returns: - A list of providers containing GoLibrary, GoSource and GoStdLib. + A list of providers containing GoInfo and GoStdLib. """ - library = go.new_library(go) - source = go.library_to_source(go, {}, library, False) + go_info = new_go_info(go, {}, coverage_instrumented = False) stdlib = _sdk_stdlib(go) if _should_use_sdk_stdlib(go) else _build_stdlib(go) - return [source, library, stdlib] + return [go_info, stdlib] def _should_use_sdk_stdlib(go): version = parse_version(go.sdk.version) diff --git a/go/private/context.bzl b/go/private/context.bzl index 7539c2647d..300a63aec4 100644 --- a/go/private/context.bzl +++ b/go/private/context.bzl @@ -69,8 +69,7 @@ load( "GoArchive", "GoConfigInfo", "GoContextInfo", - "GoLibrary", - "GoSource", + "GoInfo", "GoStdLib", "INFERRED_PATH", "get_archive", @@ -196,29 +195,6 @@ def _tool_args(go): args.use_param_file("-param=%s") return args -def _new_library(go, name = None, importpath = None, resolver = None, importable = True, testfilter = None, is_main = False, **kwargs): - if not importpath: - importpath = go.importpath - importmap = go.importmap - else: - importmap = importpath - pathtype = go.pathtype - if not importable and pathtype == EXPLICIT_PATH: - pathtype = EXPORT_PATH - - return GoLibrary( - name = go.label.name if not name else name, - label = go.label, - importpath = importpath, - importmap = importmap, - importpath_aliases = go.importpath_aliases, - pathtype = pathtype, - resolve = resolver, - testfilter = testfilter, - is_main = is_main, - **kwargs - ) - def _merge_embed(source, embed): s = get_source(embed) source["srcs"] = s.srcs + source["srcs"] @@ -259,16 +235,85 @@ def _dedup_archives(archives): deduped_archives.append(arc) return deduped_archives -def _library_to_source(go, attr, library, coverage_instrumented, verify_resolver_deps = True): +def _deprecated_new_library(go, name = None, importpath = None, resolver = None, importable = True, testfilter = None, is_main = False, **kwargs): + if not importpath: + importpath = go.importpath + importmap = go.importmap + else: + importmap = importpath + pathtype = go.pathtype + if not importable and pathtype == EXPLICIT_PATH: + pathtype = EXPORT_PATH + + return struct( + name = go.label.name if not name else name, + label = go.label, + importpath = importpath, + importmap = importmap, + importpath_aliases = go.importpath_aliases, + pathtype = pathtype, + resolve = resolver, + testfilter = testfilter, + is_main = is_main, + **kwargs + ) + +def _deprecated_library_to_source(go, attr, library, coverage_instrumented, verify_resolver_deps = True): + return new_go_info( + go, + attr, + name = library.name, + importpath = library.importpath, + resolver = library.resolve, + testfilter = library.testfilter, + is_main = library.is_main, + coverage_instrumented = coverage_instrumented, + generated_srcs = getattr(library, "srcs", []), + pathtype = library.pathtype, + verify_resolver_deps = verify_resolver_deps, + ) + +def new_go_info( + go, + attr, + name = None, + importpath = None, + resolver = None, + importable = True, + testfilter = None, + is_main = False, + coverage_instrumented = None, + generated_srcs = [], + pathtype = None, + verify_resolver_deps = False): + if not importpath: + importpath = go.importpath + importmap = go.importmap + else: + importmap = importpath + if not pathtype: + pathtype = go.pathtype + if not importable and pathtype == EXPLICIT_PATH: + pathtype = EXPORT_PATH + + if coverage_instrumented == None: + coverage_instrumented = go.coverage_instrumented + #TODO: stop collapsing a depset in this line... attr_srcs = [f for t in getattr(attr, "srcs", []) for f in as_iterable(t.files)] - generated_srcs = getattr(library, "srcs", []) srcs = attr_srcs + generated_srcs embedsrcs = [f for t in getattr(attr, "embedsrcs", []) for f in as_iterable(t.files)] - attr_deps = getattr(attr, "deps", []) - deps = [get_archive(dep) for dep in attr_deps] - source = { - "library": library, + deps = [get_archive(dep) for dep in getattr(attr, "deps", [])] + + go_info = { + "name": go.label.name if not name else name, + "label": go.label, + "importpath": importpath, + "importmap": importmap, + "importpath_aliases": tuple(getattr(attr, "importpath_aliases", ())), + "pathtype": pathtype, + "testfilter": testfilter, + "is_main": is_main, "mode": go.mode, "srcs": srcs, "embedsrcs": embedsrcs, @@ -276,7 +321,7 @@ def _library_to_source(go, attr, library, coverage_instrumented, verify_resolver "x_defs": {}, "deps": deps, "gc_goopts": _expand_opts(go, "gc_goopts", getattr(attr, "gc_goopts", [])), - "runfiles": _collect_runfiles(go, getattr(attr, "data", []), attr_deps), + "runfiles": _collect_runfiles(go, getattr(attr, "data", []), deps), "cgo": getattr(attr, "cgo", False), "cdeps": getattr(attr, "cdeps", []), "cppopts": _expand_opts(go, "cppopts", getattr(attr, "cppopts", [])), @@ -287,42 +332,43 @@ def _library_to_source(go, attr, library, coverage_instrumented, verify_resolver } for e in getattr(attr, "embed", []): - _merge_embed(source, e) + _merge_embed(go_info, e) + + go_info["deps"] = _dedup_archives(go_info["deps"]) - source["deps"] = _dedup_archives(source["deps"]) + x_defs = go_info["x_defs"] - x_defs = source["x_defs"] for k, v in getattr(attr, "x_defs", {}).items(): v = _expand_location(go, attr, v) if "." not in k: - k = "{}.{}".format(library.importmap, k) + k = "{}.{}".format(importmap, k) x_defs[k] = v - source["x_defs"] = x_defs - if not source["cgo"]: + go_info["x_defs"] = x_defs + if not go_info["cgo"]: for k in ("cdeps", "cppopts", "copts", "cxxopts", "clinkopts"): if getattr(attr, k, None): fail(k + " set without cgo = True") - for f in source["srcs"]: + for f in go_info["srcs"]: # This check won't report directory sources that contain C/C++ # sources. compilepkg will catch these instead. if f.extension in ("c", "cc", "cxx", "cpp", "hh", "hpp", "hxx"): fail("source {} has C/C++ extension, but cgo was not enabled (set 'cgo = True')".format(f.path)) - if library.resolve: - library.resolve(go, attr, source, _merge_embed) + if resolver: + resolver(go, attr, go_info, _merge_embed) # TODO(zbarsky): Remove this once downstream has a chance to migrate. if verify_resolver_deps: - for dep in source["deps"]: + for dep in go_info["deps"]: if type(dep) == "Target": print('Detected Targets in `source["deps"]` as a result of _resolver: ' + - "{}, from target {}. ".format(library.resolve, str(library.label)) + + "{}, from target {}. ".format(resolver, str(go.label)) + "Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. " + "This will be an error in the future.") - source["deps"] = [get_archive(dep) for dep in source["deps"]] + go_info["deps"] = [get_archive(dep) for dep in go_info["deps"]] break - return GoSource(**source) + return GoInfo(**go_info) def _collect_runfiles(go, data, deps): """Builds a set of runfiles from the deps and data attributes. @@ -342,7 +388,7 @@ def _infer_importpath(ctx, embeds, importpath, importmap): embed_importpath = "" embed_importmap = "" for embed in embeds: - lib = embed[GoLibrary] + lib = embed[GoInfo] if lib.pathtype == EXPLICIT_PATH: embed_importpath = lib.importpath embed_importmap = lib.importmap @@ -595,8 +641,8 @@ def go_context( # Helpers builder_args = _builder_args, tool_args = _tool_args, - new_library = _new_library, - library_to_source = _library_to_source, + new_library = _deprecated_new_library, + library_to_source = _deprecated_library_to_source, declare_file = _declare_file, declare_directory = _declare_directory, diff --git a/go/private/providers.bzl b/go/private/providers.bzl index e3becb68f0..619d1d12d4 100644 --- a/go/private/providers.bzl +++ b/go/private/providers.bzl @@ -12,24 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -# A representation of the inputs to a go package. -# This is a configuration independent provider. -# You must call resolve with a mode to produce a GoSource. -# See go/providers.rst#GoLibrary for full documentation. -GoLibrary = provider() - # The filtered inputs and dependencies needed to build a GoArchive # This is a configuration specific provider. # It has no transitive information. -# See go/providers.rst#GoSource for full documentation. -GoSource = provider() +# See go/providers.rst#GoInfo for full documentation. +GoInfo = provider() # This compiled form of a package used in transitive dependencies. # This is a configuration specific provider. # See go/providers.rst#GoArchiveData for full documentation. GoArchiveData = provider() -# The compiled form of a GoLibrary, with everything needed to link it into a binary. +# The compiled form of GoInfo, with everything needed to link it into a binary. # This is a configuration specific provider. # See go/providers.rst#GoArchive for full documentation. GoArchive = provider() @@ -76,7 +70,7 @@ EXPORT_PATH = "export" def get_source(dep): if type(dep) == "struct": return dep - return dep[GoSource] + return dep[GoInfo] def get_archive(dep): if type(dep) == "struct": @@ -91,7 +85,7 @@ def effective_importpath_pkgpath(lib): removed, and vendor directories from importmap may be modified. Args: - lib: GoLibrary or GoArchiveData + lib: GoInfo or GoArchiveData Returns: A tuple of effective import path and effective package path. Both are "" diff --git a/go/private/rules/binary.bzl b/go/private/rules/binary.bzl index 9a75d441d7..1d0dd0bc27 100644 --- a/go/private/rules/binary.bzl +++ b/go/private/rules/binary.bzl @@ -23,6 +23,7 @@ load( load( "//go/private:context.bzl", "go_context", + "new_go_info", ) load( "//go/private:mode.bzl", @@ -35,9 +36,8 @@ load( ) load( "//go/private:providers.bzl", - "GoLibrary", + "GoInfo", "GoSDK", - "GoSource", ) load( "//go/private/rules:transition.bzl", @@ -96,7 +96,7 @@ def new_cc_import( ) def _go_cc_aspect_impl(target, ctx): - if GoSource not in target: + if GoInfo not in target: return [] deps = ( @@ -127,8 +127,12 @@ def _go_binary_impl(ctx): ) is_main = go.mode.linkmode not in (LINKMODE_SHARED, LINKMODE_PLUGIN) - library = go.new_library(go, importable = False, is_main = is_main) - source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented()) + go_info = new_go_info( + go, + ctx.attr, + importable = False, + is_main = is_main, + ) name = ctx.attr.basename if not name: name = ctx.label.name @@ -141,7 +145,7 @@ def _go_binary_impl(ctx): archive, executable, runfiles = go.binary( go, name = name, - source = source, + source = go_info, gc_linkopts = gc_linkopts(ctx), version_file = ctx.version_file, info_file = ctx.info_file, @@ -238,20 +242,20 @@ def _go_binary_kwargs(go_cc_aspects = []): """, ), "deps": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], aspects = go_cc_aspects, doc = """List of Go libraries this package imports directly. - These may be `go_library` rules or compatible rules with the [GoLibrary] provider. + These may be `go_library` rules or compatible rules with the [GoInfo] provider. """, cfg = go_transition, ), "embed": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], aspects = go_cc_aspects, doc = """List of Go libraries whose sources should be compiled together with this binary's sources. Labels listed here must name `go_library`, - `go_proto_library`, or other compatible targets with the [GoLibrary] and - [GoSource] providers. Embedded libraries must all have the same `importpath`, + `go_proto_library`, or other compatible targets with the [GoInfo] provider. + Embedded libraries must all have the same `importpath`, which must match the `importpath` for this `go_binary` if one is specified. At most one embedded library may have `cgo = True`, and the embedding binary may not also have `cgo = True`. See [Embedding] for @@ -451,8 +455,6 @@ def _go_binary_kwargs(go_cc_aspects = []): ***Note:*** `name` should be the same as the desired name of the generated binary.

**Providers:** """, diff --git a/go/private/rules/cross.bzl b/go/private/rules/cross.bzl index 1d9e32a325..259031aa32 100644 --- a/go/private/rules/cross.bzl +++ b/go/private/rules/cross.bzl @@ -126,8 +126,6 @@ _go_cross_kwargs = { of the golang SDK.

**Providers:** """, diff --git a/go/private/rules/library.bzl b/go/private/rules/library.bzl index 5d48540c23..601eeacb60 100644 --- a/go/private/rules/library.bzl +++ b/go/private/rules/library.bzl @@ -23,10 +23,11 @@ load( load( "//go/private:context.bzl", "go_context", + "new_go_info", ) load( "//go/private:providers.bzl", - "GoLibrary", + "GoInfo", ) load( "//go/private/rules:transition.bzl", @@ -45,14 +46,12 @@ def _go_library_impl(ctx): go_context_data = ctx.attr._go_context_data, ) - library = go.new_library(go) - source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented()) - archive = go.archive(go, source) + go_info = new_go_info(go, ctx.attr) + archive = go.archive(go, go_info) validation_output = archive.data._validation_output return [ - library, - source, + go_info, archive, DefaultInfo( files = depset([archive.data.export_file]), @@ -94,10 +93,10 @@ go_library = rule( """, ), "deps": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], doc = """ List of Go libraries this package imports directly. - These may be `go_library` rules or compatible rules with the [GoLibrary] provider. + These may be `go_library` rules or compatible rules with the [GoInfo] provider. """, ), "importpath": attr.string( @@ -117,11 +116,11 @@ go_library = rule( "importpath_aliases": attr.string_list( ), # experimental, undocumented "embed": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], doc = """ List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name `go_library`, `go_proto_library`, or other compatible targets with - the [GoLibrary] and [GoSource] providers. Embedded libraries must have the same `importpath` as the embedding library. + the [GoInfo] provider. Embedded libraries must have the same `importpath` as the embedding library. At most one embedded library may have `cgo = True`, and the embedding library may not also have `cgo = True`. See [Embedding] for more information. """, @@ -199,8 +198,7 @@ go_library = rule( or `go_default_library`, with the old naming convention.

**Providers:** """, @@ -212,13 +210,11 @@ def _go_tool_library_impl(ctx): """Implements the go_tool_library() rule.""" go = go_context(ctx, include_deprecated_properties = False) - library = go.new_library(go) - source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented()) - archive = go.archive(go, source) + go_info = new_go_info(go, ctx.attr) + archive = go.archive(go, go_info) return [ - library, - source, + go_info, archive, ] @@ -227,10 +223,10 @@ go_tool_library = rule( attrs = { "data": attr.label_list(allow_files = True), "srcs": attr.label_list(allow_files = True), - "deps": attr.label_list(providers = [GoLibrary]), + "deps": attr.label_list(providers = [GoInfo]), "importpath": attr.string(), "importmap": attr.string(), - "embed": attr.label_list(providers = [GoLibrary]), + "embed": attr.label_list(providers = [GoInfo]), "gc_goopts": attr.string_list(), "x_defs": attr.string_dict(), "_go_config": attr.label(default = "//:go_config"), diff --git a/go/private/rules/nogo.bzl b/go/private/rules/nogo.bzl index 18f8e865e9..aa306feb94 100644 --- a/go/private/rules/nogo.bzl +++ b/go/private/rules/nogo.bzl @@ -19,12 +19,12 @@ load( load( "//go/private:context.bzl", "go_context", + "new_go_info", ) load( "//go/private:providers.bzl", "EXPORT_PATH", "GoArchive", - "GoLibrary", ) load( "//go/private/rules:transition.bzl", @@ -61,26 +61,23 @@ def _nogo_impl(ctx): ) # Compile the nogo binary itself. - nogo_library = GoLibrary( + nogo_info = new_go_info( + go, + struct( + embed = [ctx.attr._nogo_srcs], + deps = analyzer_archives, + ), + generated_srcs = [nogo_main], name = go.label.name + "~nogo", - label = go.label, importpath = "nogomain", - importmap = "nogomain", - importpath_aliases = (), pathtype = EXPORT_PATH, is_main = True, - resolve = None, + coverage_instrumented = False, ) - - nogo_source = go.library_to_source(go, struct( - srcs = [struct(files = [nogo_main])], - embed = [ctx.attr._nogo_srcs], - deps = analyzer_archives, - ), nogo_library, False) _, executable, runfiles = go.binary( go, name = ctx.label.name, - source = nogo_source, + source = nogo_info, ) return [DefaultInfo( files = depset([executable]), diff --git a/go/private/rules/source.bzl b/go/private/rules/source.bzl index a3d7ccdb69..cf438f0537 100644 --- a/go/private/rules/source.bzl +++ b/go/private/rules/source.bzl @@ -19,22 +19,21 @@ load( load( "//go/private:context.bzl", "go_context", + "new_go_info", ) load( "//go/private:providers.bzl", - "GoLibrary", + "GoInfo", ) def _go_source_impl(ctx): """Implements the go_source() rule.""" go = go_context(ctx, include_deprecated_properties = False) - library = go.new_library(go) - source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented()) + go_info = new_go_info(go, ctx.attr) return [ - library, - source, + go_info, DefaultInfo( - files = depset(source.srcs), + files = depset(go_info.srcs), ), ] @@ -58,17 +57,17 @@ go_source = rule( """, ), "deps": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], doc = """List of Go libraries this source list imports directly. - These may be go_library rules or compatible rules with the [GoLibrary] provider. + These may be go_library rules or compatible rules with the [GoInfo] provider. """, ), "embed": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], doc = """List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name `go_library`, - `go_proto_library`, or other compatible targets with the [GoLibrary] and - [GoSource] providers. Embedded libraries must have the same `importpath` as + `go_proto_library`, or other compatible targets with the [GoInfo] + provider. Embedded libraries must have the same `importpath` as the embedding library. At most one embedded library may have `cgo = True`, and the embedding library may not also have `cgo = True`. See [Embedding] for more information. @@ -88,8 +87,7 @@ go_source = rule( This is used as a way of easily declaring a common set of sources re-used in multiple rules.

**Providers:** """, ) diff --git a/go/private/rules/test.bzl b/go/private/rules/test.bzl index 32b110f8d8..4ae32b82f8 100644 --- a/go/private/rules/test.bzl +++ b/go/private/rules/test.bzl @@ -30,6 +30,7 @@ load( load( "//go/private:context.bzl", "go_context", + "new_go_info", ) load( "//go/private:mode.bzl", @@ -38,8 +39,7 @@ load( load( "//go/private:providers.bzl", "GoArchive", - "GoLibrary", - "GoSource", + "GoInfo", "INFERRED_PATH", ) load( @@ -71,29 +71,32 @@ def _go_test_impl(ctx): validation_outputs = [] # Compile the library to test with internal white box tests - internal_library = go.new_library(go, testfilter = "exclude") - internal_source = go.library_to_source(go, ctx.attr, internal_library, ctx.coverage_instrumented()) - internal_archive = go.archive(go, internal_source) + internal_go_info = new_go_info( + go, + ctx.attr, + testfilter = "exclude", + ) + internal_archive = go.archive(go, internal_go_info) if internal_archive.data._validation_output: validation_outputs.append(internal_archive.data._validation_output) - go_srcs = [src for src in internal_source.srcs if src.extension == "go"] + go_srcs = [src for src in internal_go_info.srcs if src.extension == "go"] # Compile the library with the external black box tests - external_library = go.new_library( + external_go_info = new_go_info( go, - name = internal_library.name + "_test", - importpath = internal_library.importpath + "_test", + struct( + srcs = [struct(files = go_srcs)], + data = ctx.attr.data, + embedsrcs = [struct(files = internal_go_info.embedsrcs)], + deps = internal_archive.direct + [internal_archive], + x_defs = ctx.attr.x_defs, + ), + name = internal_go_info.name + "_test", + importpath = internal_go_info.importpath + "_test", testfilter = "only", ) - external_source = go.library_to_source(go, struct( - srcs = [struct(files = go_srcs)], - data = ctx.attr.data, - embedsrcs = [struct(files = internal_source.embedsrcs)], - deps = internal_archive.direct + [internal_archive], - x_defs = ctx.attr.x_defs, - ), external_library, ctx.coverage_instrumented()) - external_source, internal_archive = _recompile_external_deps(go, external_source, internal_archive, [t.label for t in ctx.attr.embed]) - external_archive = go.archive(go, external_source, is_external_pkg = True) + external_go_info, internal_archive = _recompile_external_deps(go, external_go_info, internal_archive, [t.label for t in ctx.attr.embed]) + external_archive = go.archive(go, external_go_info, is_external_pkg = True) if external_archive.data._validation_output: validation_outputs.append(external_archive.data._validation_output) @@ -121,13 +124,13 @@ def _go_test_impl(ctx): # the l is the alias for the package under test, the l_test must be the # same with the test suffix "-import", - "l=" + internal_source.library.importpath, + "l=" + internal_go_info.importpath, ) arguments.add( "-import", - "l_test=" + external_source.library.importpath, + "l_test=" + external_go_info.importpath, ) - arguments.add("-pkgname", internal_source.library.importpath) + arguments.add("-pkgname", internal_go_info.importpath) arguments.add_all(go_srcs, before_each = "-src", format_each = "l=%s") ctx.actions.run( @@ -153,27 +156,25 @@ def _go_test_impl(ctx): test_gc_linkopts.extend(["-X", "+initfirst/github.com/bazelbuild/rules_go/go/tools/bzltestutil/chdir.RunDir=" + run_dir]) # Now compile the test binary itself - test_library = GoLibrary( + test_deps = external_archive.direct + [external_archive] + ctx.attr._testmain_additional_deps + if go.coverage_enabled: + test_deps.append(go.coverdata) + test_go_info = new_go_info( + go, + struct( + deps = test_deps, + ), name = go.label.name + "~testmain", - label = go.label, importpath = "testmain", - importmap = "testmain", - importpath_aliases = (), pathtype = INFERRED_PATH, is_main = True, - resolve = None, + generated_srcs = [main_go], + coverage_instrumented = False, ) - test_deps = external_archive.direct + [external_archive] + ctx.attr._testmain_additional_deps - if go.coverage_enabled: - test_deps.append(go.coverdata) - test_source = go.library_to_source(go, struct( - srcs = [struct(files = [main_go])], - deps = test_deps, - ), test_library, False) test_archive, executable, runfiles = go.binary( go, name = ctx.label.name, - source = test_source, + source = test_go_info, test_archives = [internal_archive.data], gc_linkopts = test_gc_linkopts, version_file = ctx.version_file, @@ -234,18 +235,18 @@ _go_test_kwargs = { """, ), "deps": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], doc = """List of Go libraries this test imports directly. - These may be go_library rules or compatible rules with the [GoLibrary] provider. + These may be go_library rules or compatible rules with the [GoInfo] provider. """, cfg = go_transition, ), "embed": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], doc = """List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name `go_library`, - `go_proto_library`, or other compatible targets with the [GoLibrary] and - [GoSource] providers. Embedded libraries must have the same `importpath` as + `go_proto_library`, or other compatible targets with the + [GoInfo] provider. Embedded libraries must have the same `importpath` as the embedding library. At most one embedded library may have `cgo = True`, and the embedding library may not also have `cgo = True`. See [Embedding] for more information. @@ -436,7 +437,7 @@ _go_test_kwargs = { ), "_go_context_data": attr.label(default = "//:go_context_data", cfg = go_transition), "_testmain_additional_deps": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], default = ["//go/tools/bzltestutil"], cfg = go_transition, ), @@ -497,7 +498,7 @@ _go_test_kwargs = { go_test = rule(**_go_test_kwargs) -def _recompile_external_deps(go, external_source, internal_archive, library_labels): +def _recompile_external_deps(go, external_go_info, internal_archive, library_labels): """Recompiles some archives in order to split internal and external tests. go_test, like 'go test', splits tests into two separate archives: an @@ -520,29 +521,29 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe Args: go: go object returned by go_context. - external_source: GoSource for the external archive. + external_go_info: GoInfo for the external archive. internal_archive: GoArchive for the internal archive. library_labels: labels for embedded libraries under test. Returns: - external_soruce: recompiled GoSource for the external archive. If no - recompilation is needed, the original GoSource is returned. + external_source: recompiled GoInfo for the external archive. If no + recompilation is needed, the original GoInfo is returned. internal_archive: recompiled GoArchive for the internal archive. If no - recompilation is needed, the original GoSource is returned. + recompilation is needed, the original GoInfo is returned. """ # If no libraries are embedded in the internal archive, then nothing needs # to be recompiled. if not library_labels: - return external_source, internal_archive + return external_go_info, internal_archive # Build a map from labels to GoArchiveData. # If none of the librares embedded in the internal archive are in the # dependency graph, then nothing needs to be recompiled. - arc_data_list = depset(transitive = [archive.transitive for archive in external_source.deps]).to_list() + arc_data_list = depset(transitive = [archive.transitive for archive in external_go_info.deps]).to_list() label_to_arc_data = {a.label: a for a in arc_data_list} if all([l not in label_to_arc_data for l in library_labels]): - return external_source, internal_archive + return external_go_info, internal_archive # Build a depth-first post-order list of dependencies starting with the # external archive. Each archive appears after its dependencies and before @@ -557,7 +558,7 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe dep_list = [] # stack is a stack of targets to process. We're done when it's empty. - stack = [archive.data.label for archive in external_source.deps] + stack = [archive.data.label for archive in external_go_info.deps] # deps_pushed tracks the status of each target. # DEPS_UNPROCESSED means the target is on the stack, but its dependencies @@ -629,27 +630,27 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe # recompilation. This breaks a cycle which occurs because the deps list # is shared between the internal and external archive. The internal archive # can't import anything that imports itself. - internal_source = internal_archive.source + internal_go_info = internal_archive.source internal_deps = [] # Pass internal dependencies that need to be recompiled down to the builder to check if the internal archive # tries to import any of the dependencies. If there is, that means that there is a dependency cycle. need_recompile_deps = [] - for archive in internal_source.deps: + for archive in internal_go_info.deps: dep_data = archive.data if not need_recompile[dep_data.label]: internal_deps.append(archive) else: need_recompile_deps.append(dep_data.importpath) - x_defs = dict(internal_source.x_defs) + x_defs = dict(internal_go_info.x_defs) x_defs.update(internal_archive.x_defs) - attrs = structs.to_dict(internal_source) + attrs = structs.to_dict(internal_go_info) attrs["deps"] = internal_deps attrs["x_defs"] = x_defs - internal_source = GoSource(**attrs) - internal_archive = go.archive(go, internal_source, _recompile_suffix = ".recompileinternal", recompile_internal_deps = need_recompile_deps) + internal_go_info = GoInfo(**attrs) + internal_archive = go.archive(go, internal_go_info, _recompile_suffix = ".recompileinternal", recompile_internal_deps = need_recompile_deps) # Build a map from labels to possibly recompiled GoArchives. label_to_archive = {} @@ -668,22 +669,18 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe label_to_archive[label] = internal_archive continue - # Create a stub GoLibrary and GoSource from the archive data. + # Create a stub GoInfo from the archive data. arc_data = label_to_arc_data[label] - library = GoLibrary( + deps = [label_to_archive[d] for d in arc_data._dep_labels] + go_info = GoInfo( name = arc_data.name, label = arc_data.label, importpath = arc_data.importpath, importmap = arc_data.importmap, importpath_aliases = arc_data.importpath_aliases, pathtype = arc_data.pathtype, - resolve = None, testfilter = None, is_main = False, - ) - deps = [label_to_archive[d] for d in arc_data._dep_labels] - source = GoSource( - library = library, mode = go.mode, srcs = as_list(arc_data.srcs), cover = arc_data._cover, @@ -704,24 +701,24 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe # Otherwise, create a stub GoArchive, using the original file. if need_recompile[label]: recompile_suffix = ".recompile%d" % i - archive = go.archive(go, source, _recompile_suffix = recompile_suffix) + archive = go.archive(go, go_info, _recompile_suffix = recompile_suffix) else: archive = GoArchive( - source = source, + source = go_info, data = arc_data, direct = deps, libs = depset(direct = [arc_data.file], transitive = [a.libs for a in deps]), transitive = depset(direct = [arc_data], transitive = [a.transitive for a in deps]), - x_defs = source.x_defs, + x_defs = go_info.x_defs, cgo_deps = depset(transitive = [arc_data._cgo_deps] + [a.cgo_deps for a in deps]), cgo_exports = depset(transitive = [a.cgo_exports for a in deps]), - runfiles = source.runfiles, + runfiles = go_info.runfiles, mode = go.mode, ) label_to_archive[label] = archive - # Finally, we need to replace external_source.deps with the recompiled + # Finally, we need to replace external_go_info.deps with the recompiled # archives. - attrs = structs.to_dict(external_source) - attrs["deps"] = [label_to_archive[archive.data.label] for archive in external_source.deps] - return GoSource(**attrs), internal_archive + attrs = structs.to_dict(external_go_info) + attrs["deps"] = [label_to_archive[archive.data.label] for archive in external_go_info.deps] + return GoInfo(**attrs), internal_archive diff --git a/go/private/rules/transition.bzl b/go/private/rules/transition.bzl index bd9f2d39ec..4358dfc6ee 100644 --- a/go/private/rules/transition.bzl +++ b/go/private/rules/transition.bzl @@ -29,8 +29,7 @@ load( load( "//go/private:providers.bzl", "GoArchive", - "GoLibrary", - "GoSource", + "GoInfo", ) # A list of rules_go settings that are possibly set by go_transition. @@ -278,7 +277,7 @@ go_stdlib_transition = transition( def _go_reset_target_impl(ctx): t = ctx.attr.dep[0] # [0] seems to be necessary with the transition - providers = [t[p] for p in [GoLibrary, GoSource, GoArchive] if p in t] + providers = [t[p] for p in [GoInfo, GoArchive] if p in t] # We can't pass DefaultInfo through as-is, since Bazel forbids executable # if it's a file declared in a different target. To emulate that, symlink diff --git a/go/providers.rst b/go/providers.rst index deb1adebdc..a4321b8506 100644 --- a/go/providers.rst +++ b/go/providers.rst @@ -13,8 +13,7 @@ Go providers .. _race detector: modes.rst#using-the-race-detector .. _runfiles: https://docs.bazel.build/versions/master/skylark/lib/runfiles.html .. _File: https://docs.bazel.build/versions/master/skylark/lib/File.html -.. _new_library: toolchains.rst#new_library -.. _library_to_source: toolchains.rst#library_to_source +.. _new_go_info: toolchains.rst#new_go_info .. _archive: toolchains.rst#archive .. role:: param(kbd) @@ -41,19 +40,19 @@ All the providers are designed to hold only immutable data. This is partly because its a cleaner design choice to be able to assume a provider will never change, but also because only immutable objects are allowed to be stored in a depset, and it's really useful to have depsets of providers. Specifically the -:param:`direct` and :param:`transitive` fields on GoLibrary_ only work because -it is immutable. +:param:`direct` and :param:`transitive` fields on GoArchive_ only work because +GoArchiveData_ is immutable. API --- -GoLibrary -~~~~~~~~~ +GoInfo +~~~~~~~~ -``GoLibrary`` contains metadata about an individual library. It is provided -by the `go_library`_ rule and other compatible rules. In general, you should -build ``GoLibrary`` with the `new_library`_ helper method. ``GoLibrary`` is -an input to the `library_to_source`_ helper method, which produces GoSource_. +GoInfo contains metadata about an individual library. +It takes into account mode-specific processing, ready to build +a GoArchive_. This is produced by calling the `new_go_info`_ helper +method. In general, only rules_go should need to build or handle these. +--------------------------------+-----------------------------------------------------------------+ | **Name** | **Type** | @@ -95,33 +94,13 @@ an input to the `library_to_source`_ helper method, which produces GoSource_. | not importable. This is the case for binaries and tests. The importpath | | may still be useful for `go_path`_ and other rules. | +--------------------------------+-----------------------------------------------------------------+ -| :param:`resolve` | :type:`function (optional)` | -+--------------------------------+-----------------------------------------------------------------+ -| A function called by `library_to_source`_ that can be used to resolve this | -| library to a mode-specific GoSource_. | -+--------------------------------+-----------------------------------------------------------------+ | :param:`is_main` | :type:`bool` | +--------------------------------+-----------------------------------------------------------------+ | Indicates whether the library should be compiled as a `main` package. | | `main` packages may have arbitrary `importpath` and `importmap` values, | | but the compiler and linker must see them as `main`. | +--------------------------------+-----------------------------------------------------------------+ - -GoSource -~~~~~~~~ - -GoSource represents a GoLibrary_ after mode-specific processing, ready to build -a GoArchive_. This is produced by calling the `library_to_source`_ helper -method. In general, only rules_go should need to build or handle these. - -+--------------------------------+-----------------------------------------------------------------+ -| **Name** | **Type** | -+--------------------------------+-----------------------------------------------------------------+ -| :param:`library` | :type:`GoLibrary` | -+--------------------------------+-----------------------------------------------------------------+ -| The go library that this GoSource was generated from. | -+--------------------------------+-----------------------------------------------------------------+ -| :param:`mode` | :type:`GoConfigInfo` | +| :param:`mode` | :type:`Mode` | +--------------------------------+-----------------------------------------------------------------+ | The mode this library is being built for. | +--------------------------------+-----------------------------------------------------------------+ @@ -276,7 +255,7 @@ which is available through the :param:`data` field. +--------------------------------+-----------------------------------------------------------------+ | **Name** | **Type** | +--------------------------------+-----------------------------------------------------------------+ -| :param:`source` | :type:`GoSource` | +| :param:`source` | :type:`GoInfo` | +--------------------------------+-----------------------------------------------------------------+ | The source provider this GoArchive was compiled from. | +--------------------------------+-----------------------------------------------------------------+ @@ -306,7 +285,7 @@ which is available through the :param:`data` field. | The direct cgo dependencies of this library. | | This has the same constraints as things that can appear in the deps of a cc_library_. | +--------------------------------+-----------------------------------------------------------------+ -| :param:`cgo_exports` | :type:`depset of GoSource` | +| :param:`cgo_exports` | :type:`depset of GoInfo` | +--------------------------------+-----------------------------------------------------------------+ | The transitive set of c headers needed to reference exports of this archive. | +--------------------------------+-----------------------------------------------------------------+ diff --git a/go/toolchains.rst b/go/toolchains.rst index 71aeef1752..ae8df77189 100644 --- a/go/toolchains.rst +++ b/go/toolchains.rst @@ -5,9 +5,8 @@ Go toolchains .. _Bazel toolchains: https://docs.bazel.build/versions/master/toolchains.html .. _Go website: https://golang.org/ .. _GoArchive: providers.rst#goarchive -.. _GoLibrary: providers.rst#golibrary .. _GoSDK: providers.rst#gosdk -.. _GoSource: providers.rst#gosource +.. _GoInfo: providers.rst#gosource .. _binary distribution: https://golang.org/dl/ .. _compilation modes: modes.rst#compilation-modes .. _control the version: `Forcing the Go version`_ @@ -649,9 +648,9 @@ It returns a GoArchive_. +--------------------------------+-----------------------------+-----------------------------------+ | This must be the same GoContext object you got this function from. | +--------------------------------+-----------------------------+-----------------------------------+ -| :param:`source` | :type:`GoSource` | |mandatory| | +| :param:`source` | :type:`GoInfo` | |mandatory| | +--------------------------------+-----------------------------+-----------------------------------+ -| The GoSource_ that should be compiled into an archive. | +| The GoInfo_ that should be compiled into an archive. | +--------------------------------+-----------------------------+-----------------------------------+ @@ -675,9 +674,9 @@ a ``runfiles`` object. +--------------------------------+-----------------------------+-----------------------------------+ | The base name of the generated binaries. Required if :param:`executable` is not given. | +--------------------------------+-----------------------------+-----------------------------------+ -| :param:`source` | :type:`GoSource` | |mandatory| | +| :param:`source` | :type:`GoInfo` | |mandatory| | +--------------------------------+-----------------------------+-----------------------------------+ -| The GoSource_ that should be compiled and linked. | +| The GoInfo_ that should be compiled and linked. | +--------------------------------+-----------------------------+-----------------------------------+ | :param:`test_archives` | :type:`list GoArchiveData` | :value:`[]` | +--------------------------------+-----------------------------+-----------------------------------+ @@ -787,18 +786,17 @@ current build mode to make the filename unique between configurations. | If this is not set, the current rule name is used in it's place. | +--------------------------------+-----------------------------+-----------------------------------+ -library_to_source +new_go_info +++++++++++++++++ -This is used to build a GoSource object for a given GoLibrary in the current -build mode. +This is used to build a GoInfo object in the current build mode. +--------------------------------+-----------------------------+-----------------------------------+ | **Name** | **Type** | **Default value** | +--------------------------------+-----------------------------+-----------------------------------+ | :param:`go` | :type:`GoContext` | |mandatory| | +--------------------------------+-----------------------------+-----------------------------------+ -| This must be the same GoContext object you got this function from. | +| The GoContext object for this target. | +--------------------------------+-----------------------------+-----------------------------------+ | :param:`attr` | :type:`ctx.attr` | |mandatory| | +--------------------------------+-----------------------------+-----------------------------------+ @@ -815,33 +813,18 @@ build mode. | As an exception, ``deps``, if present, must be a list containing either | | ``Targets`` or ``GoArchives``. | +--------------------------------+-----------------------------+-----------------------------------+ -| :param:`library` | :type:`GoLibrary` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| The GoLibrary_ that you want to build a GoSource_ object for in the current build mode. | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`coverage_instrumented` | :type:`bool` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| This controls whether cover is enabled for this specific library in this mode. | -| This should generally be the value of ctx.coverage_instrumented() | -+--------------------------------+-----------------------------+-----------------------------------+ - -new_library -+++++++++++ - -This creates a new GoLibrary. You can add extra fields to the go library by -providing extra named parameters to this function, they will be visible to the -resolver when it is invoked. - -+--------------------------------+-----------------------------+-----------------------------------+ -| **Name** | **Type** | **Default value** | -+--------------------------------+-----------------------------+-----------------------------------+ -| :param:`go` | :type:`GoContext` | |mandatory| | -+--------------------------------+-----------------------------+-----------------------------------+ -| This must be the same GoContext object you got this function from. | +| :param:`name` | :type:`string` | ++--------------------------------+-----------------------------------------------------------------+ +| The name of the library. Usually, this is the ``name`` attribute. | ++--------------------------------+-----------------------------------------------------------------+ +| :param:`importpath` | :type:`string` | ++--------------------------------+-----------------------------------------------------------------+ +| The string used in ``import`` declarations in Go source code to import | +| this library. Usually, this is the ``importpath`` attribute. | +--------------------------------+-----------------------------+-----------------------------------+ | :param:`resolver` | :type:`function` | :value:`None` | +--------------------------------+-----------------------------+-----------------------------------+ -| This is the function that gets invoked when converting from a GoLibrary to a GoSource. | +| This is the function that gets invoked when building the GoInfo. | | The function's signature must be | | | | .. code:: bzl | @@ -849,11 +832,43 @@ resolver when it is invoked. | def _stdlib_library_to_source(go, attr, source, merge) | | | | attr is the attributes of the rule being processed | -| source is the dictionary of GoSource fields being generated | +| source is the dictionary of GoInfo fields being generated | | merge is a helper you can call to merge | +--------------------------------+-----------------------------+-----------------------------------+ -| :param:`importable` | :type:`bool` | |mandatory| | +| :param:`importable` | :type:`bool` | |False| | +--------------------------------+-----------------------------+-----------------------------------+ -| This controls whether the GoLibrary_ is supposed to be importable. This is generally only false | +| This controls whether the GoInfo_ is supposed to be importable. This is generally only false | | for the "main" libraries that are built just before linking. | +--------------------------------+-----------------------------+-----------------------------------+ +| :param:`testfilter` | :type:`string` | |None| | ++--------------------------------+-----------------------------+-----------------------------------+ +| :param:`is_main` | :type:`bool` | ++--------------------------------+-----------------------------------------------------------------+ +| Indicates whether the library should be compiled as a `main` package. | +| `main` packages may have arbitrary `importpath` and `importmap` values, | +| but the compiler and linker must see them as `main`. | ++--------------------------------+-----------------------------+-----------------------------------+ +| :param:`coverage_instrumented` | :type:`bool` | |None| | ++--------------------------------+-----------------------------+-----------------------------------+ +| This controls whether cover is enabled for this specific library in this mode. | +| If ommitted, it falls back to ctx.coverage_instrumented() | ++--------------------------------+-----------------------------+-----------------------------------+ +| :param:`generated_srcs` | :type:`List[file]` | |None| | ++--------------------------------+-----------------------------+-----------------------------------+ +| :param:`pathtype` | :type:`string` | ++--------------------------------+-----------------------------------------------------------------+ +| Information about the source of the importpath. Possible values are: | +| | +| :value:`explicit` | +| The importpath was explicitly supplied by the user and the library is importable. | +| This is the normal case. | +| :value:`inferred` | +| The importpath was inferred from the directory structure and rule name. The library may be | +| importable. | +| This is normally true for rules that do not expect to be compiled directly to a library, | +| embeded into another rule instead (source generators) | +| :value:`export` | +| The importpath was explicitly supplied by the user, but the library is | +| not importable. This is the case for binaries and tests. The importpath | +| may still be useful for `go_path`_ and other rules. | ++--------------------------------+-----------------------------+-----------------------------------+ diff --git a/proto/compiler.bzl b/proto/compiler.bzl index aaf7d6fd65..dca3535d20 100644 --- a/proto/compiler.bzl +++ b/proto/compiler.bzl @@ -22,7 +22,7 @@ load( ) load( "//go:def.bzl", - "GoLibrary", + "GoInfo", "go_context", ) load( @@ -30,6 +30,10 @@ load( "GO_TOOLCHAIN", "GO_TOOLCHAIN_LABEL", ) +load( + "//go/private:context.bzl", + "new_go_info", +) load( "//go/private/rules:transition.bzl", "go_reset_target", @@ -59,7 +63,7 @@ the import path of the Go library being generated. The function should declare output .go files and actions to generate them. It should return a list of .go Files to be compiled by the Go compiler. """, - "deps": """List of targets providing GoLibrary, GoSource, and GoArchive. + "deps": """List of targets providing GoInfo and GoArchive. These are added as implicit dependencies for any go_proto_library using this compiler. Typically, these are Well Known Types and proto runtime libraries.""", "valid_archive": """A Boolean indicating whether the .go files produced @@ -183,8 +187,7 @@ def proto_path(src, proto): def _go_proto_compiler_impl(ctx): go = go_context(ctx, include_deprecated_properties = False) - library = go.new_library(go) - source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented()) + go_info = new_go_info(go, ctx.attr) proto_toolchain = proto_toolchains.find_toolchain( ctx, legacy_attr = "_legacy_proto_toolchain", @@ -205,14 +208,13 @@ def _go_proto_compiler_impl(ctx): import_path_option = ctx.attr.import_path_option, ), ), - library, - source, + go_info, ] _go_proto_compiler = rule( implementation = _go_proto_compiler_impl, attrs = dict({ - "deps": attr.label_list(providers = [GoLibrary]), + "deps": attr.label_list(providers = [GoInfo]), "options": attr.string_list(), "suffix": attr.string(default = ".pb.go"), "suffixes": attr.string_list(), diff --git a/proto/core.rst b/proto/core.rst index 6f37fb36fb..ed7519a853 100644 --- a/proto/core.rst +++ b/proto/core.rst @@ -5,8 +5,7 @@ Go Protocol buffers .. _default Go plugin: https://github.com/golang/protobuf .. _common plugins: #predefined-plugins .. _Go providers: /go/providers.rst -.. _GoLibrary: /go/providers.rst#golibrary -.. _GoSource: /go/providers.rst#gosource +.. _GoInfo: /go/providers.rst#gosource .. _GoArchive: /go/providers.rst#goarchive .. _Gazelle: https://github.com/bazelbuild/bazel-gazelle .. _Make variable substitution: https://docs.bazel.build/versions/master/be/make-variables.html#make-var-substitution @@ -160,8 +159,7 @@ files. ``go_proto_library`` can be imported like any ``go_library`` rule. Providers ^^^^^^^^^ -* GoLibrary_ -* GoSource_ +* GoInfo_ * GoArchive_ Attributes @@ -371,8 +369,7 @@ Providers ^^^^^^^^^ * GoProtoCompiler_ -* GoLibrary_ -* GoSource_ +* GoInfo_ Attributes ^^^^^^^^^^ @@ -387,7 +384,7 @@ Attributes | :param:`deps` | :type:`label_list` | :value:`[]` | +-----------------------------+----------------------+-----------------------------------------------------+ | List of Go libraries that Go code *generated by* this compiler depends on | -| implicitly. Rules in this list must produce the `GoLibrary`_ provider. This | +| implicitly. Rules in this list must produce the `GoInfo`_ provider. This | | should contain libraries for the Well Known Types at least. | +-----------------------------+----------------------+-----------------------------------------------------+ | :param:`options` | :type:`string_list` | :value:`[]` | @@ -443,7 +440,7 @@ Providers Providers are objects produced by Bazel rules and consumed by other rules that depend on them. See `Go providers`_ for information about Go providers, -specifically GoLibrary_, GoSource_, and GoArchive_. +specifically GoInfo_, and GoArchive_. GoProtoCompiler ~~~~~~~~~~~~~~~ @@ -467,7 +464,7 @@ added to pass information to the ``compile`` function. This interface is +-----------------------------+-------------------------------------------------+ | A list of Go libraries to be added as dependencies to any | | ``go_proto_library`` compiled with this compiler. Each target must provide | -| GoLibrary_, GoSource_, and GoArchive_. This list should include libraries | +| GoInfo_ and GoArchive_. This list should include libraries | | for the Well Known Types and anything else considered "standard". | +-----------------------------+-------------------------------------------------+ | :param:`compile` | :type:`Function` | diff --git a/proto/def.bzl b/proto/def.bzl index 0964c842ee..702e019f77 100644 --- a/proto/def.bzl +++ b/proto/def.bzl @@ -22,14 +22,17 @@ load( ) load( "//go:def.bzl", - "GoLibrary", - "GoSource", + "GoInfo", "go_context", ) load( "//go/private:common.bzl", "GO_TOOLCHAIN", ) +load( + "//go/private:context.bzl", + "new_go_info", +) load( "//go/private/rules:transition.bzl", "non_go_tool_transition", @@ -94,8 +97,8 @@ def _proto_library_to_source(_go, attr, source, merge): else: compilers = attr.compilers for compiler in compilers: - if GoSource in compiler: - merge(source, compiler[GoSource]) + if GoInfo in compiler: + merge(source, compiler[GoInfo]) def _go_proto_library_impl(ctx): go = go_context( @@ -139,18 +142,20 @@ def _go_proto_library_impl(ctx): imports = get_imports(ctx.attr, go.importpath), importpath = go.importpath, )) - library = go.new_library( + + go_info = new_go_info( go, + ctx.attr, resolver = _proto_library_to_source, - srcs = go_srcs, + generated_srcs = go_srcs, + coverage_instrumented = False, ) - source = go.library_to_source(go, ctx.attr, library, False, verify_resolver_deps = False) - providers = [library, source] + providers = [go_info] output_groups = { "go_generated_srcs": go_srcs, } if valid_archive: - archive = go.archive(go, source) + archive = go.archive(go, go_info) output_groups["compilation_outputs"] = [archive.data.file] providers.extend([ archive, @@ -174,13 +179,13 @@ go_proto_library = rule( default = [], ), "deps": attr.label_list( - providers = [GoLibrary], + providers = [GoInfo], aspects = [_go_proto_aspect], ), "importpath": attr.string(), "importmap": attr.string(), "importpath_aliases": attr.string_list(), # experimental, undocumented - "embed": attr.label_list(providers = [GoLibrary]), + "embed": attr.label_list(providers = [GoInfo]), "gc_goopts": attr.string_list(), "compiler": attr.label(providers = [GoProtoCompiler]), "compilers": attr.label_list( diff --git a/tests/core/go_binary/many_deps.bzl b/tests/core/go_binary/many_deps.bzl index 621e286d31..827be2ebcf 100644 --- a/tests/core/go_binary/many_deps.bzl +++ b/tests/core/go_binary/many_deps.bzl @@ -17,6 +17,10 @@ load( "go_binary", "go_context", ) +load( + "//go/private:context.bzl", + "new_go_info", +) _PREFIX = "/".join(["abcdefgh"[i] * 100 for i in range(7)]) + "/" @@ -24,12 +28,11 @@ def _gen_library_impl(ctx): go = go_context(ctx) src = go.actions.declare_file(ctx.label.name + ".go") go.actions.write(src, "package " + ctx.label.name + "\n") - library = go.new_library(go, srcs = [src]) - source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented()) - archive = go.archive(go, source) + + go_info = new_go_info(go, ctx.attr, generated_srcs = [src]) + archive = go.archive(go, go_info) return [ - library, - source, + go_info, archive, DefaultInfo(files = depset([archive.data.file])), ] diff --git a/tests/core/go_path/pkg/lib/generated_embeded.bzl b/tests/core/go_path/pkg/lib/generated_embeded.bzl index 42bcf595a7..3e81f0374f 100644 --- a/tests/core/go_path/pkg/lib/generated_embeded.bzl +++ b/tests/core/go_path/pkg/lib/generated_embeded.bzl @@ -16,6 +16,10 @@ load( "@io_bazel_rules_go//go:def.bzl", "go_context", ) +load( + "//go/private:context.bzl", + "new_go_info", +) def _gen_library_impl(ctx): go = go_context(ctx) @@ -42,12 +46,10 @@ def _gen_library_impl(ctx): ctx.actions.write(src, "\n".join(lines)) - library = go.new_library(go, srcs = [src]) - source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented()) - archive = go.archive(go, source) + go_info = new_go_info(go, ctx.attr, generated_srcs = [src]) + archive = go.archive(go, go_info) return [ - library, - source, + go_info, archive, DefaultInfo(files = depset([archive.data.file])), ] diff --git a/tests/core/go_proto_library/README.rst b/tests/core/go_proto_library/README.rst index 7696102a7a..d72969801b 100644 --- a/tests/core/go_proto_library/README.rst +++ b/tests/core/go_proto_library/README.rst @@ -14,7 +14,7 @@ Tests to ensure the basic features of `go_proto_library`_ are working. embed_test ---------- -Checks that `go_proto_library`_ can embed rules that provide `GoLibrary`_. +Checks that `go_proto_library`_ can embed rules that provide `GoInfo`_. transitive_test --------------- diff --git a/tests/extras/gomock/README.rst b/tests/extras/gomock/README.rst index b59af8ad2e..75e094749e 100644 --- a/tests/extras/gomock/README.rst +++ b/tests/extras/gomock/README.rst @@ -1,15 +1,15 @@ -gomock + ===================== Tests that ensure the gomock rules can be called correctly under different input permutations. reflective ------------------------ -Checks that gomock can be run in "reflective" mode when passed a `GoLibrary` and `interfaces`. +Checks that gomock can be run in "reflective" mode when passed a `GoInfo` and `interfaces`. source ------------------------ -Checks that gomock can be run in "source" mode when passed a `GoLibrary` and `source`. +Checks that gomock can be run in "source" mode when passed a `GoInfo` and `source`. source_with_importpath ------------------------ diff --git a/tests/legacy/providers/test.bzl b/tests/legacy/providers/test.bzl index a82ba5f501..0cbd4093df 100644 --- a/tests/legacy/providers/test.bzl +++ b/tests/legacy/providers/test.bzl @@ -1,4 +1,4 @@ -load("//go:def.bzl", "GoLibrary") +load("//go:def.bzl", "GoInfo") def _test_impl(ctx): pass @@ -8,7 +8,7 @@ test_source = rule( attrs = { "srcs": attr.label( mandatory = True, - providers = [GoLibrary], + providers = [GoInfo], ), }, )