@@ -19,7 +19,6 @@ load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
19
19
load ("@bazel_skylib//rules:expand_template.bzl" , "expand_template" )
20
20
load ("//python:py_binary.bzl" , "py_binary" )
21
21
load ("//python/private:bzlmod_enabled.bzl" , "BZLMOD_ENABLED" ) # buildifier: disable=bzl-visibility
22
- load ("//python/private:text_util.bzl" , "render" ) # buildifier: disable=bzl-visibility
23
22
24
23
visibility (["//..." ])
25
24
@@ -28,11 +27,10 @@ _REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:
28
27
_LockRunInfo = provider (
29
28
doc = "Information about source tree for Sphinx to build." ,
30
29
fields = {
31
- "args" : """
32
- :type: Args
33
-
34
- TODO
35
- """ ,
30
+ "args" : "" ,
31
+ "cmd" : "" ,
32
+ "cmd_file" : "" ,
33
+ "srcs" : "" ,
36
34
},
37
35
)
38
36
@@ -45,24 +43,42 @@ def _lock_impl(ctx):
45
43
])
46
44
args .add ("--output-file" , ctx .outputs .out )
47
45
args .add_all (ctx .files .srcs )
48
- args .use_param_file ("--file=%s" , use_always = True )
49
46
47
+ # We use a manual param file so that we can forward it to the debug executable rule
48
+ param_file = ctx .actions .declare_file (ctx .label .name + ".params.txt" )
49
+ ctx .actions .write (
50
+ output = param_file ,
51
+ content = args ,
52
+ )
53
+
54
+ run_args = [param_file .path ]
55
+ args = ctx .actions .args ()
56
+ args .add_all (run_args )
57
+
58
+ cmd = ctx .executable .cmd
59
+
60
+ srcs = ctx .files .srcs + ctx .files .maybe_out + [param_file ]
50
61
ctx .actions .run (
51
62
executable = ctx .executable .cmd ,
52
63
mnemonic = "RulesPythonLock" ,
53
- inputs = ctx .files .srcs + ctx .files .maybe_out ,
54
- outputs = [
55
- ctx .outputs .out ,
56
- ],
64
+ inputs = srcs ,
65
+ outputs = [ctx .outputs .out ],
57
66
arguments = [args ],
58
- tools = [ctx . executable . cmd ],
67
+ tools = [cmd ],
59
68
progress_message = "Locking requirements using uv" ,
60
69
env = ctx .attr .env ,
61
70
)
62
71
63
72
return [
64
- DefaultInfo (files = depset ([ctx .outputs .out ])),
65
- _LockRunInfo (args = args ),
73
+ DefaultInfo (
74
+ files = depset ([ctx .outputs .out ]),
75
+ ),
76
+ _LockRunInfo (
77
+ cmd = ctx .attr .cmd ,
78
+ cmd_file = ctx .executable .cmd ,
79
+ args = run_args ,
80
+ srcs = srcs ,
81
+ ),
66
82
]
67
83
68
84
_lock = rule (
@@ -84,18 +100,23 @@ _lock = rule(
84
100
)
85
101
86
102
def _run_lock_impl (ctx ):
87
- provider = ctx .attr .lock [_LockRunInfo ]
88
-
89
- executable = ctx .actions .declare_file (ctx .label .name )
90
- ctx .actions .expand_template (
91
- template = ctx .file ._template ,
103
+ run_info = ctx .attr .lock [_LockRunInfo ]
104
+ executable = ctx .actions .declare_file (ctx .label .name + ".exe" )
105
+ ctx .actions .symlink (
92
106
output = executable ,
93
- substitutions = {
94
- " args = []" : " args = " + render .indent (render .list (provider .args )),
95
- },
107
+ target_file = run_info .cmd_file ,
96
108
is_executable = True ,
97
109
)
98
- fail (provider )
110
+
111
+ runfiles = ctx .runfiles (
112
+ files = run_info .srcs ,
113
+ transitive_files = run_info .cmd [DefaultInfo ].files ,
114
+ ).merge (run_info .cmd [DefaultInfo ].default_runfiles )
115
+
116
+ return DefaultInfo (
117
+ executable = executable ,
118
+ runfiles = runfiles ,
119
+ )
99
120
100
121
_run_lock = rule (
101
122
implementation = _run_lock_impl ,
0 commit comments