about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-20 15:21:03 +0000
committerbors <bors@rust-lang.org>2022-07-20 15:21:03 +0000
commit7dc36eeb781fcf35a69bb1a75e7005397a9da418 (patch)
tree4567dcef4a2e32f7dce9fc781d4b3e20b6142c3a
parentbd4439fafafb778f9d287f7369218c744381e8cd (diff)
parent844aa8b53e47934e30bff1ba9f70a0986874ae97 (diff)
downloadrust-7dc36eeb781fcf35a69bb1a75e7005397a9da418.tar.gz
rust-7dc36eeb781fcf35a69bb1a75e7005397a9da418.zip
Auto merge of #12831 - fasterthanlime:proc-macro-test-in-tmp-dir, r=fasterthanlime
Build proc-macro-test-impl out-of-tree

Building it in-place fails in rust CI because the source directory is read-only. This changes `proc-macro-test`'s build script to first
copy `imp` under `OUT_DIR` (which is read-write).

It also prints stdout/stderr for the nested cargo invocation, should it fail. (I've seen failures in rust CI that I couldn't explain, and
when they take 25 minutes to reproduce, you want to have that info)

This change is tracked in:

  * https://github.com/rust-lang/rust-analyzer/issues/12818

Maintainer impact: none.
-rw-r--r--crates/proc-macro-test/build.rs40
1 files changed, 38 insertions, 2 deletions
diff --git a/crates/proc-macro-test/build.rs b/crates/proc-macro-test/build.rs
index 767a790437e..c6bd5160d4d 100644
--- a/crates/proc-macro-test/build.rs
+++ b/crates/proc-macro-test/build.rs
@@ -12,14 +12,43 @@ use std::{
 use cargo_metadata::Message;
 
 fn main() {
+    println!("cargo:rerun-if-changed=imp");
+
     let out_dir = env::var_os("OUT_DIR").unwrap();
     let out_dir = Path::new(&out_dir);
 
     let name = "proc-macro-test-impl";
     let version = "0.0.0";
+
+    let imp_dir = std::env::current_dir().unwrap().join("imp");
+
+    let staging_dir = out_dir.join("proc-macro-test-imp-staging");
+    // this'll error out if the staging dir didn't previously exist. using
+    // `std::fs::exists` would suffer from TOCTOU so just do our best to
+    // wipe it and ignore errors.
+    let _ = std::fs::remove_dir_all(&staging_dir);
+
+    println!("Creating {}", staging_dir.display());
+    std::fs::create_dir_all(&staging_dir).unwrap();
+
+    let src_dir = staging_dir.join("src");
+    println!("Creating {}", src_dir.display());
+    std::fs::create_dir_all(src_dir).unwrap();
+
+    for item_els in [&["Cargo.toml"][..], &["src", "lib.rs"]] {
+        let mut src = imp_dir.clone();
+        let mut dst = staging_dir.clone();
+        for el in item_els {
+            src.push(el);
+            dst.push(el);
+        }
+        println!("Copying {} to {}", src.display(), dst.display());
+        std::fs::copy(src, dst).unwrap();
+    }
+
     let target_dir = out_dir.join("target");
     let output = Command::new(toolchain::cargo())
-        .current_dir("imp")
+        .current_dir(&staging_dir)
         .args(&["build", "-p", "proc-macro-test-impl", "--message-format", "json"])
         // Explicit override the target directory to avoid using the same one which the parent
         // cargo is using, or we'll deadlock.
@@ -29,7 +58,14 @@ fn main() {
         .arg(&target_dir)
         .output()
         .unwrap();
-    assert!(output.status.success());
+    if !output.status.success() {
+        println!("proc-macro-test-impl failed to build");
+        println!("============ stdout ============");
+        println!("{}", String::from_utf8_lossy(&output.stdout));
+        println!("============ stderr ============");
+        println!("{}", String::from_utf8_lossy(&output.stderr));
+        panic!("proc-macro-test-impl failed to build");
+    }
 
     let mut artifact_path = None;
     for message in Message::parse_stream(output.stdout.as_slice()) {