diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 1b44492bdf..8bea011f42 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -6,7 +6,7 @@ use crate::{ GroupType, ImportParser, OutputBytes, - OutputsFile, + OutputFile, }; use leo_ast::LeoParser; use leo_input::LeoInputParser; @@ -25,7 +25,7 @@ use std::{fs, marker::PhantomData, path::PathBuf}; pub struct Compiler> { package_name: String, main_file_path: PathBuf, - outputs_directory: PathBuf, + output_directory: PathBuf, program: Program, program_input: Input, imported_programs: ImportParser, @@ -34,11 +34,11 @@ pub struct Compiler> { } impl> Compiler { - 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 { package_name: package_name.clone(), main_file_path, - outputs_directory, + output_directory, program: Program::new(package_name), program_input: Input::new(), imported_programs: ImportParser::new(), @@ -52,9 +52,9 @@ impl> Compiler { pub fn parse_program_without_input( package_name: String, main_file_path: PathBuf, - outputs_directory: PathBuf, + output_directory: PathBuf, ) -> Result { - 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()?; compiler.parse_program(&program_string)?; @@ -67,11 +67,11 @@ impl> Compiler { pub fn parse_program_with_input( package_name: String, main_file_path: PathBuf, - outputs_directory: PathBuf, + output_directory: PathBuf, input_string: &str, state_string: &str, ) -> Result { - 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)?; @@ -175,7 +175,7 @@ impl> Compiler { Ok(Self { package_name: program.name.clone(), main_file_path: PathBuf::new(), - outputs_directory: PathBuf::new(), + output_directory: PathBuf::new(), program, program_input, imported_programs: ImportParser::new(), @@ -188,7 +188,7 @@ impl> Compiler { impl> ConstraintSynthesizer for Compiler { /// Synthesizes the circuit with program input. fn generate_constraints>(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 result = self.generate_constraints_helper(cs).map_err(|e| { log::error!("{}", e); @@ -198,8 +198,8 @@ impl> ConstraintSynthesizer for Compil log::info!("Program circuit successfully synthesized!"); // Write results to file - let outputs_file = OutputsFile::new(&package_name); - outputs_file.write(&outputs_directory, result.bytes()).unwrap(); + let output_file = OutputFile::new(&package_name); + output_file.write(&output_directory, result.bytes()).unwrap(); Ok(()) } diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index c7acf1951b..ff76268520 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -1,4 +1,4 @@ -use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputsFileError}; +use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError}; use leo_ast::ParserError; use leo_input::InputParserError; @@ -26,7 +26,7 @@ pub enum CompilerError { NoMainFunction, #[error("{}", _0)] - OutputError(#[from] OutputsFileError), + OutputError(#[from] OutputFileError), #[error("{}", _0)] OutputStringError(#[from] OutputBytesError), diff --git a/compiler/src/errors/output_file.rs b/compiler/src/errors/output_file.rs index 29b8f84bba..547e931819 100644 --- a/compiler/src/errors/output_file.rs +++ b/compiler/src/errors/output_file.rs @@ -1,7 +1,7 @@ use std::{io, path::PathBuf}; #[derive(Debug, Error)] -pub enum OutputsFileError { +pub enum OutputFileError { #[error("{}: {}", _0, _1)] Crate(&'static str, String), @@ -15,8 +15,8 @@ pub enum OutputsFileError { Writing(io::Error), } -impl From for OutputsFileError { +impl From for OutputFileError { fn from(error: std::io::Error) -> Self { - OutputsFileError::Crate("std::io", format!("{}", error)) + OutputFileError::Crate("std::io", format!("{}", error)) } } diff --git a/compiler/src/output/output_file.rs b/compiler/src/output/output_file.rs index 54310bc70d..aac326d6cb 100644 --- a/compiler/src/output/output_file.rs +++ b/compiler/src/output/output_file.rs @@ -1,6 +1,6 @@ //! The `program.out` file. -use crate::errors::OutputsFileError; +use crate::errors::OutputFileError; use std::{ fs::{self, File}, @@ -8,14 +8,14 @@ use std::{ path::PathBuf, }; -pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/"; -pub static OUTPUTS_FILE_EXTENSION: &str = ".out"; +pub static OUTPUT_DIRECTORY_NAME: &str = "output/"; +pub static OUTPUT_FILE_EXTENSION: &str = ".out"; -pub struct OutputsFile { +pub struct OutputFile { pub package_name: String, } -impl OutputsFile { +impl OutputFile { pub fn new(package_name: &str) -> Self { Self { package_name: package_name.to_string(), @@ -27,16 +27,16 @@ impl OutputsFile { path.exists() } - /// Reads the outputs from the given file path if it exists. - pub fn read_from(&self, path: &PathBuf) -> Result { + /// Reads the output register variables from the given file path if it exists. + pub fn read_from(&self, path: &PathBuf) -> Result { let path = self.setup_file_path(path); - let outputs = fs::read_to_string(&path).map_err(|_| OutputsFileError::FileReadError(path.clone()))?; - Ok(outputs) + let output = fs::read_to_string(&path).map_err(|_| OutputFileError::FileReadError(path.clone()))?; + Ok(output) } /// 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 let path = self.setup_file_path(path); let mut file = File::create(&path)?; @@ -48,13 +48,10 @@ impl OutputsFile { fn setup_file_path(&self, path: &PathBuf) -> PathBuf { let mut path = path.to_owned(); if path.is_dir() { - if !path.ends_with(OUTPUTS_DIRECTORY_NAME) { - path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); + if !path.ends_with(OUTPUT_DIRECTORY_NAME) { + path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME)); } - path.push(PathBuf::from(format!( - "{}{}", - self.package_name, OUTPUTS_FILE_EXTENSION - ))); + path.push(PathBuf::from(format!("{}{}", self.package_name, OUTPUT_FILE_EXTENSION))); } path } diff --git a/compiler/tests/array/mod.rs b/compiler/tests/array/mod.rs index 3b17b35657..2667402334 100644 --- a/compiler/tests/array/mod.rs +++ b/compiler/tests/array/mod.rs @@ -1,22 +1,22 @@ use crate::{ assert_satisfied, expect_compiler_error, - get_outputs, + get_output, parse_program, parse_program_with_input, EdwardsTestCompiler, }; pub fn output_ones(program: EdwardsTestCompiler) { - let expected = include_bytes!("outputs_/registers_ones.out"); - let actual = get_outputs(program); + let expected = include_bytes!("output_/registers_ones.out"); + let actual = get_output(program); assert!(expected.eq(actual.bytes().as_slice())); } pub fn output_zeros(program: EdwardsTestCompiler) { - let expected = include_bytes!("outputs_/registers_zeros.out"); - let actual = get_outputs(program); + let expected = include_bytes!("output_/registers_zeros.out"); + let actual = get_output(program); assert!(expected.eq(actual.bytes().as_slice())); } diff --git a/compiler/tests/array/outputs_/registers_ones.out b/compiler/tests/array/output_/registers_ones.out similarity index 100% rename from compiler/tests/array/outputs_/registers_ones.out rename to compiler/tests/array/output_/registers_ones.out diff --git a/compiler/tests/array/outputs_/registers_zeros.out b/compiler/tests/array/output_/registers_zeros.out similarity index 100% rename from compiler/tests/array/outputs_/registers_zeros.out rename to compiler/tests/array/output_/registers_zeros.out diff --git a/compiler/tests/boolean/mod.rs b/compiler/tests/boolean/mod.rs index 0783d8a0bf..b0a173e14c 100644 --- a/compiler/tests/boolean/mod.rs +++ b/compiler/tests/boolean/mod.rs @@ -2,7 +2,7 @@ use crate::{ assert_satisfied, expect_compiler_error, expect_synthesis_error, - get_outputs, + get_output, parse_program, parse_program_with_input, EdwardsTestCompiler, @@ -10,15 +10,15 @@ use crate::{ use leo_compiler::errors::{BooleanError, CompilerError, ExpressionError, FunctionError, StatementError}; pub fn output_true(program: EdwardsTestCompiler) { - let expected = include_bytes!("outputs_/registers_true.out"); - let actual = get_outputs(program); + let expected = include_bytes!("output_/registers_true.out"); + let actual = get_output(program); assert_eq!(expected, actual.bytes().as_slice()); } pub fn output_false(program: EdwardsTestCompiler) { - let expected = include_bytes!("outputs_/registers_false.out"); - let actual = get_outputs(program); + let expected = include_bytes!("output_/registers_false.out"); + let actual = get_output(program); assert_eq!(expected, actual.bytes().as_slice()); } diff --git a/compiler/tests/boolean/outputs_/registers_false.out b/compiler/tests/boolean/output_/registers_false.out similarity index 100% rename from compiler/tests/boolean/outputs_/registers_false.out rename to compiler/tests/boolean/output_/registers_false.out diff --git a/compiler/tests/boolean/outputs_/registers_true.out b/compiler/tests/boolean/output_/registers_true.out similarity index 100% rename from compiler/tests/boolean/outputs_/registers_true.out rename to compiler/tests/boolean/output_/registers_true.out diff --git a/compiler/tests/compiler_outputs/empty.out b/compiler/tests/compiler_output/empty.out similarity index 100% rename from compiler/tests/compiler_outputs/empty.out rename to compiler/tests/compiler_output/empty.out diff --git a/compiler/tests/field/mod.rs b/compiler/tests/field/mod.rs index 33df5b9b76..ccfdd1820c 100644 --- a/compiler/tests/field/mod.rs +++ b/compiler/tests/field/mod.rs @@ -279,15 +279,15 @@ fn test_ternary() { // // pub fn output_one(program: EdwardsTestCompiler) { -// let expected = include_bytes!("outputs_/register_one.out"); -// let actual = get_outputs(program); +// let expected = include_bytes!("output_/register_one.out"); +// let actual = get_output(program); // // assert_eq!(expected, actual.bytes().as_slice()); // } // // pub fn output_zero(program: EdwardsTestCompiler) { -// let expected = include_bytes!("outputs_/register_zero.out"); -// let actual = get_outputs(program); +// let expected = include_bytes!("output_/register_zero.out"); +// let actual = get_output(program); // // assert_eq!(expected, actual.bytes().as_slice()); // } diff --git a/compiler/tests/field/outputs_/register_one.out b/compiler/tests/field/output_/register_one.out similarity index 100% rename from compiler/tests/field/outputs_/register_one.out rename to compiler/tests/field/output_/register_one.out diff --git a/compiler/tests/field/outputs_/register_zero.out b/compiler/tests/field/output_/register_zero.out similarity index 100% rename from compiler/tests/field/outputs_/register_zero.out rename to compiler/tests/field/output_/register_zero.out diff --git a/compiler/tests/function/mod.rs b/compiler/tests/function/mod.rs index d9d40f45e6..15ba6d33a3 100644 --- a/compiler/tests/function/mod.rs +++ b/compiler/tests/function/mod.rs @@ -1,7 +1,7 @@ use crate::{ assert_satisfied, expect_compiler_error, - get_outputs, + get_output, parse_program, parse_program_with_input, EdwardsTestCompiler, @@ -56,9 +56,9 @@ fn test_multiple_returns_main() { 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 actual_bytes = get_outputs(program); + let actual_bytes = get_output(program); let actual = std::str::from_utf8(actual_bytes.bytes().as_slice()).unwrap(); assert_eq!(expected, actual); diff --git a/compiler/tests/function/outputs_/registers.out b/compiler/tests/function/output_/registers.out similarity index 100% rename from compiler/tests/function/outputs_/registers.out rename to compiler/tests/function/output_/registers.out diff --git a/compiler/tests/import/imports/bar/.gitignore b/compiler/tests/import/imports/bar/.gitignore index 17aa483ab4..ea1472ec1f 100755 --- a/compiler/tests/import/imports/bar/.gitignore +++ b/compiler/tests/import/imports/bar/.gitignore @@ -1 +1 @@ -outputs/ +output/ diff --git a/compiler/tests/import/imports/car/.gitignore b/compiler/tests/import/imports/car/.gitignore index 17aa483ab4..ea1472ec1f 100755 --- a/compiler/tests/import/imports/car/.gitignore +++ b/compiler/tests/import/imports/car/.gitignore @@ -1 +1 @@ -outputs/ +output/ diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index f6f6ccf7b6..e48a823edd 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -27,8 +27,7 @@ use snarkos_models::gadgets::r1cs::TestConstraintSystem; use std::path::PathBuf; -pub const TEST_OUTPUTS_DIRECTORY: &str = "/outputs/"; -pub const TEST_OUTPUTS_FILE_NAME: &str = "/outputs/test.out"; +pub const TEST_OUTPUT_DIRECTORY: &str = "/output/"; const EMPTY_FILE: &str = ""; pub type EdwardsTestCompiler = Compiler; @@ -37,9 +36,9 @@ pub type EdwardsConstrainedValue = ConstrainedValue; fn new_compiler() -> EdwardsTestCompiler { let program_name = "test".to_string(); 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 { @@ -129,7 +128,7 @@ pub fn parse_program_with_input_and_state( 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 let mut cs = TestConstraintSystem::::new(); 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) { - let empty_output_bytes = include_bytes!("compiler_outputs/empty.out"); - let res = get_outputs(program); + let empty_output_bytes = include_bytes!("compiler_output/empty.out"); + let res = get_output(program); // assert that the output is empty assert_eq!(empty_output_bytes, res.bytes().as_slice()); diff --git a/compiler/tests/statements/conditional/mod.rs b/compiler/tests/statements/conditional/mod.rs index edd77db414..7ffe8384b6 100644 --- a/compiler/tests/statements/conditional/mod.rs +++ b/compiler/tests/statements/conditional/mod.rs @@ -2,7 +2,7 @@ use crate::{ assert_satisfied, expect_synthesis_error, generate_main_input, - get_outputs, + get_output, parse_program, parse_program_with_input, EdwardsTestCompiler, @@ -216,15 +216,15 @@ fn test_nested() { } fn output_one(program: EdwardsTestCompiler) { - let expected = include_bytes!("outputs_/registers_one.out"); - let actual = get_outputs(program); + let expected = include_bytes!("output_/registers_one.out"); + let actual = get_output(program); assert_eq!(expected, actual.bytes().as_slice()); } fn output_zero(program: EdwardsTestCompiler) { - let expected = include_bytes!("outputs_/registers_zero.out"); - let actual = get_outputs(program); + let expected = include_bytes!("output_/registers_zero.out"); + let actual = get_output(program); assert_eq!(expected, actual.bytes().as_slice()); } diff --git a/compiler/tests/statements/conditional/outputs_/registers_one.out b/compiler/tests/statements/conditional/output_/registers_one.out similarity index 100% rename from compiler/tests/statements/conditional/outputs_/registers_one.out rename to compiler/tests/statements/conditional/output_/registers_one.out diff --git a/compiler/tests/statements/conditional/outputs_/registers_zero.out b/compiler/tests/statements/conditional/output_/registers_zero.out similarity index 100% rename from compiler/tests/statements/conditional/outputs_/registers_zero.out rename to compiler/tests/statements/conditional/output_/registers_zero.out diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 9b7eab4907..53bfa03b31 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -1,7 +1,7 @@ use crate::{ cli::*, cli_types::*, - directories::{source::SOURCE_DIRECTORY_NAME, OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, + directories::{source::SOURCE_DIRECTORY_NAME, OutputDirectory, OUTPUT_DIRECTORY_NAME}, errors::CLIError, files::{ChecksumFile, InputFile, LibFile, MainFile, Manifest, StateFile, LIB_FILE_NAME, MAIN_FILE_NAME}, }; @@ -47,9 +47,9 @@ impl CLI for BuildCommand { package_path.pop(); } - // Construct the path to the outputs directory - let mut outputs_directory = package_path.clone(); - outputs_directory.push(OUTPUTS_DIRECTORY_NAME); + // Construct the path to the output directory + let mut output_directory = package_path.clone(); + output_directory.push(OUTPUT_DIRECTORY_NAME); // Compile the package starting with the lib.leo file if LibFile::exists_at(&package_path) { @@ -62,7 +62,7 @@ impl CLI for BuildCommand { let _program = Compiler::::parse_program_without_input( package_name.clone(), lib_file_path.clone(), - outputs_directory.clone(), + output_directory.clone(), )?; log::info!("Compiled library file {:?}", lib_file_path); @@ -70,8 +70,8 @@ impl CLI for BuildCommand { // Compile the main.leo file along with constraints if MainFile::exists_at(&package_path) { - // Create the outputs directory - OutputsDirectory::create(&package_path)?; + // Create the output directory + OutputDirectory::create(&package_path)?; // Construct the path to the main file in the source directory let mut main_file_path = package_path.clone(); @@ -88,7 +88,7 @@ impl CLI for BuildCommand { let program = Compiler::::parse_program_with_input( package_name.clone(), main_file_path.clone(), - outputs_directory, + output_directory, &input_string, &state_string, )?; @@ -124,7 +124,7 @@ impl CLI for BuildCommand { // If checksum differs, compile the program 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)?; log::debug!("Checksum saved ({:?})", path); diff --git a/leo/commands/clean.rs b/leo/commands/clean.rs index 3c41690019..ec45d669d2 100644 --- a/leo/commands/clean.rs +++ b/leo/commands/clean.rs @@ -15,7 +15,7 @@ impl CLI for CleanCommand { type Options = (); type Output = (); - const ABOUT: AboutType = "Clean the outputs directory"; + const ABOUT: AboutType = "Clean the output directory"; const ARGUMENTS: &'static [ArgumentType] = &[]; const FLAGS: &'static [FlagType] = &[]; const NAME: NameType = "clean"; @@ -33,16 +33,16 @@ impl CLI for CleanCommand { let path = current_dir()?; 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)?; - // Remove the proving key from the outputs directory + // Remove the proving key from the output directory 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)?; - // Remove the proof from the outputs directory + // Remove the proof from the output directory ProofFile::new(&package_name).remove(&path)?; Ok(()) diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index 01319da4d3..9923da5758 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -52,7 +52,7 @@ impl CLI for ProveCommand { // Output the proving time 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![]; program_proof.write(&mut proof)?; ProofFile::new(&package_name).write_to(&path, &proof)?; diff --git a/leo/commands/publish.rs b/leo/commands/publish.rs index 90acbde86f..91cc096386 100644 --- a/leo/commands/publish.rs +++ b/leo/commands/publish.rs @@ -2,7 +2,7 @@ use crate::{ cli::*, cli_types::*, commands::BuildCommand, - directories::outputs::OutputsDirectory, + directories::output::OutputDirectory, errors::CLIError, files::{Manifest, ZipFile}, }; @@ -39,8 +39,8 @@ impl CLI for PublishCommand { let path = current_dir()?; let package_name = Manifest::try_from(&path)?.get_package_name(); - // Create the outputs directory - OutputsDirectory::create(&path)?; + // Create the output directory + OutputDirectory::create(&path)?; // Create zip file let zip_file = ZipFile::new(&package_name); diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index 09bbe16beb..9a99a4c94d 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -68,13 +68,13 @@ impl CLI for SetupCommand { log::info!("Setup completed in {:?} milliseconds", start.elapsed().as_millis()); // 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![]; proving_key.write(&mut proving_key_bytes)?; ProvingKeyFile::new(&package_name).write_to(&path, &proving_key_bytes)?; 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![]; proving_key.vk.write(&mut verification_key)?; VerificationKeyFile::new(&package_name).write_to(&path, &verification_key)?; @@ -84,11 +84,11 @@ impl CLI for SetupCommand { } else { 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 = Parameters::::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 = VerifyingKey::::read(verifying_key_bytes.as_slice())?; diff --git a/leo/commands/test.rs b/leo/commands/test.rs index 4b8c7fe8d3..a280d38a24 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -1,7 +1,7 @@ use crate::{ cli::*, cli_types::*, - directories::{outputs::OUTPUTS_DIRECTORY_NAME, source::SOURCE_DIRECTORY_NAME}, + directories::{output::OUTPUT_DIRECTORY_NAME, source::SOURCE_DIRECTORY_NAME}, errors::{CLIError, TestError}, 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(MAIN_FILE_NAME); - // Construct the path to the outputs directory; - let mut outputs_directory = package_path.clone(); - outputs_directory.push(OUTPUTS_DIRECTORY_NAME); + // Construct the path to the output directory; + let mut output_directory = package_path.clone(); + output_directory.push(OUTPUT_DIRECTORY_NAME); // Load the input file at `package_name` let input_string = InputFile::new(&package_name).read_from(&path)?; @@ -70,7 +70,7 @@ impl CLI for TestCommand { let program = Compiler::::parse_program_with_input( package_name.clone(), main_file_path.clone(), - outputs_directory, + output_directory, &input_string, &state_string, )?; diff --git a/leo/directories/mod.rs b/leo/directories/mod.rs index bcdf3dd48f..c6ad59e6c8 100644 --- a/leo/directories/mod.rs +++ b/leo/directories/mod.rs @@ -4,8 +4,8 @@ pub use self::imports::*; pub mod input; pub use self::input::*; -pub mod outputs; -pub use self::outputs::*; +pub mod output; +pub use self::output::*; pub mod source; pub use self::source::*; diff --git a/leo/directories/output.rs b/leo/directories/output.rs new file mode 100644 index 0000000000..783f3c98f5 --- /dev/null +++ b/leo/directories/output.rs @@ -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(()) + } +} diff --git a/leo/directories/outputs.rs b/leo/directories/outputs.rs deleted file mode 100644 index e876addb7d..0000000000 --- a/leo/directories/outputs.rs +++ /dev/null @@ -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(()) - } -} diff --git a/leo/errors/cli.rs b/leo/errors/cli.rs index 98760c2a3a..6602e86821 100644 --- a/leo/errors/cli.rs +++ b/leo/errors/cli.rs @@ -39,7 +39,7 @@ pub enum CLIError { NewError(NewError), #[error("{}", _0)] - OutputsDirectoryError(OutputsDirectoryError), + OutputDirectoryError(OutputDirectoryError), #[error("{}", _0)] ProofFileError(ProofFileError), @@ -143,10 +143,10 @@ impl From for CLIError { } } -impl From for CLIError { - fn from(error: OutputsDirectoryError) -> Self { +impl From for CLIError { + fn from(error: OutputDirectoryError) -> Self { log::error!("{}\n", error); - CLIError::OutputsDirectoryError(error) + CLIError::OutputDirectoryError(error) } } diff --git a/leo/errors/directory/mod.rs b/leo/errors/directory/mod.rs index bcdf3dd48f..c6ad59e6c8 100644 --- a/leo/errors/directory/mod.rs +++ b/leo/errors/directory/mod.rs @@ -4,8 +4,8 @@ pub use self::imports::*; pub mod input; pub use self::input::*; -pub mod outputs; -pub use self::outputs::*; +pub mod output; +pub use self::output::*; pub mod source; pub use self::source::*; diff --git a/leo/errors/directory/outputs.rs b/leo/errors/directory/output.rs similarity index 95% rename from leo/errors/directory/outputs.rs rename to leo/errors/directory/output.rs index 7742fff615..361143fcbf 100644 --- a/leo/errors/directory/outputs.rs +++ b/leo/errors/directory/output.rs @@ -1,7 +1,7 @@ use std::{ffi::OsString, fs::FileType, io}; #[derive(Debug, Error)] -pub enum OutputsDirectoryError { +pub enum OutputDirectoryError { #[error("creating: {}", _0)] Creating(io::Error), diff --git a/leo/files/checksum.rs b/leo/files/checksum.rs index a8d9053021..caafddcb84 100644 --- a/leo/files/checksum.rs +++ b/leo/files/checksum.rs @@ -1,6 +1,6 @@ //! 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 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(OUTPUTS_DIRECTORY_NAME) { - path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); + if !path.ends_with(OUTPUT_DIRECTORY_NAME) { + path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME)); } path.push(PathBuf::from(format!( "{}{}", diff --git a/leo/files/gitignore.rs b/leo/files/gitignore.rs index ae9be67cfd..41b92109a1 100644 --- a/leo/files/gitignore.rs +++ b/leo/files/gitignore.rs @@ -35,7 +35,7 @@ impl Gitignore { fn template(&self) -> String { format!( - r#"outputs/ + r#"output/ "#, ) } diff --git a/leo/files/proof.rs b/leo/files/proof.rs index 2353699ef8..aca7483e75 100644 --- a/leo/files/proof.rs +++ b/leo/files/proof.rs @@ -1,6 +1,6 @@ //! 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 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(OUTPUTS_DIRECTORY_NAME) { - path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); + if !path.ends_with(OUTPUT_DIRECTORY_NAME) { + path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME)); } path.push(PathBuf::from(format!("{}{}", self.package_name, PROOF_FILE_EXTENSION))); } diff --git a/leo/files/proving_key.rs b/leo/files/proving_key.rs index 4c62a5cea9..7015bb67a8 100644 --- a/leo/files/proving_key.rs +++ b/leo/files/proving_key.rs @@ -1,6 +1,6 @@ //! 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 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(OUTPUTS_DIRECTORY_NAME) { - path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); + if !path.ends_with(OUTPUT_DIRECTORY_NAME) { + path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME)); } path.push(PathBuf::from(format!( "{}{}", diff --git a/leo/files/verification_key.rs b/leo/files/verification_key.rs index 6087e2d999..407326e33d 100644 --- a/leo/files/verification_key.rs +++ b/leo/files/verification_key.rs @@ -1,6 +1,6 @@ //! 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 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(OUTPUTS_DIRECTORY_NAME) { - path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); + if !path.ends_with(OUTPUT_DIRECTORY_NAME) { + path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME)); } path.push(PathBuf::from(format!( "{}{}", diff --git a/leo/files/zip.rs b/leo/files/zip.rs index 99b5776765..f6fffde7b2 100644 --- a/leo/files/zip.rs +++ b/leo/files/zip.rs @@ -1,7 +1,7 @@ //! The program package zip file. use crate::{ - directories::{IMPORTS_DIRECTORY_NAME, INPUT_DIRECTORY_NAME, OUTPUTS_DIRECTORY_NAME}, + directories::{IMPORTS_DIRECTORY_NAME, INPUT_DIRECTORY_NAME, OUTPUT_DIRECTORY_NAME}, errors::ZipFileError, files::{ CHECKSUM_FILE_EXTENSION, @@ -99,8 +99,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(OUTPUTS_DIRECTORY_NAME) { - path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME)); + if !path.ends_with(OUTPUT_DIRECTORY_NAME) { + path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME)); } path.push(PathBuf::from(format!("{}{}", self.package_name, ZIP_FILE_EXTENSION))); } @@ -109,9 +109,9 @@ impl ZipFile { } 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("/")) - | 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("/")) { return true;