|
1 | 1 | //! Tests for build.rs scripts.
|
2 | 2 |
|
3 |
| -use cargo_test_support::paths::CargoPathExt; |
| 3 | +use cargo_test_support::project_in_home; |
4 | 4 | use cargo_test_support::registry::Package;
|
5 | 5 | use cargo_test_support::{basic_manifest, cross_compile, is_coarse_mtime, project};
|
| 6 | +use cargo_test_support::{lines_match, paths::CargoPathExt}; |
6 | 7 | use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported};
|
7 | 8 | use cargo_util::paths::remove_dir_all;
|
8 | 9 | use std::env;
|
@@ -2602,6 +2603,98 @@ fn fresh_builds_possible_with_multiple_metadata_overrides() {
|
2602 | 2603 | .run();
|
2603 | 2604 | }
|
2604 | 2605 |
|
| 2606 | +#[cargo_test] |
| 2607 | +fn generate_good_d_files() { |
| 2608 | + // this is here to stop regression on an issue where build.rs rerun-if-changed paths aren't |
| 2609 | + // made absolute properly, which in turn interacts poorly with the dep-info-basedir setting, |
| 2610 | + // and the dep-info files have other-crate-relative paths spat out in them |
| 2611 | + let dep = project_in_home("awoo") |
| 2612 | + .file( |
| 2613 | + "Cargo.toml", |
| 2614 | + r#" |
| 2615 | + [project] |
| 2616 | + name = "awoo" |
| 2617 | + version = "0.5.0" |
| 2618 | + build = "build.rs" |
| 2619 | + "#, |
| 2620 | + ) |
| 2621 | + .file("src/lib.rs", "") |
| 2622 | + .file( |
| 2623 | + "build.rs", |
| 2624 | + r#" |
| 2625 | + fn main() { |
| 2626 | + println!("cargo:rerun-if-changed=build.rs"); |
| 2627 | + println!("cargo:rerun-if-changed=barkbarkbark"); |
| 2628 | + } |
| 2629 | + "#, |
| 2630 | + ) |
| 2631 | + .build(); |
| 2632 | + |
| 2633 | + let p = project_in_home("meow") |
| 2634 | + .file( |
| 2635 | + "Cargo.toml", |
| 2636 | + &format!( |
| 2637 | + r#" |
| 2638 | + [project] |
| 2639 | + name = "meow" |
| 2640 | + version = "0.5.0" |
| 2641 | + [dependencies] |
| 2642 | + awoo = {{ path = "{path}" }} |
| 2643 | + "#, |
| 2644 | + path = dep.root().to_str().unwrap(), |
| 2645 | + ), |
| 2646 | + ) |
| 2647 | + .file("src/main.rs", "fn main() {}") |
| 2648 | + .build(); |
| 2649 | + |
| 2650 | + p.cargo("build -v").run(); |
| 2651 | + |
| 2652 | + let dot_d_path = p.bin("meow").with_extension("d"); |
| 2653 | + println!("*meow at* {:?}", dot_d_path); |
| 2654 | + let dot_d = fs::read_to_string(&dot_d_path).unwrap(); |
| 2655 | + |
| 2656 | + println!("*.d file content*: {}", &dot_d); |
| 2657 | + |
| 2658 | + assert!( |
| 2659 | + lines_match( |
| 2660 | + "[..]/target/debug/meow: [..]/awoo/barkbarkbark [..]/awoo/build.rs[..]", |
| 2661 | + &dot_d |
| 2662 | + ) || lines_match( |
| 2663 | + "[..]/target/debug/meow: [..]/awoo/build.rs [..]/awoo/barkbarkbark[..]", |
| 2664 | + &dot_d |
| 2665 | + ) |
| 2666 | + ); |
| 2667 | + |
| 2668 | + // paths relative to dependency roots should not be allowed |
| 2669 | + assert!(!dot_d.split_whitespace().any(|v| v == "build.rs")); |
| 2670 | + |
| 2671 | + p.change_file( |
| 2672 | + ".cargo/config.toml", |
| 2673 | + r#" |
| 2674 | + [build] |
| 2675 | + dep-info-basedir="." |
| 2676 | + "#, |
| 2677 | + ); |
| 2678 | + p.cargo("build -v").run(); |
| 2679 | + |
| 2680 | + let dot_d = fs::read_to_string(&dot_d_path).unwrap(); |
| 2681 | + |
| 2682 | + println!("*.d file content with dep-info-basedir*: {}", &dot_d); |
| 2683 | + |
| 2684 | + assert!( |
| 2685 | + lines_match( |
| 2686 | + "target/debug/meow: [..]/awoo/barkbarkbark [..]/awoo/build.rs[..]", |
| 2687 | + &dot_d |
| 2688 | + ) || lines_match( |
| 2689 | + "target/debug/meow: [..]/awoo/build.rs [..]/awoo/barkbarkbark[..]", |
| 2690 | + &dot_d |
| 2691 | + ) |
| 2692 | + ); |
| 2693 | + |
| 2694 | + // paths relative to dependency roots should not be allowed |
| 2695 | + assert!(!dot_d.split_whitespace().any(|v| v == "build.rs")); |
| 2696 | +} |
| 2697 | + |
2605 | 2698 | #[cargo_test]
|
2606 | 2699 | fn rebuild_only_on_explicit_paths() {
|
2607 | 2700 | let p = project()
|
|
0 commit comments