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

Commit

Permalink
Merge pull request #86 from SwiftGen/fix/circle-xcode9
Browse files Browse the repository at this point in the history
Fix CircleCI not finding Xcode 9
  • Loading branch information
AliSoftware authored Oct 26, 2017
2 parents 156c32e + 702506e commit 71f7957
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require 'English'
WORKSPACE = 'Templates'.freeze
SCHEME_NAME = 'Tests'.freeze
CONFIGURATION = 'Debug'.freeze
MIN_XCODE_VERSION = 9.0
MIN_XCODE_VERSION = '~> 9.0'

## [ Output compilation ] #####################################################

Expand Down
2 changes: 0 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
machine:
xcode:
version: 9.0
pre:
- sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

dependencies:
post:
Expand Down
45 changes: 32 additions & 13 deletions rakelib/utils.rake
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,49 @@ class Utils

# select the xcode version we want/support
def self.version_select
@@version_select ||= compute_developer_dir(MIN_XCODE_VERSION) # rubocop:disable Style/ClassVars
@version_select ||= compute_developer_dir(MIN_XCODE_VERSION)
end
private_class_method :version_select

def self.compute_developer_dir(min_version)
# Return the "DEVELOPER_DIR=..." prefix to use in order to point to the best Xcode version
#
# @param [String|Float|Gem::Requirement] version_req
# The Xcode version requirement.
# - If it's a Float, it's converted to a "~> x.y" requirement
# - If it's a String, it's converted to a Gem::Requirement as is
# @note If you pass a String, be sure to use "~> " in the string unless you really want
# to point to an exact, very specific version
#
def self.compute_developer_dir(version_req)
version_req = Gem::Requirement.new("~> #{version_req}") if version_req.is_a?(Float)
version_req = Gem::Requirement.new(version_req) unless version_req.is_a?(Gem::Requirement)
# if current Xcode already fulfills min version don't force DEVELOPER_DIR=...
current_xcode = Pathname.new(`xcode-select -p`).parent.parent
current_xcode_version = `mdls -name kMDItemVersion -raw "#{current_xcode}"`.chomp
return '' if current_xcode_version.to_f >= min_version.to_f
current_xcode_version = `xcodebuild -version`.split("\n").first.match(/[0-9.]+/).to_s
return '' if version_req.satisfied_by? Gem::Version.new(current_xcode_version)

# Get all available Xcodes, order by version, get the latest one
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'"`.chomp.split("\n")
versions = xcodes.map { |path| { vers: `mdls -name kMDItemVersion -raw "#{path}"`, path: path } }
latest_xcode = versions.sort_by { |a| a[:vers] }.last
supported_versions = all_xcode_versions.select { |app| version_req.satisfied_by?(app[:vers]) }
latest_supported_xcode = supported_versions.sort_by { |app| app[:vers] }.last

# Check if it's at least the right version
if latest_xcode.nil? || latest_xcode[:vers].to_f < min_version
raise "\n[!!!] SwiftGen requires Xcode #{MIN_XCODE_VERSION}, but we were not able to find it. " \
"If it's already installed update your Spotlight index with 'mdimport /Applications/Xcode*'\n\n"
if latest_supported_xcode.nil?
raise "\n[!!!] SwiftGen requires Xcode #{version_req}, but we were not able to find it. " \
"If it's already installed, either `xcode-select -s` to it, or update your Spotlight index " \
"with 'mdimport /Applications/Xcode*'\n\n"
end

%(DEVELOPER_DIR="#{latest_xcode[:path]}/Contents/Developer")
%(DEVELOPER_DIR="#{latest_supported_xcode[:path]}/Contents/Developer")
end
private_class_method :compute_developer_dir

# @return [Array<Hash>] A list of { :vers => ... , :path => ... } hashes
# of all Xcodes found on the machine using Spotlight
def self.all_xcode_versions
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'"`.chomp.split("\n")
xcodes.map do |path|
{ vers: Gem::Version.new(`mdls -name kMDItemVersion -raw "#{path}"`), path: path }
end
end
private_class_method :all_xcode_versions
end

# Colorization support for Strings
Expand Down

0 comments on commit 71f7957

Please sign in to comment.