Skip to content

Commit f4d314a

Browse files
committed
Add some YARD documentation to helper methods
1 parent 40b5c58 commit f4d314a

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_send_app_size_metrics.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,24 @@ def self.run(params)
5858
)
5959
end
6060

61+
#####################################################
6162
# @!group Small helper methods
63+
#####################################################
6264
class << self
65+
# @raise if `bundletool` can not be found in `$PATH`
6366
def check_bundletool_installed!
6467
Action.sh('command', '-v', 'bundletool', print_command: false, print_command_output: false)
6568
rescue StandardError
66-
UI.user_error!('bundletool is required to build the split APKs. Install it with `brew install bundletool`')
69+
UI.user_error!('`bundletool` is required to build the split APKs. Install it with `brew install bundletool`')
6770
raise
6871
end
6972

73+
# The path where the `apkanalyzer` binary was found, after searching it:
74+
# - in priority in `$ANDROID_SDK_ROOT` (or `$ANDROID_HOME` for legacy setups), under `cmdline-tools/latest/bin/` or `cmdline-tools/tools/bin`
75+
# - and falling back by trying to find it in `$PATH`
76+
#
77+
# @return [String,Nil] The path to `apkanalyzer`, or `nil` if it wasn't found in any of the above tested paths.
78+
#
7079
def find_apkanalyzer_binary
7180
sdk_root = ENV['ANDROID_SDK_ROOT'] || ENV['ANDROID_HOME']
7281
if sdk_root
@@ -76,12 +85,26 @@ def find_apkanalyzer_binary
7685
apkanalyzer_bin || Action.sh('command', '-v', 'apkanalyzer', print_command_output: false) { |_| nil }
7786
end
7887

88+
# The path where the `apkanalyzer` binary was found, after searching it:
89+
# - in priority in `$ANDROID_SDK_ROOT` (or `$ANDROID_HOME` for legacy setups), under `cmdline-tools/latest/bin/` or `cmdline-tools/tools/bin`
90+
# - and falling back by trying to find it in `$PATH`
91+
#
92+
# @return [String] The path to `apkanalyzer`
93+
# @raise [FastlaneCore::Interface::FastlaneError] if it wasn't found in any of the above tested paths.
94+
#
7995
def find_apkanalyzer_binary!
8096
apkanalyzer_bin = find_apkanalyzer_binary
8197
UI.user_error!('Unable to find `apkanalyzer` executable in `$PATH` nor `$ANDROID_SDK_ROOT`. Make sure you installed the Android SDK Command-line Tools') if apkanalyzer_bin.nil?
8298
apkanalyzer_bin
8399
end
84100

101+
# Add the `file-size` and `download-size` values of an APK to the helper, as reported by the corresponding `apkanalyzer apk …` commands
102+
#
103+
# @param [Fastlane::Helper::AppSizeMetricsHelper] helper The helper to add the metrics to
104+
# @param [String] apkanalyzer_bin The path to the `apkanalyzer` binary to use to extract those file and download sizes from the `.apk`
105+
# @param [String] apk The path to the `.apk` file to extract the sizes from
106+
# @param [String] split_name The name to use for the value of the `split` metadata key in the metrics being added
107+
#
85108
def add_apk_size_metrics(helper:, apkanalyzer_bin:, apk:, split_name:)
86109
UI.message("[App Size Metrics] Computing file and download size of #{File.basename(apk)}...")
87110
file_size = Action.sh(apkanalyzer_bin, 'apk', 'file-size', apk, print_command: false, print_command_output: false).chomp.to_i
@@ -90,6 +113,13 @@ def add_apk_size_metrics(helper:, apkanalyzer_bin:, apk:, split_name:)
90113
helper.add_metric(name: APK_OPTIMIZED_DOWNLOAD_SIZE_KEY, value: download_size, metadata: { split: split_name })
91114
end
92115

116+
# Generates all the split `.apk` files (typically one per device architecture) from a given `.aab` file, then yield for each apk produced.
117+
#
118+
# @note The split `.apk` files are generated in a temporary directory and are thus all deleted after each of them has been `yield`ed to the provided block.
119+
# @param [String] aab_path The path to the `.aab` file to generate split `.apk` files for
120+
# @yield [apk] Calls the provided block once for each split `.apk` that was generated from the `.aab`
121+
# @yieldparam apk [String] The path to one of the split `.apk` temporary file generated from the `.aab`
122+
#
93123
def generate_split_apks(aab_path:, &block)
94124
check_bundletool_installed!
95125
UI.message("[App Size Metrics] Generating the various APK splits from #{aab_path}...")

0 commit comments

Comments
 (0)