Skip to content

Commit

Permalink
Filter newlines from cargo instruction output (#289)
Browse files Browse the repository at this point in the history
* Filter newlines from cargo instruction output

* tweaks for coverage
  • Loading branch information
CraZySacX authored Jan 14, 2024
1 parent 51642f6 commit 8bad39c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions vergen/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,22 @@ impl Emitter {
{
// Emit the 'cargo:rustc-env' instructions
for (k, v) in &self.cargo_rustc_env_map {
writeln!(stdout, "cargo:rustc-env={}={v}", k.name())?;
let output = Self::filter_newlines(v);
writeln!(stdout, "cargo:rustc-env={}={output}", k.name())?;
}

// Emit the `cargo:warning` instructions
if !quiet {
for warning in &self.warnings {
writeln!(stdout, "cargo:warning={warning}")?;
let output = Self::filter_newlines(warning);
writeln!(stdout, "cargo:warning={output}")?;
}
}

// Emit the 'cargo:rerun-if-changed' instructions for the git paths (if added)
for path in &self.rerun_if_changed {
writeln!(stdout, "cargo:rerun-if-changed={path}")?;
let output = Self::filter_newlines(path);
writeln!(stdout, "cargo:rerun-if-changed={output}")?;
}

// Emit the 'cargo:rerun-if-changed' instructions
Expand All @@ -304,12 +307,24 @@ impl Emitter {
} else {
"build.rs"
};
writeln!(stdout, "cargo:rerun-if-changed={buildrs}")?;
let output = Self::filter_newlines(buildrs);
writeln!(stdout, "cargo:rerun-if-changed={output}")?;
writeln!(stdout, "cargo:rerun-if-env-changed=VERGEN_IDEMPOTENT")?;
writeln!(stdout, "cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH")?;
}
Ok(())
}

#[cfg(any(
feature = "build",
feature = "cargo",
feature = "git",
feature = "rustc",
feature = "si"
))]
fn filter_newlines(s: &str) -> String {
s.chars().filter(|c| *c != '\n').collect()
}
}

/// Build the `vergen` configuration to enable specific cargo instruction
Expand Down

0 comments on commit 8bad39c

Please sign in to comment.