Module: OS::Mac::CLT Private

Extended by:
T::Sig
Defined in:
os/mac/xcode.rb,
os/linux.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper module for querying macOS Command Line Tools information.

Constant Summary collapse

EXECUTABLE_PKG_ID =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

The original Mavericks CLT package ID

"com.apple.pkg.CLTools_Executables"
MAVERICKS_NEW_PKG_ID =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

obsolete

"com.apple.pkg.CLTools_Base"
PKG_PATH =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"/Library/Developer/CommandLineTools"

Class Method Summary collapse

Class Method Details

.below_minimum_version?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


343
344
345
346
347
# File 'os/mac/xcode.rb', line 343

def below_minimum_version?
  return false unless installed?

  version < minimum_version
end

.detect_clang_versionObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



357
358
359
360
# File 'os/mac/xcode.rb', line 357

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

.detect_versionObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



377
378
379
380
381
382
383
384
385
386
387
# File 'os/mac/xcode.rb', line 377

def detect_version
  version = nil
  [EXECUTABLE_PKG_ID, MAVERICKS_NEW_PKG_ID].each do |id|
    next unless File.exist?("#{PKG_PATH}/usr/bin/clang")

    version = MacOS.pkgutil_info(id)[/version: (.+)$/, 1]
    return version if version
  end

  detect_version_from_clang_version
end

.detect_version_from_clang_versionObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



362
363
364
# File 'os/mac/xcode.rb', line 362

def detect_version_from_clang_version
  detect_clang_version&.sub(/^(\d+)0(\d)\./, "\\1.\\2.")
end

.installation_instructionsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'os/mac/xcode.rb', line 275

def installation_instructions
  if MacOS.version == "10.14"
    # This is not available from `xcode-select`
    <<~EOS
      Install the Command Line Tools for Xcode 11.3.1 from:
        #{Formatter.url("https://developer.apple.com/download/more/")}
    EOS
  else
    <<~EOS
      Install the Command Line Tools:
        xcode-select --install
    EOS
  end
end

.installed?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns true even if outdated tools are installed.

Returns:

  • (Boolean)


251
252
253
# File 'os/mac/xcode.rb', line 251

def installed?
  false
end

.latest_clang_versionString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Bump these when the new version is distributed through Software Update and our CI systems have been updated.

Returns:



315
316
317
318
319
320
321
322
323
324
325
326
# File 'os/mac/xcode.rb', line 315

def latest_clang_version
  case MacOS.version
  when "11"    then "1205.0.22.9"
  when "10.15" then "1200.0.32.29"
  when "10.14" then "1100.0.33.17"
  when "10.13" then "1000.10.44.2"
  when "10.12" then "900.0.39.2"
  when "10.11" then "800.0.42.1"
  when "10.10" then "700.1.81"
  else              "600.0.57"
  end
end

.minimum_versionString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Bump these if things are badly broken (e.g. no SDK for this macOS) without this. Generally this will be the first stable CLT release on that macOS version.

Returns:



332
333
334
335
336
337
338
339
340
341
# File 'os/mac/xcode.rb', line 332

def minimum_version
  case MacOS.version
  when "11" then "12.0.0"
  when "10.15" then "11.0.0"
  when "10.14" then "10.0.0"
  when "10.13" then "9.0.0"
  when "10.12" then "8.0.0"
  else              "1.0.0"
  end
end

.outdated?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


350
351
352
353
354
355
# File 'os/mac/xcode.rb', line 350

def outdated?
  clang_version = detect_clang_version
  return false unless clang_version

  ::Version.new(clang_version) < latest_clang_version
end

.provides_sdk?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


259
260
261
# File 'os/mac/xcode.rb', line 259

def provides_sdk?
  version >= "8"
end

.sdk(v = nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



267
268
269
# File 'os/mac/xcode.rb', line 267

def sdk(v = nil)
  sdk_locator.sdk_if_applicable(v)
end

.sdk_locatorObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



263
264
265
# File 'os/mac/xcode.rb', line 263

def sdk_locator
  @sdk_locator ||= CLTSDKLocator.new
end

.sdk_path(v = nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



271
272
273
# File 'os/mac/xcode.rb', line 271

def sdk_path(v = nil)
  sdk(v)&.path
end

.separate_header_package?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


255
256
257
# File 'os/mac/xcode.rb', line 255

def separate_header_package?
  version >= "10" && MacOS.version >= "10.14"
end

.update_instructionsString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'os/mac/xcode.rb', line 291

def update_instructions
  software_update_location = if MacOS.version >= "10.14"
    "System Preferences"
  else
    "the App Store"
  end

  <<~EOS
    Update them from Software Update in #{software_update_location} or run:
      softwareupdate --all --install --force

    If that doesn't show you any updates, run:
      sudo rm -rf /Library/Developer/CommandLineTools
      sudo xcode-select --install

    Alternatively, manually download them from:
      #{Formatter.url("https://developer.apple.com/download/more/")}.
    You should download the Command Line Tools for Xcode #{MacOS::Xcode.latest_version}.
  EOS
end

.versionObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

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



369
370
371
# File 'os/mac/xcode.rb', line 369

def version
  Version::NULL
end