From 8dde4786644343b7de89644582396f225988ed3e Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Fri, 15 Jul 2022 15:35:19 -0700 Subject: [PATCH] fix leo new --- .../src/code_generation/visit_expressions.rs | 2 +- leo/commands/new.rs | 25 +++++++++++++------ leo/package/src/package.rs | 9 +++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/compiler/passes/src/code_generation/visit_expressions.rs b/compiler/passes/src/code_generation/visit_expressions.rs index 32160815ed..32939c353f 100644 --- a/compiler/passes/src/code_generation/visit_expressions.rs +++ b/compiler/passes/src/code_generation/visit_expressions.rs @@ -162,7 +162,7 @@ impl<'a> CodeGenerator<'a> { format!("{}.{}", name, type_) } else { // foo; // no visibility for interfaces - name.to_string() + name } } else { unreachable!("All composite types should be known at this phase of compilation") diff --git a/leo/commands/new.rs b/leo/commands/new.rs index 979000c421..ac914a7220 100644 --- a/leo/commands/new.rs +++ b/leo/commands/new.rs @@ -18,7 +18,8 @@ use crate::{ commands::{Command, ALEO_CLI_COMMAND}, context::Context, }; -use leo_errors::{CliError, Result}; +use leo_errors::{CliError, PackageError, Result}; +use leo_package::build::BuildDirectory; use leo_package::package::Package; use aleo::commands::New as AleoNew; @@ -47,19 +48,27 @@ impl Command for New { fn apply(self, context: Context, _: Self::Input) -> Result { tracing::info!("Starting..."); + let path = context.dir()?; + + // Derive the program directory path. + let mut package_path = path.clone(); + package_path.push(&self.name); + + // Initialize the Leo package in the directory created by `aleo new`. + Package::initialize(&self.name, &package_path)?; + + // Create the Leo build/ directory + let build_directory = BuildDirectory::create(&path)?; + + // Change the cwd to the Leo build/ directory to compile aleo files. + std::env::set_current_dir(&build_directory) + .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?; // Call the `aleo new` command from the Aleo SDK. let command = AleoNew::try_parse_from(&[ALEO_CLI_COMMAND, &self.name]).map_err(CliError::failed_to_parse_aleo_new)?; let result = command.parse().map_err(CliError::failed_to_execute_aleo_new)?; - // Derive the program directory path. - let mut path = context.dir()?; - path.push(&self.name); - - // Initialize the Leo package in the directory created by `aleo new`. - Package::initialize(&self.name, &path)?; - // todo: modify the readme file to recommend building with `leo build`. // Log the output of the `aleo new` command. diff --git a/leo/package/src/package.rs b/leo/package/src/package.rs index 13509dab5d..4f9f770a2f 100644 --- a/leo/package/src/package.rs +++ b/leo/package/src/package.rs @@ -168,7 +168,7 @@ impl Package { // Create the source directory. SourceDirectory::create(path)?; - // Create the input directory. + // Create the inputs directory. InputsDirectory::create(path)?; // Create the input file in the inputs directory. @@ -176,11 +176,10 @@ impl Package { // Create the main file in the source directory. MainFile::new(package_name).write_to(path)?; + // Next, verify that a valid Leo package has been initialized in this directory - { - if !Self::is_initialized(package_name, path) { - return Err(PackageError::failed_to_initialize_package(package_name, path.as_os_str()).into()); - } + if !Self::is_initialized(package_name, path) { + return Err(PackageError::failed_to_initialize_package(package_name, path.as_os_str()).into()); } Ok(())