Skip to content

Commit 8243f56

Browse files
committed
Merge GoLibrary and GoSource providers
1 parent 520bee5 commit 8243f56

27 files changed

+387
-366
lines changed

docs/go/core/rules.bzl

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
[Bourne shell tokenization]: https://docs.bazel.build/versions/master/be/common-definitions.html#sh-tokenization
44
[Gazelle]: https://github.com/bazelbuild/bazel-gazelle
55
[GoArchive]: /go/providers.rst#GoArchive
6-
[GoLibrary]: /go/providers.rst#GoLibrary
76
[GoPath]: /go/providers.rst#GoPath
8-
[GoSource]: /go/providers.rst#GoSource
7+
[GoInfo]: /go/providers.rst#GoInfo
98
[build constraints]: https://golang.org/pkg/go/build/#hdr-Build_Constraints
109
[cc_library deps]: https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library.deps
1110
[cgo]: http://golang.org/cmd/cgo/
@@ -50,9 +49,8 @@ sufficient to match the capabilities of the normal go tools.
5049
- [Bourne shell tokenization]
5150
- [Gazelle]
5251
- [GoArchive]
53-
- [GoLibrary]
5452
- [GoPath]
55-
- [GoSource]
53+
- [GoInfo]
5654
- [build constraints]:
5755
- [cc_library deps]
5856
- [cgo]

docs/go/core/rules.md

+12-20
Large diffs are not rendered by default.

extras/gomock.bzl

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
load("@bazel_skylib//lib:paths.bzl", "paths")
2626
load("//go/private:common.bzl", "GO_TOOLCHAIN", "GO_TOOLCHAIN_LABEL")
2727
load("//go/private:context.bzl", "go_context")
28-
load("//go/private:providers.bzl", "GoLibrary")
28+
load("//go/private:providers.bzl", "GoInfo")
2929
load("//go/private/rules:wrappers.bzl", go_binary = "go_binary_macro")
3030

3131
_MOCKGEN_TOOL = Label("//extras/gomock:mockgen")
@@ -36,10 +36,10 @@ def _gomock_source_impl(ctx):
3636

3737
# In Source mode, it's not necessary to pass through a library, as the only thing we use it for is setting up
3838
# the relative file locations. Forcing users to pass a library makes it difficult in the case where a mock should
39-
# be included as part of that same library, as it results in a dependency loop (GoMock -> GoLibrary -> GoMock).
39+
# be included as part of that same library, as it results in a dependency loop (GoMock -> GoInfo -> GoMock).
4040
# Allowing users to pass an importpath directly bypasses this issue.
4141
# See the test case in //tests/extras/gomock/source_with_importpath for an example.
42-
importpath = ctx.attr.source_importpath if ctx.attr.source_importpath else ctx.attr.library[GoLibrary].importmap
42+
importpath = ctx.attr.source_importpath if ctx.attr.source_importpath else ctx.attr.library[GoInfo].importmap
4343

4444
# create GOPATH and copy source into GOPATH
4545
go_path_prefix = "gopath"
@@ -113,7 +113,7 @@ _gomock_source = rule(
113113
attrs = {
114114
"library": attr.label(
115115
doc = "The target the Go library where this source file belongs",
116-
providers = [GoLibrary],
116+
providers = [GoInfo],
117117
mandatory = False,
118118
),
119119
"source_importpath": attr.string(
@@ -250,7 +250,7 @@ def _gomock_reflect(name, library, out, mockgen_tool, **kwargs):
250250

251251
def _gomock_prog_gen_impl(ctx):
252252
args = ["-prog_only"]
253-
args.append(ctx.attr.library[GoLibrary].importpath)
253+
args.append(ctx.attr.library[GoInfo].importpath)
254254
args.append(",".join(ctx.attr.interfaces))
255255

256256
cmd = ctx.file.mockgen_tool
@@ -273,7 +273,7 @@ _gomock_prog_gen = rule(
273273
attrs = {
274274
"library": attr.label(
275275
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.",
276-
providers = [GoLibrary],
276+
providers = [GoInfo],
277277
mandatory = True,
278278
),
279279
"out": attr.output(
@@ -306,7 +306,7 @@ def _gomock_prog_exec_impl(ctx):
306306

307307
# annoyingly, the interfaces join has to go after the importpath so we can't
308308
# share those.
309-
args.append(ctx.attr.library[GoLibrary].importpath)
309+
args.append(ctx.attr.library[GoInfo].importpath)
310310
args.append(",".join(ctx.attr.interfaces))
311311

312312
ctx.actions.run_shell(
@@ -330,7 +330,7 @@ _gomock_prog_exec = rule(
330330
attrs = {
331331
"library": attr.label(
332332
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.",
333-
providers = [GoLibrary],
333+
providers = [GoInfo],
334334
mandatory = True,
335335
),
336336
"out": attr.output(

go/core.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ Core Go rules
55
.. _Bourne shell tokenization: https://docs.bazel.build/versions/master/be/common-definitions.html#sh-tokenization
66
.. _Gazelle: https://github.com/bazelbuild/bazel-gazelle
77
.. _GoArchive: providers.rst#GoArchive
8-
.. _GoLibrary: providers.rst#GoLibrary
98
.. _GoPath: providers.rst#GoPath
10-
.. _GoSource: providers.rst#GoSource
9+
.. _GoInfo: providers.rst#GoInfo
1110
.. _build constraints: https://golang.org/pkg/go/build/#hdr-Build_Constraints
1211
.. _cc_library deps: https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library.deps
1312
.. _cgo: http://golang.org/cmd/cgo/

go/def.bzl

+10-6
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ load(
3838
"//go/private:providers.bzl",
3939
_GoArchive = "GoArchive",
4040
_GoArchiveData = "GoArchiveData",
41-
_GoLibrary = "GoLibrary",
41+
_GoInfo = "GoInfo",
4242
_GoPath = "GoPath",
4343
_GoSDK = "GoSDK",
44-
_GoSource = "GoSource",
4544
)
4645
load(
4746
"//go/private/rules:cross.bzl",
@@ -130,11 +129,16 @@ go_tool_library = _go_tool_library
130129
go_toolchain = _go_toolchain
131130
nogo = _nogo
132131

133-
# See go/providers.rst#GoLibrary for full documentation.
134-
GoLibrary = _GoLibrary
132+
# This provider is deprecated and will be removed in a future release.
133+
# Use GoInfo instead.
134+
GoLibrary = _GoInfo
135135

136-
# See go/providers.rst#GoSource for full documentation.
137-
GoSource = _GoSource
136+
# This provider is deprecated and will be removed in a future release.
137+
# Use GoInfo instead.
138+
GoSource = _GoInfo
139+
140+
# See go/providers.rst#GoInfo for full documentation.
141+
GoInfo = _GoInfo
138142

139143
# See go/providers.rst#GoPath for full documentation.
140144
GoPath = _GoPath

go/nogo.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
.. _go_library: /docs/go/core/rules.md#go_library
99
.. _analysis: https://godoc.org/golang.org/x/tools/go/analysis
1010
.. _Analyzer: https://godoc.org/golang.org/x/tools/go/analysis#Analyzer
11-
.. _GoLibrary: providers.rst#GoLibrary
12-
.. _GoSource: providers.rst#GoSource
11+
.. _GoInfo: providers.rst#GoInfo
1312
.. _GoArchive: providers.rst#GoArchive
1413
.. _vet: https://golang.org/cmd/vet/
1514
.. _golangci-lint: https://github.com/golangci/golangci-lint

go/private/actions/archive.bzl

+15-17
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
4747
if source == None:
4848
fail("source is a required parameter")
4949

50-
testfilter = getattr(source.library, "testfilter", None)
50+
testfilter = getattr(source, "testfilter", None)
5151
pre_ext = ""
5252
if go.mode.link == LINKMODE_C_ARCHIVE:
5353
pre_ext = "_" # avoid collision with go_binary output file with .a extension
@@ -57,17 +57,17 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
5757
pre_ext = ".external"
5858
if _recompile_suffix:
5959
pre_ext += _recompile_suffix
60-
out_lib = go.declare_file(go, name = source.library.name, ext = pre_ext + ".a")
60+
out_lib = go.declare_file(go, name = source.name, ext = pre_ext + ".a")
6161

6262
# store export information for compiling dependent packages separately
63-
out_export = go.declare_file(go, name = source.library.name, ext = pre_ext + ".x")
63+
out_export = go.declare_file(go, name = source.name, ext = pre_ext + ".x")
6464
out_cgo_export_h = None # set if cgo used in c-shared or c-archive mode
6565

6666
nogo = get_nogo(go)
6767
if nogo:
68-
out_facts = go.declare_file(go, name = source.library.name, ext = pre_ext + ".facts")
69-
out_nogo_log = go.declare_file(go, name = source.library.name, ext = pre_ext + ".nogo.log")
70-
out_nogo_validation = go.declare_file(go, name = source.library.name, ext = pre_ext + ".nogo")
68+
out_facts = go.declare_file(go, name = source.name, ext = pre_ext + ".facts")
69+
out_nogo_log = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo.log")
70+
out_nogo_validation = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo")
7171
else:
7272
out_facts = None
7373
out_nogo_log = None
@@ -82,8 +82,8 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
8282
fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode)))
8383
runfiles = source.runfiles.merge_all(files)
8484

85-
importmap = "main" if source.library.is_main else source.library.importmap
86-
importpath, _ = effective_importpath_pkgpath(source.library)
85+
importmap = "main" if source.is_main else source.importmap
86+
importpath, _ = effective_importpath_pkgpath(source)
8787

8888
if source.cgo and not go.mode.pure:
8989
# TODO(jayconrod): do we need to do full Bourne tokenization here?
@@ -161,15 +161,13 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
161161
# may be mutable. For now, new copied fields are private (named with
162162
# a leading underscore) since they may change in the future.
163163

164-
# GoLibrary fields
165-
name = source.library.name,
166-
label = source.library.label,
167-
importpath = source.library.importpath,
168-
importmap = source.library.importmap,
169-
importpath_aliases = source.library.importpath_aliases,
170-
pathtype = source.library.pathtype,
171-
172-
# GoSource fields
164+
# GoInfo fields
165+
name = source.name,
166+
label = source.label,
167+
importpath = source.importpath,
168+
importmap = source.importmap,
169+
importpath_aliases = source.importpath_aliases,
170+
pathtype = source.pathtype,
173171
srcs = as_tuple(source.srcs),
174172
_cover = source.cover,
175173
_embedsrcs = as_tuple(source.embedsrcs),

go/private/actions/stdlib.bzl

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ load(
1818
"GO_TOOLCHAIN_LABEL",
1919
"SUPPORTS_PATH_MAPPING_REQUIREMENT",
2020
)
21+
load(
22+
"//go/private:context.bzl",
23+
"new_go_info",
24+
)
2125
load(
2226
"//go/private:mode.bzl",
2327
"LINKMODE_NORMAL",
@@ -38,12 +42,11 @@ def emit_stdlib(go):
3842
Otherwise, the standard library will be compiled for the target.
3943
4044
Returns:
41-
A list of providers containing GoLibrary, GoSource and GoStdLib.
45+
A list of providers containing GoInfo and GoStdLib.
4246
"""
43-
library = go.new_library(go)
44-
source = go.library_to_source(go, {}, library, False)
47+
go_info = new_go_info(go, {}, coverage_instrumented = False)
4548
stdlib = _sdk_stdlib(go) if _should_use_sdk_stdlib(go) else _build_stdlib(go)
46-
return [source, library, stdlib]
49+
return [go_info, stdlib]
4750

4851
def _should_use_sdk_stdlib(go):
4952
version = parse_version(go.sdk.version)

0 commit comments

Comments
 (0)