2022-06-24 21:16:22 -07:00
|
|
|
use anyhow::{ensure, Result};
|
|
|
|
use std::fs::File;
|
2023-04-05 21:01:21 -07:00
|
|
|
use std::io;
|
2022-06-24 21:16:22 -07:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use std::process::Command;
|
|
|
|
use zip::ZipWriter;
|
|
|
|
|
2023-04-05 21:01:21 -07:00
|
|
|
fn main() -> Result<()> {
|
2022-06-24 21:16:22 -07:00
|
|
|
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
|
|
|
|
|
|
|
let output = Command::new("cargo")
|
|
|
|
.args(["package", "--list", "--allow-dirty"])
|
|
|
|
.output()?;
|
|
|
|
ensure!(output.status.success(), "unsuccessful");
|
|
|
|
|
|
|
|
let mut writer = ZipWriter::new(File::create(out_dir.join("source.zip"))?);
|
|
|
|
for path in String::from_utf8(output.stdout)?.lines() {
|
|
|
|
if path == "Cargo.toml.orig" {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.start_file(path, Default::default())?;
|
|
|
|
io::copy(
|
|
|
|
&mut File::open(Path::new(env!("CARGO_MANIFEST_DIR")).join(path))?,
|
|
|
|
&mut writer,
|
|
|
|
)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.finish()?;
|
|
|
|
Ok(())
|
|
|
|
}
|