bazelbuild / bazel

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

repository_disable_download fails with blzmod enabled #24483

Closed davexroth closed 3 days ago

davexroth commented 3 days ago

Description of the bug:

I have a workspace where all bazel dependencies are specified through local_repositories. If I run bazel with --experimental_repository_disable_download --enable_bzlmod=false everything works. However, if I enable bzlmod, the bazel fails with the following error message:

INFO: Repository platforms instantiated at:
  <builtin>: in <toplevel>
Repository rule http_archive defined at:
  /usr/local/google/home/davidroth/.cache/bazel/_bazel_davidroth/17b321a4c24be48339cbd5cfb60ee2e8/external/bazel_tools/tools/build_defs/repo/http.bzl:387:31: in <toplevel>
ERROR: /usr/local/google/home/davidroth/.cache/bazel/_bazel_davidroth/17b321a4c24be48339cbd5cfb60ee2e8/external/bazel_tools/tools/build_defs/repo/http.bzl:136:45: An error occurred during the fetch of repository 'platforms':
   Traceback (most recent call last):
    File "/usr/local/google/home/davidroth/.cache/bazel/_bazel_davidroth/17b321a4c24be48339cbd5cfb60ee2e8/external/bazel_tools/tools/build_defs/repo/http.bzl", line 136, column 45, in _http_archive_impl
        download_info = ctx.download_and_extract(
Error in download_and_extract: java.io.IOException: Failed to download repository @@platforms: download is disabled.
ERROR: no such package '@@platforms//host': java.io.IOException: Failed to download repository @@platforms: download is disabled.
ERROR: /usr/local/google/home/davidroth/.cache/bazel/_bazel_davidroth/17b321a4c24be48339cbd5cfb60ee2e8/external/bazel_tools/tools/BUILD:102:6: @@bazel_tools//tools:host_platform depends on @@platforms//host:host in repository @@platforms which failed to fetch. no such package '@@platforms//host': java.io.IOException: Failed to download repository @@platforms: download is disabled.
ERROR: /usr/local/google/home/davidroth/GitHub/davexroth/bazel_no_download_repro/BUILD:1:10: Target @@bazel_tools//tools:host_platform was referenced as a platform, but does not provide PlatformInfo
ERROR: Analysis of target '//:main' failed; build aborted
INFO: Elapsed time: 0.445s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

Please see the included minimal reproduction with full details.

Which category does this issue belong to?

External Dependency

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

https://github.com/davexroth/bazel_no_download_repro

Which operating system are you running Bazel on?

linux

What is the output of bazel info release?

release 7.4.1

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

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

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

No response

davexroth commented 3 days ago

cc @Wyverald @tpudlik

Wyverald commented 3 days ago

This is WAI -- the overrides you have in WORKSPACE don't affect the Bzlmod part of the build. You'll need to add local_path_override clauses to your MODULE.bazel file, similar to what you have in your WORKSPACE file.

So local_path_override(module_name="platforms", path="external/platforms") etc.

davexroth commented 3 days ago

This is a little un-intuitive for users upgrading from bazel 6 to 7, as by default in version 7 both enable_workspace and enable_bzlmod are true, which causes a working WORKSPACE to start failing on upgrade. It's also not obvious to a user why these WORKSPACE overrides are ignored while other parts of the WORKSPACE are honored in this configuration.