Skip to content

Commit fc9e42d

Browse files
committed
Improve CLI args/output
- Don't require the output path to have .apk on the end - Print a clearer warning about random keys - Use stderr for warnings, not stdout - Print the locations of files written to disk - Print a "finished" message instead of remaining silent
1 parent bc480fc commit fc9e42d

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ JAR Signing and the APK Signature Scheme v2 and v3.
2727

2828
<details>
2929
<summary><h3>...as a CLI</h3></summary>
30+
3031
pack can be used in place of `aapt2` etc. on desktop machines. After cloning the
3132
repo:
3233

3334
```sh
34-
$ cargo run -p pack-cli ./watchface watchface.apk
35-
# Will generate both watchface.apk and watchface.aab.
36-
# Both will be signed using a built-in testing key/certificate.
35+
$ cargo run -p pack-cli ./watchface ./package
36+
# Will generate both package.apk and package.aab.
37+
# Both will be signed using a random testing key/certificate.
38+
# For custom signing, pass a .pem file as a third CLI argument.
3739
```
40+
3841
</details>
3942

4043
<details>

pack-asset-compiler/src/xml_file.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ pub fn xml_to_res_chunk<T: Read + Seek>(
329329
}
330330
Ok(XmlEvent::EndDocument) => {}
331331
Err(e) => return Err(PackError::XmlParsingFailed(e)),
332-
_ => println!("Warning: Unknown XML part: {:?}", event.unwrap())
332+
// TODO: Don't println from within this library crate, consumers might not want that
333+
_ => eprintln!("Warning: Unknown XML part: {:?}", event.unwrap())
333334
}
334335
}
335336

pack-cli/src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub mod res_dir;
2424
/// ```
2525
/// $ ls ./watchface
2626
/// res/ AndroidManifest.xml
27-
/// $ pack-cli ./watchface ./watchface/package.apk
27+
/// $ pack-cli ./watchface ./watchface/package
2828
/// $ ls ./watchface
2929
/// res/ AndroidManifest.xml package.apk package.aab
3030
/// ```
@@ -41,10 +41,11 @@ fn main() -> Result<()> {
4141
let in_dir = env::args()
4242
.nth(1)
4343
.ok_or(PackError::Cli("Input directory path not provided".into()))?;
44-
let out_apk_path = env::args()
44+
let out_path = env::args()
4545
.nth(2)
4646
.ok_or(PackError::Cli("Output APK path not provided".into()))?;
47-
let out_aab_path = PathBuf::from(&out_apk_path).with_extension("aab");
47+
let out_apk_path = PathBuf::from(&out_path).with_extension("apk");
48+
let out_aab_path = PathBuf::from(&out_path).with_extension("aab");
4849

4950
let signing_keys =
5051
env::args()
@@ -72,9 +73,13 @@ fn main() -> Result<()> {
7273
};
7374

7475
let apk = compile_and_sign_apk(&pkg, &signing_keys)?;
75-
fs::write(out_apk_path, apk)?;
76+
fs::write(&out_apk_path, apk)?;
77+
println!("Wrote {:?} to disk", out_apk_path);
7678
let aab = compile_and_sign_aab(&pkg, &signing_keys)?;
77-
fs::write(out_aab_path, aab)?;
79+
fs::write(&out_aab_path, aab)?;
80+
println!("Wrote {:?} to disk", out_aab_path);
81+
82+
println!("Compiled, aligned & signed successfully!");
7883

7984
Ok(())
8085
}

pack-cli/src/res_dir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn read_res_dir(res_path: &PathBuf) -> Result<Vec<FileResource>> {
2828
}
2929
}
3030
}
31-
println!("Warning: Ignoring unusable res/ entry {:?}", res_type)
31+
eprintln!("Warning: Ignoring unusable res/ entry {:?}", res_type)
3232
}
3333
Ok(resources)
3434
}
@@ -37,7 +37,7 @@ fn collect_resources(path: &PathBuf, resources: &mut Vec<FileResource>) {
3737
let res_name = path.file_name().unwrap().to_string_lossy();
3838
let maybe_resource_files = fs::read_dir(path);
3939
if let Err(err) = maybe_resource_files {
40-
println!(
40+
eprintln!(
4141
"Warning: Failed to read res/ subdirectory {} {:?}",
4242
res_name, err
4343
);
@@ -63,7 +63,7 @@ fn collect_resources(path: &PathBuf, resources: &mut Vec<FileResource>) {
6363
}
6464
}
6565
}
66-
println!(
66+
eprintln!(
6767
"Warning: Ignoring unusable {} resource entry {:?}",
6868
res_name, file
6969
)

pack-sign/src/crypto_keys.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ impl Keys {
9696
use rcgen::{CertificateParams, DistinguishedName, DnType, KeyPair};
9797
use rsa::pkcs8::{EncodePrivateKey, LineEnding};
9898

99-
println!("Warning: Randomly generating a placeholder signing key. This is slow!");
99+
eprintln!("Warning: Randomly generating a placeholder signing key. This is slow!");
100+
eprintln!(" It's recommended to generate your own keys first and pass them in.");
100101

101102
// Randomly generate an RSA Private Key, derive its Public Key,
102103
// and prepare it for passing over to the rcgen library.

0 commit comments

Comments
 (0)