Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ql-for-ql-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/tree-sitter-extractor-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

resolver = "2"
members = [
"shared/extractor-common",
"shared/tree-sitter-extractor",
"shared/yeast",
"shared/yeast-macros",
Expand Down
25 changes: 25 additions & 0 deletions misc/bazel/3rdparty/rust_workspace_deps/crates.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ruby/actions/create-extractor-pack/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions ruby/extractor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ codeql_rust_binary(
deps = all_crate_deps(
normal = True,
) + [
"//shared/extractor-common",
"//shared/tree-sitter-extractor",
],
)
1 change: 1 addition & 0 deletions ruby/extractor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Comment thread
paldepind marked this conversation as resolved.
Resolved
4 changes: 2 additions & 2 deletions ruby/extractor/src/extractor.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions rust/extractor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ codeql_rust_binary(
deps = all_crate_deps(
normal = True,
) + [
"//shared/extractor-common",
"//shared/tree-sitter-extractor",
],
)
1 change: 1 addition & 0 deletions rust/extractor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion rust/extractor/src/archive.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 2 additions & 1 deletion rust/extractor/src/trap.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 10 additions & 0 deletions shared/extractor-common/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
8 changes: 8 additions & 0 deletions shared/extractor-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "extractor-common"
description = "Code shared between the extractors."
version = "0.1.0"
edition = "2024"

[lints]
workspace = true
3 changes: 3 additions & 0 deletions shared/extractor-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# extractor-common

This package contains code shared between the Rust extractors.
3 changes: 3 additions & 0 deletions shared/extractor-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Parser-independent utilities shared by CodeQL extractors.

pub mod file_paths;
1 change: 1 addition & 0 deletions shared/tree-sitter-extractor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rust_library(
"src/generator/prefix.dbscheme",
],
deps = all_crate_deps() + [
"//shared/extractor-common",
"//shared/yeast",
],
)
Expand Down
1 change: 1 addition & 0 deletions shared/tree-sitter-extractor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 4 additions & 8 deletions shared/tree-sitter-extractor/src/extractor/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//! 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;
use std::io::BufRead;
use std::path::{Path, PathBuf};

use crate::diagnostics;
use crate::file_paths;
use crate::node_types::NodeTypeMap;
use crate::trap;

Expand Down Expand Up @@ -147,12 +147,8 @@ pub(crate) fn run_extractor<L: LanguageExtractor>(
.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();

Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion shared/tree-sitter-extractor/src/extractor/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion shared/tree-sitter-extractor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading