Skip to content

Commit

Permalink
Merge pull request #149 from czechboy0/hd/fixed_workspace_owned_schemes
Browse files Browse the repository at this point in the history
Fixed unrecognized schemes owned by workspace
  • Loading branch information
czechboy0 committed Oct 2, 2015
2 parents 43b9a8d + d33cf0b commit 75484a6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 20 deletions.
7 changes: 3 additions & 4 deletions BuildaKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,10 @@ public class Project : JSONSerializable {
return json
}

public func schemeNames() -> [String] {
public func schemes() -> [XcodeScheme] {

let schemes = XcodeProjectParser.sharedSchemeUrlsFromProjectOrWorkspaceUrl(self.url)
let names = schemes.map { ($0.lastPathComponent! as NSString).stringByDeletingPathExtension }
return names
let schemes = XcodeProjectParser.sharedSchemesFromProjectOrWorkspaceUrl(self.url)
return schemes
}

private class func loadWorkspaceMetadata(url: NSURL) throws -> WorkspaceMetadata {
Expand Down
20 changes: 17 additions & 3 deletions BuildaKit/XcodeDeviceParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class XcodeDeviceParser {
}
}

public class func parseDeviceTypeFromProjectUrlAndScheme(projectUrl: NSURL, scheme: String) throws -> DeviceType {
public class func parseDeviceTypeFromProjectUrlAndScheme(projectUrl: NSURL, scheme: XcodeScheme) throws -> DeviceType {

let typeString = try self.parseTargetTypeFromSchemeAndProjectAtUrl(scheme, projectFolderUrl: projectUrl)
guard let deviceType = DeviceType(rawValue: typeString) else {
Expand All @@ -38,10 +38,24 @@ public class XcodeDeviceParser {
return deviceType
}

private class func parseTargetTypeFromSchemeAndProjectAtUrl(schemeName: String, projectFolderUrl: NSURL) throws -> String {
private class func parseTargetTypeFromSchemeAndProjectAtUrl(scheme: XcodeScheme, projectFolderUrl: NSURL) throws -> String {

let ownerArgs = try { () throws -> String in

let ownerUrl = scheme.ownerProjectOrWorkspace.path!
switch (scheme.ownerProjectOrWorkspace.lastPathComponent! as NSString).pathExtension {
case "xcworkspace":
return "-workspace \"\(ownerUrl)\""
case "xcodeproj":
return "-project \"\(ownerUrl)\""
default: throw Error.withInfo("Unrecognized project/workspace path \(ownerUrl)")
}
}()

let folder = projectFolderUrl.URLByDeletingLastPathComponent?.path ?? "~"
let script = "cd \"\(folder)\"; xcodebuild -scheme \"\(schemeName)\" -showBuildSettings 2>/dev/null | egrep '^\\s*PLATFORM_NAME' | cut -d = -f 2 | uniq | xargs echo"
let schemeName = scheme.name

let script = "cd \"\(folder)\"; xcodebuild \(ownerArgs) -scheme \"\(schemeName)\" -showBuildSettings 2>/dev/null | egrep '^\\s*PLATFORM_NAME' | cut -d = -f 2 | uniq | xargs echo"
let res = Script.runTemporaryScript(script)
if res.terminationStatus == 0 {
let deviceType = res.standardOutput.stripTrailingNewline()
Expand Down
17 changes: 9 additions & 8 deletions BuildaKit/XcodeProjectParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class XcodeProjectParser {
}
}

public class func sharedSchemeUrlsFromProjectOrWorkspaceUrl(url: NSURL) -> [NSURL] {
public class func sharedSchemesFromProjectOrWorkspaceUrl(url: NSURL) -> [XcodeScheme] {

var projectUrls: [NSURL]
if self.isWorkspaceUrl(url) {
Expand All @@ -111,16 +111,16 @@ public class XcodeProjectParser {
}

//we have the project urls, now let's parse schemes from each of them
let schemeUrls = projectUrls.map {
let schemes = projectUrls.map {
return self.sharedSchemeUrlsFromProjectUrl($0)
}.reduce([NSURL](), combine: { (arr, newUrls) -> [NSURL] in
arr + newUrls
}.reduce([XcodeScheme](), combine: { (arr, newSchemes) -> [XcodeScheme] in
return arr + newSchemes
})

return schemeUrls
return schemes
}

private class func sharedSchemeUrlsFromProjectUrl(url: NSURL) -> [NSURL] {
private class func sharedSchemeUrlsFromProjectUrl(url: NSURL) -> [XcodeScheme] {

//the structure is
//in a project file, if there are any shared schemes, they will be in
Expand All @@ -138,17 +138,18 @@ public class XcodeProjectParser {
return itemUrl.lastPathComponent == "xcschemes"
}) {
//we have the right folder, yay! just filter all files ending with xcscheme
let schemes = try self.allItemsMatchingTest(schemesFolder, test: { (itemUrl: NSURL) -> Bool in
let schemeUrls = try self.allItemsMatchingTest(schemesFolder, test: { (itemUrl: NSURL) -> Bool in
let ext = itemUrl.pathExtension ?? ""
return ext == "xcscheme"
})
let schemes = schemeUrls.map { XcodeScheme(path: $0, ownerProjectOrWorkspace: url) }
return schemes
}
}
} catch {
Log.error(error)
}
return [NSURL]()
return []
}

private class func isProjectUrl(url: NSURL) -> Bool {
Expand Down
26 changes: 26 additions & 0 deletions BuildaKit/XcodeScheme.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// XcodeScheme.swift
// Buildasaur
//
// Created by Honza Dvorsky on 02/10/2015.
// Copyright © 2015 Honza Dvorsky. All rights reserved.
//

import Foundation

extension NSURL {

public var fileNameNoExtension: String? {
return ((self.lastPathComponent ?? "") as NSString).stringByDeletingPathExtension
}
}

public struct XcodeScheme {

public var name: String {
return self.path.fileNameNoExtension!
}

public let path: NSURL
public let ownerProjectOrWorkspace: NSURL
}
4 changes: 4 additions & 0 deletions Buildasaur.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
3ACBAE151B5ADE2A00204457 /* XcodeProject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ACBADF91B5ADE2A00204457 /* XcodeProject.swift */; };
3ACBAE161B5ADE2A00204457 /* XcodeProjectParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ACBADFA1B5ADE2A00204457 /* XcodeProjectParser.swift */; };
3ACBAE171B5ADE2A00204457 /* XcodeServerSyncerUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ACBADFB1B5ADE2A00204457 /* XcodeServerSyncerUtils.swift */; };
3ACF93A41BBE80B400CD888C /* XcodeScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ACF93A31BBE80B400CD888C /* XcodeScheme.swift */; settings = {ASSET_TAGS = (); }; };
3AD338B01AAE31D500ECD0F2 /* BuildTemplateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AD338AF1AAE31D500ECD0F2 /* BuildTemplateViewController.swift */; };
3AF090B81B1134AA0058567F /* BranchWatchingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF090B71B1134AA0058567F /* BranchWatchingViewController.swift */; };
3AF1B1241AAC7CA500917EF3 /* StatusSyncerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF1B1231AAC7CA500917EF3 /* StatusSyncerViewController.swift */; };
Expand Down Expand Up @@ -262,6 +263,7 @@
3ACBADF91B5ADE2A00204457 /* XcodeProject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeProject.swift; sourceTree = "<group>"; };
3ACBADFA1B5ADE2A00204457 /* XcodeProjectParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeProjectParser.swift; sourceTree = "<group>"; };
3ACBADFB1B5ADE2A00204457 /* XcodeServerSyncerUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeServerSyncerUtils.swift; sourceTree = "<group>"; };
3ACF93A31BBE80B400CD888C /* XcodeScheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeScheme.swift; sourceTree = "<group>"; };
3AD338AF1AAE31D500ECD0F2 /* BuildTemplateViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BuildTemplateViewController.swift; sourceTree = "<group>"; };
3AF090B71B1134AA0058567F /* BranchWatchingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BranchWatchingViewController.swift; sourceTree = "<group>"; };
3AF1B1231AAC7CA500917EF3 /* StatusSyncerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusSyncerViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -473,6 +475,7 @@
3ACBADFB1B5ADE2A00204457 /* XcodeServerSyncerUtils.swift */,
3A2024AA1BBAF60A0093807F /* SourceControlFileParser.swift */,
3A2024AC1BBAF64B0093807F /* WorkspaceMetadata.swift */,
3ACF93A31BBE80B400CD888C /* XcodeScheme.swift */,
);
path = BuildaKit;
sourceTree = "<group>";
Expand Down Expand Up @@ -1143,6 +1146,7 @@
3ACBAE061B5ADE2A00204457 /* SyncerBotManipulation.swift in Sources */,
3ACBAE021B5ADE2A00204457 /* SSHKeyVerification.swift in Sources */,
3ACBAE111B5ADE2A00204457 /* SyncPairExtensions.swift in Sources */,
3ACF93A41BBE80B400CD888C /* XcodeScheme.swift in Sources */,
3ACBADFC1B5ADE2A00204457 /* BuildTemplate.swift in Sources */,
3ACBAE121B5ADE2A00204457 /* SyncPairPRResolver.swift in Sources */,
3ACBAE151B5ADE2A00204457 /* XcodeProject.swift in Sources */,
Expand Down
15 changes: 10 additions & 5 deletions Buildasaur/BuildTemplateViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class BuildTemplateViewController: SetupViewController, NSComboBoxDelegate, NSTa
self.testDeviceFilterComboBox.usesDataSource = true
self.testDeviceFilterComboBox.dataSource = self

let schemes = self.project.schemeNames()
let schemeNames = self.project.schemes().map { $0.name }
self.schemesComboBox.removeAllItems()
self.schemesComboBox.addItemsWithObjectValues(schemes)
self.schemesComboBox.addItemsWithObjectValues(schemeNames)

let temp = self.buildTemplate

Expand Down Expand Up @@ -345,14 +345,19 @@ class BuildTemplateViewController: SetupViewController, NSComboBoxDelegate, NSTa
//validate that the selection is valid
if let selectedScheme = self.schemesComboBox.objectValueOfSelectedItem as? String
{
let schemes = self.project.schemeNames()
if schemes.indexOf(selectedScheme) != nil {
let schemes = self.project.schemes()
let schemeNames = schemes.map { $0.name }
let index = schemeNames.indexOf(selectedScheme)
if let index = index {

let scheme = schemes[index]

//found it, good, use it
self.buildTemplate.scheme = selectedScheme

//also refresh devices for testing based on the scheme type
do {
let platformType = try XcodeDeviceParser.parseDeviceTypeFromProjectUrlAndScheme(self.project.url, scheme: selectedScheme).toPlatformType()
let platformType = try XcodeDeviceParser.parseDeviceTypeFromProjectUrlAndScheme(self.project.url, scheme: scheme).toPlatformType()
self.buildTemplate.platformType = platformType
self.reloadUI()
self.fetchDevices({ () -> () in
Expand Down

0 comments on commit 75484a6

Please sign in to comment.