Created
January 3, 2020 16:39
-
-
Save pepicrft/b26f8de222aca13164faa163e3bfa0bf to your computer and use it in GitHub Desktop.
A Ruby code snippet to check whether an Xcode project and its targets have empty build settings
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
require 'xcodeproj' | |
desc "Errors if the project contains build settings" | |
task :check_empty_build_settings do | |
project = Xcodeproj::Project.open(PROJECT_PATH) | |
elements_with_settings = [] | |
# Project | |
project | |
.build_configurations | |
.each do |configuration| | |
unless configuration.build_settings.empty? | |
elements_with_settings << "Project[#{configuration.name}]" | |
end | |
end | |
# Targets | |
project | |
.targets | |
.each do |target| | |
target.build_configurations.each do |configuration| | |
unless configuration.build_settings.empty? | |
elements_with_settings << "#{target.name}[#{configuration.name}]" | |
end | |
end | |
end | |
unless elements_with_settings.empty? | |
message = <<~EOD | |
The following elements have build settings defined: #{elements_with_settings.join(", ")}. | |
Move those to the associated .xcconfig files. | |
EOD | |
abort(message) | |
else | |
puts "The project and its targets have no build settings." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment