Bazel Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(12 intermediate revisions by the same user not shown)
Line 7: Line 7:


==<tt>build</tt>==
==<tt>build</tt>==
<syntaxhighlight lang='bash'>
bazel build //...
</syntaxhighlight>
==<tt>clean</tt>==
==<tt>clean</tt>==
==<tt>fetch</tt>==
==<tt>fetch</tt>==
Line 22: Line 26:
===<tt>--script-path</tt>===
===<tt>--script-path</tt>===
Write a shell script that invokes the target. In this way, the target is not run from bazel - the bazel lock is released and the executable is connected to the terminal's stdin.
Write a shell script that invokes the target. In this way, the target is not run from bazel - the bazel lock is released and the executable is connected to the terminal's stdin.
===<tt>--</tt>===
Everything after <code>--</code> is passed to the binary:


=Options=
<syntaxhighlight lang='bash'>
bazel run //tools/sometool -- arg1 arg2 ...
</syntaxhighlight>
 
==<tt>version</tt>==
==<tt>query</tt>==
<font size=-2>
bazel query <options> <query-expression>
</font>
Executes a query language expression over a specified subgraph of the [[Bazel_Concepts#Build_Dependency_Graph|build dependency graph]].
===Find All Targets===
<syntaxhighlight lang='bash'>
bazel query '//:*'
</syntaxhighlight>
===Find all Dependencies of a Dependency Graph Node===
<syntaxhighlight lang='bash'>
bazel query 'deps(//path/to/package:target)'
</syntaxhighlight>
Example:
<syntaxhighlight lang='bash'>
bazel query 'deps(//my_package:my_executable)'
</syntaxhighlight>
<syntaxhighlight lang='bash'>
bazel query 'deps(//:main)'
</syntaxhighlight>
To build the graphic dependency graph:
<syntaxhighlight lang='bash'>
bazel query 'deps(//my_package:my_executable)' --output graph > graph.in
dot -Tpng < graph.in > graph.png
</syntaxhighlight>
===Find a Dependency Path between a Target and a Dependency===
<syntaxhighlight lang='bash'>
bazel query 'somepath(//path/to/package:target, //dependency)'
</syntaxhighlight>
<syntaxhighlight lang='bash'>
bazel query 'somepath(//my_package:my_executable, //tools/somepackage/somelib)'
</syntaxhighlight>
==<tt>test</tt>==
===Re-run a Cached Test===
<syntaxhighlight lang='bash'>
bazel test --cache_test_results=no ...
</syntaxhighlight>
 
=Scenarios=
==Clean Cache==
<syntaxhighlight lang='bash'>
bazel run @cached_local_xcode//:clear_cache; bazel clean --expunge; bazel shutdown; go clean -cache
</syntaxhighlight>

Latest revision as of 20:54, 16 August 2024

External

Internal

Commands

build

bazel build //...

clean

fetch

info

bazel info

run

Runs the specified target. It inherits all options form build.

bazel run --script_path=/Users/ovidiu/bin/something //a/something

Runs the specified target.

--script-path

Write a shell script that invokes the target. In this way, the target is not run from bazel - the bazel lock is released and the executable is connected to the terminal's stdin.

--

Everything after -- is passed to the binary:

bazel run //tools/sometool -- arg1 arg2 ...

version

query

bazel query <options> <query-expression>

Executes a query language expression over a specified subgraph of the build dependency graph.

Find All Targets

bazel query '//:*'

Find all Dependencies of a Dependency Graph Node

bazel query 'deps(//path/to/package:target)'

Example:

bazel query 'deps(//my_package:my_executable)'
bazel query 'deps(//:main)'

To build the graphic dependency graph:

bazel query 'deps(//my_package:my_executable)' --output graph > graph.in
dot -Tpng < graph.in > graph.png

Find a Dependency Path between a Target and a Dependency

bazel query 'somepath(//path/to/package:target, //dependency)'
bazel query 'somepath(//my_package:my_executable, //tools/somepackage/somelib)'

test

Re-run a Cached Test

bazel test --cache_test_results=no ...

Scenarios

Clean Cache

bazel run @cached_local_xcode//:clear_cache; bazel clean --expunge; bazel shutdown; go clean -cache