| @@ -10,6 +10,7 @@ use louise_package as package; |
| 10 | 10 | use louise_span::timings::Timings; |
| 11 | 11 | |
| 12 | 12 | use crate::compile::{Compiled, compile}; |
| 13 | +use crate::fingerprint::{self, Fingerprint}; |
| 13 | 14 | use crate::run::build_dir; |
| 14 | 15 | |
| 15 | 16 | /// What `louise test` is asked for. |
| @@ -241,7 +242,10 @@ fn in_package(path: &str, name: &str) -> bool { |
| 241 | 242 | /// One executable running every test (its index in `LOUISE_ENTRY`): |
| 242 | 243 | /// `test/<name>-tests` in the program's build directory, so that a second |
| 243 | 244 | /// run reuses the objects (issue #113), and named apart from the program |
| 244 | | −/// so that their objects don't collide. |
| 245 | +/// so that their objects don't collide. When nothing it is built from has |
| 246 | +/// changed since, it is reused as it is, without generating or linking |
| 247 | +/// anything ([`Fingerprint`], issue #316); the tests it runs are part of |
| 248 | +/// the key, so another `--filter` builds again. |
| 245 | 249 | fn build_tests( |
| 246 | 250 | compiled: &Compiled, |
| 247 | 251 | tests: &[(&String, louise_core::Test)], |
| @@ -262,14 +266,10 @@ fn build_tests( |
| 262 | 266 | .map(|(_, t)| louise_core::runnable(&analysis.hir, &analysis.typeck, program, t.def)) |
| 263 | 267 | .collect::<Result<Vec<_>, _>>() |
| 264 | 268 | .map_err(fail)?; |
| 265 | | − let units = louise_build::default_units(false); |
| 266 | | − let c = louise_codegen_c::generate_units(program, &entries, Some(db.sources()), units, timings) |
| 267 | | − .map_err(|e| fail(e.to_string()))?; |
| 268 | 269 | let opts = louise_build::CcOptions { |
| 269 | 270 | natives: loaded.natives(), |
| 270 | 271 | ..Default::default() |
| 271 | 272 | }; |
| 272 | | − let c: Vec<(&str, &str)> = c.iter().map(|(n, t)| (n.as_str(), t.as_str())).collect(); |
| 273 | 273 | let build = build_dir(loaded, None, true).map_err(fail)?; |
| 274 | 274 | let name = match &loaded.package { |
| 275 | 275 | Some(package) => package.root().name.clone(), |
| @@ -281,8 +281,36 @@ fn build_tests( |
| 281 | 281 | .to_owned(), |
| 282 | 282 | }; |
| 283 | 283 | let exe = build.join("test").join(format!("{name}-tests")); |
| 284 | | − louise_build::build_executable_timed(&c, &exe, &build, &opts, timings) |
| 284 | + let units = louise_build::default_units(false); |
| 285 | + let dir = louise_build::BuildDir::lock(&build).map_err(|e| fail(e.to_string()))?; |
| 286 | + let entry = tests |
| 287 | + .iter() |
| 288 | + .map(|(m, t)| format!("{m}.{}", t.name)) |
| 289 | + .collect::<Vec<_>>() |
| 290 | + .join(" "); |
| 291 | + let fingerprint = timings.time("fingerprint", || { |
| 292 | + Fingerprint::new( |
| 293 | + dir.path(), |
| 294 | + &fingerprint::Program { |
| 295 | + db, |
| 296 | + loaded, |
| 297 | + entry: &format!("tests: {entry}"), |
| 298 | + units, |
| 299 | + opts: &opts, |
| 300 | + output: &exe, |
| 301 | + }, |
| 302 | + ) |
| 303 | + }); |
| 304 | + if fingerprint.fresh(&exe) { |
| 305 | + return Ok(exe); |
| 306 | + } |
| 307 | + fingerprint.forget(); |
| 308 | + let c = louise_codegen_c::generate_units(program, &entries, Some(db.sources()), units, timings) |
| 285 | 309 | .map_err(|e| fail(e.to_string()))?; |
| 310 | + let c: Vec<(&str, &str)> = c.iter().map(|(n, t)| (n.as_str(), t.as_str())).collect(); |
| 311 | + let built = |
| 312 | + louise_build::build_in(&c, &exe, &dir, &opts, timings).map_err(|e| fail(e.to_string()))?; |
| 313 | + fingerprint.record(&exe, &built); |
| 286 | 314 | Ok(exe) |
| 287 | 315 | } |
| 288 | 316 | |