Module: OS::Mac::CLT

Defined in:
brew/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"
HEADER_PKG_PATH =
"/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_:macos_version.pkg"
HEADER_PKG_ID =
"com.apple.pkg.macOS_SDK_headers_for_macOS_10.14"

Class Method Summary collapse

Class Method Details

.below_minimum_version?Boolean

Returns:

  • (Boolean)


268
269
270
271
272
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 268

def below_minimum_version?
  return false unless installed?

  version < minimum_version
end

.detect_clang_versionObject



281
282
283
284
285
286
287
288
289
290
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 281

def detect_clang_version
  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



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

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]
    break if version
  end
  version
end

.headers_installed?Boolean

Returns:

  • (Boolean)


213
214
215
216
217
218
219
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 213

def headers_installed?
  if !separate_header_package?
    installed?
  else
    headers_version == version
  end
end

.headers_versionObject

Version string of the header package, which is a separate package as of macOS 10.14.



305
306
307
308
309
310
311
312
313
314
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 305

def headers_version
  if !separate_header_package?
    version
  else
    @header_version ||= MacOS.pkgutil_info(HEADER_PKG_ID)[/version: (.+)$/, 1]
    return ::Version::NULL unless @header_version

    ::Version.new(@header_version)
  end
end

.installed?Boolean

Returns true even if outdated tools are installed

Returns:

  • (Boolean)


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

def installed?
  !version.null?
end

.latest_versionObject



243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 243

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.15" then "1100.0.20.17"
  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



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

def minimum_version
  case MacOS.version
  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)


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

def outdated?
  clang_version = detect_clang_version
  return false unless clang_version

  ::Version.new(clang_version) < latest_version
end

.provides_sdk?Boolean

Returns:

  • (Boolean)


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

def provides_sdk?
  version >= "8"
end

.sdk(v = nil) ⇒ Object



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

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

  @locator.sdk_if_applicable(v)
end

.sdk_path(v = nil) ⇒ Object



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

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

.separate_header_package?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 205

def separate_header_package?
  version >= "10"
end

.update_instructionsObject



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

def update_instructions
  if MacOS.version >= "10.14"
    <<~EOS
      Update them from Software Update in System Preferences.
    EOS
  else
    <<~EOS
      Update them from Software Update in the App Store.
    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.



295
296
297
298
299
300
301
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 295

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