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

@ -1,6 +1,6 @@
use crate::cli::CheckCommand;
use anyhow::Result;
use forc_pkg::{self as pkg, ManifestFile};
use forc_pkg::{self as pkg, PackageManifestFile};
use std::path::PathBuf;
use sway_core::CompileResult;
@ -17,7 +17,7 @@ pub fn check(command: CheckCommand) -> Result<CompileResult<sway_core::TyProgram
} else {
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)?;
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 anyhow::{anyhow, Context, Result};
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 fs_extra::dir::{copy, CopyOptions};
@ -55,7 +55,7 @@ pub fn init(command: TemplateCommand) -> Result<()> {
})?,
None => {
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);
}
repo_path

View file

@ -1,6 +1,6 @@
use crate::cli::UpdateCommand;
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 std::{fs, path::PathBuf};
use tracing::info;
@ -32,7 +32,7 @@ pub async fn update(command: UpdateCommand) -> Result<()> {
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 old_lock = Lock::from_path(&lock_path).ok().unwrap_or_default();
let offline = false;

View file

@ -157,7 +157,8 @@ fn parse_default_manifest() {
use sway_utils::constants::MAIN_ENTRY;
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() {
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()
)
}