Class: XCCache::Swift::Sdk

Inherits:
Object
  • Object
show all
Defined in:
lib/xccache/swift/sdk.rb

Constant Summary collapse

NAME_TO_PLATFORM =
{
  :iphonesimulator => :ios,
  :iphoneos => :ios,
  :macos => :macos,
  :watchos => :watchos,
  :watchsimulator => :watchos,
  :appletvos => :tvos,
  :appletvsimulator => :tvos,
  :xros => :xros,
  :xrsimulator => :xros,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version: nil) ⇒ Sdk

Returns a new instance of Sdk.

Raises:



21
22
23
24
25
26
27
28
29
# File 'lib/xccache/swift/sdk.rb', line 21

def initialize(name, version: nil)
  @name = name.to_sym
  @vendor = "apple"
  @arch = "arm64"
  @platform = NAME_TO_PLATFORM.fetch(@name, @name)
  @version = version
  return if NAME_TO_PLATFORM.key?(@name)
  raise GeneralError, "Unknown sdk: #{@name}. Must be one of #{NAME_TO_PLATFORM.keys}"
end

Instance Attribute Details

#archObject (readonly)

Returns the value of attribute arch.



6
7
8
# File 'lib/xccache/swift/sdk.rb', line 6

def arch
  @arch
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/xccache/swift/sdk.rb', line 6

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform.



6
7
8
# File 'lib/xccache/swift/sdk.rb', line 6

def platform
  @platform
end

#vendorObject (readonly)

Returns the value of attribute vendor.



6
7
8
# File 'lib/xccache/swift/sdk.rb', line 6

def vendor
  @vendor
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/xccache/swift/sdk.rb', line 7

def version
  @version
end

Instance Method Details

#sdk_nameObject



43
44
45
# File 'lib/xccache/swift/sdk.rb', line 43

def sdk_name
  name == :macos ? :macosx : name
end

#sdk_pathObject



47
48
49
50
51
52
# File 'lib/xccache/swift/sdk.rb', line 47

def sdk_path
  # rubocop:disable Layout/LineLength
  # /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
  # rubocop:enable Layout/LineLength
  @sdk_path ||= Pathname(Sh.capture_output("xcrun --sdk #{sdk_name} --show-sdk-path")).realpath
end

#sdk_platform_developer_pathObject



54
55
56
# File 'lib/xccache/swift/sdk.rb', line 54

def sdk_platform_developer_path
  @sdk_platform_developer_path ||= sdk_path.parent.parent # iPhoneSimulator.platform/Developer
end

#simulator?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/xccache/swift/sdk.rb', line 67

def simulator?
  name.to_s.end_with?("simulator")
end

#swiftc_argsObject



58
59
60
61
62
63
64
65
# File 'lib/xccache/swift/sdk.rb', line 58

def swiftc_args
  developer_library_frameworks_path = sdk_platform_developer_path / "Library" / "Frameworks"
  developer_usr_lib_path = sdk_platform_developer_path / "usr" / "lib"
  [
    "-F#{developer_library_frameworks_path}",
    "-I#{developer_usr_lib_path}",
  ]
end

#to_sObject



31
32
33
# File 'lib/xccache/swift/sdk.rb', line 31

def to_s
  name.to_s
end

#triple(with_vendor: true, with_version: false) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/xccache/swift/sdk.rb', line 35

def triple(with_vendor: true, with_version: false)
  cmps = [arch]
  cmps << vendor if with_vendor
  cmps << (with_version && version ? "#{platform}#{version}" : platform.to_s)
  cmps << "simulator" if simulator?
  cmps.join("-")
end