Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
fixed build cache invalidation (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
RIg410 authored Dec 1, 2021
1 parent 3287564 commit e61a934
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 1 addition & 38 deletions dove/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dove"
version = "1.5.0"
version = "1.5.1"
authors = [
"Alex Koz. <[email protected]>",
"Dm. Yakushev <[email protected]>",
Expand Down Expand Up @@ -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 = []
23 changes: 12 additions & 11 deletions dove/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
}
Expand All @@ -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::<u64>()
.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<u64> {
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"
Expand Down
1 change: 1 addition & 0 deletions dove/src/cmd/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl Cmd for Clean {
project_dir,
move_args,
manifest: default_sourcemanifest(),
manifest_hash: 0,
})
}

Expand Down
7 changes: 7 additions & 0 deletions dove/src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,13 +38,17 @@ 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)?;

Ok(Context {
project_dir,
move_args,
manifest,
manifest_hash,
})
}

Expand All @@ -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,
})
}

Expand Down
2 changes: 2 additions & 0 deletions dove/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub struct Context {
pub move_args: Move,
/// Project manifest.
pub manifest: SourceManifest,
/// Manifest hash.
pub manifest_hash: u64,
}

impl Context {
Expand Down

0 comments on commit e61a934

Please sign in to comment.