android_tools_rs/bundletool/
get_size_total.rs1use crate::error::*;
2use std::path::{Path, PathBuf};
3use std::process::Command;
4
5pub struct GetSizeTotal {
14 apks: PathBuf,
15 device_spec: Option<PathBuf>,
16 dimensions: Option<String>,
17 instant: bool,
18 modules: Option<String>,
19}
20
21impl GetSizeTotal {
22 pub fn new(apks: &Path) -> Self {
25 Self {
26 apks: apks.to_owned(),
27 device_spec: None,
28 dimensions: None,
29 instant: false,
30 modules: None,
31 }
32 }
33
34 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 pub fn dimensions(&mut self, dimensions: String) -> &mut Self {
46 self.dimensions = Some(dimensions);
47 self
48 }
49
50 pub fn instant(&mut self, instant: bool) -> &mut Self {
53 self.instant = instant;
54 self
55 }
56
57 pub fn modules(&mut self, modules: String) -> &mut Self {
62 self.modules = Some(modules);
63 self
64 }
65
66 pub fn run(&self) -> Result<()> {
67 let mut get_size_total = Command::new("java");
68 get_size_total.arg("-jar");
69 if let Ok(bundletool_path) = std::env::var("BUNDLETOOL_PATH") {
70 get_size_total.arg(bundletool_path);
71 } else {
72 return Err(Error::BundletoolNotFound);
73 }
74 get_size_total.arg("get-size");
75 get_size_total.arg("total");
76 get_size_total.arg("--apks");
77 get_size_total.arg(&self.apks);
78 if let Some(device_spec) = &self.device_spec {
79 get_size_total.arg("--device-spec").arg(device_spec);
80 }
81 if let Some(dimensions) = &self.dimensions {
82 get_size_total.arg("--dimensions").arg(dimensions);
83 }
84 if self.instant {
85 get_size_total.arg("--instant");
86 }
87 if let Some(modules) = &self.modules {
88 get_size_total.arg("--modules").arg(modules);
89 }
90 get_size_total.output_err(true)?;
91 Ok(())
92 }
93}