Failed to generate C++ Coverage file with bazel on Ubuntu - c++

Description of the problem / feature request:
I am doing some coverage test on bazel-example project, but I failed to get coverage file:
build project with coverage related options
git clone https://github.com/bazelbuild/examples/ bazel_examples
cd bazel_examples/cpp-tutorial/stage1
bazel build -s --copt="-coverage" --linkopt="-lgcov" //main:hello-world
The result shows build command runs successfully, but no coverage files(*.gcno) are generated.
Then I run the binary output, but no runtime coverage files(*.gcda) are generated too.
I am using bazel 3.5.0, gcc 9.4.0, Ubuntu 18.04.5.
Does any one know how to resolve this?

Did you try checking the coverage by running the below command.
bazel coverage -s \
--instrument_test_targets \
--experimental_cc_coverage \
--combined_report=lcov \
--coverage_report_generator=#bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main \
//...
You can find the coverage file here
bazel-out/_coverage/_coverage_report.dat

Related

How to compile schema at build step?

Waf 2.0.17 glib2 compiles and install the gsettings schemas
of hamster smoothly.
Yet it is not possible to run the application without installing first:
python3 src/hamster-cli.py
(hamster-cli.py:4690): GLib-GIO-ERROR **: 17:27:08.176:
Settings schema 'org.gnome.Hamster' is not installed
The workaround described in First steps with GSettings does not work.
./waf configure build
...
[127/127] Compiling data/org.gnome.hamster.gschema.xml
GSETTINGS_SCHEMA_DIR=build/data python3 src/hamster-cli.py
(hamster-cli.py:4850): GLib-GIO-ERROR **: 17:31:56.381: Settings schema 'org.gnome.Hamster' is not installed
Trace/breakpoint trap (core dumped)
GSETTINGS_SCHEMA_DIR=build/data gsettings describe org.gnome.hamster last-report-folder
No such schema “org.gnome.hamster”
and indeed, there is only the empty build/data/org.gnome.hamster.gschema.xml.valid file that serves as a target:
hcode = 'rm -f ${GLIB_VALIDATE_SCHEMA_OUTPUT} \
&& ${GLIB_COMPILE_SCHEMAS} --dry-run ${GLIB_COMPILE_SCHEMAS_OPTIONS} \
&& touch ${GLIB_VALIDATE_SCHEMA_OUTPUT}'
Workaround
Following this answer:
glib-compile-schemas --targetdir=build/data data
Question
How to get the compiled schema in build/data with ./waf configure build ?

Tensorflow C++ API example line ending?

I have a problem running the standard C++ API example:
https://www.tensorflow.org/api_guides/cc/guide
I created all the files and directories. Bazel then throws an error after being started.
INFO: From Compiling external/snappy/snappy-sinksource.cc [for host]:
cc1plus: warning: command line option '-Wno-implicit-function-declaration' is valid for C/ObjC but not for C++
ERROR: /home/[...]/tensorflow/tensorflow/core/BUILD:1796:1: Executing genrule //tensorflow/core:version_info_gen failed (Exit 127): bash failed: error executing command
(cd /home/[...]/.cache/bazel/_bazel_[...]/[...]/org_tensorflow && \
exec env - \
LD_LIBRARY_PATH=/opt/ros/lunar/lib \
PATH=/opt/ros/lunar/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; tensorflow/tools/git/gen_git_source.py --generate external/local_config_git/gen/spec.json external/local_config_git/gen/head external/local_config_git/gen/branch_ref "bazel-out/host/genfiles/tensorflow/core/util/version_info.cc"')
/usr/bin/env: 'python\r': No such file or directory
Target //tensorflow/cc/example:example failed to build
INFO: Elapsed time: 2.329s, Critical Path: 0.57s
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target
My system is running Debian. It looks like there is an issue with the line ending, but I could not really find anything. Shouldn't work the examples under Linux systems by default?
Or did I misconfigure bazel somehow?
After running dos2unix on all files in the tensorflow directory, compilation works. I think this is really weird. Shouldn't tf be supposed to run out of the box in a Unix system? Anyway, refer
How can I run dos2unix on an entire directory?
to run dos2unix recursively.
I got the same error Build failed. Not running target when trying to follow their guide. For me the problem was solved by explicitly compiling Tensorflow with bazel before compiling and running the example.cc file. I.e. :
./configure
bazel build //tensorflow:libtensorflow_cc.so
bazel run -c opt //tensorflow/cc/example:example

How to run nosetests in jenkins

I have a project which has two folders on same level
/home/ishan/my_repo/jenkins_test/business_logic
/home/ishan/my_repo/jenkins_test/test_cases
test_cases has two files test_fib and test_fact
when I run nosetests --exe at /home/ishan/my_repo/jenkins_test/ it runs correctly showing
....
----------------------------------------------------------------------
Ran 4 tests in 0.036s
OK
I am trying to run these test cases so, I created following script at /home/ishan/my_repo
#!/bin/bash
source /home/ishan/venv/bin/activate
nosetests --exe /home/ishan/sf_shared/my_repo/jenkin_test/
deactivate
When I run it using
source /home/ishan/my_repo/test_runner.sh it shows correct output.
So, I tried to put it in jenksins build step. So, I added the same line
source /home/ishan/my_repo/test_runner.sh in command section of Execute Shell in jenkins.
Now, when I trigger the build using build now it fails saying
Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/jenkins_test
[jenkins_test] $ /bin/sh -xe /tmp/hudson5020664150857393715.sh
+ source /home/ishan/sf_shared/test_runner.sh
/tmp/hudson5020664150857393715.sh: 2: /tmp/hudson5020664150857393715.sh: source: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I think it doesn't even execute any test cases. It fails long before.
Can you suggest what am I doing wrong?
Maybe this will works:
/home/ishan/venv/bin/nosetests --exe /home/ishan/sf_shared/my_repo/jenkin_test/
Resolved it, issue was with the following line
source /home/ishan/venv/bin/activate
I replaced it source with standard . then it worked. So, my line became
. /home/ishan/venv/bin/activate

ocaml-glpk (glpk bindings) and OASIS

Preface: I am new to OCaml, OPAM, and OASIS.
tldr question: How do I properly set up a package with opam that is not already available in the repository (I can't just do opam install X)? More details follow:
I am trying to include ocaml-glpk in an OCaml project. I installed ocaml-glpk just by running make and make install as stated in the README, and the given example compiles and runs correctly. However, I am using OASIS to generate the build system of my project, and I am not sure how to set it up. I have the same example (renamed to glpkExample.ml in a src folder) and the following in my _oasis file:
Executable "glpkExample"
Path: src
MainIs: glpkExample.ml
CompiledObject: best
BuildDepends:
glpk
After running oasis setup -setup-update dynamic, I run make and get the following error:
ocaml setup.ml -build
Finished, 0 targets (0 cached) in 00:00:00.
+ /home/dimitrios/.opam/system/bin/ocamlfind ocamlopt -g -linkpkg -package glpk src/glpkExample.cmx -o src/glpkExample.native
File "_none_", line 1:
Error: Cannot find file /home/dimitrios/.opam/system/lib/glpk/glpk.cmxa
Command exited with code 2.
Compilation unsuccessful after building 4 targets (3 cached) in 00:00:00.
E: Failure("Command ''/usr/bin/ocamlbuild' src/glpkExample.native -tag debug' terminated with error code 10")
make: *** [build] Error 1
It seems the glpk library is missing a cmxa file needed to compile a native executable. I am not sure how to fix this. To compile glpkExample.ml correctly, my Makefile includes /home/dimitrios/.opam/system/lib/glpk and also uses the OCamlMakefile, which is extremely long and convoluted. Any help on setting this up with OASIS or how to get ocaml-glpk to work nicely with OASIS would be greatly appreciated.
Thanks!
This website is not appropriate for bug reports. You should really report it here.
The temporary solution is to use CompiledObject: byte to compile in bytecode.
If you're using opam then it is best to install application with it, not manually. Try to clean up your system and remove whatever you installed, and then do:
$ eval `opam config env`
$ opam install ocaml-glpk
Afterwards, if glpk is packaged in opam correctly, it should work with your setup, i.e., just with oasis's BuildDepends field and nothing more.

Build Tensorflow with Bazel

I would like build tensorflow with Bazel to use the compiled libary in c++. I run the following commands in cmd.
C:\Users\Furkan\Desktop\tensorflow-1.14.0>bazel build --config=opt
WARNING: Usage: bazel build <options> <targets>.
Invoke `bazel help build` for full description of usage and options.
Your request is correct, but requested an empty set of targets. Nothing will be built.
INFO: Build option --define has changed, discarding analysis cache.
INFO: Analyzed 0 targets (0 packages loaded, 0 targets configured).
INFO: Found 0 targets...
INFO: Elapsed time: 0.124s, Critical Path: 0.01s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
After that they create the folders in tensorflow, but the folders are empty.. What I do wrong??
bazel: 0.25.2
tensorflow: 1.14.0
I guess you're typing an incomplete command, you should type:
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
The
//tensorflow/tools/pip_package:build_pip_package
is the location of the BUILD file, if you're not including it bazel does not know what to build. Including that in your command should solve the issue.