fail build if we can't build source.zip

This commit is contained in:
iliana etaoin 2023-04-05 21:01:21 -07:00
parent 0a3de049b4
commit 0005b3bd56
2 changed files with 7 additions and 13 deletions

View File

@ -1,20 +1,13 @@
use anyhow::{ensure, Result}; use anyhow::{ensure, Result};
use std::fs::File; use std::fs::File;
use std::io::{self, Write}; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use zip::ZipWriter; use zip::ZipWriter;
fn main() { fn main() -> Result<()> {
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let mut rs_file = File::create(out_dir.join("zip.rs")).unwrap();
match attempt(&out_dir) {
Ok(()) => writeln!(rs_file, r#"Some(include_bytes!("source.zip"))"#).unwrap(),
Err(_) => writeln!(rs_file, "None").unwrap(),
}
}
fn attempt(out_dir: &Path) -> Result<()> {
let output = Command::new("cargo") let output = Command::new("cargo")
.args(["package", "--list", "--allow-dirty"]) .args(["package", "--list", "--allow-dirty"])
.output()?; .output()?;

View File

@ -144,16 +144,17 @@ struct Code {
} }
#[get("/code")] #[get("/code")]
fn code() -> Option<Code> { fn code() -> Code {
let zip = include!(concat!(env!("OUT_DIR"), "/zip.rs"))?; let zip = include_bytes!(concat!(env!("OUT_DIR"), "/source.zip"));
Some(Code {
Code {
zip, zip,
content_type: ContentType::ZIP, content_type: ContentType::ZIP,
disposition: Header::new( disposition: Header::new(
"content-disposition", "content-disposition",
r#"attachment; filename="emojos.in.zip""#, r#"attachment; filename="emojos.in.zip""#,
), ),
}) }
} }
#[get("/static/site.css")] #[get("/static/site.css")]