http_archive: Build file is not a regular file

124 views Asked by At

Source Code: https://github.com/abitofhelp/hellobzlmod.git

Hello,

I am fairly new to Bazel & Gazelle and am creating a simple proof-of-concept app. It is the ubiquitous "hello world" using ProtoBuf. Everything builds properly, except when I added 'import "google/api/annotations.proto";' to the hello_world.proto file. I am using bzlmod and discovered that googleapis is undefined. The best solution that I can think of is to add an http_archive to WORKSPACE.bzlmod that points to "https://github.com/googleapis/googleapis/archive/refs/heads/master.zip" Since it has Bazel build files, I should be able to use the repository in my build.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# My first attempt to directly use it, but this failed to work.
#http_archive(
#    name = "googleapi",
#    sha256 = "5abf56b8df52ef94b51b313271cc9a55185b53449e85dc77e972162dbc6fe769",
#    strip_prefix = "googleapis-master/",
#    url = "https://github.com/googleapis/googleapis/archive/refs/heads/master.zip",
#)
# My current attempt to download googleapis-master and create a proto_library from it.  
# This is failing and I have posted the error below.
http_archive(
    name = "googleapi",
    build_file = "BUILD.googleapis",
    sha256 = "5abf56b8df52ef94b51b313271cc9a55185b53449e85dc77e972162dbc6fe769",
    strip_prefix = "googleapis-master/",
    url = "https://github.com/googleapis/googleapis/archive/refs/heads/master.zip",
)

Here is the error stream:

bazel build --sandbox_debug //...
Starting local Bazel server and connecting to it...
(02:11:15) INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=162
(02:11:15) INFO: Reading rc options for 'build' from /Users/mike/Go/src/github.com/abitofhelp/hellobzlmod/.bazelrc:
  Inherited 'common' options: --announce_rc --show_timestamps --enable_bzlmod
(02:11:15) INFO: Reading rc options for 'build' from /Users/mike/Go/src/github.com/abitofhelp/hellobzlmod/.bazelrc:
  'build' options: --verbose_failures
(02:11:15) INFO: Current date is 2023-11-06
(02:11:23) INFO: Repository googleapi instantiated at:
  /Users/mike/Go/src/github.com/abitofhelp/hellobzlmod/WORKSPACE.bzlmod:13:13: in <toplevel>
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_mike/9aa66e3ee6939dac4d9b0bf2e4c9a081/external/bazel_tools/tools/build_defs/repo/http.bzl:372:31: in <toplevel>
(02:11:23) INFO: repository @googleapi' used the following cache hits instead of downloading the corresponding file.
 * Hash '5abf56b8df52ef94b51b313271cc9a55185b53449e85dc77e972162dbc6fe769' for https://github.com/googleapis/googleapis/archive/refs/heads/master.zip
If the definition of 'repository @googleapi' was updated, verify that the hashes were also updated.
(02:11:23) ERROR: An error occurred during the fetch of repository 'googleapi':
   Traceback (most recent call last):
        File "/private/var/tmp/_bazel_mike/9aa66e3ee6939dac4d9b0bf2e4c9a081/external/bazel_tools/tools/build_defs/repo/http.bzl", line 142, column 28, in _http_archive_impl
                workspace_and_buildfile(ctx)
        File "/private/var/tmp/_bazel_mike/9aa66e3ee6939dac4d9b0bf2e4c9a081/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 61, column 41, in workspace_and_buildfile
                ctx.file(**"BUILD.bazel", ctx.read(ctx.attr.build_file))
Error in read: Not a regular file:** /Users/mike/Go/src/github.com/abitofhelp/hellobzlmod/external/BUILD.googleapis
(02:11:23) ERROR: /Users/mike/Go/src/github.com/abitofhelp/hellobzlmod/WORKSPACE.bzlmod:13:13: fetching http_archive rule //external:googleapi: Traceback (most recent call last):
        File "/private/var/tmp/_bazel_mike/9aa66e3ee6939dac4d9b0bf2e4c9a081/external/bazel_tools/tools/build_defs/repo/http.bzl", line 142, column 28, in _http_archive_impl
                workspace_and_buildfile(ctx)
        File "/private/var/tmp/_bazel_mike/9aa66e3ee6939dac4d9b0bf2e4c9a081/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 61, column 41, in workspace_and_buildfile
                ctx.file("BUILD.bazel", ctx.read(ctx.attr.build_file))
Error in read: Not a regular file: /Users/mike/Go/src/github.com/abitofhelp/hellobzlmod/external/BUILD.googleapis
(02:11:23) ERROR: /Users/mike/Go/src/github.com/abitofhelp/hellobzlmod/proto/abitofhelp/api/helloworld/v1/BUILD.bazel:5:14: //proto/abitofhelp/api/helloworld/v1:abitofhelp_api_helloworld_v1_proto depends on @googleapi//:annotations_proto in repository @googleapi which failed to fetch. no such package '@googleapi//': Not a regular file: /Users/mike/Go/src/github.com/abitofhelp/hellobzlmod/external/BUILD.googleapis
(02:11:23) ERROR: Analysis of target '//proto/abitofhelp/api/helloworld/v1:abitofhelp_api_helloworld_v1_proto' failed; build aborted: Analysis failed
(02:11:23) INFO: Elapsed time: 13.022s
(02:11:23) INFO: 0 processes.
(02:11:23) FAILED: Build did NOT complete successfully (31 packages loaded, 7 targets configured)
    Fetching repository @bazel_tools~cc_configure_extension~local_config_cc_toolchains; Building xcode-locator 4s
task: Failed to run task "baz_build_all": exit status 1

The build failed and reported that the Build files were "Not a regular file". They are text files, so I don't have a clue what is wrong.

So, having spent three days trying to resolve the googleapis issue, I am hoping that someone can give me hints or tell me how folks are resolving this problem. Will it be easier in Bazel 7 with bzlmod? I'd really appreciate your help and thank you for your time and interest.

0

There are 0 answers