@@ -151,20 +151,20 @@ def _make_absolute_if_not_already_or_is_macro(path):
151151# TODO(nacl, #459): These are redundant with functions and structures in
152152# pkg/private/pkg_files.bzl. We should really use the infrastructure provided
153153# there, but as of writing, it's not quite ready.
154- def _process_files (pfi , origin_label , grouping_label , file_base , dest_check_map , packaged_directories , rpm_files_list , install_script_pieces ):
154+ def _process_files (pfi , origin_label , grouping_label , file_base , process_ctx ):
155155 for dest , src in pfi .dest_src_map .items ():
156156 metadata = _package_contents_metadata (origin_label , grouping_label )
157- if dest in dest_check_map :
158- _conflicting_contents_error (dest , metadata , dest_check_map [dest ])
157+ if dest in process_ctx . dest_check_map :
158+ _conflicting_contents_error (dest , metadata , process_ctx . dest_check_map [dest ])
159159 else :
160- dest_check_map [dest ] = metadata
160+ process_ctx . dest_check_map [dest ] = metadata
161161
162162 abs_dest = _make_absolute_if_not_already_or_is_macro (dest )
163163 if src .is_directory :
164164 # Set aside TreeArtifact information for external processing
165165 #
166166 # @unsorted-dict-items
167- packaged_directories .append ({
167+ process_ctx . packaged_directories .append ({
168168 "src" : src ,
169169 "dest" : abs_dest ,
170170 # This doesn't exactly make it extensible, but it saves
@@ -174,43 +174,43 @@ def _process_files(pfi, origin_label, grouping_label, file_base, dest_check_map,
174174 })
175175 else :
176176 # Files are well-known. Take care of them right here.
177- rpm_files_list .append (_FILE_MODE_STANZA_FMT .format (file_base , abs_dest ))
178- install_script_pieces .append (_INSTALL_FILE_STANZA_FMT .format (
177+ process_ctx . rpm_files_list .append (_FILE_MODE_STANZA_FMT .format (file_base , abs_dest ))
178+ process_ctx . install_script_pieces .append (_INSTALL_FILE_STANZA_FMT .format (
179179 src .path ,
180180 abs_dest ,
181181 ))
182182
183- def _process_dirs (pdi , origin_label , grouping_label , file_base , dest_check_map , packaged_directories , rpm_files_list , install_script_pieces ):
183+ def _process_dirs (pdi , origin_label , grouping_label , file_base , process_ctx ):
184184 for dest in pdi .dirs :
185185 metadata = _package_contents_metadata (origin_label , grouping_label )
186- if dest in dest_check_map :
187- _conflicting_contents_error (dest , metadata , dest_check_map [dest ])
186+ if dest in process_ctx . dest_check_map :
187+ _conflicting_contents_error (dest , metadata , process_ctx . dest_check_map [dest ])
188188 else :
189- dest_check_map [dest ] = metadata
189+ process_ctx . dest_check_map [dest ] = metadata
190190
191191 abs_dirname = _make_absolute_if_not_already_or_is_macro (dest )
192- rpm_files_list .append (_FILE_MODE_STANZA_FMT .format (file_base , abs_dirname ))
192+ process_ctx . rpm_files_list .append (_FILE_MODE_STANZA_FMT .format (file_base , abs_dirname ))
193193
194- install_script_pieces .append (_INSTALL_DIR_STANZA_FMT .format (
194+ process_ctx . install_script_pieces .append (_INSTALL_DIR_STANZA_FMT .format (
195195 abs_dirname ,
196196 ))
197197
198- def _process_symlink (psi , origin_label , grouping_label , file_base , dest_check_map , packaged_directories , rpm_files_list , install_script_pieces ):
198+ def _process_symlink (psi , origin_label , grouping_label , file_base , process_ctx ):
199199 metadata = _package_contents_metadata (origin_label , grouping_label )
200- if psi .destination in dest_check_map :
201- _conflicting_contents_error (psi .destination , metadata , dest_check_map [psi .destination ])
200+ if psi .destination in process_ctx . dest_check_map :
201+ _conflicting_contents_error (psi .destination , metadata , process_ctx . dest_check_map [psi .destination ])
202202 else :
203- dest_check_map [psi .destination ] = metadata
203+ process_ctx . dest_check_map [psi .destination ] = metadata
204204
205205 abs_dest = _make_absolute_if_not_already_or_is_macro (psi .destination )
206- rpm_files_list .append (_FILE_MODE_STANZA_FMT .format (file_base , abs_dest ))
207- install_script_pieces .append (_INSTALL_SYMLINK_STANZA_FMT .format (
206+ process_ctx . rpm_files_list .append (_FILE_MODE_STANZA_FMT .format (file_base , abs_dest ))
207+ process_ctx . install_script_pieces .append (_INSTALL_SYMLINK_STANZA_FMT .format (
208208 abs_dest ,
209209 psi .target ,
210210 psi .attributes ["mode" ],
211211 ))
212212
213- def _process_dep (dep , dest_check_map , packaged_directories , rpm_files_list , install_script_pieces ):
213+ def _process_dep (dep , process_ctx ):
214214 # NOTE: This does not detect cases where directories are not named
215215 # consistently. For example, all of these may collide in reality, but
216216 # won't be detected by the below:
@@ -233,10 +233,7 @@ def _process_dep(dep, dest_check_map, packaged_directories, rpm_files_list, inst
233233 dep .label , # origin label
234234 None , # group label
235235 _make_filetags (dep [PackageFilesInfo ].attributes ), # file_base
236- dest_check_map ,
237- packaged_directories ,
238- rpm_files_list ,
239- install_script_pieces ,
236+ process_ctx ,
240237 )
241238
242239 if PackageDirsInfo in dep :
@@ -245,10 +242,7 @@ def _process_dep(dep, dest_check_map, packaged_directories, rpm_files_list, inst
245242 dep .label , # origin label
246243 None , # group label
247244 _make_filetags (dep [PackageDirsInfo ].attributes , "%dir" ), # file_base
248- dest_check_map ,
249- packaged_directories ,
250- rpm_files_list ,
251- install_script_pieces ,
245+ process_ctx ,
252246 )
253247
254248 if PackageSymlinkInfo in dep :
@@ -257,10 +251,7 @@ def _process_dep(dep, dest_check_map, packaged_directories, rpm_files_list, inst
257251 dep .label , # origin label
258252 None , # group label
259253 _make_filetags (dep [PackageSymlinkInfo ].attributes ), # file_base
260- dest_check_map ,
261- packaged_directories ,
262- rpm_files_list ,
263- install_script_pieces ,
254+ process_ctx ,
264255 )
265256
266257 if PackageFilegroupInfo in dep :
@@ -272,10 +263,7 @@ def _process_dep(dep, dest_check_map, packaged_directories, rpm_files_list, inst
272263 origin ,
273264 dep .label ,
274265 file_base ,
275- dest_check_map ,
276- packaged_directories ,
277- rpm_files_list ,
278- install_script_pieces ,
266+ process_ctx ,
279267 )
280268 for entry , origin in pfg_info .pkg_dirs :
281269 file_base = _make_filetags (entry .attributes , "%dir" )
@@ -284,10 +272,7 @@ def _process_dep(dep, dest_check_map, packaged_directories, rpm_files_list, inst
284272 origin ,
285273 dep .label ,
286274 file_base ,
287- dest_check_map ,
288- packaged_directories ,
289- rpm_files_list ,
290- install_script_pieces ,
275+ process_ctx ,
291276 )
292277
293278 for entry , origin in pfg_info .pkg_symlinks :
@@ -297,10 +282,7 @@ def _process_dep(dep, dest_check_map, packaged_directories, rpm_files_list, inst
297282 origin ,
298283 dep .label ,
299284 file_base ,
300- dest_check_map ,
301- packaged_directories ,
302- rpm_files_list ,
303- install_script_pieces ,
285+ process_ctx ,
304286 )
305287
306288#### Rule implementation
@@ -571,8 +553,15 @@ def _pkg_rpm_impl(ctx):
571553 # produce an installation script that is longer than necessary. A better
572554 # implementation would track directories that are created and ensure that
573555 # they aren't unnecessarily recreated.
556+
557+ process_ctx = struct (
558+ dest_check_map = dest_check_map ,
559+ packaged_directories = packaged_directories ,
560+ rpm_files_list = rpm_files_list ,
561+ install_script_pieces = install_script_pieces ,
562+ )
574563 for dep in ctx .attr .srcs :
575- _process_dep (dep , dest_check_map , packaged_directories , rpm_files_list , install_script_pieces )
564+ _process_dep (dep , process_ctx )
576565
577566 #### Procedurally-generated scripts/lists (%install, %files)
578567
0 commit comments