@@ -210,10 +210,8 @@ package actor SwiftPMBuildSystem {
210
210
/// Maps source and header files to the target that include them.
211
211
private var fileToTargets : [ DocumentURI : Set < BuildTargetIdentifier > ] = [ : ]
212
212
213
- /// Maps target ids to their SwiftPM build target as well as the depth at which they occur in the build
214
- /// graph. Top level targets on which no other target depends have a depth of `1`. Targets with dependencies have a
215
- /// greater depth.
216
- private var targets : [ BuildTargetIdentifier : ( buildTarget: SwiftBuildTarget , depth: Int ) ] = [ : ]
213
+ /// Maps target ids to their SwiftPM build target.
214
+ private var swiftPMTargets : [ BuildTargetIdentifier : SwiftBuildTarget ] = [ : ]
217
215
218
216
private var targetDependencies : [ BuildTargetIdentifier : Set < BuildTargetIdentifier > ] = [ : ]
219
217
@@ -442,7 +440,7 @@ extension SwiftPMBuildSystem {
442
440
/// properties because otherwise we might end up in an inconsistent state
443
441
/// with only some properties modified.
444
442
445
- self . targets = [ : ]
443
+ self . swiftPMTargets = [ : ]
446
444
self . fileToTargets = [ : ]
447
445
self . targetDependencies = [ : ]
448
446
@@ -451,10 +449,7 @@ extension SwiftPMBuildSystem {
451
449
guard let targetIdentifier else {
452
450
return
453
451
}
454
- var depth = depth
455
- if let existingDepth = targets [ targetIdentifier] ? . depth {
456
- depth = max ( existingDepth, depth)
457
- } else {
452
+ if swiftPMTargets [ targetIdentifier] == nil {
458
453
for source in buildTarget. sources + buildTarget. headers {
459
454
fileToTargets [ DocumentURI ( source) , default: [ ] ] . insert ( targetIdentifier)
460
455
}
@@ -464,7 +459,7 @@ extension SwiftPMBuildSystem {
464
459
{
465
460
self . targetDependencies [ parentIdentifier, default: [ ] ] . insert ( targetIdentifier)
466
461
}
467
- targets [ targetIdentifier] = ( buildTarget, depth )
462
+ swiftPMTargets [ targetIdentifier] = buildTarget
468
463
}
469
464
470
465
await messageHandler? . sendNotificationToSourceKitLSP ( DidChangeBuildTargetNotification ( changes: nil ) )
@@ -523,9 +518,9 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
523
518
}
524
519
525
520
package func buildTargets( request: BuildTargetsRequest ) async throws -> BuildTargetsResponse {
526
- let targets = self . targets . map { ( targetId, target) in
521
+ let targets = self . swiftPMTargets . map { ( targetId, target) in
527
522
var tags : [ BuildTargetTag ] = [ . test]
528
- if target. depth != 1 {
523
+ if ! target. isPartOfRootPackage {
529
524
tags. append ( . dependency)
530
525
}
531
526
return BuildTarget (
@@ -547,10 +542,10 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
547
542
// TODO: Query The SwiftPM build system for the document's language and add it to SourceItem.data
548
543
// (https://github.com/swiftlang/sourcekit-lsp/issues/1267)
549
544
for target in request. targets {
550
- guard let swiftPMTarget = self . targets [ target] else {
545
+ guard let swiftPMTarget = self . swiftPMTargets [ target] else {
551
546
continue
552
547
}
553
- let sources = swiftPMTarget. buildTarget . sources. map {
548
+ let sources = swiftPMTarget. sources. map {
554
549
SourceItem ( uri: DocumentURI ( $0) , kind: . file, generated: false )
555
550
}
556
551
result. append ( SourcesItem ( target: target, sources: sources) )
@@ -568,13 +563,13 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
568
563
return try settings ( forPackageManifest: path)
569
564
}
570
565
571
- guard let buildTarget = self . targets [ request. target] ? . buildTarget else {
566
+ guard let swiftPMTarget = self . swiftPMTargets [ request. target] else {
572
567
logger. fault ( " Did not find target \( request. target. forLogging) " )
573
568
return nil
574
569
}
575
570
576
- if !buildTarget . sources. lazy. map ( DocumentURI . init) . contains ( request. textDocument. uri) ,
577
- let substituteFile = buildTarget . sources. sorted ( by: { $0. path < $1. path } ) . first
571
+ if !swiftPMTarget . sources. lazy. map ( DocumentURI . init) . contains ( request. textDocument. uri) ,
572
+ let substituteFile = swiftPMTarget . sources. sorted ( by: { $0. path < $1. path } ) . first
578
573
{
579
574
logger. info ( " Getting compiler arguments for \( url) using substitute file \( substituteFile) " )
580
575
// If `url` is not part of the target's source, it's most likely a header file. Fake compiler arguments for it
@@ -585,7 +580,7 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
585
580
// getting its compiler arguments and then patching up the compiler arguments by replacing the substitute file
586
581
// with the `.cpp` file.
587
582
let buildSettings = FileBuildSettings (
588
- compilerArguments: try await compilerArguments ( for: DocumentURI ( substituteFile) , in: buildTarget ) ,
583
+ compilerArguments: try await compilerArguments ( for: DocumentURI ( substituteFile) , in: swiftPMTarget ) ,
589
584
workingDirectory: projectRoot. pathString
590
585
) . patching ( newFile: try resolveSymlinks ( path) . pathString, originalFile: substituteFile. absoluteString)
591
586
return SourceKitOptionsResponse (
@@ -595,7 +590,7 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
595
590
}
596
591
597
592
return SourceKitOptionsResponse (
598
- compilerArguments: try await compilerArguments ( for: request. textDocument. uri, in: buildTarget ) ,
593
+ compilerArguments: try await compilerArguments ( for: request. textDocument. uri, in: swiftPMTarget ) ,
599
594
workingDirectory: projectRoot. pathString
600
595
)
601
596
}
@@ -635,14 +630,6 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
635
630
await self . packageLoadingQueue. async { } . valuePropagatingCancellation
636
631
}
637
632
638
- package func topologicalSort( of targets: [ BuildTargetIdentifier ] ) -> [ BuildTargetIdentifier ] ? {
639
- return targets. sorted { ( lhs: BuildTargetIdentifier , rhs: BuildTargetIdentifier ) -> Bool in
640
- let lhsDepth = self . targets [ lhs] ? . depth ?? 0
641
- let rhsDepth = self . targets [ rhs] ? . depth ?? 0
642
- return lhsDepth > rhsDepth
643
- }
644
- }
645
-
646
633
package func prepare( request: PrepareTargetsRequest ) async throws -> VoidResponse {
647
634
// TODO: Support preparation of multiple targets at once. (https://github.com/swiftlang/sourcekit-lsp/issues/1262)
648
635
for target in request. targets {
@@ -804,21 +791,6 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
804
791
}
805
792
}
806
793
807
- package func sourceFiles( ) -> [ SourceFileInfo ] {
808
- var sourceFiles : [ DocumentURI : SourceFileInfo ] = [ : ]
809
- for (buildTarget, depth) in self . targets. values {
810
- for sourceFile in buildTarget. sources {
811
- let uri = DocumentURI ( sourceFile)
812
- sourceFiles [ uri] = SourceFileInfo (
813
- uri: uri,
814
- isPartOfRootProject: depth == 1 || ( sourceFiles [ uri] ? . isPartOfRootProject ?? false ) ,
815
- mayContainTests: true
816
- )
817
- }
818
- }
819
- return sourceFiles. values. sorted { $0. uri. pseudoPath < $1. uri. pseudoPath }
820
- }
821
-
822
794
package func addSourceFilesDidChangeCallback( _ callback: @Sendable @escaping ( ) async -> Void ) async {
823
795
testFilesDidChangeCallbacks. append ( callback)
824
796
}
0 commit comments