forked from solana-foundation/surfpool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteel.rs
More file actions
43 lines (39 loc) · 1.39 KB
/
steel.rs
File metadata and controls
43 lines (39 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use anyhow::{Result, anyhow};
use txtx_core::kit::helpers::fs::FileLocation;
use super::{
ProgramMetadata,
utils::{CargoManifestFile, get_program_metadata_from_manifest_with_dep},
};
use crate::types::Framework;
/// This function attempts to load a program from a native project.
/// It looks for a `Cargo.toml` file in the specified base location.
/// If the `Cargo.toml` has a package with the `steel` dependency,
/// it is considered a native project.
pub fn try_get_programs_from_project(
base_location: FileLocation,
artifacts_path: Option<&str>,
) -> Result<Option<(Framework, Vec<ProgramMetadata>)>> {
let mut manifest_location = base_location.clone();
manifest_location
.append_path("Cargo.toml")
.map_err(|e| anyhow!("{e}"))?;
if manifest_location.exists() {
let manifest = manifest_location
.read_content_as_utf8()
.map_err(|e| anyhow!("{e}"))?;
let manifest = CargoManifestFile::from_manifest_str(&manifest)
.map_err(|e| anyhow!("unable to read Cargo.toml: {}", e))?;
let Some(program_metadata) = get_program_metadata_from_manifest_with_dep(
"steel",
&base_location,
&manifest,
artifacts_path,
)?
else {
return Ok(None);
};
Ok(Some((Framework::Steel, vec![program_metadata])))
} else {
Ok(None)
}
}