11"""# package_info"""
22
3- load ("//autoconf/private:providers.bzl" , "CcAutoconfInfo" )
3+ load (
4+ ":cc_autoconf_info.bzl" ,
5+ "CcAutoconfInfo" ,
6+ "encode_result" ,
7+ )
48
59_RUNNER_SOURCES = [
610 "PACKAGE_NAME" ,
@@ -84,60 +88,31 @@ def _package_info_impl(ctx):
8488 if source not in _RUNNER_SOURCES :
8589 ctx .actions .write (
8690 output = extra_results [key ],
87- content = json .encode_indent ({
88- key : {
89- "success" : True ,
90- "value" : json .encode (starlark_alias_values [source ]),
91- },
92- }, indent = " " * 4 ) + "\n " ,
91+ content = encode_result (starlark_alias_values [source ]),
9392 )
9493
9594 else :
96- # Write JSON files in check result format for PACKAGE_NAME
97- # Use regular string (not json.encode) so it goes through .dump() in check.cc
9895 ctx .actions .write (
9996 output = results ["PACKAGE_NAME" ],
100- content = json .encode_indent ({
101- "PACKAGE_NAME" : {
102- "success" : True ,
103- "value" : json .encode (ctx .attr .package_name ),
104- },
105- }, indent = " " * 4 ) + "\n " ,
97+ content = encode_result (ctx .attr .package_name ),
10698 )
10799
108- # Write JSON files in check result format for PACKAGE_VERSION
109100 ctx .actions .write (
110101 output = results ["PACKAGE_VERSION" ],
111- content = json .encode_indent ({
112- "PACKAGE_VERSION" : {
113- "success" : True ,
114- "value" : json .encode (ctx .attr .package_version ),
115- },
116- }, indent = " " * 4 ) + "\n " ,
102+ content = encode_result (ctx .attr .package_version ),
117103 )
118104
119- # Write PACKAGE_STRING as "package_name package_version"
120105 package_string = ctx .attr .package_name + " " + ctx .attr .package_version
121106 ctx .actions .write (
122107 output = results ["PACKAGE_STRING" ],
123- content = json .encode_indent ({
124- "PACKAGE_STRING" : {
125- "success" : True ,
126- "value" : json .encode (package_string ),
127- },
128- }, indent = " " * 4 ) + "\n " ,
108+ content = encode_result (package_string ),
129109 )
130110
131111 ctx .actions .write (
132112 output = results ["PACKAGE_TARNAME" ],
133- content = json .encode_indent ({
134- "PACKAGE_TARNAME" : {
135- "success" : True ,
136- "value" : json .encode (
137- ctx .attr .package_tarname if ctx .attr .package_tarname else ctx .attr .package_name ,
138- ),
139- },
140- }, indent = " " * 4 ) + "\n " ,
113+ content = encode_result (
114+ ctx .attr .package_tarname if ctx .attr .package_tarname else ctx .attr .package_name ,
115+ ),
141116 )
142117
143118 all_values = {
@@ -151,43 +126,23 @@ def _package_info_impl(ctx):
151126 for key , source in ctx .attr .aliases .items ():
152127 ctx .actions .write (
153128 output = extra_results [key ],
154- content = json .encode_indent ({
155- key : {
156- "success" : True ,
157- "value" : json .encode (all_values [source ]),
158- },
159- }, indent = " " * 4 ) + "\n " ,
129+ content = encode_result (all_values [source ]),
160130 )
161131
162132 ctx .actions .write (
163133 output = results ["PACKAGE_BUGREPORT" ],
164- content = json .encode_indent ({
165- "PACKAGE_BUGREPORT" : {
166- "success" : True ,
167- "value" : json .encode (ctx .attr .package_bugreport ),
168- },
169- }, indent = " " * 4 ) + "\n " ,
134+ content = encode_result (ctx .attr .package_bugreport ),
170135 )
171136
172137 ctx .actions .write (
173138 output = results ["PACKAGE_URL" ],
174- content = json .encode_indent ({
175- "PACKAGE_URL" : {
176- "success" : True ,
177- "value" : json .encode (ctx .attr .package_url ),
178- },
179- }, indent = " " * 4 ) + "\n " ,
139+ content = encode_result (ctx .attr .package_url ),
180140 )
181141
182- # Package info creates defines (for config.h), so put them in define_results
183- # They're not cache variables or subst values
184142 return [
185143 CcAutoconfInfo (
186144 owner = ctx .label ,
187- deps = depset (),
188- cache_results = {},
189145 define_results = results | extra_results ,
190- subst_results = {},
191146 ),
192147 ]
193148
0 commit comments