@@ -19,7 +19,6 @@ load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
1919load ("@bazel_skylib//rules:expand_template.bzl" , "expand_template" )
2020load ("//python:py_binary.bzl" , "py_binary" )
2121load ("//python/private:bzlmod_enabled.bzl" , "BZLMOD_ENABLED" ) # buildifier: disable=bzl-visibility
22- load ("//python/private:text_util.bzl" , "render" ) # buildifier: disable=bzl-visibility
2322
2423visibility (["//..." ])
2524
@@ -28,11 +27,10 @@ _REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:
2827_LockRunInfo = provider (
2928 doc = "Information about source tree for Sphinx to build." ,
3029 fields = {
31- "args" : """
32- :type: Args
33-
34- TODO
35- """ ,
30+ "args" : "" ,
31+ "cmd" : "" ,
32+ "cmd_file" : "" ,
33+ "srcs" : "" ,
3634 },
3735)
3836
@@ -45,24 +43,42 @@ def _lock_impl(ctx):
4543 ])
4644 args .add ("--output-file" , ctx .outputs .out )
4745 args .add_all (ctx .files .srcs )
48- args .use_param_file ("--file=%s" , use_always = True )
4946
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 ]
5061 ctx .actions .run (
5162 executable = ctx .executable .cmd ,
5263 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 ],
5766 arguments = [args ],
58- tools = [ctx . executable . cmd ],
67+ tools = [cmd ],
5968 progress_message = "Locking requirements using uv" ,
6069 env = ctx .attr .env ,
6170 )
6271
6372 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+ ),
6682 ]
6783
6884_lock = rule (
@@ -84,18 +100,23 @@ _lock = rule(
84100)
85101
86102def _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 (
92106 output = executable ,
93- substitutions = {
94- " args = []" : " args = " + render .indent (render .list (provider .args )),
95- },
107+ target_file = run_info .cmd_file ,
96108 is_executable = True ,
97109 )
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+ )
99120
100121_run_lock = rule (
101122 implementation = _run_lock_impl ,
0 commit comments