Skip to content

Commit b4d7350

Browse files
authored
chore(vdev): add --features flag and FEATURES env var support to build/check/test commands (#25688)
1 parent 2f497a3 commit b4d7350

10 files changed

Lines changed: 89 additions & 45 deletions

File tree

.github/workflows/vdev_autotag.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- "vdev/Cargo.toml"
99

1010
permissions:
11-
contents: read
11+
contents: write
1212

1313
jobs:
1414
tag:

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ else
1919
export RUST_TARGET ?= "x86_64-unknown-linux-gnu"
2020
export DNSTAP_BENCHES := dnstap-benches
2121
endif
22-
export FEATURES ?= default
22+
export FEATURES ?=
2323

2424
# When COVERAGE=true, swap cargo-nextest for cargo-llvm-cov so test targets collect
2525
# coverage data. Run `make coverage-report` afterwards to emit the lcov file.
@@ -89,7 +89,7 @@ help:
8989
build: check-build-tools
9090
build: export CFLAGS += -g0 -O3
9191
build: ## Build the project in release mode
92-
cargo build --release --no-default-features --features ${FEATURES}
92+
cargo build --release $(if $(FEATURES),--no-default-features --features "$(FEATURES)")
9393

9494
.PHONY: build-x86_64-unknown-linux-gnu
9595
build-x86_64-unknown-linux-gnu: target/x86_64-unknown-linux-gnu/release/vector ## Build a release binary for the x86_64-unknown-linux-gnu triple.
@@ -245,11 +245,11 @@ target/%/vector.tar.gz: target/%/vector CARGO_HANDLES_FRESHNESS
245245
# https://github.com/rust-lang/cargo/issues/6454
246246
.PHONY: test
247247
test: ## Run the unit test suite
248-
${TEST_RUNNER} --workspace --no-fail-fast --no-default-features --features "${FEATURES}" ${SCOPE}
248+
${TEST_RUNNER} --workspace --no-fail-fast $(if $(FEATURES),--no-default-features --features "$(FEATURES)") ${SCOPE}
249249

250250
.PHONY: test-docs
251251
test-docs: ## Run the docs test suite
252-
cargo test --doc --workspace --no-fail-fast --no-default-features --features "${FEATURES}" ${SCOPE}
252+
cargo test --doc --workspace --no-fail-fast $(if $(FEATURES),--no-default-features --features "$(FEATURES)") ${SCOPE}
253253

254254
.PHONY: test-all
255255
test-all: test test-docs test-behavior test-integration test-component-validation ## Runs all tests: unit, docs, behavioral, integration, and component validation.

vdev/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vdev"
3-
version = "0.3.5"
3+
version = "0.3.6"
44
edition = "2024"
55
authors = ["Vector Contributors <vector@datadoghq.com>"]
66
license = "MPL-2.0"

vdev/src/app.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ pub trait CommandExt {
8383
fn run(&mut self) -> Result<ExitStatus>;
8484
fn wait(&mut self, message: impl Into<Cow<'static, str>>) -> Result<()>;
8585
fn pre_exec(&self);
86-
fn features(&mut self, features: &[String]) -> &mut Self;
8786
}
8887

8988
impl CommandExt for Command {
@@ -176,17 +175,6 @@ impl CommandExt for Command {
176175
}
177176
}
178177
}
179-
180-
fn features(&mut self, features: &[String]) -> &mut Self {
181-
self.arg("--no-default-features");
182-
self.arg("--features");
183-
if features.is_empty() {
184-
self.arg("default");
185-
} else {
186-
self.arg(features.join(","));
187-
}
188-
self
189-
}
190178
}
191179

192180
/// Helper function to build an error message from command output

vdev/src/commands/build/vector.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ pub struct Cli {
1616
#[arg(short, long)]
1717
release: bool,
1818

19-
/// The feature to activate (multiple allowed)
20-
#[arg(short = 'F', long)]
21-
feature: Vec<String>,
19+
/// Features to activate (comma-separated, or set FEATURES env var)
20+
#[arg(short = 'F', long, value_delimiter = ',', env = "FEATURES")]
21+
features: Vec<String>,
22+
23+
#[arg(long)]
24+
no_default_features: bool,
2225
}
2326

2427
impl Cli {
@@ -31,7 +34,17 @@ impl Cli {
3134
command.arg("--release");
3235
}
3336

34-
command.features(&self.feature);
37+
if self.no_default_features {
38+
command.arg("--no-default-features");
39+
}
40+
let features: Vec<String> = self
41+
.features
42+
.into_iter()
43+
.filter(|f| !f.is_empty())
44+
.collect();
45+
if !features.is_empty() {
46+
command.args(["--features", &features.join(",")]);
47+
}
3548

3649
let target = self.target.unwrap_or_else(platform::default_target);
3750
command.args(["--target", &target]);

vdev/src/commands/check/rust.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ pub struct Cli {
1313
#[arg(long, default_value_t = true)]
1414
clippy: bool,
1515

16-
#[arg(value_name = "FEATURE")]
16+
#[arg(short = 'F', long, value_delimiter = ',', env = "FEATURES")]
1717
features: Vec<String>,
1818

19+
#[arg(long)]
20+
no_default_features: bool,
21+
1922
#[arg(long)]
2023
fix: bool,
2124
}
@@ -36,14 +39,25 @@ impl Cli {
3639
Vec::default()
3740
};
3841

39-
let feature_args = if self.features.is_empty() {
40-
vec!["--all-features".to_string()]
42+
let features: Vec<&str> = self
43+
.features
44+
.iter()
45+
.map(String::as_str)
46+
.filter(|f| !f.is_empty())
47+
.collect();
48+
49+
let feature_args: Vec<String> = if self.no_default_features || !features.is_empty() {
50+
let mut args = Vec::new();
51+
if self.no_default_features {
52+
args.push("--no-default-features".to_string());
53+
}
54+
if !features.is_empty() {
55+
args.push("--features".to_string());
56+
args.push(features.join(","));
57+
}
58+
args
4159
} else {
42-
vec![
43-
"--no-default-features".to_string(),
44-
"--features".to_string(),
45-
self.features.join(",").clone(),
46-
]
60+
vec!["--all-features".to_string()]
4761
};
4862

4963
[tool.as_ref(), "--workspace", "--all-targets"]

vdev/src/commands/crate_versions.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,34 @@ pub struct Cli {
1818
#[arg(long)]
1919
all: bool,
2020

21-
/// The feature to active (multiple allowed). If none are specified, the default is used.
22-
#[arg(short = 'F', long)]
23-
feature: Vec<String>,
21+
/// Features to activate (comma-separated, or set FEATURES env var)
22+
#[arg(short = 'F', long, value_delimiter = ',', env = "FEATURES")]
23+
features: Vec<String>,
24+
25+
#[arg(long)]
26+
no_default_features: bool,
2427
}
2528

2629
impl Cli {
2730
pub fn exec(self) -> Result<()> {
2831
let re_crate = Regex::new(r" (\S+) v([0-9.]+)").unwrap();
2932
let mut versions: HashMap<String, HashSet<String>> = HashMap::default();
33+
let features: Vec<String> = self
34+
.features
35+
.into_iter()
36+
.filter(|f| !f.is_empty())
37+
.collect();
38+
39+
let mut cmd = Command::new("cargo");
40+
cmd.arg("tree");
41+
if self.no_default_features {
42+
cmd.arg("--no-default-features");
43+
}
44+
if !features.is_empty() {
45+
cmd.args(["--features", &features.join(",")]);
46+
}
3047

31-
for line in Command::new("cargo")
32-
.arg("tree")
33-
.features(&self.feature)
34-
.check_output()?
35-
.lines()
36-
{
48+
for line in cmd.check_output()?.lines() {
3749
if let Some(captures) = re_crate.captures(line) {
3850
let package = &captures[1];
3951
let version = &captures[2];

vdev/src/commands/test.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ pub struct Cli {
1414
/// Environment variables in the form KEY[=VALUE]
1515
#[arg(short, long)]
1616
env: Option<Vec<String>>,
17+
18+
/// Features to activate (comma-separated, or set FEATURES env var)
19+
#[arg(short = 'F', long, value_delimiter = ',', env = "FEATURES")]
20+
features: Vec<String>,
21+
22+
#[arg(long)]
23+
no_default_features: bool,
1724
}
1825

1926
fn parse_env(env: Vec<String>) -> BTreeMap<String, Option<String>> {
@@ -30,14 +37,23 @@ fn parse_env(env: Vec<String>) -> BTreeMap<String, Option<String>> {
3037

3138
impl Cli {
3239
pub fn exec(self) -> Result<()> {
40+
let features: Vec<String> = self
41+
.features
42+
.into_iter()
43+
.filter(|f| !f.is_empty())
44+
.collect();
45+
3346
let mut args = vec!["--workspace".to_string()];
3447

35-
if let Some(mut extra_args) = self.args {
36-
args.append(&mut extra_args);
48+
if self.no_default_features {
49+
args.push("--no-default-features".to_string());
50+
}
51+
if !features.is_empty() {
52+
args.extend(["--features".to_string(), features.join(",")]);
3753
}
3854

39-
if !args.contains(&"--features".to_string()) {
40-
args.extend(["--features".to_string(), "default".to_string()]);
55+
if let Some(mut extra_args) = self.args {
56+
args.append(&mut extra_args);
4157
}
4258

4359
LocalTestRunner.test(

vdev/src/testing/runner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const TEST_COMMAND: &[&str] = &[
2929
"--no-fail-fast",
3030
"--no-default-features",
3131
];
32+
const LOCAL_TEST_COMMAND: &[&str] = &["cargo", "nextest", "run", "--no-fail-fast"];
3233
const COVERAGE_COMMAND: &[&str] = &[
3334
"cargo",
3435
"llvm-cov",
@@ -417,7 +418,7 @@ impl TestRunner for LocalTestRunner {
417418
let test_cmd = if coverage {
418419
COVERAGE_COMMAND
419420
} else {
420-
TEST_COMMAND
421+
LOCAL_TEST_COMMAND
421422
};
422423
let mut command = Command::new(test_cmd[0]);
423424
command.args(&test_cmd[1..]);

0 commit comments

Comments
 (0)