diff --git a/Cargo.lock b/Cargo.lock index 6c435d86..ebb38574 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -969,7 +969,7 @@ dependencies = [ [[package]] name = "dove" -version = "1.5.0" +version = "1.5.1" dependencies = [ "anyhow", "atty", diff --git a/dove/Cargo.toml b/dove/Cargo.toml index fa74648d..cb7790e2 100644 --- a/dove/Cargo.toml +++ b/dove/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dove" -version = "1.5.0" +version = "1.5.1" authors = [ "Alex Koz. ", "Dm. Yakushev ", @@ -49,42 +49,5 @@ lazy_static = "1.4.0" regex = "1.4.3" itertools = "0.9.0" -#http = "0.2" -#tiny-keccak = { version = "2.0.2", default-features = false, features = ["sha3"] } -#lang = { path = "../lang" } - -#bech32 = "0.7.2" -#once_cell = "1.4.0" -#walkdir = "2.3.1" -#fs_extra = "1.2.0" - -#itertools = "0.9.0" -#maplit = "1.0.2" -#serde_json = "1.0.52" -#git2 = "0.13" -#bcs = "0.1.2" -#dunce = "1.0.1" -#indexmap = { version = "=1.6.2", default-features = false, features = ["std"] } -#codespan-reporting = "0.8.0" - -#decompiler = { path = "../lang/decompiler" } -#net = { path = "../net" } - -#move-cli = { git = "https://github.com/pontem-network/diem.git", branch = "v1.5-pre" } -#move-core-types = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } -#move-lang = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } -#docgen = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } -#move-model = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } - - -#move-unit-test = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } -#move-vm-runtime = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } -#move-vm-types = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } -#diem-types = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } -#move-binary-format = { git = "https://github.com/pontem-network/diem.git", branch = "v1.3-r1" } -#diem-crypto-derive = { git = "https://github.com/pontem-network/diem.git", branch = "v1.5-pre" } -#diem-crypto = { git = "https://github.com/pontem-network/diem.git", branch = "v1.5-pre" } - - [features] default = [] diff --git a/dove/src/cli.rs b/dove/src/cli.rs index 35634468..33e927c6 100644 --- a/dove/src/cli.rs +++ b/dove/src/cli.rs @@ -22,7 +22,6 @@ use crate::cmd::init::Init; use crate::cmd::run::Run; use crate::cmd::test::Test; use crate::cmd::tx::CreateTransactionCmd; -use crate::manifest::HashU64; use crate::context::Context; const HASH_FILE_NAME: &str = ".version"; @@ -222,9 +221,9 @@ where CommonCommand::Dove(mut cmd) => { let mut ctx = cmd.context(cwd, move_args)?; - if move_toml_has_been_updated(&ctx) { + if !check_manifest_hash(&ctx) { run_internal_clean(&mut ctx)?; - update_move_toml_hash(&ctx)?; + store_manifest_checksum(&ctx)?; } cmd.apply(&mut ctx) } @@ -245,30 +244,32 @@ fn check_dove_version(req_ver: &str) -> Result<(), Error> { } /// Move.toml has been updated -fn move_toml_has_been_updated(ctx: &Context) -> bool { +fn check_manifest_hash(ctx: &Context) -> bool { let path_version = ctx.project_dir.join("build").join(HASH_FILE_NAME); if !path_version.exists() { - return true; + return false; } - let new_version = ctx.manifest.hash_u64(); + let old_version = fs::read_to_string(&path_version) .unwrap_or_default() .parse::() .unwrap_or_default(); - new_version != old_version + ctx.manifest_hash == old_version } /// Writing the hash move.toml to file -fn update_move_toml_hash(ctx: &Context) -> Result { - let hash = ctx.manifest.hash_u64(); +fn store_manifest_checksum(ctx: &Context) -> Result<()> { let build_path = ctx.project_dir.join("build"); if !build_path.exists() { fs::create_dir_all(&build_path)?; } let path_version = build_path.join(HASH_FILE_NAME); - fs::write(&path_version, hash.to_string())?; - Ok(hash) + if path_version.exists() { + fs::remove_file(&path_version)?; + } + fs::write(&path_version, ctx.manifest_hash.to_string())?; + Ok(()) } /// To display the full version of "Dove" diff --git a/dove/src/cmd/clean.rs b/dove/src/cmd/clean.rs index 7c382c50..a843b72e 100644 --- a/dove/src/cmd/clean.rs +++ b/dove/src/cmd/clean.rs @@ -37,6 +37,7 @@ impl Cmd for Clean { project_dir, move_args, manifest: default_sourcemanifest(), + manifest_hash: 0, }) } diff --git a/dove/src/cmd/mod.rs b/dove/src/cmd/mod.rs index 7663db2b..d3ad691b 100644 --- a/dove/src/cmd/mod.rs +++ b/dove/src/cmd/mod.rs @@ -1,6 +1,8 @@ use std::fs::read_to_string; use std::path::PathBuf; use std::collections::BTreeMap; +use std::collections::hash_map::DefaultHasher; +use std::hash::{Hash, Hasher}; use anyhow::Result; use dialect::init_context; use move_cli::Move; @@ -36,6 +38,9 @@ pub trait Cmd { init_context(move_args.dialect); let manifest_string = read_to_string(project_dir.join(layout::SourcePackageLayout::Manifest.path()))?; + let mut hasher = DefaultHasher::default(); + manifest_string.hash(&mut hasher); + let manifest_hash = hasher.finish(); let toml_manifest = manifest_parser::parse_move_manifest_string(manifest_string)?; let manifest = manifest_parser::parse_source_manifest(toml_manifest)?; @@ -43,6 +48,7 @@ pub trait Cmd { project_dir, move_args, manifest, + manifest_hash, }) } @@ -58,6 +64,7 @@ pub fn context_with_empty_manifest(project_dir: PathBuf, move_args: Move) -> Res move_args, // empty manifest manifest: default_sourcemanifest(), + manifest_hash: 0, }) } diff --git a/dove/src/context.rs b/dove/src/context.rs index cb35ff92..d477c79b 100644 --- a/dove/src/context.rs +++ b/dove/src/context.rs @@ -15,6 +15,8 @@ pub struct Context { pub move_args: Move, /// Project manifest. pub manifest: SourceManifest, + /// Manifest hash. + pub manifest_hash: u64, } impl Context {