Merge pull request #2792 from ehuss/remove-relative-renderer-command
Remove legacy relative renderer command paths
This commit is contained in:
commit
01da420f76
2 changed files with 7 additions and 51 deletions
|
|
@ -50,7 +50,7 @@ impl CmdRenderer {
|
||||||
CmdRenderer { name, cmd }
|
CmdRenderer { name, cmd }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compose_command(&self, root: &Path, destination: &Path) -> Result<Command> {
|
fn compose_command(&self, root: &Path) -> Result<Command> {
|
||||||
let mut words = Shlex::new(&self.cmd);
|
let mut words = Shlex::new(&self.cmd);
|
||||||
let exe = match words.next() {
|
let exe = match words.next() {
|
||||||
Some(e) => PathBuf::from(e),
|
Some(e) => PathBuf::from(e),
|
||||||
|
|
@ -61,30 +61,8 @@ impl CmdRenderer {
|
||||||
// Search PATH for the executable.
|
// Search PATH for the executable.
|
||||||
exe
|
exe
|
||||||
} else {
|
} else {
|
||||||
// Relative paths are preferred to be relative to the book root.
|
// Relative path is relative to book root.
|
||||||
let abs_exe = root.join(&exe);
|
root.join(&exe)
|
||||||
if abs_exe.exists() {
|
|
||||||
abs_exe
|
|
||||||
} else {
|
|
||||||
// Historically paths were relative to the destination, but
|
|
||||||
// this is not the preferred way.
|
|
||||||
let legacy_path = destination.join(&exe);
|
|
||||||
if legacy_path.exists() {
|
|
||||||
warn!(
|
|
||||||
"Renderer command `{}` uses a path relative to the \
|
|
||||||
renderer output directory `{}`. This was previously \
|
|
||||||
accepted, but has been deprecated. Relative executable \
|
|
||||||
paths should be relative to the book root.",
|
|
||||||
exe.display(),
|
|
||||||
destination.display()
|
|
||||||
);
|
|
||||||
legacy_path
|
|
||||||
} else {
|
|
||||||
// Let this bubble through to later be handled by
|
|
||||||
// handle_render_command_error.
|
|
||||||
abs_exe
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut cmd = Command::new(exe);
|
let mut cmd = Command::new(exe);
|
||||||
|
|
@ -143,7 +121,7 @@ impl Renderer for CmdRenderer {
|
||||||
let _ = fs::create_dir_all(&ctx.destination);
|
let _ = fs::create_dir_all(&ctx.destination);
|
||||||
|
|
||||||
let mut child = match self
|
let mut child = match self
|
||||||
.compose_command(&ctx.root, &ctx.destination)?
|
.compose_command(&ctx.root)?
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::inherit())
|
.stdout(Stdio::inherit())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
|
|
|
||||||
|
|
@ -211,11 +211,10 @@ fn backends_receive_render_context_via_stdin() {
|
||||||
RenderContext::from_json(f).unwrap();
|
RenderContext::from_json(f).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy relative renderer paths.
|
// Verifies that a relative path for the renderer command is relative to the
|
||||||
//
|
// book root.
|
||||||
// https://github.com/rust-lang/mdBook/pull/1418
|
|
||||||
#[test]
|
#[test]
|
||||||
fn legacy_relative_command_path() {
|
fn relative_command_path() {
|
||||||
let mut test = BookTest::init(|_| {});
|
let mut test = BookTest::init(|_| {});
|
||||||
test.rust_program(
|
test.rust_program(
|
||||||
"renderers/myrenderer",
|
"renderers/myrenderer",
|
||||||
|
|
@ -228,7 +227,6 @@ fn legacy_relative_command_path() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
// Test with a modern path, relative to the book directory.
|
|
||||||
.change_file(
|
.change_file(
|
||||||
"book.toml",
|
"book.toml",
|
||||||
"[output.myrenderer]\n\
|
"[output.myrenderer]\n\
|
||||||
|
|
@ -240,26 +238,6 @@ fn legacy_relative_command_path() {
|
||||||
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the myrenderer backend
|
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the myrenderer backend
|
||||||
[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "myrenderer" renderer
|
[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "myrenderer" renderer
|
||||||
|
|
||||||
"#]]);
|
|
||||||
})
|
|
||||||
.check_file("book/output", "test");
|
|
||||||
std::fs::remove_file(test.dir.join("book/output")).unwrap();
|
|
||||||
// Test with legacy path, relative to the output directory.
|
|
||||||
test.change_file(
|
|
||||||
"book.toml",
|
|
||||||
&format!(
|
|
||||||
"[output.myrenderer]\n\
|
|
||||||
command = '../renderers/myrenderer{exe}'\n",
|
|
||||||
exe = std::env::consts::EXE_SUFFIX
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.run("build", |cmd| {
|
|
||||||
cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
|
|
||||||
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
|
|
||||||
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the myrenderer backend
|
|
||||||
[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "myrenderer" renderer
|
|
||||||
[TIMESTAMP] [WARN] (mdbook_driver::builtin_renderers): Renderer command `../renderers/myrenderer[EXE]` uses a path relative to the renderer output directory `[ROOT]/book`. This was previously accepted, but has been deprecated. Relative executable paths should be relative to the book root.
|
|
||||||
|
|
||||||
"#]]);
|
"#]]);
|
||||||
})
|
})
|
||||||
.check_file("book/output", "test");
|
.check_file("book/output", "test");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue