Write assets like manual pages to a predictable location.

- Fixes #45.
This commit is contained in:
Justus Winter 2024-01-05 15:57:05 +01:00
parent 2580e26ba5
commit 0ea5ef9fad
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 16 additions and 3 deletions

View File

@ -29,4 +29,7 @@ cargo build
```
The above creates the `sq` executable, the manual pages, and its shell
completions.
completions. By default, the manual pages and shell completions are
put into the `cargo` target directory, but the exact location is
unpredictable. To write the assets to a predictable location, set the
environment variable `ASSET_OUT_DIR` to a suitable location.

View File

@ -30,11 +30,21 @@ fn main() {
generate_man_pages(&sq).unwrap();
}
/// Variable name to control the asset out directory with.
const ASSET_OUT_DIR: &str = "ASSET_OUT_DIR";
/// Returns the directory to write the given assets to.
fn asset_out_dir(asset: &str) -> Result<PathBuf> {
println!("cargo:rerun-if-env-changed={}", ASSET_OUT_DIR);
let outdir: PathBuf =
env::var_os("OUT_DIR").expect("OUT_DIR not set").into();
assert!(outdir.is_dir());
env::var_os(ASSET_OUT_DIR).unwrap_or_else(
|| env::var_os("OUT_DIR").expect("OUT_DIR not set")).into();
if outdir.exists() && ! outdir.is_dir() {
return Err(
anyhow::anyhow!("{}={:?} is not a directory",
ASSET_OUT_DIR, outdir));
}
let path = outdir.join(asset);
fs::create_dir_all(&path)?;
Ok(path)