From 0a8e9366fd7d889ac4b399cd9dc3cef994bc6a9b Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 26 Nov 2026 13:14:53 +0100 Subject: [PATCH 1/4] Shared: Add extractor-common crate Add a crate for parser-independent functionality that is shared across the Rust-based extractors, so that such functionality does not have to live in the tree-sitter-specific `codeql-extractor` crate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c30357-9ac7-4fd6-ac9c-f6fc837aa378 --- Cargo.lock | 4 +++ Cargo.toml | 1 + .../3rdparty/rust_workspace_deps/crates.bzl | 25 +++++++++++++++++++ shared/extractor-common/BUILD.bazel | 10 ++++++++ shared/extractor-common/Cargo.toml | 8 ++++++ shared/extractor-common/README.md | 3 +++ shared/extractor-common/src/lib.rs | 1 + 7 files changed, 52 insertions(+) create mode 100644 shared/extractor-common/BUILD.bazel create mode 100644 shared/extractor-common/Cargo.toml create mode 100644 shared/extractor-common/README.md create mode 100644 shared/extractor-common/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index c15fc50a8c37..f282af68ba3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1022,6 +1022,10 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "extractor-common" +version = "0.1.0" + [[package]] name = "fastrand" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index a726a12210f8..38e4b66809f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ resolver = "2" members = [ + "shared/extractor-common", "shared/tree-sitter-extractor", "shared/yeast", "shared/yeast-macros", diff --git a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl index dab963f5cedd..6e014b191839 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl +++ b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl @@ -324,6 +324,7 @@ _CRATE_EDITIONS = { "rust/autobuild": "2024", "rust/extractor": "2024", "rust/extractor/macros": "2024", + "shared/extractor-common": "2024", "shared/tree-sitter-extractor": "2024", "shared/yeast": "2021", "shared/yeast-macros": "2021", @@ -462,6 +463,8 @@ _NORMAL_DEPENDENCIES = { "syn": Label("@vendor_rs//syn-3.0.9"), }, }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { _COMMON_CONDITION: { "chrono": Label("@vendor_rs//chrono-0.4.45"), @@ -560,6 +563,8 @@ _NORMAL_ALIASES = { _COMMON_CONDITION: { }, }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { _COMMON_CONDITION: { }, @@ -607,6 +612,8 @@ _NORMAL_DEV_DEPENDENCIES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { _COMMON_CONDITION: { "rand": Label("@vendor_rs//rand-0.10.3"), @@ -649,6 +656,8 @@ _NORMAL_DEV_ALIASES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { _COMMON_CONDITION: { }, @@ -688,6 +697,8 @@ _PROC_MACRO_DEPENDENCIES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { }, "shared/yeast": { @@ -725,6 +736,8 @@ _PROC_MACRO_ALIASES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { }, "shared/yeast": { @@ -762,6 +775,8 @@ _PROC_MACRO_DEV_DEPENDENCIES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { }, "shared/yeast": { @@ -799,6 +814,8 @@ _PROC_MACRO_DEV_ALIASES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { _COMMON_CONDITION: { }, @@ -844,6 +861,8 @@ _BUILD_DEPENDENCIES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { }, "shared/yeast": { @@ -885,6 +904,8 @@ _BUILD_ALIASES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { }, "shared/yeast": { @@ -922,6 +943,8 @@ _BUILD_PROC_MACRO_DEPENDENCIES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { }, "shared/yeast": { @@ -959,6 +982,8 @@ _BUILD_PROC_MACRO_ALIASES = { }, "rust/extractor/macros": { }, + "shared/extractor-common": { + }, "shared/tree-sitter-extractor": { }, "shared/yeast": { diff --git a/shared/extractor-common/BUILD.bazel b/shared/extractor-common/BUILD.bazel new file mode 100644 index 000000000000..ab2ba3756976 --- /dev/null +++ b/shared/extractor-common/BUILD.bazel @@ -0,0 +1,10 @@ +load("@rules_rust//rust:defs.bzl", "rust_library") + +exports_files(["Cargo.toml"]) + +rust_library( + name = "extractor-common", + srcs = glob(["src/**/*.rs"]), + crate_name = "extractor_common", + visibility = ["//visibility:public"], +) diff --git a/shared/extractor-common/Cargo.toml b/shared/extractor-common/Cargo.toml new file mode 100644 index 000000000000..56bc5e6cd9a9 --- /dev/null +++ b/shared/extractor-common/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "extractor-common" +description = "Code shared between the extractors." +version = "0.1.0" +edition = "2024" + +[lints] +workspace = true diff --git a/shared/extractor-common/README.md b/shared/extractor-common/README.md new file mode 100644 index 000000000000..78f56102ba02 --- /dev/null +++ b/shared/extractor-common/README.md @@ -0,0 +1,3 @@ +# extractor-common + +This package contains code shared between the Rust extractors. diff --git a/shared/extractor-common/src/lib.rs b/shared/extractor-common/src/lib.rs new file mode 100644 index 000000000000..8b3ba0ffe601 --- /dev/null +++ b/shared/extractor-common/src/lib.rs @@ -0,0 +1 @@ +//! Parser-independent utilities shared by CodeQL extractors. From 67dc1081ef9092f5811fd4c6b00eb7742911be24 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 26 Nov 2026 13:15:05 +0100 Subject: [PATCH 2/4] Shared: Move file_paths to extractor-common Move the `file_paths` module, which does not depend on tree-sitter, from `codeql-extractor` to the new `extractor-common` crate and update all extractors that use it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c30357-9ac7-4fd6-ac9c-f6fc837aa378 --- Cargo.lock | 3 +++ ruby/extractor/BUILD.bazel | 1 + ruby/extractor/Cargo.toml | 1 + ruby/extractor/src/extractor.rs | 4 ++-- rust/extractor/BUILD.bazel | 1 + rust/extractor/Cargo.toml | 1 + rust/extractor/src/archive.rs | 2 +- rust/extractor/src/trap.rs | 3 ++- .../src/file_paths.rs | 0 shared/extractor-common/src/lib.rs | 2 ++ shared/tree-sitter-extractor/BUILD.bazel | 1 + shared/tree-sitter-extractor/Cargo.toml | 1 + shared/tree-sitter-extractor/src/extractor/driver.rs | 12 ++++-------- shared/tree-sitter-extractor/src/extractor/mod.rs | 2 +- shared/tree-sitter-extractor/src/lib.rs | 1 - 15 files changed, 21 insertions(+), 14 deletions(-) rename shared/{tree-sitter-extractor => extractor-common}/src/file_paths.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index f282af68ba3b..e0f2e02c33e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -466,6 +466,7 @@ name = "codeql-extractor" version = "0.2.0" dependencies = [ "chrono", + "extractor-common", "flate2", "globset", "num_cpus", @@ -507,6 +508,7 @@ dependencies = [ "clap", "codeql-extractor", "encoding", + "extractor-common", "rayon", "regex", "serde_json", @@ -546,6 +548,7 @@ dependencies = [ "clap", "codeql-extractor", "dunce", + "extractor-common", "figment", "glob", "itertools 0.15.0", diff --git a/ruby/extractor/BUILD.bazel b/ruby/extractor/BUILD.bazel index b3b990499204..8c93cec30785 100644 --- a/ruby/extractor/BUILD.bazel +++ b/ruby/extractor/BUILD.bazel @@ -14,6 +14,7 @@ codeql_rust_binary( deps = all_crate_deps( normal = True, ) + [ + "//shared/extractor-common", "//shared/tree-sitter-extractor", ], ) diff --git a/ruby/extractor/Cargo.toml b/ruby/extractor/Cargo.toml index 4ca43af279ce..cb6e3e3041dc 100644 --- a/ruby/extractor/Cargo.toml +++ b/ruby/extractor/Cargo.toml @@ -22,3 +22,4 @@ encoding = "0.2" serde_json = "1.0.154" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } +extractor-common = { path = "../../shared/extractor-common" } diff --git a/ruby/extractor/src/extractor.rs b/ruby/extractor/src/extractor.rs index 7956b97d3b6f..3fe2f1834f90 100644 --- a/ruby/extractor/src/extractor.rs +++ b/ruby/extractor/src/extractor.rs @@ -1,5 +1,5 @@ use clap::Args; -use codeql_extractor::file_paths::PathTransformer; +use extractor_common::file_paths::{self, PathTransformer}; use rayon::prelude::*; use std::borrow::Cow; use std::collections::HashSet; @@ -9,7 +9,7 @@ use std::path::{Path, PathBuf}; use std::sync::LazyLock; use tree_sitter::{Language, Parser, Range}; -use codeql_extractor::{diagnostics, extractor, file_paths, node_types, trap}; +use codeql_extractor::{diagnostics, extractor, node_types, trap}; #[derive(Args)] pub struct Options { diff --git a/rust/extractor/BUILD.bazel b/rust/extractor/BUILD.bazel index 92882b2b5f32..3c6e76f1ed1b 100644 --- a/rust/extractor/BUILD.bazel +++ b/rust/extractor/BUILD.bazel @@ -20,6 +20,7 @@ codeql_rust_binary( deps = all_crate_deps( normal = True, ) + [ + "//shared/extractor-common", "//shared/tree-sitter-extractor", ], ) diff --git a/rust/extractor/Cargo.toml b/rust/extractor/Cargo.toml index 15ac0510f844..2d2291cc1a27 100644 --- a/rust/extractor/Cargo.toml +++ b/rust/extractor/Cargo.toml @@ -34,6 +34,7 @@ serde = "1.0.229" serde_with = "3.24.0" triomphe = "0.1.17" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } +extractor-common = { path = "../../shared/extractor-common" } rust-extractor-macros = { path = "macros" } itertools = "0.15.0" glob = "0.3.4" diff --git a/rust/extractor/src/archive.rs b/rust/extractor/src/archive.rs index 2cc3be227016..125d86e1775a 100644 --- a/rust/extractor/src/archive.rs +++ b/rust/extractor/src/archive.rs @@ -1,4 +1,4 @@ -use codeql_extractor::file_paths; +use extractor_common::file_paths; use std::fs; use std::path::{Path, PathBuf}; use tracing::{debug, warn}; diff --git a/rust/extractor/src/trap.rs b/rust/extractor/src/trap.rs index 31e9f2122d70..0dd665eea393 100644 --- a/rust/extractor/src/trap.rs +++ b/rust/extractor/src/trap.rs @@ -1,5 +1,6 @@ use crate::{config, generated}; -use codeql_extractor::{extractor, file_paths, trap}; +use codeql_extractor::{extractor, trap}; +use extractor_common::file_paths; use ra_ap_ide_db::line_index::LineCol; use std::fmt::Debug; use std::hash::Hash; diff --git a/shared/tree-sitter-extractor/src/file_paths.rs b/shared/extractor-common/src/file_paths.rs similarity index 100% rename from shared/tree-sitter-extractor/src/file_paths.rs rename to shared/extractor-common/src/file_paths.rs diff --git a/shared/extractor-common/src/lib.rs b/shared/extractor-common/src/lib.rs index 8b3ba0ffe601..8ecc127546ef 100644 --- a/shared/extractor-common/src/lib.rs +++ b/shared/extractor-common/src/lib.rs @@ -1 +1,3 @@ //! Parser-independent utilities shared by CodeQL extractors. + +pub mod file_paths; diff --git a/shared/tree-sitter-extractor/BUILD.bazel b/shared/tree-sitter-extractor/BUILD.bazel index 43e878a1bf51..39ce000c5ba6 100644 --- a/shared/tree-sitter-extractor/BUILD.bazel +++ b/shared/tree-sitter-extractor/BUILD.bazel @@ -13,6 +13,7 @@ rust_library( "src/generator/prefix.dbscheme", ], deps = all_crate_deps() + [ + "//shared/extractor-common", "//shared/yeast", ], ) diff --git a/shared/tree-sitter-extractor/Cargo.toml b/shared/tree-sitter-extractor/Cargo.toml index 582b284a1da8..a0424cd9addf 100644 --- a/shared/tree-sitter-extractor/Cargo.toml +++ b/shared/tree-sitter-extractor/Cargo.toml @@ -9,6 +9,7 @@ workspace = true # When updating these dependencies, run `rust/update_cargo_deps.sh` [dependencies] +extractor-common = { path = "../extractor-common" } flate2 = "1.1" globset = "0.4" tree-sitter = ">= 0.23.0" diff --git a/shared/tree-sitter-extractor/src/extractor/driver.rs b/shared/tree-sitter-extractor/src/extractor/driver.rs index 8a6ee33accc9..14993da9f915 100644 --- a/shared/tree-sitter-extractor/src/extractor/driver.rs +++ b/shared/tree-sitter-extractor/src/extractor/driver.rs @@ -6,6 +6,7 @@ //! by glob, writing TRAP, and copying into the source archive — is identical //! and lives here, parameterised over the [`LanguageExtractor`] trait. +use extractor_common::file_paths; use globset::{GlobBuilder, GlobSetBuilder}; use rayon::prelude::*; use std::fs::File; @@ -13,7 +14,6 @@ use std::io::BufRead; use std::path::{Path, PathBuf}; use crate::diagnostics; -use crate::file_paths; use crate::node_types::NodeTypeMap; use crate::trap; @@ -147,12 +147,8 @@ pub(crate) fn run_extractor( .try_for_each(|line| { let mut diagnostics_writer = diagnostics.logger(); let path = PathBuf::from(line).canonicalize()?; - let src_archive_file = crate::file_paths::path_for( - source_archive_dir, - &path, - "", - path_transformer.as_ref(), - ); + let src_archive_file = + file_paths::path_for(source_archive_dir, &path, "", path_transformer.as_ref()); let source = std::fs::read(&path)?; let mut trap_writer = trap::Writer::new(); @@ -219,7 +215,7 @@ fn write_trap( trap_writer: &trap::Writer, trap_compression: trap::Compression, ) -> std::io::Result<()> { - let trap_file = crate::file_paths::path_for(trap_dir, path, trap_compression.extension(), None); + let trap_file = file_paths::path_for(trap_dir, path, trap_compression.extension(), None); std::fs::create_dir_all(trap_file.parent().unwrap())?; trap_writer.write_to_file(&trap_file, trap_compression) } diff --git a/shared/tree-sitter-extractor/src/extractor/mod.rs b/shared/tree-sitter-extractor/src/extractor/mod.rs index 5a1856c76fbc..29a290a96bf3 100644 --- a/shared/tree-sitter-extractor/src/extractor/mod.rs +++ b/shared/tree-sitter-extractor/src/extractor/mod.rs @@ -1,7 +1,7 @@ use crate::diagnostics; -use crate::file_paths; use crate::node_types::{self, EntryKind, Field, NodeTypeMap, Storage, TypeName}; use crate::trap; +use extractor_common::file_paths; use std::collections::BTreeMap as Map; use std::collections::BTreeSet as Set; use std::env; diff --git a/shared/tree-sitter-extractor/src/lib.rs b/shared/tree-sitter-extractor/src/lib.rs index b83c4951b73c..dfc5446f657e 100644 --- a/shared/tree-sitter-extractor/src/lib.rs +++ b/shared/tree-sitter-extractor/src/lib.rs @@ -1,7 +1,6 @@ pub mod autobuilder; pub mod diagnostics; pub mod extractor; -pub mod file_paths; pub mod generator; pub mod node_types; pub mod options; From 6fbc9dc19c5ce69ce904222a1e780de585b8efb9 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 26 Nov 2026 13:15:08 +0100 Subject: [PATCH 3/4] CI: Test extractor-common alongside tree-sitter-extractor Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c30357-9ac7-4fd6-ac9c-f6fc837aa378 --- .github/workflows/ql-for-ql-build.yml | 2 +- .github/workflows/tree-sitter-extractor-test.yml | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ql-for-ql-build.yml b/.github/workflows/ql-for-ql-build.yml index 6ee75fa86b65..0e7b1b91d438 100644 --- a/.github/workflows/ql-for-ql-build.yml +++ b/.github/workflows/ql-for-ql-build.yml @@ -37,7 +37,7 @@ jobs: path: | ql/extractor-pack/ target/release/buramu - key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}-${{ hashFiles('shared/tree-sitter-extractor') }}-${{ hashFiles('ql/**/*.rs') }} + key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}-${{ hashFiles('shared/tree-sitter-extractor') }}-${{ hashFiles('shared/extractor-common/**/*.rs') }}-${{ hashFiles('ql/**/*.rs') }} - name: Cache cargo if: steps.cache-extractor.outputs.cache-hit != 'true' uses: actions/cache@v3 diff --git a/.github/workflows/tree-sitter-extractor-test.yml b/.github/workflows/tree-sitter-extractor-test.yml index 932146b3d6a3..0d866d377514 100644 --- a/.github/workflows/tree-sitter-extractor-test.yml +++ b/.github/workflows/tree-sitter-extractor-test.yml @@ -3,6 +3,7 @@ name: Test tree-sitter-extractor on: push: paths: &tree_sitter_paths + - "shared/extractor-common/**" - "shared/tree-sitter-extractor/**" - Cargo.toml - Cargo.lock @@ -33,18 +34,18 @@ jobs: steps: - uses: actions/checkout@v5 - name: Check formatting - run: cargo fmt -- --check + run: cargo fmt -p extractor-common -p codeql-extractor -- --check - name: Run tests - run: cargo test --verbose + run: cargo test -p extractor-common -p codeql-extractor --verbose fmt: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - name: Check formatting - run: cargo fmt --check + run: cargo fmt -p extractor-common -p codeql-extractor --check clippy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - name: Run clippy - run: cargo clippy -- --no-deps -D warnings + run: cargo clippy -p extractor-common -p codeql-extractor --no-deps -- -D warnings From 9a3b337422cd68e2d46f49bb021c540a0beba24c Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 26 Nov 2026 14:53:17 +0100 Subject: [PATCH 4/4] Ruby: Include extractor-common in cache key Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c30357-9ac7-4fd6-ac9c-f6fc837aa378 --- ruby/actions/create-extractor-pack/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/actions/create-extractor-pack/action.yml b/ruby/actions/create-extractor-pack/action.yml index d8bba46064bd..6e07ca1a24df 100644 --- a/ruby/actions/create-extractor-pack/action.yml +++ b/ruby/actions/create-extractor-pack/action.yml @@ -10,7 +10,7 @@ runs: uses: actions/cache@v4 with: path: ruby/extractor-pack - key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/scripts/create-extractor-pack.sh', 'ruby/extractor/**/Cargo.lock', 'ruby/actions/create-extractor-pack/action.yml') }}-${{ hashFiles('shared/tree-sitter-extractor') }}-${{ hashFiles('ruby/extractor/**/*.rs') }}-${{ hashFiles('ruby/codeql-extractor.yml', 'ruby/downgrades', 'ruby/tools', 'ruby/ql/lib/ruby.dbscheme', 'ruby/ql/lib/ruby.dbscheme.stats') }} + key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'ruby/extractor/Cargo.toml', 'ruby/extractor/rust-toolchain.toml', 'ruby/scripts/create-extractor-pack.sh', 'ruby/extractor/**/Cargo.lock', 'ruby/actions/create-extractor-pack/action.yml') }}-${{ hashFiles('shared/tree-sitter-extractor/**', 'shared/tree-sitter-extractor/Cargo.toml', 'shared/extractor-common/**', 'shared/extractor-common/Cargo.toml') }}-${{ hashFiles('ruby/extractor/**/*.rs') }}-${{ hashFiles('ruby/codeql-extractor.yml', 'ruby/downgrades', 'ruby/tools', 'ruby/ql/lib/ruby.dbscheme', 'ruby/ql/lib/ruby.dbscheme.stats') }} - name: Cache cargo uses: actions/cache@v4 if: steps.cache-extractor.outputs.cache-hit != 'true'