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)


263
264
265
266
267
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 263

def below_minimum_version?
  return false unless installed?

  version < minimum_version
end

.detect_clang_versionObject



276
277
278
279
280
281
282
283
284
285
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 276

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



311
312
313
314
315
316
317
318
319
320
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 311

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)


210
211
212
213
214
215
216
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 210

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.



300
301
302
303
304
305
306
307
308
309
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 300

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)


198
199
200
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 198

def installed?
  !version.null?
end

.latest_versionObject



240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 240

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.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



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

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


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

def outdated?
  clang_version = detect_clang_version
  return false unless clang_version

  ::Version.new(clang_version) < latest_version
end

.provides_sdk?Boolean

Returns:

  • (Boolean)


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

def provides_sdk?
  version >= "8"
end

.sdk(v = nil) ⇒ Object



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

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

  @locator.sdk_if_applicable(v)
end

.sdk_path(v = nil) ⇒ Object



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

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

.separate_header_package?Boolean

Returns:

  • (Boolean)


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

def separate_header_package?
  version >= "10"
end

.update_instructionsObject



228
229
230
231
232
233
234
235
236
237
238
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 228

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.



290
291
292
293
294
295
296
# File 'brew/Library/Homebrew/os/mac/xcode.rb', line 290

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