Class: Pod::Xcode::XCFramework::Slice

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/xcode/xcframework/xcframework_slice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, identifier, archs, platform, platform_variant: nil, headers: path.join('Headers')) ⇒ Slice

Returns a new instance of Slice.



31
32
33
34
35
36
37
38
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 31

def initialize(path, identifier, archs, platform, platform_variant: nil, headers: path.join('Headers'))
  @path = path
  @identifier = identifier
  @supported_archs = archs
  @platform = Pod::Platform.new(platform)
  @platform_variant = platform_variant.to_sym unless platform_variant.nil?
  @headers = headers
end

Instance Attribute Details

#headersPathname (readonly)

Returns the path to the headers.

Returns:

  • (Pathname)

    the path to the headers



29
30
31
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 29

def headers
  @headers
end

#identifierString (readonly)

Returns the framework identifier.

Returns:

  • (String)

    the framework identifier



17
18
19
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 17

def identifier
  @identifier
end

#pathPathname (readonly)

Returns the path to the .framework, .a or .dylib of this slice.

Returns:

  • (Pathname)

    the path to the .framework, .a or .dylib of this slice



9
10
11
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 9

def path
  @path
end

#platformPlatform (readonly)

Returns the supported platform.

Returns:

  • (Platform)

    the supported platform



21
22
23
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 21

def platform
  @platform
end

#platform_variantSymbol (readonly)

Returns the platform variant. Either :simulator or nil.

Returns:

  • (Symbol)

    the platform variant. Either :simulator or nil



25
26
27
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 25

def platform_variant
  @platform_variant
end

#supported_archsArray<String> (readonly)

Returns list of supported architectures.

Returns:

  • (Array<String>)

    list of supported architectures



13
14
15
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 13

def supported_archs
  @supported_archs
end

Instance Method Details

#binary_pathPathname

Returns the path to the bundled binary.

Returns:

  • (Pathname)

    the path to the bundled binary



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 129

def binary_path
  @binary_path ||= begin
    case package_type
    when :framework
      path + name
    when :library
      path
    else
      raise Informative, "Invalid package type `#{package_type}`"
    end
  end
end

#build_typeBuildType

Returns the build type of the binary.

Returns:

  • (BuildType)

    the build type of the binary



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 111

def build_type
  @build_type ||= begin
    linkage = Xcode::LinkageAnalyzer.dynamic_binary?(binary_path) ? :dynamic : :static
    ext = File.extname(path)
    packaging = case ext
                when '.framework'
                  :framework
                when '.a', '.dylib'
                  :library
                else
                  raise Informative, "Invalid XCFramework slice type `#{ext}`"
                end
    BuildType.new(:linkage => linkage, :packaging => packaging)
  end
end

#dynamic?Boolean

Returns true if this slice contains a dynamically-linked binary.

Returns:

  • (Boolean)

    true if this slice contains a dynamically-linked binary



105
106
107
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 105

def dynamic?
  build_type.dynamic?
end

#framework?Boolean

Returns true if this slice is a framework, not a library.

Returns:

  • (Boolean)

    true if this slice is a framework, not a library



87
88
89
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 87

def framework?
  build_type.framework?
end

#library?Boolean

Returns true if this slice is a library, not a framework.

Returns:

  • (Boolean)

    true if this slice is a library, not a framework



93
94
95
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 93

def library?
  build_type.library?
end

#nameString

Returns the name of the framework.

Returns:

  • (String)

    the name of the framework



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 42

def name
  @name ||= begin
    case package_type
    when :framework
      File.basename(path, '.framework')
    when :library
      ext = File.extname(path)
      case ext
      when '.a', '.dylib'
        result = File.basename(path).gsub(/^lib/, '')
        result[0] = result.downcase[0]
        result
      else
        raise Informative, "Invalid package type `#{package_type}`"
      end
    else
      raise Informative, "Invalid package type `#{package_type}`"
    end
  end
end

#package_typeSymbol

Returns the package type of the slice - either :framework or :library.

Returns:

  • (Symbol)

    the package type of the slice - either :framework or :library



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 71

def package_type
  @package_type ||= begin
    ext = File.extname(path)
    case ext
    when '.framework'
      :framework
    when '.a', '.dylib'
      :library
    else
      raise Informative, "Invalid XCFramework slice type `#{ext}`"
    end
  end
end

#simulator_variant?Boolean

Returns true if this is a slice built for simulator.

Returns:

  • (Boolean)

    true if this is a slice built for simulator



65
66
67
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 65

def simulator_variant?
  @platform_variant == :simulator
end

#static?Boolean

Returns true if this slice contains a statically-linked binary.

Returns:

  • (Boolean)

    true if this slice contains a statically-linked binary



99
100
101
# File 'lib/cocoapods/xcode/xcframework/xcframework_slice.rb', line 99

def static?
  build_type.static?
end