lib/xcjobs/xcodebuild.rb in xcjobs-0.8.1 vs lib/xcjobs/xcodebuild.rb in xcjobs-0.9.0
- old
+ new
@@ -29,18 +29,19 @@
attr_accessor :unsetenv_others
def initialize(name)
$stdout.sync = $stderr.sync = true
-
+
@name = name
@destinations = []
@only_testings = []
@skip_testings = []
@build_options = {}
@build_settings = {}
@unsetenv_others = false
+ @description = Rake.application.last_description # nil or given from "desc"
end
def project
if @project
File.extname(@project).empty? ? "#{@project}.xcodeproj" : @project
@@ -172,81 +173,45 @@
class Test < Xcodebuild
attr_accessor :without_building
def initialize(name = :test)
super
- @description = 'test application'
+ @description ||= 'test application'
@without_building = false
yield self if block_given?
define
end
def sdk
@sdk || 'iphonesimulator'
end
private
-
- def show_coverage(profdata_path, target_path)
+
+ def show_coverage_report(profdata_path, target_path)
cmd = ['xcrun', 'llvm-cov', 'report']
opts = ['-instr-profile', profdata_path, target_path, '-use-color=0']
- puts (cmd + opts).join(" ")
- out, status = Open3.capture2(*(cmd + opts))
- out.lines.each do |line|
- puts line
- end
+ sh *(cmd + opts)
end
-
- def generate_gcov_file(profdata_path, target_path)
- puts 'Generage gcov file...'
+
+ def build_coverage_report(profdata_path, target_path)
gcov_file = {}
source_path = ''
-
+
cmd = ['xcrun', 'llvm-cov', 'show']
opts = ['-instr-profile', profdata_path, target_path, '-use-color=0']
-
- out, status = Open3.capture2(*(cmd + opts))
- out.lines.each do |line|
- match = /^(['"]?(?:\/[^\/]+)*['"]?):$/.match(line)
- if match.to_a.count > 0
- source_path = match.to_a[1]
- gcov_file[source_path] = []
- next
- end
-
- match = /^[ ]*([0-9]+|[ ]+)\|[ ]*([0-9]+)\|(.*)$/.match(line)
- next unless match.to_a.count == 4
- count, number, text = match.to_a[1..3]
-
- execution_count = case count.strip
- when ''
- '-'.rjust(5)
- when '0'
- '#####'
- else count
- end
- gcov_file[source_path] << "#{execution_count.rjust(5)}:#{number.rjust(5)}:#{text}"
- end
-
- gcov_file.each do |key, value|
- gcon_path = File.join(File.dirname(profdata_path), "#{SecureRandom.urlsafe_base64(6)}-#{File.basename(target_path)}.gcov")
- file = File::open(gcon_path, "w")
- file.puts("#{'-'.rjust(5)}:#{'0'.rjust(5)}:Source:#{key}")
- file.puts(value)
- file.flush
- end
+
+ sh *(cmd + opts)
end
-
+
def coverage_report(options)
settings = build_settings(options)
-
- xcode_version = `xcodebuild -version`.split("\n").first.scan(/\d+/).join('.')
-
+
targetSettings = settings.select { |key, _| settings[key]['PRODUCT_TYPE'] != 'com.apple.product-type.bundle.unit-test' }
targetSettings.each do |target, settings|
objroot = settings['OBJROOT']
-
+
product_type = settings['PRODUCT_TYPE']
if product_type == 'com.apple.product-type.framework' || product_type == 'com.apple.product-type.application'
if sdk.start_with?('iphone') && settings['ONLY_ACTIVE_ARCH'] == 'NO'
executable_name = settings['EXECUTABLE_NAME']
else
@@ -254,21 +219,21 @@
end
target_path = Dir.glob(File.join(objroot, '/**/' +executable_name)).select { |f| File.stat(f).file? }.first
elsif
raise %[Product type (PRODUCT_TYPE) '#{product_type}' is unsupported.]
end
-
+
profdata_path = Dir.glob(File.join(objroot, '/**/Coverage.profdata')).first
-
- show_coverage(profdata_path, target_path)
- generate_gcov_file(profdata_path, target_path)
+
+ show_coverage_report(profdata_path, target_path)
+ build_coverage_report(profdata_path, target_path)
end
end
-
+
def build_settings(options)
out, status = Open3.capture2(*(['xcodebuild', 'test'] + options + ['-showBuildSettings']))
-
+
settings, target = {}, nil
out.lines.each do |line|
case line
when /Build settings for action test and target (.+):/
target = $1
@@ -284,29 +249,30 @@
def define
raise 'test action requires specifying a scheme' unless scheme
raise 'cannot specify both a scheme and targets' if scheme && target
desc @description
- task @name do
+ task @name do
add_build_setting('GCC_SYMBOLS_PRIVATE_EXTERN', 'NO')
- run(['xcodebuild', without_building ? 'test-without-building' : 'test'] + options)
+ run(['xcodebuild', command] + options)
if coverage_enabled
coverage_report(options)
end
end
end
+
+ def command
+ 'test'
+ end
end
class Build < Xcodebuild
- attr_accessor :for_testing
-
def initialize(name = :build)
super
- @description = 'build application'
- @for_testing = false
+ @description ||= 'build application'
yield self if block_given?
define
end
private
@@ -322,21 +288,41 @@
task @name do
add_build_setting('CONFIGURATION_TEMP_DIR', File.join(build_dir, 'temp')) if build_dir
add_build_setting('CODE_SIGN_IDENTITY', signing_identity) if signing_identity
add_build_setting('PROVISIONING_PROFILE', provisioning_profile_uuid) if provisioning_profile_uuid
- run(['xcodebuild', for_testing ? 'build-for-testing' : 'build'] + options)
+ run(['xcodebuild', command] + options)
end
end
+
+ def command
+ 'build'
+ end
end
+ class TestWithoutBuilding < Build
+ private
+
+ def command
+ 'test-without-building'
+ end
+ end
+
+ class BuildForTesting < Build
+ private
+
+ def command
+ 'build-for-testing'
+ end
+ end
+
class Archive < Xcodebuild
attr_accessor :archive_path
def initialize(name = :archive)
super
- @description = 'make xcarchive'
+ @description ||= 'make xcarchive'
yield self if block_given?
define
end
private
@@ -391,10 +377,10 @@
attr_accessor :options_plist
def initialize(name = :export)
super
self.unsetenv_others = true
- @description = 'export from an archive'
+ @description ||= 'export from an archive'
@export_format = 'IPA'
yield self if block_given?
define
end