Skip to content

Commit e625b66

Browse files
committed
Add xtask for (crudely) checking license headers
1 parent 4145083 commit e625b66

File tree

7 files changed

+262
-70
lines changed

7 files changed

+262
-70
lines changed

.licenserc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ header:
88
file, You can obtain one at https://mozilla.org/MPL/2.0/.
99
paths:
1010
- '**/*.rs'
11+
paths-ignore:
12+
- 'target/**/*.rs'
1113

1214
comment: on-failure

Cargo.lock

+59-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xtask/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ edition = "2021"
66
[dependencies]
77
anyhow.workspace = true
88
clap = { workspace = true, features = ["derive"] }
9+
serde = { workspace = true, features = ["derive"] }
910
serde_json = { workspace = true }
11+
serde_yaml = { version = "0.9" }
12+
glob = { version = "0.3.1" }
13+
globset = { version = "0.4.11" }

xtask/src/main.rs

+9-62
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use std::process::{Command, Stdio};
6-
7-
use anyhow::{bail, Result};
5+
use anyhow::Result;
86
use clap::{Parser, Subcommand};
9-
use serde_json::{Map, Value};
7+
8+
mod task_clippy;
9+
mod task_license;
10+
mod util;
1011

1112
#[derive(Parser)]
1213
#[command(name = "cargo xtask", about = "Builder tasks for Propolis")]
@@ -23,67 +24,13 @@ enum Cmds {
2324
#[arg(short, long)]
2425
strict: bool,
2526
},
26-
}
27-
28-
fn workspace_root() -> Result<String> {
29-
let mut cmd = Command::new("cargo");
30-
cmd.args(["metadata", "--format-version=1"])
31-
.stdin(Stdio::null())
32-
.stderr(Stdio::inherit());
33-
34-
let output = cmd.output()?;
35-
if !output.status.success() {
36-
bail!("failed to query cargo metadata");
37-
}
38-
let metadata: Map<String, Value> = serde_json::from_slice(&output.stdout)?;
39-
40-
if let Some(Value::String(root)) = metadata.get("workspace_root") {
41-
Ok(root.clone())
42-
} else {
43-
bail!("could not location workspace root")
44-
}
45-
}
46-
47-
fn cmd_clippy(strict: bool) -> Result<()> {
48-
let wroot = workspace_root()?;
49-
50-
let run_clippy = |args: &[&str]| -> Result<bool> {
51-
let mut cmd = Command::new("cargo");
52-
cmd.arg("clippy").arg("--no-deps").args(args).current_dir(&wroot);
53-
54-
if strict {
55-
cmd.args(["--", "-Dwarnings"]);
56-
}
57-
58-
let status = cmd.spawn()?.wait()?;
59-
Ok(!status.success())
60-
};
61-
62-
let mut failed = false;
63-
64-
// Everything in the workspace (including tests, etc)
65-
failed |= run_clippy(&["--workspace", "--all-targets"])?;
66-
67-
// Check the server as it is built for production
68-
failed |=
69-
run_clippy(&["-p", "propolis-server", "--features", "omicron-build"])?;
70-
71-
// Check the Falcon bits
72-
failed |= run_clippy(&["-p", "propolis-server", "--features", "falcon"])?;
73-
74-
// Check the mock server
75-
failed |=
76-
run_clippy(&["-p", "propolis-server", "--features", "mock-only"])?;
77-
78-
if failed {
79-
bail!("Clippy failures detected")
80-
}
81-
82-
Ok(())
27+
/// (Crudely) Check for appropriate license headers
28+
License,
8329
}
8430

8531
fn main() -> Result<()> {
8632
match Args::parse().cmd {
87-
Cmds::Clippy { strict } => cmd_clippy(strict),
33+
Cmds::Clippy { strict } => task_clippy::cmd_clippy(strict),
34+
Cmds::License => task_license::cmd_license(),
8835
}
8936
}

xtask/src/task_clippy.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
use std::process::Command;
6+
7+
use anyhow::{bail, Result};
8+
9+
use crate::util::*;
10+
11+
pub(crate) fn cmd_clippy(strict: bool) -> Result<()> {
12+
let wroot = workspace_root()?;
13+
14+
let run_clippy = |args: &[&str]| -> Result<bool> {
15+
let mut cmd = Command::new("cargo");
16+
cmd.arg("clippy").arg("--no-deps").args(args).current_dir(&wroot);
17+
18+
if strict {
19+
cmd.args(["--", "-Dwarnings"]);
20+
}
21+
22+
let status = cmd.spawn()?.wait()?;
23+
Ok(!status.success())
24+
};
25+
26+
let mut failed = false;
27+
28+
// Everything in the workspace (including tests, etc)
29+
failed |= run_clippy(&["--workspace", "--all-targets"])?;
30+
31+
// Check the server as it is built for production
32+
failed |=
33+
run_clippy(&["-p", "propolis-server", "--features", "omicron-build"])?;
34+
35+
// Check the Falcon bits
36+
failed |= run_clippy(&["-p", "propolis-server", "--features", "falcon"])?;
37+
38+
// Check the mock server
39+
failed |=
40+
run_clippy(&["-p", "propolis-server", "--features", "mock-only"])?;
41+
42+
if failed {
43+
bail!("Clippy failures detected")
44+
}
45+
46+
Ok(())
47+
}

0 commit comments

Comments
 (0)