diff --git a/go/private/actions/archive.bzl b/go/private/actions/archive.bzl index 54c20bf3e..c218c8400 100644 --- a/go/private/actions/archive.bzl +++ b/go/private/actions/archive.bzl @@ -69,15 +69,13 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d out_nogo_validation = go.declare_file(go, name = source.library.name, ext = pre_ext + ".nogo") direct = [get_archive(dep) for dep in source.deps] - runfiles = source.runfiles - data_files = runfiles.files files = [] for a in direct: files.append(a.runfiles) if a.source.mode != go.mode: fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode))) - runfiles = runfiles.merge_all(files) + runfiles = source.runfiles.merge_all(files) importmap = "main" if source.library.is_main else source.library.importmap importpath, _ = effective_importpath_pkgpath(source.library) @@ -189,7 +187,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d file = out_lib, export_file = out_export, facts_file = out_facts, - data_files = as_tuple(data_files), + runfiles = source.runfiles, _validation_output = out_nogo_validation, _cgo_deps = as_tuple(cgo_deps), ) diff --git a/go/private/rules/test.bzl b/go/private/rules/test.bzl index ed4c3ddba..ab3cf2eb6 100644 --- a/go/private/rules/test.bzl +++ b/go/private/rules/test.bzl @@ -679,7 +679,7 @@ def _recompile_external_deps(go, external_source, internal_archive, library_labe x_defs = dict(arc_data._x_defs), deps = deps, gc_goopts = as_list(arc_data._gc_goopts), - runfiles = go._ctx.runfiles(files = arc_data.data_files), + runfiles = arc_data.runfiles, cgo = arc_data._cgo, cdeps = as_list(arc_data._cdeps), cppopts = as_list(arc_data._cppopts), diff --git a/go/private/tools/path.bzl b/go/private/tools/path.bzl index e3b1ed8c2..84f888bf3 100644 --- a/go/private/tools/path.bzl +++ b/go/private/tools/path.bzl @@ -58,14 +58,13 @@ def _go_path_impl(ctx): importpath = importpath, dir = "src/" + pkgpath, srcs = as_list(archive.orig_srcs), - data = as_list(archive.data_files), + runfiles = archive.runfiles, embedsrcs = as_list(archive._embedsrcs), pkgs = {mode: archive.file}, ) if pkgpath in pkg_map: - _merge_pkg(pkg_map[pkgpath], pkg) - else: - pkg_map[pkgpath] = pkg + pkg = _merge_pkg(pkg_map[pkgpath], pkg) + pkg_map[pkgpath] = pkg # Build a manifest file that includes all files to copy/link/zip. inputs = [] @@ -95,7 +94,7 @@ def _go_path_impl(ctx): _add_manifest_entry(manifest_entries, manifest_entry_map, inputs, f, dst) if ctx.attr.include_data: for pkg in pkg_map.values(): - for f in pkg.data: + for f in pkg.runfiles.files.to_list(): parts = f.path.split("/") if "testdata" in parts: i = parts.index("testdata") @@ -261,12 +260,21 @@ go_path = rule( def _merge_pkg(x, y): x_srcs = {f.path: None for f in x.srcs} - x_data = {f.path: None for f in x.data} x_embedsrcs = {f.path: None for f in x.embedsrcs} - x.srcs.extend([f for f in y.srcs if f.path not in x_srcs]) - x.data.extend([f for f in y.data if f.path not in x_data]) - x.embedsrcs.extend([f for f in y.embedsrcs if f.path not in x_embedsrcs]) - x.pkgs.update(y.pkgs) + + # Not all bazel versions support `dict1 | dict2` yet. + pkgs = dict() + pkgs.update(x.pkgs) + pkgs.update(y.pkgs) + + return struct( + importpath = x.importpath, + dir = x.dir, + srcs = x.srcs + [f for f in y.srcs if f.path not in x_srcs], + runfiles = x.runfiles.merge(y.runfiles), + embedsrcs = x.embedsrcs + [f for f in y.embedsrcs if f.path not in x_embedsrcs], + pkgs = pkgs, + ) def _add_manifest_entry(entries, entry_map, inputs, src, dst): if dst in entry_map: diff --git a/go/providers.rst b/go/providers.rst index df88137a9..dad79cd42 100644 --- a/go/providers.rst +++ b/go/providers.rst @@ -274,7 +274,7 @@ rule. Instead, it's referenced in the ``data`` field of GoArchive_. +--------------------------------+-----------------------------------------------------------------+ | The unmodified sources provided to the rule, including .go, .s, .h, .c files. | +--------------------------------+-----------------------------------------------------------------+ -| :param:`data_files` | :type:`tuple of File` | +| :param:`runfiles` | :type:`runfiles` | +--------------------------------+-----------------------------------------------------------------+ | Data files that should be available at runtime to binaries and tests built | | from this archive. |