While adding the maven dependency in bazel project,unable to running the bazel run #maven//:pin,getting maven_install.json as empty.facing below issue - bazel

bazel run #maven//:pin
Starting local Bazel server and connecting to it...
INFO: Analyzed target #maven//:pin (7 packages loaded, 26 targets configured).
INFO: Found 1 target...
Target #maven//:pin up-to-date:
bazel-bin/external/maven/pin
bazel-bin/external/maven/pin.exe
INFO: Elapsed time: 14.964s, Critical Path: 0.13s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Starting local Bazel server and connecting to it...
C:\Users\mohit.jaiswal_bazel_mohit.jaiswal\3crxb23l\execroot_main_\bazel-out\x64_windows-fastbuild\bin\external\maven\pin: line 13: ../maven/jq: No such file o
r directory
and maven_install.json file is showing empty

Make sure github.com/bazelbuild/rules_jvm_external is added properly in the worksapce file. Clean the build by [bazel clean --expunge] and try compiling it again.

Related

How do you debug a Bazel sandboxing failure?

Repo with full code example.
When I try to run a test with Bazel involving the tree-sitter binary, I get an Operation not permitted error without any further information.
❯ bazel test --test_output=errors --verbose_failures --sandbox_debug //tree-sitter-nbts:check-generated
INFO: Analyzed target //tree-sitter-nbts:check-generated (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
FAIL: //tree-sitter-nbts:check-generated (see /private/var/tmp/_bazel_varun/e55142ab9bc72292b8c54fb9627025eb/execroot/__main__/bazel-out/darwin_arm64-fastbuild/testlogs/tree-sitter-nbts/check-generated/test.log)
INFO: From Testing //tree-sitter-nbts:check-generated:
==================== Test output for //tree-sitter-nbts:check-generated:
++ dirname /private/var/tmp/_bazel_varun/e55142ab9bc72292b8c54fb9627025eb/sandbox/darwin-sandbox/17/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/tree-sitter-nbts/check-generated.runfiles/__main__/tree-sitter-nbts/check-generated
+ cd /private/var/tmp/_bazel_varun/e55142ab9bc72292b8c54fb9627025eb/sandbox/darwin-sandbox/17/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/tree-sitter-nbts/check-generated.runfiles/__main__/tree-sitter-nbts
+ git init -b main
Initialized empty Git repository in /private/var/tmp/_bazel_varun/e55142ab9bc72292b8c54fb9627025eb/sandbox/darwin-sandbox/17/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/tree-sitter-nbts/check-generated.runfiles/__main__/tree-sitter-nbts/.git/
+ git add .
+ GIT_AUTHOR_EMAIL=_
+ GIT_AUTHOR_NAME=_
+ GIT_COMMITTER_EMAIL=_
+ GIT_COMMITTER_NAME=_
+ git commit -m 'Initial commit'
[main (root-commit) 1f79ef2] Initial commit
11 files changed, 11 insertions(+)
create mode 120000 Cargo.lock
create mode 120000 Cargo.toml
create mode 120000 bindings/rust/build.rs
create mode 120000 bindings/rust/lib.rs
create mode 120000 check-generated
create mode 120000 check-generated.sh
create mode 120000 grammar.js
create mode 120000 src/grammar.json
create mode 120000 src/node-types.json
create mode 120000 src/parser.c
create mode 120000 src/tree_sitter/parser.h
+ tree-sitter generate
Operation not permitted (os error 1)
================================================================================
Target //tree-sitter-nbts:check-generated up-to-date:
bazel-bin/tree-sitter-nbts/check-generated
INFO: Elapsed time: 0.220s, Critical Path: 0.11s
INFO: 2 processes: 2 darwin-sandbox.
INFO: Build completed, 1 test FAILED, 2 total actions
//tree-sitter-nbts:check-generated FAILED in 0.1s
/private/var/tmp/_bazel_varun/e55142ab9bc72292b8c54fb9627025eb/execroot/__main__/bazel-out/darwin_arm64-fastbuild/testlogs/tree-sitter-nbts/check-generated/test.log
INFO: Build completed, 1 test FAILED, 2 total actions
What is a good way of debugging this? So far, I know the following:
Running tree-sitter generate directly in the source tree works fine.
The bazel test command works fine with --spawn_strategy=standalone, which I think confirms that this is a sandboxing issue.
The bazel test command works fine inside the Nix environment (see the linked repo). This one is a little weird, not sure what's going on here.
Configuration information:
macOS 12.4 on an M1 Mac
Bazel v5.2.0 (both in Nix and outside)
tree-sitter v0.20.6 (both in Nix and outside) (I tried using the Nix-installed binary with Bazel and that didn't seem to make any difference)
OpenJDK v11.0.15 in the global environment vs OpenJDK v11.0.11 in Nix.
GitHub issues which seem related:
ln call fails with "operation not permitted" during bazel test - This comment mentions there is no command printed with --verbose_failures --sandbox_debug.
Strange "Operation not permitted" problem for test program accessing files in the sand box on MacOS

"bazel test //..." executes actions unrelated to any tests

I have a target //src/hello:hello_proj.bit which should not be a dependency for any tests. This is confirmed by:
$ bazel cquery 'rdeps(//..., //src/hello:hello_proj.bit)' --output=label_kind
INFO: Analyzed 38 targets (0 packages loaded, 0 targets configured).
INFO: Found 38 targets...
vivado_bitstream rule //src/hello:hello_proj.bit (43fd5e3)
vivado_config_memory rule //src/hello:hello_proj.bin (43fd5e3)
vivado_load rule //src/hello:hello_proj.load (43fd5e3)
vivado_flash rule //src/hello:hello_proj.flash (43fd5e3)
INFO: Elapsed time: 0.175s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
And:
$ bazel cquery 'allpaths(tests(//...), //src/hello:hello_proj.bit)'
INFO: Analyzed 38 targets (0 packages loaded, 3 targets configured).
INFO: Found 38 targets...
INFO: Empty query results
INFO: Elapsed time: 0.247s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
In addition, the following returns no results:
$ bazel aquery 'deps(tests(//...))' | grep hello_proj.bit
But yet the following still tries to build //src/hello:hello_proj.bit even though the tests can complete successfully if --keep_going is issued. So clearly it is not truly a dependecy but ends up in the action graph for some unknown reason.
$ bazel test -s --keep_going //...
INFO: Analyzed 35 targets (0 packages loaded, 0 targets configured).
INFO: Found 26 targets and 9 test targets...
SUBCOMMAND: # //src/hello:hello_proj.bit [action 'Synthesizing hello', configuration: 0decb71fa64362af97ee459b2292a0b5285d3f4092bf077905729774dcbbdb43, execution platform: #local_config_platform//:host]
... Removed for brevity ...
ERROR: /home/agoessling/hdl/src/hello/BUILD:26:15: Synthesizing hello failed (Exit 1):
... Removed for brevity ...
INFO: Elapsed time: 0.339s, Critical Path: 0.18s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
//src/hello:test_hello_ver_BAUD25000000_FREP100000 (cached) PASSED in 0.4s
//src/lib:prove_strobe_div (cached) PASSED in 1.0s
//src/lib:prove_uart_tx (cached) PASSED in 4.2s
//src/lib:test_strobe_div_DIV100 (cached) PASSED in 0.4s
//src/lib:test_strobe_div_DIV2 (cached) PASSED in 0.4s
//src/lib:test_strobe_div_DIV6 (cached) PASSED in 0.3s
//src/lib:test_strobe_div_DIV7 (cached) PASSED in 0.3s
//src/lib:test_strobe_div_DIV8 (cached) PASSED in 0.4s
//src/lib:test_uart_tx_BAUD_DIV3 (cached) PASSED in 0.4s
Executed 0 out of 9 tests: 9 tests pass.
All tests passed but there were other errors during the build.
FAILED: Build did NOT complete successfully
I'm at a loss at what else to try to dig into this. No query, cquery, or aquery that I have tried has yielded any connection from any test to //src/hello:hello_proj.bit. What am I missing?
In bazel, the test verb is essentially "build the given targets and execute any of them that are tests".
//... expands to all targets in the current workspace, which therefore includes //src/hello:hello_proj.bit
So here bazel is building everything (//...) and then running any tests.
To build just the test cases, pass --build_tests_only

How to bazel gazelle --update-repos with private repository

How do you run bazel gazelle update-repo command when you have private repository when your go.mod file has private repository in there
❯ bazel run //:gazelle -- update-repos -from_file=search/go.mod
INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
bazel-bin/gazelle-runner.bash
bazel-bin/gazelle
INFO: Elapsed time: 0.231s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
go: bitbucket.org/blah/backend-components/go-logging#v1.0.5/go.mod: verifying module: bitbucket.org/blah/backend-components/go-logging#v1.0.5/go.mod: reading https://sum.golang.org/lookup/bitbucket.org/blah/backend-components/go-logging#v1.0.5: 410 Gone
server response:
not found: bitbucket.org/blah/backend-components/go-logging#v1.0.5: reading https://api.bitbucket.org/2.0/repositories/blah/backend-components?fields=scm: 403 Forbidden
server response: Access denied. You must have write or admin access.
gazelle: exit status 1
I can't find it in the docs how, but you set the environment variable GOPRIVATE to a comma-separated list of module-like patters. For example:
export GOPRIVATE='github.com/mycompany/myrepo,*.example.com'

Bazel inside Alpine container issue

I'm trying to test the build of google/or-tools using the Bazel based build system on various GNU/Linux distro by using various common distros
When trying to use bazel inside an Alpine:edge based Dockerfile (i.e. in a RUN cmd), at "docker build" time.
I don't have a consistency build between my Archlinux and on Github action workflow runners (ubuntu 18.04 IIRC).
Dockerfile: https://github.com/google/or-tools/blob/master/bazel/docker/alpine/Dockerfile
I run it using my Makefile target alpine_build in google/or-tools/bazel
ref: https://github.com/google/or-tools/blob/master/bazel/Makefile
From GH ubuntu-latest (18.04 LTS ?) runner, I got this trace
$ make alpine_build
...
Step 11/11 : RUN bazel build --curses=no --copt='-Wno-sign-compare' //...:all
---> Running in 9a2f9b6f24c7
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
Loading:
Loading: 0 packages loaded
Loading: 0 packages loaded
Loading: 0 packages loaded
DEBUG: Rule 'com_google_protobuf' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "fe1790ca0df67173702f70d5646b82f48f412b99", shallow_since = "1576187991 -0800"
DEBUG: Call stack for the definition of repository 'com_google_protobuf' which is a git_repository (rule definition at /root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18):
- /home/lib/WORKSPACE:22:1
Loading: 2 packages loaded
Analyzing: 301 targets (16 packages loaded, 0 targets configured)
Analyzing: 301 targets (25 packages loaded, 43 targets configured)
Analyzing: 301 targets (26 packages loaded, 43 targets configured)
...
ref: https://github.com/google/or-tools/runs/568849544?check_suite_focus=true
So everything seems fine up to this point (still need to figure out the jdk javac issue but it's an other topic)
On the contrary on my Archlinux, I've got:
$ make alpine_build
...
Step 11/11 : RUN bazel build --curses=no --copt='-Wno-sign-compare' //...:all
---> Running in e13ca9fd3e84
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
Loading:
Loading: 0 packages loaded
Loading: 0 packages loaded
Loading: 0 packages loaded
INFO: Call stack for the definition of repository 'com_google_protobuf' which is a git_repository (rule definition at /root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18):
- /home/lib/WORKSPACE:22:1
ERROR: An error occurred during the fetch of repository 'com_google_protobuf':
java.io.IOException: unlinkat(/root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/com_google_protobuf/.git/logs/refs/remotes/origin) (Directory not empty)
ERROR: no such package '#com_google_protobuf//': java.io.IOException: unlinkat(/root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/com_google_protobuf/.git/logs/refs/remotes/origin) (Directory not empty)
ERROR: no such package '#com_google_protobuf//': java.io.IOException: unlinkat(/root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/com_google_protobuf/.git/logs/refs/remotes/origin) (Directory not empty)
INFO: Elapsed time: 29.713s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)
The command '/bin/sh -c bazel build --curses=no --copt='-Wno-sign-compare' //...:all' returned a non-zero code: 1
make: *** [Makefile:121: alpine_build] Error 1
I've tried to look at the file /root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/com_google_protobuf/.git/logs/refs/remotes/origin
using the previous step (alpine_devel) container:
$ make sh_alpine_devel
/home/lib # bazel build --curses=no --copt='-Wno-sign-compare' //...:all
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
Loading:
Loading: 0 packages loaded
Loading: 0 packages loaded
Loading: 0 packages loaded
INFO: Call stack for the definition of repository 'com_google_protobuf' which is a git_repository (rule definition at /root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18):
- /home/lib/WORKSPACE:22:1
ERROR: An error occurred during the fetch of repository 'com_google_protobuf':
java.io.IOException: unlinkat(/root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/com_google_protobuf/.git/logs/refs/remotes/origin) (Directory not empty)
ERROR: no such package '#com_google_protobuf//': java.io.IOException: unlinkat(/root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/com_google_protobuf/.git/logs/refs/remotes/origin) (Directory not empty)
ERROR: no such package '#com_google_protobuf//': java.io.IOException: unlinkat(/root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/com_google_protobuf/.git/logs/refs/remotes/origin) (Directory not empty)
INFO: Elapsed time: 29.924s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)
cat /root/.cache/bazel/_bazel_root/86fee77ec27da0053940f3f327a6fd59/external/com_google_protobuf/.git/logs/
refs/remotes/origin/revert-6272-MutableSequence-import
0000000000000000000000000000000000000000 c5fedd61a48a174054f98684d5ddbc2d11530367 root <root#Flex2.home> 1586336706 +0000 fetch origin refs/heads/*:refs/remotes/origin/* refs/tags/*:refs/tags/*: storing head
note Flex2 is my local machine...
So my questions:
Is it a known issue (ed don't find anything on java.io.IOException: unlinkat) ?
Does Bazel deal with the kernel (or uname -a etc...) which could explain why I don't have the same behaviour from one host to an other ?
May I have more trace to debug this issue ?
How can I fix it ?
Thanks,
Basically you need to tell to bazel to use the java locally installed by alpine than downloading one.
this can be done using the option --host_javabase=#local_jdk//:jdk
ref: https://github.com/google/or-tools/blob/2cb85b4eead4c38e1c54b48044f92087cf165bce/bazel/docker/alpine/Dockerfile#L26
Minimal working example:
https://github.com/Mizux/bazel-cpp/blob/main/ci/docker/alpine/Dockerfile

build abseil on windows using bazel

im trying to build abseil on windows using bazel,
the version im trying to build is :
abseil-cpp-20181200
im using the next bazel command:
bazel build
im getting this output:
INFO: Invocation ID: d85f94c1-e562-4ede-9bcd-9ab7e39020f3
Loading:
Loading: 0 packages loaded
Analyzing: 0 targets (0 packages loaded, 0 targets configured)
INFO: Analysed 0 targets (0 packages loaded, 0 targets configured).
INFO: Found 0 targets...
[0 / 1] [-----] BazelWorkspaceStatusAction stable-status.txt
INFO: Elapsed time: 0.261s, Critical Path: 0.01s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
I see that some folders were created in abseil-cpp-20181200
bazel-abseil-cpp-20181200
bazel-bin
bazel-genfiles
bazel-out
bazel-testlogs
these folders are empty.
the system im using is windows7 64 bit
if more info is needed please tell me and I will supply it,
help is appreciated
bazel build itself doesn't build anything. You'll have to specify a target to tell Bazel what to build. For example, if you want to build strings, specify the target //absl/strings:strings, or //absl/strings for short:
$ bazel build //absl/strings
See the C++ Quickstart for more information.

Resources