More fixes

This commit is contained in:
Pranav Gaddamadugu 2024-05-31 19:38:38 -07:00
parent a23f31d0b7
commit af0a016eed
6 changed files with 29 additions and 10 deletions

View File

@ -397,4 +397,11 @@ create_messages!(
msg: "The name of the program to execute on-chain is missing.".to_string(),
help: Some("Either set `--local` to execute the local program on chain, or set `--program <PROGRAM>`.".to_string()),
}
@backtraced
failed_to_read_manifest_file {
args: (path: impl Display, error: impl ErrorArg),
msg: format!("Failed to read manifest file from the provided file path {path} - {error}"),
help: None,
}
);

View File

@ -123,7 +123,7 @@ impl Command for Add {
manifest.license(),
Some(dependencies),
);
new_manifest.write_to_dir(path)?;
new_manifest.write_to_dir(&path)?;
Ok(())
}

View File

@ -20,16 +20,19 @@ use leo_ast::Stub;
use leo_compiler::{Compiler, CompilerOptions, OutputOptions};
use leo_errors::UtilError;
use leo_package::{build::BuildDirectory, outputs::OutputsDirectory, source::SourceDirectory};
use leo_retriever::{NetworkName, Retriever};
use leo_retriever::{Manifest, NetworkName, Retriever};
use leo_span::Symbol;
use snarkvm::{package::Package, prelude::ProgramID};
use snarkvm::{
package::Package,
prelude::{MainnetV0, Network, ProgramID, TestnetV0},
};
use indexmap::IndexMap;
use snarkvm::prelude::{MainnetV0, Network, TestnetV0};
use std::{
io::Write,
path::{Path, PathBuf},
str::FromStr,
};
impl From<BuildOptions> for CompilerOptions {
@ -108,8 +111,8 @@ fn handle_build<N: Network>(command: &Build, context: Context) -> Result<<Build
let build_directory = BuildDirectory::create(&package_path)?;
// Get the program id.
let manifest = context.open_manifest::<N>()?;
let program_id = manifest.program_id();
let manifest = Manifest::read_from_dir(&package_path)?;
let program_id = ProgramID::<N>::from_str(manifest.program())?;
// Initialize error handler
let handler = Handler::default();

View File

@ -104,7 +104,7 @@ impl Command for Remove {
manifest.license(),
Some(dependencies),
);
new_manifest.write_to_dir(path)?;
new_manifest.write_to_dir(&path)?;
Ok(())
}

View File

@ -152,7 +152,7 @@ impl Package {
// Create a manifest.
let manifest = Manifest::default(package_name);
manifest.write_to_dir(path.to_path_buf())?;
manifest.write_to_dir(&path)?;
// Create the source directory.
SourceDirectory::create(&path)?;

View File

@ -17,7 +17,7 @@
use crate::Dependency;
use leo_errors::PackageError;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::path::Path;
// Struct representation of program's `program.json` specification
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -76,11 +76,20 @@ impl Manifest {
&self.dependencies
}
pub fn write_to_dir(&self, path: PathBuf) -> Result<(), PackageError> {
pub fn write_to_dir(&self, path: &Path) -> Result<(), PackageError> {
// Serialize the manifest to a JSON string.
let contents = serde_json::to_string_pretty(&self)
.map_err(|err| PackageError::failed_to_serialize_manifest_file(path.to_str().unwrap(), err))?;
// Write the manifest to the file.
std::fs::write(path.join("program.json"), contents).map_err(PackageError::failed_to_write_manifest)
}
pub fn read_from_dir(path: &Path) -> Result<Self, PackageError> {
// Read the manifest file.
let contents = std::fs::read_to_string(path.join("program.json"))
.map_err(|err| PackageError::failed_to_read_file(path.to_str().unwrap(), err))?;
// Deserialize the manifest.
serde_json::from_str(&contents)
.map_err(|err| PackageError::failed_to_deserialize_manifest_file(path.to_str().unwrap(), err))
}
}