Skip to content

Commit cfba0d4

Browse files
committed
Auto merge of #46514 - zackmdavis:sticking_it_to_the_man, r=alexcrichton
template month/year, version into man pages while building dist tarball ![the_man](https://user-images.githubusercontent.com/1076988/33596149-963956f4-d94f-11e7-926f-e683217765e5.png) This is meant to resolve #25689. r? @alexcrichton
2 parents abe85ab + 207fc0b commit cfba0d4

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/bootstrap/dist.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use build_helper::output;
2828

2929
use {Build, Compiler, Mode};
3030
use channel;
31-
use util::{cp_r, libdir, is_dylib, cp_filtered, copy};
31+
use util::{cp_r, libdir, is_dylib, cp_filtered, copy, replace_in_file};
3232
use builder::{Builder, RunConfig, ShouldRun, Step};
3333
use compile;
3434
use tool::{self, Tool};
@@ -434,7 +434,22 @@ impl Step for Rustc {
434434

435435
// Man pages
436436
t!(fs::create_dir_all(image.join("share/man/man1")));
437-
cp_r(&build.src.join("src/doc/man"), &image.join("share/man/man1"));
437+
let man_src = build.src.join("src/doc/man");
438+
let man_dst = image.join("share/man/man1");
439+
let date_output = output(Command::new("date").arg("+%B %Y"));
440+
let month_year = date_output.trim();
441+
// don't use our `bootstrap::util::{copy, cp_r}`, because those try
442+
// to hardlink, and we don't want to edit the source templates
443+
for entry_result in t!(fs::read_dir(man_src)) {
444+
let file_entry = t!(entry_result);
445+
let page_src = file_entry.path();
446+
let page_dst = man_dst.join(file_entry.file_name());
447+
t!(fs::copy(&page_src, &page_dst));
448+
// template in month/year and version number
449+
replace_in_file(&page_dst,
450+
&[("<INSERT DATE HERE>", month_year),
451+
("<INSERT VERSION HERE>", channel::CFG_RELEASE_NUM)]);
452+
}
438453

439454
// Debugger scripts
440455
builder.ensure(DebuggerScripts {

src/bootstrap/util.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
1616
use std::env;
1717
use std::str;
18-
use std::fs::{self, File};
19-
use std::io::{self, Read, Write};
18+
use std::fs::{self, File, OpenOptions};
19+
use std::io::{self, Read, Write, Seek, SeekFrom};
2020
use std::path::{Path, PathBuf};
2121
use std::process::Command;
2222
use std::time::{SystemTime, Instant};
@@ -51,6 +51,20 @@ pub fn copy(src: &Path, dst: &Path) {
5151
t!(filetime::set_file_times(dst, atime, mtime));
5252
}
5353

54+
/// Search-and-replaces within a file. (Not maximally efficiently: allocates a
55+
/// new string for each replacement.)
56+
pub fn replace_in_file(path: &Path, replacements: &[(&str, &str)]) {
57+
let mut contents = String::new();
58+
let mut file = t!(OpenOptions::new().read(true).write(true).open(path));
59+
t!(file.read_to_string(&mut contents));
60+
for &(target, replacement) in replacements {
61+
contents = contents.replace(target, replacement);
62+
}
63+
t!(file.seek(SeekFrom::Start(0)));
64+
t!(file.set_len(0));
65+
t!(file.write_all(contents.as_bytes()));
66+
}
67+
5468
pub fn read_stamp_file(stamp: &Path) -> Vec<PathBuf> {
5569
let mut paths = Vec::new();
5670
let mut contents = Vec::new();

src/doc/man/rustc.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH RUSTC "1" "September 2016" "rustc 1.13.0" "User Commands"
1+
.TH RUSTC "1" "<INSERT DATE HERE>" "rustc <INSERT VERSION HERE>" "User Commands"
22
.SH NAME
33
rustc \- The Rust compiler
44
.SH SYNOPSIS

src/doc/man/rustdoc.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH RUSTDOC "1" "May 2017" "rustdoc 1.19.0" "User Commands"
1+
.TH RUSTDOC "1" "<INSERT DATE HERE>" "rustdoc <INSERT VERSION HERE>" "User Commands"
22
.SH NAME
33
rustdoc \- generate documentation from Rust source code
44
.SH SYNOPSIS

0 commit comments

Comments
 (0)