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

Support for native watch app targets #272

Merged
merged 5 commits into from
Jun 24, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Ensure that duplicate resources or source files aren't added to a target.
[Samuel Giddins](https://github.com/segiddins)

* Support for native watch app targets.
[Boris Bügling](https://github.com/neonichu)
[Xcodeproj#272](https://github.com/CocoaPods/Xcodeproj/pull/272)

##### Bug Fixes

* Fix the help output for `xcodeproj config-dump`.
Expand Down
10 changes: 9 additions & 1 deletion lib/xcodeproj/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module Constants
#
LAST_KNOWN_OSX_SDK = '10.10'

# @return [String] The last known watchOS SDK (unstable).
LAST_KNOWN_WATCHOS_SDK = '2.0'

# @return [String] The last known archive version to Xcodeproj.
#
LAST_KNOWN_ARCHIVE_VERSION = 1
Expand All @@ -23,7 +26,7 @@ module Constants

# @return [String] The last known object version to Xcodeproj.
#
LAST_UPGRADE_CHECK = '0640'
LAST_UPGRADE_CHECK = '0700'

# @return [Hash] The all the known ISAs grouped by superclass.
#
Expand Down Expand Up @@ -101,7 +104,9 @@ module Constants
:app_extension => 'com.apple.product-type.app-extension',
:command_line_tool => 'com.apple.product-type.tool',
:watch_app => 'com.apple.product-type.application.watchapp',
:watch2_app => 'com.apple.product-type.application.watchapp2',
:watch_extension => 'com.apple.product-type.watchkit-extension',
:watch2_extension => 'com.apple.product-type.watchkit2-extension',
}.freeze

# @return [Hash] The extensions or the various product UTIs.
Expand Down Expand Up @@ -134,6 +139,9 @@ module Constants
[:osx] => {
'SDKROOT' => 'macosx',
}.freeze,
[:watchos] => {
'SDKROOT' => 'watchos',
}.freeze,
[:debug, :osx] => {
# Empty?
}.freeze,
Expand Down
14 changes: 10 additions & 4 deletions lib/xcodeproj/project/object/native_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def platform_name
:ios
elsif sdk.include? 'macosx'
:osx
elsif sdk.include? 'watchos'
:watchos
end
end

Expand All @@ -108,10 +110,10 @@ def sdk_version
# platform.
#
def deployment_target
if platform_name == :ios
common_resolved_build_setting('IPHONEOS_DEPLOYMENT_TARGET')
else
common_resolved_build_setting('MACOSX_DEPLOYMENT_TARGET')
case platform_name
when :ios then common_resolved_build_setting('IPHONEOS_DEPLOYMENT_TARGET')
when :osx then common_resolved_build_setting('MACOSX_DEPLOYMENT_TARGET')
when :watchos then common_resolved_build_setting('WATCHOS_DEPLOYMENT_TARGET')
end
end

Expand Down Expand Up @@ -294,6 +296,10 @@ def add_system_framework(names)
group = project.frameworks_group['OS X'] || project.frameworks_group.new_group('OS X')
path_sdk_name = 'MacOSX'
path_sdk_version = sdk_version || Constants::LAST_KNOWN_OSX_SDK
when :watchos
group = project.frameworks_group['watchOS'] || project.frameworks_group.new_group('watchOS')
path_sdk_name = 'WatchOS'
path_sdk_version = sdk_version || Constants::LAST_KNOWN_WATCHOS_SDK
else
raise 'Unknown platform for target'
end
Expand Down
10 changes: 5 additions & 5 deletions lib/xcodeproj/project/project_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.new_target(project, type, name, platform, deployment_target, product_gr
target.build_phases << project.new(PBXFrameworksBuildPhase)

# Frameworks
framework_name = (platform == :ios) ? 'Foundation' : 'Cocoa'
framework_name = (platform == :osx) ? 'Cocoa' : 'Foundation'
target.add_system_framework(framework_name)

target
Expand Down Expand Up @@ -234,10 +234,10 @@ def self.common_build_settings(type, platform = nil, deployment_target = nil, ta
end

if deployment_target
if platform == :ios
settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
elsif platform == :osx
settings['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
case platform
when :ios then settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
when :osx then settings['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
when :watchos then settings['WATCHOS_DEPLOYMENT_TARGET'] = deployment_target
end
end

Expand Down
11 changes: 10 additions & 1 deletion lib/xcodeproj/xcodebuild_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def last_osx_sdk
verions_by_sdk[:osx].sort.last
end

# @return [String] The version of the last watchOS sdk.
#
def last_watchos_sdk
parse_sdks_if_needed
verions_by_sdk[:watchos].sort.last
end

private

# !@group Private Helpers
Expand All @@ -38,12 +45,14 @@ def parse_sdks_if_needed
@verions_by_sdk = {}
@verions_by_sdk[:osx] = []
@verions_by_sdk[:ios] = []
@verions_by_sdk[:watchos] = []
if xcodebuild_available?
skds = parse_sdks_information(xcodebuild_sdks)
skds.each do |(name, version)|
case
when name == 'macosx' then @verions_by_sdk[:osx] << version
when name == 'iphoneos' then @verions_by_sdk[:ios] << version
when name == 'watchos' then @verions_by_sdk[:watchos] << version
end
end
end
Expand All @@ -64,7 +73,7 @@ def xcodebuild_available?
# is the name of the SDK and the second is the version.
#
def parse_sdks_information(output)
output.scan(/-sdk (macosx|iphoneos)(.+\w)/)
output.scan(/-sdk (macosx|iphoneos|watchos)(.+\w)/)
end

# @return [String] The sdk information reported by xcodebuild.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
23 changes: 23 additions & 0 deletions spec/project/object/native_target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ module ProjectSpecs
t2 = @project.new_target(:static_library, 'Pods', :osx)
t2.build_configuration_list.set_setting('SDKROOT', 'macosx10.8')
t2.sdk_version.should == '10.8'

t3 = @project.new_target(:static_library, 'Pods', :watchos)
t3.build_configuration_list.set_setting('SDKROOT', 'watchos2.0')
t3.sdk_version.should == '2.0'
end

describe 'returns the deployment target specified in its build configuration' do
Expand All @@ -134,6 +138,11 @@ module ProjectSpecs
@project.build_configuration_list.set_setting('MACOSX_DEPLOYMENT_TARGET', nil)
@project.new_target(:static_library, 'Pods', :osx, '10.7').deployment_target.should == '10.7'
end

it 'works for watchOS' do
@project.build_configuration_list.set_setting('WATCHOS_DEPLOYMENT_TARGET', nil)
@project.new_target(:static_library, 'Pods', :watchos, '2.0').deployment_target.should == '2.0'
end
end

describe 'returns the deployment target of the project build configuration' do
Expand All @@ -150,6 +159,13 @@ module ProjectSpecs
osx_target.build_configurations.first.build_settings['MACOSX_DEPLOYMENT_TARGET'] = nil
osx_target.deployment_target.should == '10.7'
end

it 'works for watchOS' do
@project.build_configuration_list.set_setting('WATCHOS_DEPLOYMENT_TARGET', '2.0')
watch_target = @project.new_target(:static_library, 'Pods', :watchos)
watch_target.build_configurations.first.build_settings['WATCHOS_DEPLOYMENT_TARGET'] = nil
watch_target.deployment_target.should == '2.0'
end
end

it 'returns the build configuration' do
Expand Down Expand Up @@ -347,6 +363,13 @@ module ProjectSpecs
file.path.scan(/\d\.\d/).first.should == Xcodeproj::Constants::LAST_KNOWN_IOS_SDK
end

it 'uses the last known watchOS SDK version if none is specified in the target' do
@target.build_configuration_list.set_setting('SDKROOT', 'watchos')
@target.add_system_framework('WatchConnectivity')
file = @project['Frameworks/watchOS'].files.first
file.path.scan(/\d\.\d/).first.should == Xcodeproj::Constants::LAST_KNOWN_WATCHOS_SDK
end

it "doesn't duplicate references to a frameworks if one already exists" do
@target.add_system_framework('QuartzCore')
@target.add_system_framework('QuartzCore')
Expand Down
18 changes: 18 additions & 0 deletions spec/project/project_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ module ProjectSpecs
target.build_phases.map(&:isa).sort.should == %w(PBXFrameworksBuildPhase PBXSourcesBuildPhase)
end

it 'creates a new watchOS target' do
target = @helper.new_target(@project, :static_library, 'Pods', :watchos, '2.0', @project.products_group, :objc)
target.name.should == 'Pods'
target.product_type.should == 'com.apple.product-type.library.static'

target.build_configuration_list.should.not.be.nil
configurations = target.build_configuration_list.build_configurations
configurations.map(&:name).sort.should == %w(Debug Release)
build_settings = configurations.first.build_settings
build_settings['WATCHOS_DEPLOYMENT_TARGET'].should == '2.0'
build_settings['SDKROOT'].should == 'watchos'

@project.targets.should.include target
@project.products.should.include target.product_reference

target.build_phases.map(&:isa).sort.should == %w(PBXFrameworksBuildPhase PBXSourcesBuildPhase)
end

it 'uses default build settings for Release and Debug configurations' do
target = @helper.new_target(@project, :static_library, 'Pods', :ios, '6.0', @project.products_group, :objc)
debug_settings = @helper.common_build_settings(:debug, :ios, '6.0', :static_library)
Expand Down
2 changes: 1 addition & 1 deletion spec/scheme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module ProjectSpecs
@scheme.to_s[0..190].should == <<-DOC.strip_heredoc
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
12 changes: 11 additions & 1 deletion spec/xcodebuild_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

iOS Simulator SDKs:
Simulator - iOS 6.1 -sdk iphonesimulator6.1

watchOS SDKs:
Watch OS 2.0 -sdk watchos2.0

watchOS Simulator SDKs:
Simulator - Watch OS 2.0 -sdk watchsimulator2.0
DOC
# rubocop:enable Style/Tab

Expand All @@ -35,6 +41,10 @@ module Xcodeproj
it 'returns the last OS X SDK' do
@helper.last_osx_sdk.should == '10.8'
end

it 'returns the last watchOS SDK' do
@helper.last_watchos_sdk.should == '2.0'
end
end

#--------------------------------------------------------------------------------#
Expand All @@ -55,7 +65,7 @@ module Xcodeproj
describe '#parse_sdks_information' do
it 'parses the skds information returned by xcodebuild' do
result = @helper.send(:parse_sdks_information, SPEC_XCODEBUILD_SAMPLE_SDK_OTPUT)
result.should == [['macosx', '10.7'], ['macosx', '10.8'], ['iphoneos', '6.1']]
result.should == [['macosx', '10.7'], ['macosx', '10.8'], ['iphoneos', '6.1'], ['watchos', '2.0']]
end
end
end
Expand Down