From c08f41a75f55034543b9ea07a442dae34113e67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wo=C5=9B?= Date: Fri, 8 Sep 2023 17:14:40 +0200 Subject: [PATCH] enhancement: rebuild when manifest changed (#1338) rebuild when manifest changed --- .../forc-index/src/ops/forc_index_build.rs | 3 ++- plugins/forc-index/src/utils.rs | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/forc-index/src/ops/forc_index_build.rs b/plugins/forc-index/src/ops/forc_index_build.rs index b2d0526b3..90e78c4cc 100644 --- a/plugins/forc-index/src/ops/forc_index_build.rs +++ b/plugins/forc-index/src/ops/forc_index_build.rs @@ -85,9 +85,10 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> { }; // Rebuild the WASM module even if only the schema has changed. - crate::utils::ensure_rebuild_if_schema_changed( + crate::utils::ensure_rebuild_if_schema_or_manifest_changed( root_dir.as_path(), Path::new(manifest_schema_file.as_path()), + indexer_manifest_path.as_path(), manifest.execution_source(), )?; diff --git a/plugins/forc-index/src/utils.rs b/plugins/forc-index/src/utils.rs index 6fe64c104..3d0422050 100644 --- a/plugins/forc-index/src/utils.rs +++ b/plugins/forc-index/src/utils.rs @@ -150,9 +150,10 @@ pub fn touch_file(path: &Path) -> std::io::Result<()> { /// Set src/lib.rs' atime and mtime to now and thus ensure the WASM module is /// rebuilt if schema file has changed. -pub fn ensure_rebuild_if_schema_changed( +pub fn ensure_rebuild_if_schema_or_manifest_changed( project_dir: &Path, schema: &Path, + manifest: &Path, exec_source: ExecutionSource, ) -> std::io::Result<()> { let schema_mtime = { @@ -160,25 +161,29 @@ pub fn ensure_rebuild_if_schema_changed( filetime::FileTime::from_last_modification_time(&metadata) }; - let sourcefile = match exec_source { - ExecutionSource::Native => "main.rs", - ExecutionSource::Wasm => "lib.rs", + let manifest_mtime = { + let metadata = std::fs::metadata(manifest).unwrap(); + filetime::FileTime::from_last_modification_time(&metadata) }; - let lib_rs = { + let entrypoint_rs = { + let sourcefile = match exec_source { + ExecutionSource::Native => "main.rs", + ExecutionSource::Wasm => "lib.rs", + }; let mut path = project_dir.to_owned(); path.push("src"); path.push(sourcefile); path }; - let lib_rs_mtime = { - let metadata = std::fs::metadata(lib_rs.as_path()).unwrap(); + let entrypoint_rs_mtime = { + let metadata = std::fs::metadata(entrypoint_rs.as_path()).unwrap(); filetime::FileTime::from_last_modification_time(&metadata) }; - if schema_mtime > lib_rs_mtime { - touch_file(lib_rs.as_path())?; + if schema_mtime > entrypoint_rs_mtime || manifest_mtime > entrypoint_rs_mtime { + touch_file(entrypoint_rs.as_path())?; } Ok(())