Last active
December 30, 2015 13:39
-
-
Save jnjosh/7837207 to your computer and use it in GitHub Desktop.
Script that gets the path to your built product from an Xcode workspace no matter your build location (Derived Data or Legacy Build Directory)
This file contains hidden or 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
# | |
# Usage: | |
# | |
# app_path = product_path :workspace => "MyProject.xcworkspace", | |
# :scheme => "MyProjectScheme", | |
# :configuration => "Debug", | |
# :sdk => "iphonesimulator" | |
# | |
# puts app_path //=> /Users/yourusername/Library/Developer/Xcode/DerivedData/MyProject-bltlcokzhdicjggqmcrwibpdgdcp/Build/Products/Debug-iphonesimulator/MyProject.app | |
# | |
def build_settings options = { :workspace => nil, :scheme => nil, :configuration => nil, :sdk => nil } | |
build_output = `xcodebuild -workspace #{options[ :workspace ]} -scheme #{options[ :scheme ]} -configuration #{options[ :configuration ]} -sdk #{options[ :sdk ]} -showBuildSettings` | |
Hash[build_output.split(/\r?\n/).collect { |setting| | |
setting.split(' = ', 2).collect &:strip | |
}.reject { |setting| | |
setting.length != 2 || setting[0] == "" | |
}] | |
end | |
def product_path options = { :workspace => nil, :scheme => nil, :configuration => nil, :sdk => nil } | |
settings = build_settings options | |
target_build_directory = settings[ "TARGET_BUILD_DIR" ] | |
executable_file_directory = settings[ "EXECUTABLE_FOLDER_PATH" ] | |
File.join(target_build_directory, executable_file_directory) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems like you could further simplify this code by using split instead of a regex when building your hash.
This was typed on an iPad, so it probably contains errors.