Skip to content

Commit

Permalink
[x] add lint for build dependencies being defined without a build script
Browse files Browse the repository at this point in the history
Cargo ignores such dependencies.

Closes: diem#3595
Approved by: metajack
  • Loading branch information
sunshowers authored and bors-libra committed Apr 24, 2020
1 parent 11864c2 commit fccfd8a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions devtools/x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.51"
structopt = "0.3.14"
anyhow = "1.0"
guppy = "0.3.1"
toml = "0.5.6"
env_logger = "0.7.1"
log = "0.4.8"
Expand Down
38 changes: 38 additions & 0 deletions devtools/x/src/lint/guppy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! Project and package linters that run queries on guppy.
use crate::config::EnforcedAttributesConfig;
use guppy::graph::BuildTargetId;
use std::{collections::HashMap, ffi::OsStr};
use x_lint::prelude::*;

Expand Down Expand Up @@ -213,3 +214,40 @@ impl PackageLinter for WorkspaceHack {
Ok(RunStatus::Executed)
}
}

/// Ensure that any workspace packages with build dependencies also have a build script.
#[derive(Debug)]
pub struct IrrelevantBuildDeps;

impl Linter for IrrelevantBuildDeps {
fn name(&self) -> &'static str {
"irrelevant-build-deps"
}
}

impl PackageLinter for IrrelevantBuildDeps {
fn run<'l>(
&self,
ctx: &PackageContext<'l>,
out: &mut LintFormatter<'l, '_>,
) -> Result<RunStatus<'l>> {
let metadata = ctx.metadata();

// TODO: clean up with guppy 0.4.
let has_build_script = metadata.build_target(&BuildTargetId::BuildScript).is_some();

let has_build_dep = ctx
.project_ctx()
.package_graph()
.unwrap()
.dep_links(metadata.id())
.unwrap()
.any(|link| link.edge.build().is_some());

if !has_build_script && has_build_dep {
out.write(LintLevel::Error, "build dependencies but no build script");
}

Ok(RunStatus::Executed)
}
}
1 change: 1 addition & 0 deletions devtools/x/src/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn run(args: Args, xctx: XContext) -> crate::Result<()> {
let package_linters: &[&dyn PackageLinter] = &[
&guppy::EnforcedAttributes::new(&workspace_config.enforced_attributes),
&guppy::CrateNamesPaths,
&guppy::IrrelevantBuildDeps,
&guppy::WorkspaceHack,
];

Expand Down
3 changes: 0 additions & 3 deletions mempool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ storage-service = { path = "../storage/storage-service", version = "0.1.0", opti
parity-multiaddr = { version = "0.8.0", default-features = false }
rand = "0.7.3"

[build-dependencies]
tonic-build = "0.2"

[features]
default = []
fuzzing = ["libra-types/fuzzing", "storage-service", "storage-service/fuzzing"]

0 comments on commit fccfd8a

Please sign in to comment.