Refactor manifest handling around forc-pkg to accommodate workspace manifest files (#2894)

This commit is contained in:
Kaya Gökalp 2022-10-07 11:51:53 +03:00 committed by GitHub
parent 4e9a5ae61a
commit c27135ffee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 164 additions and 60 deletions

View file

@ -9,7 +9,9 @@ pub mod manifest;
mod pkg; mod pkg;
pub use lock::Lock; pub use lock::Lock;
pub use manifest::{BuildProfile, Manifest, ManifestFile}; pub use manifest::{
BuildProfile, PackageManifest, PackageManifestFile, WorkspaceManifest, WorkspaceManifestFile,
};
#[doc(inline)] #[doc(inline)]
pub use pkg::*; pub use pkg::*;

View file

@ -14,11 +14,11 @@ use sway_utils::constants;
type PatchMap = BTreeMap<String, Dependency>; type PatchMap = BTreeMap<String, Dependency>;
/// A [Manifest] that was deserialized from a file at a particular path. /// A [PackageManifest] that was deserialized from a file at a particular path.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ManifestFile { pub struct PackageManifestFile {
/// The deserialized `Forc.toml`. /// The deserialized `Forc.toml`.
manifest: Manifest, manifest: PackageManifest,
/// The path from which the `Forc.toml` file was read. /// The path from which the `Forc.toml` file was read.
path: PathBuf, path: PathBuf,
} }
@ -26,7 +26,7 @@ pub struct ManifestFile {
/// A direct mapping to a `Forc.toml`. /// A direct mapping to a `Forc.toml`.
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
pub struct Manifest { pub struct PackageManifest {
pub project: Project, pub project: Project,
pub network: Option<Network>, pub network: Option<Network>,
pub dependencies: Option<BTreeMap<String, Dependency>>, pub dependencies: Option<BTreeMap<String, Dependency>>,
@ -103,8 +103,8 @@ impl Dependency {
} }
} }
impl ManifestFile { impl PackageManifestFile {
/// Given a path to a `Forc.toml`, read it and construct a `Manifest`. /// Given a path to a `Forc.toml`, read it and construct a `PackageManifest`.
/// ///
/// This also `validate`s the manifest, returning an `Err` in the case that invalid names, /// This also `validate`s the manifest, returning an `Err` in the case that invalid names,
/// fields were used. /// fields were used.
@ -114,14 +114,14 @@ impl ManifestFile {
/// specify the pinned commit at which we fetch `std`. /// specify the pinned commit at which we fetch `std`.
pub fn from_file(path: PathBuf) -> Result<Self> { pub fn from_file(path: PathBuf) -> Result<Self> {
let path = path.canonicalize()?; let path = path.canonicalize()?;
let manifest = Manifest::from_file(&path)?; let manifest = PackageManifest::from_file(&path)?;
Ok(Self { manifest, path }) Ok(Self { manifest, path })
} }
/// Read the manifest from the `Forc.toml` in the directory specified by the given `path` or /// Read the manifest from the `Forc.toml` in the directory specified by the given `path` or
/// any of its parent directories. /// any of its parent directories.
/// ///
/// This is short for `Manifest::from_file`, but takes care of constructing the path to the /// This is short for `PackageManifest::from_file`, but takes care of constructing the path to the
/// file. /// file.
pub fn from_dir(manifest_dir: &Path) -> Result<Self> { pub fn from_dir(manifest_dir: &Path) -> Result<Self> {
let dir = forc_util::find_manifest_dir(manifest_dir) let dir = forc_util::find_manifest_dir(manifest_dir)
@ -130,7 +130,7 @@ impl ManifestFile {
Self::from_file(path) Self::from_file(path)
} }
/// Validate the `Manifest`. /// Validate the `PackageManifest`.
/// ///
/// This checks the project and organization names against a set of reserved/restricted /// This checks the project and organization names against a set of reserved/restricted
/// keywords and patterns, and if a given entry point exists. /// keywords and patterns, and if a given entry point exists.
@ -166,7 +166,7 @@ impl ManifestFile {
.expect("failed to retrieve manifest directory") .expect("failed to retrieve manifest directory")
} }
/// Given the directory in which the file associated with this `Manifest` resides, produce the /// Given the directory in which the file associated with this `PackageManifest` resides, produce the
/// path to the entry file as specified in the manifest. /// path to the entry file as specified in the manifest.
/// ///
/// This will always be a canonical path. /// This will always be a canonical path.
@ -232,10 +232,10 @@ impl ManifestFile {
} }
} }
impl Manifest { impl PackageManifest {
pub const DEFAULT_ENTRY_FILE_NAME: &'static str = "main.sw"; pub const DEFAULT_ENTRY_FILE_NAME: &'static str = "main.sw";
/// Given a path to a `Forc.toml`, read it and construct a `Manifest`. /// Given a path to a `Forc.toml`, read it and construct a `PackageManifest`.
/// ///
/// This also `validate`s the manifest, returning an `Err` in the case that invalid names, /// This also `validate`s the manifest, returning an `Err` in the case that invalid names,
/// fields were used. /// fields were used.
@ -258,7 +258,7 @@ impl Manifest {
Ok(manifest) Ok(manifest)
} }
/// Validate the `Manifest`. /// Validate the `PackageManifest`.
/// ///
/// This checks the project and organization names against a set of reserved/restricted /// This checks the project and organization names against a set of reserved/restricted
/// keywords and patterns. /// keywords and patterns.
@ -272,7 +272,7 @@ impl Manifest {
/// Given a directory to a forc project containing a `Forc.toml`, read the manifest. /// Given a directory to a forc project containing a `Forc.toml`, read the manifest.
/// ///
/// This is short for `Manifest::from_file`, but takes care of constructing the path to the /// This is short for `PackageManifest::from_file`, but takes care of constructing the path to the
/// file. /// file.
pub fn from_dir(dir: &Path) -> Result<Self> { pub fn from_dir(dir: &Path) -> Result<Self> {
let manifest_dir = find_manifest_dir(dir).ok_or_else(|| manifest_file_missing(dir))?; let manifest_dir = find_manifest_dir(dir).ok_or_else(|| manifest_file_missing(dir))?;
@ -422,8 +422,8 @@ impl BuildProfile {
} }
} }
impl std::ops::Deref for ManifestFile { impl std::ops::Deref for PackageManifestFile {
type Target = Manifest; type Target = PackageManifest;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.manifest &self.manifest
} }
@ -440,7 +440,7 @@ fn implicit_std_dep() -> Dependency {
// Here, we use the `forc-pkg` crate version formatted with the `v` prefix (e.g. "v1.2.3"), // Here, we use the `forc-pkg` crate version formatted with the `v` prefix (e.g. "v1.2.3"),
// or the revision commit hash (e.g. "abcdefg"). // or the revision commit hash (e.g. "abcdefg").
// //
// This git tag or revision is used during `Manifest` construction to pin the version of the // This git tag or revision is used during `PackageManifest` construction to pin the version of the
// implicit `std` dependency to the `forc-pkg` version. // implicit `std` dependency to the `forc-pkg` version.
// //
// This is important to ensure that the version of `sway-core` that is baked into `forc-pkg` is // This is important to ensure that the version of `sway-core` that is baked into `forc-pkg` is
@ -474,9 +474,104 @@ fn implicit_std_dep() -> Dependency {
} }
fn default_entry() -> String { fn default_entry() -> String {
Manifest::DEFAULT_ENTRY_FILE_NAME.to_string() PackageManifest::DEFAULT_ENTRY_FILE_NAME.to_string()
} }
fn default_url() -> String { fn default_url() -> String {
constants::DEFAULT_NODE_URL.into() constants::DEFAULT_NODE_URL.into()
} }
/// A [WorkspaceManifest] that was deserialized from a file at a particular path.
#[derive(Clone, Debug)]
pub struct WorkspaceManifestFile {
/// The derserialized `Forc.toml`
manifest: WorkspaceManifest,
/// The path from which the `Forc.toml` file was read.
path: PathBuf,
}
/// A direct mapping to `Forc.toml` if it is a WorkspaceManifest
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct WorkspaceManifest {
pub members: Vec<String>,
}
impl WorkspaceManifestFile {
/// Given a path to a `Forc.toml`, read it and construct a `PackageManifest`
///
/// This also `validate`s the manifest, returning an `Err` in the case that given members are
/// not present in the manifest dir.
pub fn from_file(path: PathBuf) -> Result<Self> {
let path = path.canonicalize()?;
let parent = path
.parent()
.ok_or_else(|| anyhow!("Cannot get parent dir of {:?}", path))?;
let manifest = WorkspaceManifest::from_file(&path)?;
manifest.validate(parent)?;
Ok(Self { manifest, path })
}
/// Read the manifest from the `Forc.toml` in the directory specified by the given `path` or
/// any of its parent directories.
///
/// This is short for `PackageManifest::from_file`, but takes care of constructing the path to the
/// file.
pub fn from_dir(manifest_dir: &Path) -> Result<Self> {
let dir = forc_util::find_manifest_dir(manifest_dir)
.ok_or_else(|| manifest_file_missing(manifest_dir))?;
let path = dir.join(constants::MANIFEST_FILE_NAME);
Self::from_file(path)
}
pub fn members(&self) -> impl Iterator<Item = &String> + '_ {
self.members.iter()
}
pub fn member_paths(&self) -> Result<impl Iterator<Item = PathBuf> + '_> {
let parent = self
.path
.parent()
.ok_or_else(|| anyhow!("Cannot get parent dir of {:?}", self.path))?;
Ok(self.members.iter().map(|member| parent.join(member)))
}
}
impl WorkspaceManifest {
/// Given a path to a `Forc.toml`, read it and construct a `WorkspaceManifest`.
pub fn from_file(path: &Path) -> Result<Self> {
let manifest_str = std::fs::read_to_string(path)
.map_err(|e| anyhow!("failed to read manifest at {:?}: {}", path, e))?;
let toml_de = &mut toml::de::Deserializer::new(&manifest_str);
let manifest: Self = serde_ignored::deserialize(toml_de, |path| {
let warning = format!(" WARNING! unused manifest key: {}", path);
println_yellow_err(&warning);
})
.map_err(|e| anyhow!("failed to parse manifest: {}.", e))?;
Ok(manifest)
}
/// Validate the `WorkspaceManifest`
///
/// This checks if the listed members in the `WorkspaceManifest` are indeed in the given `Forc.toml`'s directory.
pub fn validate(&self, path: &Path) -> Result<()> {
for member in self.members.iter() {
let member_path = path.join(&member).join("Forc.toml");
if !member_path.exists() {
bail!(
"{:?} is listed as a member of the workspace but {:?} does not exists",
&member,
member_path
);
}
}
Ok(())
}
}
impl std::ops::Deref for WorkspaceManifestFile {
type Target = WorkspaceManifest;
fn deref(&self) -> &Self::Target {
&self.manifest
}
}

View file

@ -1,6 +1,8 @@
use crate::{ use crate::{
lock::Lock, lock::Lock,
manifest::{BuildProfile, ConfigTimeConstant, Dependency, Manifest, ManifestFile}, manifest::{
BuildProfile, ConfigTimeConstant, Dependency, PackageManifest, PackageManifestFile,
},
CORE, PRELUDE, STD, CORE, PRELUDE, STD,
}; };
use anyhow::{anyhow, bail, Context, Error, Result}; use anyhow::{anyhow, bail, Context, Error, Result};
@ -40,7 +42,7 @@ type Edge = DependencyName;
pub type Graph = petgraph::stable_graph::StableGraph<Node, Edge, Directed, GraphIx>; pub type Graph = petgraph::stable_graph::StableGraph<Node, Edge, Directed, GraphIx>;
pub type EdgeIx = petgraph::graph::EdgeIndex<GraphIx>; pub type EdgeIx = petgraph::graph::EdgeIndex<GraphIx>;
pub type NodeIx = petgraph::graph::NodeIndex<GraphIx>; pub type NodeIx = petgraph::graph::NodeIndex<GraphIx>;
pub type ManifestMap = HashMap<PinnedId, ManifestFile>; pub type ManifestMap = HashMap<PinnedId, PackageManifestFile>;
/// A unique ID for a pinned package. /// A unique ID for a pinned package.
/// ///
@ -243,7 +245,7 @@ impl BuildPlan {
/// Create a new build plan for the project by fetching and pinning all dependenies. /// Create a new build plan for the project by fetching and pinning all dependenies.
/// ///
/// To account for an existing lock file, use `from_lock_and_manifest` instead. /// To account for an existing lock file, use `from_lock_and_manifest` instead.
pub fn from_manifest(manifest: &ManifestFile, offline: bool) -> Result<Self> { pub fn from_manifest(manifest: &PackageManifestFile, offline: bool) -> Result<Self> {
// Check toolchain version // Check toolchain version
validate_version(manifest)?; validate_version(manifest)?;
let mut graph = Graph::default(); let mut graph = Graph::default();
@ -260,11 +262,11 @@ impl BuildPlan {
}) })
} }
/// Create a new build plan taking into account the state of both the Manifest and the existing /// Create a new build plan taking into account the state of both the PackageManifest and the existing
/// lock file if there is one. /// lock file if there is one.
/// ///
/// This will first attempt to load a build plan from the lock file and validate the resulting /// This will first attempt to load a build plan from the lock file and validate the resulting
/// graph using the current state of the Manifest. /// graph using the current state of the PackageManifest.
/// ///
/// This includes checking if the [dependencies] or [patch] tables have changed and checking /// This includes checking if the [dependencies] or [patch] tables have changed and checking
/// the validity of the local path dependencies. If any changes are detected, the graph is /// the validity of the local path dependencies. If any changes are detected, the graph is
@ -277,7 +279,7 @@ impl BuildPlan {
// the manifest alongside some lock diff type that can be used to optionally write the updated // the manifest alongside some lock diff type that can be used to optionally write the updated
// lock file and print the diff. // lock file and print the diff.
pub fn from_lock_and_manifest( pub fn from_lock_and_manifest(
manifest: &ManifestFile, manifest: &PackageManifestFile,
locked: bool, locked: bool,
offline: bool, offline: bool,
) -> Result<Self> { ) -> Result<Self> {
@ -401,7 +403,7 @@ fn find_proj_node(graph: &Graph, proj_name: &str) -> Result<NodeIx> {
/// ///
/// If required minimum forc version is higher than current forc version return an error with /// If required minimum forc version is higher than current forc version return an error with
/// upgrade instructions /// upgrade instructions
fn validate_version(pkg_manifest: &ManifestFile) -> Result<()> { fn validate_version(pkg_manifest: &PackageManifestFile) -> Result<()> {
match &pkg_manifest.project.forc_version { match &pkg_manifest.project.forc_version {
Some(min_forc_version) => { Some(min_forc_version) => {
// Get the current version of the toolchain // Get the current version of the toolchain
@ -425,7 +427,7 @@ fn validate_version(pkg_manifest: &ManifestFile) -> Result<()> {
/// Validates the state of the pinned package graph against the given project manifest. /// Validates the state of the pinned package graph against the given project manifest.
/// ///
/// Returns the set of invalid dependency edges. /// Returns the set of invalid dependency edges.
fn validate_graph(graph: &Graph, proj_manifest: &ManifestFile) -> BTreeSet<EdgeIx> { fn validate_graph(graph: &Graph, proj_manifest: &PackageManifestFile) -> BTreeSet<EdgeIx> {
// If we don't have a project node, remove everything as we can't validate dependencies // If we don't have a project node, remove everything as we can't validate dependencies
// without knowing where to start. // without knowing where to start.
let proj_node = match find_proj_node(graph, &proj_manifest.project.name) { let proj_node = match find_proj_node(graph, &proj_manifest.project.name) {
@ -443,7 +445,7 @@ fn validate_graph(graph: &Graph, proj_manifest: &ManifestFile) -> BTreeSet<EdgeI
fn validate_deps( fn validate_deps(
graph: &Graph, graph: &Graph,
node: NodeIx, node: NodeIx,
node_manifest: &ManifestFile, node_manifest: &PackageManifestFile,
visited: &mut HashSet<NodeIx>, visited: &mut HashSet<NodeIx>,
) -> BTreeSet<EdgeIx> { ) -> BTreeSet<EdgeIx> {
let mut remove = BTreeSet::default(); let mut remove = BTreeSet::default();
@ -471,10 +473,10 @@ fn validate_deps(
/// Returns the `ManifestFile` in the case that the dependency is valid. /// Returns the `ManifestFile` in the case that the dependency is valid.
fn validate_dep( fn validate_dep(
graph: &Graph, graph: &Graph,
node_manifest: &ManifestFile, node_manifest: &PackageManifestFile,
dep_name: &str, dep_name: &str,
dep_node: NodeIx, dep_node: NodeIx,
) -> Result<ManifestFile> { ) -> Result<PackageManifestFile> {
// Check the validity of the dependency path, including its path root. // Check the validity of the dependency path, including its path root.
let dep_path = dep_path(graph, node_manifest, dep_name, dep_node).map_err(|e| { let dep_path = dep_path(graph, node_manifest, dep_name, dep_node).map_err(|e| {
anyhow!( anyhow!(
@ -485,7 +487,7 @@ fn validate_dep(
})?; })?;
// Ensure the manifest is accessible. // Ensure the manifest is accessible.
let dep_manifest = ManifestFile::from_dir(&dep_path)?; let dep_manifest = PackageManifestFile::from_dir(&dep_path)?;
// Check that the dependency's source matches the entry in the parent manifest. // Check that the dependency's source matches the entry in the parent manifest.
let dep_entry = node_manifest let dep_entry = node_manifest
@ -502,7 +504,7 @@ fn validate_dep(
Ok(dep_manifest) Ok(dep_manifest)
} }
/// Part of dependency validation, any checks related to the depenency's manifest content. /// Part of dependency validation, any checks related to the depenency's manifest content.
fn validate_dep_manifest(dep: &Pinned, dep_manifest: &ManifestFile) -> Result<()> { fn validate_dep_manifest(dep: &Pinned, dep_manifest: &PackageManifestFile) -> Result<()> {
// Ensure that the dependency is a library. // Ensure that the dependency is a library.
if !matches!(dep_manifest.program_type()?, TreeType::Library { .. }) { if !matches!(dep_manifest.program_type()?, TreeType::Library { .. }) {
bail!( bail!(
@ -531,7 +533,7 @@ fn validate_dep_manifest(dep: &Pinned, dep_manifest: &ManifestFile) -> Result<()
/// invalid. /// invalid.
fn dep_path( fn dep_path(
graph: &Graph, graph: &Graph,
node_manifest: &ManifestFile, node_manifest: &PackageManifestFile,
dep_name: &str, dep_name: &str,
dep_node: NodeIx, dep_node: NodeIx,
) -> Result<PathBuf> { ) -> Result<PathBuf> {
@ -930,7 +932,7 @@ pub fn compilation_order(graph: &Graph) -> Result<Vec<NodeIx>> {
/// manifest of for every node in the graph. /// manifest of for every node in the graph.
/// ///
/// Assumes the given `graph` only contains valid dependencies (see `validate_graph`). /// Assumes the given `graph` only contains valid dependencies (see `validate_graph`).
fn graph_to_manifest_map(proj_manifest: ManifestFile, graph: &Graph) -> Result<ManifestMap> { fn graph_to_manifest_map(proj_manifest: PackageManifestFile, graph: &Graph) -> Result<ManifestMap> {
let mut manifest_map = ManifestMap::new(); let mut manifest_map = ManifestMap::new();
// Traverse the graph from the project node. // Traverse the graph from the project node.
@ -965,7 +967,7 @@ fn graph_to_manifest_map(proj_manifest: ManifestFile, graph: &Graph) -> Result<M
e e
) )
})?; })?;
let dep_manifest = ManifestFile::from_dir(&dep_path)?; let dep_manifest = PackageManifestFile::from_dir(&dep_path)?;
let dep = &graph[dep_node]; let dep = &graph[dep_node];
manifest_map.insert(dep.id(), dep_manifest); manifest_map.insert(dep.id(), dep_manifest);
} }
@ -1038,7 +1040,7 @@ pub fn fetch_id(path: &Path, timestamp: std::time::Instant) -> u64 {
/// ///
/// Upon success, returns the set of nodes that were added to the graph during traversal. /// Upon success, returns the set of nodes that were added to the graph during traversal.
fn fetch_graph( fn fetch_graph(
proj_manifest: &ManifestFile, proj_manifest: &PackageManifestFile,
offline: bool, offline: bool,
graph: &mut Graph, graph: &mut Graph,
manifest_map: &mut ManifestMap, manifest_map: &mut ManifestMap,
@ -1307,7 +1309,7 @@ fn pin_pkg(
let source = SourcePinned::Root; let source = SourcePinned::Root;
let pinned = Pinned { name, source }; let pinned = Pinned { name, source };
let id = pinned.id(); let id = pinned.id();
let manifest = ManifestFile::from_dir(path)?; let manifest = PackageManifestFile::from_dir(path)?;
manifest_map.insert(id, manifest); manifest_map.insert(id, manifest);
pinned pinned
} }
@ -1316,7 +1318,7 @@ fn pin_pkg(
let source = SourcePinned::Path(path_pinned); let source = SourcePinned::Path(path_pinned);
let pinned = Pinned { name, source }; let pinned = Pinned { name, source };
let id = pinned.id(); let id = pinned.id();
let manifest = ManifestFile::from_dir(path)?; let manifest = PackageManifestFile::from_dir(path)?;
manifest_map.insert(id, manifest); manifest_map.insert(id, manifest);
pinned pinned
} }
@ -1393,7 +1395,7 @@ fn pin_pkg(
pinned_git.to_string() pinned_git.to_string()
) )
})?; })?;
let manifest = ManifestFile::from_dir(&path)?; let manifest = PackageManifestFile::from_dir(&path)?;
entry.insert(manifest); entry.insert(manifest);
} }
pinned pinned
@ -1644,7 +1646,7 @@ fn dep_to_source(pkg_path: &Path, dep: &Dependency) -> Result<Source> {
/// If a patch exists for the given dependency source within the given project manifest, this /// If a patch exists for the given dependency source within the given project manifest, this
/// returns the patch. /// returns the patch.
fn dep_source_patch<'manifest>( fn dep_source_patch<'manifest>(
manifest: &'manifest ManifestFile, manifest: &'manifest PackageManifestFile,
dep_name: &str, dep_name: &str,
dep_source: &Source, dep_source: &Source,
) -> Option<&'manifest Dependency> { ) -> Option<&'manifest Dependency> {
@ -1662,7 +1664,11 @@ fn dep_source_patch<'manifest>(
/// `Source` with the patch applied. /// `Source` with the patch applied.
/// ///
/// If no patch exists, this returns the original `Source`. /// If no patch exists, this returns the original `Source`.
fn apply_patch(manifest: &ManifestFile, dep_name: &str, dep_source: &Source) -> Result<Source> { fn apply_patch(
manifest: &PackageManifestFile,
dep_name: &str,
dep_source: &Source,
) -> Result<Source> {
match dep_source_patch(manifest, dep_name, dep_source) { match dep_source_patch(manifest, dep_name, dep_source) {
Some(patch) => dep_to_source(manifest.dir(), patch), Some(patch) => dep_to_source(manifest.dir(), patch),
None => Ok(dep_source.clone()), None => Ok(dep_source.clone()),
@ -1672,7 +1678,7 @@ fn apply_patch(manifest: &ManifestFile, dep_name: &str, dep_source: &Source) ->
/// Converts the `Dependency` to a `Source` with any relevant patches in the given manifest /// Converts the `Dependency` to a `Source` with any relevant patches in the given manifest
/// applied. /// applied.
fn dep_to_source_patched( fn dep_to_source_patched(
manifest: &ManifestFile, manifest: &PackageManifestFile,
dep_name: &str, dep_name: &str,
dep: &Dependency, dep: &Dependency,
) -> Result<Source> { ) -> Result<Source> {
@ -1799,7 +1805,7 @@ fn find_core_dep(graph: &Graph, node: NodeIx) -> Option<NodeIx> {
/// Compiles the package to an AST. /// Compiles the package to an AST.
pub fn compile_ast( pub fn compile_ast(
manifest: &ManifestFile, manifest: &PackageManifestFile,
build_profile: &BuildProfile, build_profile: &BuildProfile,
namespace: namespace::Module, namespace: namespace::Module,
) -> Result<CompileResult<TyProgram>> { ) -> Result<CompileResult<TyProgram>> {
@ -1830,7 +1836,7 @@ pub fn compile_ast(
/// Scripts and Predicates will be compiled to bytecode and will not emit any JSON ABI. /// Scripts and Predicates will be compiled to bytecode and will not emit any JSON ABI.
pub fn compile( pub fn compile(
pkg: &Pinned, pkg: &Pinned,
manifest: &ManifestFile, manifest: &PackageManifestFile,
build_profile: &BuildProfile, build_profile: &BuildProfile,
namespace: namespace::Module, namespace: namespace::Module,
source_map: &mut SourceMap, source_map: &mut SourceMap,
@ -2047,7 +2053,7 @@ pub fn build_with_options(build_options: BuildOptions) -> Result<Compiled> {
std::env::current_dir()? std::env::current_dir()?
}; };
let manifest = ManifestFile::from_dir(&this_dir)?; let manifest = PackageManifestFile::from_dir(&this_dir)?;
let plan = BuildPlan::from_lock_and_manifest(&manifest, locked, offline_mode)?; let plan = BuildPlan::from_lock_and_manifest(&manifest, locked, offline_mode)?;
@ -2391,7 +2397,7 @@ pub fn check(
/// Returns a parsed AST from the supplied [ManifestFile] /// Returns a parsed AST from the supplied [ManifestFile]
pub fn parse( pub fn parse(
manifest: &ManifestFile, manifest: &PackageManifestFile,
terse_mode: bool, terse_mode: bool,
) -> anyhow::Result<CompileResult<ParseProgram>> { ) -> anyhow::Result<CompileResult<ParseProgram>> {
let profile = BuildProfile { let profile = BuildProfile {
@ -2413,7 +2419,7 @@ pub fn find_within(dir: &Path, pkg_name: &str) -> Option<PathBuf> {
.filter(|entry| entry.path().ends_with(constants::MANIFEST_FILE_NAME)) .filter(|entry| entry.path().ends_with(constants::MANIFEST_FILE_NAME))
.find_map(|entry| { .find_map(|entry| {
let path = entry.path(); let path = entry.path();
let manifest = Manifest::from_file(path).ok()?; let manifest = PackageManifest::from_file(path).ok()?;
if manifest.project.name == pkg_name { if manifest.project.name == pkg_name {
Some(path.to_path_buf()) Some(path.to_path_buf())
} else { } else {

View file

@ -1,5 +1,5 @@
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use forc_pkg::{BuildOptions, Compiled, ManifestFile}; use forc_pkg::{BuildOptions, Compiled, PackageManifestFile};
use fuel_crypto::Signature; use fuel_crypto::Signature;
use fuel_gql_client::client::FuelClient; use fuel_gql_client::client::FuelClient;
use fuel_tx::{Output, Salt, StorageSlot, Transaction}; use fuel_tx::{Output, Salt, StorageSlot, Transaction};
@ -20,7 +20,7 @@ pub async fn deploy(command: DeployCommand) -> Result<fuel_tx::ContractId> {
} else { } else {
std::env::current_dir()? std::env::current_dir()?
}; };
let manifest = ManifestFile::from_dir(&curr_dir)?; let manifest = PackageManifestFile::from_dir(&curr_dir)?;
manifest.check_program_type(vec![TreeType::Contract])?; manifest.check_program_type(vec![TreeType::Contract])?;
let DeployCommand { let DeployCommand {

View file

@ -1,5 +1,5 @@
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, bail, Result};
use forc_pkg::{fuel_core_not_running, BuildOptions, ManifestFile}; use forc_pkg::{fuel_core_not_running, BuildOptions, PackageManifestFile};
use fuel_crypto::Signature; use fuel_crypto::Signature;
use fuel_gql_client::client::FuelClient; use fuel_gql_client::client::FuelClient;
use fuel_tx::{AssetId, Output, Transaction, Witness}; use fuel_tx::{AssetId, Output, Transaction, Witness};
@ -21,7 +21,7 @@ pub async fn run(command: RunCommand) -> Result<Vec<fuel_tx::Receipt>> {
} else { } else {
std::env::current_dir().map_err(|e| anyhow!("{:?}", e))? std::env::current_dir().map_err(|e| anyhow!("{:?}", e))?
}; };
let manifest = ManifestFile::from_dir(&path_dir)?; let manifest = PackageManifestFile::from_dir(&path_dir)?;
manifest.check_program_type(vec![TreeType::Script])?; manifest.check_program_type(vec![TreeType::Script])?;
let input_data = &command.data.unwrap_or_else(|| "".into()); let input_data = &command.data.unwrap_or_else(|| "".into());

View file

@ -1,6 +1,6 @@
use crate::cli::CheckCommand; use crate::cli::CheckCommand;
use anyhow::Result; use anyhow::Result;
use forc_pkg::{self as pkg, ManifestFile}; use forc_pkg::{self as pkg, PackageManifestFile};
use std::path::PathBuf; use std::path::PathBuf;
use sway_core::CompileResult; use sway_core::CompileResult;
@ -17,7 +17,7 @@ pub fn check(command: CheckCommand) -> Result<CompileResult<sway_core::TyProgram
} else { } else {
std::env::current_dir()? std::env::current_dir()?
}; };
let manifest = ManifestFile::from_dir(&this_dir)?; let manifest = PackageManifestFile::from_dir(&this_dir)?;
let plan = pkg::BuildPlan::from_lock_and_manifest(&manifest, locked, offline)?; let plan = pkg::BuildPlan::from_lock_and_manifest(&manifest, locked, offline)?;
Ok(pkg::check(&plan, terse_mode)?.flat_map(|(_, tp)| CompileResult::new(tp, vec![], vec![]))) Ok(pkg::check(&plan, terse_mode)?.flat_map(|(_, tp)| CompileResult::new(tp, vec![], vec![])))

View file

@ -2,7 +2,7 @@ use crate::cli::TemplateCommand;
use crate::utils::defaults; use crate::utils::defaults;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use forc_pkg::{ use forc_pkg::{
fetch_git, fetch_id, find_dir_within, git_commit_path, pin_git, Manifest, SourceGit, fetch_git, fetch_id, find_dir_within, git_commit_path, pin_git, PackageManifest, SourceGit,
}; };
use forc_util::validate_name; use forc_util::validate_name;
use fs_extra::dir::{copy, CopyOptions}; use fs_extra::dir::{copy, CopyOptions};
@ -55,7 +55,7 @@ pub fn init(command: TemplateCommand) -> Result<()> {
})?, })?,
None => { None => {
let manifest_path = repo_path.join(constants::MANIFEST_FILE_NAME); let manifest_path = repo_path.join(constants::MANIFEST_FILE_NAME);
if Manifest::from_file(&manifest_path).is_err() { if PackageManifest::from_file(&manifest_path).is_err() {
anyhow::bail!("failed to find a template in {}", command.url); anyhow::bail!("failed to find a template in {}", command.url);
} }
repo_path repo_path

View file

@ -1,6 +1,6 @@
use crate::cli::UpdateCommand; use crate::cli::UpdateCommand;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use forc_pkg::{self as pkg, lock, Lock, ManifestFile}; use forc_pkg::{self as pkg, lock, Lock, PackageManifestFile};
use forc_util::lock_path; use forc_util::lock_path;
use std::{fs, path::PathBuf}; use std::{fs, path::PathBuf};
use tracing::info; use tracing::info;
@ -32,7 +32,7 @@ pub async fn update(command: UpdateCommand) -> Result<()> {
None => std::env::current_dir()?, None => std::env::current_dir()?,
}; };
let manifest = ManifestFile::from_dir(&this_dir)?; let manifest = PackageManifestFile::from_dir(&this_dir)?;
let lock_path = lock_path(manifest.dir()); let lock_path = lock_path(manifest.dir());
let old_lock = Lock::from_path(&lock_path).ok().unwrap_or_default(); let old_lock = Lock::from_path(&lock_path).ok().unwrap_or_default();
let offline = false; let offline = false;

View file

@ -157,7 +157,8 @@ fn parse_default_manifest() {
use sway_utils::constants::MAIN_ENTRY; use sway_utils::constants::MAIN_ENTRY;
tracing::info!( tracing::info!(
"{:#?}", "{:#?}",
toml::from_str::<forc_pkg::Manifest>(&default_manifest("test_proj", MAIN_ENTRY)).unwrap() toml::from_str::<forc_pkg::PackageManifest>(&default_manifest("test_proj", MAIN_ENTRY))
.unwrap()
) )
} }
@ -165,6 +166,6 @@ fn parse_default_manifest() {
fn parse_default_tests_manifest() { fn parse_default_tests_manifest() {
tracing::info!( tracing::info!(
"{:#?}", "{:#?}",
toml::from_str::<forc_pkg::Manifest>(&default_tests_manifest("test_proj")).unwrap() toml::from_str::<forc_pkg::PackageManifest>(&default_tests_manifest("test_proj")).unwrap()
) )
} }

View file

@ -147,7 +147,7 @@ impl Session {
let offline = false; let offline = false;
// TODO: match on any errors and report them back to the user in a future PR // TODO: match on any errors and report them back to the user in a future PR
if let Ok(manifest) = pkg::ManifestFile::from_dir(&manifest_dir) { if let Ok(manifest) = pkg::PackageManifestFile::from_dir(&manifest_dir) {
if let Ok(plan) = pkg::BuildPlan::from_lock_and_manifest(&manifest, locked, offline) { if let Ok(plan) = pkg::BuildPlan::from_lock_and_manifest(&manifest, locked, offline) {
//we can then use them directly to convert them to a Vec<Diagnostic> //we can then use them directly to convert them to a Vec<Diagnostic>
if let Ok(CompileResult { if let Ok(CompileResult {