From 207fc0bb459d9420cdb9e3050592c6eaada94709 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Mon, 4 Dec 2017 21:36:57 -0800 Subject: [PATCH] template month/year, version into man pages while building dist tarball This is meant to resolve #25689. --- src/bootstrap/dist.rs | 19 +++++++++++++++++-- src/bootstrap/util.rs | 18 ++++++++++++++++-- src/doc/man/rustc.1 | 2 +- src/doc/man/rustdoc.1 | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index bfe2a64f5ba48..f04ce47c83fb5 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -28,7 +28,7 @@ use build_helper::output; use {Build, Compiler, Mode}; use channel; -use util::{cp_r, libdir, is_dylib, cp_filtered, copy}; +use util::{cp_r, libdir, is_dylib, cp_filtered, copy, replace_in_file}; use builder::{Builder, RunConfig, ShouldRun, Step}; use compile; use tool::{self, Tool}; @@ -434,7 +434,22 @@ impl Step for Rustc { // Man pages t!(fs::create_dir_all(image.join("share/man/man1"))); - cp_r(&build.src.join("src/doc/man"), &image.join("share/man/man1")); + let man_src = build.src.join("src/doc/man"); + let man_dst = image.join("share/man/man1"); + let date_output = output(Command::new("date").arg("+%B %Y")); + let month_year = date_output.trim(); + // don't use our `bootstrap::util::{copy, cp_r}`, because those try + // to hardlink, and we don't want to edit the source templates + for entry_result in t!(fs::read_dir(man_src)) { + let file_entry = t!(entry_result); + let page_src = file_entry.path(); + let page_dst = man_dst.join(file_entry.file_name()); + t!(fs::copy(&page_src, &page_dst)); + // template in month/year and version number + replace_in_file(&page_dst, + &[("", month_year), + ("", channel::CFG_RELEASE_NUM)]); + } // Debugger scripts builder.ensure(DebuggerScripts { diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs index 2506048858f2b..874065f21d080 100644 --- a/src/bootstrap/util.rs +++ b/src/bootstrap/util.rs @@ -15,8 +15,8 @@ use std::env; use std::str; -use std::fs::{self, File}; -use std::io::{self, Read, Write}; +use std::fs::{self, File, OpenOptions}; +use std::io::{self, Read, Write, Seek, SeekFrom}; use std::path::{Path, PathBuf}; use std::process::Command; use std::time::{SystemTime, Instant}; @@ -51,6 +51,20 @@ pub fn copy(src: &Path, dst: &Path) { t!(filetime::set_file_times(dst, atime, mtime)); } +/// Search-and-replaces within a file. (Not maximally efficiently: allocates a +/// new string for each replacement.) +pub fn replace_in_file(path: &Path, replacements: &[(&str, &str)]) { + let mut contents = String::new(); + let mut file = t!(OpenOptions::new().read(true).write(true).open(path)); + t!(file.read_to_string(&mut contents)); + for &(target, replacement) in replacements { + contents = contents.replace(target, replacement); + } + t!(file.seek(SeekFrom::Start(0))); + t!(file.set_len(0)); + t!(file.write_all(contents.as_bytes())); +} + pub fn read_stamp_file(stamp: &Path) -> Vec { let mut paths = Vec::new(); let mut contents = Vec::new(); diff --git a/src/doc/man/rustc.1 b/src/doc/man/rustc.1 index 0bb41cee2c518..19f6cc9ac619d 100644 --- a/src/doc/man/rustc.1 +++ b/src/doc/man/rustc.1 @@ -1,4 +1,4 @@ -.TH RUSTC "1" "September 2016" "rustc 1.13.0" "User Commands" +.TH RUSTC "1" "" "rustc " "User Commands" .SH NAME rustc \- The Rust compiler .SH SYNOPSIS diff --git a/src/doc/man/rustdoc.1 b/src/doc/man/rustdoc.1 index d34ab6135499d..a878380f556b3 100644 --- a/src/doc/man/rustdoc.1 +++ b/src/doc/man/rustdoc.1 @@ -1,4 +1,4 @@ -.TH RUSTDOC "1" "May 2017" "rustdoc 1.19.0" "User Commands" +.TH RUSTDOC "1" "" "rustdoc " "User Commands" .SH NAME rustdoc \- generate documentation from Rust source code .SH SYNOPSIS