Skip to content

Commit 38712e6

Browse files
paldepindCopilot
andcommitted
Rust: read extraction inputs from an explicit file list
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 35193a30-9bd2-4372-a2e5-65422a7779cf
1 parent 7ba5fa4 commit 38712e6

6 files changed

Lines changed: 33 additions & 35 deletions

File tree

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ pub fn extractor_cli_config(_attr: TokenStream, item: TokenStream) -> TokenStrea
2020
.iter()
2121
.map(|f| {
2222
let ty_tip = get_type_tip(&f.ty);
23-
if f.ident.as_ref().is_some_and(|i| i != "inputs")
24-
&& ty_tip.is_some_and(|i| i == "Vec")
25-
{
23+
if ty_tip.is_some_and(|i| i == "Vec") {
2624
quote! {
2725
#[serde(deserialize_with="deserialize::deserialize_newline_or_comma_separated_vec")]
2826
#f
@@ -62,10 +60,6 @@ pub fn extractor_cli_config(_attr: TokenStream, item: TokenStream) -> TokenStrea
6260
#[serde(skip_serializing_if="u8::is_zero")]
6361
#id: u8
6462
}
65-
} else if id == &format_ident!("inputs") {
66-
quote! {
67-
#f
68-
}
6963
} else if type_tip.is_some_and(|i| i == "Vec" || i == "FxHashMap" || i == "HashMap") {
7064
quote! {
7165
#[arg(long)]
@@ -84,14 +78,8 @@ pub fn extractor_cli_config(_attr: TokenStream, item: TokenStream) -> TokenStrea
8478
.iter()
8579
.map(|f| {
8680
let id = f.ident.as_ref().unwrap();
87-
if id == &format_ident!("inputs") {
88-
quote! {
89-
.field("number of inputs", &self.#id.len())
90-
}
91-
} else {
92-
quote! {
93-
.field(stringify!(#id), &self.#id)
94-
}
81+
quote! {
82+
.field(stringify!(#id), &self.#id)
9583
}
9684
})
9785
.collect::<Vec<_>>();

‎rust/extractor/src/config.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct Config {
6262
pub logging_flamegraph: Option<PathBuf>,
6363
pub logging_verbosity: Option<String>,
6464
pub trap_compression: Compression,
65-
pub inputs: Vec<PathBuf>,
65+
pub file_list: Option<PathBuf>,
6666
pub qltest: bool,
6767
pub qltest_cargo_check: bool,
6868
pub qltest_dependencies: Vec<String>,
@@ -95,9 +95,7 @@ impl Config {
9595
}
9696

9797
pub fn extract() -> anyhow::Result<Config> {
98-
let args = argfile::expand_args(argfile::parse_fromfile, argfile::PREFIX)
99-
.context("expanding parameter files")?;
100-
let cli_args = CliConfig::parse_from(args);
98+
let cli_args = CliConfig::parse();
10199
let mut figment = Figment::new()
102100
.merge(Env::raw().filter_map(|f| {
103101
if f.eq("CODEQL_VERBOSITY") {

‎rust/extractor/src/main.rs‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use ra_ap_project_model::{CargoConfig, ProjectManifest};
1515
use ra_ap_vfs::Vfs;
1616
use rust_analyzer::{ParseResult, RustAnalyzer};
1717
use std::collections::HashSet;
18+
use std::fs::File;
1819
use std::hash::RandomState;
20+
use std::io::{self, BufRead, BufReader};
1921
use std::time::Instant;
2022
use std::{
2123
collections::HashMap,
@@ -212,10 +214,20 @@ fn cwd() -> anyhow::Result<AbsPathBuf> {
212214
}
213215

214216
fn main() -> anyhow::Result<()> {
215-
let mut cfg = config::Config::extract().context("failed to load configuration")?;
216-
if cfg.qltest {
217-
qltest::prepare(&mut cfg)?;
218-
}
217+
let cfg = config::Config::extract().context("failed to load configuration")?;
218+
let inputs = if cfg.qltest {
219+
qltest::prepare(&cfg)?
220+
} else if let Some(path) = &cfg.file_list {
221+
let file =
222+
File::open(path).with_context(|| format!("opening file list {}", path.display()))?;
223+
BufReader::new(file)
224+
.lines()
225+
.map(|line| line.map(PathBuf::from))
226+
.collect::<io::Result<Vec<_>>>()
227+
.with_context(|| format!("reading file list {}", path.display()))?
228+
} else {
229+
Vec::new()
230+
};
219231
let start = Instant::now();
220232
let (flame_layer, _flush_guard) = if let Some(path) = &cfg.logging_flamegraph {
221233
tracing_flame::FlameLayer::with_file(path)
@@ -240,8 +252,7 @@ fn main() -> anyhow::Result<()> {
240252
root: cfg.source_archive_dir.clone(),
241253
};
242254
let mut extractor = Extractor::new(&archiver, &traps);
243-
let files: Vec<PathBuf> = cfg
244-
.inputs
255+
let files: Vec<PathBuf> = inputs
245256
.iter()
246257
.map(|file| {
247258
let file = std::path::absolute(file).unwrap_or(file.to_path_buf());

‎rust/extractor/src/qltest.rs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use glob::glob;
44
use itertools::Itertools;
55
use std::ffi::OsStr;
66
use std::fs;
7-
use std::path::Path;
7+
use std::path::{Path, PathBuf};
88
use tracing::info;
99

1010
const DEFAULT_EDITION: &str = "2021";
@@ -80,13 +80,12 @@ fn dump_nightly_toolchain() -> anyhow::Result<()> {
8080
Ok(())
8181
}
8282

83-
fn set_sources(config: &mut Config) -> anyhow::Result<()> {
83+
fn get_sources() -> anyhow::Result<Vec<PathBuf>> {
8484
let path_iterator = glob("**/*.rs").context("globbing test sources")?;
85-
config.inputs = path_iterator
85+
path_iterator
8686
.filter(|f| f.is_err() || !f.as_ref().unwrap().starts_with("target"))
8787
.collect::<Result<Vec<_>, _>>()
88-
.context("fetching test sources")?;
89-
Ok(())
88+
.context("fetching test sources")
9089
}
9190

9291
fn cargo_check(config: &Config) -> anyhow::Result<()> {
@@ -105,9 +104,9 @@ fn cargo_check(config: &Config) -> anyhow::Result<()> {
105104
}
106105
}
107106

108-
pub(crate) fn prepare(config: &mut Config) -> anyhow::Result<()> {
107+
pub(crate) fn prepare(config: &Config) -> anyhow::Result<Vec<PathBuf>> {
109108
dump_lib()?;
110-
set_sources(config)?;
109+
let inputs = get_sources()?;
111110
let edition = config.qltest_edition.as_deref().unwrap_or(DEFAULT_EDITION);
112111
dump_cargo_manifest(&config.qltest_dependencies, edition)?;
113112
if config.qltest_use_nightly {
@@ -116,5 +115,5 @@ pub(crate) fn prepare(config: &mut Config) -> anyhow::Result<()> {
116115
if config.qltest_cargo_check {
117116
cargo_check(config)?;
118117
}
119-
Ok(())
118+
Ok(inputs)
120119
}

‎rust/tools/index-files.cmd‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@echo off
22

3-
type NUL && "%CODEQL_EXTRACTOR_RUST_ROOT%\tools\%CODEQL_PLATFORM%\extractor" @"%1"
3+
type NUL && "%CODEQL_EXTRACTOR_RUST_ROOT%\tools\%CODEQL_PLATFORM%\extractor" ^
4+
--file-list "%1"
45

56
exit /b %ERRORLEVEL%

‎rust/tools/index-files.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
set -eu
44

55
export RUST_BACKTRACE=1
6-
exec "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor" @"$1"
6+
exec "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor" \
7+
--file-list "$1"

0 commit comments

Comments
 (0)