Tool to play with artifacts, builds and CI.
bazel query java/Hello.java
echo "That is how it is represented in bazel world."
bazel query java:Hello
bazel query java/com/systemlogic/sample:hello
bazel query python:Hello
bazel query python/...
bazel query python/...
bazel query java/...
bazel query //...
bazel query java/Hello.java --output package
bazel query 'java/...' --output package
bazel query //... --output package
bazel query //... --output label_kind
bazel query 'kind(rule, //...)' --output label_kind
bazel query 'kind(.*_binary, //...)' --output label_kind
bazel query 'kind(.*_test, //...)' --output label_kind
echo "bazel query 'rdeps(set(y), set(x))'"
bazel query 'rdeps(set(//java/...), set(//java:Hello.java))'
bazel query 'rdeps(set(//...), set(//java:Hello.java))'
bazel query 'rdeps(set(//java/...), set(java/com/systemlogic/sample:Hello.java))'
bazel query 'rdeps(set(//java/... //python/...), set(java/com/systemlogic/sample:Hello.java))'
bazel query 'rdeps(set(//java/... //python/... //cross-language/...), set(java/com/systemlogic/sample:Hello.java))'
bazel query 'rdeps(set(//...), set(java/com/systemlogic/sample:Hello.java))'
echo "Simply removing file name targets"
bazel query 'rdeps(set(//...), set(//java/com/systemlogic/sample:Hello.java)) - set(//java/com/systemlogic/sample:Hello.java)'
bazel query 'rdeps(//..., set(//java/com/systemlogic/sample:Hello.java)) - set(//java/com/systemlogic/sample:Hello.java)'
bazel query 'kind(".*_test rule", rdeps(set(//...), set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html )))'
bazel test `bazel query 'kind(".*_test rule", rdeps(set(//...), set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html )))'`
bazel query 'kind(".*_test rule", rdeps(set(//...), set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html )) except set(//java/com/webapp:WebTest) )'
echo "OR simply tag the test case with skip_test or any custome string. skip_test is used in this particular case."
bazel query 'kind(".*_test rule", rdeps(set(//...), set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html )) except attr(tags, "skip_test", kind(".*_test rule", rdeps(set(//...), set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html )))) )'
- Please use exclusive tag in tags attribute provided by bazel.
- manual keyword will exclude the target from expansion of target pattern.
bazel query 'kind(".*_library rule", rdeps(set(//...), set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html )))'
bazel query 'kind(".*_binary rule", rdeps(set(//...), set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html )))'
bazel query 'kind("rule", rdeps(//..., set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html)) )' --output label_kind
echo "Please note: appengine_war_base, container_image_, and _k8s_object are not in category of binary, library, test case"
List of targets that should not be run at the time of CI, includes image creation and k8s deployment.
bazel query 'kind("_k8s_object|_k8s_object_describe|_run_all|_k8s_object_apply|_reversed", rdeps(//..., set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html))) '
echo "From main query subtract the docker and k8s targets."
bazel query 'kind("rule", rdeps(//..., set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html))) - kind("_k8s_object|_k8s_object_describe|_run_all|_k8s_object_apply|_reversed", rdeps(//..., set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html))) '
bazel query 'kind("rule", rdeps(//..., set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html))) except ( kind("_k8s_object|_k8s_object_describe|_run_all|_k8s_object_apply|_reversed", rdeps(//..., set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html))) )'
bazel query 'kind("rule", attr(tags, "cd", rdeps(//..., set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html))))'
echo "problem with above query is, tag is attached to macro not with the rule. To get rid of this problem, I have to download"
echo "k8s repository on local mark the apply rule as cd or continuous_deployment."
echo "Ref: https://github.com/bazelbuild/rules_k8s/blob/master/k8s/objects.bzl#L102"
bazel run `bazel query 'kind("rule", attr(tags, "cd", rdeps(//..., set(//java/com/systemlogic/sample:Hello.java java/com/webapp/deployment.yaml java/com/webapp/index.html))))'`
echo "Complete pipeline is setup without using external tool like jenkins, travis, buildkte"
git diff --name-only origin/master..origin/branchName
echo "git command will help in identifying list of files added/changed in particular PR. This can save developers time to merge the code."
bazel coverage //...
bazel coverage //javatests/com/systemlogic/sample:HelloTest
genhtml -o coverage /home/fyre/.cache/bazel/_bazel_fyre/14bd4613f8913871890b0e8218348648/execroot/learn_bazel/bazel-out/k8-fastbuild/testlogs/javatests/com/systemlogic/sample/HelloTest/coverage.dat
echo "OR"
genhtml -o coverage `bazel coverage javatests/com/systemlogic/sample:HelloTest | grep coverage.dat`
and now look into coverage folder.
There is other custom rules to do so. https://github.com/jinfwhuang/bazel-examples
Executes a query on the post-analysis action graph.
bazel aquery 'deps(//java:Hello)'
bazel aquery 'mnemonic("JavaDeployJar", deps(//java/...))'
bazel aquery 'inputs(".*systemlogic/sample/Hello.jar" ,deps(//java/com/systemlogic/sample:Hello))'
bazel aquery 'outputs("bazel-out/k8-fastbuild/internal/_middlemen/java_Scom_Ssystemlogic_Ssample_SHello-runfiles" ,deps(//java/com/systemlogic/sample:Hello))'
where inputs, outputs and mnemonic are filter function.
Executes a post-analysis dependency graph query.
To format and remove the unused loads
buildozer 'fix unusedLoads' //...:*
or to simply fix the formatting.
buildifier --mode=fix BUILD
Unused Deps is a command line tool to determine any unused dependencies in java_library rules. Please add one dependency and run the unused command.
unused_deps <JAVA TARGET NAME>