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