Skip to content

Commit 623fc60

Browse files
author
Jay Conrod
authored
doc: improve documentation for go.library_to_source attr param (bazel-contrib#2665)
attr["deps"] may be a list of either Targets or GoArchive. Fixes bazel-contrib#1784
1 parent f3ccea6 commit 623fc60

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

go/private/context.bzl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,18 @@ def _merge_embed(source, embed):
187187
source["cgo_exports"] = source["cgo_exports"] + s.cgo_exports
188188

189189
def _dedup_deps(deps):
190-
"""Returns a list of targets without duplicate import paths.
190+
"""Returns a list of deps without duplicate import paths.
191191
192192
Earlier targets take precedence over later targets. This is intended to
193193
allow an embedding library to override the dependencies of its
194194
embedded libraries.
195+
196+
Args:
197+
deps: an iterable containing either Targets or GoArchives.
195198
"""
196199
deduped_deps = []
197200
importpaths = {}
198201
for dep in deps:
199-
# TODO(#1784): we allow deps to be a list of GoArchive since go_test and
200-
# nogo work this way. We should force deps to be a list of Targets.
201202
if hasattr(dep, "data") and hasattr(dep.data, "importpath"):
202203
importpath = dep.data.importpath
203204
else:

go/toolchains.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,18 @@ build mode.
879879
+--------------------------------+-----------------------------+-----------------------------------+
880880
| :param:`attr` | :type:`ctx.attr` | |mandatory| |
881881
+--------------------------------+-----------------------------+-----------------------------------+
882-
| The attributes of the rule being processed. In a normal rule implementation this would be |
883-
| ctx.attr. |
882+
| The attributes of the target being analyzed. For most rules, this should be |
883+
| ``ctx.attr``. Rules can also pass in a ``struct`` with the same fields. |
884+
| |
885+
| ``library_to_source`` looks for fields corresponding to the attributes of |
886+
| ``go_library`` and ``go_binary``. This includes ``srcs``, ``deps``, ``embed``, |
887+
| and so on. All fields are optional (and may not be defined in the struct |
888+
| argument at all), but if they are present, they must have the same types and |
889+
| allowed values as in ``go_library`` and ``go_binary``. For example, ``srcs`` |
890+
| must be a list of ``Targets``; ``gc_goopts`` must be a list of strings. |
891+
| |
892+
| As an exception, ``deps``, if present, must be a list containing either |
893+
| ``Targets`` or ``GoArchives``. |
884894
+--------------------------------+-----------------------------+-----------------------------------+
885895
| :param:`library` | :type:`GoLibrary` | |mandatory| |
886896
+--------------------------------+-----------------------------+-----------------------------------+

0 commit comments

Comments
 (0)