@@ -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
+ // TODO: Clang targets should support generated resources in the future.
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 {
@@ -239,7 +250,7 @@ public final class ClangTargetBuildDescription {
239
250
240
251
/// Path to the bundle generated for this module (if any).
241
252
var bundlePath : AbsolutePath ? {
242
- buildParameters. bundlePath ( for : target )
253
+ target . underlyingTarget . bundleName . map ( buildParameters. bundlePath ( named : ) )
243
254
}
244
255
245
256
/// The modulemap file for this target, if any.
@@ -542,16 +553,28 @@ 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 let bundleName = target. underlyingTarget. potentialBundleName, !resources. isEmpty {
562
+ return buildParameters. bundlePath ( named: bundleName)
563
+ } else {
564
+ return nil
565
+ }
548
566
}
549
567
550
568
/// The list of all source files in the target, including the derived ones.
551
569
public var sources : [ AbsolutePath ] {
552
570
target. sources. paths + derivedSources. paths + pluginDerivedSources. paths
553
571
}
554
572
573
+ /// The list of all resource files in the target, including the derived ones.
574
+ public var resources : [ Resource ] {
575
+ target. underlyingTarget. resources + pluginDerivedResources
576
+ }
577
+
555
578
/// The objects in this target.
556
579
public var objects : [ AbsolutePath ] {
557
580
let relativePaths = target. sources. relativePaths + derivedSources. relativePaths + pluginDerivedSources. relativePaths
@@ -633,16 +656,21 @@ public final class SwiftTargetBuildDescription {
633
656
/// The results of running any prebuild commands for this target.
634
657
public let prebuildCommandResults : [ PrebuildCommandResult ]
635
658
659
+ /// ObservabilityScope with which to emit diagnostics
660
+ private let observabilityScope : ObservabilityScope
661
+
636
662
/// Create a new target description with target and build parameters.
637
663
init (
638
664
target: ResolvedTarget ,
639
665
toolsVersion: ToolsVersion ,
666
+ additionalFileRules: [ FileRuleDescription ] = [ ] ,
640
667
buildParameters: BuildParameters ,
641
668
buildToolPluginInvocationResults: [ BuildToolPluginInvocationResult ] = [ ] ,
642
669
prebuildCommandResults: [ PrebuildCommandResult ] = [ ] ,
643
670
isTestTarget: Bool ? = nil ,
644
671
isTestDiscoveryTarget: Bool = false ,
645
- fileSystem: FileSystem
672
+ fileSystem: FileSystem ,
673
+ observabilityScope: ObservabilityScope
646
674
) throws {
647
675
guard target. underlyingTarget is SwiftTarget else {
648
676
throw InternalError ( " underlying target type mismatch \( target) " )
@@ -659,25 +687,31 @@ public final class SwiftTargetBuildDescription {
659
687
self . pluginDerivedSources = Sources ( paths: [ ] , root: buildParameters. dataPath)
660
688
self . buildToolPluginInvocationResults = buildToolPluginInvocationResults
661
689
self . prebuildCommandResults = prebuildCommandResults
690
+ self . observabilityScope = observabilityScope
662
691
663
- // Add any derived source files that were declared for any commands from plugin invocations.
692
+ // Add any derived files that were declared for any commands from plugin invocations.
693
+ var pluginDerivedFiles = [ AbsolutePath] ( )
664
694
for command in buildToolPluginInvocationResults. reduce ( [ ] , { $0 + $1. buildCommands } ) {
665
- // TODO: What should we do if we find non-Swift sources here?
666
695
for absPath in command. outputFiles {
667
- let relPath = absPath. relative ( to: self . pluginDerivedSources. root)
668
- self . pluginDerivedSources. relativePaths. append ( relPath)
696
+ pluginDerivedFiles. append ( absPath)
669
697
}
670
698
}
671
699
672
- // Add any derived source files that were discovered from output directories of prebuild commands.
700
+ // Add any derived files that were discovered from output directories of prebuild commands.
673
701
for result in self . prebuildCommandResults {
674
- // TODO: What should we do if we find non-Swift sources here?
675
- for path in result. derivedSourceFiles {
676
- let relPath = path. relative ( to: self . pluginDerivedSources. root)
677
- self . pluginDerivedSources. relativePaths. append ( relPath)
702
+ for path in result. derivedFiles {
703
+ pluginDerivedFiles. append ( path)
678
704
}
679
705
}
680
706
707
+ // Let `TargetSourcesBuilder` compute the treatment of plugin generated files.
708
+ let ( derivedSources, derivedResources) = TargetSourcesBuilder . computeContents ( for: pluginDerivedFiles, toolsVersion: toolsVersion, additionalFileRules: additionalFileRules, defaultLocalization: target. defaultLocalization, targetName: target. name, targetPath: target. underlyingTarget. path, observabilityScope: observabilityScope)
709
+ self . pluginDerivedResources = derivedResources
710
+ derivedSources. forEach { absPath in
711
+ let relPath = absPath. relative ( to: self . pluginDerivedSources. root)
712
+ self . pluginDerivedSources. relativePaths. append ( relPath)
713
+ }
714
+
681
715
if shouldEmitObjCCompatibilityHeader {
682
716
self . moduleMap = try self . generateModuleMap ( )
683
717
}
@@ -1585,7 +1619,8 @@ public class BuildPlan {
1585
1619
toolsVersion: toolsVersion,
1586
1620
buildParameters: buildParameters,
1587
1621
isTestTarget: true ,
1588
- fileSystem: fileSystem
1622
+ fileSystem: fileSystem,
1623
+ observabilityScope: observabilityScope
1589
1624
)
1590
1625
1591
1626
result. append ( ( testProduct, desc) )
@@ -1621,7 +1656,8 @@ public class BuildPlan {
1621
1656
buildParameters: buildParameters,
1622
1657
isTestTarget: true ,
1623
1658
isTestDiscoveryTarget: true ,
1624
- fileSystem: fileSystem
1659
+ fileSystem: fileSystem,
1660
+ observabilityScope: observabilityScope
1625
1661
)
1626
1662
1627
1663
result. append ( ( testProduct, target) )
@@ -1635,28 +1671,11 @@ public class BuildPlan {
1635
1671
return result
1636
1672
}
1637
1673
1638
- @available ( * , deprecated, message: " use observability system instead " )
1639
- public convenience init (
1640
- buildParameters: BuildParameters ,
1641
- graph: PackageGraph ,
1642
- buildToolPluginInvocationResults: [ ResolvedTarget : [ BuildToolPluginInvocationResult ] ] = [ : ] ,
1643
- prebuildCommandResults: [ ResolvedTarget : [ PrebuildCommandResult ] ] = [ : ] ,
1644
- diagnostics: DiagnosticsEngine ,
1645
- fileSystem: FileSystem
1646
- ) throws {
1647
- let observabilitySystem = ObservabilitySystem ( diagnosticEngine: diagnostics)
1648
- try self . init (
1649
- buildParameters: buildParameters,
1650
- graph: graph,
1651
- fileSystem: fileSystem,
1652
- observabilityScope: observabilitySystem. topScope
1653
- )
1654
- }
1655
-
1656
1674
/// Create a build plan with build parameters and a package graph.
1657
1675
public init (
1658
1676
buildParameters: BuildParameters ,
1659
1677
graph: PackageGraph ,
1678
+ additionalFileRules: [ FileRuleDescription ] = [ ] ,
1660
1679
buildToolPluginInvocationResults: [ ResolvedTarget : [ BuildToolPluginInvocationResult ] ] = [ : ] ,
1661
1680
prebuildCommandResults: [ ResolvedTarget : [ PrebuildCommandResult ] ] = [ : ] ,
1662
1681
fileSystem: FileSystem ,
@@ -1700,10 +1719,12 @@ public class BuildPlan {
1700
1719
targetMap [ target] = try . swift( SwiftTargetBuildDescription (
1701
1720
target: target,
1702
1721
toolsVersion: toolsVersion,
1722
+ additionalFileRules: additionalFileRules,
1703
1723
buildParameters: buildParameters,
1704
1724
buildToolPluginInvocationResults: buildToolPluginInvocationResults [ target] ?? [ ] ,
1705
1725
prebuildCommandResults: prebuildCommandResults [ target] ?? [ ] ,
1706
- fileSystem: fileSystem)
1726
+ fileSystem: fileSystem,
1727
+ observabilityScope: observabilityScope)
1707
1728
)
1708
1729
case is ClangTarget :
1709
1730
targetMap [ target] = try . clang( ClangTargetBuildDescription (
@@ -2236,11 +2257,9 @@ private extension Basics.Diagnostic {
2236
2257
}
2237
2258
2238
2259
extension BuildParameters {
2239
- /// Returns a target's bundle path inside the build directory.
2240
- fileprivate func bundlePath( for target: ResolvedTarget ) -> AbsolutePath ? {
2241
- target. underlyingTarget. bundleName
2242
- . map { $0 + triple. nsbundleExtension }
2243
- . map ( buildPath. appending ( component: ) )
2260
+ /// Returns a named bundle's path inside the build directory.
2261
+ fileprivate func bundlePath( named name: String ) -> AbsolutePath {
2262
+ return buildPath. appending ( component: name + triple. nsbundleExtension)
2244
2263
}
2245
2264
}
2246
2265
0 commit comments