build: fix cargo publish by symlinking cli/docs->docs

I think `cargo publish` will currently fail because of the
`include_str!()` in `cli/src/commands/help.rs` pointing to
`../../../docs/`, i.e. outside of the crate directory. This patch
attempts to fix that creating a `cli/docs` symlink to `docs` and makes
the `include_str!` use that symlink. I hope the symlink will be
resolved at `cargo publish` time so it also works in the published
crate.

Because symlinks don't work well on Windows, I updated `cli/build.rs`
to include the original path (the one pointing outside the crate) if
`cli/docs` is not a symlink, so the regular build still should work on
Windows (but `cargo publish` won't).

Thanks to Yuya for proposing this solution.
This commit is contained in:
Martin von Zweigbergk 2024-11-04 21:52:04 -08:00 committed by Martin von Zweigbergk
parent 10424481f7
commit e4bf147164
5 changed files with 12 additions and 2 deletions

View file

@ -18,6 +18,7 @@ include = [
"/build.rs",
"/examples/",
"/src/",
"/docs/**",
"/testing/",
"/tests/",
"!*.pending-snap",

View file

@ -37,6 +37,14 @@ fn main() {
} else {
println!("cargo:rustc-env=JJ_VERSION={version}");
}
let docs_symlink_path = Path::new("docs");
println!("cargo:rerun-if-changed={}", docs_symlink_path.display());
if docs_symlink_path.join("index.md").exists() {
println!("cargo:rustc-env=JJ_DOCS_DIR=docs/");
} else {
println!("cargo:rustc-env=JJ_DOCS_DIR=../docs/");
}
}
fn get_git_hash() -> Option<String> {

1
cli/docs Symbolic link
View file

@ -0,0 +1 @@
../docs

View file

@ -98,12 +98,12 @@ const KEYWORDS: &[Keyword] = &[
Keyword {
name: "revsets",
description: "A functional language for selecting a set of revision",
content: include_str!("../../../docs/revsets.md"),
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "revsets.md")),
},
Keyword {
name: "tutorial",
description: "Show a tutorial to get started with jj",
content: include_str!("../../../docs/tutorial.md"),
content: include_str!(concat!("../../", env!("JJ_DOCS_DIR"), "tutorial.md")),
},
];

0
foo bar Normal file
View file