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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 7 compatibility #78

Merged
merged 5 commits into from
Jul 2, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions BuildaUtils/XcodeDeviceParser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// XcodeDeviceParser.swift
// Buildasaur
//
// Created by Honza Dvorsky on 30/06/2015.
// Copyright © 2015 Honza Dvorsky. All rights reserved.
//

import Foundation
import XcodeServerSDK

public class XcodeDeviceParser {

public enum DeviceType: String {
case iPhoneOS = "iphoneos"
case macOSX = "macosx"
case watchOS = "watchos"

public func toPlatformType() -> DevicePlatform.PlatformType {
switch self {
case .iPhoneOS:
return .iOS
case .macOSX:
return .OSX
case .watchOS:
return .watchOS
}
}
}

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

let typeString = try self.parseTargetTypeFromSchemeAndProjectAtUrl(scheme, projectFolderUrl: projectUrl)
guard let deviceType = DeviceType(rawValue: typeString) else {
throw Error.withInfo("Unrecognized type: \(typeString)")
}
return deviceType
}

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

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 res = Script.runTemporaryScript(script)
if res.terminationStatus == 0 {
let deviceType = res.standardOutput.stripTrailingNewline()
return deviceType
}
throw Error.withInfo("Termination status: \(res.terminationStatus), output: \(res.standardOutput), error: \(res.standardError)")
}
}
3 changes: 2 additions & 1 deletion BuildaUtils/XcodeProjectParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public class XcodeProjectParser {
let projectRelativePaths = components.map {
(line: String) -> String? in

let range1 = line.rangeOfString("group:")
//xcode 7 and 6 styles (container vs group)
let range1 = line.rangeOfString("container:") ?? line.rangeOfString("group:")
let range2 = line.rangeOfString("\">", options: NSStringCompareOptions.BackwardsSearch)
if let range1 = range1, let range2 = range2 {
let start = range1.endIndex
Expand Down
4 changes: 4 additions & 0 deletions Buildasaur.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
3AB4898E1B0929C9005C87BE /* MockHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB4898D1B0929C9005C87BE /* MockHelpers.swift */; };
3AB489901B0929F8005C87BE /* sampleFinishedIntegration.json in Resources */ = {isa = PBXBuildFile; fileRef = 3AB4898F1B0929F8005C87BE /* sampleFinishedIntegration.json */; };
3AD338B01AAE31D500ECD0F2 /* BuildTemplateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AD338AF1AAE31D500ECD0F2 /* BuildTemplateViewController.swift */; };
3AD4D9E21B4356BE0054B315 /* XcodeDeviceParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AD4D9E11B4356BE0054B315 /* XcodeDeviceParser.swift */; };
3AF090B81B1134AA0058567F /* BranchWatchingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF090B71B1134AA0058567F /* BranchWatchingViewController.swift */; };
3AF1B1221AAC621800917EF3 /* UIUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF1B1211AAC621800917EF3 /* UIUtils.swift */; };
3AF1B1241AAC7CA500917EF3 /* StatusSyncerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF1B1231AAC7CA500917EF3 /* StatusSyncerViewController.swift */; };
Expand Down Expand Up @@ -248,6 +249,7 @@
3AB4898D1B0929C9005C87BE /* MockHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockHelpers.swift; sourceTree = "<group>"; };
3AB4898F1B0929F8005C87BE /* sampleFinishedIntegration.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = sampleFinishedIntegration.json; sourceTree = "<group>"; };
3AD338AF1AAE31D500ECD0F2 /* BuildTemplateViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BuildTemplateViewController.swift; sourceTree = "<group>"; };
3AD4D9E11B4356BE0054B315 /* XcodeDeviceParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeDeviceParser.swift; sourceTree = "<group>"; };
3AF090B71B1134AA0058567F /* BranchWatchingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BranchWatchingViewController.swift; sourceTree = "<group>"; };
3AF1B1211AAC621800917EF3 /* UIUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIUtils.swift; sourceTree = "<group>"; };
3AF1B1231AAC7CA500917EF3 /* StatusSyncerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusSyncerViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -556,6 +558,7 @@
3AB3FDC81B05616A00021197 /* TimeUtils.swift */,
3AF1B1211AAC621800917EF3 /* UIUtils.swift */,
3A4770A31A745FFA0016E170 /* XcodeProjectParser.swift */,
3AD4D9E11B4356BE0054B315 /* XcodeDeviceParser.swift */,
3AAF6E761A3CE4CC00C657FB /* Supporting Files */,
);
path = BuildaUtils;
Expand Down Expand Up @@ -1200,6 +1203,7 @@
files = (
3A3BDC1D1AF6C51900D2CD99 /* Extensions.swift in Sources */,
3A808A1D1ADB063F0073145D /* Persistence.swift in Sources */,
3AD4D9E21B4356BE0054B315 /* XcodeDeviceParser.swift in Sources */,
3AB3FDC91B05616A00021197 /* TimeUtils.swift in Sources */,
3AF1B1221AAC621800917EF3 /* UIUtils.swift in Sources */,
3A4770A41A745FFA0016E170 /* XcodeProjectParser.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions Buildasaur/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14E36b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8121.20"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
Expand Down Expand Up @@ -1373,7 +1373,7 @@
</textField>
<comboBox verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eJ7-3i-rhz">
<rect key="frame" x="80" y="167" width="353" height="26"/>
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="Test destination" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="dho-Hu-TVn">
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="Test Device Filter" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="dho-Hu-TVn">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -1530,7 +1530,7 @@
<outlet property="scheduleComboBox" destination="oIQ-W6-NnZ" id="JPk-p4-MTh"/>
<outlet property="schemesComboBox" destination="AgV-fV-tZQ" id="SIt-HX-o19"/>
<outlet property="testButton" destination="uhv-2l-5xn" id="wU2-bu-fTN"/>
<outlet property="testDestinationComboBox" destination="eJ7-3i-rhz" id="jjF-jf-wLp"/>
<outlet property="testDeviceFilterComboBox" destination="eJ7-3i-rhz" id="ad3-Gd-jau"/>
<outlet property="testDevicesActivityIndicator" destination="VY0-39-fd9" id="omW-hD-iMO"/>
<outlet property="testDevicesTableView" destination="8jQ-1w-bC4" id="ioY-T3-5oI"/>
<outlet property="triggersTableView" destination="3LH-7K-zWF" id="mJs-5d-eR7"/>
Expand Down Expand Up @@ -2157,7 +2157,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" id="jDu-Ec-web">
<rect key="frame" x="0.0" y="0.0" width="342" height="19"/>
<rect key="frame" x="0.0" y="0.0" width="349" height="19"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down
37 changes: 30 additions & 7 deletions Buildasaur/BuildTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ private let kKeySchedule = "schedule"
private let kKeyCleaningPolicy = "cleaning_policy"
private let kKeyTriggers = "triggers"
private let kKeyTestingDevices = "testing_devices"
private let kKeyDestinationType = "destination_type"
private let kKeyDeviceFilter = "device_filter"
private let kKeyPlatformType = "platform_type"
private let kKeyShouldAnalyze = "should_analyze"
private let kKeyShouldTest = "should_test"
private let kKeyShouldArchive = "should_archive"
Expand All @@ -33,8 +34,10 @@ class BuildTemplate: JSONSerializable {
var shouldAnalyze: Bool?
var shouldTest: Bool?
var shouldArchive: Bool?
var deviceSpecification: DeviceSpecification

var testingDeviceIds: [String]
var deviceFilter: DeviceFilter.FilterType
var platformType: DevicePlatform.PlatformType?

func validate() -> Bool {

if self.uniqueId.isEmpty { return false }
Expand All @@ -54,7 +57,9 @@ class BuildTemplate: JSONSerializable {
self.shouldAnalyze = false
self.shouldTest = false
self.shouldArchive = false
self.deviceSpecification = DeviceSpecification(testingDeviceIDs: [])
self.testingDeviceIds = []
self.deviceFilter = .AllAvailableDevicesAndSimulators
self.platformType = nil
}

required init?(json: NSDictionary) {
Expand Down Expand Up @@ -84,8 +89,24 @@ class BuildTemplate: JSONSerializable {
self.shouldTest = json.optionalBoolForKey(kKeyShouldTest)
self.shouldArchive = json.optionalBoolForKey(kKeyShouldArchive)

let testingDevices = json.optionalArrayForKey(kKeyTestingDevices) as? [String] ?? []
self.deviceSpecification = DeviceSpecification(testingDeviceIDs: testingDevices)
self.testingDeviceIds = json.optionalArrayForKey(kKeyTestingDevices) as? [String] ?? []

if
let deviceFilterInt = json.optionalIntForKey(kKeyDeviceFilter),
let deviceFilter = DeviceFilter.FilterType(rawValue: deviceFilterInt)
{
self.deviceFilter = deviceFilter
} else {
self.deviceFilter = .AllAvailableDevicesAndSimulators
}

if
let platformTypeString = json.optionalStringForKey(kKeyPlatformType),
let platformType = DevicePlatform.PlatformType(rawValue: platformTypeString) {
self.platformType = platformType
} else {
self.platformType = nil
}

if !self.validate() {
return nil
Expand All @@ -97,14 +118,16 @@ class BuildTemplate: JSONSerializable {

dict[kKeyUniqueId] = self.uniqueId
dict[kKeyTriggers] = self.triggers.map({ $0.dictionarify() })
dict[kKeyTestingDevices] = self.deviceSpecification.deviceIdentifiers
dict[kKeyDeviceFilter] = self.deviceFilter.rawValue
dict[kKeyTestingDevices] = self.testingDeviceIds ?? []
dict[kKeyCleaningPolicy] = self.cleaningPolicy.rawValue
dict.optionallyAddValueForKey(self.name, key: kKeyName)
dict.optionallyAddValueForKey(self.scheme, key: kKeyScheme)
dict.optionallyAddValueForKey(self.schedule?.dictionarify(), key: kKeySchedule)
dict.optionallyAddValueForKey(self.shouldAnalyze, key: kKeyShouldAnalyze)
dict.optionallyAddValueForKey(self.shouldTest, key: kKeyShouldTest)
dict.optionallyAddValueForKey(self.shouldArchive, key: kKeyShouldArchive)
dict.optionallyAddValueForKey(self.platformType?.rawValue, key: kKeyPlatformType)

return dict
}
Expand Down
Loading