salesforce / rules_spring

Bazel rule for building Spring Boot apps as a deployable jar
BSD 3-Clause "New" or "Revised" License
224 stars 48 forks source link

Springboot rule in root of workspace fails with bazelrun_env.sh error #124

Closed dullchap closed 3 years ago

dullchap commented 3 years ago

It seems that the examples in README.md do not work properly. Did I miss something?


bazel build //:SpringBootDemo

INFO: Analyzed target //:SpringBootDemo (0 packages loaded, 0 targets configured). INFO: Found 1 target... ERROR: /Users/jack/Documents/workspace/myProject/SpringBootDemo/BUILD:17:11: declared output 'bazelrun_env.sh' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely) ERROR: /Users/jack/Documents/workspace/myProject/SpringBootDemo/BUILD:17:11: Executing genrule //:_genbazelrunenv failed: not all outputs were created or valid Target //:SpringBootDemo failed to build Use --verbose_failures to see the command lines of failed build steps. INFO: Elapsed time: 0.185s, Critical Path: 0.06s INFO: 4 processes: 3 internal, 1 darwin-sandbox. FAILED: Build did NOT complete successfully

plaird commented 3 years ago

That is coming from a new feature, so this might be a bug. I will try to repro today and get back to you. Sorry.

Are you using the release 2.1.1? It looks like you are on Mac.

plaird commented 3 years ago

This issue affects a use case that we don't have internally, so we didn't detect the bug. This problem occurs if the springboot() rule is in a BUILD file in the workspace root (next to the WORKSPACE file, as in //:myservice) instead of a subdirectory path (as in //projects/myservice:myservice).

The problem was that the native.package_name() starlark function was used to populate a positional argument passed to a subrule. If the springboot() rule is in a BUILD file in the workspace root, native.package_name() returns an empty string. This caused the positional arguments to shift left one spot because the empty string didn't render into the argument list.

plaird commented 3 years ago

Jack - this should be fixed now if you upgrade to 2.1.2. Sorry for the bug. We don't have usages internal to my company where the springboot rule is in the root of the workspace, so we missed it. Thanks for reporting.

@dullchap

dullchap commented 3 years ago

It worked. Thank you for your solution and answers