@@ -82,10 +82,9 @@ def Cleanup():
8282
8383def FindOutputFile (log ):
8484 """Find the written file from the log information."""
85-
86- m = WROTE_FILE_RE .search (log )
85+ m = WROTE_FILE_RE .findall (log )
8786 if m :
88- return m . group ( 'rpm_path' )
87+ return m
8988 return None
9089
9190def SlurpFile (input_path ):
@@ -188,7 +187,7 @@ def __init__(self, name, version, release, arch, rpmbuild_path,
188187 self .arch = arch
189188 self .files = []
190189 self .rpmbuild_path = FindRpmbuild (rpmbuild_path )
191- self .rpm_path = None
190+ self .rpm_paths = None
192191 self .source_date_epoch = helpers .GetFlagValue (source_date_epoch )
193192 self .debug = debug
194193
@@ -205,6 +204,7 @@ def __init__(self, name, version, release, arch, rpmbuild_path,
205204 self .post_scriptlet = None
206205 self .preun_scriptlet = None
207206 self .postun_scriptlet = None
207+ self .subpackages = None
208208
209209 def AddFiles (self , paths , root = '' ):
210210 """Add a set of files to the current RPM.
@@ -228,6 +228,7 @@ def SetupWorkdir(self,
228228 preamble_file = None ,
229229 description_file = None ,
230230 install_script_file = None ,
231+ subpackages_file = None ,
231232 pre_scriptlet_path = None ,
232233 post_scriptlet_path = None ,
233234 preun_scriptlet_path = None ,
@@ -269,6 +270,8 @@ def SetupWorkdir(self,
269270 SlurpFile (os .path .join (original_dir , preun_scriptlet_path )) if preun_scriptlet_path is not None else ''
270271 self .postun_scriptlet = \
271272 SlurpFile (os .path .join (original_dir , postun_scriptlet_path )) if postun_scriptlet_path is not None else ''
273+ self .subpackages = \
274+ SlurpFile (os .path .join (original_dir , subpackages_file )) if subpackages_file is not None else ''
272275
273276 # Then prepare for textual substitution. This is typically only the case for the
274277 # experimental `pkg_rpm`.
@@ -277,6 +280,7 @@ def SetupWorkdir(self,
277280 'POST_SCRIPTLET' : ("%post\n " + self .post_scriptlet ) if self .post_scriptlet else "" ,
278281 'PREUN_SCRIPTLET' : ("%preun\n " + self .preun_scriptlet ) if self .preun_scriptlet else "" ,
279282 'POSTUN_SCRIPTLET' : ("%postun\n " + self .postun_scriptlet ) if self .postun_scriptlet else "" ,
283+ 'SUBPACKAGES' : (self .subpackages if self .subpackages else "" ),
280284 'CHANGELOG' : ""
281285 }
282286
@@ -406,9 +410,9 @@ def CallRpmBuild(self, dirname, rpmbuild_args):
406410
407411 if p .returncode == 0 :
408412 # Find the created file.
409- self .rpm_path = FindOutputFile (output )
413+ self .rpm_paths = FindOutputFile (output )
410414
411- if p .returncode != 0 or not self .rpm_path :
415+ if p .returncode != 0 or not self .rpm_paths :
412416 print ('Error calling rpmbuild:' )
413417 print (output )
414418 elif self .debug :
@@ -417,20 +421,33 @@ def CallRpmBuild(self, dirname, rpmbuild_args):
417421 # Return the status.
418422 return p .returncode
419423
420- def SaveResult (self , out_file ):
424+ def SaveResult (self , out_file , subpackage_out_files ):
421425 """Save the result RPM out of the temporary working directory."""
422426
423- if self .rpm_path :
424- shutil .copy (self .rpm_path , out_file )
427+ if self .rpm_paths :
428+ rpm_path = self .rpm_paths [0 ]
429+ shutil .copy (rpm_path , out_file )
425430 if self .debug :
426431 print ('Saved RPM file to %s' % out_file )
432+
433+ subrpm_paths = self .rpm_paths [1 :]
434+ for s_name , s_out_file in subpackage_out_files :
435+ s_prefix = self .name + '-' + s_name
436+
437+ for p in subrpm_paths :
438+ if os .path .basename (p ).startswith (s_prefix ):
439+ shutil .copy (p , s_out_file )
440+ if self .debug :
441+ print ('Saved %s sub RPM file to %s' % (s_name , s_out_file ))
442+ break
427443 else :
428444 print ('No RPM file created.' )
429445
430- def Build (self , spec_file , out_file ,
446+ def Build (self , spec_file , out_file , subpackage_out_files ,
431447 preamble_file = None ,
432448 description_file = None ,
433449 install_script_file = None ,
450+ subpackages_file = None ,
434451 pre_scriptlet_path = None ,
435452 post_scriptlet_path = None ,
436453 preun_scriptlet_path = None ,
@@ -446,20 +463,24 @@ def Build(self, spec_file, out_file,
446463 original_dir = os .getcwd ()
447464 spec_file = os .path .join (original_dir , spec_file )
448465 out_file = os .path .join (original_dir , out_file )
466+ subpackage_out_files = (s .split (':' ) for s in subpackage_out_files )
467+ subpackage_out_files = [
468+ (s [0 ], os .path .join (original_dir , s [1 ])) for s in subpackage_out_files ]
449469 with Tempdir () as dirname :
450470 self .SetupWorkdir (spec_file ,
451471 original_dir ,
452472 preamble_file = preamble_file ,
453473 description_file = description_file ,
454474 install_script_file = install_script_file ,
475+ subpackages_file = subpackages_file ,
455476 file_list_path = file_list_path ,
456477 pre_scriptlet_path = pre_scriptlet_path ,
457478 post_scriptlet_path = post_scriptlet_path ,
458479 preun_scriptlet_path = preun_scriptlet_path ,
459480 postun_scriptlet_path = postun_scriptlet_path ,
460481 changelog_file = changelog_file )
461482 status = self .CallRpmBuild (dirname , rpmbuild_args or [])
462- self .SaveResult (out_file )
483+ self .SaveResult (out_file , subpackage_out_files )
463484
464485 return status
465486
@@ -482,6 +503,9 @@ def main(argv):
482503 help = 'The file containing the RPM specification.' )
483504 parser .add_argument ('--out_file' , required = True ,
484505 help = 'The destination to save the resulting RPM file to.' )
506+ parser .add_argument ('--subpackage_out_file' , action = 'append' ,
507+ help = 'List of destinations to save resulting ' +
508+ 'subpackage RPMs to in the form of name:destination' )
485509 parser .add_argument ('--rpmbuild' , help = 'Path to rpmbuild executable.' )
486510 parser .add_argument ('--source_date_epoch' ,
487511 help = 'Value for the SOURCE_DATE_EPOCH rpmbuild '
@@ -498,6 +522,8 @@ def main(argv):
498522 help = 'File containing the RPM Preamble' )
499523 parser .add_argument ('--description' ,
500524 help = 'File containing the RPM %description text' )
525+ parser .add_argument ('--subpackages' ,
526+ help = 'File containing the RPM subpackage details' )
501527 parser .add_argument ('--pre_scriptlet' ,
502528 help = 'File containing the RPM %pre scriptlet, if to be substituted' )
503529 parser .add_argument ('--post_scriptlet' ,
@@ -528,9 +554,11 @@ def main(argv):
528554 debug = options .debug )
529555 builder .AddFiles (options .files )
530556 return builder .Build (options .spec_file , options .out_file ,
557+ options .subpackage_out_file ,
531558 preamble_file = options .preamble ,
532559 description_file = options .description ,
533560 install_script_file = options .install_script ,
561+ subpackages_file = options .subpackages ,
534562 file_list_path = options .file_list ,
535563 pre_scriptlet_path = options .pre_scriptlet ,
536564 post_scriptlet_path = options .post_scriptlet ,
0 commit comments