Write completions and manfile to cargo outdir (cargo publish restriction)

This commit is contained in:
sharkdp 2020-03-22 11:33:50 +01:00
parent 6386a4b812
commit 02f2b55d5f
2 changed files with 18 additions and 7 deletions

View file

@ -7,6 +7,7 @@ extern crate liquid;
use std::error::Error;
use std::fs;
use std::path::Path;
// Read environment variables.
lazy_static! {
@ -42,7 +43,7 @@ fn init_template() -> liquid::value::Object {
fn template(
variables: &liquid::value::Object,
in_file: &str,
out_file: &str,
out_file: impl AsRef<Path>,
) -> Result<(), Box<dyn Error>> {
let template = liquid::ParserBuilder::with_liquid()
.build()?
@ -55,11 +56,21 @@ fn template(
fn main() -> Result<(), Box<dyn Error>> {
let variables = init_template();
template(&variables, "assets/manual/bat.1.in", "assets/manual/bat.1")?;
let out_dir_env = std::env::var_os("OUT_DIR").expect("OUT_DIR to be set in build.rs");
let out_dir = Path::new(&out_dir_env);
std::fs::create_dir_all(out_dir.join("assets/manual")).unwrap();
std::fs::create_dir_all(out_dir.join("assets/completions")).unwrap();
template(
&variables,
"assets/manual/bat.1.in",
out_dir.join("assets/manual/bat.1"),
)?;
template(
&variables,
"assets/completions/bat.fish.in",
"assets/completions/bat.fish",
out_dir.join("assets/completions/bat.fish"),
)?;
Ok(())

View file

@ -38,7 +38,7 @@ pack() {
"${gcc_prefix}"strip "$tempdir/$package_name/$PROJECT_NAME"
# manpage, readme and license
cp "assets/manual/bat.1" "$tempdir/$package_name/$PROJECT_NAME.1"
cp "$out_dir/assets/manual/bat.1" "$tempdir/$package_name/$PROJECT_NAME.1"
cp README.md "$tempdir/$package_name"
cp LICENSE-MIT "$tempdir/$package_name"
cp LICENSE-APACHE "$tempdir/$package_name"
@ -47,7 +47,7 @@ pack() {
# TODO: disabled for now, see issue #372
# cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/"$PROJECT_NAME".bash "$tempdir/$package_name/autocomplete/${PROJECT_NAME}.bash-completion"
# cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/"$PROJECT_NAME".fish "$tempdir/$package_name/autocomplete"
cp "assets/completions/bat.fish" "$tempdir/$package_name/autocomplete/$PROJECT_NAME.fish"
cp "$out_dir/assets/completions/bat.fish" "$tempdir/$package_name/autocomplete/$PROJECT_NAME.fish"
# cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/_"$PROJECT_NAME" "$tempdir/$package_name/autocomplete"
# archiving
@ -108,11 +108,11 @@ make_deb() {
"${gcc_prefix}"strip "$tempdir/usr/bin/$PROJECT_NAME"
# manpage
install -Dm644 "assets/manual/bat.1" "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
install -Dm644 "$out_dir/assets/manual/bat.1" "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
gzip --best "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
# completions
install -Dm644 "assets/completions/bat.fish" "$tempdir/usr/share/fish/vendor_completions.d/$PROJECT_NAME.fish"
install -Dm644 "$out_dir/assets/completions/bat.fish" "$tempdir/usr/share/fish/vendor_completions.d/$PROJECT_NAME.fish"
# readme and license
install -Dm644 README.md "$tempdir/usr/share/doc/$PROJECT_NAME/README.md"