Skip to content

Instantly share code, notes, and snippets.

@alanzeino
Created May 6, 2016 22:27
Show Gist options
  • Save alanzeino/70928ea035cf97505911600cef564ced to your computer and use it in GitHub Desktop.
Save alanzeino/70928ea035cf97505911600cef564ced to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'yaml'
def find_value_for_key(yaml_file, key)
yaml_file.each do |yaml_key, yaml_value|
if key == yaml_key
return yaml_value
end
end
return nil
end
if ARGV.length != 1
puts "Usage: #{$PROGRAM_NAME} derived_data_path"
exit 1
end
slather_file = '.slather.yml'
# Open the slather yaml
slather_yml = YAML.load_file(File.join(Dir.pwd, slather_file))
# Get the scheme name
scheme_name = find_value_for_key(slather_yml, 'scheme')
if scheme_name == nil
puts "Couldn't find scheme in #{slather_file}"
end
# Find the Scheme build artifact folder in DerivedData
derived_data_path = ARGV[0]
build_artifact_folder = ""
Dir.chdir(derived_data_path) do
composed_regex = "^" + scheme_name + "-.*$"
puts "Searching for build artifact folder using regex: #{composed_regex}"
Dir.glob("*") do |file_name|
if file_name =~ /#{composed_regex}/
puts "Found " + file_name
build_artifact_folder = file_name
break
end
end
end
app_path = File.join(derived_data_path, build_artifact_folder, "Build/Intermediates/CodeCoverage/Products/Debug-iphonesimulator/#{scheme_name}.framework/#{scheme_name}")
puts "Running slather with app path: #{app_path}"
system('slather', 'coverage', '--input-format', 'profdata', '-s', '--build-directory', derived_data_path, '--binary-file', app_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment