rebuild when the cargo.toml changes
This commit is contained in:
1 parent
b3d119b815
commit
cc983dc091
1 file changed
+28
-17
@@ -179,6 +179,27 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
|
|||||||
.map(|path| crate_dir.join(PathBuf::from(path)))
|
.map(|path| crate_dir.join(PathBuf::from(path)))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let rebuild = || {
|
||||||
|
if let Some(rebuild_command) = rebuild_with {
|
||||||
|
*aborted.lock().unwrap() = true;
|
||||||
|
if log {
|
||||||
|
println!("Rebuilding the application...");
|
||||||
|
}
|
||||||
|
execute::shell(rebuild_command)
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to rebuild the application. Is cargo installed?");
|
||||||
|
for channel in &mut *channels.lock().unwrap() {
|
||||||
|
send_msg(HotReloadMsg::Shutdown, channel);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if log {
|
||||||
|
println!(
|
||||||
|
"Rebuild needed... shutting down hot reloading.\nManually rebuild the application to view futher changes."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for evt in rx {
|
for evt in rx {
|
||||||
if chrono::Local::now().timestamp() > last_update_time {
|
if chrono::Local::now().timestamp() > last_update_time {
|
||||||
if let Ok(evt) = evt {
|
if let Ok(evt) = evt {
|
||||||
@@ -187,7 +208,7 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|path| {
|
.filter(|path| {
|
||||||
// skip non rust files
|
// skip non rust files
|
||||||
path.extension().and_then(|p| p.to_str()) == Some("rs") &&
|
matches!(path.extension().and_then(|p| p.to_str()), Some("rs" | "toml" | "css" | "html" | "js")) &&
|
||||||
// skip excluded paths
|
// skip excluded paths
|
||||||
!excluded_paths.iter().any(|p| path.starts_with(p))
|
!excluded_paths.iter().any(|p| path.starts_with(p))
|
||||||
})
|
})
|
||||||
@@ -200,6 +221,10 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
|
|||||||
|
|
||||||
let mut channels = channels.lock().unwrap();
|
let mut channels = channels.lock().unwrap();
|
||||||
for path in real_paths {
|
for path in real_paths {
|
||||||
|
// if this file type cannot be hot reloaded, rebuild the application
|
||||||
|
if path.extension().and_then(|p| p.to_str()) != Some("rs") {
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
// find changes to the rsx in the file
|
// find changes to the rsx in the file
|
||||||
match file_map
|
match file_map
|
||||||
.lock()
|
.lock()
|
||||||
@@ -223,22 +248,8 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateResult::NeedsRebuild => {
|
UpdateResult::NeedsRebuild => {
|
||||||
if let Some(rebuild_command) = rebuild_with {
|
drop(channels);
|
||||||
*aborted.lock().unwrap() = true;
|
rebuild();
|
||||||
if log {
|
|
||||||
println!("Rebuilding the application...");
|
|
||||||
}
|
|
||||||
execute::shell(rebuild_command).spawn().expect("Failed to rebuild the application. Is cargo installed?");
|
|
||||||
for channel in &mut *channels {
|
|
||||||
send_msg(HotReloadMsg::Shutdown, channel);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if log {
|
|
||||||
println!(
|
|
||||||
"Rebuild needed... shutting down hot reloading.\nManually rebuild the application to view futher changes."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user