lib/run_loop/xcode.rb in run_loop-2.3.0 vs lib/run_loop/xcode.rb in run_loop-2.3.1
- old
+ new
@@ -1,7 +1,5 @@
-require 'open3'
-
module RunLoop
# A model of the active Xcode version.
#
# @note All command line tools are run in the context of `xcrun`.
@@ -10,11 +8,15 @@
# _active version of Xcode_. The active Xcode version is the one returned
# by `xcrun xcodebuild`. The current Xcode version can be set using
# `xcode-select` or overridden using the `DEVELOPER_DIR`.
class Xcode
+ require "run_loop/regex"
+ require "run_loop/shell"
+
include RunLoop::Regex
+ include RunLoop::Shell
# Returns a String representation.
def to_s
"#<Xcode #{version.to_s}>"
end
@@ -22,10 +24,18 @@
# Returns debug String representation
def inspect
to_s
end
+ # Returns a version instance for Xcode 8.3 ; used to check for the
+ # availability of features and paths to various items on the filesystem
+ #
+ # @return [RunLoop::Version] 8.3
+ def v83
+ fetch_version(:v83)
+ end
+
# Returns a version instance for Xcode 8.2 ; used to check for the
# availability of features and paths to various items on the filesystem
#
# @return [RunLoop::Version] 8.2
def v82
@@ -134,10 +144,17 @@
# @return [RunLoop::Version] 5.0
def v50
fetch_version(:v50)
end
+ # Is the active Xcode version 8.3 or above?
+ #
+ # @return [Boolean] `true` if the current Xcode version is >= 8.3
+ def version_gte_83?
+ version >= v83
+ end
+
# Is the active Xcode version 8.2 or above?
#
# @return [Boolean] `true` if the current Xcode version is >= 8.2
def version_gte_82?
version >= v82
@@ -232,16 +249,35 @@
# Returns the current version of Xcode.
#
# @return [RunLoop::Version] The current version of Xcode as reported by
# `xcrun xcodebuild -version`.
def version
- @xcode_version ||= lambda do
- execute_command(['-version']) do |stdout, _, _|
- version_string = stdout.read.chomp[VERSION_REGEX, 0]
- RunLoop::Version.new(version_string)
+ @xcode_version ||= begin
+ if RunLoop::Environment.xtc?
+ RunLoop::Version.new("0.0.0")
+ else
+ version = RunLoop::Version.new("0.0.0")
+ begin
+ args = ["xcrun", "xcodebuild", "-version"]
+ hash = run_shell_command(args)
+ if hash[:exit_status] != 0
+ RunLoop.log_error("xcrun xcodebuild -version exited non-zero")
+ else
+ out = hash[:out]
+ version_string = out.chomp[VERSION_REGEX, 0]
+ version = RunLoop::Version.new(version_string)
+ end
+ rescue RuntimeError => e
+ RunLoop.log_error(%Q[
+Could not find Xcode version:
+
+ #{e.class}: #{e.message}
+])
+ end
+ version
end
- end.call
+ end
end
# Is this a beta version of Xcode?
#
# @note Relies on Xcode beta versions having and app bundle named Xcode-Beta.app
@@ -328,15 +364,9 @@
raise "Expected version key '#{key}' to have exactly 3 characters"
end
unless string[/v\d{2}/, 0]
raise "Expected version key '#{key}' to match vXX pattern"
- end
- end
-
- def execute_command(args)
- Open3.popen3('xcrun', 'xcodebuild', *args) do |_, stdout, stderr, wait_thr|
- yield stdout, stderr, wait_thr
end
end
def xcode_select_path
Open3.popen3('xcode-select', '--print-path') do |_, stdout, _, _|