mirror of
https://github.com/rust-lang/cargo
synced 2024-10-02 05:53:53 +00:00
Address review comments.
- Add newline at end of file. - Remove unnecessary rustfmt changes. - Move file writing code to `write_if_changed`.
This commit is contained in:
parent
2be857af59
commit
ae5e84518d
|
@ -560,17 +560,10 @@ fn prepare_metabuild<'a, 'cfg>(
|
|||
for dep in &meta_deps {
|
||||
output.push(format!(" {}::metabuild();\n", dep));
|
||||
}
|
||||
output.push("}".to_string());
|
||||
output.push("}\n".to_string());
|
||||
let output = output.join("");
|
||||
let path = cx.files().metabuild_path(unit);
|
||||
let changed = if let Ok(orig) = fs::read_to_string(&path) {
|
||||
orig != output
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if changed {
|
||||
fs::write(&path, output)?;
|
||||
}
|
||||
paths::write_if_changed(path, &output)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -622,8 +615,7 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>, units: &[Unit<'b>]) -> Ca
|
|||
}
|
||||
|
||||
{
|
||||
let key = unit
|
||||
.pkg
|
||||
let key = unit.pkg
|
||||
.manifest()
|
||||
.links()
|
||||
.map(|l| (l.to_string(), unit.kind));
|
||||
|
|
|
@ -142,6 +142,26 @@ pub fn write(path: &Path, contents: &[u8]) -> CargoResult<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_if_changed<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> CargoResult<()> {
|
||||
(|| -> CargoResult<()> {
|
||||
let contents = contents.as_ref();
|
||||
let mut f = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(&path)?;
|
||||
let mut orig = Vec::new();
|
||||
f.read_to_end(&mut orig)?;
|
||||
if orig != contents {
|
||||
f.set_len(0)?;
|
||||
f.write_all(contents)?;
|
||||
}
|
||||
Ok(())
|
||||
})()
|
||||
.chain_err(|| format!("failed to write `{}`", path.as_ref().display()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn append(path: &Path, contents: &[u8]) -> CargoResult<()> {
|
||||
(|| -> CargoResult<()> {
|
||||
let mut f = OpenOptions::new()
|
||||
|
|
|
@ -528,14 +528,7 @@ fn clean_targets_with_legacy_path(
|
|||
validate_unique_names(&toml_targets, target_kind)?;
|
||||
let mut result = Vec::new();
|
||||
for target in toml_targets {
|
||||
let path = target_path(
|
||||
&target,
|
||||
inferred,
|
||||
target_kind,
|
||||
package_root,
|
||||
edition,
|
||||
legacy_path,
|
||||
);
|
||||
let path = target_path(&target, inferred, target_kind, package_root, edition, legacy_path);
|
||||
let path = match path {
|
||||
Ok(path) => path,
|
||||
Err(e) => {
|
||||
|
|
Loading…
Reference in a new issue