Class: Fastlane::Actions::CarthageAction

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

Constant Summary

Constants inherited from Fastlane::Action

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

Class Method Summary collapse

Methods inherited from Fastlane::Action

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

Class Method Details

.authorsObject



233
234
235
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 233

def self.authors
  ["bassrock", "petester42", "jschmid", "JaviSoto", "uny", "phatblat", "bfcrampton", "antondomashnev", "gbrhaz"]
end

.available_commandsObject



69
70
71
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 69

def self.available_commands
  %w(build bootstrap update archive)
end

.available_optionsObject



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
103
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 77

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :command,
                                 env_name: "FL_CARTHAGE_COMMAND",
                                 description: "Carthage command (one of: #{available_commands.join(', ')})",
                                 default_value: 'bootstrap',
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass a valid command. Use one of the following: #{available_commands.join(', ')}") unless available_commands.include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :dependencies,
                                 description: "Carthage dependencies to update, build or bootstrap",
                                 default_value: [],
                                 type: Array),
    FastlaneCore::ConfigItem.new(key: :use_ssh,
                                 env_name: "FL_CARTHAGE_USE_SSH",
                                 description: "Use SSH for downloading GitHub repositories",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :use_submodules,
                                 env_name: "FL_CARTHAGE_USE_SUBMODULES",
                                 description: "Add dependencies as Git submodules",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :use_netrc,
                                 env_name: "FL_CARTHAGE_USE_NETRC",
                                 description: "Use .netrc for downloading frameworks",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :use_binaries,
                                 env_name: "FL_CARTHAGE_USE_BINARIES",
                                 description: "Check out dependency repositories even when prebuilt frameworks exist",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :no_checkout,
                                 env_name: "FL_CARTHAGE_NO_CHECKOUT",
                                 description: "When bootstrapping Carthage do not checkout",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :no_build,
                                 env_name: "FL_CARTHAGE_NO_BUILD",
                                 description: "When bootstrapping Carthage do not build",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :no_skip_current,
                                 env_name: "FL_CARTHAGE_NO_SKIP_CURRENT",
                                 description: "Don't skip building the Carthage project (in addition to its dependencies)",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :derived_data,
                                 env_name: "FL_CARTHAGE_DERIVED_DATA",
                                 description: "Use derived data folder at path",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                 env_name: "FL_CARTHAGE_VERBOSE",
                                 description: "Print xcodebuild output inline",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :platform,
                                 env_name: "FL_CARTHAGE_PLATFORM",
                                 description: "Define which platform to build for",
                                 optional: true,
                                 verify_block: proc do |value|
                                   value.split(',').each do |platform|
                                     UI.user_error!("Please pass a valid platform. Use one of the following: #{available_platforms.join(', ')}") unless available_platforms.map(&:downcase).include?(platform.downcase)
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :cache_builds,
                                 env_name: "FL_CARTHAGE_CACHE_BUILDS",
                                 description: "By default Carthage will rebuild a dependency regardless of whether it's the same resolved version as before. Passing the --cache-builds will cause carthage to avoid rebuilding a dependency if it can",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :frameworks,
                                 description: "Framework name or names to archive, could be applied only along with the archive command",
                                 default_value: [],
                                 type: Array),
    FastlaneCore::ConfigItem.new(key: :output,
                                 description: "Output name for the archive, could be applied only along with the archive command. Use following format *.framework.zip",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass a valid string for output. Use following format *.framework.zip") unless value.end_with?("framework.zip")
                                 end),
    FastlaneCore::ConfigItem.new(key: :configuration,
                                 env_name: "FL_CARTHAGE_CONFIGURATION",
                                 description: "Define which build configuration to use when building",
                                 optional: true,
                                 verify_block: proc do |value|
                                   if value.chomp(' ').empty?
                                     UI.user_error!("Please pass a valid build configuration. You can review the list of configurations for this project using the command: xcodebuild -list")
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :toolchain,
                                 env_name: "FL_CARTHAGE_TOOLCHAIN",
                                 description: "Define which xcodebuild toolchain to use when building",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :project_directory,
                                 env_name: "FL_CARTHAGE_PROJECT_DIRECTORY",
                                 description: "Define the directory containing the Carthage project",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :new_resolver,
                                 env_name: "FL_CARTHAGE_NEW_RESOLVER",
                                 description: "Use new resolver when resolving dependency graph",
                                 optional: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :log_path,
                                 env_name: "FL_CARTHAGE_LOG_PATH",
                                 description: "Path to the xcode build output",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :use_xcframeworks,
                                 env_name: "FL_CARTHAGE_USE_XCFRAMEWORKS",
                                 description: "Create xcframework bundles instead of one framework per platform (requires Xcode 12+)",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :archive,
                                 env_name: "FL_CARTHAGE_ARCHIVE",
                                 description: "Archive built frameworks from the current project",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :executable,
                                 env_name: "FL_CARTHAGE_EXECUTABLE",
                                 description: "Path to the `carthage` executable on your machine",
                                 default_value: 'carthage')
  ]
end

.available_platformsObject



73
74
75
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 73

def self.available_platforms
  %w(all iOS Mac tvOS watchOS)
end

.categoryObject



225
226
227
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 225

def self.category
  :building
end

.descriptionObject



65
66
67
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 65

def self.description
  "Runs `carthage` for your project"
end

.example_codeObject



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 201

def self.example_code
  [
    'carthage',
    'carthage(
      frameworks: ["MyFramework1", "MyFramework2"],   # Specify which frameworks to archive (only for the archive command)
      output: "MyFrameworkBundle.framework.zip",      # Specify the output archive name (only for the archive command)
      command: "bootstrap",                           # One of: build, bootstrap, update, archive. (default: bootstrap)
      dependencies: ["Alamofire", "Notice"],          # Specify which dependencies to update or build (only for update, build and bootstrap commands)
      use_ssh: false,                                 # Use SSH for downloading GitHub repositories.
      use_submodules: false,                          # Add dependencies as Git submodules.
      use_binaries: true,                             # Check out dependency repositories even when prebuilt frameworks exist
      no_build: false,                                # When bootstrapping Carthage do not build
      no_skip_current: false,                         # Don\'t skip building the current project (only for frameworks)
      verbose: false,                                 # Print xcodebuild output inline
      platform: "all",                                # Define which platform to build for (one of ‘all’, ‘Mac’, ‘iOS’, ‘watchOS’, ‘tvOS‘, or comma-separated values of the formers except for ‘all’)
      configuration: "Release",                       # Build configuration to use when building
      cache_builds: true,                             # By default Carthage will rebuild a dependency regardless of whether its the same resolved version as before.
      toolchain: "com.apple.dt.toolchain.Swift_2_3",  # Specify the xcodebuild toolchain
      new_resolver: false,                            # Use the new resolver to resolve dependency graph
      log_path: "carthage.log"                        # Path to the xcode build output
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



229
230
231
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 229

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

.run(params) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 5

def self.run(params)
  validate(params)

  cmd = [params[:executable]]
  command_name = params[:command]
  cmd << command_name

  if command_name == "archive" && params[:frameworks].count > 0
    cmd.concat(params[:frameworks])
  # "update", "build" and "bootstrap" are the only commands that support "--derived-data" parameter
  elsif ["update", "build", "bootstrap"].include?(command_name)
    cmd.concat(params[:dependencies]) if params[:dependencies].count > 0
    cmd << "--derived-data #{params[:derived_data].shellescape}" if params[:derived_data]
  end

  cmd << "--output #{params[:output]}" if params[:output]
  cmd << "--use-ssh" if params[:use_ssh]
  cmd << "--use-submodules" if params[:use_submodules]
  cmd << "--use-netrc" if params[:use_netrc]
  cmd << "--no-use-binaries" if params[:use_binaries] == false
  cmd << "--no-checkout" if params[:no_checkout] == true
  cmd << "--no-build" if params[:no_build] == true
  cmd << "--no-skip-current" if params[:no_skip_current] == true
  cmd << "--verbose" if params[:verbose] == true
  cmd << "--platform #{params[:platform]}" if params[:platform]
  cmd << "--configuration #{params[:configuration]}" if params[:configuration]
  cmd << "--toolchain #{params[:toolchain]}" if params[:toolchain]
  cmd << "--project-directory #{params[:project_directory]}" if params[:project_directory]
  cmd << "--cache-builds" if params[:cache_builds]
  cmd << "--new-resolver" if params[:new_resolver]
  cmd << "--log-path #{params[:log_path]}" if params[:log_path]
  cmd << "--use-xcframeworks" if params[:use_xcframeworks]
  cmd << "--archive" if params[:archive]

  Actions.sh(cmd.join(' '))
end

.validate(params) ⇒ Object

rubocop:enable Metrics/PerceivedComplexity



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'fastlane/lib/fastlane/actions/carthage.rb', line 43

def self.validate(params)
  command_name = params[:command]
  if command_name != "archive" && params[:frameworks].count > 0
    UI.user_error!("Frameworks option is available only for 'archive' command.")
  end
  if command_name != "archive" && params[:output]
    UI.user_error!("Output option is available only for 'archive' command.")
  end

  if params[:log_path] && !%w(build bootstrap update).include?(command_name)
    UI.user_error!("Log path option is available only for 'build', 'bootstrap', and 'update' command.")
  end

  if params[:use_xcframeworks] && !%w(build bootstrap update).include?(command_name)
    UI.user_error!("Use XCFrameworks option is available only for 'build', 'bootstrap', and 'update' command.")
  end

  if command_name != "build" && params[:archive]
    UI.user_error!("Archive option is available only for 'build' command.")
  end
end