Skip to content

Commit 1a78acc

Browse files
paldepindCopilot
andcommitted
Rust: simplify extractor command-line options
Replace the generated CLI configuration with explicit support for file-list, qltest, and logging-verbosity. Preserve configuration through environment variables and options.yml, and remove the unused macro crate and serde_with dependencies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 03abd0ed-3880-4e39-8713-990a317c96e6
1 parent 96852da commit 1a78acc

8 files changed

Lines changed: 151 additions & 460 deletions

File tree

‎Cargo.lock‎

Lines changed: 24 additions & 304 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ members = [
1111
"unified/extractor",
1212
"unified/swift-syntax-rs",
1313
"rust/extractor",
14-
"rust/extractor/macros",
1514
"rust/ast-generator",
1615
"rust/autobuild",
1716
]

‎rust/extractor/BUILD.bazel‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ codeql_rust_binary(
1313
],
1414
proc_macro_deps = all_crate_deps(
1515
proc_macro = True,
16-
) + [
17-
"//rust/extractor/macros",
18-
],
16+
),
1917
visibility = ["//rust:__subpackages__"],
2018
deps = all_crate_deps(
2119
normal = True,

‎rust/extractor/Cargo.toml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ ra_ap_span = "0.0.358"
2828
ra_ap_cfg = "0.0.358"
2929
ra_ap_intern = "0.0.358"
3030
serde = "1.0.229"
31-
serde_with = "3.24.0"
3231
triomphe = "0.1.17"
3332
codeql-extractor = { path = "../../shared/tree-sitter-extractor" }
34-
rust-extractor-macros = { path = "macros" }
3533
itertools = "0.15.0"
3634
glob = "0.3.4"
3735
chrono = { version = "0.4.45", features = ["serde"] }

‎rust/extractor/macros/BUILD.bazel‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎rust/extractor/macros/Cargo.toml‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎rust/extractor/macros/src/lib.rs‎

Lines changed: 0 additions & 110 deletions
This file was deleted.

‎rust/extractor/src/config.rs‎

Lines changed: 126 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@ use ra_ap_paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
1717
use ra_ap_project_model::{
1818
CargoConfig, CargoFeatures, CfgOverrides, RustLibSource, Sysroot, TargetDirectoryConfig,
1919
};
20-
use rust_extractor_macros::extractor_cli_config;
2120
use serde::{Deserialize, Serialize};
2221
use std::collections::HashSet;
23-
use std::fmt::Debug;
2422
use std::ops::Not;
2523
use std::path::{Path, PathBuf};
2624

2725
use crate::toolchain::select_toolchain;
2826

29-
#[derive(Debug, PartialEq, Eq, Default, Serialize, Deserialize, Clone, Copy, clap::ValueEnum)]
27+
#[derive(Debug, PartialEq, Eq, Default, Serialize, Deserialize, Clone, Copy)]
3028
#[serde(rename_all = "lowercase")]
31-
#[clap(rename_all = "lowercase")]
3229
pub enum Compression {
3330
None,
3431
Gzip,
@@ -46,17 +43,38 @@ impl From<Compression> for trap::Compression {
4643
}
4744
}
4845

49-
#[extractor_cli_config]
46+
#[derive(Parser, Serialize)]
47+
#[command(about, long_about = None)]
48+
struct CliConfig {
49+
#[arg(long)]
50+
#[serde(skip_serializing_if = "Option::is_none")]
51+
file_list: Option<PathBuf>,
52+
53+
#[arg(long)]
54+
#[serde(skip_serializing_if = "<&bool>::not")]
55+
qltest: bool,
56+
57+
#[arg(long)]
58+
#[serde(skip_serializing_if = "Option::is_none")]
59+
logging_verbosity: Option<String>,
60+
}
61+
62+
#[derive(Debug, Default, Deserialize)]
63+
#[serde(default)]
5064
pub struct Config {
5165
pub scratch_dir: PathBuf,
5266
pub trap_dir: PathBuf,
5367
pub source_archive_dir: PathBuf,
5468
pub diagnostic_dir: PathBuf,
5569
pub cargo_target_dir: Option<PathBuf>,
5670
pub cargo_target: Option<String>,
71+
#[serde(deserialize_with = "deserialize::deserialize_newline_or_comma_separated_vec")]
5772
pub cargo_features: Vec<String>,
73+
#[serde(deserialize_with = "deserialize::deserialize_newline_or_comma_separated_vec")]
5874
pub cargo_cfg_overrides: Vec<String>,
75+
#[serde(deserialize_with = "deserialize::deserialize_newline_or_comma_separated_map")]
5976
pub cargo_extra_env: FxHashMap<String, Option<String>>,
77+
#[serde(deserialize_with = "deserialize::deserialize_newline_or_comma_separated_vec")]
6078
pub cargo_extra_args: Vec<String>,
6179
pub cargo_all_targets: bool,
6280
pub logging_flamegraph: Option<PathBuf>,
@@ -65,13 +83,16 @@ pub struct Config {
6583
pub file_list: Option<PathBuf>,
6684
pub qltest: bool,
6785
pub qltest_cargo_check: bool,
86+
#[serde(deserialize_with = "deserialize::deserialize_newline_or_comma_separated_vec")]
6887
pub qltest_dependencies: Vec<String>,
6988
pub qltest_use_nightly: bool,
7089
pub qltest_edition: Option<String>,
7190
pub sysroot: Option<PathBuf>,
7291
pub sysroot_src: Option<PathBuf>,
7392
pub rustc_src: Option<PathBuf>,
93+
#[serde(deserialize_with = "deserialize::deserialize_newline_or_comma_separated_vec")]
7494
pub build_script_command: Vec<String>,
95+
#[serde(deserialize_with = "deserialize::deserialize_newline_or_comma_separated_vec")]
7596
pub extra_includes: Vec<PathBuf>,
7697
pub proc_macro_server: Option<PathBuf>,
7798
pub extract_dependencies_as_source: bool,
@@ -286,3 +307,103 @@ fn join_path_buf(lhs: &AbsPath, rhs: &Path) -> AbsPathBuf {
286307
};
287308
lhs.join(path)
288309
}
310+
311+
#[cfg(test)]
312+
mod tests {
313+
use super::*;
314+
315+
#[test]
316+
fn rejects_configuration_only_cli_options() {
317+
for flag in [
318+
"--cargo-target",
319+
"--trap-compression",
320+
"--force-library-mode",
321+
] {
322+
let err = CliConfig::try_parse_from(["extractor", flag])
323+
.err()
324+
.unwrap();
325+
assert_eq!(err.kind(), clap::error::ErrorKind::UnknownArgument);
326+
}
327+
}
328+
329+
#[test]
330+
fn absent_cli_options_preserve_configuration() {
331+
let config: Config = Figment::new()
332+
.merge(Yaml::string(
333+
r#"
334+
file_list: files.txt
335+
qltest: true
336+
logging_verbosity: debug
337+
"#,
338+
))
339+
.merge(Serialized::defaults(
340+
CliConfig::try_parse_from(["extractor"]).unwrap(),
341+
))
342+
.extract()
343+
.unwrap();
344+
345+
assert_eq!(config.file_list, Some(PathBuf::from("files.txt")));
346+
assert!(config.qltest);
347+
assert_eq!(config.logging_verbosity.as_deref(), Some("debug"));
348+
assert_eq!(config.trap_compression, Compression::Zstd);
349+
assert!(config.cargo_features.is_empty());
350+
assert!(config.cargo_extra_env.is_empty());
351+
}
352+
353+
#[test]
354+
fn explicit_cli_options_override_configuration() {
355+
let config: Config = Figment::new()
356+
.merge(Yaml::string(
357+
r#"
358+
file_list: original.txt
359+
qltest: false
360+
logging_verbosity: off
361+
"#,
362+
))
363+
.merge(Serialized::defaults(
364+
CliConfig::try_parse_from([
365+
"extractor",
366+
"--file-list",
367+
"selected.txt",
368+
"--qltest",
369+
"--logging-verbosity=progress+",
370+
])
371+
.unwrap(),
372+
))
373+
.extract()
374+
.unwrap();
375+
376+
assert_eq!(config.file_list, Some(PathBuf::from("selected.txt")));
377+
assert!(config.qltest);
378+
assert_eq!(config.logging_verbosity.as_deref(), Some("progress+"));
379+
}
380+
381+
#[test]
382+
fn preserves_custom_configuration_deserializers() {
383+
let config: Config = Figment::new()
384+
.merge(Yaml::string(
385+
r#"
386+
cargo_features: default,extra
387+
cargo_cfg_overrides: "foo\n-bar"
388+
cargo_extra_env: SET=value,UNSET
389+
cargo_extra_args: ["--offline"]
390+
qltest_dependencies: ["serde"]
391+
build_script_command: cargo,check
392+
extra_includes: ["generated"]
393+
trap_compression: none
394+
"#,
395+
))
396+
.extract()
397+
.unwrap();
398+
399+
assert_eq!(config.cargo_features, ["default", "extra"]);
400+
assert_eq!(config.cargo_cfg_overrides, ["foo", "-bar"]);
401+
assert_eq!(config.cargo_extra_env["SET"].as_deref(), Some("value"));
402+
assert_eq!(config.cargo_extra_env["UNSET"], None);
403+
assert_eq!(config.cargo_extra_args, ["--offline"]);
404+
assert_eq!(config.qltest_dependencies, ["serde"]);
405+
assert_eq!(config.build_script_command, ["cargo", "check"]);
406+
assert_eq!(config.extra_includes, [PathBuf::from("generated")]);
407+
assert_eq!(config.trap_compression, Compression::None);
408+
}
409+
}

0 commit comments

Comments
 (0)