Integrating with Bazel

You can translate projects written in Java or Python that are built with Bazel. When the build runs, OpenText SAST translates the source files as they are compiled. See Build tools for supported Bazel versions.

Make sure the following requirements are met before you run the OpenText SAST Bazel integration:

  • Your Bazel build runs without errors.

  • The sourceanalyzer executable is included in the PATH environment variable.

    After the build is complete, always run the OpenText SAST analysis phase with the same version of OpenText SAST that is included in the PATH environment variable.

To run the translation phase for the configured Java or Python, go to the Bazel workspace directory, and then run the OpenText SAST command with the target you want to build. Prepend the Bazel build command line with the sourceanalyzer command as follows:

sourceanalyzer -b <build_id><sca_options> bazel build <target>

If you have multiple OpenText SAST installations, make sure that the version you want to use for your Bazel projects is defined before all other OpenText SAST versions included in the PATH environment variable.

Bazel build integration examples

Translate a project for a specific target:

sourceanalyzer -b MyProjectA bazel build //proja:my-prj

Translate target abc in package proja/abc:

sourceanalyzer -b MyProjectA bazel build //proja/abc

or

sourceanalyzer -b MyProjectA bazel build //proja/abc:abc

Translate all targets in the package proja/abc:

sourceanalyzer -b MyProjectA bazel build //proja/abc:all

Translate all targets within the projb/ directory:

sourceanalyzer -b MyProjectB bazel build //projb/...

Specify a specific JDK version for the translation:

sourceanalyzer -b MyProjectC -jdk 17 bazel build //projc:my-java-prj

Translate a project and exclude a file from the translation:

sourceanalyzer -b MyProjectC -exclude C:\test\MY-JAVA-APP\src\main\java\com\example\HelpContent.java bazel build //projc:my-java-prj

Specify Python project dependencies for the translation:

sourceanalyzer -b MyProjectD -python-path /usr/local/lib/python3.6/ bazel build //projd:my-python-app

OpenText SAST Bazel integration does not support multiple targets and related actions such as excluding targets.

See Also

Java Command-Line Options

Python command-line options