Last active
May 9, 2020 17:17
-
-
Save danielpetroianu/ba99d85e399af0d930a056aa9dae551b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Sets in a pod the given build setting | |
# | |
# @param [Xcodeproj::Project] project | |
# The xcode project instance. | |
# | |
# @param [Hash] build_settings | |
# An hash with the build configurations | |
# | |
# @param [Array<String>] build_configurations = nil | |
# An array with all the build configurations that the `build_setting` will apply to | |
# | |
# @param [Array<String>] targets = nil | |
# An array with all the names of the targets that the `build_setting` will apply to. | |
# | |
# @example Enable asserts on all pods and targets: | |
# set_project_build_settings project, {'ENABLE_NS_ASSERTIONS' => 'YES'} | |
# | |
# @example Enable asserts on a specific configuration: | |
# set_project_build_settings project, {'ENABLE_NS_ASSERTIONS' => 'YES'}, :build_configurations => ['Testing'] | |
# | |
def set_project_build_settings(project, build_settings, **params) | |
build_configurations = params.fetch(:build_configurations, nil) | |
targets = params.fetch(:targets, nil) | |
raise "Expecting an hash for `build_settings`, got #{build_settings.inspect}" unless build_settings.kind_of?(Hash) | |
raise "Invalid build_setting key 'build_configurations', got: #{build_settings.inspect}" if build_settings.has_key?(:build_configurations) | |
raise "Invalid build_setting key 'targets', got: #{build_settings.inspect}" if build_settings.has_key?(:targets) | |
raise "Expecting nil or an array for `build_configurations`, got: #{build_configurations.inspect}" if !build_configurations.nil? && !build_configurations.kind_of?(Array) | |
raise "Expecting nil or an array for `targets`, got #{targets.inspect}" if !targets.nil? && !targets.kind_of?(Array) | |
title = [] | |
title << "Setting '#{build_settings}' on" | |
title << " - configurations: #{build_configurations || 'all configurations'}" | |
title << " - pods project targets: #{targets || 'all targets'}" | |
Pod::UI.title( title.join("\n") ) | |
found_build_configurations = [] | |
found_targets = [] | |
project.targets.each do |target| | |
next if !targets.nil? && !targets.include?(target.name) | |
found_targets << target.name | |
verboseMessage = "`#{target.name}` ( " | |
target.build_configurations.each do |build_configuration| | |
next if !build_configurations.nil? && !build_configurations.include?(build_configuration.name) | |
found_build_configurations << build_configuration.name | |
verboseMessage += "#{build_configuration.name} " | |
build_settings.each do |build_setting, value| | |
build_configuration.build_settings[build_setting.to_s] = value.to_s | |
end | |
end | |
verboseMessage += ")\n" | |
Pod::UI.message(verboseMessage) | |
end | |
notfound_build_configurations = (build_configurations || []) - found_build_configurations | |
notfound_targets = (targets || []) - found_targets | |
if notfound_build_configurations.count != 0 | |
Pod::UI.warn("Could not find #{notfound_build_configurations} build configuration(s)") | |
end | |
if notfound_targets.count != 0 | |
Pod::UI.warn("Could not find #{notfound_targets} target(s)") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage in Podfile
and will output