Everything happens under your drake/ folder.
To build the whole folder:
bazel build //...
// means the root path of your drake folder, it equals
... means build everything. Build everything can take a long time. We could speed up building by narrow down the range. For example, to build all targets under a subfolder:
bazel build //tools/...
Or to build a specific target:
bazel build //tools:drake_visualizer
bazel that the path of the target is drake/tools/. What's followed after
: is the target
drake_visualizer that we want to build.
bazel will try to find the
BUILD.bazel file under drake/tools/ and build the target based on the rule defined in the
To run a specific executable:
bazel run //examples/double_pendulum:double_pendulum_demo
bazel run will detect the relevant file modification. If the files are changed, this command will build first and then run immediately after the build.
: is followed by the executable binary, in this case,
Another way to run the binary is to type the binary name directly in the terminal. It does not check the file change nor recompile. All the
bazel binaries are put in the drake/bazel-bin/ folder after being built. The detailed location of an executable is defined by
How to find where is the executable? Well, check the
BUILD.bazel file and find the
drake_cc_binary item. The executable sits in the
using gdb to debug when you find errors like segmentation fault comes handy. We could compile the executable with gdb by:
bazel build --compilation_mode=dbg //examples/multibody/inclined_plane_with_body
Then you could run the executable with gdb inspecting the variables and function calls. When there is a error and program crashes, we could trace back to where it went wrong.
gdb ./bazel-bin/examples/multibody/inclined_plane_with_body(gdb) run # execute the program and record the runtime stack data(gdb) bt # back trace to where the program crashes and figure the problem(gdb) quit
This command applies when you wrote your own function and test cases. Then you could test your cases by:
bazel test //common:polynomial_test
Commands in this page are enough to handle most cases.
bazel usage, check out the Drake document of bazel.
To learn more about
bazel, please refer to bazel official document.