Commit 7827e0b
fix: handle unsubstituted template placeholders for external native py_binary (#3495)
### Problem
In #3242, it looks like `rules_python` introduced new template
placeholders in the bootstrap scripts: `%stage2_bootstrap%` and
`%interpreter_args%`. And from what I can tell, also made their
successful substitution a requirement.
This works totally fine when the caller is calling `rules_python`
directly. However, when external repositories (like gRPC's cython)
define py_binary using the native rule, these placeholders don't seem to
be substituted? The result is that the literal placeholder text ends up
in the generated bootstrap scripts, causing `SyntaxError`s or
file-not-found errors at runtime
### Fix
Detect if the `%stage2_bootstrap%` variable isn't expanded and fallback
to
`%main%` which IS substituted even for native `py_binary`.
For `%interpreter_args%`, wrap it in triple-quotes so it's hopefully
always valid Python syntax, then detect the sentinel and default to an
empty list. This is a bit hacky,
but is fairly non-invasive.
---------
Co-authored-by: Richard Levasseur <rlevasseur@google.com>1 parent b4ec825 commit 7827e0b
2 files changed
Lines changed: 30 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
728 | 728 | | |
729 | 729 | | |
730 | 730 | | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
| 731 | + | |
735 | 732 | | |
736 | 733 | | |
737 | 734 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
17 | 38 | | |
18 | 39 | | |
19 | 40 | | |
| |||
35 | 56 | | |
36 | 57 | | |
37 | 58 | | |
38 | | - | |
39 | | - | |
40 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
41 | 66 | | |
42 | 67 | | |
43 | 68 | | |
| |||
0 commit comments