bazel-contrib / bazel-contrib/rules_go

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

Open
#4,473 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start with go/tools/gopackagesdriver/aspect.bzl around line 30 and trace how the aspect traverses deps and populates the driver registry. Reproduce the missing-package case with a target whose dependency is supplied outside deps, then determine how the proposed additional labels field should be represented. Done means the gopackagesdriver response includes those packages for package analysis.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.