@@ -174,6 +174,17 @@ public enum TargetBuildDescription {
174
174
}
175
175
}
176
176
177
+ /// The resources in this target.
178
+ var resources : [ Resource ] {
179
+ switch self {
180
+ case . swift( let target) :
181
+ return target. resources
182
+ case . clang( let target) :
183
+ // FIXME: Clang targets should support generated resources.
184
+ return target. target. underlyingTarget. resources
185
+ }
186
+ }
187
+
177
188
/// Path to the bundle generated for this module (if any).
178
189
var bundlePath : AbsolutePath ? {
179
190
switch self {
@@ -542,16 +553,31 @@ public final class SwiftTargetBuildDescription {
542
553
/// These are the source files derived from plugins.
543
554
private var pluginDerivedSources : Sources
544
555
556
+ /// These are the resource files derived from plugins.
557
+ private var pluginDerivedResources : [ Resource ]
558
+
545
559
/// Path to the bundle generated for this module (if any).
546
560
var bundlePath : AbsolutePath ? {
547
- buildParameters. bundlePath ( for: target)
561
+ if target. underlyingTarget. bundleName != nil {
562
+ return buildParameters. bundlePath ( for: target)
563
+ } else if !pluginDerivedResources. isEmpty {
564
+ // FIXME: Use proper bundle name here.
565
+ return buildParameters. bundlePath ( named: " foo_ \( target. name) " )
566
+ } else {
567
+ return nil
568
+ }
548
569
}
549
570
550
571
/// The list of all source files in the target, including the derived ones.
551
572
public var sources : [ AbsolutePath ] {
552
573
target. sources. paths + derivedSources. paths + pluginDerivedSources. paths
553
574
}
554
575
576
+ /// The list of all resource files in the target, including the derived ones.
577
+ public var resources : [ Resource ] {
578
+ target. underlyingTarget. resources + pluginDerivedResources
579
+ }
580
+
555
581
/// The objects in this target.
556
582
public var objects : [ AbsolutePath ] {
557
583
let relativePaths = target. sources. relativePaths + derivedSources. relativePaths + pluginDerivedSources. relativePaths
@@ -633,6 +659,9 @@ public final class SwiftTargetBuildDescription {
633
659
/// The results of running any prebuild commands for this target.
634
660
public let prebuildCommandResults : [ PrebuildCommandResult ]
635
661
662
+ /// ObservabilityScope with which to emit diagnostics
663
+ private let observabilityScope : ObservabilityScope
664
+
636
665
/// Create a new target description with target and build parameters.
637
666
init (
638
667
target: ResolvedTarget ,
@@ -642,7 +671,8 @@ public final class SwiftTargetBuildDescription {
642
671
prebuildCommandResults: [ PrebuildCommandResult ] = [ ] ,
643
672
isTestTarget: Bool ? = nil ,
644
673
isTestDiscoveryTarget: Bool = false ,
645
- fileSystem: FileSystem
674
+ fileSystem: FileSystem ,
675
+ observabilityScope: ObservabilityScope
646
676
) throws {
647
677
guard target. underlyingTarget is SwiftTarget else {
648
678
throw InternalError ( " underlying target type mismatch \( target) " )
@@ -657,24 +687,46 @@ public final class SwiftTargetBuildDescription {
657
687
self . tempsPath = buildParameters. buildPath. appending ( component: target. c99name + " .build " )
658
688
self . derivedSources = Sources ( paths: [ ] , root: tempsPath. appending ( component: " DerivedSources " ) )
659
689
self . pluginDerivedSources = Sources ( paths: [ ] , root: buildParameters. dataPath)
690
+ self . pluginDerivedResources = [ ]
660
691
self . buildToolPluginInvocationResults = buildToolPluginInvocationResults
661
692
self . prebuildCommandResults = prebuildCommandResults
693
+ self . observabilityScope = observabilityScope
694
+
695
+ func handlePluginDerivedFile( path absPath: AbsolutePath ) {
696
+ // FIXME: Carry `additionalFileRules` until here.
697
+ let rule = TargetSourcesBuilder . computeRule ( for: absPath, toolsVersion: toolsVersion, additionalFileRules: [ ] , observabilityScope: observabilityScope)
698
+ print ( " Determined \( rule) for generated file at \( absPath) " )
699
+ switch rule {
700
+ case . compile:
701
+ if absPath. extension == " swift " {
702
+ let relPath = absPath. relative ( to: self . pluginDerivedSources. root)
703
+ self . pluginDerivedSources. relativePaths. append ( relPath)
704
+ } else {
705
+ // FIXME: Error for unsupported source file type.
706
+ }
707
+ case . copy, . processResource:
708
+ if let resource = TargetSourcesBuilder . resource ( for: absPath, with: rule, defaultLocalization: target. defaultLocalization, targetName: target. name, targetPath: target. underlyingTarget. path, observabilityScope: observabilityScope) {
709
+ self . pluginDerivedResources. append ( resource)
710
+ } else {
711
+ // FIXME: Error for not obtaining a `Resource` object for a file.
712
+ }
713
+ case . header, . ignored, . modulemap, . none:
714
+ break // Ignored for now.
715
+ }
716
+ }
662
717
663
718
// Add any derived source files that were declared for any commands from plugin invocations.
664
719
for command in buildToolPluginInvocationResults. reduce ( [ ] , { $0 + $1. buildCommands } ) {
665
- // TODO: What should we do if we find non-Swift sources here?
666
720
for absPath in command. outputFiles {
667
- let relPath = absPath. relative ( to: self . pluginDerivedSources. root)
668
- self . pluginDerivedSources. relativePaths. append ( relPath)
721
+ handlePluginDerivedFile ( path: absPath)
669
722
}
670
723
}
671
724
672
725
// Add any derived source files that were discovered from output directories of prebuild commands.
673
726
for result in self . prebuildCommandResults {
674
- // TODO: What should we do if we find non-Swift sources here?
727
+ // FIXME: `derivedSourceFiles` should probably be renamed here.
675
728
for path in result. derivedSourceFiles {
676
- let relPath = path. relative ( to: self . pluginDerivedSources. root)
677
- self . pluginDerivedSources. relativePaths. append ( relPath)
729
+ handlePluginDerivedFile ( path: path)
678
730
}
679
731
}
680
732
@@ -1585,7 +1637,8 @@ public class BuildPlan {
1585
1637
toolsVersion: toolsVersion,
1586
1638
buildParameters: buildParameters,
1587
1639
isTestTarget: true ,
1588
- fileSystem: fileSystem
1640
+ fileSystem: fileSystem,
1641
+ observabilityScope: observabilityScope
1589
1642
)
1590
1643
1591
1644
result. append ( ( testProduct, desc) )
@@ -1621,7 +1674,8 @@ public class BuildPlan {
1621
1674
buildParameters: buildParameters,
1622
1675
isTestTarget: true ,
1623
1676
isTestDiscoveryTarget: true ,
1624
- fileSystem: fileSystem
1677
+ fileSystem: fileSystem,
1678
+ observabilityScope: observabilityScope
1625
1679
)
1626
1680
1627
1681
result. append ( ( testProduct, target) )
@@ -1703,7 +1757,8 @@ public class BuildPlan {
1703
1757
buildParameters: buildParameters,
1704
1758
buildToolPluginInvocationResults: buildToolPluginInvocationResults [ target] ?? [ ] ,
1705
1759
prebuildCommandResults: prebuildCommandResults [ target] ?? [ ] ,
1706
- fileSystem: fileSystem)
1760
+ fileSystem: fileSystem,
1761
+ observabilityScope: observabilityScope)
1707
1762
)
1708
1763
case is ClangTarget :
1709
1764
targetMap [ target] = try . clang( ClangTargetBuildDescription (
@@ -2238,9 +2293,11 @@ private extension Basics.Diagnostic {
2238
2293
extension BuildParameters {
2239
2294
/// Returns a target's bundle path inside the build directory.
2240
2295
fileprivate func bundlePath( for target: ResolvedTarget ) -> AbsolutePath ? {
2241
- target. underlyingTarget. bundleName
2242
- . map { $0 + triple. nsbundleExtension }
2243
- . map ( buildPath. appending ( component: ) )
2296
+ target. underlyingTarget. bundleName. map ( bundlePath ( named: ) )
2297
+ }
2298
+
2299
+ fileprivate func bundlePath( named: String ) -> AbsolutePath {
2300
+ return buildPath. appending ( component: named + triple. nsbundleExtension)
2244
2301
}
2245
2302
}
2246
2303
0 commit comments