about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAmos Wenger <amoswenger@gmail.com>2022-07-20 16:14:53 +0200
committerAmos Wenger <amoswenger@gmail.com>2022-07-20 16:16:29 +0200
commita88e088fa782820c7a594bbdff2eae011f5f286d (patch)
tree935e9b09d5413504f5ca99466451656d08928abb
parentbd4439fafafb778f9d287f7369218c744381e8cd (diff)
downloadrust-a88e088fa782820c7a594bbdff2eae011f5f286d.tar.gz
rust-a88e088fa782820c7a594bbdff2eae011f5f286d.zip
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)
-rw-r--r--crates/proc-macro-test/build.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/crates/proc-macro-test/build.rs b/crates/proc-macro-test/build.rs
index 767a790437e..8e13563c14e 100644
--- a/crates/proc-macro-test/build.rs
+++ b/crates/proc-macro-test/build.rs
@@ -17,9 +17,25 @@ fn main() {
 
     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("staging");
+    std::fs::create_dir_all(&staging_dir).unwrap();
+    std::fs::create_dir_all(staging_dir.join("src")).unwrap();
+
+    for item_els in [&["Cargo.toml"][..], &["Cargo.lock"], &["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);
+        }
+        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 +45,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()) {