Merge pull request #137 from AleoHQ/feature/package

Adds leo-package module
This commit is contained in:
Collin Chin 2020-08-03 14:44:11 -07:00 committed by GitHub
commit 4565274893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
85 changed files with 350 additions and 290 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
**/target
/tmp/
**.idea/
outputs/
*.DS_Store

16
Cargo.lock generated
View File

@ -661,6 +661,7 @@ dependencies = [
"leo-compiler",
"leo-gadgets",
"leo-input",
"leo-package",
"log",
"rand",
"rand_core",
@ -675,8 +676,6 @@ dependencies = [
"snarkos-utilities",
"thiserror",
"toml",
"walkdir",
"zip",
]
[[package]]
@ -754,6 +753,19 @@ dependencies = [
name = "leo-linter"
version = "0.1.0"
[[package]]
name = "leo-package"
version = "0.1.0"
dependencies = [
"log",
"serde",
"serde_json",
"thiserror",
"toml",
"walkdir",
"zip",
]
[[package]]
name = "leo-typed"
version = "0.1.0"

View File

@ -13,12 +13,13 @@ name = "leo"
path = "leo/main.rs"
[workspace]
members = [ "ast", "compiler", "gadgets", "input", "linter", "typed" ]
members = [ "ast", "compiler", "gadgets", "input", "linter", "package", "typed" ]
[dependencies]
leo-compiler = { path = "compiler", version = "0.1.0" }
leo-gadgets = { path = "gadgets", version = "0.1.0" }
leo-input = { path = "input", version = "0.1.0" }
leo-package = { path = "package", version = "0.1.0" }
snarkos-algorithms = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-algorithms", default-features = false }
snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-curves", default-features = false }
@ -38,8 +39,6 @@ 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.2" }

View File

@ -8,7 +8,7 @@ use std::{
path::PathBuf,
};
pub static OUTPUT_DIRECTORY_NAME: &str = "output/";
pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/";
pub static OUTPUT_FILE_EXTENSION: &str = ".out";
pub struct OutputFile {
@ -48,8 +48,8 @@ impl OutputFile {
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!("{}{}", self.package_name, OUTPUT_FILE_EXTENSION)));
}

View File

@ -1,2 +1,2 @@
/output
outputs/
/.leo

View File

@ -0,0 +1,2 @@
[registers]
r0: u32 = 0;

2
examples/hello_world/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
outputs/
/.leo

View File

@ -0,0 +1,2 @@
[registers]
r0: u32 = 0;

View File

@ -1,2 +1,2 @@
/output
outputs/
/.leo

View File

@ -1 +1,4 @@
[main]
[registers]
r0: group = (1, 0)group;

View File

@ -1 +1,2 @@
outputs/
/.leo

View File

@ -1,4 +1,7 @@
// The program input for square_root/src/main.leo
[main]
a: field = 337;
b: field = 113569;
b: field = 113569;
[registers]
r0: bool = false;

View File

@ -1,11 +1,11 @@
use crate::{
cli::*,
cli_types::*,
directories::{source::SOURCE_DIRECTORY_NAME, OutputDirectory, OUTPUT_DIRECTORY_NAME},
errors::CLIError,
files::{ChecksumFile, InputFile, LibFile, MainFile, Manifest, StateFile, LIB_FILE_NAME, MAIN_FILE_NAME},
};
use crate::{cli::*, cli_types::*, errors::CLIError};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_package::{
inputs::*,
outputs::{ChecksumFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME},
root::Manifest,
source::{LibFile, MainFile, LIB_FILE_NAME, MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
};
use snarkos_algorithms::snark::groth16::KeypairAssembly;
use snarkos_curves::{bls12_377::Bls12_377, edwards_bls12::Fq};
@ -49,7 +49,7 @@ impl CLI for BuildCommand {
// Construct the path to the output directory
let mut output_directory = package_path.clone();
output_directory.push(OUTPUT_DIRECTORY_NAME);
output_directory.push(OUTPUTS_DIRECTORY_NAME);
// Compile the package starting with the lib.leo file
if LibFile::exists_at(&package_path) {
@ -71,7 +71,7 @@ impl CLI for BuildCommand {
// Compile the main.leo file along with constraints
if MainFile::exists_at(&package_path) {
// Create the output directory
OutputDirectory::create(&package_path)?;
OutputsDirectory::create(&package_path)?;
// Construct the path to the main file in the source directory
let mut main_file_path = package_path.clone();

View File

@ -1,8 +1,7 @@
use crate::{
cli::*,
cli_types::*,
errors::CLIError,
files::{ChecksumFile, Manifest, ProofFile, ProvingKeyFile, VerificationKeyFile},
use crate::{cli::*, cli_types::*, errors::CLIError};
use leo_package::{
outputs::{ChecksumFile, ProofFile, ProvingKeyFile, VerificationKeyFile},
root::Manifest,
};
use clap::ArgMatches;

View File

@ -2,9 +2,11 @@ use crate::{
cli::*,
cli_types::*,
commands::BuildCommand,
directories::SOURCE_DIRECTORY_NAME,
errors::{CLIError, RunError},
files::{Manifest, MAIN_FILE_NAME},
};
use leo_package::{
root::Manifest,
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
};
use clap::ArgMatches;

View File

@ -1,9 +1,12 @@
use crate::{
cli::*,
cli_types::*,
directories::{InputDirectory, SourceDirectory},
errors::{CLIError, InitError},
files::{Gitignore, InputFile, LibFile, MainFile, Manifest},
};
use leo_package::{
inputs::*,
root::{Gitignore, Manifest},
source::{LibFile, MainFile, SourceDirectory},
};
use clap::ArgMatches;
@ -68,7 +71,7 @@ impl CLI for InitCommand {
}
} else {
// Create the input directory
InputDirectory::create(&path)?;
InputsDirectory::create(&path)?;
// Verify the input file does not exist
let input_file = InputFile::new(&package_name);

View File

@ -2,9 +2,11 @@ use crate::{
cli::*,
cli_types::*,
commands::BuildCommand,
directories::SOURCE_DIRECTORY_NAME,
errors::{CLIError, RunError},
files::{Manifest, MAIN_FILE_NAME},
};
use leo_package::{
root::Manifest,
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
};
use clap::ArgMatches;

View File

@ -2,9 +2,11 @@ use crate::{
cli::*,
cli_types::*,
commands::BuildCommand,
directories::SOURCE_DIRECTORY_NAME,
errors::{CLIError, RunError},
files::{Manifest, MAIN_FILE_NAME},
};
use leo_package::{
root::Manifest,
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
};
use clap::ArgMatches;

View File

@ -1,9 +1,12 @@
use crate::{
cli::*,
cli_types::*,
directories::{InputDirectory, SourceDirectory},
errors::{CLIError, NewError},
files::{Gitignore, InputFile, LibFile, MainFile, Manifest},
};
use leo_package::{
inputs::*,
root::{Gitignore, Manifest},
source::{LibFile, MainFile, SourceDirectory},
};
use clap::ArgMatches;
@ -85,7 +88,7 @@ impl CLI for NewCommand {
LibFile::new(&package_name).write_to(&path)?;
} else {
// Create the input directory
InputDirectory::create(&path)?;
InputsDirectory::create(&path)?;
// Create the input file in the input directory
InputFile::new(&package_name).write_to(&path)?;

View File

@ -1,10 +1,5 @@
use crate::{
cli::*,
cli_types::*,
commands::SetupCommand,
errors::CLIError,
files::{Manifest, ProofFile},
};
use crate::{cli::*, cli_types::*, commands::SetupCommand, errors::CLIError};
use leo_package::{outputs::ProofFile, root::Manifest};
use snarkos_algorithms::snark::groth16::{Groth16, PreparedVerifyingKey, Proof};
use snarkos_curves::bls12_377::{Bls12_377, Fr};

View File

@ -1,10 +1,7 @@
use crate::{
cli::*,
cli_types::*,
commands::BuildCommand,
directories::output::OutputDirectory,
errors::CLIError,
files::{Manifest, ZipFile},
use crate::{cli::*, cli_types::*, commands::BuildCommand, errors::CLIError};
use leo_package::{
outputs::OutputsDirectory,
root::{Manifest, ZipFile},
};
use clap::ArgMatches;
@ -40,7 +37,7 @@ impl CLI for PublishCommand {
let package_name = Manifest::try_from(&path)?.get_package_name();
// Create the output directory
OutputDirectory::create(&path)?;
OutputsDirectory::create(&path)?;
// Create zip file
let zip_file = ZipFile::new(&package_name);

View File

@ -2,11 +2,14 @@ use crate::{
cli::*,
cli_types::*,
commands::BuildCommand,
directories::SOURCE_DIRECTORY_NAME,
errors::{CLIError, RunError},
files::{Manifest, ProvingKeyFile, VerificationKeyFile, MAIN_FILE_NAME},
};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_package::{
outputs::{ProvingKeyFile, VerificationKeyFile},
root::Manifest,
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
};
use snarkos_algorithms::snark::groth16::{Groth16, Parameters, PreparedVerifyingKey, VerifyingKey};
use snarkos_curves::bls12_377::{Bls12_377, Fr};

View File

@ -1,11 +1,15 @@
use crate::{
cli::*,
cli_types::*,
directories::{output::OUTPUT_DIRECTORY_NAME, source::SOURCE_DIRECTORY_NAME},
errors::{CLIError, TestError},
files::{InputFile, MainFile, Manifest, StateFile, MAIN_FILE_NAME},
};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_package::{
inputs::*,
outputs::OUTPUTS_DIRECTORY_NAME,
root::Manifest,
source::{MainFile, MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
};
use snarkos_curves::edwards_bls12::Fq;
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
@ -58,7 +62,7 @@ impl CLI for TestCommand {
// Construct the path to the output directory;
let mut output_directory = package_path.clone();
output_directory.push(OUTPUT_DIRECTORY_NAME);
output_directory.push(OUTPUTS_DIRECTORY_NAME);
// Load the input file at `package_name`
let input_string = InputFile::new(&package_name).read_from(&path)?;

View File

@ -2,9 +2,11 @@ use crate::{
cli::*,
cli_types::*,
commands::BuildCommand,
directories::SOURCE_DIRECTORY_NAME,
errors::{CLIError, RunError},
files::{Manifest, MAIN_FILE_NAME},
};
use leo_package::{
root::Manifest,
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
};
use clap::ArgMatches;

View File

@ -1,60 +0,0 @@
use crate::errors::InputDirectoryError;
use std::{fs, path::PathBuf};
pub(crate) static INPUT_DIRECTORY_NAME: &str = "input/";
static INPUT_FILE_EXTENSION: &str = "leo.in";
pub struct InputDirectory;
impl InputDirectory {
/// Creates a directory at the provided path with the default directory name.
pub fn create(path: &PathBuf) -> Result<(), InputDirectoryError> {
let mut path = path.to_owned();
if path.is_dir() && !path.ends_with(INPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
}
fs::create_dir_all(&path).map_err(InputDirectoryError::Creating)
}
/// Returns a list of files in the source directory.
pub fn files(path: &PathBuf) -> Result<Vec<PathBuf>, InputDirectoryError> {
let mut path = path.to_owned();
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
let directory = fs::read_dir(&path).map_err(InputDirectoryError::Reading)?;
let mut file_paths = Vec::new();
for file_entry in directory.into_iter() {
let file_entry = file_entry.map_err(InputDirectoryError::GettingFileEntry)?;
let file_path = file_entry.path();
// Verify that the entry is structured as a valid file
let file_type = file_entry
.file_type()
.map_err(|error| InputDirectoryError::GettingFileType(file_path.as_os_str().to_owned(), error))?;
if !file_type.is_file() {
return Err(InputDirectoryError::InvalidFileType(
file_path.as_os_str().to_owned(),
file_type,
));
}
// Verify that the file has the default file extension
let file_extension = file_path
.extension()
.ok_or_else(|| InputDirectoryError::GettingFileExtension(file_path.as_os_str().to_owned()))?;
if file_extension != INPUT_FILE_EXTENSION {
return Err(InputDirectoryError::InvalidFileExtension(
file_path.as_os_str().to_owned(),
file_extension.to_owned(),
));
}
file_paths.push(file_path);
}
Ok(file_paths)
}
}

View File

@ -1,11 +0,0 @@
pub mod imports;
pub use self::imports::*;
pub mod input;
pub use self::input::*;
pub mod output;
pub use self::output::*;
pub mod source;
pub use self::source::*;

View File

@ -1,33 +0,0 @@
use crate::errors::OutputDirectoryError;
use std::{fs, path::PathBuf};
pub(crate) static OUTPUT_DIRECTORY_NAME: &str = "output/";
pub struct OutputDirectory;
impl OutputDirectory {
/// Creates a directory at the provided path with the default directory name.
pub fn create(path: &PathBuf) -> Result<(), OutputDirectoryError> {
let mut path = path.to_owned();
if path.is_dir() && !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
}
fs::create_dir_all(&path).map_err(OutputDirectoryError::Creating)
}
/// Removes the directory at the provided path.
pub fn remove(path: &PathBuf) -> Result<(), OutputDirectoryError> {
let mut path = path.to_owned();
if path.is_dir() && !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
}
if path.exists() {
fs::remove_dir_all(&path).map_err(OutputDirectoryError::Removing)?;
}
Ok(())
}
}

View File

@ -1,4 +1,5 @@
use crate::errors::*;
use leo_package::errors::*;
#[derive(Debug, Error)]
pub enum CLIError {
@ -21,7 +22,7 @@ pub enum CLIError {
InitError(InitError),
#[error("{}", _0)]
InputDirectoryError(InputDirectoryError),
InputDirectoryError(InputsDirectoryError),
#[error("{}", _0)]
InputFileError(InputFileError),
@ -39,7 +40,7 @@ pub enum CLIError {
NewError(NewError),
#[error("{}", _0)]
OutputDirectoryError(OutputDirectoryError),
OutputDirectoryError(OutputsDirectoryError),
#[error("{}", _0)]
ProofFileError(ProofFileError),
@ -101,8 +102,8 @@ impl From<InitError> for CLIError {
}
}
impl From<InputDirectoryError> for CLIError {
fn from(error: InputDirectoryError) -> Self {
impl From<InputsDirectoryError> for CLIError {
fn from(error: InputsDirectoryError) -> Self {
log::error!("{}\n", error);
CLIError::InputDirectoryError(error)
}
@ -143,8 +144,8 @@ impl From<NewError> for CLIError {
}
}
impl From<OutputDirectoryError> for CLIError {
fn from(error: OutputDirectoryError) -> Self {
impl From<OutputsDirectoryError> for CLIError {
fn from(error: OutputsDirectoryError) -> Self {
log::error!("{}\n", error);
CLIError::OutputDirectoryError(error)
}

View File

@ -1,4 +1,4 @@
use crate::errors::ManifestError;
use leo_package::errors::ManifestError;
use std::ffi::OsString;

View File

@ -1,4 +1,4 @@
use crate::errors::ManifestError;
use leo_package::errors::ManifestError;
use std::{ffi::OsString, io};

View File

@ -1,4 +1,4 @@
use crate::errors::ManifestError;
use leo_package::errors::ManifestError;
use std::{ffi::OsString, io};

View File

@ -1,4 +1,4 @@
use crate::errors::ManifestError;
use leo_package::errors::ManifestError;
use std::ffi::OsString;

View File

@ -1,4 +1,4 @@
use crate::errors::ManifestError;
use leo_package::errors::ManifestError;
use std::ffi::OsString;

View File

@ -1,11 +0,0 @@
pub mod imports;
pub use self::imports::*;
pub mod input;
pub use self::input::*;
pub mod output;
pub use self::output::*;
pub mod source;
pub use self::source::*;

View File

@ -1,32 +0,0 @@
pub mod zip;
pub use self::zip::*;
pub mod checksum;
pub use self::checksum::*;
pub mod gitignore;
pub use self::gitignore::*;
pub mod input;
pub use self::input::*;
pub mod lib;
pub use self::lib::*;
pub mod main;
pub use self::main::*;
pub mod manifest;
pub use self::manifest::*;
pub mod proof;
pub use self::proof::*;
pub mod proving_key;
pub use self::proving_key::*;
pub mod state;
pub use self::state::*;
pub mod verification_key;
pub use self::verification_key::*;

View File

@ -3,9 +3,3 @@ pub use self::cli::*;
pub mod commands;
pub use self::commands::*;
pub mod directory;
pub use self::directory::*;
pub mod files;
pub use self::files::*;

View File

@ -1,32 +0,0 @@
pub mod zip;
pub use self::zip::*;
pub mod checksum;
pub use self::checksum::*;
pub mod input;
pub use self::input::*;
pub mod gitignore;
pub use self::gitignore::*;
pub mod lib;
pub use self::lib::*;
pub mod main;
pub use self::main::*;
pub mod manifest;
pub use self::manifest::*;
pub mod proof;
pub use self::proof::*;
pub mod proving_key;
pub use self::proving_key::*;
pub mod state;
pub use self::state::*;
pub mod verification_key;
pub use self::verification_key::*;

View File

@ -5,7 +5,5 @@ extern crate thiserror;
pub mod cli;
pub mod cli_types;
pub mod commands;
pub mod directories;
pub mod errors;
pub mod files;
pub mod logger;

14
package/Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "leo-package"
version = "0.1.0"
authors = ["The Aleo Team <hello@aleo.org>"]
edition = "2018"
[dependencies]
log = { version = "0.4" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
thiserror = { version = "1.0" }
toml = { version = "0.5" }
walkdir = { version = "2" }
zip = { version = "0.5" }

View File

@ -0,0 +1,2 @@
pub mod directory;
pub use directory::*;

View File

@ -1,7 +1,7 @@
use std::{ffi::OsString, fs::FileType, io};
#[derive(Debug, Error)]
pub enum InputDirectoryError {
pub enum InputsDirectoryError {
#[error("creating: {}", _0)]
Creating(io::Error),

View File

@ -0,0 +1,8 @@
pub mod directory;
pub use directory::*;
pub mod input;
pub use input::*;
pub mod state;
pub use state::*;

14
package/src/errors/mod.rs Normal file
View File

@ -0,0 +1,14 @@
pub mod imports;
pub use imports::*;
pub mod inputs;
pub use inputs::*;
pub mod outputs;
pub use outputs::*;
pub mod root;
pub use self::root::*;
pub mod source;
pub use self::source::*;

View File

@ -1,7 +1,7 @@
use std::{ffi::OsString, fs::FileType, io};
#[derive(Debug, Error)]
pub enum OutputDirectoryError {
pub enum OutputsDirectoryError {
#[error("creating: {}", _0)]
Creating(io::Error),

View File

@ -0,0 +1,14 @@
pub mod checksum;
pub use checksum::*;
pub mod directory;
pub use self::directory::*;
pub mod proof;
pub use proof::*;
pub mod proving_key;
pub use proving_key::*;
pub mod verification_key;
pub use verification_key::*;

View File

@ -0,0 +1,8 @@
pub mod gitignore;
pub use self::gitignore::*;
pub mod manifest;
pub use self::manifest::*;
pub mod zip;
pub use self::zip::*;

View File

@ -0,0 +1,8 @@
pub mod directory;
pub use directory::*;
pub mod lib;
pub use lib::*;
pub mod main;
pub use main::*;

View File

@ -2,7 +2,7 @@ use crate::errors::ImportsDirectoryError;
use std::{fs, path::PathBuf};
pub(crate) static IMPORTS_DIRECTORY_NAME: &str = "imports/";
pub static IMPORTS_DIRECTORY_NAME: &str = "imports/";
pub struct ImportsDirectory;

View File

@ -0,0 +1,2 @@
pub mod directory;
pub use directory::*;

View File

@ -0,0 +1,58 @@
use crate::{errors::InputsDirectoryError, inputs::INPUT_FILE_EXTENSION};
use std::{fs, path::PathBuf};
pub static INPUTS_DIRECTORY_NAME: &str = "inputs/";
pub struct InputsDirectory;
impl InputsDirectory {
/// Creates a directory at the provided path with the default directory name.
pub fn create(path: &PathBuf) -> Result<(), InputsDirectoryError> {
let mut path = path.to_owned();
if path.is_dir() && !path.ends_with(INPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
}
fs::create_dir_all(&path).map_err(InputsDirectoryError::Creating)
}
/// Returns a list of files in the source directory.
pub fn files(path: &PathBuf) -> Result<Vec<PathBuf>, InputsDirectoryError> {
let mut path = path.to_owned();
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
let directory = fs::read_dir(&path).map_err(InputsDirectoryError::Reading)?;
let mut file_paths = Vec::new();
for file_entry in directory.into_iter() {
let file_entry = file_entry.map_err(InputsDirectoryError::GettingFileEntry)?;
let file_path = file_entry.path();
// Verify that the entry is structured as a valid file
let file_type = file_entry
.file_type()
.map_err(|error| InputsDirectoryError::GettingFileType(file_path.as_os_str().to_owned(), error))?;
if !file_type.is_file() {
return Err(InputsDirectoryError::InvalidFileType(
file_path.as_os_str().to_owned(),
file_type,
));
}
// Verify that the file has the default file extension
let file_extension = file_path
.extension()
.ok_or_else(|| InputsDirectoryError::GettingFileExtension(file_path.as_os_str().to_owned()))?;
if file_extension != INPUT_FILE_EXTENSION {
return Err(InputsDirectoryError::InvalidFileExtension(
file_path.as_os_str().to_owned(),
file_extension.to_owned(),
));
}
file_paths.push(file_path);
}
Ok(file_paths)
}
}

View File

@ -1,6 +1,6 @@
//! The `program.in` file.
use crate::{directories::input::INPUT_DIRECTORY_NAME, errors::InputFileError};
use crate::{errors::InputFileError, inputs::INPUTS_DIRECTORY_NAME};
use serde::Deserialize;
use std::{
@ -58,8 +58,8 @@ b: u32 = 2;
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(INPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!("{}{}", self.package_name, INPUT_FILE_EXTENSION)));
}

View File

@ -0,0 +1,8 @@
pub mod directory;
pub use directory::*;
pub mod input;
pub use input::*;
pub mod state;
pub use state::*;

View File

@ -1,6 +1,6 @@
//! The `program.state` file.
use crate::{directories::input::INPUT_DIRECTORY_NAME, errors::StateFileError};
use crate::{errors::StateFileError, inputs::INPUTS_DIRECTORY_NAME};
use serde::Deserialize;
use std::{
@ -79,8 +79,8 @@ leaf_randomness: u8[32] = [0u8; 32];
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(INPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!("{}{}", self.package_name, STATE_FILE_EXTENSION)));
}

11
package/src/lib.rs Normal file
View File

@ -0,0 +1,11 @@
#[macro_use]
extern crate thiserror;
pub mod errors;
pub use errors::*;
pub mod imports;
pub mod inputs;
pub mod outputs;
pub mod root;
pub mod source;

View File

@ -1,6 +1,6 @@
//! The build checksum file.
use crate::{directories::output::OUTPUT_DIRECTORY_NAME, errors::ChecksumFileError};
use crate::{errors::ChecksumFileError, outputs::OUTPUTS_DIRECTORY_NAME};
use serde::Deserialize;
use std::{
@ -60,8 +60,8 @@ impl ChecksumFile {
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!(
"{}{}",

View File

@ -0,0 +1,33 @@
use crate::errors::OutputsDirectoryError;
use std::{fs, path::PathBuf};
pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/";
pub struct OutputsDirectory;
impl OutputsDirectory {
/// Creates a directory at the provided path with the default directory name.
pub fn create(path: &PathBuf) -> Result<(), OutputsDirectoryError> {
let mut path = path.to_owned();
if path.is_dir() && !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
}
fs::create_dir_all(&path).map_err(OutputsDirectoryError::Creating)
}
/// Removes the directory at the provided path.
pub fn remove(path: &PathBuf) -> Result<(), OutputsDirectoryError> {
let mut path = path.to_owned();
if path.is_dir() && !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
}
if path.exists() {
fs::remove_dir_all(&path).map_err(OutputsDirectoryError::Removing)?;
}
Ok(())
}
}

View File

@ -0,0 +1,14 @@
pub mod checksum;
pub use self::checksum::*;
pub mod directory;
pub use directory::*;
pub mod proof;
pub use self::proof::*;
pub mod proving_key;
pub use self::proving_key::*;
pub mod verification_key;
pub use self::verification_key::*;

View File

@ -1,6 +1,6 @@
//! The proof file.
use crate::{directories::output::OUTPUT_DIRECTORY_NAME, errors::ProofFileError};
use crate::{errors::ProofFileError, outputs::OUTPUTS_DIRECTORY_NAME};
use serde::Deserialize;
use std::{
@ -63,8 +63,8 @@ impl ProofFile {
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!("{}{}", self.package_name, PROOF_FILE_EXTENSION)));
}

View File

@ -1,6 +1,6 @@
//! The proving key file.
use crate::{directories::output::OUTPUT_DIRECTORY_NAME, errors::ProvingKeyFileError};
use crate::{errors::ProvingKeyFileError, outputs::OUTPUTS_DIRECTORY_NAME};
use serde::Deserialize;
use std::{
@ -60,8 +60,8 @@ impl ProvingKeyFile {
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!(
"{}{}",

View File

@ -1,6 +1,6 @@
//! The verification key file.
use crate::{directories::output::OUTPUT_DIRECTORY_NAME, errors::VerificationKeyFileError};
use crate::{errors::VerificationKeyFileError, outputs::OUTPUTS_DIRECTORY_NAME};
use serde::Deserialize;
use std::{
@ -60,8 +60,8 @@ impl VerificationKeyFile {
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!(
"{}{}",

View File

@ -35,7 +35,7 @@ impl Gitignore {
fn template(&self) -> String {
format!(
r#"output/
r#"outputs/
"#,
)
}

8
package/src/root/mod.rs Normal file
View File

@ -0,0 +1,8 @@
pub mod gitignore;
pub use self::gitignore::*;
pub mod manifest;
pub use self::manifest::*;
pub mod zip;
pub use self::zip::*;

View File

@ -1,11 +1,12 @@
//! The program package zip file.
use crate::{
directories::{IMPORTS_DIRECTORY_NAME, INPUT_DIRECTORY_NAME, OUTPUT_DIRECTORY_NAME},
errors::ZipFileError,
files::{
imports::IMPORTS_DIRECTORY_NAME,
inputs::{INPUTS_DIRECTORY_NAME, INPUT_FILE_EXTENSION},
outputs::{
CHECKSUM_FILE_EXTENSION,
INPUT_FILE_EXTENSION,
OUTPUTS_DIRECTORY_NAME,
PROOF_FILE_EXTENSION,
PROVING_KEY_FILE_EXTENSION,
VERIFICATION_KEY_FILE_EXTENSION,
@ -99,8 +100,8 @@ impl ZipFile {
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned();
if path.is_dir() {
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
}
path.push(PathBuf::from(format!("{}{}", self.package_name, ZIP_FILE_EXTENSION)));
}
@ -110,8 +111,8 @@ impl ZipFile {
fn is_excluded(path: &Path) -> bool {
// excluded directories: `input`, `output`, `imports`
if path.ends_with(INPUT_DIRECTORY_NAME.trim_end_matches("/"))
| path.ends_with(OUTPUT_DIRECTORY_NAME.trim_end_matches("/"))
if path.ends_with(INPUTS_DIRECTORY_NAME.trim_end_matches("/"))
| path.ends_with(OUTPUTS_DIRECTORY_NAME.trim_end_matches("/"))
| path.ends_with(IMPORTS_DIRECTORY_NAME.trim_end_matches("/"))
{
return true;

View File

@ -2,7 +2,7 @@ use crate::errors::SourceDirectoryError;
use std::{fs, path::PathBuf};
pub(crate) static SOURCE_DIRECTORY_NAME: &str = "src/";
pub static SOURCE_DIRECTORY_NAME: &str = "src/";
static SOURCE_FILE_EXTENSION: &str = "leo";

View File

@ -1,6 +1,6 @@
//! The `lib.leo` file.
use crate::{directories::source::SOURCE_DIRECTORY_NAME, errors::LibFileError};
use crate::{errors::LibFileError, source::directory::SOURCE_DIRECTORY_NAME};
use serde::Deserialize;
use std::{fs::File, io::Write, path::PathBuf};

View File

@ -1,6 +1,6 @@
//! The `main.leo` file.
use crate::{directories::source::SOURCE_DIRECTORY_NAME, errors::MainFileError};
use crate::{errors::MainFileError, source::directory::SOURCE_DIRECTORY_NAME};
use serde::Deserialize;
use std::{fs::File, io::Write, path::PathBuf};

View File

@ -0,0 +1,8 @@
pub mod directory;
pub use directory::*;
pub mod lib;
pub use lib::*;
pub mod main;
pub use main::*;