@@ -345,6 +345,12 @@ class BuildResult(models.Model):
345345 string = 'Build type' )
346346
347347 parent_id = fields .Many2one ('runbot.build' , 'Parent Build' , index = True )
348+ parent_link_ids = fields .One2many ('runbot.build.link' , 'child_id' , string = 'Used in links' )
349+ parent_ids = fields .Many2many ('runbot.build' , related = 'parent_link_ids.parent_id' )
350+
351+ child_link_ids = fields .One2many ('runbot.build.link' , 'parent_id' , string = 'Child links' )
352+
353+
348354 parent_path = fields .Char ('Parent path' , index = True )
349355 top_parent = fields .Many2one ('runbot.build' , compute = '_compute_top_parent' )
350356 ancestors = fields .Many2many ('runbot.build' , compute = '_compute_ancestors' )
@@ -525,7 +531,7 @@ def write(self, values):
525531
526532 return res
527533
528- def _add_child (self , param_values , orphan = False , description = False , additionnal_commit_links = False ):
534+ def _add_child (self , param_values , orphan = False , description = False , additionnal_commit_links = False , link = False ):
529535 build_values = {key : value for key , value in param_values .items () if key not in self .params_id ._fields }
530536 param_values = {key : value for key , value in param_values .items () if key in self .params_id ._fields }
531537
@@ -538,17 +544,40 @@ def _add_child(self, param_values, orphan=False, description=False, additionnal_
538544 commit_link_ids |= additionnal_commit_links
539545 param_values ['commit_link_ids' ] = commit_link_ids
540546
541- return self .create ({
542- 'params_id' : self .params_id .copy (param_values ).id ,
543- 'parent_id' : self .id ,
547+ params = self .params_id .copy (param_values )
548+
549+ build_values = {
550+ 'params_id' : params .id ,
544551 'build_type' : self .build_type ,
545552 'priority_level' : self .priority_level ,
546553 'description' : description ,
547554 'orphan_result' : orphan ,
548555 'keep_host' : self .keep_host ,
549556 'host' : self .host if self .keep_host else False ,
550557 ** build_values ,
551- })
558+ }
559+
560+ if link :
561+ existing_builds = params .build_ids
562+ if self .keep_host :
563+ existing_builds = existing_builds .filtered (lambda b : b .host == self .host )
564+ if existing_builds :
565+ build = existing_builds .sorted ('id' )[- 1 ]
566+ build .killable = False
567+
568+ if build :
569+ build = self .create (build_values )
570+
571+ self .env ['runbot.build.link' ].create ({
572+ 'parent_id' : self .id ,
573+ 'child_id' : link ,
574+ })
575+ return build
576+ else :
577+ return self .create ({
578+ 'parent_id' : self .id ,
579+ ** build_values ,
580+ })
552581
553582 @api .depends ('params_id.version_id.name' )
554583 def _compute_dest (self ):
@@ -1627,5 +1656,5 @@ class BuildLink(models.Model):
16271656
16281657 parent_id = fields .Many2one ('runbot.build' , string = 'Parent Build' , required = True , ondelete = 'cascade' )
16291658 child_id = fields .Many2one ('runbot.build' , string = 'Child Build' , required = True , ondelete = 'cascade' )
1630- params_id = fields .Many2one ('runbot.params' , string = 'Params' , related = 'child_id.params_id' , store = True )
1631-
1659+ params_id = fields .Many2one ('runbot.build. params' , string = 'Params' , related = 'child_id.params_id' , store = True )
1660+ orphan_result = fields . Boolean ( string = 'Orphan Result' , help = 'If set, the result of the child build will not be taken into account for the parent build result' )
0 commit comments