Skip to content

Commit f43b85d

Browse files
committed
build: restore cargo build output somewhat
Somewhere along the line in either cargo itself or cargo_metadata real-time build progress is no longer printed. Not a cause of concern, but if there is no build cache, it will look like an invocation is stuck. But errors are now printed as expected, which is the important part. Perhaps some rudimentary spinner should be added in the future?
1 parent 2843c22 commit f43b85d

File tree

5 files changed

+22
-45
lines changed

5 files changed

+22
-45
lines changed

Cargo.lock

Lines changed: 2 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ description = "RTIC Scope backend"
1313
[dependencies]
1414
structopt = "0.3"
1515
clap = "2.33"
16-
cargo_metadata = "0.11"
16+
cargo_metadata = "0.14"
1717
syn = "1"
1818
proc-macro2 = "1"
1919
quote = "1"

src/build.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl CargoWrapper {
9292
Ok((
9393
CargoWrapper {
9494
target_dir: Some(metadata.target_directory.clone().canonicalize().map_err(
95-
|e| CargoError::CannotCanonicalize(metadata.target_directory.clone(), e),
95+
|e| CargoError::CannotCanonicalize(metadata.target_directory.clone().into(), e),
9696
)?),
9797
app_metadata: Some(metadata),
9898
},
@@ -136,7 +136,7 @@ impl CargoWrapper {
136136
cargo.arg(self.target_dir());
137137
}
138138

139-
cargo.args(&["--message-format", "json-diagnostic-rendered-ansi"]);
139+
cargo.arg("--message-format=json-diagnostic-rendered-ansi");
140140
cargo.stdout(Stdio::piped());
141141
cargo.stderr(Stdio::piped());
142142

@@ -166,15 +166,7 @@ impl CargoWrapper {
166166
let stdout = BufReader::new(child.stdout.take().expect("Pipe to cargo process failed"));
167167
let stderr = BufReader::new(child.stderr.take().expect("Pipe to cargo process failed"));
168168

169-
// NOTE(collect) ensure we don't block stdout which could
170-
// prevent the process from exiting
171-
let messages = Message::parse_stream(stdout)
172-
.chain(Message::parse_stream(stderr))
173-
.collect::<Vec<_>>();
174-
175-
let status = child
176-
.wait()
177-
.map_err(|e| CargoError::CargoBuildSpawnWaitError(e))?;
169+
let messages = Message::parse_stream(stdout).chain(Message::parse_stream(stderr));
178170

179171
let mut target_artifact: Option<Artifact> = None;
180172
for message in messages {
@@ -199,6 +191,10 @@ impl CargoWrapper {
199191
}
200192
}
201193

194+
let status = child
195+
.wait()
196+
.map_err(|e| CargoError::CargoBuildSpawnWaitError(e))?;
197+
202198
if !status.success() {
203199
return Err(CargoError::CargoBuildExecFailed(status, opts));
204200
}
@@ -227,15 +223,15 @@ fn find_manifest_path(artifact: &cargo_metadata::Artifact) -> Result<PathBuf, Ca
227223
path.push("Cargo.toml");
228224
path.exists()
229225
} {
230-
return Ok(path);
226+
return Ok(path.into());
231227
} else {
232228
path.pop(); // remove Cargo.toml
233229
if path.pop() {
234230
// move up a directory
235231
continue;
236232
}
237233

238-
return Err(CargoError::CannotFindManifest(start_path()));
234+
return Err(CargoError::CannotFindManifest(start_path().into()));
239235
}
240236
}
241237
}

src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ fn main_try() -> Result<(), RTICScopeError> {
241241

242242
// Build RTIC application to be traced, and create a wrapper around
243243
// cargo, reusing the target directory of the application.
244+
log::status("Building", "RTIC target application...".to_string());
244245
let (cargo, artifact) = CargoWrapper::new(
245246
&env::current_dir()?,
246247
{
@@ -252,11 +253,7 @@ fn main_try() -> Result<(), RTICScopeError> {
252253
.to_cargo_options(),
253254
)?;
254255

255-
let prog = format!(
256-
"{} ({})",
257-
artifact.target.name,
258-
artifact.target.src_path.display()
259-
);
256+
let prog = format!("{} ({})", artifact.target.name, artifact.target.src_path,);
260257
log::status(
261258
"Recovering",
262259
format!("metadata for {} and preparing target...", prog,),
@@ -579,8 +576,13 @@ fn trace(
579576
let flashloader = opts
580577
.flash_options
581578
.probe_options
582-
.build_flashloader(&mut session, &elf)?;
583-
flash::run_flash_download(&mut session, &elf, &opts.flash_options, flashloader)?;
579+
.build_flashloader(&mut session, &elf.clone().into_std_path_buf())?;
580+
flash::run_flash_download(
581+
&mut session,
582+
&elf.clone().into_std_path_buf(),
583+
&opts.flash_options,
584+
flashloader,
585+
)?;
584586

585587
let mut trace_source: Box<dyn sources::Source> = if let Some(dev) = &opts.serial {
586588
Box::new(sources::TTYSource::new(

src/sinks/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl FileSink {
3939

4040
// generate a short descroption on the format
4141
// "blinky-gbaadf00-dirty-2021-06-16T17:13:16.trace"
42-
let repo = find_git_repo(artifact.target.src_path.clone())?;
42+
let repo = find_git_repo(artifact.target.src_path.clone().into())?;
4343
let git_shortdesc = repo
4444
.describe(&DescribeOptions::new().show_commit_oid_as_fallback(true))?
4545
.format(Some(

0 commit comments

Comments
 (0)