outputs -> output

This commit is contained in:
collin 2020-07-31 21:15:33 -07:00
parent 070fa0edea
commit 3d35fb026b
40 changed files with 147 additions and 151 deletions

View File

@ -6,7 +6,7 @@ use crate::{
GroupType, GroupType,
ImportParser, ImportParser,
OutputBytes, OutputBytes,
OutputsFile, OutputFile,
}; };
use leo_ast::LeoParser; use leo_ast::LeoParser;
use leo_input::LeoInputParser; use leo_input::LeoInputParser;
@ -25,7 +25,7 @@ use std::{fs, marker::PhantomData, path::PathBuf};
pub struct Compiler<F: Field + PrimeField, G: GroupType<F>> { pub struct Compiler<F: Field + PrimeField, G: GroupType<F>> {
package_name: String, package_name: String,
main_file_path: PathBuf, main_file_path: PathBuf,
outputs_directory: PathBuf, output_directory: PathBuf,
program: Program, program: Program,
program_input: Input, program_input: Input,
imported_programs: ImportParser, imported_programs: ImportParser,
@ -34,11 +34,11 @@ pub struct Compiler<F: Field + PrimeField, G: GroupType<F>> {
} }
impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> { impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
pub fn new(package_name: String, main_file_path: PathBuf, outputs_directory: PathBuf) -> Self { pub fn new(package_name: String, main_file_path: PathBuf, output_directory: PathBuf) -> Self {
Self { Self {
package_name: package_name.clone(), package_name: package_name.clone(),
main_file_path, main_file_path,
outputs_directory, output_directory,
program: Program::new(package_name), program: Program::new(package_name),
program_input: Input::new(), program_input: Input::new(),
imported_programs: ImportParser::new(), imported_programs: ImportParser::new(),
@ -52,9 +52,9 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
pub fn parse_program_without_input( pub fn parse_program_without_input(
package_name: String, package_name: String,
main_file_path: PathBuf, main_file_path: PathBuf,
outputs_directory: PathBuf, output_directory: PathBuf,
) -> Result<Self, CompilerError> { ) -> Result<Self, CompilerError> {
let mut compiler = Self::new(package_name, main_file_path, outputs_directory); let mut compiler = Self::new(package_name, main_file_path, output_directory);
let program_string = compiler.load_program()?; let program_string = compiler.load_program()?;
compiler.parse_program(&program_string)?; compiler.parse_program(&program_string)?;
@ -67,11 +67,11 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
pub fn parse_program_with_input( pub fn parse_program_with_input(
package_name: String, package_name: String,
main_file_path: PathBuf, main_file_path: PathBuf,
outputs_directory: PathBuf, output_directory: PathBuf,
input_string: &str, input_string: &str,
state_string: &str, state_string: &str,
) -> Result<Self, CompilerError> { ) -> Result<Self, CompilerError> {
let mut compiler = Self::new(package_name, main_file_path, outputs_directory); let mut compiler = Self::new(package_name, main_file_path, output_directory);
compiler.parse_input(input_string, state_string)?; compiler.parse_input(input_string, state_string)?;
@ -175,7 +175,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
Ok(Self { Ok(Self {
package_name: program.name.clone(), package_name: program.name.clone(),
main_file_path: PathBuf::new(), main_file_path: PathBuf::new(),
outputs_directory: PathBuf::new(), output_directory: PathBuf::new(),
program, program,
program_input, program_input,
imported_programs: ImportParser::new(), imported_programs: ImportParser::new(),
@ -188,7 +188,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<F, G> { impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<F, G> {
/// Synthesizes the circuit with program input. /// Synthesizes the circuit with program input.
fn generate_constraints<CS: ConstraintSystem<F>>(self, cs: &mut CS) -> Result<(), SynthesisError> { fn generate_constraints<CS: ConstraintSystem<F>>(self, cs: &mut CS) -> Result<(), SynthesisError> {
let outputs_directory = self.outputs_directory.clone(); let output_directory = self.output_directory.clone();
let package_name = self.package_name.clone(); let package_name = self.package_name.clone();
let result = self.generate_constraints_helper(cs).map_err(|e| { let result = self.generate_constraints_helper(cs).map_err(|e| {
log::error!("{}", e); log::error!("{}", e);
@ -198,8 +198,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compil
log::info!("Program circuit successfully synthesized!"); log::info!("Program circuit successfully synthesized!");
// Write results to file // Write results to file
let outputs_file = OutputsFile::new(&package_name); let output_file = OutputFile::new(&package_name);
outputs_file.write(&outputs_directory, result.bytes()).unwrap(); output_file.write(&output_directory, result.bytes()).unwrap();
Ok(()) Ok(())
} }

View File

@ -1,4 +1,4 @@
use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputsFileError}; use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError};
use leo_ast::ParserError; use leo_ast::ParserError;
use leo_input::InputParserError; use leo_input::InputParserError;
@ -26,7 +26,7 @@ pub enum CompilerError {
NoMainFunction, NoMainFunction,
#[error("{}", _0)] #[error("{}", _0)]
OutputError(#[from] OutputsFileError), OutputError(#[from] OutputFileError),
#[error("{}", _0)] #[error("{}", _0)]
OutputStringError(#[from] OutputBytesError), OutputStringError(#[from] OutputBytesError),

View File

@ -1,7 +1,7 @@
use std::{io, path::PathBuf}; use std::{io, path::PathBuf};
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum OutputsFileError { pub enum OutputFileError {
#[error("{}: {}", _0, _1)] #[error("{}: {}", _0, _1)]
Crate(&'static str, String), Crate(&'static str, String),
@ -15,8 +15,8 @@ pub enum OutputsFileError {
Writing(io::Error), Writing(io::Error),
} }
impl From<std::io::Error> for OutputsFileError { impl From<std::io::Error> for OutputFileError {
fn from(error: std::io::Error) -> Self { fn from(error: std::io::Error) -> Self {
OutputsFileError::Crate("std::io", format!("{}", error)) OutputFileError::Crate("std::io", format!("{}", error))
} }
} }

View File

@ -1,6 +1,6 @@
//! The `program.out` file. //! The `program.out` file.
use crate::errors::OutputsFileError; use crate::errors::OutputFileError;
use std::{ use std::{
fs::{self, File}, fs::{self, File},
@ -8,14 +8,14 @@ use std::{
path::PathBuf, path::PathBuf,
}; };
pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/"; pub static OUTPUT_DIRECTORY_NAME: &str = "output/";
pub static OUTPUTS_FILE_EXTENSION: &str = ".out"; pub static OUTPUT_FILE_EXTENSION: &str = ".out";
pub struct OutputsFile { pub struct OutputFile {
pub package_name: String, pub package_name: String,
} }
impl OutputsFile { impl OutputFile {
pub fn new(package_name: &str) -> Self { pub fn new(package_name: &str) -> Self {
Self { Self {
package_name: package_name.to_string(), package_name: package_name.to_string(),
@ -27,16 +27,16 @@ impl OutputsFile {
path.exists() path.exists()
} }
/// Reads the outputs from the given file path if it exists. /// Reads the output register variables from the given file path if it exists.
pub fn read_from(&self, path: &PathBuf) -> Result<String, OutputsFileError> { pub fn read_from(&self, path: &PathBuf) -> Result<String, OutputFileError> {
let path = self.setup_file_path(path); let path = self.setup_file_path(path);
let outputs = fs::read_to_string(&path).map_err(|_| OutputsFileError::FileReadError(path.clone()))?; let output = fs::read_to_string(&path).map_err(|_| OutputFileError::FileReadError(path.clone()))?;
Ok(outputs) Ok(output)
} }
/// Writes output to a file. /// Writes output to a file.
pub fn write(&self, path: &PathBuf, bytes: &[u8]) -> Result<(), OutputsFileError> { pub fn write(&self, path: &PathBuf, bytes: &[u8]) -> Result<(), OutputFileError> {
// create output file // create output file
let path = self.setup_file_path(path); let path = self.setup_file_path(path);
let mut file = File::create(&path)?; let mut file = File::create(&path)?;
@ -48,13 +48,10 @@ impl OutputsFile {
fn setup_file_path(&self, path: &PathBuf) -> PathBuf { fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
let mut path = path.to_owned(); let mut path = path.to_owned();
if path.is_dir() { if path.is_dir() {
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) { if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
} }
path.push(PathBuf::from(format!( path.push(PathBuf::from(format!("{}{}", self.package_name, OUTPUT_FILE_EXTENSION)));
"{}{}",
self.package_name, OUTPUTS_FILE_EXTENSION
)));
} }
path path
} }

View File

@ -1,22 +1,22 @@
use crate::{ use crate::{
assert_satisfied, assert_satisfied,
expect_compiler_error, expect_compiler_error,
get_outputs, get_output,
parse_program, parse_program,
parse_program_with_input, parse_program_with_input,
EdwardsTestCompiler, EdwardsTestCompiler,
}; };
pub fn output_ones(program: EdwardsTestCompiler) { pub fn output_ones(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_ones.out"); let expected = include_bytes!("output_/registers_ones.out");
let actual = get_outputs(program); let actual = get_output(program);
assert!(expected.eq(actual.bytes().as_slice())); assert!(expected.eq(actual.bytes().as_slice()));
} }
pub fn output_zeros(program: EdwardsTestCompiler) { pub fn output_zeros(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_zeros.out"); let expected = include_bytes!("output_/registers_zeros.out");
let actual = get_outputs(program); let actual = get_output(program);
assert!(expected.eq(actual.bytes().as_slice())); assert!(expected.eq(actual.bytes().as_slice()));
} }

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied, assert_satisfied,
expect_compiler_error, expect_compiler_error,
expect_synthesis_error, expect_synthesis_error,
get_outputs, get_output,
parse_program, parse_program,
parse_program_with_input, parse_program_with_input,
EdwardsTestCompiler, EdwardsTestCompiler,
@ -10,15 +10,15 @@ use crate::{
use leo_compiler::errors::{BooleanError, CompilerError, ExpressionError, FunctionError, StatementError}; use leo_compiler::errors::{BooleanError, CompilerError, ExpressionError, FunctionError, StatementError};
pub fn output_true(program: EdwardsTestCompiler) { pub fn output_true(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_true.out"); let expected = include_bytes!("output_/registers_true.out");
let actual = get_outputs(program); let actual = get_output(program);
assert_eq!(expected, actual.bytes().as_slice()); assert_eq!(expected, actual.bytes().as_slice());
} }
pub fn output_false(program: EdwardsTestCompiler) { pub fn output_false(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_false.out"); let expected = include_bytes!("output_/registers_false.out");
let actual = get_outputs(program); let actual = get_output(program);
assert_eq!(expected, actual.bytes().as_slice()); assert_eq!(expected, actual.bytes().as_slice());
} }

View File

@ -279,15 +279,15 @@ fn test_ternary() {
// //
// pub fn output_one(program: EdwardsTestCompiler) { // pub fn output_one(program: EdwardsTestCompiler) {
// let expected = include_bytes!("outputs_/register_one.out"); // let expected = include_bytes!("output_/register_one.out");
// let actual = get_outputs(program); // let actual = get_output(program);
// //
// assert_eq!(expected, actual.bytes().as_slice()); // assert_eq!(expected, actual.bytes().as_slice());
// } // }
// //
// pub fn output_zero(program: EdwardsTestCompiler) { // pub fn output_zero(program: EdwardsTestCompiler) {
// let expected = include_bytes!("outputs_/register_zero.out"); // let expected = include_bytes!("output_/register_zero.out");
// let actual = get_outputs(program); // let actual = get_output(program);
// //
// assert_eq!(expected, actual.bytes().as_slice()); // assert_eq!(expected, actual.bytes().as_slice());
// } // }

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
assert_satisfied, assert_satisfied,
expect_compiler_error, expect_compiler_error,
get_outputs, get_output,
parse_program, parse_program,
parse_program_with_input, parse_program_with_input,
EdwardsTestCompiler, EdwardsTestCompiler,
@ -56,9 +56,9 @@ fn test_multiple_returns_main() {
let program = parse_program_with_input(program_bytes, input_bytes).unwrap(); let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
let expected_bytes = include_bytes!("outputs_/registers.out"); let expected_bytes = include_bytes!("output_/registers.out");
let expected = std::str::from_utf8(expected_bytes).unwrap(); let expected = std::str::from_utf8(expected_bytes).unwrap();
let actual_bytes = get_outputs(program); let actual_bytes = get_output(program);
let actual = std::str::from_utf8(actual_bytes.bytes().as_slice()).unwrap(); let actual = std::str::from_utf8(actual_bytes.bytes().as_slice()).unwrap();
assert_eq!(expected, actual); assert_eq!(expected, actual);

View File

@ -1 +1 @@
outputs/ output/

View File

@ -1 +1 @@
outputs/ output/

View File

@ -27,8 +27,7 @@ use snarkos_models::gadgets::r1cs::TestConstraintSystem;
use std::path::PathBuf; use std::path::PathBuf;
pub const TEST_OUTPUTS_DIRECTORY: &str = "/outputs/"; pub const TEST_OUTPUT_DIRECTORY: &str = "/output/";
pub const TEST_OUTPUTS_FILE_NAME: &str = "/outputs/test.out";
const EMPTY_FILE: &str = ""; const EMPTY_FILE: &str = "";
pub type EdwardsTestCompiler = Compiler<Fq, EdwardsGroupType>; pub type EdwardsTestCompiler = Compiler<Fq, EdwardsGroupType>;
@ -37,9 +36,9 @@ pub type EdwardsConstrainedValue = ConstrainedValue<Fq, EdwardsGroupType>;
fn new_compiler() -> EdwardsTestCompiler { fn new_compiler() -> EdwardsTestCompiler {
let program_name = "test".to_string(); let program_name = "test".to_string();
let path = PathBuf::from("/test/src/main.leo"); let path = PathBuf::from("/test/src/main.leo");
let outputs_dir = PathBuf::from(TEST_OUTPUTS_DIRECTORY); let output_dir = PathBuf::from(TEST_OUTPUT_DIRECTORY);
EdwardsTestCompiler::new(program_name, path, outputs_dir) EdwardsTestCompiler::new(program_name, path, output_dir)
} }
pub(crate) fn parse_program(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> { pub(crate) fn parse_program(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> {
@ -129,7 +128,7 @@ pub fn parse_program_with_input_and_state(
Ok(compiler) Ok(compiler)
} }
pub(crate) fn get_outputs(program: EdwardsTestCompiler) -> OutputBytes { pub(crate) fn get_output(program: EdwardsTestCompiler) -> OutputBytes {
// synthesize the circuit on the test constraint system // synthesize the circuit on the test constraint system
let mut cs = TestConstraintSystem::<Fq>::new(); let mut cs = TestConstraintSystem::<Fq>::new();
let output = program.generate_constraints_helper(&mut cs).unwrap(); let output = program.generate_constraints_helper(&mut cs).unwrap();
@ -141,8 +140,8 @@ pub(crate) fn get_outputs(program: EdwardsTestCompiler) -> OutputBytes {
} }
pub(crate) fn assert_satisfied(program: EdwardsTestCompiler) { pub(crate) fn assert_satisfied(program: EdwardsTestCompiler) {
let empty_output_bytes = include_bytes!("compiler_outputs/empty.out"); let empty_output_bytes = include_bytes!("compiler_output/empty.out");
let res = get_outputs(program); let res = get_output(program);
// assert that the output is empty // assert that the output is empty
assert_eq!(empty_output_bytes, res.bytes().as_slice()); assert_eq!(empty_output_bytes, res.bytes().as_slice());

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied, assert_satisfied,
expect_synthesis_error, expect_synthesis_error,
generate_main_input, generate_main_input,
get_outputs, get_output,
parse_program, parse_program,
parse_program_with_input, parse_program_with_input,
EdwardsTestCompiler, EdwardsTestCompiler,
@ -216,15 +216,15 @@ fn test_nested() {
} }
fn output_one(program: EdwardsTestCompiler) { fn output_one(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_one.out"); let expected = include_bytes!("output_/registers_one.out");
let actual = get_outputs(program); let actual = get_output(program);
assert_eq!(expected, actual.bytes().as_slice()); assert_eq!(expected, actual.bytes().as_slice());
} }
fn output_zero(program: EdwardsTestCompiler) { fn output_zero(program: EdwardsTestCompiler) {
let expected = include_bytes!("outputs_/registers_zero.out"); let expected = include_bytes!("output_/registers_zero.out");
let actual = get_outputs(program); let actual = get_output(program);
assert_eq!(expected, actual.bytes().as_slice()); assert_eq!(expected, actual.bytes().as_slice());
} }

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
cli::*, cli::*,
cli_types::*, cli_types::*,
directories::{source::SOURCE_DIRECTORY_NAME, OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, directories::{source::SOURCE_DIRECTORY_NAME, OutputDirectory, OUTPUT_DIRECTORY_NAME},
errors::CLIError, errors::CLIError,
files::{ChecksumFile, InputFile, LibFile, MainFile, Manifest, StateFile, LIB_FILE_NAME, MAIN_FILE_NAME}, files::{ChecksumFile, InputFile, LibFile, MainFile, Manifest, StateFile, LIB_FILE_NAME, MAIN_FILE_NAME},
}; };
@ -47,9 +47,9 @@ impl CLI for BuildCommand {
package_path.pop(); package_path.pop();
} }
// Construct the path to the outputs directory // Construct the path to the output directory
let mut outputs_directory = package_path.clone(); let mut output_directory = package_path.clone();
outputs_directory.push(OUTPUTS_DIRECTORY_NAME); output_directory.push(OUTPUT_DIRECTORY_NAME);
// Compile the package starting with the lib.leo file // Compile the package starting with the lib.leo file
if LibFile::exists_at(&package_path) { if LibFile::exists_at(&package_path) {
@ -62,7 +62,7 @@ impl CLI for BuildCommand {
let _program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input( let _program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(
package_name.clone(), package_name.clone(),
lib_file_path.clone(), lib_file_path.clone(),
outputs_directory.clone(), output_directory.clone(),
)?; )?;
log::info!("Compiled library file {:?}", lib_file_path); log::info!("Compiled library file {:?}", lib_file_path);
@ -70,8 +70,8 @@ impl CLI for BuildCommand {
// Compile the main.leo file along with constraints // Compile the main.leo file along with constraints
if MainFile::exists_at(&package_path) { if MainFile::exists_at(&package_path) {
// Create the outputs directory // Create the output directory
OutputsDirectory::create(&package_path)?; OutputDirectory::create(&package_path)?;
// Construct the path to the main file in the source directory // Construct the path to the main file in the source directory
let mut main_file_path = package_path.clone(); let mut main_file_path = package_path.clone();
@ -88,7 +88,7 @@ impl CLI for BuildCommand {
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_with_input( let program = Compiler::<Fq, EdwardsGroupType>::parse_program_with_input(
package_name.clone(), package_name.clone(),
main_file_path.clone(), main_file_path.clone(),
outputs_directory, output_directory,
&input_string, &input_string,
&state_string, &state_string,
)?; )?;
@ -124,7 +124,7 @@ impl CLI for BuildCommand {
// If checksum differs, compile the program // If checksum differs, compile the program
if checksum_differs { if checksum_differs {
// Write the new checksum to the outputs directory // Write the new checksum to the output directory
checksum_file.write_to(&path, program_checksum)?; checksum_file.write_to(&path, program_checksum)?;
log::debug!("Checksum saved ({:?})", path); log::debug!("Checksum saved ({:?})", path);

View File

@ -15,7 +15,7 @@ impl CLI for CleanCommand {
type Options = (); type Options = ();
type Output = (); type Output = ();
const ABOUT: AboutType = "Clean the outputs directory"; const ABOUT: AboutType = "Clean the output directory";
const ARGUMENTS: &'static [ArgumentType] = &[]; const ARGUMENTS: &'static [ArgumentType] = &[];
const FLAGS: &'static [FlagType] = &[]; const FLAGS: &'static [FlagType] = &[];
const NAME: NameType = "clean"; const NAME: NameType = "clean";
@ -33,16 +33,16 @@ impl CLI for CleanCommand {
let path = current_dir()?; let path = current_dir()?;
let package_name = Manifest::try_from(&path)?.get_package_name(); let package_name = Manifest::try_from(&path)?.get_package_name();
// Remove the checksum from the outputs directory // Remove the checksum from the output directory
ChecksumFile::new(&package_name).remove(&path)?; ChecksumFile::new(&package_name).remove(&path)?;
// Remove the proving key from the outputs directory // Remove the proving key from the output directory
ProvingKeyFile::new(&package_name).remove(&path)?; ProvingKeyFile::new(&package_name).remove(&path)?;
// Remove the verification key from the outputs directory // Remove the verification key from the output directory
VerificationKeyFile::new(&package_name).remove(&path)?; VerificationKeyFile::new(&package_name).remove(&path)?;
// Remove the proof from the outputs directory // Remove the proof from the output directory
ProofFile::new(&package_name).remove(&path)?; ProofFile::new(&package_name).remove(&path)?;
Ok(()) Ok(())

View File

@ -52,7 +52,7 @@ impl CLI for ProveCommand {
// Output the proving time // Output the proving time
log::info!("Prover completed in {:?} milliseconds", start.elapsed().as_millis()); log::info!("Prover completed in {:?} milliseconds", start.elapsed().as_millis());
// Write the proof file to the outputs directory // Write the proof file to the output directory
let mut proof = vec![]; let mut proof = vec![];
program_proof.write(&mut proof)?; program_proof.write(&mut proof)?;
ProofFile::new(&package_name).write_to(&path, &proof)?; ProofFile::new(&package_name).write_to(&path, &proof)?;

View File

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

View File

@ -68,13 +68,13 @@ impl CLI for SetupCommand {
log::info!("Setup completed in {:?} milliseconds", start.elapsed().as_millis()); log::info!("Setup completed in {:?} milliseconds", start.elapsed().as_millis());
// TODO (howardwu): Convert parameters to a 'proving key' struct for serialization. // TODO (howardwu): Convert parameters to a 'proving key' struct for serialization.
// Write the proving key file to the outputs directory // Write the proving key file to the output directory
let mut proving_key_bytes = vec![]; let mut proving_key_bytes = vec![];
proving_key.write(&mut proving_key_bytes)?; proving_key.write(&mut proving_key_bytes)?;
ProvingKeyFile::new(&package_name).write_to(&path, &proving_key_bytes)?; ProvingKeyFile::new(&package_name).write_to(&path, &proving_key_bytes)?;
log::info!("Saving proving key ({:?})", path); log::info!("Saving proving key ({:?})", path);
// Write the verification key file to the outputs directory // Write the verification key file to the output directory
let mut verification_key = vec![]; let mut verification_key = vec![];
proving_key.vk.write(&mut verification_key)?; proving_key.vk.write(&mut verification_key)?;
VerificationKeyFile::new(&package_name).write_to(&path, &verification_key)?; VerificationKeyFile::new(&package_name).write_to(&path, &verification_key)?;
@ -84,11 +84,11 @@ impl CLI for SetupCommand {
} else { } else {
log::info!("Loading saved setup..."); log::info!("Loading saved setup...");
// Read the proving key file from the outputs directory // Read the proving key file from the output directory
let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?; let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?;
let proving_key = Parameters::<Bls12_377>::read(proving_key_bytes.as_slice(), true)?; let proving_key = Parameters::<Bls12_377>::read(proving_key_bytes.as_slice(), true)?;
// Read the verification key file from the outputs directory // Read the verification key file from the output directory
let verifying_key_bytes = VerificationKeyFile::new(&package_name).read_from(&path)?; let verifying_key_bytes = VerificationKeyFile::new(&package_name).read_from(&path)?;
let verifying_key = VerifyingKey::<Bls12_377>::read(verifying_key_bytes.as_slice())?; let verifying_key = VerifyingKey::<Bls12_377>::read(verifying_key_bytes.as_slice())?;

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
cli::*, cli::*,
cli_types::*, cli_types::*,
directories::{outputs::OUTPUTS_DIRECTORY_NAME, source::SOURCE_DIRECTORY_NAME}, directories::{output::OUTPUT_DIRECTORY_NAME, source::SOURCE_DIRECTORY_NAME},
errors::{CLIError, TestError}, errors::{CLIError, TestError},
files::{InputFile, MainFile, Manifest, StateFile, MAIN_FILE_NAME}, files::{InputFile, MainFile, Manifest, StateFile, MAIN_FILE_NAME},
}; };
@ -56,9 +56,9 @@ impl CLI for TestCommand {
main_file_path.push(SOURCE_DIRECTORY_NAME); main_file_path.push(SOURCE_DIRECTORY_NAME);
main_file_path.push(MAIN_FILE_NAME); main_file_path.push(MAIN_FILE_NAME);
// Construct the path to the outputs directory; // Construct the path to the output directory;
let mut outputs_directory = package_path.clone(); let mut output_directory = package_path.clone();
outputs_directory.push(OUTPUTS_DIRECTORY_NAME); output_directory.push(OUTPUT_DIRECTORY_NAME);
// Load the input file at `package_name` // Load the input file at `package_name`
let input_string = InputFile::new(&package_name).read_from(&path)?; let input_string = InputFile::new(&package_name).read_from(&path)?;
@ -70,7 +70,7 @@ impl CLI for TestCommand {
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_with_input( let program = Compiler::<Fq, EdwardsGroupType>::parse_program_with_input(
package_name.clone(), package_name.clone(),
main_file_path.clone(), main_file_path.clone(),
outputs_directory, output_directory,
&input_string, &input_string,
&state_string, &state_string,
)?; )?;

View File

@ -4,8 +4,8 @@ pub use self::imports::*;
pub mod input; pub mod input;
pub use self::input::*; pub use self::input::*;
pub mod outputs; pub mod output;
pub use self::outputs::*; pub use self::output::*;
pub mod source; pub mod source;
pub use self::source::*; pub use self::source::*;

33
leo/directories/output.rs Normal file
View File

@ -0,0 +1,33 @@
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,33 +0,0 @@
use crate::errors::OutputsDirectoryError;
use std::{fs, path::PathBuf};
pub(crate) 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

@ -39,7 +39,7 @@ pub enum CLIError {
NewError(NewError), NewError(NewError),
#[error("{}", _0)] #[error("{}", _0)]
OutputsDirectoryError(OutputsDirectoryError), OutputDirectoryError(OutputDirectoryError),
#[error("{}", _0)] #[error("{}", _0)]
ProofFileError(ProofFileError), ProofFileError(ProofFileError),
@ -143,10 +143,10 @@ impl From<NewError> for CLIError {
} }
} }
impl From<OutputsDirectoryError> for CLIError { impl From<OutputDirectoryError> for CLIError {
fn from(error: OutputsDirectoryError) -> Self { fn from(error: OutputDirectoryError) -> Self {
log::error!("{}\n", error); log::error!("{}\n", error);
CLIError::OutputsDirectoryError(error) CLIError::OutputDirectoryError(error)
} }
} }

View File

@ -4,8 +4,8 @@ pub use self::imports::*;
pub mod input; pub mod input;
pub use self::input::*; pub use self::input::*;
pub mod outputs; pub mod output;
pub use self::outputs::*; pub use self::output::*;
pub mod source; pub mod source;
pub use self::source::*; pub use self::source::*;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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