Move vendor directory to out/

The android_bp crate, not surprisingly, contains an example Android.bp
file. If we run "cargo vendor" and put the downloaded crates inside
the Android source tree, then Soong sees this Android.bp, tries to make
sense of it, and, of course, fails.

Bug: http://b/339424309
Test: treehugger
Change-Id: Iefed78745d3bffa655fdeb495336a623bf8361b4
diff --git a/tools/external_crates/crate_tool/src/pseudo_crate.rs b/tools/external_crates/crate_tool/src/pseudo_crate.rs
index 485b3ca..ee0ce67 100644
--- a/tools/external_crates/crate_tool/src/pseudo_crate.rs
+++ b/tools/external_crates/crate_tool/src/pseudo_crate.rs
@@ -15,6 +15,7 @@
 use std::{
     cell::OnceCell,
     collections::BTreeMap,
+    env,
     fs::{read, write},
     io::BufRead,
     process::Command,
@@ -103,13 +104,21 @@
     }
     fn crates(&self) -> &CrateCollection {
         self.extra.crates.get_or_init(|| {
+            let out_dir = env::var("OUT_DIR").unwrap_or("out".to_string());
+            let vendor_dir = self
+                .get_path()
+                .with_same_root(format!("{out_dir}/rust-vendored-crates"))
+                .unwrap()
+                .join(self.get_path().rel())
+                .unwrap();
             Command::new("cargo")
                 .args(["vendor", "--versioned-dirs"])
+                .arg(vendor_dir.abs())
                 .current_dir(&self.path)
                 .run_quiet_and_expect_success()
                 .unwrap();
             let mut crates = CrateCollection::new(self.path.root());
-            crates.add_from(self.get_path().join("vendor").unwrap()).unwrap();
+            crates.add_from(vendor_dir).unwrap();
             crates
         })
     }