Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] warn if default-members is active #701

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cargo-nextest/src/cargo_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use crate::output::OutputContext;
use camino::{Utf8Path, Utf8PathBuf};
use clap::Args;
use guppy::graph::PackageGraph;
use std::path::PathBuf;

/// Options passed down to cargo.
Expand Down Expand Up @@ -143,6 +144,19 @@ pub(crate) struct CargoOptions {
unstable_flags: Vec<String>,
}

impl CargoOptions {
fn needs_default_members_warning(&self, graph: &PackageGraph) -> bool {
// If any package-related options are passed in, don't produce a warning.
if !self.packages.is_empty() || self.workspace || self.all {
return false;
}

// TODO: figure out whether this will cause everything to be built. Factors to consider:
// * symlinks
// * exact behavior with nested directories
}
}

#[derive(Clone, Debug)]
pub(crate) struct CargoCli<'a> {
cargo_path: Utf8PathBuf,
Expand Down
49 changes: 49 additions & 0 deletions nextest-runner/src/cargo_toml.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) The nextest Contributors
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Support for reading `Cargo.toml` files.
//!
//! This package contains logic to partially read and understand `Cargo.toml` files: just enough for
//! nextest's needs.

use crate::errors::RootCargoTomlError;
use camino::{Utf8Path, Utf8PathBuf};
use serde::Deserialize;

/// Represents a workspace's root Cargo.toml.
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct RootCargoToml {
/// The workspace key.
pub workspace: RootCargoTomlWorkspace,
}

impl RootCargoToml {
/// Reads the root Cargo.toml into this file.
pub fn read_file(path: &Utf8Path) -> Result<Self, RootCargoTomlError> {
let contents =
std::fs::read_to_string(&path).map_err(|error| RootCargoTomlError::ReadError {
path: path.to_owned(),
error,
})?;

toml_edit::easy::from_str(&contents).map_err(|error| RootCargoTomlError::ParseError {
path: path.to_owned(),
error,
})
}

/// Returns true if the workspace has default members.
pub fn has_default_members(&self) -> bool {
self.workspace.default_members.is_some()
}
}

/// The `[workspace]` section of a [`RootCargoToml`].
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct RootCargoTomlWorkspace {
/// The default members of the workspace.
#[serde(default)]
pub default_members: Option<Vec<Utf8PathBuf>>,
}
26 changes: 26 additions & 0 deletions nextest-runner/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,32 @@ pub enum CargoConfigError {
},
}

/// An error occurred while parsing a root Cargo.toml.
#[derive(Debug, Error)]
pub enum RootCargoTomlError {
/// Error reading a file from disk.
#[error("failed to read workspace `{path}`")]
ReadError {
/// The path to the file.
path: Utf8PathBuf,

/// The inner error.
#[source]
error: std::io::Error,
},

/// Error parsing the `Cargo.toml` file.
#[error("failed to parse workspace `{path}`")]
ParseError {
/// The path to the file.
path: Utf8PathBuf,

/// The error that occurred trying to deserialize the file.
#[source]
error: toml_edit::easy::de::Error,
},
}

/// The reason an invalid CLI config failed.
///
/// Part of [`CargoConfigError::InvalidCliConfig`].
Expand Down
1 change: 1 addition & 0 deletions nextest-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! post](https://sunshowers.io/posts/nextest-and-tokio/).

pub mod cargo_config;
pub mod cargo_toml;
pub mod config;
#[cfg(feature = "experimental-tokio-console")]
pub mod console;
Expand Down