Bazel build not respect stderr and stdout,
when you use bazel build all console log are in stderr, but should be in stdout ?
If you use a tool for separate that log into separate files. All log are in stderr (but build has no error !)
Standard log should to redirect in stdout and Error log (in red) in stderr.
/usr/bin/bazel build //... > stdout.txt 2> stderr.txt
$ cat stderr.txt
Starting local Bazel server and connecting to it...
Loading:
Loading: 0 packages loaded
Analyzing: target //:ProjectRunner (2 packages loaded)
Analyzing: target //:ProjectRunner (4 packages loaded)
INFO: Analysed target //:ProjectRunner (16 packages loaded).
INFO: Found 1 target...
[0 / 4] [-----] Writing file ProjectRunner.jar-2.params
[6 / 9] no action
[6 / 9] Compiling Java headers external/bazel_java_lib/libProjectLib-hjar.jar (1 files); 0s linux-sandbox ... (2 actions running)
[7 / 9] Building external/bazel_java_lib/libProjectLib.jar (1 source file); 2s worker ... (2 actions running)
Target //:ProjectRunner up-to-date:
bazel-bin/ProjectRunner.jar
bazel-bin/ProjectRunner
INFO: Elapsed time: 9.959s, Critical Path: 4.12s
INFO: 3 processes: 1 linux-sandbox, 2 worker.
INFO: Build completed successfully, 9 total actions
INFO: Build completed successfully, 9 total actions
$ cat stdout.txt
<EMPTY>
Debian GNU/linux Testing (Buster) with bazel from repository :
deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8
bazel info release?$ bazel info release
release 0.16.0
_Comparison of other build system..._
$ gradle jar > stdout.txt 2> stderr.txt
$ cat stderr.txt
<EMPTY>
$ cat stdout.txt
:compileJava NO-SOURCE
:processResources NO-SOURCE
:classes UP-TO-DATE
:jar UP-TO-DATE
BUILD SUCCESSFUL
Total time: 1.117 secs
md5-289f01fd95db5ed628bb13d0a380f100
$ cat stderr.txt
/test_gradle/src/main/java/Test.java:2: error: class, interface, or enum expected
bad code
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
md5-c2833341be0e557a9e16b0fa6d829924
$ cat stdout.txt
:compileJava FAILED
BUILD FAILED
Total time: 1.532 secs
md5-d45561a78200e9a19b1607f593a25e52
$ cat stderr.txt
<EMPTY>
md5-c2833341be0e557a9e16b0fa6d829924
$ cat stdout.txt
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /test_cmake
md5-72337a748896f59114efdb3e1692bdf5
$ cat stderr.txt
CMake Error at CMakeLists.txt:14 (add_executable):
Cannot find source file:
main.c
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
CMake Error at CMakeLists.txt:14 (add_executable):
No SOURCES given to target: hello
md5-c2833341be0e557a9e16b0fa6d829924
$ cat stdout.txt
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Build files have been written to: /test_cmake
I agree. I am not sure if the rest of the team does.
Changing this would probably be contentious. There are people who insist on building workflows that parse the output and doing things with it.
Parsing building workflow is always possible if output is on stdout. Many application use stderr for detect a error. Logged a good build to stderr is very strange...
In my case the feature is connected to colcon (Build system of ROS2 ) extension for colcon-core to support Bazel projects ( colcon-bazel & colcon-ros-bazel ).
I assume partly the reason is that the output of {,a,c}query commands can be redirected to a file.
Most helpful comment
I agree. I am not sure if the rest of the team does.
Changing this would probably be contentious. There are people who insist on building workflows that parse the output and doing things with it.