Skip to content

More machine readable output for bazel mod show_repo #21617

@wisechengyi

Description

@wisechengyi

Description of the feature request:

bazel mod show_repo does not the --output json or other.

$ bazel mod show_repo --base_module=gazelle @com_github_bazelbuild_buildtools --output json
go_repository(
  name = "gazelle~0.34.0~go_deps~com_github_bazelbuild_buildtools",
  importpath = "github.com/bazelbuild/buildtools",
  version = "v0.0.0-20231017121127-23aa65d4e117",
  sum = "h1:VUHCI4QRifAGYsbVJYqJndLf7YqV12YthB+PLFsEKqo=",
  replace = "",
  build_file_generation = "on",
  build_extra_args = [],
  build_directives = ["gazelle:build_file_name BUILD.bazel", "gazelle:build_file_proto_mode disable_global", "gazelle:proto disable"],
  patches = [],
  patch_args = [],
)

as compared to the non-bzlmod mode, we can do something as below to achieve our goal (this example can be found in https://github.com/wisechengyi/scoot)

% bazel query //external:bazel_gazelle --output xml
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<query version="2">
    <rule class="http_archive" location="/Users/yi/workspace/goplay/WORKSPACE:12:13" name="//external:bazel_gazelle">
        <string name="name" value="bazel_gazelle"/>
        <list name="urls">
            <string value="https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz"/>
            <string value="https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz"/>
        </list>
        <string name="sha256" value="ecba0f04f96b4960a5b250c8e8eeec42281035970aa8852dda73098274d14a1d"/>
    </rule>
</query>

Which category does this issue belong to?

External Dependency

What underlying problem are you trying to solve with this feature?

  1. We need to export a large go repo (single go.mod) into repo with multiple go.mod, the goal is that external non-monorepo can import code from the go monorepo so they don’t have to import the whole monorepo. this is done via analyzing bazel build graph including the 3rdparty info (importpath, version, sum)

  2. our deployment needs to audit on 3rdparty dependencies. it used to be case with native go toolchain, it can inspect the 3rdparty dependencies info just by looking at the binary itself, but with bazel, all that is stripped out, so we need to use bazel query related logics to tell the deployment system.

Which operating system are you running Bazel on?

linux and mac

What is the output of bazel info release?

release 6.4.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

slack discussion: https://bazelbuild.slack.com/archives/C014RARENH0/p1709760640102069

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2We'll consider working on this in future. (Assignee optional)area-BzlmodBzlmod-specific PRs, issues, and feature requeststeam-ExternalDepsExternal dependency handling, remote repositiories, WORKSPACE file.type: feature request

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions