Module: OS::Mac::CLT

Defined in:
Library/Homebrew/os/mac/xcode.rb

Constant Summary collapse

STANDALONE_PKG_ID =
"com.apple.pkg.DeveloperToolsCLILeo".freeze
FROM_XCODE_PKG_ID =
"com.apple.pkg.DeveloperToolsCLI".freeze
MAVERICKS_PKG_ID =
"com.apple.pkg.CLTools_Executables".freeze
MAVERICKS_NEW_PKG_ID =

obsolete

"com.apple.pkg.CLTools_Base".freeze
PKG_PATH =
"/Library/Developer/CommandLineTools".freeze

Class Method Summary collapse

Class Method Details

.below_minimum_version?Boolean

Returns:

  • (Boolean)


242
243
244
245
246
247
# File 'Library/Homebrew/os/mac/xcode.rb', line 242

def below_minimum_version?
  # Lion was the first version of OS X to ship with a CLT
  return false if MacOS.version < :lion
  return false unless installed?
  version < minimum_version
end

.detect_clang_versionObject



255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'Library/Homebrew/os/mac/xcode.rb', line 255

def detect_clang_version
  # Lion was the first version of OS X to ship with a CLT
  return if MacOS.version < :lion

  path = if MacOS.version >= :mavericks
    "#{PKG_PATH}/usr/bin/clang"
  else
    "/usr/bin/clang"
  end

  version_output = Utils.popen_read("#{path} --version")
  version_output[/clang-(\d+\.\d+\.\d+(\.\d+)?)/, 1]
end

.detect_versionObject



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'Library/Homebrew/os/mac/xcode.rb', line 280

def detect_version
  # CLT isn't a distinct entity pre-4.3, and pkgutil doesn't exist
  # at all on Tiger, so just count it as installed if Xcode is installed
  if MacOS::Xcode.installed? && MacOS::Xcode.version < "3.0"
    return MacOS::Xcode.version
  end

  version = nil
  [MAVERICKS_PKG_ID, MAVERICKS_NEW_PKG_ID, STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].each do |id|
    if MacOS.version >= :mavericks
      next unless File.exist?("#{PKG_PATH}/usr/bin/clang")
    end
    version = MacOS.pkgutil_info(id)[/version: (.+)$/, 1]
    break if version
  end
  version
end

.installed?Boolean

Returns true even if outdated tools are installed, e.g. tools from Xcode 4.x on 10.9

Returns:

  • (Boolean)


201
202
203
# File 'Library/Homebrew/os/mac/xcode.rb', line 201

def installed?
  !version.null?
end

.latest_versionObject



219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'Library/Homebrew/os/mac/xcode.rb', line 219

def latest_version
  # As of Xcode 8 CLT releases are no longer in sync with Xcode releases
  # on the older supported platform for that Xcode release, i.e there's no
  # CLT package for 10.11 that contains the Clang version from Xcode 8.
  case MacOS.version
  when "10.13" then "900.0.39.2"
  when "10.12" then "900.0.39.2"
  when "10.11" then "800.0.42.1"
  when "10.10" then "700.1.81"
  when "10.9"  then "600.0.57"
  when "10.8"  then "503.0.40"
  else              "425.0.28"
  end
end

.minimum_versionObject



234
235
236
237
238
239
240
# File 'Library/Homebrew/os/mac/xcode.rb', line 234

def minimum_version
  case MacOS.version
  when "10.13" then "9.0.0"
  when "10.12" then "8.0.0"
  else              "1.0.0"
  end
end

.outdated?Boolean

Returns:

  • (Boolean)


249
250
251
252
253
# File 'Library/Homebrew/os/mac/xcode.rb', line 249

def outdated?
  clang_version = detect_clang_version
  return false unless clang_version
  ::Version.new(clang_version) < latest_version
end

.update_instructionsObject



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'Library/Homebrew/os/mac/xcode.rb', line 205

def update_instructions
  if MacOS.version >= "10.9"
    <<~EOS
      Update them from Software Update in the App Store.
    EOS
  elsif MacOS.version == "10.8" || MacOS.version == "10.7"
    <<~EOS
      The standalone package can be obtained from
        https://developer.apple.com/download/more/
      or it can be installed via Xcode's preferences.
    EOS
  end
end

.versionObject

Version string (a pretty long one) of the CLT package. Note, that different ways to install the CLTs lead to different version numbers.



272
273
274
275
276
277
278
# File 'Library/Homebrew/os/mac/xcode.rb', line 272

def version
  if @version ||= detect_version
    ::Version.new @version
  else
    ::Version::NULL
  end
end