Class: XCCache::Swift::Sdk
- Inherits:
-
Object
- Object
- XCCache::Swift::Sdk
- 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
-
#arch ⇒ Object
readonly
Returns the value of attribute arch.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#vendor ⇒ Object
readonly
Returns the value of attribute vendor.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(name, version: nil) ⇒ Sdk
constructor
A new instance of Sdk.
- #sdk_name ⇒ Object
- #sdk_path ⇒ Object
- #sdk_platform_developer_path ⇒ Object
- #simulator? ⇒ Boolean
- #swiftc_args ⇒ Object
- #to_s ⇒ Object
- #triple(with_vendor: true, with_version: false) ⇒ Object
Constructor Details
#initialize(name, version: nil) ⇒ Sdk
Returns a new instance of Sdk.
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
#arch ⇒ Object (readonly)
Returns the value of attribute arch.
6 7 8 |
# File 'lib/xccache/swift/sdk.rb', line 6 def arch @arch end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/xccache/swift/sdk.rb', line 6 def name @name end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
6 7 8 |
# File 'lib/xccache/swift/sdk.rb', line 6 def platform @platform end |
#vendor ⇒ Object (readonly)
Returns the value of attribute vendor.
6 7 8 |
# File 'lib/xccache/swift/sdk.rb', line 6 def vendor @vendor end |
#version ⇒ Object
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_name ⇒ Object
43 44 45 |
# File 'lib/xccache/swift/sdk.rb', line 43 def sdk_name name == :macos ? :macosx : name end |
#sdk_path ⇒ Object
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_path ⇒ Object
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
67 68 69 |
# File 'lib/xccache/swift/sdk.rb', line 67 def simulator? name.to_s.end_with?("simulator") end |
#swiftc_args ⇒ Object
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_s ⇒ Object
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 |