Module: OS::Mac::CLT

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

Constant Summary collapse

EXECUTABLE_PKG_ID =

The original Mavericks CLT package ID

"com.apple.pkg.CLTools_Executables"
MAVERICKS_NEW_PKG_ID =

obsolete

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

Class Method Summary collapse

Class Method Details

.below_minimum_version?Boolean

Returns:

  • (Boolean)

281
282
283
284
285
# File 'Library/Homebrew/os/mac/xcode.rb', line 281

def below_minimum_version?
  return false unless installed?

  version < minimum_version
end

.detect_clang_versionObject


294
295
296
297
# File 'Library/Homebrew/os/mac/xcode.rb', line 294

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


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

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


299
300
301
# File 'Library/Homebrew/os/mac/xcode.rb', line 299

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

.installed?Boolean

Returns true even if outdated tools are installed

Returns:

  • (Boolean)

210
211
212
# File 'Library/Homebrew/os/mac/xcode.rb', line 210

def installed?
  !version.null?
end

.latest_clang_versionObject

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


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

def latest_clang_version
  case MacOS.version
  when "11.0", "10.16" then "1200.0.22.7"
  when "10.15" then "1103.0.32.59"
  when "10.14" then "1001.0.46.4"
  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_versionObject

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.


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

def minimum_version
  case MacOS.version
  when "11.0", "10.16" 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

Returns:

  • (Boolean)

287
288
289
290
291
292
# File 'Library/Homebrew/os/mac/xcode.rb', line 287

def outdated?
  clang_version = detect_clang_version
  return false unless clang_version

  ::Version.new(clang_version) < latest_clang_version
end

.provides_sdk?Boolean

Returns:

  • (Boolean)

218
219
220
# File 'Library/Homebrew/os/mac/xcode.rb', line 218

def provides_sdk?
  version >= "8"
end

.sdk(v = nil) ⇒ Object


222
223
224
225
226
# File 'Library/Homebrew/os/mac/xcode.rb', line 222

def sdk(v = nil)
  @locator ||= CLTSDKLocator.new

  @locator.sdk_if_applicable(v)
end

.sdk_path(v = nil) ⇒ Object


228
229
230
# File 'Library/Homebrew/os/mac/xcode.rb', line 228

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

.separate_header_package?Boolean

Returns:

  • (Boolean)

214
215
216
# File 'Library/Homebrew/os/mac/xcode.rb', line 214

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

.update_instructionsObject


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'Library/Homebrew/os/mac/xcode.rb', line 232

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 an update run:
      sudo rm -rf /Library/Developer/CommandLineTools
      sudo xcode-select --install

    Alternatively, manually download them from:
      #{Formatter.url("https://developer.apple.com/download/more/")}.
  EOS
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.


306
307
308
# File 'Library/Homebrew/os/mac/xcode.rb', line 306

def version
  Version::NULL
end