Skip to content
Snippets Groups Projects
Commit 4d51eeec authored by Per Lindgren's avatar Per Lindgren
Browse files

polish

parent 6fe6bb79
No related branches found
No related tags found
No related merge requests found
...@@ -23,5 +23,18 @@ Cargo uses the `target` directory for storing build artifacts. In our case we ar ...@@ -23,5 +23,18 @@ Cargo uses the `target` directory for storing build artifacts. In our case we ar
Cargo identifies a build context by a unique hash in order to distinguish cashed compilation units between builds (under different configurations). To that end, we need to determine the current hash to determine the full path of the generated llvm ir (e.g. `target/thumbv7m-none-eabi/release/examples/hello1-f3268774e62977a5.ll`, `f3268774e62977a5` being the hash). While `Cargo` can be accessed as a library, it does not (AFAIK) provide a stable API. A pragmatic solotion is to parse the actual invocation parameters to `rustc` to determine the current hash (as identified by the `extra-filename` option). Cargo identifies a build context by a unique hash in order to distinguish cashed compilation units between builds (under different configurations). To that end, we need to determine the current hash to determine the full path of the generated llvm ir (e.g. `target/thumbv7m-none-eabi/release/examples/hello1-f3268774e62977a5.ll`, `f3268774e62977a5` being the hash). While `Cargo` can be accessed as a library, it does not (AFAIK) provide a stable API. A pragmatic solotion is to parse the actual invocation parameters to `rustc` to determine the current hash (as identified by the `extra-filename` option).
### Multiple targets
An attempt to analyse multiple targets, e.g.,
> cargo call-stack --examples --release
Will render:
``` text
error: extra arguments to `rustc` can only be passed to one target, consider filtering
the package by passing e.g. `--lib` or `--bin NAME` to specify a single target
```
This is fine Since we are interested in analysing a single application. This error is reported directly by `rustc` (not by the `call-stack` command).
...@@ -15,7 +15,7 @@ struct Out { ...@@ -15,7 +15,7 @@ struct Out {
// we skip the last line (Finished ...) // we skip the last line (Finished ...)
// and look for `--crate-name x`, `extra-filename=y` and `--out dir z` // and look for `--crate-name x`, `extra-filename=y` and `--out dir z`
// //
// Notice, the parsing is a bit of a hack, implemnting look ahead using flags. // Notice, the parsing is a bit of a hack, implemnting look-ahead using flags.
fn parse_out(out_str: &str) -> Out { fn parse_out(out_str: &str) -> Out {
let mut out = Out { let mut out = Out {
hash: None, hash: None,
...@@ -47,37 +47,6 @@ fn parse_out(out_str: &str) -> Out { ...@@ -47,37 +47,6 @@ fn parse_out(out_str: &str) -> Out {
out out
} }
fn parse_output(output: &str) -> (Option<&str>, Option<&str>, Option<&str>) {
let mut suffix = None;
let mut crate_name = None;
let mut example = None;
let output = str::from_utf8(output.as_bytes()).unwrap();
println!("here ...");
let mut i = output.lines().into_iter();
i.next_back(); // skip last line
if let Some(line) = i.next_back() {
let mut b = false;
for part in line.split(' ') {
if b {
crate_name = Some(part);
b = false;
} else if part.starts_with("--crate-name") {
b = true;
println!("----- here ---------- {:?}", crate_name);
} else if part.starts_with("extra-filename=") {
suffix = part.split('=').nth(1);
println!("----- there ----------");
} else if part.starts_with("example") {
example = part.split('/').nth(1);
println!("----- there ----------");
};
}
//}
}
(suffix, crate_name, example)
}
fn main() { fn main() {
println!("start sub command"); println!("start sub command");
// first argument is the path to this binary; the second argument is always "call-stack" -- both can // first argument is the path to this binary; the second argument is always "call-stack" -- both can
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment