diff --git a/cargo-apk/src/config.rs b/cargo-apk/src/config.rs index 5f796ac..6536886 100644 --- a/cargo-apk/src/config.rs +++ b/cargo-apk/src/config.rs @@ -19,6 +19,9 @@ pub struct AndroidConfig { pub ndk_path: PathBuf, /// How to invoke `gradle`. pub gradle_command: String, + /// Stuff to include in the build.gradle file instead of the hard-coded + /// repository information + pub build_gradle_inc: Option, /// Name that the package will have on the Android machine. /// This is the key that Android uses to identify your package, so it should be unique for @@ -128,6 +131,10 @@ pub fn load(workspace: &Workspace, flag_package: &Option) -> Result) -> Result App<'static, 'static> { .arg_manifest_path() .arg_message_format() .arg_build_plan() + .arg_verbose() + .arg_quiet() + .arg_color() + .arg_frozen() + .arg_locked() .after_help( "\ All packages in the workspace are built if the `--all` flag is supplied. The @@ -429,6 +434,29 @@ pub trait AppExt: Sized { self._arg(opt("build-plan", "Output the build plan in JSON")) } + fn arg_verbose(self) -> Self { + self._arg(opt("verbose", "Use verbose output") + .short("v")) + } + + fn arg_quiet(self) -> Self { + self._arg(opt("quiet", "No output printed to stdout") + .short("q")) + } + + fn arg_color(self) -> Self { + self._arg(opt("color", "Coloring: auto, always, never") + .value_name("WHEN")) + } + + fn arg_frozen(self) -> Self { + self._arg(opt("frozen", "Require Cargo.lock and cache are up to date")) + } + + fn arg_locked(self) -> Self { + self._arg(opt("locked", "Require Cargo.lock is up to date")) + } + fn arg_new_opts(self) -> Self { self._arg( opt( diff --git a/cargo-apk/src/ops/build.rs b/cargo-apk/src/ops/build.rs index cbde31a..923cef2 100644 --- a/cargo-apk/src/ops/build.rs +++ b/cargo-apk/src/ops/build.rs @@ -3,7 +3,7 @@ use std::collections::{HashSet, HashMap}; use std::env; use std::fs; use std::fs::File; -use std::io::{self, BufRead, BufReader, Write}; +use std::io::{self, BufRead, BufReader, Read, Write}; use std::path::Path; use std::path::PathBuf; use std::process::{Command, Stdio}; @@ -327,11 +327,15 @@ pub fn build(workspace: &Workspace, config: &AndroidConfig, options: &ArgMatches // Invoking `gradle` from within `android-artifacts` in order to compile the project. drop(writeln!(workspace.config().shell().err(), "Invoking gradle")); let mut cmd = process(&config.gradle_command); + if workspace.config().frozen() { + cmd.arg("--offline"); + } if config.release { cmd.arg("assembleRelease"); } else { cmd.arg("assembleDebug"); } + drop(writeln!(workspace.config().shell().err(), "{}", cmd)); cmd.cwd(&android_artifacts_dir) .exec()?; @@ -578,7 +582,13 @@ fn build_build_gradle_root(_: &Workspace, path: &Path, config: &AndroidConfig) - //if fs::metadata(&file).is_ok() { return; } let mut file = File::create(&file).unwrap(); - write!(file, r#" + if let Some(ref inc) = config.build_gradle_inc { + let mut inc_contents = File::open(inc).unwrap(); + let mut contents = String::new(); + inc_contents.read_to_string(&mut contents).unwrap(); + writeln!(file, "{}", contents)?; + } else { + write!(file, r#" buildscript {{ repositories {{ jcenter() @@ -592,6 +602,9 @@ allprojects {{ jcenter() }} }} +"#)?; + } + write!(file, r#" ext {{ compileSdkVersion = {android_version} buildToolsVersion = "{build_tools_version}"