bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.13k stars 4.05k forks source link

`override_repo` does not suggest using repo name for module override #23981

Closed luispadron closed 5 days ago

luispadron commented 6 days ago

Description of the bug:

I have a dependency on a Bazel module swift-syntax, for reasons we override this module using archive_override:

SWIFT_SYNTAX_VERSION = "510.0.3"

bazel_dep(
    name = "swift-syntax",
    version = SWIFT_SYNTAX_VERSION,
    repo_name = "SwiftSyntax",
)

archive_override(
    module_name = "swift-syntax",
    integrity = "sha256-8HShak9S6SPqhVyHqV89Jnz37KdNa907iyPnSuWfpys=",
    strip_prefix = "swift-syntax-%s" % SWIFT_SYNTAX_VERSION,
    urls = [
        "https://github.com/square/swift-syntax-prebuilt/releases/download/{version}/swift-syntax-{version}.tar.gz".format(
            version = SWIFT_SYNTAX_VERSION,
        ),
    ],
)

I use another Bazel module rules_swift_package_manager which provides a module extension swift_deps that provides Bazel repositories for use within the build. This swift_deps extension proxy generates a repository named swiftpkg_swift_syntax.

swift_deps = use_extension(
    "@rules_swift_package_manager//:extensions.bzl",
    "swift_deps",
)
swift_deps.from_package(
    declare_swift_deps_info = True,
    resolved = "Package.resolved",
    swift = "Package.swift",
)
use_repo(
    swift_deps,
    "swift_deps_info",
    "swiftpkg_swift_syntax",
)

I'd like to replace the swiftpkg_swift_syntax repository with my override swift-syntax repository, I use the new override_repo feature in Bazel 7.4+:

override_repo(
    swift_deps,
    swiftpkg_swift_syntax = "swift-syntax",
)

I get the following error:

bazel build //...

Starting local Bazel server and connecting to it...
ERROR: /Users/lpadron/Desktop/override_repo_example/MODULE.bazel:87:14: Traceback (most recent call last):
        File "/Users/lpadron/Desktop/override_repo_example/MODULE.bazel", line 87, column 14, in <toplevel>
                override_repo(
Error in override_repo: The repo exported as 'swiftpkg_swift_syntax' by module extension 'swift_deps' is overridden with 'swift-syntax', but no repo is visible under this name
ERROR: Error computing the main repository mapping: error executing MODULE.bazel file for the root module

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

bazel build //... on the attached zip.

override_repo_example.zip

Which operating system are you running Bazel on?

macOS 14.6.1

What is the output of bazel info release?

release 7.4.0rc1
fmeum commented 6 days ago

Could you try this?

override_repo(
    swift_deps,
    swiftpkg_swift_syntax = "SwiftSyntax",
)

You need to specify apparent repo names, not module names.

luispadron commented 6 days ago

Oh, that does work and it overrides the repository as expected. Do you know where SwiftSyntax is coming from as the repo name?

At a minimum maybe the error message could suggest this if that seems doable

luispadron commented 6 days ago

Do you know where SwiftSyntax is coming from as the repo name?

😅 ah the SwiftSyntax repo name comes from my bazel_dep use nevermind, that makes sense!

fmeum commented 6 days ago

It comes from your module file:

bazel_dep(
    name = "swift-syntax",
    version = SWIFT_SYNTAX_VERSION,
    repo_name = "SwiftSyntax",
)

Let me see what I can do about the error message.

fmeum commented 6 days ago

@luispadron Could you test https://github.com/bazelbuild/bazel/pull/23982?

luispadron commented 6 days ago

@fmeum Im getting a suggestion now but its suggesting the thing im trying to override (it should suggest the SwiftSyntax repo instead):

Error in override_repo: The repo exported as 'swiftpkg_swift_syntax' by module extension 'swift_deps' is overridden with 'swift-syntax', but no repo is visible under this name (did you mean 'swiftpkg_swift_syntax'?)
ERROR: Error computing the main repository mapping: error executing MODULE.bazel file for the root module
fmeum commented 6 days ago

@luispadron Good catch, should be fixed.

luispadron commented 6 days ago

Nice!

Error in override_repo: The repo exported as 'swiftpkg_swift_syntax' by module extension 'swift_deps' is overridden with 'swift-syntax', but no repo is visible under this name (did you mean 'SwiftSyntax'?)
luispadron commented 6 days ago

Thanks for your help here!

iancha1992 commented 4 days ago

A fix for this issue has been included in Bazel 7.4.0 RC3. Please test out the release candidate and report any issues as soon as possible. If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=7.4.0rc3. Thanks!