@@ -15,6 +15,8 @@ import PackageLoading
15
15
import PackageModel
16
16
import class PackageGraph. ResolvedTarget
17
17
import struct SPMBuildCore. BuildParameters
18
+ import struct SPMBuildCore. BuildToolPluginInvocationResult
19
+ import struct SPMBuildCore. PrebuildCommandResult
18
20
19
21
import enum TSCBasic. ProcessEnv
20
22
@@ -41,9 +43,22 @@ public final class ClangTargetBuildDescription {
41
43
buildParameters. buildEnvironment
42
44
}
43
45
46
+ /// The list of all resource files in the target, including the derived ones.
47
+ public var resources : [ Resource ] {
48
+ self . target. underlyingTarget. resources + self . pluginDerivedResources
49
+ }
50
+
44
51
/// Path to the bundle generated for this module (if any).
45
52
var bundlePath : AbsolutePath ? {
46
- target. underlyingTarget. bundleName. map ( buildParameters. bundlePath ( named: ) )
53
+ guard !resources. isEmpty else {
54
+ return . none
55
+ }
56
+
57
+ if let bundleName = target. underlyingTarget. potentialBundleName {
58
+ return self . buildParameters. bundlePath ( named: bundleName)
59
+ } else {
60
+ return . none
61
+ }
47
62
}
48
63
49
64
/// The modulemap file for this target, if any.
@@ -57,6 +72,12 @@ public final class ClangTargetBuildDescription {
57
72
/// These are the source files generated during the build.
58
73
private var derivedSources : Sources
59
74
75
+ /// These are the source files derived from plugins.
76
+ private var pluginDerivedSources : Sources
77
+
78
+ /// These are the resource files derived from plugins.
79
+ private var pluginDerivedResources : [ Resource ]
80
+
60
81
/// Path to the resource accessor header file, if generated.
61
82
public private( set) var resourceAccessorHeaderFile : AbsolutePath ?
62
83
@@ -84,12 +105,19 @@ public final class ClangTargetBuildDescription {
84
105
target. type == . test
85
106
}
86
107
108
+ /// The results of applying any build tool plugins to this target.
109
+ public let buildToolPluginInvocationResults : [ BuildToolPluginInvocationResult ]
110
+
87
111
/// Create a new target description with target and build parameters.
88
112
init (
89
113
target: ResolvedTarget ,
90
114
toolsVersion: ToolsVersion ,
115
+ additionalFileRules: [ FileRuleDescription ] = [ ] ,
91
116
buildParameters: BuildParameters ,
92
- fileSystem: FileSystem
117
+ buildToolPluginInvocationResults: [ BuildToolPluginInvocationResult ] = [ ] ,
118
+ prebuildCommandResults: [ PrebuildCommandResult ] = [ ] ,
119
+ fileSystem: FileSystem ,
120
+ observabilityScope: ObservabilityScope
93
121
) throws {
94
122
guard target. underlyingTarget is ClangTarget else {
95
123
throw InternalError ( " underlying target type mismatch \( target) " )
@@ -102,6 +130,25 @@ public final class ClangTargetBuildDescription {
102
130
self . tempsPath = buildParameters. buildPath. appending ( component: target. c99name + " .build " )
103
131
self . derivedSources = Sources ( paths: [ ] , root: tempsPath. appending ( " DerivedSources " ) )
104
132
133
+ // We did not use to apply package plugins to C-family targets in prior tools-versions, this preserves the behavior.
134
+ if toolsVersion >= . v5_9 {
135
+ self . buildToolPluginInvocationResults = buildToolPluginInvocationResults
136
+
137
+ ( self . pluginDerivedSources, self . pluginDerivedResources) = SharedTargetBuildDescription . computePluginGeneratedFiles (
138
+ target: target,
139
+ toolsVersion: toolsVersion,
140
+ additionalFileRules: additionalFileRules,
141
+ buildParameters: buildParameters,
142
+ buildToolPluginInvocationResults: buildToolPluginInvocationResults,
143
+ prebuildCommandResults: prebuildCommandResults,
144
+ observabilityScope: observabilityScope
145
+ )
146
+ } else {
147
+ self . buildToolPluginInvocationResults = [ ]
148
+ self . pluginDerivedSources = Sources ( paths: [ ] , root: buildParameters. dataPath)
149
+ self . pluginDerivedResources = [ ]
150
+ }
151
+
105
152
// Try computing modulemap path for a C library. This also creates the file in the file system, if needed.
106
153
if target. type == . library {
107
154
// If there's a custom module map, use it as given.
@@ -141,6 +188,7 @@ public final class ClangTargetBuildDescription {
141
188
let sources = [
142
189
target. sources. root: target. sources. relativePaths,
143
190
derivedSources. root: derivedSources. relativePaths,
191
+ pluginDerivedSources. root: pluginDerivedSources. relativePaths
144
192
]
145
193
146
194
return try sources. flatMap { root, relativePaths in
0 commit comments