mangadex-home-rs/build.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

2021-07-10 00:37:15 +00:00
use std::path::PathBuf;
2021-07-09 21:32:00 +00:00
use std::process::Command;
2021-07-10 00:37:15 +00:00
use std::str::FromStr;
use std::{error::Error, io::Write};
2021-06-06 21:48:48 +00:00
2021-06-06 22:17:42 +00:00
use vergen::{vergen, Config, ShaKind};
2021-06-06 21:48:48 +00:00
fn main() -> Result<(), Box<dyn Error>> {
2021-07-09 21:32:00 +00:00
// Initialize vergen stuff
2021-06-06 22:17:42 +00:00
let mut config = Config::default();
*config.git_mut().sha_kind_mut() = ShaKind::Short;
vergen(config)?;
2021-07-09 21:32:00 +00:00
// Initialize SQL stuff
let project_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
Command::new("mkdir")
.args(["cache", "--parents"])
.current_dir(&project_root)
.output()?;
Command::new("sqlite3")
.args(["cache/metadata.sqlite", include_str!("db_queries/init.sql")])
.current_dir(&project_root)
.output()?;
2021-07-10 00:37:15 +00:00
let env_var_regex = "^DATABASE_URL=sqlite:./cache/metadata.sqlite$";
if !Command::new("grep")
.args([env_var_regex, ".env"])
.current_dir(&project_root)
.output()?
.status
.success()
{
let mut path = PathBuf::from_str(&project_root)?;
path.push(".env");
let mut file = std::fs::OpenOptions::new()
.append(true)
.create(true)
.open(path)?;
2021-07-10 00:37:15 +00:00
file.write_all(b"\nDATABASE_URL=sqlite:./cache/metadata.sqlite\n")?;
file.sync_all()?;
}
2021-06-06 21:48:48 +00:00
Ok(())
}