Skip to content

gopackagesdriver: Missing packages from targets that have dependencies outside of "deps" #4473

@r-hang

Description

@r-hang

When using the Bazel gopackagesdriver to analyze a rules_go project it's
possible to run into missing packages errors that look like

/home/user/go/bazel-pkgdrv/execroot/__main__/bazel-out/
k8-fastbuild/example.go:8:7: could not import example.org/mock (missing package: "@//src/example.org/mock:go_default_library")

The root cause is that the gopackagesdriver aspect only traverses
target's deps field to populate the package information in the
driver registry. In cases where a target depends on another target
that is not declared in the "deps" field this packages will be missing
from the gopackagesdriver response.

ref: https://github.com/bazel-contrib/rules_go/blob/master/go/tools/gopackagesdriver/aspect.bzl#L30

An example of this edge case is on-the-fly generated go code produced
by a bazel rule where the bazel rule provides a static dependency in
the rule implementation instead of relying soley on the deps attribute.
In this situation, this package is still required for the package
analysis to complete but it is missing from the gopackagesdriver
response.

A solution is to provide a additional labels field that the gopackages driver will
always add to the packages registry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions