@@ -109,7 +109,9 @@ func withSession(
109109    } 
110110} 
111111
112- private  final  class  PlanningOperationDelegate :  SWBPlanningOperationDelegate ,  Sendable  { 
112+ package final  class  SwiftBuildSystemPlanningOperationDelegate :  SWBPlanningOperationDelegate ,  SWBIndexingDelegate ,  Sendable  { 
113+     package init ( )  { } 
114+     
113115    public  func  provisioningTaskInputs( 
114116        targetGUID:  String , 
115117        provisioningSourceData:  SWBProvisioningTaskInputsSourceData 
@@ -194,7 +196,7 @@ public struct PluginConfiguration {
194196} 
195197
196198public  final  class  SwiftBuildSystem :  SPMBuildCore . BuildSystem  { 
197-     private  let  buildParameters :  BuildParameters 
199+     package let  buildParameters :  BuildParameters 
198200    private  let  packageGraphLoader :  ( )  async  throws  ->  ModulesGraph 
199201    private  let  packageManagerResourcesDirectory :  Basics . AbsolutePath ? 
200202    private  let  logLevel :  Basics . Diagnostic . Severity 
@@ -349,7 +351,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
349351            ) 
350352        } 
351353
352-         try await  writePIF ( buildParameters :  buildParameters ) 
354+         try await  writePIF ( ) 
353355
354356        return  try await  startSWBuildOperation ( 
355357            pifTargetName:  subset. pifTargetName, 
@@ -545,7 +547,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
545547
546548                    let  operation  =  try await  session. createBuildOperation ( 
547549                        request:  request, 
548-                         delegate:  PlanningOperationDelegate ( ) 
550+                         delegate:  SwiftBuildSystemPlanningOperationDelegate ( ) 
549551                    ) 
550552
551553                    var  buildState  =  BuildState ( ) 
@@ -631,7 +633,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
631633        ) 
632634    } 
633635
634-     private  func  makeBuildParameters( session:  SWBBuildServiceSession ,  genSymbolGraph:  Bool )  async  throws  ->  SwiftBuild . SWBBuildParameters  { 
636+     package func  makeBuildParameters( session:  SWBBuildServiceSession ,  genSymbolGraph:  Bool )  async  throws  ->  SwiftBuild . SWBBuildParameters  { 
635637        // Generate the run destination parameters.
636638        let  runDestination  =  makeRunDestination ( ) 
637639
@@ -767,8 +769,8 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
767769            buildProductsPath:  ddPathPrefix +  " /Products " , 
768770            buildIntermediatesPath:  ddPathPrefix +  " /Intermediates.noindex " , 
769771            pchPath:  ddPathPrefix +  " /PCH " , 
770-             indexRegularBuildProductsPath:  nil , 
771-             indexRegularBuildIntermediatesPath:  nil , 
772+             indexRegularBuildProductsPath:  ddPathPrefix  +   " /Index/Products " , 
773+             indexRegularBuildIntermediatesPath:  ddPathPrefix  +   " /Index/Intermediates.noindex " , 
772774            indexPCHPath:  ddPathPrefix, 
773775            indexDataStoreFolderPath:  ddPathPrefix, 
774776            indexEnableDataStore:  request. parameters. arenaInfo? . indexEnableDataStore ??  false 
@@ -902,7 +904,9 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
902904        } 
903905    } 
904906
905-     public  func  writePIF( buildParameters:  BuildParameters )  async  throws  { 
907+     public  func  writePIF( )  async  throws  { 
908+         pifBuilder =  . init( ) 
909+         packageGraph =  . init( ) 
906910        let  pifBuilder  =  try await  getPIFBuilder ( ) 
907911        let  pif  =  try await  pifBuilder. generatePIF ( 
908912            printPIFManifestGraphviz:  buildParameters. printPIFManifestGraphviz, 
@@ -912,6 +916,27 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
912916        try self . fileSystem. writeIfChanged ( path:  buildParameters. pifManifest,  string:  pif) 
913917    } 
914918
919+     package struct  LongLivedBuildServiceSession  { 
920+         package var  session :  SWBBuildServiceSession 
921+         package var  diagnostics :  [ SwiftBuildMessage . DiagnosticInfo ] 
922+         package var  teardownHandler :  ( )  async  throws  ->  Void 
923+     } 
924+ 
925+     package func  createLongLivedSession( name:  String )  async  throws  ->  LongLivedBuildServiceSession  { 
926+         let  service  =  try await  SWBBuildService ( connectionMode:  . inProcessStatic( swiftbuildServiceEntryPoint) ) 
927+         do  { 
928+             let  ( session,  diagnostics)  =  try await  createSession ( service:  service,  name:  name,  toolchainPath:  buildParameters. toolchain. toolchainDir,  packageManagerResourcesDirectory:  packageManagerResourcesDirectory) 
929+             let  teardownHandler  =  { 
930+                 try await  session. close ( ) 
931+                 await  service. close ( ) 
932+             } 
933+             return  LongLivedBuildServiceSession ( session:  session,  diagnostics:  diagnostics,  teardownHandler:  teardownHandler) 
934+         }  catch  { 
935+             await  service. close ( ) 
936+             throw  error
937+         } 
938+     } 
939+ 
915940    public  func  cancel( deadline:  DispatchTime )  throws  { } 
916941
917942    /// Returns the package graph using the graph loader closure.
0 commit comments