Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect rerun-if-changed triggering needless rebuilds #115

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ futures = "0.3"

[build-dependencies]
fs_extra = "1.3"
glob = "0.3"

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
Expand Down
32 changes: 7 additions & 25 deletions rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ use std::path::{Path, PathBuf};
use std::{env, fs};

use fs_extra::dir::CopyOptions;
use glob::glob;

// This is the version of the jar that should be used
const VERSION: &str = "0.20.0-SNAPSHOT";
const JAVA_FX_VERSION: &str = "21.0.2";

fn main() -> Result<(), J4rsBuildError> {
// ensure build.rs is not rerun when there are no `rerun-if-*` printed
println!("cargo:rerun-if-changed=build.rs");

let out_dir = env::var("OUT_DIR")?;
let source_jar_location = PathBuf::from(format!(
"../java/target/j4rs-{VERSION}-jar-with-dependencies.jar"
Expand All @@ -46,7 +48,7 @@ fn main() -> Result<(), J4rsBuildError> {
// Copy the needed jar files if they are available
// (that is, if the build is done with the full source-code - not in crates.io)
copy_jars_from_java(&source_jar_location)?;
let _ = copy_jars_to_exec_directory(&out_dir)?;
copy_jars_to_exec_directory(&out_dir)?;
generate_src(&out_dir)?;

Ok(())
Expand Down Expand Up @@ -103,8 +105,8 @@ fn are_same_files(path1: &Path, path2: &Path) -> Result<bool, J4rsBuildError> {
Ok(std::fs::read(path1)? == std::fs::read(path2)?)
}

// Copies the jars to and returns the PathBuf of the exec directory.
fn copy_jars_to_exec_directory(out_dir: &str) -> Result<PathBuf, J4rsBuildError> {
// Copies the jars to the exec directory.
fn copy_jars_to_exec_directory(out_dir: &str) -> Result<(), J4rsBuildError> {
let mut exec_dir_path_buf = PathBuf::from(out_dir);
exec_dir_path_buf.pop();
exec_dir_path_buf.pop();
Expand Down Expand Up @@ -134,11 +136,7 @@ fn copy_jars_to_exec_directory(out_dir: &str) -> Result<PathBuf, J4rsBuildError>
fs_extra::copy_items(&[jassets_path], jassets_output_dir, &CopyOptions::new())?;
}

let jassets_output_files = glob(&format!("{jassets_output_dir}/jassets/**/*"))?;
for glob_res in jassets_output_files {
println!("cargo:rerun-if-changed={}", glob_res?.to_str().unwrap());
}
Ok(exec_dir_path_buf)
Ok(())
}

#[derive(Debug)]
Expand Down Expand Up @@ -181,19 +179,3 @@ impl From<fs_extra::error::Error> for J4rsBuildError {
}
}
}

impl From<glob::PatternError> for J4rsBuildError {
fn from(err: glob::PatternError) -> J4rsBuildError {
J4rsBuildError {
description: format!("{:?}", err),
}
}
}

impl From<glob::GlobError> for J4rsBuildError {
fn from(err: glob::GlobError) -> J4rsBuildError {
J4rsBuildError {
description: format!("{:?}", err),
}
}
}
Loading