Auto merge of #5688 - ebroto:fix_cargo_tests_in_rustc, r=flip1995
Fix cargo tests when running inside the rustlang/rust repo It seems we hit https://github.com/rust-lang/cargo/issues/5418, so I've applied the suggested solution. Also added some more info when cargo-metadata fails to execute. (there was no open issue for this) changelog: none
This commit is contained in:
commit
ea7066a01d
@ -147,6 +147,8 @@ fn get_manifest_contents(lint_name: &str, hint: &str) -> String {
|
|||||||
name = "{}"
|
name = "{}"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
"#,
|
"#,
|
||||||
hint, lint_name
|
hint, lint_name
|
||||||
)
|
)
|
||||||
|
@ -36,13 +36,9 @@ declare_clippy_lint! {
|
|||||||
"common metadata is defined in `Cargo.toml`"
|
"common metadata is defined in `Cargo.toml`"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn warning(cx: &LateContext<'_, '_>, message: &str) {
|
|
||||||
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn missing_warning(cx: &LateContext<'_, '_>, package: &cargo_metadata::Package, field: &str) {
|
fn missing_warning(cx: &LateContext<'_, '_>, package: &cargo_metadata::Package, field: &str) {
|
||||||
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
|
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
|
||||||
warning(cx, &message);
|
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty_str(value: &Option<String>) -> bool {
|
fn is_empty_str(value: &Option<String>) -> bool {
|
||||||
@ -66,12 +62,7 @@ impl LateLintPass<'_, '_> for CargoCommonMetadata {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
|
let metadata = unwrap_cargo_metadata!(cx, CARGO_COMMON_METADATA, false);
|
||||||
metadata
|
|
||||||
} else {
|
|
||||||
warning(cx, "could not read cargo metadata");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
for package in metadata.packages {
|
for package in metadata.packages {
|
||||||
if is_empty_vec(&package.authors) {
|
if is_empty_vec(&package.authors) {
|
||||||
|
@ -7,7 +7,7 @@ use rustc_lint::{LateContext, LateLintPass};
|
|||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::DUMMY_SP;
|
use rustc_span::source_map::DUMMY_SP;
|
||||||
|
|
||||||
use cargo_metadata::{DependencyKind, MetadataCommand, Node, Package, PackageId};
|
use cargo_metadata::{DependencyKind, Node, Package, PackageId};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
@ -42,13 +42,7 @@ impl LateLintPass<'_, '_> for MultipleCrateVersions {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let metadata = if let Ok(metadata) = MetadataCommand::new().exec() {
|
let metadata = unwrap_cargo_metadata!(cx, MULTIPLE_CRATE_VERSIONS, true);
|
||||||
metadata
|
|
||||||
} else {
|
|
||||||
span_lint(cx, MULTIPLE_CRATE_VERSIONS, DUMMY_SP, "could not read cargo metadata");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let local_name = cx.tcx.crate_name(LOCAL_CRATE).as_str();
|
let local_name = cx.tcx.crate_name(LOCAL_CRATE).as_str();
|
||||||
let mut packages = metadata.packages;
|
let mut packages = metadata.packages;
|
||||||
packages.sort_by(|a, b| a.name.cmp(&b.name));
|
packages.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
@ -1405,6 +1405,24 @@ pub fn run_lints(cx: &LateContext<'_, '_>, lints: &[&'static Lint], id: HirId) -
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! unwrap_cargo_metadata {
|
||||||
|
($cx: ident, $lint: ident, $deps: expr) => {{
|
||||||
|
let mut command = cargo_metadata::MetadataCommand::new();
|
||||||
|
if !$deps {
|
||||||
|
command.no_deps();
|
||||||
|
}
|
||||||
|
|
||||||
|
match command.exec() {
|
||||||
|
Ok(metadata) => metadata,
|
||||||
|
Err(err) => {
|
||||||
|
span_lint($cx, $lint, DUMMY_SP, &format!("could not read cargo metadata: {}", err));
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::{trim_multiline, without_block_comments};
|
use super::{trim_multiline, without_block_comments};
|
||||||
|
@ -34,12 +34,7 @@ impl LateLintPass<'_, '_> for WildcardDependencies {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
|
let metadata = unwrap_cargo_metadata!(cx, WILDCARD_DEPENDENCIES, false);
|
||||||
metadata
|
|
||||||
} else {
|
|
||||||
span_lint(cx, WILDCARD_DEPENDENCIES, DUMMY_SP, "could not read cargo metadata");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
for dep in &metadata.packages[0].dependencies {
|
for dep in &metadata.packages[0].dependencies {
|
||||||
// VersionReq::any() does not work
|
// VersionReq::any() does not work
|
||||||
|
@ -220,10 +220,6 @@ fn run_ui_cargo(config: &mut compiletest::Config) {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cargo::is_rustc_test_suite() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
config.mode = TestMode::Ui;
|
config.mode = TestMode::Ui;
|
||||||
config.src_base = Path::new("tests").join("ui-cargo").canonicalize().unwrap();
|
config.src_base = Path::new("tests").join("ui-cargo").canonicalize().unwrap();
|
||||||
|
|
||||||
|
@ -2,3 +2,5 @@
|
|||||||
name = "cargo_common_metadata"
|
name = "cargo_common_metadata"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
@ -9,3 +9,5 @@ readme = "README.md"
|
|||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
keywords = ["metadata", "lint", "clippy"]
|
keywords = ["metadata", "lint", "clippy"]
|
||||||
categories = ["development-tools::testing"]
|
categories = ["development-tools::testing"]
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
@ -5,6 +5,8 @@ name = "multiple_crate_versions"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
# One of the versions of winapi is only a dev dependency: allowed
|
# One of the versions of winapi is only a dev dependency: allowed
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ctrlc = "=3.1.0"
|
ctrlc = "=3.1.0"
|
||||||
|
@ -3,6 +3,8 @@ name = "multiple_crate_versions"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ctrlc = "=3.1.0"
|
ctrlc = "=3.1.0"
|
||||||
ansi_term = "=0.11.0"
|
ansi_term = "=0.11.0"
|
||||||
|
@ -3,6 +3,8 @@ name = "cargo_common_metadata"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "1.3.7"
|
regex = "1.3.7"
|
||||||
serde = "1.0.110"
|
serde = "1.0.110"
|
||||||
|
@ -3,5 +3,7 @@ name = "wildcard_dependencies"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "*"
|
regex = "*"
|
||||||
|
@ -3,5 +3,7 @@ name = "wildcard_dependencies"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "1"
|
regex = "1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user