Skip to content
This repository has been archived by the owner on Oct 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #176 from lacostej/features/wrap_xcodebuild
Browse files Browse the repository at this point in the history
Issue #168 wrap xcodebuild calls within ruby system environment
  • Loading branch information
KrauseFx committed Jan 12, 2016
2 parents 9551fb7 + 41dcf91 commit e77dc79
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ After building the archive it is being checked by `gym`. If it's valid, it gets
### Xcode 7 and above

```
/usr/bin/xcrun xcodebuild -exportArchive \
/usr/bin/xcrun path/to/xcbuild-safe.sh -exportArchive \
-exportOptionsPlist '/tmp/gym_config_1442852529.plist' \
-archivePath '/Users/fkrause/Library/Developer/Xcode/Archives/2015-09-21/App 2015-09-21 09.21.56.xcarchive' \
-exportPath '/tmp/1442852529'
Expand All @@ -214,6 +214,8 @@ After building the archive it is being checked by `gym`. If it's valid, it gets

Using this method there are no workarounds for WatchKit or Swift required, as it uses the same technique Xcode uses when exporting your binary.

Note: the [xcbuild-safe.sh script](https://github.com/fastlane/gym/tree/master/lib/assets/wrap_xcodebuild/xcbuild-safe.sh) wraps around xcodebuild to workaround some incompatibilities.

### Xcode 6 and below

```
Expand Down
49 changes: 49 additions & 0 deletions lib/assets/wrap_xcodebuild/xcbuild-safe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash --login

# Originally from, http://stackoverflow.com/questions/33041109
# Modified to work in RVM and non RVM environments
#
# Xcode 7 (incl. 7.0.1) seems to have a dependency on the system ruby.
# xcodebuild is screwed up by using rvm to map to another non-system
# ruby†. This script is a fix that allows you call xcodebuild in a
# "safe" rvm environment, but will not (AFAIK) affect the "external"
# rvm setting.
#
# The script is a drop in replacement for your xcodebuild call.
#
# xcodebuild arg1 ... argn
#
# would become
#
# path/to/xcbuild-safe.sh arg1 ... argn
#
# -----
# † Because, you know, that *never* happens when you are building
# Xcode projects, say with abstruse tools like Rake or CocoaPods.

which rvm > /dev/null

if [[ $? -eq 0 ]]; then
echo "RVM detected, forcing to use system ruby"
# This allows you to use rvm in a script. Otherwise you get a BS
# error along the lines of "cannot use rvm as function". Jeez.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

# Cause rvm to use system ruby. AFAIK, this is effective only for
# the scope of this script.
rvm use system

# rvm doesn't unset itself properly without doing this
unset RUBYLIB
unset RUBYOPT
unset BUNDLE_BIN_PATH
unset _ORIGINAL_GEM_PATH
unset BUNDLE_GEMFILE
fi

# to help troubleshooting
# env | sort > /tmp/env.wrapper
# rvm info >> /tmp/env.wrapper

set -x # echoes commands
xcodebuild "$@" # calls xcodebuild with all the arguments passed to this
2 changes: 1 addition & 1 deletion lib/gym/generators/package_command_generator_xcode7.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class << self
def generate
print_legacy_information unless Helper.fastlane_enabled?

parts = ["/usr/bin/xcrun xcodebuild -exportArchive"]
parts = ["/usr/bin/xcrun #{XcodebuildFixes.wrap_xcodebuild} -exportArchive"]
parts += options
parts += pipe

Expand Down
6 changes: 6 additions & 0 deletions lib/gym/xcodebuild_fixes/package_application_fix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def patch_package_application

return @patched_package_application_path # Return path to the patched PackageApplication
end

# Wrap xcodebuild to work-around ipatool dependecy to system ruby
def wrap_xcodebuild
require 'fileutils'
@wrapped_xcodebuild_path ||= File.join(Helper.gem_path("gym"), "lib/assets/wrap_xcodebuild/xcbuild-safe.sh")
end
end
end
end
2 changes: 1 addition & 1 deletion spec/package_command_generator_xcode7_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

result = Gym::PackageCommandGeneratorXcode7.generate
expect(result).to eq([
"/usr/bin/xcrun xcodebuild -exportArchive",
"/usr/bin/xcrun #{Gym::XcodebuildFixes.wrap_xcodebuild} -exportArchive",
"-exportOptionsPlist '#{Gym::PackageCommandGeneratorXcode7.config_path}'",
"-archivePath '#{Gym::BuildCommandGenerator.archive_path}'",
"-exportPath '#{Gym::PackageCommandGeneratorXcode7.temporary_output_path}'",
Expand Down

0 comments on commit e77dc79

Please sign in to comment.