@@ -693,6 +693,36 @@ impl Transaction<'_> {
693693 Ok ( ( ) )
694694 }
695695
696+ #[ tracing:: instrument( skip( self ) , err) ]
697+ pub async fn find_build_step_outputs (
698+ & mut self ,
699+ store_dir : & StoreDir ,
700+ drv_path : & StorePath ,
701+ ) -> sqlx:: Result < BTreeMap < OutputName , StorePath > > {
702+ let drv_path = store_dir. display ( drv_path) . to_string ( ) ;
703+ let items: Vec < ( String , String ) > = sqlx:: query_as (
704+ r"SELECT o.name, o.path
705+ FROM buildstepoutputs o
706+ JOIN buildsteps s ON s.build = o.build AND s.stepnr = o.stepnr
707+ WHERE s.drvpath = $1 AND o.path IS NOT NULL" ,
708+ )
709+ . bind ( drv_path)
710+ . fetch_all ( & mut * self . tx )
711+ . await ?;
712+
713+ items
714+ . into_iter ( )
715+ . map ( |( name, path) | -> anyhow:: Result < _ > {
716+ let name: OutputName = name. parse ( ) . context ( "invalid output name from DB" ) ?;
717+ let path: StorePath = store_dir
718+ . parse ( & path)
719+ . context ( "invalid store path from DB" ) ?;
720+ Ok ( ( name, path) )
721+ } )
722+ . collect :: < anyhow:: Result < _ > > ( )
723+ . map_err ( |e| sqlx:: Error :: Decode ( e. into_boxed_dyn_error ( ) ) )
724+ }
725+
696726 #[ tracing:: instrument( skip( self , res) , err) ]
697727 pub async fn update_build_step_in_finish (
698728 & mut self ,
@@ -941,6 +971,60 @@ impl Transaction<'_> {
941971 Ok ( step_nr)
942972 }
943973
974+ #[ tracing:: instrument(
975+ skip( self , start_time, stop_time, build_id, drv_path, outputs, ) ,
976+ err,
977+ ret
978+ ) ]
979+ pub async fn create_local_step (
980+ & mut self ,
981+ store_dir : & StoreDir ,
982+ start_time : i32 ,
983+ stop_time : i32 ,
984+ build_id : crate :: models:: BuildID ,
985+ drv_path : & StorePath ,
986+ outputs : BTreeMap < OutputName , StorePath > ,
987+ ) -> anyhow:: Result < i32 > {
988+ let step_nr = loop {
989+ if let Some ( step_nr) = self
990+ . insert_build_step (
991+ store_dir,
992+ InsertBuildStep {
993+ build_id,
994+ r#type : crate :: models:: BuildType :: Substitution ,
995+ drv_path,
996+ status : BuildStatus :: Success ,
997+ busy : false ,
998+ start_time : Some ( start_time) ,
999+ stop_time : Some ( stop_time) ,
1000+ platform : None ,
1001+ propagated_from : None ,
1002+ error_msg : None ,
1003+ machine : "" ,
1004+ } ,
1005+ )
1006+ . await ?
1007+ {
1008+ break step_nr;
1009+ }
1010+ } ;
1011+
1012+ let output_items: Vec < _ > = outputs
1013+ . into_iter ( )
1014+ . map ( |( name, path) | InsertBuildStepOutput {
1015+ build_id,
1016+ step_nr,
1017+ name,
1018+ path : Some ( path) ,
1019+ } )
1020+ . collect ( ) ;
1021+
1022+ self . insert_build_step_outputs ( store_dir, & output_items)
1023+ . await ?;
1024+
1025+ Ok ( step_nr)
1026+ }
1027+
9441028 #[ tracing:: instrument(
9451029 skip( self , start_time, stop_time, build_id, drv_path, output, ) ,
9461030 err,
0 commit comments