Skip to content
Browse files

Avoid testing schemes with no testables

  • Loading branch information...
1 parent a11d8c5 commit feb0b088b48471dce2779b58e25e3d9a3fb3e08c @rayh committed May 23, 2013
View
6 bin/xcoder
@@ -26,6 +26,12 @@ OptionParser.new do |opts|
opts.on("--install-profile [PROFILE]", "Install the given profile into ~/Library") do |profile|
Xcode::ProvisioningProfile.new(profile).install
end
+
+ opts.on("--show-sdks", "Show the available SDKs") do
+ Xcode::Platforms.supported.each do |p|
+ puts "#{p.name}: #{p.platform}, #{p.version}"
+ end
+ end
opts.separator ""
opts.separator "Buildspec options:"
View
6 lib/xcode/builder/base_builder.rb
@@ -96,8 +96,12 @@ def prepare_build_command sdk=@sdk
end
def prepare_test_command sdk=@sdk
- cmd = prepare_xcodebuild sdk
+ cmd = Xcode::Shell::Command.new 'xcodebuild'
+ cmd.env["OBJROOT"] = "\"#{@objroot}/\""
+ cmd.env["SYMROOT"] = "\"#{@symroot}/\""
cmd.env["TEST_AFTER_BUILD"]="YES"
+ cmd << "-sdk #{sdk}" unless sdk.nil?
+ cmd << "test"
cmd
end
View
19 lib/xcode/builder/scheme_builder.rb
@@ -29,11 +29,20 @@ def prepare_xcodebuild sdk=nil
cmd
end
- # def prepare_build_command sdk=nil
- # cmd = super sdk
- # cmd << 'archive'
- # cmd
- # end
+ def prepare_test_command sdk=@sdk
+ cmd = super sdk
+ cmd << "-scheme \"#{@scheme.name}\""
+ cmd << "-configuration \"#{@scheme.test_config}\""
+ cmd
+ end
+
+ def test
+ unless @scheme.testable?
+ print_task :builder, "Nothing to test", :warning
+ else
+ super
+ end
+ end
end
end
View
17 lib/xcode/buildspec.rb
@@ -129,6 +129,15 @@ def keychain path, password = nil
end
+ #
+ # Specify the platform to build for
+ #
+ # @param the platform, can be 'iphone', 'iphonesimulator', 'macosx'
+ # @param the version, can be any valid, installed sdk version for the appropriate platform or nil
+ def platform name, version=nil
+ @platform = Xcode::Platforms.find name, version
+ end
+
#
# Set's the identity to use to sign the package
#
@@ -191,6 +200,10 @@ def builder
end
raise "Could not create a builder using #{@args}" if @builder.nil?
+
+ unless @platform.nil?
+ builder.sdk = @platform.sdk
+ end
unless @identity.nil?
builder.identity = @identity
@@ -243,12 +256,12 @@ def generate_rake_tasks
end
desc "Test #{project_name}"
- task :test => [:build] do
+ task :test => [:deps] do
builder.test
end
desc "Package (.ipa & .dSYM.zip) #{project_name}"
- task :package => [:test] do
+ task :package => [:build, :test] do
builder.package
end
View
65 lib/xcode/platform.rb
@@ -0,0 +1,65 @@
+module Xcode
+
+ module Platforms
+ @@platforms = []
+
+ def self.[] sdk_name
+ supported.find {|p| p.sdk==sdk_name}
+ end
+
+ def self.find platform, version = nil
+ platform = supported.sort do
+ |a,b| a.version.to_f <=> b.version.to_f
+ end.find do |p|
+ p.platform==platform and (version.nil? or p.version==version)
+ end
+
+ raise "Unable to find a platform #{platform},#{version} - available platforms are #{supported.map{|p| p.sdk}.join(', ')}" if platform.nil?
+
+ platform
+ end
+
+ def self.supported
+ return @@platforms unless @@platforms.count==0
+
+ parsing = false
+ `xcodebuild -showsdks`.split("\n").each do |l|
+ l.strip!
+ if l=~/(.*)\s+SDKs:/
+ parsing = true
+ elsif l=~/^\s*$/
+ parsing = false
+ elsif parsing
+ l=~/([^\t]+)\t+\-sdk (.*)/
+ name = $1.strip
+ $2.strip=~/([a-zA-Z]+)(\d+\.\d+)/
+
+ platform = Platform.new name, $1, $2
+ @@platforms << platform
+ end
+ end
+
+ @@platforms
+ end
+
+ end
+
+ class Platform
+ attr_reader :platform, :name, :version
+
+ def initialize name, platform, version
+ @platform = platform
+ @name = name
+ @version = version
+ end
+
+ def sdk
+ "#{@platform}#{@version}"
+ end
+
+ def to_s
+ "#{name} #{sdk}"
+ end
+ end
+
+end
View
9 lib/xcode/provisioning_profile.rb
@@ -10,6 +10,7 @@ def initialize(path)
@identifiers = []
@devices = []
@appstore = true
+ @enterprise = false
# TODO: im sure this could be done in a nicer way. maybe read out the XML-like stuff and use the plist -> json converter
uuid = nil
@@ -20,6 +21,10 @@ def initialize(path)
@appstore = false
end
+ if input=~/<key>ProvisionsAllDevices<\/key>/
+ @enterprise = true
+ end
+
if input=~/<key>ProvisionedDevices<\/key>.*?<array>(.*?)<\/array>/im
$1.split(/<string>/).each do |id|
next if id.nil? or id.strip==""
@@ -45,6 +50,10 @@ def initialize(path)
def appstore?
@appstore
end
+
+ def enterprise?
+ @enterprise
+ end
def self.profiles_path
File.expand_path "~/Library/MobileDevice/Provisioning\\ Profiles/"
View
21 lib/xcode/scheme.rb
@@ -1,12 +1,16 @@
require 'nokogiri'
module Xcode
+
+ class SchemeAction
+ attr_accessor :config, :name
+ end
# Schemes are an XML file that describe build, test, launch and profile actions
# For the purposes of Xcoder, we want to be able to build and test
class Scheme
attr_reader :parent, :path, :name, :build_targets
- attr_accessor :build_config, :archive_config
+ attr_accessor :build_config, :archive_config, :test_config
#
# Parse all the schemes given the current project.
@@ -55,14 +59,23 @@ def initialize(params={})
parse_build_actions(doc)
end
- # Returns a builder for building this scheme
+ #
+ # @return a builder for building this scheme
+ #
def builder
Xcode::Builder::SchemeBuilder.new(self)
end
def to_s
"#{name} (Scheme) in #{parent}"
end
+
+ #
+ # @return true if the scheme is testable, false otherwise
+ #
+ def testable?
+ !@test_config.nil?
+ end
private
@@ -105,6 +118,10 @@ def parse_build_actions(doc)
@build_config = doc.xpath("//LaunchAction").first['buildConfiguration']
@archive_config = doc.xpath("//ArchiveAction").first['buildConfiguration']
+ if doc.xpath("//TestAction/Testables/*").children.count>0
+ @test_config = doc.xpath("//TestAction").first['buildConfiguration']
+ end
+
build_action_entries = doc.xpath("//BuildAction//BuildableReference").each do |ref|
@build_targets << target_from_build_reference(ref)
end
View
11 lib/xcode/shell.rb
@@ -4,7 +4,13 @@
module Xcode
module Shell
- class ExecutionError < StandardError; end
+ class ExecutionError < StandardError;
+ attr_accessor :output
+ def initialize(message, output=nil)
+ super message
+ @output = output
+ end
+ end
def self.execute(cmd, show_output=true, show_command=false)
out = []
@@ -18,8 +24,7 @@ def self.execute(cmd, show_output=true, show_command=false)
out << line
end
end
-
- raise ExecutionError.new("Error (#{$?.exitstatus}) executing '#{cmd}'\n\n #{out.join(" ")}") if $?.exitstatus>0
+ raise ExecutionError.new("Error (#{$?.exitstatus}) executing '#{cmd}'", out) if $?.exitstatus>0
out
end
end
View
1 lib/xcoder.rb
@@ -8,6 +8,7 @@
require 'plist'
require 'xcode/keychain'
require 'xcode/workspace'
+require 'xcode/platform'
require 'multi_json'
module Xcode

0 comments on commit feb0b08

Please sign in to comment.
Something went wrong with that request. Please try again.