Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: fix qltest logging #18882

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
22 changes: 20 additions & 2 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions rust/codeql-extractor.yml
Original file line number Diff line number Diff line change
@@ -78,3 +78,9 @@ options:
Collect flame graph data using the `tracing-flame` crate. To render a flame graph
or chart, run the `inferno-flamegraph` command. See also: https://crates.io/crates/tracing-flame
type: string
color:
title: Enable or disable colored output
description: >
Enable or disable colored output in the extractor log. Currently the default is to enable it.
type: string
pattern: "^(yes|no)$"
1 change: 1 addition & 0 deletions rust/extractor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -39,3 +39,4 @@ toml = "0.8.19"
tracing = "0.1.41"
tracing-flame = "0.2.0"
tracing-subscriber = "0.3.19"
is-terminal = "0.4.15"
19 changes: 19 additions & 0 deletions rust/extractor/src/config.rs
Original file line number Diff line number Diff line change
@@ -31,6 +31,24 @@ pub enum Compression {
Gzip,
}

#[derive(Debug, PartialEq, Eq, Default, Serialize, Deserialize, Clone, Copy, clap::ValueEnum)]
#[serde(rename_all = "lowercase")]
#[clap(rename_all = "lowercase")]
pub enum Color {
#[default]
Yes,
No,
}

impl Color {
pub fn yes(&self) -> bool {
match self {
Color::Yes => true,
Color::No => false,
}
}
}

impl From<Compression> for trap::Compression {
fn from(val: Compression) -> Self {
match val {
@@ -55,6 +73,7 @@ pub struct Config {
pub cargo_all_targets: bool,
pub logging_flamegraph: Option<PathBuf>,
pub logging_verbosity: Option<String>,
pub logging_color: Color,
pub compression: Compression,
pub inputs: Vec<PathBuf>,
pub qltest: bool,
2 changes: 2 additions & 0 deletions rust/extractor/src/main.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ use crate::rust_analyzer::path_to_file_id;
use crate::trap::TrapId;
use anyhow::Context;
use archive::Archiver;
use codeql_extractor::extractor::Color;
use ra_ap_hir::Semantics;
use ra_ap_ide_db::line_index::{LineCol, LineIndex};
use ra_ap_ide_db::RootDatabase;
@@ -201,6 +202,7 @@ fn main() -> anyhow::Result<()> {
.with(codeql_extractor::extractor::default_subscriber_with_level(
"single_arch",
&cfg.logging_verbosity,
Color::from(cfg.logging_color.yes()),
))
.with(flame_layer)
.init();
7 changes: 6 additions & 1 deletion rust/tools/qltest.sh
Original file line number Diff line number Diff line change
@@ -4,7 +4,12 @@ set -eu

export RUST_BACKTRACE=full
QLTEST_LOG="$CODEQL_EXTRACTOR_RUST_LOG_DIR"/qltest.log
if ! "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor" --qltest >> "$QLTEST_LOG" 2>&1; then
EXTRACTOR_OPTS=(
--qltest
--logging-verbosity=progress+
--logging-color=no
)
if ! "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor" "${EXTRACTOR_OPTS[@]}" >> "$QLTEST_LOG" 2>&1; then
cat "$QLTEST_LOG"
exit 1
fi
25 changes: 24 additions & 1 deletion shared/tree-sitter-extractor/src/extractor/mod.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use crate::diagnostics;
use crate::file_paths;
use crate::node_types::{self, EntryKind, Field, NodeTypeMap, Storage, TypeName};
use crate::trap;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap as Map;
use std::collections::BTreeSet as Set;
use std::env;
@@ -18,13 +19,33 @@ use tree_sitter::{Language, Node, Parser, Range, Tree};

pub mod simple;

#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub enum Color {
Yes,
No,
}

impl Color {
pub fn from(condition: bool) -> Self {
if condition {
Color::Yes
} else {
Color::No
}
}
}

/// Sets the tracing level based on the environment variables
/// `RUST_LOG` and `CODEQL_VERBOSITY` (prioritized in that order),
/// falling back to `warn` if neither is set.
pub fn set_tracing_level(language: &str) {
let verbosity = env::var("CODEQL_VERBOSITY").ok();
tracing_subscriber::registry()
.with(default_subscriber_with_level(language, &verbosity))
.with(default_subscriber_with_level(
language,
&verbosity,
Color::Yes,
))
.init();
}

@@ -33,6 +54,7 @@ pub fn set_tracing_level(language: &str) {
pub fn default_subscriber_with_level(
language: &str,
verbosity: &Option<String>,
color: Color,
) -> Filtered<
tracing_subscriber::fmt::Layer<
tracing_subscriber::Registry,
@@ -46,6 +68,7 @@ pub fn default_subscriber_with_level(
.with_target(false)
.without_time()
.with_level(true)
.with_ansi(color == Color::Yes)
.with_filter(
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(
|_| -> tracing_subscriber::EnvFilter {
Loading
Oops, something went wrong.