bazelbuild / bazelbuild/rules_license

Native Java provider appears when using REPO.bazel

Open
#158 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
85
Forks
37
PR merge metrics
No merged PRs in 30d

Description

@fmeum (https://github.com/bazelbuild/bazel-gazelle/pull/1852) and I (https://github.com/bazelbuild/bazel-gazelle/pull/1917) have been trying to make the bazel-gazelle `go_repository` PackageInfo functional.

bazel-gazelle generates a target `@some-go-package//:gazelle_generated_package_info` for each package installed, you can observe this working with `cquery` for example:

```
% bazel cquery --output=starlark --starlark:expr='providers(target)["@@rules_license//rules:providers.bzl%PackageInfo"]' @com_github_spf13_cobra//:gazelle_generated_package_info
INFO: Analyzed target @@com_github_spf13_cobra//:gazelle_generated_package_info (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
struct(label = Label("@@com_github_spf13_cobra//:gazelle_generated_package_info"), package_name = "github.com/spf13/cobra", package_url = "https://github.com/spf13/cobra", package_version = "1.8.1", type = "package_info")
struct(label = Label("@@com_github_spf13_cobra//:gazelle_generated_package_info"), package_name = "github.com/spf13/cobra", package_url = "https://github.com/spf13/cobra", package_version = "1.8.1", type = "package_info")
```

This package info isn't attached directly to `go_library` targets. Rather it uses the (new?) `repo()` function in the `REPO.bazel` for that external repo (after all, every target there is licensed the same way)

https://github.com/bazelbuild/bazel-gazelle/blob/089096315dcaa0aea52e87ecc2bd6b89b531da1e/internal/go_repository.bzl#L369-L371

However when we `cquery` on a `go_library` target that may be reachable through the dep graph from a Go application:

The only relevant provider hanging from that `go_library` is `LicenseInfo`:

```shell
% bazel cquery --output=starlark --starlark:expr='providers(target).keys()' @com_github_spf13_cobra//:cobra
[
"LicenseInfo",
"@@io_bazel_rules_go//go/private:providers.bzl%GoLibrary",
"@@io_bazel_rules_go//go/private:providers.bzl%GoSource",
"@@io_bazel_rules_go//go/private:providers.bzl%GoArchive",
"InstrumentedFilesInfo",
"FileProvider",
"FilesToRunProvider",
"OutputGroupInfo"
]
```

```
% bazel cquery --output=starlark --starlark:expr='providers(target)["LicenseInfo"]' @com_github_spf13_cobra//:cobra
INFO: Analyzed target @@com_github_spf13_cobra//:cobra (0 packages loaded, 0 targets configured).
INFO: Found 1 target...

```

LicenseInfo here is the one built-into [Bazel's Java code](https://github.com/bazelbuild/bazel/blob/63c887b339499c5178f9535f821a3256134e1c08/src/main/java/com/google/devtools/build/lib/analysis/LicensesProvider.java), not the one [declared in rules_license](https://github.com/bazelbuild/rules_license/blob/5b980eaa19dec16c85d8ec5e58c16257c8738ea3/rules/providers.bzl#L36).

Does this mean the `go_repository` implementation needs to attach the PackageInfo to each `go_library` as well?

Contributor guide

Open the contributing guide

Research direction

Start with internal/go_repository.bzl at the linked repo() implementation and compare the PackageInfo target with the providers exposed by a generated go_library. Reproduce the cquery provider listings shown in the issue, then establish whether the expected rules_license PackageInfo should be visible on each go_library and what existing validation covers that behavior.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.