Commit 6972584a authored by Drew's avatar Drew

Add target dependency

Test targets must depend on app targets, otherwise they won't link successfully
parent e881a857
Pipeline #1797 passed with stage
......@@ -39,14 +39,14 @@ func emit(task: Task, testTask: Task?, package: Package) {
}
func process(tasks: [Task], testTask: Task?, package: Package) -> [PbxprojSerializable] {
func process(tasks: [Task], testTask: Task?, package: Package, xcodeprojGUID: String) -> [PbxprojSerializable] {
let task = tasks[0] //pull off head
//are there dependencies?
var objects: [PbxprojSerializable] = []
if tasks.count > 1 {
let nextTasks = Array(tasks[1..<tasks.count])
objects.append(contentsOf: process(tasks: nextTasks, testTask: nil, package: package))
objects.append(contentsOf: process(tasks: nextTasks, testTask: nil, package: package, xcodeprojGUID: xcodeprojGUID))
}
guard let taskname = task["name"]?.string else { fatalError("No task name.")}
guard let sourceDescriptions = task["sources"]?.vector?.flatMap({$0.string}) else { fatalError("Can't find sources for atllbuild.") }
......@@ -103,7 +103,7 @@ func process(tasks: [Task], testTask: Task?, package: Package) -> [PbxprojSerial
let target = PbxNativeTarget(productReference: product, outputType: outputType, sourceFiles: sourceRefs, linkFiles: linkWith, appTarget: nil)
let target = PbxNativeTarget(productReference: product, outputType: outputType, sourceFiles: sourceRefs, linkFiles: linkWith, appTarget: nil, xcodeprojGUID: xcodeprojGUID )
objects.append(target)
objects.append(product)
......@@ -111,7 +111,7 @@ func process(tasks: [Task], testTask: Task?, package: Package) -> [PbxprojSerial
guard let testSourceDescriptions = testTask["sources"]?.vector?.flatMap({$0.string}) else { fatalError("Can't find sources for atllbuild.") }
let sources = collectSources(sourceDescriptions: testSourceDescriptions, taskForCalculatingPath: testTask).map() {PbxSourceFileReference(path: $0.description)}
let testProduct = PbxProductReference(name: taskname+"Tests", type: .TestTarget)
let testTarget = PbxNativeTarget(productReference: testProduct, outputType: .TestTarget, sourceFiles: sources, linkFiles: [], appTarget: target)
let testTarget = PbxNativeTarget(productReference: testProduct, outputType: .TestTarget, sourceFiles: sources, linkFiles: [], appTarget: target, xcodeprojGUID: xcodeprojGUID)
objects.append(testProduct)
objects.append(testTarget)
for o in sources {
......@@ -130,14 +130,15 @@ func process(tasks: [Task], testTask: Task?, package: Package) -> [PbxprojSerial
}
func pbxproj(task: Task, testTask: Task?, package: Package) -> Pbxproj {
let guid = xcodeguid()
var targets : [PbxNativeTarget] = []
var objects = process(tasks: package.prunedDependencyGraph(task: task).reversed(), testTask: testTask, package: package)
var objects = process(tasks: package.prunedDependencyGraph(task: task).reversed(), testTask: testTask, package: package, xcodeprojGUID: guid)
for object in objects {
if object.dynamicType == PbxNativeTarget.self {
targets.append(object as! PbxNativeTarget)
}
}
let project = Pbxproject(targets: targets)
let project = Pbxproject( guid: guid, targets: targets)
objects.append(project)
let groups = PbxGroups(targets: targets)
objects.append(groups)
......
......@@ -17,7 +17,7 @@ import atfoundation
private func xcodeguid() -> String {
func xcodeguid() -> String {
let choices = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]
var guid = ""
for _ in 0..<24 {
......@@ -52,7 +52,7 @@ struct Pbxproj: PbxprojSerializable {
struct Pbxproject: PbxprojSerializable {
let guid = xcodeguid()
let guid : String
var targets: [PbxNativeTarget]
let hacks = PbxConfigurationHacks()
......@@ -288,6 +288,8 @@ struct PbxNativeTarget: PbxprojSerializable {
let linkFiles: [PbxProductReference]
let configurationList: PbxTargetConfigurations
let dependencies: [PbxTargetDependency]
let appTarget: TargetWrapper?
//todo: This should be a more generic type than plists
......@@ -295,7 +297,7 @@ struct PbxNativeTarget: PbxprojSerializable {
let phases: PbxPhases
init(productReference: PbxProductReference, outputType: OutputType, sourceFiles: [PbxSourceFileReference], linkFiles:[PbxProductReference], appTarget: PbxNativeTarget?) {
init(productReference: PbxProductReference, outputType: OutputType, sourceFiles: [PbxSourceFileReference], linkFiles:[PbxProductReference], appTarget: PbxNativeTarget?, xcodeprojGUID: String) {
if let a = appTarget {
self.appTarget = TargetWrapper(target: a)
}
......@@ -338,6 +340,7 @@ struct PbxNativeTarget: PbxprojSerializable {
try! s.write(to: Path(plistName))
self.otherFiles = [PbxPlistFileReference(path: plistName)]
self.configurationList = PbxTargetConfigurations(plistPath: plistName, testThisApp: nil)
self.dependencies = []
case .TestTarget:
var s = ""
s += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
......@@ -370,10 +373,12 @@ struct PbxNativeTarget: PbxprojSerializable {
try! s.write(to: Path(plistName))
self.otherFiles = [PbxPlistFileReference(path: plistName)]
self.configurationList = PbxTargetConfigurations(plistPath: plistName, testThisApp: appTarget!.name)
self.dependencies = [PbxTargetDependency(target: appTarget!, projectGUID: xcodeprojGUID)]
case .StaticLibrary, .Executable:
self.configurationList = PbxTargetConfigurations(plistPath: nil, testThisApp: nil)
self.otherFiles = []
self.dependencies = []
}
}
func serialize() -> String {
......@@ -391,6 +396,9 @@ struct PbxNativeTarget: PbxprojSerializable {
s += " buildRules = (\n"
s += " );\n"
s += " dependencies = (\n"
for dependency in dependencies {
s += " \(dependency.guid) /* PBXTargetDependency */,\n"
}
s += " );\n"
s += " name = \(name);\n"
s += " productName = \(name);\n"
......@@ -412,6 +420,10 @@ struct PbxNativeTarget: PbxprojSerializable {
s += phases.serialize()
s += configurationList.serialize()
for dependency in dependencies {
s += dependency.serialize()
}
return s
}
}
......@@ -592,6 +604,31 @@ struct PbxPlistFileReference: PbxprojSerializable {
}
}
struct PbxTargetDependency : PbxprojSerializable {
let guid = xcodeguid()
let target : PbxNativeTarget
let targetProxyGUID = xcodeguid()
let projectGUID: String
func serialize() -> String {
var s = ""
s += "\(guid) /* PBXTargetDependency */ = {\n"
s += " isa = PBXTargetDependency;\n"
s += " target = \(target.guid) /* main */;\n"
s += " targetProxy = \(targetProxyGUID) /* PBXContainerItemProxy */;\n"
s += "};\n"
s += " \(targetProxyGUID) /* PBXContainerItemProxy */ = {\n"
s += " isa = PBXContainerItemProxy;\n"
s += " containerPortal = \(projectGUID) /* Project object */;\n"
s += " proxyType = 1;\n"
s += " remoteGlobalIDString = \(target.guid);\n"
s += " remoteInfo = \(target.name);\n"
s += "};\n"
return s
}
}
struct PbxSourceFileReference: PbxprojSerializable {
let path: String
let guid = xcodeguid()
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>15E65</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>main</string>
<key>CFBundleIdentifier</key>
<string>com.dca.SmallestiOSApp</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>SmallestiOSApp</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneSimulator</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string></string>
<key>DTPlatformName</key>
<string>iphonesimulator</string>
<key>DTPlatformVersion</key>
<string>9.3</string>
<key>DTSDKBuild</key>
<string>13E230</string>
<key>DTSDKName</key>
<string>iphonesimulator9.3</string>
<key>DTXcode</key>
<string>0730</string>
<key>DTXcodeBuild</key>
<string>7D175</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
<string>9.3</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
</dict>
</plist>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment