From c602e82ac42d03fe0e008433c465cf2664423390 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Thu, 23 Jan 2025 16:03:16 +0100 Subject: [PATCH 1/6] Rust: use tracing-subscriber --- Cargo.lock | 57 ++---- MODULE.bazel | 3 +- .../tree_sitter_extractors_deps/BUILD.bazel | 36 ++-- .../BUILD.hermit-abi-0.4.0.bazel | 83 --------- .../BUILD.is-terminal-0.4.13.bazel | 170 ------------------ .../BUILD.termcolor-1.1.3.bazel | 95 ---------- ....bazel => BUILD.tracing-flame-0.2.0.bazel} | 17 +- .../BUILD.windows-sys-0.52.0.bazel | 3 - .../tree_sitter_extractors_deps/defs.bzl | 59 ++---- rust/extractor/Cargo.toml | 5 +- rust/extractor/src/archive.rs | 2 +- rust/extractor/src/diagnostics.rs | 2 +- rust/extractor/src/main.rs | 22 ++- rust/extractor/src/qltest.rs | 2 +- rust/extractor/src/rust_analyzer.rs | 6 +- rust/extractor/src/translate/base.rs | 44 +++-- rust/extractor/src/trap.rs | 2 +- .../src/extractor/mod.rs | 31 +++- 18 files changed, 132 insertions(+), 507 deletions(-) delete mode 100644 misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.hermit-abi-0.4.0.bazel delete mode 100644 misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.is-terminal-0.4.13.bazel delete mode 100644 misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.termcolor-1.1.3.bazel rename misc/bazel/3rdparty/tree_sitter_extractors_deps/{BUILD.stderrlog-0.6.0.bazel => BUILD.tracing-flame-0.2.0.bazel} (90%) diff --git a/Cargo.lock b/Cargo.lock index 9e30973bcb6b..48aa23d25ea3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -415,7 +415,6 @@ dependencies = [ "figment", "glob", "itertools 0.14.0", - "log 0.4.22", "num-traits", "ra_ap_base_db", "ra_ap_cfg", @@ -435,8 +434,10 @@ dependencies = [ "serde", "serde_json", "serde_with", - "stderrlog", "toml", + "tracing", + "tracing-flame", + "tracing-subscriber", "triomphe", ] @@ -800,12 +801,6 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" -[[package]] -name = "hermit-abi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" - [[package]] name = "hex" version = "0.4.3" @@ -898,17 +893,6 @@ dependencies = [ "libc", ] -[[package]] -name = "is-terminal" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" -dependencies = [ - "hermit-abi 0.4.0", - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -1165,7 +1149,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.9", + "hermit-abi", "libc", ] @@ -2190,19 +2174,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "stderrlog" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c910772f992ab17d32d6760e167d2353f4130ed50e796752689556af07dc6b" -dependencies = [ - "chrono", - "is-terminal", - "log 0.4.22", - "termcolor", - "thread_local", -] - [[package]] name = "streaming-iterator" version = "0.1.9" @@ -2237,15 +2208,6 @@ dependencies = [ "syn", ] -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - [[package]] name = "text-size" version = "1.1.1" @@ -2379,6 +2341,17 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-flame" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bae117ee14789185e129aaee5d93750abe67fdc5a9a62650452bfe4e122a3a9" +dependencies = [ + "lazy_static", + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-log" version = "0.2.0" diff --git a/MODULE.bazel b/MODULE.bazel index 385860767730..1874a7fb8b30 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -87,7 +87,6 @@ use_repo( "vendor__globset-0.4.15", "vendor__itertools-0.14.0", "vendor__lazy_static-1.5.0", - "vendor__log-0.4.22", "vendor__mustache-0.9.0", "vendor__num-traits-0.2.19", "vendor__num_cpus-1.16.0", @@ -114,10 +113,10 @@ use_repo( "vendor__serde-1.0.217", "vendor__serde_json-1.0.135", "vendor__serde_with-3.12.0", - "vendor__stderrlog-0.6.0", "vendor__syn-2.0.96", "vendor__toml-0.8.19", "vendor__tracing-0.1.41", + "vendor__tracing-flame-0.2.0", "vendor__tracing-subscriber-0.3.19", "vendor__tree-sitter-0.24.6", "vendor__tree-sitter-embedded-template-0.23.2", diff --git a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.bazel b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.bazel index ca9eaaf86c9b..952ad2432905 100644 --- a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.bazel +++ b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.bazel @@ -187,18 +187,6 @@ alias( tags = ["manual"], ) -alias( - name = "log-0.4.22", - actual = "@vendor__log-0.4.22//:log", - tags = ["manual"], -) - -alias( - name = "log", - actual = "@vendor__log-0.4.22//:log", - tags = ["manual"], -) - alias( name = "mustache-0.9.0", actual = "@vendor__mustache-0.9.0//:mustache", @@ -517,18 +505,6 @@ alias( tags = ["manual"], ) -alias( - name = "stderrlog-0.6.0", - actual = "@vendor__stderrlog-0.6.0//:stderrlog", - tags = ["manual"], -) - -alias( - name = "stderrlog", - actual = "@vendor__stderrlog-0.6.0//:stderrlog", - tags = ["manual"], -) - alias( name = "syn-2.0.96", actual = "@vendor__syn-2.0.96//:syn", @@ -565,6 +541,18 @@ alias( tags = ["manual"], ) +alias( + name = "tracing-flame-0.2.0", + actual = "@vendor__tracing-flame-0.2.0//:tracing_flame", + tags = ["manual"], +) + +alias( + name = "tracing-flame", + actual = "@vendor__tracing-flame-0.2.0//:tracing_flame", + tags = ["manual"], +) + alias( name = "tracing-subscriber-0.3.19", actual = "@vendor__tracing-subscriber-0.3.19//:tracing_subscriber", diff --git a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.hermit-abi-0.4.0.bazel b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.hermit-abi-0.4.0.bazel deleted file mode 100644 index c6ebd68edc32..000000000000 --- a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.hermit-abi-0.4.0.bazel +++ /dev/null @@ -1,83 +0,0 @@ -############################################################################### -# @generated -# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To -# regenerate this file, run the following: -# -# bazel run @@//misc/bazel/3rdparty:vendor_tree_sitter_extractors -############################################################################### - -load("@rules_rust//rust:defs.bzl", "rust_library") - -package(default_visibility = ["//visibility:public"]) - -rust_library( - name = "hermit_abi", - srcs = glob( - include = ["**/*.rs"], - allow_empty = True, - ), - compile_data = glob( - include = ["**"], - allow_empty = True, - exclude = [ - "**/* *", - ".tmp_git_root/**/*", - "BUILD", - "BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - ], - ), - crate_root = "src/lib.rs", - edition = "2021", - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-bazel", - "crate-name=hermit-abi", - "manual", - "noclippy", - "norustfmt", - ], - target_compatible_with = select({ - "@rules_rust//rust/platform:aarch64-apple-darwin": [], - "@rules_rust//rust/platform:aarch64-apple-ios": [], - "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], - "@rules_rust//rust/platform:aarch64-linux-android": [], - "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], - "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], - "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], - "@rules_rust//rust/platform:aarch64-unknown-uefi": [], - "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:armv7-linux-androideabi": [], - "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:i686-apple-darwin": [], - "@rules_rust//rust/platform:i686-linux-android": [], - "@rules_rust//rust/platform:i686-pc-windows-msvc": [], - "@rules_rust//rust/platform:i686-unknown-freebsd": [], - "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], - "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], - "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], - "@rules_rust//rust/platform:thumbv7em-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], - "@rules_rust//rust/platform:wasm32-unknown-unknown": [], - "@rules_rust//rust/platform:wasm32-wasip1": [], - "@rules_rust//rust/platform:x86_64-apple-darwin": [], - "@rules_rust//rust/platform:x86_64-apple-ios": [], - "@rules_rust//rust/platform:x86_64-linux-android": [], - "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], - "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], - "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-none": [], - "@rules_rust//rust/platform:x86_64-unknown-uefi": [], - "//conditions:default": ["@platforms//:incompatible"], - }), - version = "0.4.0", -) diff --git a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.is-terminal-0.4.13.bazel b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.is-terminal-0.4.13.bazel deleted file mode 100644 index b869c77744b1..000000000000 --- a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.is-terminal-0.4.13.bazel +++ /dev/null @@ -1,170 +0,0 @@ -############################################################################### -# @generated -# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To -# regenerate this file, run the following: -# -# bazel run @@//misc/bazel/3rdparty:vendor_tree_sitter_extractors -############################################################################### - -load("@rules_rust//rust:defs.bzl", "rust_library") - -package(default_visibility = ["//visibility:public"]) - -rust_library( - name = "is_terminal", - srcs = glob( - include = ["**/*.rs"], - allow_empty = True, - ), - compile_data = glob( - include = ["**"], - allow_empty = True, - exclude = [ - "**/* *", - ".tmp_git_root/**/*", - "BUILD", - "BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - ], - ), - crate_root = "src/lib.rs", - edition = "2018", - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-bazel", - "crate-name=is-terminal", - "manual", - "noclippy", - "norustfmt", - ], - target_compatible_with = select({ - "@rules_rust//rust/platform:aarch64-apple-darwin": [], - "@rules_rust//rust/platform:aarch64-apple-ios": [], - "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], - "@rules_rust//rust/platform:aarch64-linux-android": [], - "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], - "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], - "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], - "@rules_rust//rust/platform:aarch64-unknown-uefi": [], - "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:armv7-linux-androideabi": [], - "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:i686-apple-darwin": [], - "@rules_rust//rust/platform:i686-linux-android": [], - "@rules_rust//rust/platform:i686-pc-windows-msvc": [], - "@rules_rust//rust/platform:i686-unknown-freebsd": [], - "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], - "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], - "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], - "@rules_rust//rust/platform:thumbv7em-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], - "@rules_rust//rust/platform:wasm32-unknown-unknown": [], - "@rules_rust//rust/platform:wasm32-wasip1": [], - "@rules_rust//rust/platform:x86_64-apple-darwin": [], - "@rules_rust//rust/platform:x86_64-apple-ios": [], - "@rules_rust//rust/platform:x86_64-linux-android": [], - "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], - "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], - "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-none": [], - "@rules_rust//rust/platform:x86_64-unknown-uefi": [], - "//conditions:default": ["@platforms//:incompatible"], - }), - version = "0.4.13", - deps = select({ - "@rules_rust//rust/platform:aarch64-apple-darwin": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:aarch64-apple-ios": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:aarch64-apple-ios-sim": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:aarch64-linux-android": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor__windows-sys-0.52.0//:windows_sys", # cfg(windows) - ], - "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:armv7-linux-androideabi": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:i686-apple-darwin": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:i686-linux-android": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor__windows-sys-0.52.0//:windows_sys", # cfg(windows) - ], - "@rules_rust//rust/platform:i686-unknown-freebsd": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:i686-unknown-linux-gnu": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:wasm32-wasip1": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:x86_64-apple-darwin": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:x86_64-apple-ios": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:x86_64-linux-android": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor__windows-sys-0.52.0//:windows_sys", # cfg(windows) - ], - "@rules_rust//rust/platform:x86_64-unknown-freebsd": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [ - "@vendor__libc-0.2.169//:libc", # cfg(any(unix, target_os = "wasi")) - ], - "//conditions:default": [], - }), -) diff --git a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.termcolor-1.1.3.bazel b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.termcolor-1.1.3.bazel deleted file mode 100644 index 80d2e6662562..000000000000 --- a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.termcolor-1.1.3.bazel +++ /dev/null @@ -1,95 +0,0 @@ -############################################################################### -# @generated -# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To -# regenerate this file, run the following: -# -# bazel run @@//misc/bazel/3rdparty:vendor_tree_sitter_extractors -############################################################################### - -load("@rules_rust//rust:defs.bzl", "rust_library") - -package(default_visibility = ["//visibility:public"]) - -rust_library( - name = "termcolor", - srcs = glob( - include = ["**/*.rs"], - allow_empty = True, - ), - compile_data = glob( - include = ["**"], - allow_empty = True, - exclude = [ - "**/* *", - ".tmp_git_root/**/*", - "BUILD", - "BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - ], - ), - crate_root = "src/lib.rs", - edition = "2018", - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-bazel", - "crate-name=termcolor", - "manual", - "noclippy", - "norustfmt", - ], - target_compatible_with = select({ - "@rules_rust//rust/platform:aarch64-apple-darwin": [], - "@rules_rust//rust/platform:aarch64-apple-ios": [], - "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], - "@rules_rust//rust/platform:aarch64-linux-android": [], - "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], - "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], - "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], - "@rules_rust//rust/platform:aarch64-unknown-uefi": [], - "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:armv7-linux-androideabi": [], - "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:i686-apple-darwin": [], - "@rules_rust//rust/platform:i686-linux-android": [], - "@rules_rust//rust/platform:i686-pc-windows-msvc": [], - "@rules_rust//rust/platform:i686-unknown-freebsd": [], - "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], - "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], - "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], - "@rules_rust//rust/platform:thumbv7em-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], - "@rules_rust//rust/platform:wasm32-unknown-unknown": [], - "@rules_rust//rust/platform:wasm32-wasip1": [], - "@rules_rust//rust/platform:x86_64-apple-darwin": [], - "@rules_rust//rust/platform:x86_64-apple-ios": [], - "@rules_rust//rust/platform:x86_64-linux-android": [], - "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], - "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], - "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-none": [], - "@rules_rust//rust/platform:x86_64-unknown-uefi": [], - "//conditions:default": ["@platforms//:incompatible"], - }), - version = "1.1.3", - deps = select({ - "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor__winapi-util-0.1.9//:winapi_util", # cfg(windows) - ], - "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor__winapi-util-0.1.9//:winapi_util", # cfg(windows) - ], - "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor__winapi-util-0.1.9//:winapi_util", # cfg(windows) - ], - "//conditions:default": [], - }), -) diff --git a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.stderrlog-0.6.0.bazel b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.tracing-flame-0.2.0.bazel similarity index 90% rename from misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.stderrlog-0.6.0.bazel rename to misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.tracing-flame-0.2.0.bazel index c428b2cb8e9f..978d69bb0ef3 100644 --- a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.stderrlog-0.6.0.bazel +++ b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.tracing-flame-0.2.0.bazel @@ -11,7 +11,7 @@ load("@rules_rust//rust:defs.bzl", "rust_library") package(default_visibility = ["//visibility:public"]) rust_library( - name = "stderrlog", + name = "tracing_flame", srcs = glob( include = ["**/*.rs"], allow_empty = True, @@ -29,9 +29,8 @@ rust_library( ], ), crate_features = [ - "chrono", "default", - "timestamps", + "smallvec", ], crate_root = "src/lib.rs", edition = "2018", @@ -40,7 +39,7 @@ rust_library( ], tags = [ "cargo-bazel", - "crate-name=stderrlog", + "crate-name=tracing-flame", "manual", "noclippy", "norustfmt", @@ -84,12 +83,10 @@ rust_library( "@rules_rust//rust/platform:x86_64-unknown-uefi": [], "//conditions:default": ["@platforms//:incompatible"], }), - version = "0.6.0", + version = "0.2.0", deps = [ - "@vendor__chrono-0.4.39//:chrono", - "@vendor__is-terminal-0.4.13//:is_terminal", - "@vendor__log-0.4.22//:log", - "@vendor__termcolor-1.1.3//:termcolor", - "@vendor__thread_local-1.1.8//:thread_local", + "@vendor__lazy_static-1.5.0//:lazy_static", + "@vendor__tracing-0.1.41//:tracing", + "@vendor__tracing-subscriber-0.3.19//:tracing_subscriber", ], ) diff --git a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.windows-sys-0.52.0.bazel b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.windows-sys-0.52.0.bazel index e6b17709611c..8d2ee2174e1b 100644 --- a/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.windows-sys-0.52.0.bazel +++ b/misc/bazel/3rdparty/tree_sitter_extractors_deps/BUILD.windows-sys-0.52.0.bazel @@ -31,10 +31,7 @@ rust_library( crate_features = [ "Win32", "Win32_Foundation", - "Win32_Storage", - "Win32_Storage_FileSystem", "Win32_System", - "Win32_System_Console", "Win32_System_ProcessStatus", "Win32_System_Threading", "default", diff --git a/misc/bazel/3rdparty/tree_sitter_extractors_deps/defs.bzl b/misc/bazel/3rdparty/tree_sitter_extractors_deps/defs.bzl index 8cb3ec76d15e..bd5fbaf27ae0 100644 --- a/misc/bazel/3rdparty/tree_sitter_extractors_deps/defs.bzl +++ b/misc/bazel/3rdparty/tree_sitter_extractors_deps/defs.bzl @@ -333,7 +333,6 @@ _NORMAL_DEPENDENCIES = { "figment": Label("@vendor__figment-0.10.19//:figment"), "glob": Label("@vendor__glob-0.3.2//:glob"), "itertools": Label("@vendor__itertools-0.14.0//:itertools"), - "log": Label("@vendor__log-0.4.22//:log"), "num-traits": Label("@vendor__num-traits-0.2.19//:num_traits"), "ra_ap_base_db": Label("@vendor__ra_ap_base_db-0.0.258//:ra_ap_base_db"), "ra_ap_cfg": Label("@vendor__ra_ap_cfg-0.0.258//:ra_ap_cfg"), @@ -352,8 +351,10 @@ _NORMAL_DEPENDENCIES = { "serde": Label("@vendor__serde-1.0.217//:serde"), "serde_json": Label("@vendor__serde_json-1.0.135//:serde_json"), "serde_with": Label("@vendor__serde_with-3.12.0//:serde_with"), - "stderrlog": Label("@vendor__stderrlog-0.6.0//:stderrlog"), "toml": Label("@vendor__toml-0.8.19//:toml"), + "tracing": Label("@vendor__tracing-0.1.41//:tracing"), + "tracing-flame": Label("@vendor__tracing-flame-0.2.0//:tracing_flame"), + "tracing-subscriber": Label("@vendor__tracing-subscriber-0.3.19//:tracing_subscriber"), "triomphe": Label("@vendor__triomphe-0.1.14//:triomphe"), }, }, @@ -594,7 +595,6 @@ _CONDITIONS = { "cfg(any(target_os = \"linux\", target_os = \"android\"))": ["@rules_rust//rust/platform:aarch64-linux-android", "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu", "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", "@rules_rust//rust/platform:armv7-linux-androideabi", "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi", "@rules_rust//rust/platform:i686-linux-android", "@rules_rust//rust/platform:i686-unknown-linux-gnu", "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", "@rules_rust//rust/platform:s390x-unknown-linux-gnu", "@rules_rust//rust/platform:x86_64-linux-android", "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu"], "cfg(any(target_os = \"macos\", target_os = \"ios\"))": ["@rules_rust//rust/platform:aarch64-apple-darwin", "@rules_rust//rust/platform:aarch64-apple-ios", "@rules_rust//rust/platform:aarch64-apple-ios-sim", "@rules_rust//rust/platform:i686-apple-darwin", "@rules_rust//rust/platform:x86_64-apple-darwin", "@rules_rust//rust/platform:x86_64-apple-ios"], "cfg(any(target_pointer_width = \"8\", target_pointer_width = \"16\", target_pointer_width = \"32\"))": ["@rules_rust//rust/platform:arm-unknown-linux-gnueabi", "@rules_rust//rust/platform:armv7-linux-androideabi", "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi", "@rules_rust//rust/platform:i686-apple-darwin", "@rules_rust//rust/platform:i686-linux-android", "@rules_rust//rust/platform:i686-pc-windows-msvc", "@rules_rust//rust/platform:i686-unknown-freebsd", "@rules_rust//rust/platform:i686-unknown-linux-gnu", "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", "@rules_rust//rust/platform:riscv32imc-unknown-none-elf", "@rules_rust//rust/platform:thumbv7em-none-eabi", "@rules_rust//rust/platform:thumbv8m.main-none-eabi", "@rules_rust//rust/platform:wasm32-unknown-unknown", "@rules_rust//rust/platform:wasm32-wasip1"], - "cfg(any(unix, target_os = \"wasi\"))": ["@rules_rust//rust/platform:aarch64-apple-darwin", "@rules_rust//rust/platform:aarch64-apple-ios", "@rules_rust//rust/platform:aarch64-apple-ios-sim", "@rules_rust//rust/platform:aarch64-linux-android", "@rules_rust//rust/platform:aarch64-unknown-fuchsia", "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu", "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710", "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", "@rules_rust//rust/platform:armv7-linux-androideabi", "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi", "@rules_rust//rust/platform:i686-apple-darwin", "@rules_rust//rust/platform:i686-linux-android", "@rules_rust//rust/platform:i686-unknown-freebsd", "@rules_rust//rust/platform:i686-unknown-linux-gnu", "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", "@rules_rust//rust/platform:s390x-unknown-linux-gnu", "@rules_rust//rust/platform:wasm32-wasip1", "@rules_rust//rust/platform:x86_64-apple-darwin", "@rules_rust//rust/platform:x86_64-apple-ios", "@rules_rust//rust/platform:x86_64-linux-android", "@rules_rust//rust/platform:x86_64-unknown-freebsd", "@rules_rust//rust/platform:x86_64-unknown-fuchsia", "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu"], "cfg(not(windows))": ["@rules_rust//rust/platform:aarch64-apple-darwin", "@rules_rust//rust/platform:aarch64-apple-ios", "@rules_rust//rust/platform:aarch64-apple-ios-sim", "@rules_rust//rust/platform:aarch64-linux-android", "@rules_rust//rust/platform:aarch64-unknown-fuchsia", "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu", "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710", "@rules_rust//rust/platform:aarch64-unknown-uefi", "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", "@rules_rust//rust/platform:armv7-linux-androideabi", "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi", "@rules_rust//rust/platform:i686-apple-darwin", "@rules_rust//rust/platform:i686-linux-android", "@rules_rust//rust/platform:i686-unknown-freebsd", "@rules_rust//rust/platform:i686-unknown-linux-gnu", "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", "@rules_rust//rust/platform:riscv32imc-unknown-none-elf", "@rules_rust//rust/platform:riscv64gc-unknown-none-elf", "@rules_rust//rust/platform:s390x-unknown-linux-gnu", "@rules_rust//rust/platform:thumbv7em-none-eabi", "@rules_rust//rust/platform:thumbv8m.main-none-eabi", "@rules_rust//rust/platform:wasm32-unknown-unknown", "@rules_rust//rust/platform:wasm32-wasip1", "@rules_rust//rust/platform:x86_64-apple-darwin", "@rules_rust//rust/platform:x86_64-apple-ios", "@rules_rust//rust/platform:x86_64-linux-android", "@rules_rust//rust/platform:x86_64-unknown-freebsd", "@rules_rust//rust/platform:x86_64-unknown-fuchsia", "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu", "@rules_rust//rust/platform:x86_64-unknown-none", "@rules_rust//rust/platform:x86_64-unknown-uefi"], "cfg(target_os = \"android\")": ["@rules_rust//rust/platform:aarch64-linux-android", "@rules_rust//rust/platform:armv7-linux-androideabi", "@rules_rust//rust/platform:i686-linux-android", "@rules_rust//rust/platform:x86_64-linux-android"], "cfg(target_os = \"haiku\")": [], @@ -1453,16 +1453,6 @@ def crate_repositories(): build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.hermit-abi-0.3.9.bazel"), ) - maybe( - http_archive, - name = "vendor__hermit-abi-0.4.0", - sha256 = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc", - type = "tar.gz", - urls = ["https://static.crates.io/crates/hermit-abi/0.4.0/download"], - strip_prefix = "hermit-abi-0.4.0", - build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.hermit-abi-0.4.0.bazel"), - ) - maybe( http_archive, name = "vendor__hex-0.4.3", @@ -1563,16 +1553,6 @@ def crate_repositories(): build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.inotify-sys-0.1.5.bazel"), ) - maybe( - http_archive, - name = "vendor__is-terminal-0.4.13", - sha256 = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b", - type = "tar.gz", - urls = ["https://static.crates.io/crates/is-terminal/0.4.13/download"], - strip_prefix = "is-terminal-0.4.13", - build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.is-terminal-0.4.13.bazel"), - ) - maybe( http_archive, name = "vendor__is_terminal_polyfill-1.70.1", @@ -2702,16 +2682,6 @@ def crate_repositories(): build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.stable_deref_trait-1.2.0.bazel"), ) - maybe( - http_archive, - name = "vendor__stderrlog-0.6.0", - sha256 = "61c910772f992ab17d32d6760e167d2353f4130ed50e796752689556af07dc6b", - type = "tar.gz", - urls = ["https://static.crates.io/crates/stderrlog/0.6.0/download"], - strip_prefix = "stderrlog-0.6.0", - build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.stderrlog-0.6.0.bazel"), - ) - maybe( http_archive, name = "vendor__streaming-iterator-0.1.9", @@ -2752,16 +2722,6 @@ def crate_repositories(): build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.synstructure-0.13.1.bazel"), ) - maybe( - http_archive, - name = "vendor__termcolor-1.1.3", - sha256 = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755", - type = "tar.gz", - urls = ["https://static.crates.io/crates/termcolor/1.1.3/download"], - strip_prefix = "termcolor-1.1.3", - build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.termcolor-1.1.3.bazel"), - ) - maybe( http_archive, name = "vendor__text-size-1.1.1", @@ -2892,6 +2852,16 @@ def crate_repositories(): build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.tracing-core-0.1.33.bazel"), ) + maybe( + http_archive, + name = "vendor__tracing-flame-0.2.0", + sha256 = "0bae117ee14789185e129aaee5d93750abe67fdc5a9a62650452bfe4e122a3a9", + type = "tar.gz", + urls = ["https://static.crates.io/crates/tracing-flame/0.2.0/download"], + strip_prefix = "tracing-flame-0.2.0", + build_file = Label("//misc/bazel/3rdparty/tree_sitter_extractors_deps:BUILD.tracing-flame-0.2.0.bazel"), + ) + maybe( http_archive, name = "vendor__tracing-log-0.2.0", @@ -3456,7 +3426,6 @@ def crate_repositories(): struct(repo = "vendor__globset-0.4.15", is_dev_dep = False), struct(repo = "vendor__itertools-0.14.0", is_dev_dep = False), struct(repo = "vendor__lazy_static-1.5.0", is_dev_dep = False), - struct(repo = "vendor__log-0.4.22", is_dev_dep = False), struct(repo = "vendor__mustache-0.9.0", is_dev_dep = False), struct(repo = "vendor__num-traits-0.2.19", is_dev_dep = False), struct(repo = "vendor__num_cpus-1.16.0", is_dev_dep = False), @@ -3482,10 +3451,10 @@ def crate_repositories(): struct(repo = "vendor__serde-1.0.217", is_dev_dep = False), struct(repo = "vendor__serde_json-1.0.135", is_dev_dep = False), struct(repo = "vendor__serde_with-3.12.0", is_dev_dep = False), - struct(repo = "vendor__stderrlog-0.6.0", is_dev_dep = False), struct(repo = "vendor__syn-2.0.96", is_dev_dep = False), struct(repo = "vendor__toml-0.8.19", is_dev_dep = False), struct(repo = "vendor__tracing-0.1.41", is_dev_dep = False), + struct(repo = "vendor__tracing-flame-0.2.0", is_dev_dep = False), struct(repo = "vendor__tracing-subscriber-0.3.19", is_dev_dep = False), struct(repo = "vendor__tree-sitter-0.24.6", is_dev_dep = False), struct(repo = "vendor__tree-sitter-embedded-template-0.23.2", is_dev_dep = False), diff --git a/rust/extractor/Cargo.toml b/rust/extractor/Cargo.toml index 310ffefb7784..62f7038c5e73 100644 --- a/rust/extractor/Cargo.toml +++ b/rust/extractor/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" anyhow = "1.0.95" clap = { version = "4.5.26", features = ["derive"] } figment = { version = "0.10.19", features = ["env", "yaml"] } -log = "0.4.22" num-traits = "0.2.19" ra_ap_base_db = "0.0.258" ra_ap_hir = "0.0.258" @@ -26,7 +25,6 @@ ra_ap_cfg = "0.0.258" ra_ap_intern = "0.0.258" serde = "1.0.217" serde_with = "3.12.0" -stderrlog = "0.6.0" triomphe = "0.1.14" argfile = "0.2.1" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } @@ -37,3 +35,6 @@ chrono = { version = "0.4.39", features = ["serde"] } serde_json = "1.0.135" dunce = "1.0.5" toml = "0.8.19" +tracing = "0.1.41" +tracing-flame = "0.2.0" +tracing-subscriber = "0.3.19" diff --git a/rust/extractor/src/archive.rs b/rust/extractor/src/archive.rs index 248c0e85d9da..ad27c483942c 100644 --- a/rust/extractor/src/archive.rs +++ b/rust/extractor/src/archive.rs @@ -1,7 +1,7 @@ use codeql_extractor::file_paths; -use log::{debug, warn}; use std::fs; use std::path::{Path, PathBuf}; +use tracing::{debug, warn}; pub struct Archiver { pub root: PathBuf, diff --git a/rust/extractor/src/diagnostics.rs b/rust/extractor/src/diagnostics.rs index 0e202e95bbd0..d111975db7d5 100644 --- a/rust/extractor/src/diagnostics.rs +++ b/rust/extractor/src/diagnostics.rs @@ -1,7 +1,6 @@ use crate::config::Config; use anyhow::Context; use chrono::{DateTime, Utc}; -use log::{debug, info}; use ra_ap_project_model::ProjectManifest; use serde::ser::SerializeMap; use serde::Serialize; @@ -10,6 +9,7 @@ use std::fmt::Display; use std::fs::File; use std::path::{Path, PathBuf}; use std::time::Instant; +use tracing::{debug, info}; #[derive(Default, Debug, Clone, Copy, Serialize)] #[serde(rename_all = "camelCase")] diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 1b5ec515d0e7..5c738e29dab8 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -3,7 +3,6 @@ use crate::rust_analyzer::path_to_file_id; use crate::trap::TrapId; use anyhow::Context; use archive::Archiver; -use log::{info, warn}; use ra_ap_hir::Semantics; use ra_ap_ide_db::line_index::{LineCol, LineIndex}; use ra_ap_ide_db::RootDatabase; @@ -16,6 +15,9 @@ use std::{ collections::HashMap, path::{Path, PathBuf}, }; +use tracing::{info, warn}; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; mod archive; mod config; @@ -85,7 +87,7 @@ impl<'a> Extractor<'a> { } translator.emit_source_file(ast); translator.trap.commit().unwrap_or_else(|err| { - log::error!( + tracing::error!( "Failed to write trap file for: {}: {}", display_path, err.to_string() @@ -180,11 +182,19 @@ fn cwd() -> anyhow::Result { fn main() -> anyhow::Result<()> { let start = Instant::now(); + let flame_layer = if let Ok(path) = std::env::var("CODEQL_EXTRACTOR_RUST_OPTION_FLAME_LOG") { + tracing_flame::FlameLayer::with_file(path).ok() + } else { + None + }; + tracing_subscriber::registry() + .with(codeql_extractor::extractor::default_subscriber_with_level( + "single_arch", + )) + .with(flame_layer.map(|x| x.0)) + .init(); + let mut cfg = config::Config::extract().context("failed to load configuration")?; - stderrlog::new() - .module(module_path!()) - .verbosity(2 + cfg.verbose as usize) - .init()?; if cfg.qltest { qltest::prepare(&mut cfg)?; } diff --git a/rust/extractor/src/qltest.rs b/rust/extractor/src/qltest.rs index d6db767a5dc4..9553907b7db0 100644 --- a/rust/extractor/src/qltest.rs +++ b/rust/extractor/src/qltest.rs @@ -2,10 +2,10 @@ use crate::config::Config; use anyhow::Context; use glob::glob; use itertools::Itertools; -use log::info; use std::ffi::OsStr; use std::fs; use std::process::Command; +use tracing::info; fn dump_lib() -> anyhow::Result<()> { let path_iterator = glob("*.rs").context("globbing test sources")?; diff --git a/rust/extractor/src/rust_analyzer.rs b/rust/extractor/src/rust_analyzer.rs index 5d03bcc156db..5821f73062b3 100644 --- a/rust/extractor/src/rust_analyzer.rs +++ b/rust/extractor/src/rust_analyzer.rs @@ -1,5 +1,4 @@ use itertools::Itertools; -use log::{debug, error, info, warn}; use ra_ap_base_db::SourceDatabase; use ra_ap_hir::Semantics; use ra_ap_ide_db::RootDatabase; @@ -22,6 +21,7 @@ use std::collections::{HashMap, HashSet}; use std::fs; use std::path::{Path, PathBuf}; use std::rc::Rc; +use tracing::{debug, error, info, warn}; use triomphe::Arc; pub enum RustAnalyzer<'a> { @@ -51,7 +51,7 @@ impl<'a> RustAnalyzer<'a> { project: &ProjectManifest, config: &CargoConfig, ) -> Option<(RootDatabase, Vfs)> { - let progress = |t| (log::trace!("progress: {}", t)); + let progress = |t| (tracing::trace!("progress: {}", t)); let load_config = LoadCargoConfig { load_out_dirs_from_check: true, with_proc_macro_server: ProcMacroServerChoice::Sysroot, @@ -62,7 +62,7 @@ impl<'a> RustAnalyzer<'a> { match load_workspace_at(manifest.as_ref(), config, &load_config, &progress) { Ok((db, vfs, _macro_server)) => Some((db, vfs)), Err(err) => { - log::error!("failed to load workspace for {}: {}", manifest, err); + tracing::error!("failed to load workspace for {}: {}", manifest, err); None } } diff --git a/rust/extractor/src/translate/base.rs b/rust/extractor/src/translate/base.rs index cfdde2053d07..3b9d6a5f95f4 100644 --- a/rust/extractor/src/translate/base.rs +++ b/rust/extractor/src/translate/base.rs @@ -4,7 +4,6 @@ use crate::rust_analyzer::FileSemanticInformation; use crate::trap::{DiagnosticSeverity, TrapFile, TrapId}; use crate::trap::{Label, TrapClass}; use itertools::Either; -use log::Level; use ra_ap_base_db::ra_salsa::InternKey; use ra_ap_base_db::CrateOrigin; use ra_ap_hir::db::ExpandDatabase; @@ -170,20 +169,37 @@ impl<'a> Translator<'a> { location: (LineCol, LineCol), ) { let (start, end) = location; - let level = match severity { - DiagnosticSeverity::Debug => Level::Debug, - DiagnosticSeverity::Info => Level::Info, - DiagnosticSeverity::Warning => Level::Warn, - DiagnosticSeverity::Error => Level::Error, + match severity { + DiagnosticSeverity::Debug => tracing::debug!( + "{}:{}:{}: {}", + self.path, + start.line + 1, + start.col + 1, + &full_message + ), + DiagnosticSeverity::Info => tracing::info!( + "{}:{}:{}: {}", + self.path, + start.line + 1, + start.col + 1, + &full_message + ), + DiagnosticSeverity::Warning => tracing::warn!( + "{}:{}:{}: {}", + self.path, + start.line + 1, + start.col + 1, + &full_message + ), + DiagnosticSeverity::Error => tracing::error!( + "{}:{}:{}: {}", + self.path, + start.line + 1, + start.col + 1, + &full_message + ), }; - log::log!( - level, - "{}:{}:{}: {}", - self.path, - start.line + 1, - start.col + 1, - &full_message - ); + if severity > DiagnosticSeverity::Debug { let location = self.trap.emit_location_label(self.label, start, end); self.trap diff --git a/rust/extractor/src/trap.rs b/rust/extractor/src/trap.rs index 6c8e9b2c3c84..d118b04b7162 100644 --- a/rust/extractor/src/trap.rs +++ b/rust/extractor/src/trap.rs @@ -1,12 +1,12 @@ use crate::config::Compression; use crate::{config, generated}; use codeql_extractor::{extractor, file_paths, trap}; -use log::debug; use ra_ap_ide_db::line_index::LineCol; use std::fmt::Debug; use std::hash::Hash; use std::marker::PhantomData; use std::path::{Path, PathBuf}; +use tracing::debug; pub use trap::Label as UntypedLabel; pub use trap::Writer; diff --git a/shared/tree-sitter-extractor/src/extractor/mod.rs b/shared/tree-sitter-extractor/src/extractor/mod.rs index f9360be14459..fc87d05b7e7d 100644 --- a/shared/tree-sitter-extractor/src/extractor/mod.rs +++ b/shared/tree-sitter-extractor/src/extractor/mod.rs @@ -7,6 +7,13 @@ use std::collections::BTreeSet as Set; use std::env; use std::path::Path; +use tracing_subscriber::filter::Filtered; +use tracing_subscriber::fmt::format::DefaultFields; +use tracing_subscriber::fmt::format::Format; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::EnvFilter; +use tracing_subscriber::Layer; use tree_sitter::{Language, Node, Parser, Range, Tree}; pub mod simple; @@ -15,11 +22,29 @@ pub mod simple; /// `RUST_LOG` and `CODEQL_VERBOSITY` (prioritized in that order), /// falling back to `warn` if neither is set. pub fn set_tracing_level(language: &str) { - tracing_subscriber::fmt() + tracing_subscriber::registry() + .with(default_subscriber_with_level(language)) + .init(); +} + +/// Create a `Subscriber` configured with 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 default_subscriber_with_level( + language: &str, +) -> Filtered< + tracing_subscriber::fmt::Layer< + tracing_subscriber::Registry, + DefaultFields, + Format, + >, + EnvFilter, + tracing_subscriber::Registry, +> { + tracing_subscriber::fmt::layer() .with_target(false) .without_time() .with_level(true) - .with_env_filter( + .with_filter( tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else( |_| -> tracing_subscriber::EnvFilter { let verbosity = env::var("CODEQL_VERBOSITY") @@ -38,9 +63,7 @@ pub fn set_tracing_level(language: &str) { }, ), ) - .init(); } - pub fn populate_file(writer: &mut trap::Writer, absolute_path: &Path) -> trap::Label { let (file_label, fresh) = writer.global_id(&trap::full_id_for_file( &file_paths::normalize_path(absolute_path), From 0442d242047e49914d6ac019f67751928641afb8 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Tue, 11 Feb 2025 18:05:15 +0100 Subject: [PATCH 2/6] Rust: drop tracing:: qualifiers --- rust/extractor/src/main.rs | 4 +-- rust/extractor/src/rust_analyzer.rs | 6 ++-- rust/extractor/src/translate/base.rs | 50 +++++++++++----------------- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 5c738e29dab8..d3732846fa4c 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -15,7 +15,7 @@ use std::{ collections::HashMap, path::{Path, PathBuf}, }; -use tracing::{info, warn}; +use tracing::{error, info, warn}; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; @@ -87,7 +87,7 @@ impl<'a> Extractor<'a> { } translator.emit_source_file(ast); translator.trap.commit().unwrap_or_else(|err| { - tracing::error!( + error!( "Failed to write trap file for: {}: {}", display_path, err.to_string() diff --git a/rust/extractor/src/rust_analyzer.rs b/rust/extractor/src/rust_analyzer.rs index 5821f73062b3..21f62281e725 100644 --- a/rust/extractor/src/rust_analyzer.rs +++ b/rust/extractor/src/rust_analyzer.rs @@ -21,7 +21,7 @@ use std::collections::{HashMap, HashSet}; use std::fs; use std::path::{Path, PathBuf}; use std::rc::Rc; -use tracing::{debug, error, info, warn}; +use tracing::{debug, error, info, trace, warn}; use triomphe::Arc; pub enum RustAnalyzer<'a> { @@ -51,7 +51,7 @@ impl<'a> RustAnalyzer<'a> { project: &ProjectManifest, config: &CargoConfig, ) -> Option<(RootDatabase, Vfs)> { - let progress = |t| (tracing::trace!("progress: {}", t)); + let progress = |t| (trace!("progress: {}", t)); let load_config = LoadCargoConfig { load_out_dirs_from_check: true, with_proc_macro_server: ProcMacroServerChoice::Sysroot, @@ -62,7 +62,7 @@ impl<'a> RustAnalyzer<'a> { match load_workspace_at(manifest.as_ref(), config, &load_config, &progress) { Ok((db, vfs, _macro_server)) => Some((db, vfs)), Err(err) => { - tracing::error!("failed to load workspace for {}: {}", manifest, err); + error!("failed to load workspace for {}: {}", manifest, err); None } } diff --git a/rust/extractor/src/translate/base.rs b/rust/extractor/src/translate/base.rs index 3b9d6a5f95f4..51424eed09e2 100644 --- a/rust/extractor/src/translate/base.rs +++ b/rust/extractor/src/translate/base.rs @@ -71,6 +71,18 @@ macro_rules! emit_detached { ($($_:tt)*) => {}; } +// see https://github.com/tokio-rs/tracing/issues/2730 +macro_rules! dispatch_to_tracing { + ($lvl:ident, $($arg:tt)+) => { + match $lvl { + DiagnosticSeverity::Debug => ::tracing::debug!($($arg)+), + DiagnosticSeverity::Info => ::tracing::info!($($arg)+), + DiagnosticSeverity::Warning => ::tracing::warn!($($arg)+), + DiagnosticSeverity::Error => ::tracing::error!($($arg)+), + } + }; +} + pub struct Translator<'a> { pub trap: TrapFile, path: &'a str, @@ -169,36 +181,14 @@ impl<'a> Translator<'a> { location: (LineCol, LineCol), ) { let (start, end) = location; - match severity { - DiagnosticSeverity::Debug => tracing::debug!( - "{}:{}:{}: {}", - self.path, - start.line + 1, - start.col + 1, - &full_message - ), - DiagnosticSeverity::Info => tracing::info!( - "{}:{}:{}: {}", - self.path, - start.line + 1, - start.col + 1, - &full_message - ), - DiagnosticSeverity::Warning => tracing::warn!( - "{}:{}:{}: {}", - self.path, - start.line + 1, - start.col + 1, - &full_message - ), - DiagnosticSeverity::Error => tracing::error!( - "{}:{}:{}: {}", - self.path, - start.line + 1, - start.col + 1, - &full_message - ), - }; + dispatch_to_tracing!( + severity, + "{}:{}:{}: {}", + self.path, + start.line + 1, + start.col + 1, + &full_message, + ); if severity > DiagnosticSeverity::Debug { let location = self.trap.emit_location_label(self.label, start, end); From 3218faee6c29d1d31e21b24598100202de2d0512 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Tue, 11 Feb 2025 18:09:53 +0100 Subject: [PATCH 3/6] Rust: make flame_log a config option --- rust/extractor/src/config.rs | 1 + rust/extractor/src/main.rs | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rust/extractor/src/config.rs b/rust/extractor/src/config.rs index b18a0fdeecef..cb8805d75749 100644 --- a/rust/extractor/src/config.rs +++ b/rust/extractor/src/config.rs @@ -51,6 +51,7 @@ pub struct Config { pub cargo_target: Option, pub cargo_features: Vec, pub cargo_cfg_overrides: Vec, + pub flame_log: Option, pub verbose: u8, pub compression: Compression, pub inputs: Vec, diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index d3732846fa4c..10a107701a91 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -181,8 +181,12 @@ fn cwd() -> anyhow::Result { } fn main() -> anyhow::Result<()> { + let mut cfg = config::Config::extract().context("failed to load configuration")?; + if cfg.qltest { + qltest::prepare(&mut cfg)?; + } let start = Instant::now(); - let flame_layer = if let Ok(path) = std::env::var("CODEQL_EXTRACTOR_RUST_OPTION_FLAME_LOG") { + let flame_layer = if let Some(path) = &cfg.flame_log { tracing_flame::FlameLayer::with_file(path).ok() } else { None @@ -193,11 +197,6 @@ fn main() -> anyhow::Result<()> { )) .with(flame_layer.map(|x| x.0)) .init(); - - let mut cfg = config::Config::extract().context("failed to load configuration")?; - if cfg.qltest { - qltest::prepare(&mut cfg)?; - } info!("{cfg:#?}\n"); let traps = trap::TrapFileProvider::new(&cfg).context("failed to set up trap files")?; From 5621eecc86c7f83c9310bbb7a8402b33a146a9a2 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Tue, 11 Feb 2025 18:32:32 +0100 Subject: [PATCH 4/6] Rust: config: replace verbose with verbosity --- rust/extractor/src/config.rs | 5 ++--- rust/extractor/src/main.rs | 1 + shared/tree-sitter-extractor/src/extractor/mod.rs | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rust/extractor/src/config.rs b/rust/extractor/src/config.rs index cb8805d75749..f852ee4c4b63 100644 --- a/rust/extractor/src/config.rs +++ b/rust/extractor/src/config.rs @@ -10,7 +10,6 @@ use figment::{ Figment, }; use itertools::Itertools; -use num_traits::Zero; use ra_ap_cfg::{CfgAtom, CfgDiff}; use ra_ap_ide_db::FxHashMap; use ra_ap_intern::Symbol; @@ -52,7 +51,7 @@ pub struct Config { pub cargo_features: Vec, pub cargo_cfg_overrides: Vec, pub flame_log: Option, - pub verbose: u8, + pub verbosity: Option, pub compression: Compression, pub inputs: Vec, pub qltest: bool, @@ -66,7 +65,7 @@ impl Config { .context("expanding parameter files")?; let cli_args = CliConfig::parse_from(args); let mut figment = Figment::new() - .merge(Env::raw().only(["CODEQL_VERBOSE"].as_slice())) + .merge(Env::prefixed("CODEQL_")) .merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_")) .merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_OPTION_")) .merge(Serialized::defaults(cli_args)); diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 10a107701a91..343bdbb0180a 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -194,6 +194,7 @@ fn main() -> anyhow::Result<()> { tracing_subscriber::registry() .with(codeql_extractor::extractor::default_subscriber_with_level( "single_arch", + &cfg.verbosity, )) .with(flame_layer.map(|x| x.0)) .init(); diff --git a/shared/tree-sitter-extractor/src/extractor/mod.rs b/shared/tree-sitter-extractor/src/extractor/mod.rs index fc87d05b7e7d..fcefe87106cb 100644 --- a/shared/tree-sitter-extractor/src/extractor/mod.rs +++ b/shared/tree-sitter-extractor/src/extractor/mod.rs @@ -22,15 +22,17 @@ pub mod simple; /// `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)) + .with(default_subscriber_with_level(language, &verbosity)) .init(); } /// Create a `Subscriber` configured with 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. +/// `RUST_LOG` and `verbosity` (prioritized in that order), falling back to `warn` if neither is set. pub fn default_subscriber_with_level( language: &str, + verbosity: &Option, ) -> Filtered< tracing_subscriber::fmt::Layer< tracing_subscriber::Registry, @@ -47,7 +49,8 @@ pub fn default_subscriber_with_level( .with_filter( tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else( |_| -> tracing_subscriber::EnvFilter { - let verbosity = env::var("CODEQL_VERBOSITY") + let verbosity = verbosity + .as_ref() .map(|v| match v.to_lowercase().as_str() { "off" | "errors" => "error", "warnings" => "warn", @@ -56,7 +59,7 @@ pub fn default_subscriber_with_level( "trace" | "progress++" | "progress+++" => "trace", _ => "warn", }) - .unwrap_or_else(|_| "warn"); + .unwrap_or_else(|| "warn"); tracing_subscriber::EnvFilter::new(format!( "{language}_extractor={verbosity},codeql_extractor={verbosity}" )) From 64f0908d0d92198e6718cd98196fc54d6ccd56f3 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Wed, 12 Feb 2025 10:03:52 +0100 Subject: [PATCH 5/6] Rust: keep FlushGuard in a variable --- rust/extractor/src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 343bdbb0180a..48eecaad4625 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -186,17 +186,21 @@ fn main() -> anyhow::Result<()> { qltest::prepare(&mut cfg)?; } let start = Instant::now(); - let flame_layer = if let Some(path) = &cfg.flame_log { - tracing_flame::FlameLayer::with_file(path).ok() + let (flame_layer, _flush_guard) = if let Some(path) = &cfg.flame_log { + tracing_flame::FlameLayer::with_file(path) + .ok() + .map(|(a, b)| (Some(a), Some(b))) + .unwrap_or((None, None)) } else { - None + (None, None) }; + tracing_subscriber::registry() .with(codeql_extractor::extractor::default_subscriber_with_level( "single_arch", &cfg.verbosity, )) - .with(flame_layer.map(|x| x.0)) + .with(flame_layer) .init(); info!("{cfg:#?}\n"); @@ -247,6 +251,5 @@ fn main() -> anyhow::Result<()> { } } } - extractor.emit_extraction_diagnostics(start, &cfg) } From 18cf39d06384ba76d121639ea925c76b5ec5ccd7 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Wed, 12 Feb 2025 11:49:10 +0100 Subject: [PATCH 6/6] Rust: add verbosity and flamegraph as extractor options --- rust/codeql-extractor.yml | 24 ++++++++++++++++++++++++ rust/extractor/src/config.rs | 12 +++++++++--- rust/extractor/src/main.rs | 4 ++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/rust/codeql-extractor.yml b/rust/codeql-extractor.yml index 2f726a10adac..27f423134a67 100644 --- a/rust/codeql-extractor.yml +++ b/rust/codeql-extractor.yml @@ -54,3 +54,27 @@ options: Comma-separated list of cfg settings to enable, or disable if prefixed with `-`. Can be repeated. type: array + logging: + title: Options pertaining to logging. + type: object + properties: + verbosity: + title: Extractor logging verbosity level. + description: > + Controls the level of verbosity of the extractor. + The supported levels are (in order of increasing verbosity): + - off + - errors + - warnings + - info or progress + - debug or progress+ + - trace or progress++ + - progress+++ + type: string + pattern: "^(off|errors|warnings|(info|progress)|(debug|progress\\+)|(trace|progress\\+\\+)|progress\\+\\+\\+)$" + flamegraph: + title: "[Experimental] File path for write flame graph log" + description: > + 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 diff --git a/rust/extractor/src/config.rs b/rust/extractor/src/config.rs index f852ee4c4b63..82568b64553f 100644 --- a/rust/extractor/src/config.rs +++ b/rust/extractor/src/config.rs @@ -50,8 +50,8 @@ pub struct Config { pub cargo_target: Option, pub cargo_features: Vec, pub cargo_cfg_overrides: Vec, - pub flame_log: Option, - pub verbosity: Option, + pub logging_flamegraph: Option, + pub logging_verbosity: Option, pub compression: Compression, pub inputs: Vec, pub qltest: bool, @@ -65,7 +65,13 @@ impl Config { .context("expanding parameter files")?; let cli_args = CliConfig::parse_from(args); let mut figment = Figment::new() - .merge(Env::prefixed("CODEQL_")) + .merge(Env::raw().filter_map(|f| { + if f.eq("CODEQL_VERBOSITY") { + Some("LOGGING_VERBOSITY".into()) + } else { + None + } + })) .merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_")) .merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_OPTION_")) .merge(Serialized::defaults(cli_args)); diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 48eecaad4625..04aaf23c652e 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -186,7 +186,7 @@ fn main() -> anyhow::Result<()> { qltest::prepare(&mut cfg)?; } let start = Instant::now(); - let (flame_layer, _flush_guard) = if let Some(path) = &cfg.flame_log { + let (flame_layer, _flush_guard) = if let Some(path) = &cfg.logging_flamegraph { tracing_flame::FlameLayer::with_file(path) .ok() .map(|(a, b)| (Some(a), Some(b))) @@ -198,7 +198,7 @@ fn main() -> anyhow::Result<()> { tracing_subscriber::registry() .with(codeql_extractor::extractor::default_subscriber_with_level( "single_arch", - &cfg.verbosity, + &cfg.logging_verbosity, )) .with(flame_layer) .init();