Skip to content

Commit

Permalink
Fixed: exemple for using rule endorctl_scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Dogild committed Dec 5, 2023
1 parent 1c8ea9c commit f477feb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ java_library(
endorctl_scan(
name = "endorctl-scan",
targets = [
":java-maven-lib",
":java-maven-lib-test",
],
scan_args = [
"--namespace=test_namespace"
],
)
```

Running the rules:

```bash
bazel test --test_env=ENDOR_TOKEN --test_output=all --test_env=ENDOR_SCAN_PATH=$(pwd) --test_env=HOME --sandbox_writable_path=$HOME/.endorctl //examples/java:endorctl-scan
```

## Development

The repository follows the [official recommendation](https://bazel.build/rules/deploying) on deploying bazel rules.
Expand Down
8 changes: 7 additions & 1 deletion endorctl/internal/scan.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ _DOC = """
_TOOLCHAIN = str(Label("//endorctl/tools/endorctl:toolchain_type"))

def _endorctl_scan(ctx):

# TODO
# Right now we need to run the rule like
# bazel test --test_env=ENDOR_TOKEN --test_output=all --test_env=ENDOR_SCAN_PATH=$(pwd) --test_env=HOME --sandbox_writable_path=$HOME/.endorctl //examples/java:endorctl-scan
# Ideally the ENDOR_SCAN_PATH, HOME and the sandbox_writable_path should not be needed.

cmd = "{} scan --use-bazel".format(ctx.toolchains[_TOOLCHAIN].cli.short_path)

for target in ctx.attr.targets:
cmd = "{} --bazel-include-targets={}".format(cmd, str(target.label))
cmd = "{} --bazel-include-targets={}".format(cmd, str(target.label)[1:])

for args in ctx.attr.scan_args:
cmd = "{} {}".format(cmd, args)
Expand Down
4 changes: 2 additions & 2 deletions examples/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ java_test(
endorctl_scan(
name = "endorctl-scan",
targets = [
":java-maven-lib",
":java-maven-test",
],
scan_args = [
"--namespace=test_namespace"
"--namespace=alex",
],
)

0 comments on commit f477feb

Please sign in to comment.