55 _transitive_deps = "transitive_deps" ,
66)
77
8-
98def _ruby_binary_impl (ctx ):
10- sdk = ctx .toolchains [TOOLCHAIN_TYPE_NAME ].ruby_runtime
11- interpreter = sdk .interpreter [DefaultInfo ].files_to_run .executable
12- init_files = [f for t in sdk .init_files for f in t .files .to_list ()]
13- init_flags = " " .join (["-r${PATH_PREFIX}%s" % f .short_path for f in init_files ])
9+ sdk = ctx .toolchains [TOOLCHAIN_TYPE_NAME ].ruby_runtime
10+ interpreter = sdk .interpreter [DefaultInfo ].files_to_run .executable
11+ init_files = [f for t in sdk .init_files for f in t .files .to_list ()]
12+ init_flags = " " .join (["-r${PATH_PREFIX}%s" % f .short_path for f in init_files ])
1413
15- main = ctx .file .main
16- if not main :
17- expected_name = "%s.rb" % ctx .attr .name
18- for f in ctx .attr .srcs :
19- if f .label .name == expected_name :
20- main = f .files .to_list ()[0 ]
21- break
22- if not main :
23- fail (
24- ("main must be present unless the name of the rule matches to one " +
25- "of the srcs" ),
26- "main" ,
27- )
14+ main = ctx .file .main
15+ if not main :
16+ expected_name = "%s.rb" % ctx .attr .name
17+ for f in ctx .attr .srcs :
18+ if f .label .name == expected_name :
19+ main = f .files .to_list ()[0 ]
20+ break
21+ if not main :
22+ fail (
23+ ("main must be present unless the name of the rule matches to one " +
24+ "of the srcs" ),
25+ "main" ,
26+ )
2827
29- executable = ctx .actions .declare_file (ctx .attr .name )
30- deps = _transitive_deps (
31- ctx ,
32- extra_files = init_files + [interpreter , executable ],
33- extra_deps = sdk .init_files + [sdk .interpreter ],
34- )
28+ executable = ctx .actions .declare_file (ctx .attr .name )
29+ deps = _transitive_deps (
30+ ctx ,
31+ extra_files = init_files + [interpreter , executable ],
32+ extra_deps = sdk .init_files + [sdk .interpreter ],
33+ )
3534
36- rubyopt = reversed (deps .rubyopt .to_list ())
37- rubyopt += ["-I${PATH_PREFIX}%s" % inc for inc in deps .incpaths .to_list ()]
35+ rubyopt = reversed (deps .rubyopt .to_list ())
36+ rubyopt += ["-I${PATH_PREFIX}%s" % inc for inc in deps .incpaths .to_list ()]
3837
39- ctx .actions .expand_template (
40- template = ctx .file ._wrapper_template ,
41- output = executable ,
42- substitutions = {
43- "{interpreter}" : interpreter .short_path ,
44- "{init_flags}" : init_flags ,
45- "{rubyopt}" : " " .join (rubyopt ),
46- "{main}" : main .short_path ,
47- "{workspace_name}" : ctx .label .workspace_name or ctx .workspace_name ,
48- },
49- is_executable = True ,
50- )
51- return [DefaultInfo (
52- executable = executable ,
53- default_runfiles = deps .default_files ,
54- data_runfiles = deps .data_files ,
55- )]
38+ ctx .actions .expand_template (
39+ template = ctx .file ._wrapper_template ,
40+ output = executable ,
41+ substitutions = {
42+ "{interpreter}" : interpreter .short_path ,
43+ "{init_flags}" : init_flags ,
44+ "{rubyopt}" : " " .join (rubyopt ),
45+ "{main}" : main .short_path ,
46+ "{workspace_name}" : ctx .label .workspace_name or ctx .workspace_name ,
47+ },
48+ is_executable = True ,
49+ )
50+ return [DefaultInfo (
51+ executable = executable ,
52+ default_runfiles = deps .default_files ,
53+ data_runfiles = deps .data_files ,
54+ )]
5655
5756_ATTRS = {
5857 "srcs" : attr .label_list (
5958 allow_files = True ,
6059 ),
6160 "deps" : attr .label_list (
62- providers = [RubyLibrary ]
61+ providers = [RubyLibrary ],
6362 ),
6463 "includes" : attr .string_list (),
6564 "rubyopt" : attr .string_list (),
@@ -69,10 +68,9 @@ _ATTRS = {
6968 "main" : attr .label (
7069 allow_single_file = True ,
7170 ),
72-
7371 "_wrapper_template" : attr .label (
74- allow_single_file = True ,
75- default = "binary_wrapper.tpl" ,
72+ allow_single_file = True ,
73+ default = "binary_wrapper.tpl" ,
7674 ),
7775}
7876
0 commit comments