Skip to content

Commit f1685ce

Browse files
committed
Use depset for SDK files
1 parent 64759ee commit f1685ce

File tree

13 files changed

+64
-75
lines changed

13 files changed

+64
-75
lines changed

extras/gomock.bzl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,14 @@ def _gomock_source_impl(ctx):
7373
needed_files.append(aux)
7474
args += ["-aux_files", ",".join(aux_files)]
7575

76-
inputs = (
77-
needed_files +
78-
go_ctx.sdk.headers + go_ctx.sdk.srcs + go_ctx.sdk.tools
79-
) + [source]
76+
inputs_direct = needed_files + [source]
77+
inputs_transitive = [go_ctx.sdk.tools, go_ctx.sdk.headers, go_ctx.sdk.srcs]
8078

8179
# We can use the go binary from the stdlib for most of the environment
8280
# variables, but our GOPATH is specific to the library target we were given.
8381
ctx.actions.run_shell(
8482
outputs = [ctx.outputs.out],
85-
inputs = inputs,
83+
inputs = depset(inputs_direct, transitive = inputs_transitive),
8684
tools = [
8785
ctx.file.mockgen_tool,
8886
go_ctx.go,

go/private/actions/compilepkg.bzl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ def emit_compilepkg(
8888
if bool(nogo) != bool(out_nogo_validation):
8989
fail("nogo must be specified if and only if out_nogo_validation is specified")
9090

91-
inputs = (sources + embedsrcs + [go.package_list] +
92-
[archive.data.export_file for archive in archives] +
93-
go.sdk.tools + go.sdk.headers + go.stdlib.libs)
91+
sdk = go.sdk
92+
inputs_direct = (sources + embedsrcs + [sdk.package_list] +
93+
[archive.data.export_file for archive in archives])
94+
inputs_transitive = [sdk.headers, sdk.tools, go.stdlib.libs]
9495
outputs = [out_lib, out_export]
9596

9697
args = go.builder_args(go, "compilepkg", use_path_mapping = True)
@@ -114,7 +115,7 @@ def emit_compilepkg(
114115
cover_archive = None
115116
if cover and go.coverdata:
116117
cover_archive = go.coverdata
117-
inputs.append(cover_archive.data.export_file)
118+
inputs_direct.append(cover_archive.data.export_file)
118119
args.add("-arc", _archive(cover_archive))
119120
if go.mode.race:
120121
cover_mode = "atomic"
@@ -172,8 +173,8 @@ def emit_compilepkg(
172173
cgo_go_srcs_for_nogo = go.declare_directory(go, path = out_lib.basename + ".cgo")
173174
outputs.append(cgo_go_srcs_for_nogo)
174175
args.add("-cgo_go_srcs", cgo_go_srcs_for_nogo.path)
175-
inputs.extend(cgo_inputs.to_list()) # OPT: don't expand depset
176-
inputs.extend(go.cc_toolchain_files)
176+
inputs_transitive.append(cgo_inputs)
177+
inputs_transitive.append(go.cc_toolchain_files)
177178
env["CC"] = go.cgo_tools.c_compiler_path
178179
if cppopts:
179180
args.add("-cppflags", quote_opts(cppopts))
@@ -190,10 +191,10 @@ def emit_compilepkg(
190191

191192
if go.mode.pgoprofile:
192193
args.add("-pgoprofile", go.mode.pgoprofile)
193-
inputs.append(go.mode.pgoprofile)
194+
inputs_direct.append(go.mode.pgoprofile)
194195

195196
go.actions.run(
196-
inputs = inputs,
197+
inputs = depset(inputs_direct, transitive = inputs_transitive),
197198
outputs = outputs,
198199
mnemonic = "GoCompilePkgExternal" if is_external_pkg else "GoCompilePkg",
199200
executable = go.toolchain._builder,
@@ -234,16 +235,16 @@ def _run_nogo(
234235
out_validation,
235236
nogo):
236237
"""Runs nogo on Go source files, including those generated by cgo."""
237-
inputs = (sources + [nogo, go.package_list] +
238-
[archive.data.facts_file for archive in archives if archive.data.facts_file] +
239-
[archive.data.export_file for archive in archives] +
240-
go.sdk.tools + go.sdk.headers + go.stdlib.libs)
238+
inputs_direct = (sources + [nogo, go.package_list] +
239+
[archive.data.facts_file for archive in archives if archive.data.facts_file] +
240+
[archive.data.export_file for archive in archives])
241+
inputs_transitive = [go.sdk.tools, go.sdk.headers, go.stdlib.libs]
241242
outputs = [out_facts, out_log]
242243

243244
args = go.builder_args(go, "nogo", use_path_mapping = True)
244245
args.add_all(sources, before_each = "-src")
245246
if cgo_go_srcs:
246-
inputs.append(cgo_go_srcs)
247+
inputs_direct.append(cgo_go_srcs)
247248
args.add_all([cgo_go_srcs], before_each = "-src")
248249
if cover_mode:
249250
args.add("-cover_mode", cover_mode)
@@ -271,7 +272,7 @@ def _run_nogo(
271272
# analyzers with --sandbox_debug. Users can set debug = True on the nogo target to have it fail
272273
# on findings to get the same debugging experience as with other failures.
273274
go.actions.run(
274-
inputs = inputs,
275+
inputs = depset(inputs_direct, transitive = inputs_transitive),
275276
outputs = outputs,
276277
mnemonic = "RunNogo",
277278
executable = go.toolchain._builder,

go/private/actions/link.bzl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ load(
1919
load(
2020
"//go/private:common.bzl",
2121
"GO_TOOLCHAIN_LABEL",
22-
"as_set",
2322
"count_group_matches",
2423
"has_shared_lib_extension",
2524
)
@@ -201,9 +200,9 @@ def emit_link(
201200
inputs_transitive = [
202201
archive.libs,
203202
archive.cgo_deps,
204-
as_set(go.cc_toolchain_files),
205-
as_set(go.sdk.tools),
206-
as_set(go.stdlib.libs),
203+
go.cc_toolchain_files,
204+
go.sdk.tools,
205+
go.stdlib.libs,
207206
]
208207
inputs = depset(direct = inputs_direct, transitive = inputs_transitive)
209208

go/private/actions/stdlib.bzl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _should_use_sdk_stdlib(go):
5656
if version and version[0] <= 1 and version[1] <= 19 and go.sdk.experiments:
5757
# The precompiled stdlib shipped with 1.19 or below doesn't have experiments
5858
return False
59-
return (go.sdk.libs and # go.sdk.libs is non-empty if sdk ships with precompiled .a files
59+
return (go.sdk.libs.to_list() and # go.sdk.libs is non-empty if sdk ships with precompiled .a files
6060
go.mode.goos == go.sdk.goos and
6161
go.mode.goarch == go.sdk.goarch and
6262
not go.mode.race and # TODO(jayconrod): use precompiled race
@@ -66,19 +66,22 @@ def _should_use_sdk_stdlib(go):
6666
go.mode.link == LINKMODE_NORMAL)
6767

6868
def _build_stdlib_list_json(go):
69+
sdk = go.sdk
70+
6971
out = go.declare_file(go, "stdlib.pkg.json")
7072
cache_dir = go.declare_directory(go, "gocache")
7173
args = go.builder_args(go, "stdliblist")
72-
args.add("-sdk", go.sdk.root_file.dirname)
74+
args.add("-sdk", sdk.root_file.dirname)
7375
args.add("-out", out)
7476
args.add("-cache", cache_dir.path)
7577

76-
inputs = go.sdk_files
78+
inputs_direct = [sdk.go]
79+
inputs_transitive = [sdk.headers, sdk.srcs, sdk.libs, sdk.tools]
7780
if not go.mode.pure:
78-
inputs += go.cc_toolchain_files
81+
inputs_transitive.append(go.cc_toolchain_files)
7982

8083
go.actions.run(
81-
inputs = inputs,
84+
inputs = depset(inputs_direct, transitive = inputs_transitive),
8285
outputs = [out, cache_dir],
8386
mnemonic = "GoStdlibList",
8487
executable = go.toolchain._builder,
@@ -140,19 +143,17 @@ def _build_stdlib(go):
140143

141144
args.add("-gcflags", quote_opts(go.mode.gc_goopts))
142145

143-
inputs = (go.sdk.srcs +
144-
go.sdk.headers +
145-
go.sdk.tools +
146-
[go.sdk.go, go.sdk.package_list, go.sdk.root_file] +
147-
go.cc_toolchain_files)
146+
sdk = go.sdk
147+
inputs_direct = [sdk.go, sdk.package_list, sdk.root_file]
148+
inputs_transitive = [sdk.headers, sdk.srcs, sdk.tools, go.cc_toolchain_files]
148149

149150
if go.mode.pgoprofile:
150151
args.add("-pgoprofile", go.mode.pgoprofile)
151-
inputs.append(go.mode.pgoprofile)
152+
inputs_direct.append(go.mode.pgoprofile)
152153

153154
outputs = [pkg]
154155
go.actions.run(
155-
inputs = inputs,
156+
inputs = depset(direct = inputs_direct, transitive = inputs_transitive),
156157
outputs = outputs,
157158
mnemonic = "GoStdlib",
158159
executable = go.toolchain._builder,
@@ -163,6 +164,6 @@ def _build_stdlib(go):
163164
)
164165
return GoStdLib(
165166
_list_json = _build_stdlib_list_json(go),
166-
libs = [pkg],
167+
libs = depset([pkg]),
167168
root_file = pkg,
168169
)

go/private/common.bzl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,6 @@ def as_tuple(v):
210210
return tuple(v.to_list())
211211
fail("as_tuple failed on {}".format(v))
212212

213-
def as_set(v):
214-
"""Returns a list, tuple, or depset as a depset."""
215-
if type(v) == "depset":
216-
return v
217-
if type(v) == "list":
218-
return depset(v)
219-
if type(v) == "tuple":
220-
return depset(v)
221-
fail("as_tuple failed on {}".format(v))
222-
223213
_STRUCT_TYPE = type(struct())
224214

225215
def is_struct(v):

go/private/context.bzl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def go_context(ctx, attr = None):
523523
env["GOARM"] = mode.arm
524524

525525
if not cgo_context_info:
526-
cc_toolchain_files = []
526+
cc_toolchain_files = depset()
527527
cgo_tools = None
528528
else:
529529
env.update(cgo_context_info.env)
@@ -558,14 +558,6 @@ def go_context(ctx, attr = None):
558558
paths.append("/usr/bin")
559559
env["PATH"] = ctx.configuration.host_path_separator.join(paths)
560560

561-
# TODO(jayconrod): remove this. It's way too broad. Everything should
562-
# depend on more specific lists.
563-
sdk_files = ([toolchain.sdk.go] +
564-
toolchain.sdk.srcs +
565-
toolchain.sdk.headers +
566-
toolchain.sdk.libs +
567-
toolchain.sdk.tools)
568-
569561
_check_importpaths(ctx)
570562
importpath, importmap, pathtype = _infer_importpath(ctx, attr)
571563
importpath_aliases = tuple(getattr(attr, "importpath_aliases", ()))
@@ -579,7 +571,6 @@ def go_context(ctx, attr = None):
579571
go = binary,
580572
stdlib = stdlib,
581573
sdk_root = toolchain.sdk.root_file,
582-
sdk_files = sdk_files,
583574
sdk_tools = toolchain.sdk.tools,
584575
actions = ctx.actions,
585576
exe_extension = goos_to_extension(mode.goos),
@@ -846,7 +837,7 @@ def _cgo_context_data_impl(ctx):
846837
)
847838

848839
return [CgoContextInfo(
849-
cc_toolchain_files = cc_toolchain.all_files.to_list(),
840+
cc_toolchain_files = cc_toolchain.all_files,
850841
tags = tags,
851842
env = env,
852843
cgo_tools = struct(

go/private/providers.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ GoSDK = provider(
4343
"goarch": "The host architecture the SDK was built for.",
4444
"experiments": "Go experiments to enable via GOEXPERIMENT.",
4545
"root_file": "A file in the SDK root directory",
46-
"libs": ("List of pre-compiled .a files for the standard library " +
46+
"libs": ("Depset of pre-compiled .a files for the standard library " +
4747
"built for the execution platform."),
48-
"headers": ("List of .h files from pkg/include that may be included " +
48+
"headers": ("Depset of .h files from pkg/include that may be included " +
4949
"in assembly sources."),
50-
"srcs": ("List of source files for importable packages in the " +
50+
"srcs": ("Depset of source files for importable packages in the " +
5151
"standard library. Internal, vendored, and tool packages " +
5252
"may not be included."),
5353
"package_list": ("A file containing a list of importable packages " +
5454
"in the standard library."),
55-
"tools": ("List of executable files in the SDK built for " +
55+
"tools": ("Depset of executable files in the SDK built for " +
5656
"the execution platform, excluding the go binary file"),
5757
"go": "The go binary file",
5858
"version": "The Go SDK version",

go/private/rules/binary.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,10 @@ exit /b %GO_EXIT_CODE%
465465
)
466466
ctx.actions.run(
467467
executable = bat,
468-
inputs = sdk.headers + sdk.tools + sdk.srcs + ctx.files.srcs + [sdk.go],
468+
inputs = depset(
469+
ctx.files.srcs + [sdk.go],
470+
transitive = [sdk.headers, sdk.srcs, sdk.tools],
471+
),
469472
outputs = [out, gotmp],
470473
mnemonic = "GoToolchainBinaryBuild",
471474
)
@@ -479,7 +482,10 @@ exit /b %GO_EXIT_CODE%
479482
)
480483
ctx.actions.run_shell(
481484
command = cmd,
482-
inputs = sdk.headers + sdk.tools + sdk.srcs + sdk.libs + ctx.files.srcs + [sdk.go],
485+
inputs = depset(
486+
ctx.files.srcs + [sdk.go],
487+
transitive = [sdk.headers, sdk.srcs, sdk.libs, sdk.tools],
488+
),
483489
outputs = [out],
484490
mnemonic = "GoToolchainBinaryBuild",
485491
)

go/private/rules/go_bin_for_host.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def _go_bin_for_host_impl(ctx):
3131
_ensure_target_cfg(ctx)
3232

3333
sdk = ctx.toolchains[GO_TOOLCHAIN].sdk
34-
sdk_files = ctx.runfiles([sdk.go] + sdk.headers + sdk.libs + sdk.srcs + sdk.tools)
34+
sdk_files = ctx.runfiles(
35+
[sdk.go],
36+
transitive_files = depset(transitive = [sdk.headers, sdk.srcs, sdk.libs, sdk.tools]),
37+
)
3538

3639
return [
3740
DefaultInfo(

go/private/rules/info.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _go_info_impl(ctx):
2727
args = go.builder_args(go)
2828
args.add("-out", report)
2929
go.actions.run(
30-
inputs = go.sdk_files,
30+
inputs = depset([go.sdk.go], transitive = [go.sdk.tools]),
3131
outputs = [report],
3232
mnemonic = "GoInfo",
3333
executable = ctx.executable._go_info,

go/private/rules/sdk.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def _go_sdk_impl(ctx):
2828
experiments = ctx.attr.experiments,
2929
root_file = ctx.file.root_file,
3030
package_list = package_list,
31-
libs = ctx.files.libs,
32-
headers = ctx.files.headers,
33-
srcs = ctx.files.srcs,
34-
tools = ctx.files.tools,
31+
libs = depset(ctx.files.libs),
32+
headers = depset(ctx.files.headers),
33+
srcs = depset(ctx.files.srcs),
34+
tools = depset(ctx.files.tools),
3535
go = ctx.executable.go,
3636
version = ctx.attr.version,
3737
)]

go/providers.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,16 @@ GoSDK
397397
+--------------------------------+-----------------------------------------------------------------+
398398
| A file in the SDK root directory. Used to determine ``GOROOT``. |
399399
+--------------------------------+-----------------------------------------------------------------+
400-
| :param:`libs` | :type:`list of File` |
400+
| :param:`libs` | :type:`depset of File` |
401401
+--------------------------------+-----------------------------------------------------------------+
402402
| Pre-compiled .a files for the standard library, built for the |
403403
| execution platform. |
404404
+--------------------------------+-----------------------------------------------------------------+
405-
| :param:`headers` | :type:`list of File` |
405+
| :param:`headers` | :type:`depset of File` |
406406
+--------------------------------+-----------------------------------------------------------------+
407407
| .h files from pkg/include that may be included in assembly sources. |
408408
+--------------------------------+-----------------------------------------------------------------+
409-
| :param:`srcs` | :type:`list of File` |
409+
| :param:`srcs` | :type:`depset of File` |
410410
+--------------------------------+-----------------------------------------------------------------+
411411
| Source files for importable packages in the standard library. |
412412
| Internal, vendored, and tool packages might not be included. |
@@ -415,7 +415,7 @@ GoSDK
415415
+--------------------------------+-----------------------------------------------------------------+
416416
| A file containing a list of importable packages in the standard library. |
417417
+--------------------------------+-----------------------------------------------------------------+
418-
| :param:`tools` | :type:`list of File` |
418+
| :param:`tools` | :type:`depset of File` |
419419
+--------------------------------+-----------------------------------------------------------------+
420420
| Executable files from pkg/tool built for the execution platform. |
421421
+--------------------------------+-----------------------------------------------------------------+

tests/core/stdlib/stdlib_files.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def _stdlib_files_impl(ctx):
2828
# ctx.attr._stdlib is a list of Target.
2929
stdlib = ctx.attr._stdlib[0][GoStdLib]
3030
libs = stdlib.libs
31-
runfiles = ctx.runfiles(files = libs)
31+
runfiles = ctx.runfiles(transitive_files = libs)
3232
return [DefaultInfo(
33-
files = depset(libs + [stdlib._list_json]),
33+
files = depset([stdlib._list_json], transitive = [libs]),
3434
runfiles = runfiles,
3535
)]
3636

0 commit comments

Comments
 (0)