Skip to content

Commit 23ba9db

Browse files
committed
Cleanup GoArchiveData runfiles handling
1 parent dfbf8b1 commit 23ba9db

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

go/private/actions/archive.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
6969
out_nogo_validation = go.declare_file(go, name = source.library.name, ext = pre_ext + ".nogo")
7070

7171
direct = [get_archive(dep) for dep in source.deps]
72-
runfiles = source.runfiles
73-
data_files = runfiles.files
7472

7573
files = []
7674
for a in direct:
7775
files.append(a.runfiles)
7876
if a.source.mode != go.mode:
7977
fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode)))
80-
runfiles = runfiles.merge_all(files)
78+
runfiles = source.runfiles.merge_all(files)
8179

8280
importmap = "main" if source.library.is_main else source.library.importmap
8381
importpath, _ = effective_importpath_pkgpath(source.library)
@@ -190,7 +188,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
190188
file = out_lib,
191189
export_file = out_export,
192190
facts_file = out_facts,
193-
data_files = as_tuple(data_files),
191+
runfiles = source.runfiles,
194192
_validation_output = out_nogo_validation,
195193
_cgo_deps = as_tuple(cgo_deps),
196194
)

go/private/rules/test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe
680680
x_defs = dict(arc_data._x_defs),
681681
deps = deps,
682682
gc_goopts = as_list(arc_data._gc_goopts),
683-
runfiles = go._ctx.runfiles(files = arc_data.data_files),
683+
runfiles = arc_data.runfiles,
684684
cgo = arc_data._cgo,
685685
cdeps = as_list(arc_data._cdeps),
686686
cppopts = as_list(arc_data._cppopts),

go/private/tools/path.bzl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ def _go_path_impl(ctx):
5858
importpath = importpath,
5959
dir = "src/" + pkgpath,
6060
srcs = as_list(archive.orig_srcs),
61-
data = as_list(archive.data_files),
61+
runfiles = archive.runfiles,
6262
embedsrcs = as_list(archive._embedsrcs),
6363
pkgs = {mode: archive.file},
6464
)
6565
if pkgpath in pkg_map:
66-
_merge_pkg(pkg_map[pkgpath], pkg)
67-
else:
68-
pkg_map[pkgpath] = pkg
66+
pkg = _merge_pkg(pkg_map[pkgpath], pkg)
67+
pkg_map[pkgpath] = pkg
6968

7069
# Build a manifest file that includes all files to copy/link/zip.
7170
inputs = []
@@ -95,7 +94,7 @@ def _go_path_impl(ctx):
9594
_add_manifest_entry(manifest_entries, manifest_entry_map, inputs, f, dst)
9695
if ctx.attr.include_data:
9796
for pkg in pkg_map.values():
98-
for f in pkg.data:
97+
for f in pkg.runfiles.files.to_list():
9998
parts = f.path.split("/")
10099
if "testdata" in parts:
101100
i = parts.index("testdata")
@@ -261,12 +260,16 @@ go_path = rule(
261260

262261
def _merge_pkg(x, y):
263262
x_srcs = {f.path: None for f in x.srcs}
264-
x_data = {f.path: None for f in x.data}
265263
x_embedsrcs = {f.path: None for f in x.embedsrcs}
266-
x.srcs.extend([f for f in y.srcs if f.path not in x_srcs])
267-
x.data.extend([f for f in y.data if f.path not in x_data])
268-
x.embedsrcs.extend([f for f in y.embedsrcs if f.path not in x_embedsrcs])
269-
x.pkgs.update(y.pkgs)
264+
265+
return struct(
266+
importpath = x.importpath,
267+
dir = x.dir,
268+
srcs = x.srcs + [f for f in y.srcs if f.path not in x_srcs],
269+
runfiles = x.runfiles.merge(y.runfiles),
270+
embedsrcs = x.embedsrcs + [f for f in y.embedsrcs if f.path not in x_embedsrcs],
271+
pkgs = x.pkgs | y.pkgs,
272+
)
270273

271274
def _add_manifest_entry(entries, entry_map, inputs, src, dst):
272275
if dst in entry_map:

go/providers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ rule. Instead, it's referenced in the ``data`` field of GoArchive_.
279279
+--------------------------------+-----------------------------------------------------------------+
280280
| The unmodified sources provided to the rule, including .go, .s, .h, .c files. |
281281
+--------------------------------+-----------------------------------------------------------------+
282-
| :param:`data_files` | :type:`tuple of File` |
282+
| :param:`runfiles` | :type:`runfiles` |
283283
+--------------------------------+-----------------------------------------------------------------+
284284
| Data files that should be available at runtime to binaries and tests built |
285285
| from this archive. |

0 commit comments

Comments
 (0)