@@ -27,6 +27,11 @@ public enum BuildDestination {
2727 case target
2828}
2929
30+ public enum BuildTargetCompiler {
31+ case swift
32+ case clang
33+ }
34+
3035public protocol BuildTarget {
3136 /// Source files in the target
3237 var sources : [ URL ] { get }
@@ -46,13 +51,18 @@ public protocol BuildTarget {
4651 /// The name of the target. It should be possible to build a target by passing this name to `swift build --target`
4752 var name : String { get }
4853
54+ /// The compiler that is responsible for building this target.
55+ var compiler : BuildTargetCompiler { get }
56+
4957 var destination : BuildDestination { get }
5058
5159 /// Whether the target is part of the root package that the user opened or if it's part of a package dependency.
5260 var isPartOfRootPackage : Bool { get }
5361
5462 var isTestTarget : Bool { get }
5563
64+ var outputPaths : [ URL ] { get throws }
65+
5666 func compileArguments( for fileURL: URL ) throws -> [ String ]
5767}
5868
@@ -100,10 +110,19 @@ private struct WrappedClangTargetBuildDescription: BuildTarget {
100110 return description. clangTarget. name
101111 }
102112
113+ var compiler : BuildTargetCompiler { . clang }
114+
115+
103116 public var destination : BuildDestination {
104117 return description. destination == . host ? . host : . target
105118 }
106119
120+ var outputPaths : [ URL ] {
121+ get throws {
122+ return try description. compilePaths ( ) . map ( \. object. asURL)
123+ }
124+ }
125+
107126 public func compileArguments( for fileURL: URL ) throws -> [ String ] {
108127 let filePath = try resolveSymlinks ( try Basics . AbsolutePath ( validating: fileURL. path) )
109128 let commandLine = try description. emitCommandLine ( for: filePath)
@@ -127,6 +146,8 @@ private struct WrappedSwiftTargetBuildDescription: BuildTarget {
127146 return description. target. name
128147 }
129148
149+ var compiler : BuildTargetCompiler { . swift }
150+
130151 public var destination : BuildDestination {
131152 return description. destination == . host ? . host : . target
132153 }
@@ -155,6 +176,15 @@ private struct WrappedSwiftTargetBuildDescription: BuildTarget {
155176 return others. map ( \. asURL)
156177 }
157178
179+ var outputPaths : [ URL ] {
180+ get throws {
181+ struct NotSupportedError : Error , CustomStringConvertible {
182+ var description : String { " Getting output paths for a Swift target is not supported " }
183+ }
184+ throw NotSupportedError ( )
185+ }
186+ }
187+
158188 func compileArguments( for fileURL: URL ) throws -> [ String ] {
159189 // Note: we ignore the `fileURL` here as the expectation is that we get a command line for the entire target
160190 // in case of Swift.
0 commit comments