Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
enhancement: rebuild when manifest changed (#1338)
Browse files Browse the repository at this point in the history
rebuild when manifest changed
  • Loading branch information
lostman authored Sep 8, 2023
1 parent 30af796 commit c08f41a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion plugins/forc-index/src/ops/forc_index_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)?;

Expand Down
23 changes: 14 additions & 9 deletions plugins/forc-index/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,35 +150,40 @@ 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 = {
let metadata = std::fs::metadata(schema).unwrap();
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(())
Expand Down

0 comments on commit c08f41a

Please sign in to comment.