Skip to content

Commit 3555526

Browse files
Merge #74
74: Simplify cargo bins and reorganize functions in lib.rs r=therealprof a=ZeroErrors ## Added - Added `--no-default-features` cargo argument support - Added `--profile` argument to allow specifying the profile to build the target package with - Added `--frozen`, `--locked`, `--offline` cargo argument support - Added `-Z` argument to allow use of unstable cargo features ## Fixed - Fixed `cargo build` running for `cargo profdata` when its not required - Fixed `--features` not allowing multiple ## Changes - Allowed multiple levels of verbosity and verbose cargo output via `-vv` and `-vvv` - Changed `src/bin/cargo-*.rs` to use `Tool::cargo_exec` similar to `Tool::rust_exec` used in `src/bin/rust-*.rs` - Removed unneeded `Endian` enum and `Context::rustc_cfg` - In-lined `Context::tool` - Moved code so `Context` is only retrieved for `Tool::Objdump` as that's currently the only use case for it, this reduces calls to `rustc_version::version_meta()` for all other tools - Re-split `determine_artifact` and `run` by in-lining and then extracting `args`, `cargo_build` and `cargo_build_args` functions - Organized args to be the same order as in `cargo --help` to allow for easier comparison - Used [`cargo clippy`](https://github.com/rust-lang/rust-clippy) to find and cleanup some minor issues --- Few changes packed together in this one, let me know if you would prefer for it to be broken down. Pending review of this PR, I agree it may be time for a release 😃 r? @therealprof Co-authored-by: Zero <nick@zero.dev>
2 parents 87a0f3e + 001eb9f commit 3555526

11 files changed

Lines changed: 321 additions & 310 deletions

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Added `--quiet` and `--color` arguments to be passed to `cargo build`
1313
- Added `--test` and `--bench` build arguments to allow targeting testing artifacts
1414
- Added `--package` argument so its possible to specify a target package in a workspace
15+
- Added `--no-default-features` cargo argument support
16+
- Added `--profile` argument to allow specifying the profile to build the target package with
17+
- Added `--frozen`, `--locked`, `--offline` cargo argument support
18+
- Added `-Z` argument to allow use of unstable cargo features
1519

1620
### Fixed
1721

@@ -21,13 +25,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2125
- Fixed panic due to broken pipe, caused by `bail!` while `cargo build` is running.
2226
Additionally fixes broken output format due to interrupted stderr output from `cargo build`
2327
- Fixed `rust-*` binaries exiting with exit code 0 if the tool was not found
28+
- Fixed `cargo build` running for `cargo profdata` when its not required
29+
- Fixed `--features` not allowing multiple
2430

2531
### Changed
2632

2733
- Changed help output to more closely reflect the help command of `cargo` subcommands
2834
- Removed `walkdir` dependency by using expected path to tool executable
2935
- Updated `cargo_metadata 0.9 -> 0.10`
3036
- Replaced `failure` dependency with [`anyhow`](https://github.com/dtolnay/anyhow)
37+
- Allowed multiple levels of verbosity and verbose cargo output via `-vv` and `-vvv`
3138

3239
## [v0.2.0] - 2020-04-11
3340

src/bin/cargo-nm.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
use std::process;
2-
3-
use cargo_binutils::Tool;
4-
51
const EXAMPLES: &str = "
62
73
EXAMPLES
@@ -10,8 +6,5 @@ EXAMPLES
106
`cargo nm --lib -- -print-size -size-sort` - lists all symbols sorted by size (smallest first)";
117

128
fn main() {
13-
match cargo_binutils::run(Tool::Nm, Some(EXAMPLES)) {
14-
Err(e) => eprintln!("error: {}", e),
15-
Ok(ec) => process::exit(ec),
16-
}
9+
cargo_binutils::Tool::Nm.cargo_exec(Some(EXAMPLES))
1710
}

src/bin/cargo-objcopy.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
use std::process;
2-
3-
use cargo_binutils::Tool;
4-
51
const EXAMPLES: &str = "
62
73
EXAMPLES
84
95
`cargo objcopy --bin foo -- -O binary foo.hex` - converts the output (e.g. ELF) into binary format";
106

117
fn main() {
12-
match cargo_binutils::run(Tool::Objcopy, Some(EXAMPLES)) {
13-
Err(e) => eprintln!("error: {}", e),
14-
Ok(ec) => process::exit(ec),
15-
}
8+
cargo_binutils::Tool::Objcopy.cargo_exec(Some(EXAMPLES))
169
}

src/bin/cargo-objdump.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
use std::process;
2-
3-
use cargo_binutils::Tool;
4-
51
const EXAMPLES: &str = "
62
73
EXAMPLES
@@ -10,8 +6,5 @@ EXAMPLES
106
`cargo objdump --bin foo --release -- -s -j .rodata` - prints the contents of the .rodata section";
117

128
fn main() {
13-
match cargo_binutils::run(Tool::Objdump, Some(EXAMPLES)) {
14-
Err(e) => eprintln!("error: {}", e),
15-
Ok(ec) => process::exit(ec),
16-
}
9+
cargo_binutils::Tool::Objdump.cargo_exec(Some(EXAMPLES))
1710
}

src/bin/cargo-profdata.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
use std::process;
2-
3-
use cargo_binutils::Tool;
4-
51
fn main() {
6-
match cargo_binutils::run(Tool::Profdata, None) {
7-
Err(e) => eprintln!("error: {}", e),
8-
Ok(ec) => process::exit(ec),
9-
}
2+
cargo_binutils::Tool::Profdata.cargo_exec(None)
103
}

src/bin/cargo-readobj.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
use std::process;
2-
3-
use cargo_binutils::Tool;
4-
51
const EXAMPLES: &str = "
62
73
EXAMPLES
@@ -10,8 +6,5 @@ EXAMPLES
106
`cargo readobj --bin app -- -t` - Displays the symbol table";
117

128
fn main() {
13-
match cargo_binutils::run(Tool::Readobj, Some(EXAMPLES)) {
14-
Err(e) => eprintln!("error: {}", e),
15-
Ok(ec) => process::exit(ec),
16-
}
9+
cargo_binutils::Tool::Readobj.cargo_exec(Some(EXAMPLES))
1710
}

src/bin/cargo-size.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
use std::process;
2-
3-
use cargo_binutils::Tool;
4-
51
const EXAMPLES: &str = "
62
73
EXAMPLES
@@ -10,8 +6,5 @@ EXAMPLES
106
`cargo size --bin foo --release -- -A` - prints binary size in System V format";
117

128
fn main() {
13-
match cargo_binutils::run(Tool::Size, Some(EXAMPLES)) {
14-
Err(e) => eprintln!("error: {}", e),
15-
Ok(ec) => process::exit(ec),
16-
}
9+
cargo_binutils::Tool::Size.cargo_exec(Some(EXAMPLES))
1710
}

src/bin/cargo-strip.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
use std::process;
2-
3-
use cargo_binutils::Tool;
4-
51
const EXAMPLES: &str = "
62
73
EXAMPLES
84
95
`cargo strip --bin foo --release -- -strip-all -o stripped` - strips all symbols";
106

117
fn main() {
12-
match cargo_binutils::run(Tool::Strip, Some(EXAMPLES)) {
13-
Err(e) => eprintln!("error: {}", e),
14-
Ok(ec) => process::exit(ec),
15-
}
8+
cargo_binutils::Tool::Strip.cargo_exec(Some(EXAMPLES))
169
}

0 commit comments

Comments
 (0)