Skip to content

Commit c1d56c7

Browse files
authored
be more consistent about workspace members (#5921)
1. We have reasons for excluding some packages from the default workspace members, but there was nothing checking that newly-added packages were added to both. I added an additional check to `cargo xtask check-workspace-deps` to ensure that `default-members` is equal to `members` minus xtask and end-to-end-tests. This had the effect that the tests in `api_identity` were not being run in CI! 2. Add `--workspace` to `cargo clippy` and `cargo doc` in CI to run checks across the entire tree. 3. Fix clippy lints / doc errors that were not being caught in the previous setup.
1 parent 6461078 commit c1d56c7

File tree

10 files changed

+62
-31
lines changed

10 files changed

+62
-31
lines changed

.github/buildomat/jobs/clippy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ ptime -m bash ./tools/install_builder_prerequisites.sh -y
3030
banner clippy
3131
export CARGO_INCREMENTAL=0
3232
ptime -m cargo xtask clippy
33-
ptime -m cargo doc
33+
RUSTDOCFLAGS="-Dwarnings" ptime -m cargo doc --workspace

.github/workflows/rust.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ jobs:
108108
- name: Install Pre-Requisites
109109
run: ./tools/install_builder_prerequisites.sh -y
110110
- name: Test build documentation
111-
run: RUSTDOCFLAGS="-Dwarnings" cargo doc
111+
run: RUSTDOCFLAGS="-Dwarnings" cargo doc --workspace

Cargo.toml

+10-3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ members = [
8787
]
8888

8989
default-members = [
90+
"api_identity",
9091
"bootstore",
9192
"certificates",
9293
"clients/bootstrap-agent-client",
@@ -113,6 +114,8 @@ default-members = [
113114
# hakari to not work as well and build times to be longer.
114115
# See omicron#4392.
115116
"dns-server",
117+
# Do not include end-to-end-tests in the list of default members, as its
118+
# tests only work on a deployed control plane.
116119
"gateway-cli",
117120
"gateway-test-utils",
118121
"gateway",
@@ -128,18 +131,21 @@ default-members = [
128131
"nexus-config",
129132
"nexus/authz-macros",
130133
"nexus/auth",
131-
"nexus/macros-common",
132-
"nexus/metrics-producer-gc",
133-
"nexus/networking",
134134
"nexus/db-fixed-data",
135135
"nexus/db-macros",
136136
"nexus/db-model",
137137
"nexus/db-queries",
138138
"nexus/defaults",
139139
"nexus/inventory",
140+
"nexus/macros-common",
141+
"nexus/metrics-producer-gc",
142+
"nexus/networking",
140143
"nexus/reconfigurator/execution",
141144
"nexus/reconfigurator/planning",
142145
"nexus/reconfigurator/preparation",
146+
"nexus/test-interface",
147+
"nexus/test-utils-macros",
148+
"nexus/test-utils",
143149
"nexus/types",
144150
"oximeter/collector",
145151
"oximeter/db",
@@ -166,6 +172,7 @@ default-members = [
166172
"wicket-dbg",
167173
"wicket",
168174
"wicketd",
175+
"workspace-hack",
169176
"zone-setup",
170177
]
171178
resolver = "2"

api_identity/src/lib.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,9 @@ mod test {
6060

6161
#[test]
6262
fn test_identity() {
63-
let ret = do_object_identity(
64-
quote! {
65-
struct Foo { identity: IdentityMetadata }
66-
}
67-
.into(),
68-
);
63+
let ret = do_object_identity(quote! {
64+
struct Foo { identity: IdentityMetadata }
65+
});
6966

7067
let expected = quote! {
7168
impl ObjectIdentity for Foo {
@@ -80,12 +77,9 @@ mod test {
8077

8178
#[test]
8279
fn test_identity_no_field() {
83-
let ret = do_object_identity(
84-
quote! {
85-
struct Foo {}
86-
}
87-
.into(),
88-
);
80+
let ret = do_object_identity(quote! {
81+
struct Foo {}
82+
});
8983

9084
let error = ret.unwrap_err();
9185
assert!(error.to_string().starts_with("deriving ObjectIdentity"));

dev-tools/xtask/src/check_workspace_deps.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{bail, Context, Result};
88
use camino::Utf8Path;
99
use cargo_toml::{Dependency, Manifest};
1010
use fs_err as fs;
11-
use std::collections::BTreeMap;
11+
use std::collections::{BTreeMap, BTreeSet};
1212

1313
const WORKSPACE_HACK_PACKAGE_NAME: &str = "omicron-workspace-hack";
1414

@@ -116,6 +116,36 @@ pub fn run_cmd() -> Result<()> {
116116
nerrors += 1;
117117
}
118118

119+
// Check that `default-members` is configured correctly.
120+
let non_default = workspace
121+
.packages
122+
.iter()
123+
.filter_map(|package| {
124+
[
125+
// Including xtask causes hakari to not work as well and build
126+
// times to be longer (omicron#4392).
127+
"xtask",
128+
// The tests here should not be run by default, as they require
129+
// a running control plane.
130+
"end-to-end-tests",
131+
]
132+
.contains(&package.name.as_str())
133+
.then_some(&package.id)
134+
})
135+
.collect::<BTreeSet<_>>();
136+
let members = workspace.workspace_members.iter().collect::<BTreeSet<_>>();
137+
let default_members =
138+
workspace.workspace_default_members.iter().collect::<BTreeSet<_>>();
139+
for package in members.difference(&default_members) {
140+
if !non_default.contains(package) {
141+
eprintln!(
142+
"error: package {:?} not in default-members",
143+
package.repr
144+
);
145+
nerrors += 1;
146+
}
147+
}
148+
119149
eprintln!(
120150
"check-workspace-deps: errors: {}, warnings: {}",
121151
nerrors, nwarnings

dev-tools/xtask/src/clippy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub fn run_cmd(args: ClippyArgs) -> Result<()> {
4242
command
4343
// Make sure we check everything.
4444
.arg("--all-targets")
45+
.arg("--workspace")
4546
.arg("--")
4647
// For a list of lints, see
4748
// https://rust-lang.github.io/rust-clippy/master.

dev-tools/xtask/src/download.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ async fn get_values_from_file<const N: usize>(
218218
.context("Failed to read {path}")?;
219219
for line in content.lines() {
220220
let line = line.trim();
221-
let Some((key, value)) = line.split_once("=") else {
221+
let Some((key, value)) = line.split_once('=') else {
222222
continue;
223223
};
224224
let value = value.trim_matches('"');

dev-tools/xtask/src/virtual_hardware.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ fn unload_xde_driver() -> Result<()> {
235235
.context("Invalid modinfo output")?
236236
.lines()
237237
.find_map(|line| {
238-
let mut cols = line.trim().splitn(2, ' ');
239-
let id = cols.next()?;
240-
let desc = cols.next()?;
238+
let (id, desc) = line.trim().split_once(' ')?;
241239
if !desc.contains("xde") {
242240
return None;
243241
}
@@ -419,7 +417,7 @@ fn run_scadm_command(args: Vec<&str>) -> Result<Output> {
419417
for arg in &args {
420418
cmd.arg(arg);
421419
}
422-
Ok(execute(cmd)?)
420+
execute(cmd)
423421
}
424422

425423
fn default_gateway_ip() -> Result<String> {
@@ -497,8 +495,8 @@ struct SledAgentConfig {
497495
impl SledAgentConfig {
498496
fn read(path: &Utf8Path) -> Result<Self> {
499497
let config = std::fs::read_to_string(path)?;
500-
Ok(toml::from_str(&config)
501-
.context("Could not parse sled agent config as toml")?)
498+
toml::from_str(&config)
499+
.context("Could not parse sled agent config as toml")
502500
}
503501
}
504502

@@ -605,7 +603,7 @@ fn swap_list() -> Result<Vec<Utf8PathBuf>> {
605603
let mut cmd = Command::new(SWAP);
606604
cmd.arg("-l");
607605

608-
let output = cmd.output().context(format!("Could not start swap"))?;
606+
let output = cmd.output().context("Could not start swap")?;
609607
if !output.status.success() {
610608
if let Ok(stderr) = String::from_utf8(output.stderr) {
611609
// This is an exceptional case - if there are no swap devices,

end-to-end-tests/src/helpers/icmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Pinger4 {
150150
"{:.3}",
151151
(t.sum.as_micros() as f32
152152
/ 1000.0
153-
/ t.rx_count as f32)
153+
/ f32::from(t.rx_count))
154154
)
155155
},
156156
format!("{:.3}", (t.high.as_micros() as f32 / 1000.0)),

nexus/test-utils/src/http_testing.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ impl<'a> RequestBuilder<'a> {
216216

217217
/// Add header and value to check for at execution time
218218
///
219-
/// Behaves like header() rather than expect_allowed_headers() in that it
220-
/// takes one header at a time rather than a whole set.
219+
/// Behaves like header() in that it takes one header at a time rather than
220+
/// a whole set.
221221
pub fn expect_response_header<K, V, KE, VE>(
222222
mut self,
223223
name: K,
@@ -291,8 +291,9 @@ impl<'a> RequestBuilder<'a> {
291291
/// response, and make the response available to the caller
292292
///
293293
/// This function checks the returned status code (if [`Self::expect_status()`]
294-
/// was used), allowed headers (if [`Self::expect_allowed_headers()`] was used), and
295-
/// various other properties of the response.
294+
/// was used), allowed headers (if [`Self::expect_websocket_handshake()`] or
295+
/// [`Self::expect_console_asset()`] was used), and various other properties
296+
/// of the response.
296297
pub async fn execute(self) -> Result<TestResponse, anyhow::Error> {
297298
if let Some(error) = self.error {
298299
return Err(error);

0 commit comments

Comments
 (0)