diff --git a/Cargo.lock b/Cargo.lock index ff85040e..ac2395bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1632,9 +1632,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080" +checksum = "dcf6960dc9a5b4ee8d3e4c5787b4a112a8818e0290a42ff664ad60692fdf2032" dependencies = [ "autocfg 1.0.0", "crossbeam-deque", @@ -1644,12 +1644,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.7.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280" +checksum = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf" dependencies = [ + "crossbeam-channel", "crossbeam-deque", - "crossbeam-queue", "crossbeam-utils", "lazy_static", "num_cpus", @@ -1697,6 +1697,18 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "remove_dir_all" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f43c8c593a759eb8eae137a1ad7b9ed881453a942ac3ce58b87b6e5c2364779" +dependencies = [ + "log", + "num_cpus", + "rayon", + "winapi 0.3.9", +] + [[package]] name = "rsa" version = "0.3.0" @@ -2025,6 +2037,7 @@ dependencies = [ "futures", "glob", "openssl", + "remove_dir_all 0.6.0", "serde", "serde_json", "sqlx", @@ -2322,7 +2335,7 @@ dependencies = [ "libc", "rand", "redox_syscall", - "remove_dir_all", + "remove_dir_all 0.5.3", "winapi 0.3.9", ] diff --git a/sqlx-cli/Cargo.toml b/sqlx-cli/Cargo.toml index b94ff73d..49849cba 100644 --- a/sqlx-cli/Cargo.toml +++ b/sqlx-cli/Cargo.toml @@ -41,6 +41,8 @@ serde = "1.0.110" glob = "0.3.0" cargo_metadata = "0.10.0" openssl = { version = "0.10.30", optional = true } +# workaround for https://github.com/rust-lang/rust/issues/29497 +remove_dir_all = "0.6.0" [features] default = [ "postgres", "sqlite", "mysql" ] diff --git a/sqlx-cli/src/prepare.rs b/sqlx-cli/src/prepare.rs index b38ddc1c..11a00c12 100644 --- a/sqlx-cli/src/prepare.rs +++ b/sqlx-cli/src/prepare.rs @@ -1,6 +1,7 @@ use anyhow::{bail, Context}; use cargo_metadata::MetadataCommand; use console::style; +use remove_dir_all::remove_dir_all; use sqlx::any::{AnyConnectOptions, AnyKind}; use std::collections::BTreeMap; use std::fs::File; @@ -82,6 +83,15 @@ fn run_prepare_step(cargo_args: Vec) -> anyhow::Result { let cargo = env::var("CARGO") .context("`prepare` subcommand may only be invoked as `cargo sqlx prepare``")?; + let metadata = MetadataCommand::new() + .cargo_path(&cargo) + .exec() + .context("failed to execute `cargo metadata`")?; + + // try removing the target/sqlx directory before running, as stale files + // have repeatedly caused issues in the past. + let _ = remove_dir_all(metadata.target_directory.join("sqlx")); + let check_status = Command::new(&cargo) .arg("rustc") .args(cargo_args) @@ -100,11 +110,6 @@ fn run_prepare_step(cargo_args: Vec) -> anyhow::Result { bail!("`cargo check` failed with status: {}", check_status); } - let metadata = MetadataCommand::new() - .cargo_path(cargo) - .exec() - .context("failed to execute `cargo metadata`")?; - let pattern = metadata.target_directory.join("sqlx/query-*.json"); let mut data = BTreeMap::new();