Skip to content

Commit ffbb9ef

Browse files
committed
Refactor XCScheme API to enable multiple targets
1 parent d6927a9 commit ffbb9ef

File tree

10 files changed

+795
-195
lines changed

10 files changed

+795
-195
lines changed

lib/xcodeproj/scheme.rb

+122-187
Large diffs are not rendered by default.

spec/fixtures/Sample Project/Cocoa Application.xcodeproj/project.pbxproj

+329
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0500"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "E52523F316245AB20012E2BA"
18+
BuildableName = "iOS application.app"
19+
BlueprintName = "iOS application"
20+
ReferencedContainer = "container:Cocoa Application.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "YES"
26+
buildForProfiling = "YES"
27+
buildForArchiving = "YES"
28+
buildForAnalyzing = "YES">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "806F6FB517EFAF46001051EE"
32+
BuildableName = "libiOS staticLibrary.a"
33+
BlueprintName = "iOS staticLibrary"
34+
ReferencedContainer = "container:Cocoa Application.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
37+
<BuildActionEntry
38+
buildForTesting = "YES"
39+
buildForRunning = "NO"
40+
buildForProfiling = "NO"
41+
buildForArchiving = "NO"
42+
buildForAnalyzing = "NO">
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "806F6FC217EFAF47001051EE"
46+
BuildableName = "iOS staticLibraryTests.xctest"
47+
BlueprintName = "iOS staticLibraryTests"
48+
ReferencedContainer = "container:Cocoa Application.xcodeproj">
49+
</BuildableReference>
50+
</BuildActionEntry>
51+
</BuildActionEntries>
52+
</BuildAction>
53+
<TestAction
54+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
55+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
buildConfiguration = "Debug">
58+
<Testables>
59+
<TestableReference
60+
skipped = "NO">
61+
<BuildableReference
62+
BuildableIdentifier = "primary"
63+
BlueprintIdentifier = "E525241E16245AB20012E2BA"
64+
BuildableName = "iOS applicationTests.octest"
65+
BlueprintName = "iOS applicationTests"
66+
ReferencedContainer = "container:Cocoa Application.xcodeproj">
67+
</BuildableReference>
68+
</TestableReference>
69+
<TestableReference
70+
skipped = "NO">
71+
<BuildableReference
72+
BuildableIdentifier = "primary"
73+
BlueprintIdentifier = "806F6FC217EFAF47001051EE"
74+
BuildableName = "iOS staticLibraryTests.xctest"
75+
BlueprintName = "iOS staticLibraryTests"
76+
ReferencedContainer = "container:Cocoa Application.xcodeproj">
77+
</BuildableReference>
78+
</TestableReference>
79+
</Testables>
80+
<MacroExpansion>
81+
<BuildableReference
82+
BuildableIdentifier = "primary"
83+
BlueprintIdentifier = "E52523F316245AB20012E2BA"
84+
BuildableName = "iOS application.app"
85+
BlueprintName = "iOS application"
86+
ReferencedContainer = "container:Cocoa Application.xcodeproj">
87+
</BuildableReference>
88+
</MacroExpansion>
89+
</TestAction>
90+
<LaunchAction
91+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
92+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
93+
launchStyle = "0"
94+
useCustomWorkingDirectory = "NO"
95+
buildConfiguration = "Debug"
96+
ignoresPersistentStateOnLaunch = "NO"
97+
debugDocumentVersioning = "YES"
98+
allowLocationSimulation = "YES">
99+
<BuildableProductRunnable>
100+
<BuildableReference
101+
BuildableIdentifier = "primary"
102+
BlueprintIdentifier = "E52523F316245AB20012E2BA"
103+
BuildableName = "iOS application.app"
104+
BlueprintName = "iOS application"
105+
ReferencedContainer = "container:Cocoa Application.xcodeproj">
106+
</BuildableReference>
107+
</BuildableProductRunnable>
108+
<AdditionalOptions>
109+
</AdditionalOptions>
110+
</LaunchAction>
111+
<ProfileAction
112+
shouldUseLaunchSchemeArgsEnv = "YES"
113+
savedToolIdentifier = ""
114+
useCustomWorkingDirectory = "NO"
115+
buildConfiguration = "Release"
116+
debugDocumentVersioning = "YES">
117+
<BuildableProductRunnable>
118+
<BuildableReference
119+
BuildableIdentifier = "primary"
120+
BlueprintIdentifier = "E52523F316245AB20012E2BA"
121+
BuildableName = "iOS application.app"
122+
BlueprintName = "iOS application"
123+
ReferencedContainer = "container:Cocoa Application.xcodeproj">
124+
</BuildableReference>
125+
</BuildableProductRunnable>
126+
</ProfileAction>
127+
<AnalyzeAction
128+
buildConfiguration = "Debug">
129+
</AnalyzeAction>
130+
<ArchiveAction
131+
buildConfiguration = "Release"
132+
revealArchiveInOrganizer = "YES">
133+
</ArchiveAction>
134+
</Scheme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Prefix header
3+
//
4+
// The contents of this file are implicitly included at the beginning of every source file.
5+
//
6+
7+
#ifdef __OBJC__
8+
#import <Foundation/Foundation.h>
9+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// iOS_staticLibrary.h
3+
// iOS staticLibrary
4+
//
5+
// Created by Jason Prado on 9/22/13.
6+
// Copyright (c) 2013 CocoaPods. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface iOS_staticLibrary : NSObject
12+
13+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// iOS_staticLibrary.m
3+
// iOS staticLibrary
4+
//
5+
// Created by Jason Prado on 9/22/13.
6+
// Copyright (c) 2013 CocoaPods. All rights reserved.
7+
//
8+
9+
#import "iOS_staticLibrary.h"
10+
11+
@implementation iOS_staticLibrary
12+
13+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* Localized versions of Info.plist keys */
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>${EXECUTABLE_NAME}</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>org.cocoapods.${PRODUCT_NAME:rfc1034identifier}</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundlePackageType</key>
14+
<string>BNDL</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>1.0</string>
17+
<key>CFBundleSignature</key>
18+
<string>????</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// iOS_staticLibraryTests.m
3+
// iOS staticLibraryTests
4+
//
5+
// Created by Jason Prado on 9/22/13.
6+
// Copyright (c) 2013 CocoaPods. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
11+
@interface iOS_staticLibraryTests : XCTestCase
12+
13+
@end
14+
15+
@implementation iOS_staticLibraryTests
16+
17+
- (void)setUp
18+
{
19+
[super setUp];
20+
// Put setup code here. This method is called before the invocation of each test method in the class.
21+
}
22+
23+
- (void)tearDown
24+
{
25+
// Put teardown code here. This method is called after the invocation of each test method in the class.
26+
[super tearDown];
27+
}
28+
29+
- (void)testExample
30+
{
31+
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
32+
}
33+
34+
@end

spec/scheme_spec.rb

+117-8
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,21 @@ module Xcodeproj
5353
@ios_application_tests = Xcodeproj::Project::PBXNativeTarget.new(nil, 'E525241E16245AB20012E2BA')
5454
@ios_application_tests.name = "iOS applicationTests"
5555
@ios_application_tests.product_type = "com.apple.product-type.bundle"
56+
@ios_static_library = Xcodeproj::Project::PBXNativeTarget.new(nil, '806F6FC217EFAF47001051EE')
57+
@ios_static_library.name = "iOS staticLibrary"
58+
@ios_static_library.product_type = "com.apple.product-type.library.static"
59+
@ios_static_library_tests = Xcodeproj::Project::PBXNativeTarget.new(nil, '806F6FC217EFAF47001051EE')
60+
@ios_static_library_tests.name = "iOS staticLibraryTests"
61+
@ios_static_library_tests.product_type = "com.apple.product-type.bundle"
5662
end
5763

5864
describe 'For iOS Application' do
5965

6066
before do
61-
@scheme = Xcodeproj::XCScheme.new('Cocoa Application', @ios_application, @ios_application_tests)
67+
@scheme = Xcodeproj::XCScheme.new
68+
@scheme.add_build_target(@ios_application, 'Cocoa Application')
69+
@scheme.add_test_target(@ios_application_tests, 'Cocoa Application')
70+
@scheme.set_launch_target(@ios_application, 'Cocoa Application')
6271
@xml = REXML::Document.new File.new fixture_path('Sample Project/Cocoa Application.xcodeproj/xcshareddata/xcschemes/iOS application.xcscheme')
6372
end
6473

@@ -219,7 +228,8 @@ module Xcodeproj
219228
describe 'For iOS Application Tests' do
220229

221230
before do
222-
@scheme = Xcodeproj::XCScheme.new 'Cocoa Application', @ios_application_tests, @ios_application_tests
231+
@scheme = Xcodeproj::XCScheme.new
232+
@scheme.add_test_target(@ios_application_tests, 'Cocoa Application')
223233
@xml = REXML::Document.new File.new fixture_path('Sample Project/Cocoa Application.xcodeproj/xcshareddata/xcschemes/iOS applicationTests.xcscheme')
224234
end
225235

@@ -302,10 +312,9 @@ module Xcodeproj
302312
extend SpecHelper::TemporaryDirectory
303313

304314
before do
305-
@scheme = Xcodeproj::XCScheme.new 'Cocoa Application', @ios_application_tests, @ios_application_tests
306-
@scheme.build_target_for_running?.should.be.false
307-
@scheme.build_target_for_running = true
308-
@scheme.build_target_for_running?.should.be.true
315+
@scheme = Xcodeproj::XCScheme.new
316+
@scheme.add_build_target(@ios_application_tests, 'Cocoa Application')
317+
@scheme.add_test_target(@ios_application_tests, 'Cocoa Application')
309318
@xml = REXML::Document.new File.new fixture_path('Sample Project/Cocoa Application.xcodeproj/xcshareddata/xcschemes/iOS applicationTests Set Build Target For Running.xcscheme')
310319
end
311320

@@ -380,13 +389,113 @@ module Xcodeproj
380389
end
381390

382391
it 'Save as Shared Scheme' do
383-
result = @scheme.save_as(temporary_directory, true)
392+
result = @scheme.save_as(temporary_directory, 'iOS applicationTests', true)
384393
(result > 0).should.be.true
385394
File.exists?(File.join temporary_directory, 'xcshareddata', 'xcschemes', 'iOS applicationTests.xcscheme').should.be.true
386395
end
387396

388397
it 'Save as User Scheme' do
389-
result = @scheme.save_as(temporary_directory, false)
398+
result = @scheme.save_as(temporary_directory, 'iOS applicationTests', false)
399+
(result > 0).should.be.true
400+
File.exists?(File.join temporary_directory, 'xcuserdata', "#{ENV['USER']}.xcuserdatad", 'xcschemes', 'iOS applicationTests.xcscheme').should.be.true
401+
end
402+
403+
end
404+
405+
#-------------------------------------------------------------------------#
406+
407+
describe 'For iOS Application And Static Library' do
408+
409+
extend SpecHelper::TemporaryDirectory
410+
411+
before do
412+
@scheme = Xcodeproj::XCScheme.new
413+
@scheme.add_build_target(@ios_application, 'Cocoa Application')
414+
@scheme.add_build_target(@ios_static_library, 'Cocoa Application')
415+
@scheme.add_test_target(@ios_application_tests, 'Cocoa Application')
416+
@scheme.add_test_target(@ios_static_library_tests, 'Cocoa Application')
417+
@scheme.set_launch_target(@ios_application, 'Cocoa Application')
418+
@xml = REXML::Document.new File.new fixture_path('Sample Project/Cocoa Application.xcodeproj/xcshareddata/xcschemes/iOS application and static library.xcscheme')
419+
end
420+
421+
it 'XML Decl' do
422+
@xml.xml_decl.should.be.equal @scheme.doc.xml_decl
423+
end
424+
425+
it 'Scheme' do
426+
compare_elements @xml.root, @scheme.doc.root
427+
end
428+
429+
it 'Scheme > BuildAction' do
430+
compare_elements @xml.root.elements['BuildAction'], @scheme.doc.root.elements['BuildAction']
431+
end
432+
433+
it 'Scheme > TestAction' do
434+
compare_elements @xml.root.elements['TestAction'], @scheme.doc.root.elements['TestAction']
435+
end
436+
437+
it 'Scheme > TestAction > Testables' do
438+
compare_elements \
439+
@xml.root.elements['TestAction'] \
440+
.elements['Testables'], \
441+
@scheme.doc.root.elements['TestAction'] \
442+
.elements['Testables']
443+
end
444+
445+
it 'Scheme > TestAction > Testables > TestableReference' do
446+
compare_elements \
447+
@xml.root.elements['TestAction'] \
448+
.elements['Testables'] \
449+
.elements['TestableReference'], \
450+
@scheme.doc.root.elements['TestAction'] \
451+
.elements['Testables'] \
452+
.elements['TestableReference']
453+
end
454+
455+
it 'Scheme > TestAction > Testables > TestableReference > BuildableReference' do
456+
compare_elements \
457+
@xml.root.elements['TestAction'] \
458+
.elements['Testables'] \
459+
.elements['TestableReference'] \
460+
.elements['BuildableReference'], \
461+
@scheme.doc.root.elements['TestAction'] \
462+
.elements['Testables'] \
463+
.elements['TestableReference'] \
464+
.elements['BuildableReference']
465+
end
466+
467+
it 'Scheme > LaunchAction' do
468+
compare_elements @xml.root.elements['LaunchAction'], @scheme.doc.root.elements['LaunchAction']
469+
end
470+
471+
it 'Scheme > LaunchAction > AdditionalOptions' do
472+
compare_elements \
473+
@xml.root.elements['LaunchAction'] \
474+
.elements['AdditionalOptions'], \
475+
@scheme.doc.root.elements['LaunchAction'] \
476+
.elements['AdditionalOptions']
477+
end
478+
479+
it 'Scheme > ProfileAction' do
480+
compare_elements @xml.root.elements['ProfileAction'], @scheme.doc.root.elements['ProfileAction']
481+
end
482+
483+
it 'Scheme > AnalyzeAction' do
484+
compare_elements @xml.root.elements['AnalyzeAction'], @scheme.doc.root.elements['AnalyzeAction']
485+
end
486+
487+
it 'Scheme > ArchiveAction' do
488+
compare_elements @xml.root.elements['ArchiveAction'], @scheme.doc.root.elements['ArchiveAction']
489+
end
490+
491+
it 'Save as Shared Scheme' do
492+
result = @scheme.save_as(temporary_directory, 'iOS applicationTests', true)
493+
(result > 0).should.be.true
494+
File.exists?(File.join temporary_directory, 'xcshareddata', 'xcschemes', 'iOS applicationTests.xcscheme').should.be.true
495+
end
496+
497+
it 'Save as User Scheme' do
498+
result = @scheme.save_as(temporary_directory, 'iOS applicationTests', false)
390499
(result > 0).should.be.true
391500
File.exists?(File.join temporary_directory, 'xcuserdata', "#{ENV['USER']}.xcuserdatad", 'xcschemes', 'iOS applicationTests.xcscheme').should.be.true
392501
end

0 commit comments

Comments
 (0)