mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-19 01:37:34 +03:00
impl leo publish to zip file
This commit is contained in:
parent
47ef6be719
commit
6662b6261f
105
Cargo.lock
generated
105
Cargo.lock
generated
@ -149,6 +149,33 @@ version = "1.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b"
|
||||
dependencies = [
|
||||
"bzip2-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2-sys"
|
||||
version = "0.1.9+1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad3b39a260062fca31f7b0b12f207e8f2590a67d32ec7d59c20484b07ea7285e"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1be3409f94d7bdceeb5f5fac551039d9b3f00e25da7a74fc4d33400a0d96368"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
@ -190,6 +217,15 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.7.3"
|
||||
@ -334,6 +370,18 @@ version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cfff41391129e0a856d6d822600b8d71179d46879e310417eb9c762eb178b42"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crc32fast",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "from-pest"
|
||||
version = "0.3.1"
|
||||
@ -492,6 +540,8 @@ dependencies = [
|
||||
"snarkos-utilities",
|
||||
"thiserror",
|
||||
"toml",
|
||||
"walkdir",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -692,6 +742,18 @@ dependencies = [
|
||||
"sha-1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
|
||||
|
||||
[[package]]
|
||||
name = "podio"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b18befed8bc2b61abc79a457295e7e838417326da1586050b919414073977f19"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.8"
|
||||
@ -857,6 +919,15 @@ version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
@ -1131,6 +1202,16 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.6"
|
||||
@ -1188,6 +1269,17 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
@ -1224,3 +1316,16 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58287c28d78507f5f91f2a4cf1e8310e2c76fd4c6932f93ac60fd1ceb402db7d"
|
||||
dependencies = [
|
||||
"bzip2",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"podio",
|
||||
"time",
|
||||
]
|
||||
|
@ -37,6 +37,8 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0" }
|
||||
toml = { version = "0.5" }
|
||||
thiserror = { version = "1.0" }
|
||||
walkdir = { version = "2" }
|
||||
zip = { version = "0.5" }
|
||||
|
||||
[dev-dependencies]
|
||||
rusty-hook = { version = "0.11.1" }
|
||||
|
@ -1,7 +1,30 @@
|
||||
use crate::{cli::*, cli_types::*, commands::BuildCommand, errors::CLIError, files::Manifest};
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::BuildCommand,
|
||||
directories::{INPUTS_DIRECTORY_NAME, OUTPUTS_DIRECTORY_NAME},
|
||||
errors::CLIError,
|
||||
files::{
|
||||
Manifest,
|
||||
BYTES_FILE_EXTENSION,
|
||||
CHECKSUM_FILE_EXTENSION,
|
||||
INPUTS_FILE_EXTENSION,
|
||||
PROOF_FILE_EXTENSION,
|
||||
PROVING_KEY_FILE_EXTENSION,
|
||||
VERIFICATION_KEY_FILE_EXTENSION,
|
||||
},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
use std::{convert::TryFrom, env::current_dir};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
env::current_dir,
|
||||
fs::File,
|
||||
io::{Read, Write},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use walkdir::WalkDir;
|
||||
use zip::write::{FileOptions, ZipWriter};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PublishCommand;
|
||||
@ -27,11 +50,81 @@ impl CLI for PublishCommand {
|
||||
let (_program, _checksum_differs) = BuildCommand::output(options)?;
|
||||
|
||||
// Get the package name
|
||||
let path = current_dir()?;
|
||||
let _package_name = Manifest::try_from(&path)?.get_package_name();
|
||||
let src_dir = current_dir()?;
|
||||
|
||||
log::info!("Unimplemented - `leo publish`");
|
||||
// Build walkdir iterator from current package
|
||||
let walkdir = WalkDir::new(src_dir.clone());
|
||||
|
||||
// Create zip file
|
||||
let package_name = Manifest::try_from(&src_dir)?.get_package_name();
|
||||
let mut zip_file = src_dir.clone();
|
||||
zip_file.push(PathBuf::from(format!("{}{}", package_name, ".zip".to_string())));
|
||||
|
||||
let file = &mut File::create(zip_file)?;
|
||||
let mut zip = ZipWriter::new(file);
|
||||
let zip_options = FileOptions::default()
|
||||
.compression_method(zip::CompressionMethod::Stored)
|
||||
.unix_permissions(0o755);
|
||||
|
||||
// Walk through files in directory and write desired ones to the zip file
|
||||
let mut buffer = Vec::new();
|
||||
for entry in walkdir.into_iter().filter_map(|e| e.ok()) {
|
||||
let path = entry.path();
|
||||
let name = path.strip_prefix(src_dir.as_path()).unwrap();
|
||||
|
||||
// filter excluded paths
|
||||
if is_excluded(name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// write file or directory
|
||||
if path.is_file() {
|
||||
log::info!("adding file {:?} as {:?}", path, name);
|
||||
zip.start_file_from_path(name, zip_options)?;
|
||||
let mut f = File::open(path)?;
|
||||
|
||||
f.read_to_end(&mut buffer)?;
|
||||
zip.write_all(&*buffer)?;
|
||||
buffer.clear();
|
||||
} else if name.as_os_str().len() != 0 {
|
||||
// Only if not root Avoids path spec / warning
|
||||
// and mapname conversion failed error on unzip
|
||||
log::info!("adding dir {:?} as {:?}", path, name);
|
||||
zip.add_directory_from_path(name, zip_options)?;
|
||||
}
|
||||
}
|
||||
|
||||
zip.finish()?;
|
||||
|
||||
log::info!("zip file created");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn is_excluded(path: &Path) -> bool {
|
||||
// excluded directories: `/inputs`, `/outputs`
|
||||
if path.ends_with(INPUTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path.ends_with(OUTPUTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// excluded extensions: `.in`, `.bytes`, `lpk`, `lvk`, `.proof`, `.sum`
|
||||
path.extension()
|
||||
.map(|ext| {
|
||||
if ext.eq(INPUTS_FILE_EXTENSION.trim_start_matches("."))
|
||||
| ext.eq(BYTES_FILE_EXTENSION.trim_start_matches("."))
|
||||
| ext.eq(PROVING_KEY_FILE_EXTENSION.trim_start_matches("."))
|
||||
| ext.eq(VERIFICATION_KEY_FILE_EXTENSION.trim_start_matches("."))
|
||||
| ext.eq(PROOF_FILE_EXTENSION.trim_start_matches("."))
|
||||
| ext.eq(CHECKSUM_FILE_EXTENSION.trim_start_matches("."))
|
||||
| ext.eq("zip")
|
||||
{
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
use crate::errors::*;
|
||||
|
||||
use walkdir::Error as WalkDirError;
|
||||
use zip::result::ZipError;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CLIError {
|
||||
#[error("{}", _0)]
|
||||
@ -55,6 +58,12 @@ pub enum CLIError {
|
||||
|
||||
#[error("{}", _0)]
|
||||
VerificationKeyFileError(VerificationKeyFileError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
WalkDirError(WalkDirError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
ZipError(ZipError),
|
||||
}
|
||||
|
||||
impl From<BytesFileError> for CLIError {
|
||||
@ -176,6 +185,20 @@ impl From<VerificationKeyFileError> for CLIError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WalkDirError> for CLIError {
|
||||
fn from(error: WalkDirError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
CLIError::WalkDirError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ZipError> for CLIError {
|
||||
fn from(error: ZipError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
CLIError::ZipError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<leo_compiler::errors::CompilerError> for CLIError {
|
||||
fn from(error: leo_compiler::errors::CompilerError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
|
Loading…
Reference in New Issue
Block a user