From e4bf147164e24decb7d3eb46bf8852f665d50bfc Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 4 Nov 2024 21:52:04 -0800 Subject: [PATCH] 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. --- cli/Cargo.toml | 1 + cli/build.rs | 8 ++++++++ cli/docs | 1 + cli/src/commands/help.rs | 4 ++-- foo bar | 0 5 files changed, 12 insertions(+), 2 deletions(-) create mode 120000 cli/docs create mode 100644 foo bar diff --git a/cli/Cargo.toml b/cli/Cargo.toml index bf9b4de4c..96db2e855 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -18,6 +18,7 @@ include = [ "/build.rs", "/examples/", "/src/", + "/docs/**", "/testing/", "/tests/", "!*.pending-snap", diff --git a/cli/build.rs b/cli/build.rs index 993a0913e..034534545 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -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 { diff --git a/cli/docs b/cli/docs new file mode 120000 index 000000000..a9594bfe4 --- /dev/null +++ b/cli/docs @@ -0,0 +1 @@ +../docs \ No newline at end of file diff --git a/cli/src/commands/help.rs b/cli/src/commands/help.rs index 0def340ed..feaeccd73 100644 --- a/cli/src/commands/help.rs +++ b/cli/src/commands/help.rs @@ -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")), }, ]; diff --git a/foo bar b/foo bar new file mode 100644 index 000000000..e69de29bb