mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
More fixes
This commit is contained in:
parent
a23f31d0b7
commit
af0a016eed
@ -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,
|
||||
}
|
||||
);
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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)?;
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user