Skip to content

Commit c93c2a3

Browse files
committed
Make file_to_string invocation more robust.
Using `py_binary()` will emit a driver script in front of the actual script; depending on flags the user chooses, this can be in Python or could also be a shell script. This can create trouble if we then attempt to invoke that shell script with a python interpreter in tcl_encode_or. Since this is a simple one-file script, always invoke it with the existing Python interpreter witout detour, making the whole situation more robust. Signed-off-by: Henner Zeller <h.zeller@acm.org>
1 parent b442cab commit c93c2a3

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

bazel/tcl_encode_or.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ tcl_encode = rule(
4848
doc = "Files to be wrapped.",
4949
),
5050
"_encode_script": attr.label(
51-
default = "//etc:file_to_string",
51+
default = "//etc:file_to_string.py",
5252
executable = True,
53-
allow_files = True,
53+
allow_single_file = [".py"],
5454
cfg = "exec",
5555
),
5656
},

etc/BUILD

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
1+
load("@rules_python//python:defs.bzl", "py_library", "py_test")
22

33
package(features = ["layering_check"])
44

@@ -7,16 +7,8 @@ exports_files(
77
"whittle.py",
88
"whittle_cleanup.tcl",
99
"whittle_cut.tcl",
10-
],
11-
visibility = ["//visibility:public"],
12-
)
13-
14-
py_binary(
15-
name = "file_to_string",
16-
srcs = [
1710
"file_to_string.py",
1811
],
19-
main = "file_to_string.py",
2012
visibility = ["//visibility:public"],
2113
)
2214

src/stt/BUILD

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ genrule(
1818
"src/flt/etc/POST9.dat",
1919
],
2020
outs = ["src/flt/etc/POST9.cpp"],
21-
cmd = "$(execpath //etc:file_to_string) --inputs $(location src/flt/etc/POST9.dat) --output \"$@\" --varname post9 --namespace stt::flt",
22-
tools = [
23-
"//etc:file_to_string",
24-
],
21+
cmd = "$(PYTHON3) $(execpath //etc:file_to_string.py) --inputs $(location src/flt/etc/POST9.dat) --output \"$@\" --varname post9 --namespace stt::flt",
22+
toolchains = ["@rules_python//python:current_py_toolchain"],
23+
tools = ["//etc:file_to_string.py"],
2524
)
2625

2726
genrule(
@@ -30,10 +29,9 @@ genrule(
3029
"src/flt/etc/POWV9.dat",
3130
],
3231
outs = ["src/flt/etc/POWV9.cpp"],
33-
cmd = "$(execpath //etc:file_to_string) --inputs $(location src/flt/etc/POWV9.dat) --output \"$@\" --varname powv9 --namespace stt::flt",
34-
tools = [
35-
"//etc:file_to_string",
36-
],
32+
cmd = "$(PYTHON3) $(execpath //etc:file_to_string.py) --inputs $(location src/flt/etc/POWV9.dat) --output \"$@\" --varname powv9 --namespace stt::flt",
33+
toolchains = ["@rules_python//python:current_py_toolchain"],
34+
tools = ["//etc:file_to_string.py"],
3735
)
3836

3937
cc_library(

0 commit comments

Comments
 (0)