Skip to content

Commit

Permalink
Refactor with generic manifest trait (#5625)
Browse files Browse the repository at this point in the history
Follow up to #5477

#5477 (comment)

---------

Co-authored-by: Vaivaswatha Nagaraj <[email protected]>
Co-authored-by: Vaivaswatha N <[email protected]>
Co-authored-by: IGI-111 <[email protected]>
Co-authored-by: João Matos <[email protected]>
Co-authored-by: Joshua Batty <[email protected]>
Co-authored-by: Igor Rončević <[email protected]>
Co-authored-by: Sudhakar Verma <[email protected]>
Co-authored-by: Marcos Henrich <[email protected]>
Co-authored-by: jjcnn <[email protected]>
  • Loading branch information
10 people committed Feb 21, 2024
1 parent 6092210 commit 68191dd
Show file tree
Hide file tree
Showing 18 changed files with 226 additions and 194 deletions.
377 changes: 194 additions & 183 deletions forc-pkg/src/manifest/mod.rs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::manifest::GenericManifestFile;
use crate::{
lock::Lock,
manifest::{
Expand Down Expand Up @@ -579,7 +580,7 @@ impl BuildPlan {
std::env::current_dir()?
};

let manifest_file = ManifestFile::from_dir(&manifest_dir)?;
let manifest_file = ManifestFile::from_dir(manifest_dir)?;
let member_manifests = manifest_file.member_manifests()?;
// Check if we have members to build so that we are not trying to build an empty workspace.
if member_manifests.is_empty() {
Expand Down Expand Up @@ -2760,7 +2761,7 @@ mod test {
.parent()
.unwrap()
.join("test/src/e2e_vm_tests/test_programs/should_pass/forc/workspace_building/");
let manifest_file = ManifestFile::from_dir(&manifest_dir).unwrap();
let manifest_file = ManifestFile::from_dir(manifest_dir).unwrap();
let member_manifests = manifest_file.member_manifests().unwrap();
let lock_path = manifest_file.lock_path().unwrap();
BuildPlan::from_lock_and_manifests(
Expand Down
2 changes: 2 additions & 0 deletions forc-pkg/src/source/git/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod auth;

use crate::manifest::GenericManifestFile;
use crate::{
manifest::{self, PackageManifestFile},
source,
Expand Down
1 change: 1 addition & 0 deletions forc-pkg/src/source/ipfs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::manifest::GenericManifestFile;
use crate::{
manifest::{self, PackageManifestFile},
source,
Expand Down
1 change: 1 addition & 0 deletions forc-pkg/src/source/member.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::manifest::GenericManifestFile;
use crate::{manifest::PackageManifestFile, source};
use serde::{Deserialize, Serialize};
use std::{
Expand Down
1 change: 1 addition & 0 deletions forc-pkg/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod path;
mod reg;

use self::git::Url;
use crate::manifest::GenericManifestFile;
use crate::{
manifest::{self, MemberManifestFiles, PackageManifestFile},
pkg::{ManifestMap, PinnedId},
Expand Down
1 change: 1 addition & 0 deletions forc-pkg/src/source/path.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::manifest::GenericManifestFile;
use crate::{manifest::PackageManifestFile, pkg::PinnedId, source};
use serde::{Deserialize, Serialize};
use std::{
Expand Down
1 change: 1 addition & 0 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
},
};
use anyhow::{bail, Context, Result};
use forc_pkg::manifest::GenericManifestFile;
use forc_pkg::{self as pkg, PackageManifestFile};
use forc_tracing::println_warning;
use forc_util::default_output_directory;
Expand Down
4 changes: 2 additions & 2 deletions forc-plugins/forc-client/src/util/pkg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{collections::HashMap, path::Path, sync::Arc};

use anyhow::Result;
use forc_pkg::manifest::GenericManifestFile;
use forc_pkg::{self as pkg, manifest::ManifestFile, BuildOpts, BuildPlan};
use pkg::{build_with_options, BuiltPackage};
use std::{collections::HashMap, path::Path, sync::Arc};

pub(crate) fn built_pkgs(path: &Path, build_opts: BuildOpts) -> Result<Vec<Arc<BuiltPackage>>> {
let manifest_file = ManifestFile::from_dir(path)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::server::{AdapterError, DapServer};
use crate::types::Instruction;
use forc_pkg::manifest::GenericManifestFile;
use forc_pkg::{self, BuildProfile, Built, BuiltPackage, PackageManifestFile};
use forc_test::execute::TestExecutor;
use forc_test::setup::TestSetup;
Expand Down
3 changes: 2 additions & 1 deletion forc-plugins/forc-doc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use clap::Parser;
use cli::Command;
use colored::*;
use forc_pkg as pkg;
use forc_pkg::manifest::GenericManifestFile;
use forc_util::default_output_directory;
use include_dir::{include_dir, Dir};
use pkg::{manifest::ManifestFile, PackageManifestFile};
Expand Down Expand Up @@ -175,7 +176,7 @@ pub fn compile_html(
} else {
std::env::current_dir()?
};
let manifest = ManifestFile::from_dir(&dir)?;
let manifest = ManifestFile::from_dir(dir)?;
let pkg_manifest = if let ManifestFile::Package(pkg_manifest) = &manifest {
pkg_manifest
} else {
Expand Down
5 changes: 4 additions & 1 deletion forc-plugins/forc-fmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

use anyhow::{bail, Result};
use clap::Parser;
use forc_pkg::{manifest::ManifestFile, WorkspaceManifestFile};
use forc_pkg::{
manifest::{GenericManifestFile, ManifestFile},
WorkspaceManifestFile,
};
use prettydiff::{basic::DiffOp, diff_lines};
use std::{
default::Default,
Expand Down
3 changes: 2 additions & 1 deletion forc/src/ops/forc_check.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::cli::CheckCommand;
use anyhow::Result;
use forc_pkg as pkg;
use forc_pkg::manifest::GenericManifestFile;
use pkg::manifest::ManifestFile;
use std::path::PathBuf;
use sway_core::{language::ty, Engines};
Expand All @@ -22,7 +23,7 @@ pub fn check(command: CheckCommand, engines: &Engines) -> Result<(Option<ty::TyP
} else {
std::env::current_dir()?
};
let manifest_file = ManifestFile::from_dir(&this_dir)?;
let manifest_file = ManifestFile::from_dir(this_dir)?;
let member_manifests = manifest_file.member_manifests()?;
let lock_path = manifest_file.lock_path()?;
let plan = pkg::BuildPlan::from_lock_and_manifests(
Expand Down
3 changes: 2 additions & 1 deletion forc/src/ops/forc_clean.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::cli::CleanCommand;
use anyhow::{anyhow, bail, Result};
use forc_pkg::manifest::GenericManifestFile;
use forc_pkg::manifest::ManifestFile;
use forc_util::default_output_directory;
use std::path::PathBuf;
Expand All @@ -25,7 +26,7 @@ pub fn clean(command: CleanCommand) -> Result<()> {
)
}
};
let manifest = ManifestFile::from_dir(&manifest_dir)?;
let manifest = ManifestFile::from_dir(manifest_dir)?;
// If this is a workspace collect all member paths and clean each of them.
let paths: Vec<PathBuf> = match manifest {
ManifestFile::Package(_) => std::iter::once(this_dir).collect(),
Expand Down
3 changes: 2 additions & 1 deletion forc/src/ops/forc_update.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::cli::UpdateCommand;
use anyhow::{anyhow, Result};
use forc_pkg::manifest::GenericManifestFile;
use forc_pkg::{self as pkg, lock, Lock};
use forc_util::lock_path;
use pkg::manifest::ManifestFile;
Expand Down Expand Up @@ -33,7 +34,7 @@ pub async fn update(command: UpdateCommand) -> Result<()> {
None => std::env::current_dir()?,
};

let manifest = ManifestFile::from_dir(&this_dir)?;
let manifest = ManifestFile::from_dir(this_dir)?;
let lock_path = lock_path(manifest.dir());
let old_lock = Lock::from_path(&lock_path).ok().unwrap_or_default();
let offline = false;
Expand Down
7 changes: 5 additions & 2 deletions sway-lsp/src/core/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use lsp_types::{
TextDocumentContentChangeEvent, TextEdit, Url,
};
use parking_lot::RwLock;
use pkg::{manifest::ManifestFile, BuildPlan};
use pkg::{
manifest::{GenericManifestFile, ManifestFile},
BuildPlan,
};
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::{
path::PathBuf,
Expand Down Expand Up @@ -323,7 +326,7 @@ impl Session {
pub(crate) fn build_plan(uri: &Url) -> Result<BuildPlan, LanguageServerError> {
let manifest_dir = PathBuf::from(uri.path());
let manifest =
ManifestFile::from_dir(&manifest_dir).map_err(|_| DocumentError::ManifestFileNotFound {
ManifestFile::from_dir(manifest_dir).map_err(|_| DocumentError::ManifestFileNotFound {
dir: uri.path().into(),
})?;
let member_manifests =
Expand Down
1 change: 1 addition & 0 deletions sway-lsp/src/core/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
utils::document::{get_path_from_url, get_url_from_path, get_url_from_span},
};
use dashmap::DashMap;
use forc_pkg::manifest::GenericManifestFile;
use forc_pkg::{manifest::Dependency, PackageManifestFile};
use indexmap::IndexMap;
use lsp_types::Url;
Expand Down
1 change: 1 addition & 0 deletions sway-lsp/src/server_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
};
use crossbeam_channel::{Receiver, Sender};
use dashmap::DashMap;
use forc_pkg::manifest::GenericManifestFile;
use forc_pkg::PackageManifestFile;
use lsp_types::{Diagnostic, Url};
use parking_lot::RwLock;
Expand Down

0 comments on commit 68191dd

Please sign in to comment.