Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Build Tool Plug-ins in AggregateTarget #1390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
### Added

- `.mlpackage` files now default to being a source type #1398 @aaron-foreflight

- Added support for `Build Tool Plug-ins` in `AggregateTarget` #1390 @BarredEwe

### Fixed

- Fixed source file `includes` not working when no paths were found #1337 @shnhrrsn
Expand Down
6 changes: 6 additions & 0 deletions Sources/ProjectSpec/AggregateTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public struct AggregateTarget: ProjectTarget {
public var targets: [String]
public var settings: Settings
public var buildScripts: [BuildScript]
public var buildToolPlugins: [BuildToolPlugin]
public var configFiles: [String: String]
public var scheme: TargetScheme?
public var attributes: [String: Any]
Expand All @@ -18,6 +19,7 @@ public struct AggregateTarget: ProjectTarget {
settings: Settings = .empty,
configFiles: [String: String] = [:],
buildScripts: [BuildScript] = [],
buildToolPlugins: [BuildToolPlugin] = [],
scheme: TargetScheme? = nil,
attributes: [String: Any] = [:]
) {
Expand All @@ -26,6 +28,7 @@ public struct AggregateTarget: ProjectTarget {
self.settings = settings
self.configFiles = configFiles
self.buildScripts = buildScripts
self.buildToolPlugins = buildToolPlugins
self.scheme = scheme
self.attributes = attributes
}
Expand All @@ -46,6 +49,7 @@ extension AggregateTarget: Equatable {
lhs.settings == rhs.settings &&
lhs.configFiles == rhs.configFiles &&
lhs.buildScripts == rhs.buildScripts &&
lhs.buildToolPlugins == rhs.buildToolPlugins &&
lhs.scheme == rhs.scheme &&
NSDictionary(dictionary: lhs.attributes).isEqual(to: rhs.attributes)
}
Expand All @@ -59,6 +63,7 @@ extension AggregateTarget: NamedJSONDictionaryConvertible {
settings = jsonDictionary.json(atKeyPath: "settings") ?? .empty
configFiles = jsonDictionary.json(atKeyPath: "configFiles") ?? [:]
buildScripts = jsonDictionary.json(atKeyPath: "buildScripts") ?? []
buildToolPlugins = jsonDictionary.json(atKeyPath: "buildToolPlugins") ?? []
scheme = jsonDictionary.json(atKeyPath: "scheme")
attributes = jsonDictionary.json(atKeyPath: "attributes") ?? [:]
}
Expand All @@ -72,6 +77,7 @@ extension AggregateTarget: JSONEncodable {
"configFiles": configFiles,
"attributes": attributes,
"buildScripts": buildScripts.map { $0.toJSONValue() },
"buildToolPlugins": buildToolPlugins.map { $0.toJSONValue() },
"scheme": scheme?.toJSONValue(),
] as [String: Any?]
}
Expand Down
1 change: 1 addition & 0 deletions Sources/ProjectSpec/ProjectTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public protocol ProjectTarget: BuildSettingsContainer {
var name: String { get }
var type: PBXProductType { get }
var buildScripts: [BuildScript] { get }
var buildToolPlugins: [BuildToolPlugin] { get }
var scheme: TargetScheme? { get }
var attributes: [String: Any] { get }
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/ProjectSpec/SpecValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ extension Project {
}

errors += validateSettings(target.settings)

for buildToolPlugin in target.buildToolPlugins {
if packages[buildToolPlugin.package] == nil {
errors.append(.invalidPluginPackageReference(plugin: buildToolPlugin.plugin, package: buildToolPlugin.package))
}
}
}

for target in aggregateTargets {
Expand Down Expand Up @@ -174,12 +180,6 @@ extension Project {
errors.append(.invalidTargetSource(target: target.name, source: sourcePath.string))
}
}

for buildToolPlugin in target.buildToolPlugins {
if packages[buildToolPlugin.package] == nil {
errors.append(.invalidPluginPackageReference(plugin: buildToolPlugin.plugin, package: buildToolPlugin.package))
}
}
}

for projectReference in projectReferences {
Expand Down
46 changes: 28 additions & 18 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PBXProjGenerator {
var generated = false

private var projects: [ProjectReference: PBXProj] = [:]
lazy private var localPackageReferences: [String] = project.packages.compactMap { $0.value.isLocal ? $0.key : nil }

public init(project: Project, projectDirectory: Path? = nil) {
self.project = project
Expand Down Expand Up @@ -339,7 +340,7 @@ public class PBXProjGenerator {
return addObject(buildConfig)
}

let dependencies = target.targets.map { generateTargetDependency(from: target.name, to: $0, platform: nil) }
var dependencies = target.targets.map { generateTargetDependency(from: target.name, to: $0, platform: nil) }

let defaultConfigurationName = project.options.defaultConfig ?? project.configs.first?.name ?? ""
let buildConfigList = addObject(XCConfigurationList(
Expand All @@ -350,6 +351,9 @@ public class PBXProjGenerator {
var buildPhases: [PBXBuildPhase] = []
buildPhases += try target.buildScripts.map { try generateBuildScript(targetName: target.name, buildScript: $0) }

let packagePluginDependencies = makePackagePluginDependency(for: target)
dependencies.append(contentsOf: packagePluginDependencies)

aggregateTarget.buildPhases = buildPhases
aggregateTarget.buildConfigurationList = buildConfigList
aggregateTarget.dependencies = dependencies
Expand Down Expand Up @@ -692,7 +696,6 @@ public class PBXProjGenerator {
var systemExtensions: [PBXBuildFile] = []
var appClips: [PBXBuildFile] = []
var carthageFrameworksToEmbed: [String] = []
let localPackageReferences: [String] = project.packages.compactMap { $0.value.isLocal ? $0.key : nil }

let targetDependencies = (target.transitivelyLinkDependencies ?? project.options.transitivelyLinkDependencies) ?
getAllDependenciesPlusTransitiveNeedingEmbedding(target: target) : target.dependencies
Expand Down Expand Up @@ -1032,22 +1035,8 @@ public class PBXProjGenerator {

carthageFrameworksToEmbed = carthageFrameworksToEmbed.uniqued()

// Adding `Build Tools Plug-ins` as a dependency to the target
for buildToolPlugin in target.buildToolPlugins {
let packageReference = packageReferences[buildToolPlugin.package]
if packageReference == nil, !localPackageReferences.contains(buildToolPlugin.package) {
continue
}

let packageDependency = addObject(
XCSwiftPackageProductDependency(productName: buildToolPlugin.plugin, package: packageReference, isPlugin: true)
)
let targetDependency = addObject(
PBXTargetDependency(product: packageDependency)
)

dependencies.append(targetDependency)
}
let packagePluginDependencies = makePackagePluginDependency(for: target)
dependencies.append(contentsOf: packagePluginDependencies)

var buildPhases: [PBXBuildPhase] = []

Expand Down Expand Up @@ -1448,6 +1437,27 @@ public class PBXProjGenerator {
}
}

/// Make `Build Tools Plug-ins` as a dependency to the target
/// - Parameter target: ProjectTarget
/// - Returns: Elements for referencing other targets through content proxies.
func makePackagePluginDependency(for target: ProjectTarget) -> [PBXTargetDependency] {
target.buildToolPlugins.compactMap { buildToolPlugin in
let packageReference = packageReferences[buildToolPlugin.package]
if packageReference == nil, !localPackageReferences.contains(buildToolPlugin.package) {
return nil
}

let packageDependency = addObject(
XCSwiftPackageProductDependency(productName: buildToolPlugin.plugin, package: packageReference, isPlugin: true)
)
let targetDependency = addObject(
PBXTargetDependency(product: packageDependency)
)

return targetDependency
}
}

func getInfoPlists(for target: Target) -> [Config: String] {
var searchForDefaultInfoPlist: Bool = true
var defaultInfoPlist: String?
Expand Down
45 changes: 45 additions & 0 deletions Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
objectVersion = 54;
objects = {

/* Begin PBXAggregateTarget section */
ADD3CE771A0D5E996031A193 /* AggTarget */ = {
isa = PBXAggregateTarget;
buildConfigurationList = A7ABF1B35D9170092F822790 /* Build configuration list for PBXAggregateTarget "AggTarget" */;
buildPhases = (
);
dependencies = (
D287BAAB664D1A024D9DD57E /* PBXTargetDependency */,
);
name = AggTarget;
productName = AggTarget;
};
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
23C6626698DE560017A89F2F /* XcodeGen in Frameworks */ = {isa = PBXBuildFile; productRef = 6F7DEA2D82649EDF903FBDBD /* XcodeGen */; };
2DA7998902987953B119E4CE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26F7EFEE613987D1E1258A60 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -221,6 +235,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
ADD3CE771A0D5E996031A193 /* AggTarget */,
C99E3C420D63D5219CE57E33 /* App */,
3F8D94C4EFC431F646AAFB28 /* StaticLibrary */,
339863E54E2D955C00B56802 /* Tests */,
Expand Down Expand Up @@ -300,6 +315,10 @@
isa = PBXTargetDependency;
productRef = 5A36E2FE69703FCAC0BE8064 /* XcodeGen */;
};
D287BAAB664D1A024D9DD57E /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 896D1E2063A93D40F04D7864 /* PrefirePlaybookPlugin */;
};
D85FFB99444DD260A72DDDA7 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = AF233B61592982A7F6431FC6 /* Codability */;
Expand All @@ -315,6 +334,12 @@
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
0C023F1AE037C42683029CE9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
};
name = Debug;
};
0CCC06807E5CD8361D899B7F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -360,6 +385,12 @@
};
name = Debug;
};
5E087A904FBC0E623E672507 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
};
name = Release;
};
7A384B9B9CF42FCF9EF02057 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -565,6 +596,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
A7ABF1B35D9170092F822790 /* Build configuration list for PBXAggregateTarget "AggTarget" */ = {
isa = XCConfigurationList;
buildConfigurations = (
0C023F1AE037C42683029CE9 /* Debug */,
5E087A904FBC0E623E672507 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
Expand Down Expand Up @@ -608,6 +648,11 @@
isa = XCSwiftPackageProductDependency;
productName = XcodeGen;
};
896D1E2063A93D40F04D7864 /* PrefirePlaybookPlugin */ = {
isa = XCSwiftPackageProductDependency;
package = 348C81C327DB1710B742C370 /* XCRemoteSwiftPackageReference "Prefire" */;
productName = "plugin:PrefirePlaybookPlugin";
};
AF233B61592982A7F6431FC6 /* Codability */ = {
isa = XCSwiftPackageProductDependency;
package = 5BA91390AE78D2EE15C60091 /* XCRemoteSwiftPackageReference "Codability" */;
Expand Down