| 497 | } |
| 498 | |
| 499 | fn update_spec(sh: &Shell) -> Result<Utf8PathBuf> { |
| 500 | let p = Utf8Path::new("target"); |
| 501 | let pkg = impl_package(sh)?; |
| 502 | let srcpath = pkg.srcpath.file_name().unwrap(); |
| 503 | let v = pkg.version; |
| 504 | let src_vendorpath = pkg.vendorpath.file_name().unwrap(); |
| 505 | { |
| 506 | let specin = File::open(format!("contrib/packaging/{NAME}.spec")) |
| 507 | .map(BufReader::new) |
| 508 | .context("Opening spec")?; |
| 509 | let mut o = File::create(p.join(format!("{NAME}.spec"))).map(BufWriter::new)?; |
| 510 | for line in specin.lines() { |
| 511 | let line = line?; |
| 512 | if line.starts_with("Version:") { |
| 513 | writeln!(o, "# Replaced by cargo xtask spec")?; |
| 514 | writeln!(o, "Version: {v}")?; |
| 515 | } else if line.starts_with("Source0") { |
| 516 | writeln!(o, "Source0: {srcpath}")?; |
| 517 | } else if line.starts_with("Source1") { |
| 518 | writeln!(o, "Source1: {src_vendorpath}")?; |
| 519 | } else { |
| 520 | writeln!(o, "{line}")?; |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | let spec_path = p.join(format!("{NAME}.spec")); |
| 525 | Ok(spec_path) |
| 526 | } |
| 527 | |
| 528 | fn spec(sh: &Shell) -> Result<()> { |
| 529 | let s = update_spec(sh)?; |