Class: Fastlane::Actions::CreateXcframeworkAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/create_xcframework.rb

Constant Summary collapse

PARAMETERS_TO_OPTIONS =
{ headers: '-headers', dsyms: '-debug-symbols' }

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, return_type, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.artifact_info_as_options(artifact_info) ⇒ Object



50
51
52
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 50

def self.artifact_info_as_options(artifact_info)
  artifact_info.map { |type, file| [PARAMETERS_TO_OPTIONS[type], "\"#{file}\""] }.flatten
end

.authorsObject



194
195
196
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 194

def self.authors
  ["jgongo"]
end

.available_optionsObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 104

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :frameworks,
                                 env_name: "FL_CREATE_XCFRAMEWORK_FRAMEWORKS",
                                 description: "Frameworks (without dSYMs) to add to the target xcframework",
                                 type: Array,
                                 optional: true,
                                 conflicting_options: [:frameworks_with_dsyms, :libraries, :libraries_with_headers_or_dsyms],
                                 verify_block: proc do |value|
                                   normalized_artifact_info(value, [:dsyms]).each do |framework, framework_info|
                                     UI.user_error!("#{framework} doesn't end with '.framework'. Is this really a framework?") unless framework.end_with?('.framework')
                                     UI.user_error!("Couldn't find framework at #{framework}") unless File.exist?(framework)
                                     UI.user_error!("#{framework} doesn't seem to be a framework") unless File.directory?(framework)
                                     check_artifact_info(framework_info)
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :frameworks_with_dsyms,
                                 env_name: "FL_CREATE_XCFRAMEWORK_FRAMEWORKS_WITH_DSYMS",
                                 description: "Frameworks (with dSYMs) to add to the target xcframework",
                                 type: Hash,
                                 optional: true,
                                 conflicting_options: [:frameworks, :libraries, :libraries_with_headers_or_dsyms],
                                 verify_block: proc do |value|
                                   normalized_artifact_info(value, [:dsyms]).each do |framework, framework_info|
                                     UI.user_error!("#{framework} doesn't end with '.framework'. Is this really a framework?") unless framework.end_with?('.framework')
                                     UI.user_error!("Couldn't find framework at #{framework}") unless File.exist?(framework)
                                     UI.user_error!("#{framework} doesn't seem to be a framework") unless File.directory?(framework)
                                     check_artifact_info(framework_info)
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :libraries,
                                 env_name: "FL_CREATE_XCFRAMEWORK_LIBRARIES",
                                 description: "Libraries (without headers or dSYMs) to add to the target xcframework",
                                 type: Array,
                                 optional: true,
                                 conflicting_options: [:frameworks, :frameworks_with_dsyms, :libraries_with_headers_or_dsyms],
                                 verify_block: proc do |value|
                                   normalized_artifact_info(value, [:headers, :dsyms]).each do |library, library_info|
                                     UI.user_error!("Couldn't find library at #{library}") unless File.exist?(library)
                                     check_artifact_info(library_info)
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :libraries_with_headers_or_dsyms,
                                 env_name: "FL_CREATE_XCFRAMEWORK_LIBRARIES_WITH_HEADERS_OR_DSYMS",
                                 description: "Libraries (with headers or dSYMs) to add to the target xcframework",
                                 type: Hash,
                                 optional: true,
                                 conflicting_options: [:frameworks, :frameworks_with_dsyms, :libraries],
                                 verify_block: proc do |value|
                                   normalized_artifact_info(value, [:headers, :dsyms]).each do |library, library_info|
                                     UI.user_error!("Couldn't find library at #{library}") unless File.exist?(library)
                                     check_artifact_info(library_info)
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :output,
                                 env_name: "FL_CREATE_XCFRAMEWORK_OUTPUT",
                                 description: "The path to write the xcframework to",
                                 type: String,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :allow_internal_distribution,
                                 env_name: "FL_CREATE_XCFRAMEWORK_ALLOW_INTERNAL_DISTRIBUTION",
                                 description: "Specifies that the created xcframework contains information not suitable for public distribution",
                                 type: Boolean,
                                 optional: true,
                                 default_value: false)
  ]
end

.categoryObject



190
191
192
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 190

def self.category
  :building
end

.check_artifact_info(artifact_info) ⇒ Object



54
55
56
57
58
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 54

def self.check_artifact_info(artifact_info)
  UI.user_error!("Headers and dSYMs information should be a hash") unless artifact_info.kind_of?(Hash)
  UI.user_error!("#{artifact_info[:headers]} doesn't exist or is not a directory") if artifact_info[:headers] && !File.directory?(artifact_info[:headers])
  UI.user_error!("#{artifact_info[:dsyms]} doesn't seem to be a dSYM archive") if artifact_info[:dsyms] && !File.directory?(artifact_info[:dsyms])
end

.descriptionObject



64
65
66
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 64

def self.description
  "Package multiple build configs of a library/framework into a single xcframework"
end

.detailsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 68

def self.details
  <<~DETAILS
    Utility for packaging multiple build configurations of a given library
    or framework into a single xcframework.

    If you want to package several frameworks just provide one of:

      * An array containing the list of frameworks using the :frameworks parameter
        (if they have no associated dSYMs):
          ['FrameworkA.framework', 'FrameworkB.framework']

      * A hash containing the list of frameworks with their dSYMs using the
        :frameworks_with_dsyms parameter:
          {
            'FrameworkA.framework' => {},
            'FrameworkB.framework' => { dsyms: 'FrameworkB.framework.dSYM' }
          }

    If you want to package several libraries just provide one of:

      * An array containing the list of libraries using the :libraries parameter
        (if they have no associated headers or dSYMs):
          ['LibraryA.so', 'LibraryB.so']

      * A hash containing the list of libraries with their headers and dSYMs
        using the :libraries_with_headers_or_dsyms parameter:
          {
            'LibraryA.so' => { dsyms: 'libraryA.so.dSYM' },
            'LibraryB.so' => { headers: 'headers' }
          }

    Finally specify the location of the xcframework to be generated using the :output
    parameter.
  DETAILS
end

.example_codeObject



181
182
183
184
185
186
187
188
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 181

def self.example_code
  [
    "create_xcframework(frameworks: ['FrameworkA.framework', 'FrameworkB.framework'], output: 'UniversalFramework.xcframework')",
    "create_xcframework(frameworks_with_dsyms: {'FrameworkA.framework' => {}, 'FrameworkB.framework' => { dsyms: 'FrameworkB.framework.dSYM' } }, output: 'UniversalFramework.xcframework')",
    "create_xcframework(libraries: ['LibraryA.so', 'LibraryB.so'], output: 'UniversalFramework.xcframework')",
    "create_xcframework(libraries_with_headers_or_dsyms: { 'LibraryA.so' => { dsyms: 'libraryA.so.dSYM' }, 'LibraryB.so' => { headers: 'LibraryBHeaders' } }, output: 'UniversalFramework.xcframework')"
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



198
199
200
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 198

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.normalized_artifact_info(artifacts_with_info, valid_info) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 34

def self.normalized_artifact_info(artifacts_with_info, valid_info)
  case artifacts_with_info
  when Array
    artifacts_with_info.map { |artifact| [artifact, {}] }.to_h
  when Hash
    # Convert keys of artifact info to symbols ('dsyms' to :dsyms) and only keep keys we are interested in
    # For example with valid_info = [:dsyms]
    #  { 'FrameworkA.framework' => { 'dsyms' => 'FrameworkA.framework.dSYM', 'foo' => bar } }
    # gets converted to
    #  { 'FrameworkA.framework' => { dsyms: 'FrameworkA.framework.dSYM' } }
    artifacts_with_info.transform_values { |artifact_info| artifact_info.transform_keys(&:to_sym).slice(*valid_info) }
  else
    artifacts_with_info
  end
end

.outputObject



172
173
174
175
176
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 172

def self.output
  [
    ['XCFRAMEWORK_PATH', 'Location of the generated xcframework']
  ]
end

.return_valueObject



178
179
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 178

def self.return_value
end

.run(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'fastlane/lib/fastlane/actions/create_xcframework.rb', line 10

def self.run(params)
  artifacts = normalized_artifact_info(params[:frameworks], [:dsyms]) ||
              normalized_artifact_info(params[:frameworks_with_dsyms], [:dsyms]) ||
              normalized_artifact_info(params[:libraries], [:headers, :dsyms]) ||
              normalized_artifact_info(params[:libraries_with_headers_or_dsyms], [:headers, :dsyms])

  UI.user_error!("Please provide either :frameworks, :frameworks_with_dsyms, :libraries or :libraries_with_headers_or_dsyms to be packaged into the xcframework") unless artifacts

  artifacts_type = params[:frameworks] || params[:frameworks_with_dsyms] ? '-framework' : '-library'
  create_command = ['xcodebuild', '-create-xcframework']
  create_command << artifacts.map { |artifact, artifact_info| [artifacts_type, "\"#{artifact}\""] + artifact_info_as_options(artifact_info) }.flatten
  create_command << ['-output', "\"#{params[:output]}\""]
  create_command << ['-allow-internal-distribution'] if params[:allow_internal_distribution]

  if File.directory?(params[:output])
    UI.message("Deleting existing: #{params[:output]}")
    FileUtils.remove_dir(params[:output])
  end

  Actions.lane_context[SharedValues::XCFRAMEWORK_PATH] = params[:output]

  sh(create_command)
end