android_tools/bundletool/get_size_total.rs
1use super::bundletool;
2use crate::error::*;
3use std::path::{Path, PathBuf};
4
5/// ## Measure the estimated download sizes of APKs in an APK set
6///
7/// To measure the estimated download sizes of APKs in an APK set as they would be served
8/// compressed over-the-wire, use the `get-size total` command:
9///
10/// ```sh
11/// `bundletool get-size total --apks=/MyApp/my_app.apks`
12/// ```
13///
14/// You can modify the behavior of the `get-size total` command using the following flags:
15#[derive(Default)]
16pub struct GetSizeTotal {
17 apks: PathBuf,
18 device_spec: Option<PathBuf>,
19 dimensions: Option<String>,
20 instant: bool,
21 modules: Option<String>,
22}
23
24impl GetSizeTotal {
25 /// (Required) Specifies the path to the existing APK set file whose download size is
26 /// measured
27 pub fn new(apks: &Path) -> Self {
28 Self {
29 apks: apks.to_owned(),
30 ..Default::default()
31 }
32 }
33
34 /// Specifies the path to the device spec file (from get-device-spec or constructed
35 /// manually) to use for matching. You can specify a partial path to evaluate a set of
36 /// configurations
37 pub fn device_spec(&mut self, device_spec: &Path) -> &mut Self {
38 self.device_spec = Some(device_spec.to_owned());
39 self
40 }
41
42 /// Specifies the dimensions used when computing the size estimates.
43 /// Accepts a comma-separated list of: `SDK`, `ABI`, `SCREEN_DENSITY`, and `LANGUAGE`.
44 /// To measure across all dimensions, specify `ALL`
45 pub fn dimensions(&mut self, dimensions: String) -> &mut Self {
46 self.dimensions = Some(dimensions);
47 self
48 }
49
50 /// Measures the download size of the instant-enabled APKs instead of the installable
51 /// APKs. By default, `bundletool` measures the installable APK download sizes
52 pub fn instant(&mut self, instant: bool) -> &mut Self {
53 self.instant = instant;
54 self
55 }
56
57 /// Specifies a comma-separated list of modules in the APK set to consider in the
58 /// measurement. The `bundletool` command automatically includes any dependent modules
59 /// for the specified set. By default, the command measures the download size of
60 /// all modules installed during the first download
61 pub fn modules(&mut self, modules: String) -> &mut Self {
62 self.modules = Some(modules);
63 self
64 }
65
66 /// Runs `bundletool` commands to measure the estimated download sizes of APKs in an APK set
67 pub fn run(&self) -> Result<()> {
68 let mut get_size_total = bundletool()?;
69 get_size_total.arg("get-size");
70 get_size_total.arg("total");
71 get_size_total.arg("--apks");
72 get_size_total.arg(&self.apks);
73 if let Some(device_spec) = &self.device_spec {
74 get_size_total.arg("--device-spec").arg(device_spec);
75 }
76 if let Some(dimensions) = &self.dimensions {
77 get_size_total.arg("--dimensions").arg(dimensions);
78 }
79 if self.instant {
80 get_size_total.arg("--instant");
81 }
82 if let Some(modules) = &self.modules {
83 get_size_total.arg("--modules").arg(modules);
84 }
85 get_size_total.output_err(true)?;
86 Ok(())
87 }
88}