From f261be60eca947c284fe1f6cb2c58dcddcff1d0b Mon Sep 17 00:00:00 2001 From: Melody Ma Date: Thu, 18 Jun 2026 15:37:50 +0800 Subject: [PATCH 1/3] refactor(cpp/libclang): extract reusable parser action --- cpp/libclang/BUILD | 3 - cpp/libclang/README.md | 9 +- cpp/libclang/cpp_parser.bzl | 238 +++++++++++++++++++++++--------- cpp/libclang/src/main.rs | 58 +++++--- cpp/libclang/src/utils/write.rs | 20 +-- 5 files changed, 219 insertions(+), 109 deletions(-) diff --git a/cpp/libclang/BUILD b/cpp/libclang/BUILD index 58c20a2c..63d6a81b 100644 --- a/cpp/libclang/BUILD +++ b/cpp/libclang/BUILD @@ -32,9 +32,6 @@ rust_binary( data = [ "@llvm_toolchain_llvm//:libclang", ], - env = { - "LIBCLANG_PATH": "$(rootpath @llvm_toolchain_llvm//:libclang)", - }, visibility = ["//visibility:public"], deps = [ "//cpp/libclang/src/utils", diff --git a/cpp/libclang/README.md b/cpp/libclang/README.md index 8d221782..5bf34744 100644 --- a/cpp/libclang/README.md +++ b/cpp/libclang/README.md @@ -26,7 +26,6 @@ cpp_parser( extra_args = [ ], target = "//cpp/libclang/integration_test/cases/include_3rdparty", - tool = ":clang_rs_parser", ) ``` @@ -38,9 +37,9 @@ Where: Expected result: - Bazel creates parser output artifact: - - `bazel-bin/cpp/libclang/cpp_parser_include_3rdparty_result.fbs.bin` + - `bazel-bin/cpp/libclang/cpp_parser_include_3rdparty_class_diagram.fbs.bin` - When `emit_debug_json = True`, the parser also writes: - - `bazel-bin/cpp/libclang/cpp_parser_include_3rdparty_result/debug.json` + - `bazel-bin/cpp/libclang/cpp_parser_include_3rdparty_debug.json` ## Configure debug logging @@ -55,6 +54,6 @@ Accepted values are: `error`, `warn`, `info`, `debug`, `trace`. ## Quick check (optional) ```bash -ls -l bazel-bin/cpp/libclang/cpp_parser_include_3rdparty_result.fbs.bin -ls -l bazel-bin/cpp/libclang/cpp_parser_include_3rdparty_result/debug.json +ls -l bazel-bin/cpp/libclang/integration_test/cases/include_3rdparty/parser_class_diagram.fbs.bin +ls -l bazel-bin/cpp/libclang/integration_test/cases/include_3rdparty/parser_debug.json ``` diff --git a/cpp/libclang/cpp_parser.bzl b/cpp/libclang/cpp_parser.bzl index d6432af1..5deade67 100644 --- a/cpp/libclang/cpp_parser.bzl +++ b/cpp/libclang/cpp_parser.bzl @@ -13,6 +13,9 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") +load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") + +# Providers and aspects used to adapt C/C++ targets for the parser action. def _extract_files_from_attr(attr, attr_name): files = [] @@ -21,7 +24,13 @@ def _extract_files_from_attr(attr, attr_name): files.extend(src.files.to_list()) return files -SourceFilesInfo = provider(fields = ["files", "inputs"]) +SourceFilesInfo = provider( + doc = "Source files and transitive inputs collected for parser actions.", + fields = { + "files": "depset of source files to parse for this target.", + "inputs": "depset of source and header inputs needed by the parser action.", + }, +) def _cc_sources_aspect_impl(target, ctx): direct_srcs = _extract_files_from_attr(ctx.rule.attr, "srcs") @@ -64,7 +73,15 @@ CompilationFlagsInfo = provider( }, ) -def _collect_from_cc_info(target): +CppParserInfo = provider( + doc = "Outputs generated by the C/C++ parser.", + fields = { + "class_fbs": "Class diagram FlatBuffer output file.", + "debug_json": "Debug JSON sidecar output file. (Optional)", + }, +) + +def _collect_from_cc_info(target, ctx): flags = [] if CcInfo in target: @@ -90,7 +107,7 @@ def _compilation_flags_aspect_impl(target, ctx): if CompilationFlagsInfo in dep: transitive.append(dep[CompilationFlagsInfo].flags) - direct_flags = _collect_from_cc_info(target) + direct_flags = _collect_from_cc_info(target, ctx) return [ CompilationFlagsInfo( @@ -103,6 +120,53 @@ compilation_flags_aspect = aspect( attr_aspects = ["deps"], ) +# Public integration helpers for rules that want to reuse the parser action. + +def cpp_parser_target_aspects(): + """Return aspects required on attrs whose targets will be parsed.""" + + return [cc_sources_aspect, compilation_flags_aspect] + +def has_cpp_parser_inputs(target): + """Check whether a target has the providers needed by run_cpp_parser_action.""" + + return (CcInfo in target and + SourceFilesInfo in target and + CompilationFlagsInfo in target and + bool(target[SourceFilesInfo].files.to_list())) + +def cpp_parser_action_internal_attrs(): + """Return private attrs required by run_cpp_parser_action callers.""" + + return { + "_tool": attr.label( + default = Label("//cpp/libclang:clang_rs_parser"), + executable = True, + cfg = "exec", + doc = "Internal libclang-based parser backend.", + ), + "_libclang": attr.label( + allow_single_file = True, + default = "@llvm_toolchain_llvm//:lib/libclang.so", + ), + "_llvm_cxx_builtin_include": attr.label( + default = "@llvm_toolchain_llvm//:cxx_builtin_include", + doc = "LLVM toolchain filegroup containing the libc++ header directory (include/c++) " + + "and the clang resource include directory (lib/clang//include).", + ), + "_llvm_extra_config_site": attr.label( + default = "@llvm_toolchain_llvm//:extra_config_site", + doc = "LLVM toolchain filegroup containing the arch-specific __config_site file " + + "(include//c++/v1/__config_site) used to locate the ABI include path.", + ), + "_log_level": attr.label( + default = Label("//cpp/libclang:log_level"), + doc = "Build setting that controls clang_rs_parser log level.", + ), + } + +# Parser action implementation. + def _detect_standard_from_flags(ctx): """ Fall back: compile the action's compile flags and look for -std=. @@ -190,58 +254,87 @@ def _collect_required_llvm_include_args(cxx_builtin_include_files, extra_config_ return result -def _cpp_parser_impl(ctx): - output_dir = ctx.actions.declare_directory( - ctx.label.name + "_result", +def run_cpp_parser_action( + ctx, + *, + target, + output_prefix, + tool, + libclang, + llvm_cxx_builtin_include, + llvm_extra_config_site, + log_level, + extra_args = [], + emit_debug_json = False): + """Register the libclang parser action and return its declared outputs. + + The target must be analyzed with cpp_parser_target_aspects() before this + helper is called. Use has_cpp_parser_inputs() when the caller accepts mixed + implementation target types. + """ + + class_fbs_output = ctx.actions.declare_file( + "{}_{}".format(output_prefix, "class_diagram.fbs.bin"), ) - libclang = ctx.file._libclang - args = [] + debug_json_output = None + if emit_debug_json: + debug_json_output = ctx.actions.declare_file( + "{}_{}".format(output_prefix, "debug.json"), + ) + + tool_files_to_run = tool[DefaultInfo].files_to_run + args = [] args += [ - "--output-dir", - output_dir.path, + "--class-fbs-output", + class_fbs_output.path, ] - if ctx.attr.emit_debug_json: - args.append("--json") + if debug_json_output: + args += [ + "--debug-json-output", + debug_json_output.path, + ] - target_compilation_flags_list = ctx.attr.target[CompilationFlagsInfo].flags.to_list() + target_compilation_flags_list = target[CompilationFlagsInfo].flags.to_list() - cxx_builtin_include_files = ctx.attr._llvm_cxx_builtin_include.files.to_list() - extra_config_site_files = ctx.attr._llvm_extra_config_site.files.to_list() + cxx_builtin_include_files = llvm_cxx_builtin_include.files.to_list() + extra_config_site_files = llvm_extra_config_site.files.to_list() llvm_include_args = _collect_required_llvm_include_args(cxx_builtin_include_files, extra_config_site_files) - extra_args = [ + parser_extra_args = [ _detect_standard_from_flags(ctx), "-nostdinc++", ] - extra_args += llvm_include_args - extra_args += target_compilation_flags_list + ctx.attr.extra_args - for ea in extra_args: + parser_extra_args += llvm_include_args + parser_extra_args += target_compilation_flags_list + extra_args + for ea in parser_extra_args: args += ["--extra-arg", ea] - target_source_files_info = ctx.attr.target[SourceFilesInfo] + target_source_files_info = target[SourceFilesInfo] target_source_files_list = target_source_files_info.files.to_list() target_source_inputs_list = target_source_files_info.inputs.to_list() - # extend args with input sources - if SourceFilesInfo in ctx.attr.target: - args += [file.path for file in target_source_files_list] + args += ["--input"] + [file.path for file in target_source_files_list] inputs = [ libclang, ] + target_source_inputs_list + cxx_builtin_include_files + extra_config_site_files + outputs = [class_fbs_output] + if debug_json_output: + outputs.append(debug_json_output) + ctx.actions.run( inputs = inputs, - outputs = [output_dir], - executable = ctx.executable.tool, - tools = [ctx.attr.tool[DefaultInfo].files_to_run], + outputs = outputs, + executable = tool_files_to_run.executable, + tools = [tool_files_to_run], arguments = args, env = { "LIBCLANG_PATH": libclang.dirname, - "LIBCLANG_LOG": ctx.attr._log_level[BuildSettingInfo].value, + "LIBCLANG_LOG": log_level, }, mnemonic = "CppAnalyze", # this is required to parse some system headers @@ -251,49 +344,62 @@ def _cpp_parser_impl(ctx): progress_message = "Running C++ AST analysis: %s" % ctx.label, ) - return DefaultInfo( - files = depset([output_dir]), - runfiles = ctx.runfiles(files = [output_dir]), + return struct( + class_fbs = class_fbs_output, + debug_json = debug_json_output, ) -cpp_parser = rule( - implementation = _cpp_parser_impl, - attrs = { - "target": attr.label( - aspects = [cc_sources_aspect, compilation_flags_aspect], - mandatory = True, - ), - "tool": attr.label( - executable = True, - cfg = "exec", - mandatory = True, - ), - "extra_args": attr.string_list( - default = [], - ), - "emit_debug_json": attr.bool( - default = False, - doc = "Emit debug.json alongside the FlatBuffer output. Intended for tests/debugging.", - ), - "_libclang": attr.label( - allow_single_file = True, - default = "@llvm_toolchain_llvm//:lib/libclang.so", - ), - "_llvm_cxx_builtin_include": attr.label( - default = "@llvm_toolchain_llvm//:cxx_builtin_include", - doc = "LLVM toolchain filegroup containing the libc++ header directory (include/c++) " + - "and the clang resource include directory (lib/clang//include).", - ), - "_llvm_extra_config_site": attr.label( - default = "@llvm_toolchain_llvm//:extra_config_site", - doc = "LLVM toolchain filegroup containing the arch-specific __config_site file " + - "(include//c++/v1/__config_site) used to locate the ABI include path.", +# cpp_parser rule + +def _cpp_parser_impl(ctx): + outputs = run_cpp_parser_action( + ctx, + target = ctx.attr.target, + output_prefix = ctx.label.name, + tool = ctx.attr._tool, + libclang = ctx.file._libclang, + llvm_cxx_builtin_include = ctx.attr._llvm_cxx_builtin_include, + llvm_extra_config_site = ctx.attr._llvm_extra_config_site, + log_level = ctx.attr._log_level[BuildSettingInfo].value, + extra_args = ctx.attr.extra_args, + emit_debug_json = ctx.attr.emit_debug_json, + ) + + runfiles_files = [outputs.class_fbs] + if outputs.debug_json: + runfiles_files.append(outputs.debug_json) + + return [ + DefaultInfo( + files = depset([outputs.class_fbs]), + runfiles = ctx.runfiles(files = runfiles_files), ), - "_log_level": attr.label( - default = Label("//cpp/libclang:log_level"), - doc = "Build setting that controls clang_rs_parser log level.", + CppParserInfo( + class_fbs = outputs.class_fbs, + debug_json = outputs.debug_json, ), - }, + ] + +_cpp_parser_attrs = { + "target": attr.label( + aspects = cpp_parser_target_aspects(), + mandatory = True, + ), + "extra_args": attr.string_list( + default = [], + ), + "emit_debug_json": attr.bool( + default = False, + doc = "Emit debug.json alongside the FlatBuffer output. Intended for tests/debugging.", + ), +} + +_cpp_parser_attrs.update(cpp_parser_action_internal_attrs()) + +# BUILD-facing parser rule: wraps run_cpp_parser_action and exposes CppParserInfo. +cpp_parser = rule( + implementation = _cpp_parser_impl, + attrs = _cpp_parser_attrs, toolchains = use_cc_toolchain(), fragments = ["cpp"], ) diff --git a/cpp/libclang/src/main.rs b/cpp/libclang/src/main.rs index 4c8f21ed..651c6c7b 100644 --- a/cpp/libclang/src/main.rs +++ b/cpp/libclang/src/main.rs @@ -24,8 +24,6 @@ use utils::{render_entity_tree, write_debug_json, write_entity_tree, write_fbs_o use visit_tu::visitor; use visit_tu::{FunctionDef, VisitContext, Visitor}; -const CLASS_DIAGRAM_STEM: &str = "class_diagram"; - #[derive(ClapParser, Debug)] #[command(name = "cpp_parser")] #[command(author = "Eclipse Foundation Contributors")] @@ -33,19 +31,20 @@ const CLASS_DIAGRAM_STEM: &str = "class_diagram"; #[command(about = "Parse C/C++ source files using libclang and extract AST info")] struct Args { /// Input C/C++ source files + #[arg(long, required = true, num_args = 1..)] input: Vec, - /// Output directory path - #[arg(short, long)] - output_dir: PathBuf, + /// Class diagram FlatBuffer output path (internal use only) + #[arg(long, hide = true)] + class_fbs_output: PathBuf, /// Additional compiler arguments (e.g., -I/path/to/includes) #[arg(short = 'X', long = "extra-arg", allow_hyphen_values = true)] extra_args: Vec, - /// Output JSON format for debugging (internal use only) + /// Debug JSON output path (internal use only) #[arg(long, hide = true)] - json: bool, + debug_json_output: Option, } #[derive(Default)] @@ -114,7 +113,7 @@ fn parse_file( file: &Path, compilation_flags: &[String], index: &clang::Index, - output_dir: &Path, + trace_output_dir: Option<&Path>, outputs: &mut ParseOutputs, ) { debug!("Parsing TU: {:?}", file); @@ -141,9 +140,11 @@ fn parse_file( let entity = parsed.get_entity(); debug!("Parsed {:?} successfully", parsed); if log::log_enabled!(log::Level::Trace) { - let ast_file_output_path = output_dir.join("libclang_parsed_ast.txt"); - let entity_tree = render_entity_tree(&entity, 0); - write_entity_tree(&ast_file_output_path, &entity_tree); + if let Some(trace_output_dir) = trace_output_dir { + let ast_file_output_path = trace_output_dir.join("libclang_parsed_ast.txt"); + let entity_tree = render_entity_tree(&entity, 0); + write_entity_tree(&ast_file_output_path, &entity_tree); + } } let mut ctx = VisitContext::default(); @@ -158,7 +159,7 @@ fn parse_file( } fn serialize_class_diagram( - output_dir: &Path, + output_path: &Path, entities: BTreeMap, ) -> Result<(), std::io::Error> { let entities: Vec<_> = entities.into_values().collect(); @@ -171,11 +172,18 @@ fn serialize_class_diagram( }; let output_fbs = ClassSerializer::serialize(&class_diagram, ""); - write_fbs_output(output_dir, CLASS_DIAGRAM_STEM, &output_fbs)?; + write_fbs_output(output_path, &output_fbs)?; Ok(()) } +fn ensure_output_parent_exists(path: &Path) -> Result<(), std::io::Error> { + if let Some(parent) = path.parent() { + fs::create_dir_all(parent)?; + } + Ok(()) +} + fn main() -> Result<(), Box> { init_logging(); let clang = init_libclang(); @@ -184,7 +192,17 @@ fn main() -> Result<(), Box> { let command_line_args = Args::parse(); let mut outputs = ParseOutputs::default(); - fs::create_dir_all(&command_line_args.output_dir)?; + ensure_output_parent_exists(&command_line_args.class_fbs_output)?; + if let Some(debug_json_output) = &command_line_args.debug_json_output { + ensure_output_parent_exists(debug_json_output)?; + } + + let trace_output_dir = command_line_args.class_fbs_output.parent().or_else(|| { + command_line_args + .debug_json_output + .as_deref() + .and_then(Path::parent) + }); for file in &command_line_args.input { let compilation_flags = &command_line_args.extra_args; @@ -193,20 +211,16 @@ fn main() -> Result<(), Box> { file, compilation_flags, &index, - &command_line_args.output_dir, + trace_output_dir, &mut outputs, ); } - if command_line_args.json { - write_debug_json( - &command_line_args.output_dir, - &outputs.types, - &outputs.functions, - )?; + if let Some(debug_json_output) = &command_line_args.debug_json_output { + write_debug_json(debug_json_output, &outputs.types, &outputs.functions)?; } - serialize_class_diagram(&command_line_args.output_dir, outputs.types)?; + serialize_class_diagram(&command_line_args.class_fbs_output, outputs.types)?; Ok(()) } diff --git a/cpp/libclang/src/utils/write.rs b/cpp/libclang/src/utils/write.rs index fd1aa748..e7eee7dd 100644 --- a/cpp/libclang/src/utils/write.rs +++ b/cpp/libclang/src/utils/write.rs @@ -15,7 +15,7 @@ use serde::Serialize; use std::fs; use std::fs::OpenOptions; use std::io::{BufWriter, Write}; -use std::path::{Path, PathBuf}; +use std::path::Path; pub fn write_entity_tree(path: &Path, entity_tree: &str) { match write_entity_tree_inner(path, entity_tree) { @@ -42,7 +42,7 @@ fn write_entity_tree_inner(path: &Path, entity_tree: &str) -> std::io::Result<() } pub fn write_debug_json( - output_dir: &Path, + output_path: &Path, types: &T, functions: &U, ) -> Result<(), Box> @@ -55,20 +55,14 @@ where debug_json.insert("functions".to_owned(), serde_json::to_value(functions)?); let output_json = serde_json::to_string_pretty(&debug_json)?; - let json_output_path = output_dir.join("debug.json"); - fs::write(&json_output_path, output_json)?; - debug!("Wrote AST debug JSON to {:?}", json_output_path); + fs::write(output_path, output_json)?; + debug!("Wrote AST debug JSON to {:?}", output_path); Ok(()) } -pub fn write_fbs_output( - output_dir: &Path, - file_stem: &str, - buffer: &[u8], -) -> Result { - let output_path = output_dir.join(format!("{file_stem}.fbs.bin")); - fs::write(&output_path, buffer)?; +pub fn write_fbs_output(output_path: &Path, buffer: &[u8]) -> Result<(), std::io::Error> { + fs::write(output_path, buffer)?; debug!("Wrote FlatBuffer to {:?}", output_path); - Ok(output_path) + Ok(()) } From f8866936ba4ead40f0f9cbd2ae1b52bb76f01941 Mon Sep 17 00:00:00 2001 From: Melody Ma Date: Thu, 18 Jun 2026 16:16:59 +0800 Subject: [PATCH 2/3] test(cpp/libclang): centralize parser integration case wiring --- cpp/libclang/cpp_parser.bzl | 3 + cpp/libclang/integration_test/README.md | 12 ++- .../cases/complex_class/BUILD | 38 +------- .../cases/complex_class/run_test.rs | 6 +- .../cases/include_3rdparty/BUILD | 38 +------- .../cases/include_3rdparty/run_test.rs | 6 +- .../cases/method_parameter_type/BUILD | 37 +------- .../cases/method_parameter_type/run_test.rs | 6 +- .../cases/method_return_type/BUILD | 37 +------- .../cases/method_return_type/run_test.rs | 6 +- .../cases/nest_namespace_class/BUILD | 38 +------- .../cases/nest_namespace_class/run_test.rs | 6 +- .../cases/relationship_aggregation/BUILD | 38 +------- .../relationship_aggregation/run_test.rs | 6 +- .../cases/relationship_association/BUILD | 38 +------- .../relationship_association/run_test.rs | 6 +- .../cases/relationship_composition/BUILD | 38 +------- .../relationship_composition/run_test.rs | 6 +- .../cases/relationship_dependency/BUILD | 38 +------- .../cases/relationship_dependency/run_test.rs | 6 +- .../cases/relationship_implementation/BUILD | 38 +------- .../relationship_implementation/run_test.rs | 6 +- .../cases/relationship_inheritance/BUILD | 38 +------- .../relationship_inheritance/run_test.rs | 6 +- .../cases/same_name_diff_namespace/BUILD | 37 +------- .../same_name_diff_namespace/run_test.rs | 6 +- .../integration_test/cases/simple_enums/BUILD | 37 +------- .../cases/simple_enums/run_test.rs | 6 +- .../cases/simple_struct/BUILD | 38 +------- .../cases/simple_struct/run_test.rs | 6 +- .../cases/template_class/BUILD | 38 +------- .../cases/template_class/run_test.rs | 6 +- .../integration_test/cases/type_alias/BUILD | 38 +------- .../cases/type_alias/run_test.rs | 6 +- .../cases/variable_namespace/BUILD | 38 +------- .../cases/variable_namespace/run_test.rs | 6 +- .../integration_test/test_framework.rs | 4 +- cpp/libclang/integration_test/test_rules.bzl | 87 +++++++++++++++++++ 38 files changed, 221 insertions(+), 629 deletions(-) create mode 100644 cpp/libclang/integration_test/test_rules.bzl diff --git a/cpp/libclang/cpp_parser.bzl b/cpp/libclang/cpp_parser.bzl index 5deade67..cbeab836 100644 --- a/cpp/libclang/cpp_parser.bzl +++ b/cpp/libclang/cpp_parser.bzl @@ -352,6 +352,9 @@ def run_cpp_parser_action( # cpp_parser rule def _cpp_parser_impl(ctx): + if not has_cpp_parser_inputs(ctx.attr.target): + fail("cpp_parser requires a C/C++ target with non-empty parse inputs: %s" % ctx.attr.target) + outputs = run_cpp_parser_action( ctx, target = ctx.attr.target, diff --git a/cpp/libclang/integration_test/README.md b/cpp/libclang/integration_test/README.md index 5eaaa6c7..b0d3eb8f 100644 --- a/cpp/libclang/integration_test/README.md +++ b/cpp/libclang/integration_test/README.md @@ -24,8 +24,16 @@ This directory contains integration tests for the C++ libclang parser and relate ## Test Workflow 1. Each case directory contains C++ source files, headers, a BUILD file, and an `expected.json` golden output. -2. The case `cpp_parser(...)` target must set `emit_debug_json = True` so the parser emits the aggregated `debug.json` sidecar required by the test harness. -3. The Rust test framework reads `debug.json` from the parser output directory and compares it to `expected.json`. +2. The case calls the shared integration test macro: + ```starlark + cpp_parser_integration_test( + name = "test_case_library", + target = ":case_library", + expected_output = ["expected.json"], + ) + ``` + The macro creates the expected output filegroup and parser target, exposes `CppParserInfo.debug_json` through the test-only debug JSON target, and wires the Rust comparison test. +3. The Rust test framework receives that debug JSON path and compares it to `expected.json`. 4. To batch test all cases: ```bash diff --git a/cpp/libclang/integration_test/cases/complex_class/BUILD b/cpp/libclang/integration_test/cases/complex_class/BUILD index fe57ea2c..44261af0 100644 --- a/cpp/libclang/integration_test/cases/complex_class/BUILD +++ b/cpp/libclang/integration_test/cases/complex_class/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "complex_class", @@ -26,31 +19,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_complex_class", + expected_output = ["expected.json"], target = ":complex_class", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/complex_class/run_test.rs b/cpp/libclang/integration_test/cases/complex_class/run_test.rs index c1ca2472..823035d3 100644 --- a/cpp/libclang/integration_test/cases/complex_class/run_test.rs +++ b/cpp/libclang/integration_test/cases/complex_class/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; diff --git a/cpp/libclang/integration_test/cases/include_3rdparty/BUILD b/cpp/libclang/integration_test/cases/include_3rdparty/BUILD index 73368b4c..a1aeb180 100644 --- a/cpp/libclang/integration_test/cases/include_3rdparty/BUILD +++ b/cpp/libclang/integration_test/cases/include_3rdparty/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "include_3rdparty", @@ -29,31 +22,8 @@ cc_library( ], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_include_3rdparty", + expected_output = ["expected.json"], target = ":include_3rdparty", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/include_3rdparty/run_test.rs b/cpp/libclang/integration_test/cases/include_3rdparty/run_test.rs index d1f7d491..5deca923 100644 --- a/cpp/libclang/integration_test/cases/include_3rdparty/run_test.rs +++ b/cpp/libclang/integration_test/cases/include_3rdparty/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/method_parameter_type/BUILD b/cpp/libclang/integration_test/cases/method_parameter_type/BUILD index 0812d16e..f393d7ed 100644 --- a/cpp/libclang/integration_test/cases/method_parameter_type/BUILD +++ b/cpp/libclang/integration_test/cases/method_parameter_type/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "method_parameter_type", @@ -25,30 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [], +cpp_parser_integration_test( + name = "test_method_parameter_type", + expected_output = ["expected.json"], target = ":method_parameter_type", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/method_parameter_type/run_test.rs b/cpp/libclang/integration_test/cases/method_parameter_type/run_test.rs index 431c39d1..9291ee54 100644 --- a/cpp/libclang/integration_test/cases/method_parameter_type/run_test.rs +++ b/cpp/libclang/integration_test/cases/method_parameter_type/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; diff --git a/cpp/libclang/integration_test/cases/method_return_type/BUILD b/cpp/libclang/integration_test/cases/method_return_type/BUILD index c14a91cd..95d42f99 100644 --- a/cpp/libclang/integration_test/cases/method_return_type/BUILD +++ b/cpp/libclang/integration_test/cases/method_return_type/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "method_return_type", @@ -25,30 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [], +cpp_parser_integration_test( + name = "test_method_return_type", + expected_output = ["expected.json"], target = ":method_return_type", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/method_return_type/run_test.rs b/cpp/libclang/integration_test/cases/method_return_type/run_test.rs index cb8f7bd1..7312dd8f 100644 --- a/cpp/libclang/integration_test/cases/method_return_type/run_test.rs +++ b/cpp/libclang/integration_test/cases/method_return_type/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; diff --git a/cpp/libclang/integration_test/cases/nest_namespace_class/BUILD b/cpp/libclang/integration_test/cases/nest_namespace_class/BUILD index d6a58367..77706b25 100644 --- a/cpp/libclang/integration_test/cases/nest_namespace_class/BUILD +++ b/cpp/libclang/integration_test/cases/nest_namespace_class/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "nest_namespace_class", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_nest_namespace_class", + expected_output = ["expected.json"], target = ":nest_namespace_class", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/nest_namespace_class/run_test.rs b/cpp/libclang/integration_test/cases/nest_namespace_class/run_test.rs index cc3f198b..ac390f98 100644 --- a/cpp/libclang/integration_test/cases/nest_namespace_class/run_test.rs +++ b/cpp/libclang/integration_test/cases/nest_namespace_class/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/relationship_aggregation/BUILD b/cpp/libclang/integration_test/cases/relationship_aggregation/BUILD index 7d1acf04..20c302d4 100644 --- a/cpp/libclang/integration_test/cases/relationship_aggregation/BUILD +++ b/cpp/libclang/integration_test/cases/relationship_aggregation/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "relationship_aggregation", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_relationship_aggregation", + expected_output = ["expected.json"], target = ":relationship_aggregation", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/relationship_aggregation/run_test.rs b/cpp/libclang/integration_test/cases/relationship_aggregation/run_test.rs index bccde141..3d32b802 100644 --- a/cpp/libclang/integration_test/cases/relationship_aggregation/run_test.rs +++ b/cpp/libclang/integration_test/cases/relationship_aggregation/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/relationship_association/BUILD b/cpp/libclang/integration_test/cases/relationship_association/BUILD index 1d8dfb73..29f6b760 100644 --- a/cpp/libclang/integration_test/cases/relationship_association/BUILD +++ b/cpp/libclang/integration_test/cases/relationship_association/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "relationship_association", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_relationship_association", + expected_output = ["expected.json"], target = ":relationship_association", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/relationship_association/run_test.rs b/cpp/libclang/integration_test/cases/relationship_association/run_test.rs index 079bc65d..5752671a 100644 --- a/cpp/libclang/integration_test/cases/relationship_association/run_test.rs +++ b/cpp/libclang/integration_test/cases/relationship_association/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/relationship_composition/BUILD b/cpp/libclang/integration_test/cases/relationship_composition/BUILD index b69199e6..c0cd2931 100644 --- a/cpp/libclang/integration_test/cases/relationship_composition/BUILD +++ b/cpp/libclang/integration_test/cases/relationship_composition/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "relationship_composition", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_relationship_composition", + expected_output = ["expected.json"], target = ":relationship_composition", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/relationship_composition/run_test.rs b/cpp/libclang/integration_test/cases/relationship_composition/run_test.rs index 84b19b5e..3fdee8b7 100644 --- a/cpp/libclang/integration_test/cases/relationship_composition/run_test.rs +++ b/cpp/libclang/integration_test/cases/relationship_composition/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/relationship_dependency/BUILD b/cpp/libclang/integration_test/cases/relationship_dependency/BUILD index f57fa2e4..40cedcdf 100644 --- a/cpp/libclang/integration_test/cases/relationship_dependency/BUILD +++ b/cpp/libclang/integration_test/cases/relationship_dependency/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "relationship_dependency", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_relationship_dependency", + expected_output = ["expected.json"], target = ":relationship_dependency", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/relationship_dependency/run_test.rs b/cpp/libclang/integration_test/cases/relationship_dependency/run_test.rs index 79ea5dcc..945f5916 100644 --- a/cpp/libclang/integration_test/cases/relationship_dependency/run_test.rs +++ b/cpp/libclang/integration_test/cases/relationship_dependency/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/relationship_implementation/BUILD b/cpp/libclang/integration_test/cases/relationship_implementation/BUILD index a9ccab4b..a2f44491 100644 --- a/cpp/libclang/integration_test/cases/relationship_implementation/BUILD +++ b/cpp/libclang/integration_test/cases/relationship_implementation/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "relationship_implementation", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_relationship_implementation", + expected_output = ["expected.json"], target = ":relationship_implementation", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/relationship_implementation/run_test.rs b/cpp/libclang/integration_test/cases/relationship_implementation/run_test.rs index 406958e3..5f940baa 100644 --- a/cpp/libclang/integration_test/cases/relationship_implementation/run_test.rs +++ b/cpp/libclang/integration_test/cases/relationship_implementation/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/relationship_inheritance/BUILD b/cpp/libclang/integration_test/cases/relationship_inheritance/BUILD index 945354a0..097f615b 100644 --- a/cpp/libclang/integration_test/cases/relationship_inheritance/BUILD +++ b/cpp/libclang/integration_test/cases/relationship_inheritance/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "relationship_inheritance", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_relationship_inheritance", + expected_output = ["expected.json"], target = ":relationship_inheritance", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/relationship_inheritance/run_test.rs b/cpp/libclang/integration_test/cases/relationship_inheritance/run_test.rs index 9cb8c6c7..2e4103de 100644 --- a/cpp/libclang/integration_test/cases/relationship_inheritance/run_test.rs +++ b/cpp/libclang/integration_test/cases/relationship_inheritance/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/same_name_diff_namespace/BUILD b/cpp/libclang/integration_test/cases/same_name_diff_namespace/BUILD index 89dc80b8..e1ae10ef 100644 --- a/cpp/libclang/integration_test/cases/same_name_diff_namespace/BUILD +++ b/cpp/libclang/integration_test/cases/same_name_diff_namespace/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "same_name_diff_namespace", @@ -25,30 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [], +cpp_parser_integration_test( + name = "test_same_name_diff_namespace", + expected_output = ["expected.json"], target = ":same_name_diff_namespace", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/same_name_diff_namespace/run_test.rs b/cpp/libclang/integration_test/cases/same_name_diff_namespace/run_test.rs index 2e5ecc2c..74e47b0c 100644 --- a/cpp/libclang/integration_test/cases/same_name_diff_namespace/run_test.rs +++ b/cpp/libclang/integration_test/cases/same_name_diff_namespace/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; diff --git a/cpp/libclang/integration_test/cases/simple_enums/BUILD b/cpp/libclang/integration_test/cases/simple_enums/BUILD index 9feb2844..b6568e06 100644 --- a/cpp/libclang/integration_test/cases/simple_enums/BUILD +++ b/cpp/libclang/integration_test/cases/simple_enums/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "simple_enums", @@ -26,30 +19,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [], +cpp_parser_integration_test( + name = "test_simple_enums", + expected_output = ["expected.json"], target = ":simple_enums", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/simple_enums/run_test.rs b/cpp/libclang/integration_test/cases/simple_enums/run_test.rs index e9273136..b553e085 100644 --- a/cpp/libclang/integration_test/cases/simple_enums/run_test.rs +++ b/cpp/libclang/integration_test/cases/simple_enums/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/simple_struct/BUILD b/cpp/libclang/integration_test/cases/simple_struct/BUILD index a96f8051..335b8b0c 100644 --- a/cpp/libclang/integration_test/cases/simple_struct/BUILD +++ b/cpp/libclang/integration_test/cases/simple_struct/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "simple_struct", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_simple_struct", + expected_output = ["expected.json"], target = ":simple_struct", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/simple_struct/run_test.rs b/cpp/libclang/integration_test/cases/simple_struct/run_test.rs index b41297d7..532bae69 100644 --- a/cpp/libclang/integration_test/cases/simple_struct/run_test.rs +++ b/cpp/libclang/integration_test/cases/simple_struct/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/template_class/BUILD b/cpp/libclang/integration_test/cases/template_class/BUILD index 2059667b..0f273843 100644 --- a/cpp/libclang/integration_test/cases/template_class/BUILD +++ b/cpp/libclang/integration_test/cases/template_class/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "template_class", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_template_class", + expected_output = ["expected.json"], target = ":template_class", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/template_class/run_test.rs b/cpp/libclang/integration_test/cases/template_class/run_test.rs index 20c7c704..630d054a 100644 --- a/cpp/libclang/integration_test/cases/template_class/run_test.rs +++ b/cpp/libclang/integration_test/cases/template_class/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/type_alias/BUILD b/cpp/libclang/integration_test/cases/type_alias/BUILD index 72ffb00c..912801c5 100644 --- a/cpp/libclang/integration_test/cases/type_alias/BUILD +++ b/cpp/libclang/integration_test/cases/type_alias/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "type_alias", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_type_alias", + expected_output = ["expected.json"], target = ":type_alias", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/type_alias/run_test.rs b/cpp/libclang/integration_test/cases/type_alias/run_test.rs index 9200a149..3e2cd492 100644 --- a/cpp/libclang/integration_test/cases/type_alias/run_test.rs +++ b/cpp/libclang/integration_test/cases/type_alias/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/cases/variable_namespace/BUILD b/cpp/libclang/integration_test/cases/variable_namespace/BUILD index fa7d5e0e..421fd051 100644 --- a/cpp/libclang/integration_test/cases/variable_namespace/BUILD +++ b/cpp/libclang/integration_test/cases/variable_namespace/BUILD @@ -10,14 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") -load("//cpp/libclang:cpp_parser.bzl", "cpp_parser") - -filegroup( - name = "expected_output", - srcs = ["expected.json"], - visibility = ["//cpp/libclang/integration_test:__subpackages__"], -) +load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test") cc_library( name = "variable_namespace", @@ -25,31 +18,8 @@ cc_library( visibility = ["//cpp/libclang:__subpackages__"], ) -cpp_parser( - name = "parser", - emit_debug_json = True, - extra_args = [ - ], +cpp_parser_integration_test( + name = "test_variable_namespace", + expected_output = ["expected.json"], target = ":variable_namespace", - tool = "//cpp/libclang:clang_rs_parser", - visibility = ["//cpp/libclang/integration_test:__pkg__"], -) - -rust_test( - name = "test_libclang_parser", - srcs = [ - "run_test.rs", - ], - data = [ - ":expected_output", - ":parser", - ], - env = { - "TEST_OUTPUT_PATH": "$(rootpath :parser)", - "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", - }, - visibility = ["//cpp/libclang:__pkg__"], - deps = [ - "//cpp/libclang/integration_test:libclang_test_framework", - ], ) diff --git a/cpp/libclang/integration_test/cases/variable_namespace/run_test.rs b/cpp/libclang/integration_test/cases/variable_namespace/run_test.rs index 50fdb974..0b0a40c8 100644 --- a/cpp/libclang/integration_test/cases/variable_namespace/run_test.rs +++ b/cpp/libclang/integration_test/cases/variable_namespace/run_test.rs @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* // Copyright (c) 2026 Contributors to the Eclipse Foundation // // See the NOTICE file(s) distributed with this work for additional @@ -6,10 +6,10 @@ // // This program and the accompanying materials are made available under the // terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 +// // // SPDX-License-Identifier: Apache-2.0 -//////////////////////////////////////////////////////////////////////////////////// +// ******************************************************************************* use test_framework::run_parser_case; #[test] diff --git a/cpp/libclang/integration_test/test_framework.rs b/cpp/libclang/integration_test/test_framework.rs index 50b98084..6cd5ab8f 100644 --- a/cpp/libclang/integration_test/test_framework.rs +++ b/cpp/libclang/integration_test/test_framework.rs @@ -15,7 +15,7 @@ use std::{path::PathBuf, str::FromStr}; fn compare(expected_path: &str, output_path: &str) { let expected = PathBuf::from_str(expected_path).unwrap(); - let output = PathBuf::from_str(output_path).unwrap().join("debug.json"); + let output = PathBuf::from_str(output_path).unwrap(); let expected_json: serde_json::Value = serde_json::from_str(&std::fs::read_to_string(expected).unwrap()).unwrap(); @@ -28,6 +28,6 @@ fn compare(expected_path: &str, output_path: &str) { pub fn run_parser_case() { let expected_path = std::env::var("EXPECTED_OUTPUT_PATH").unwrap(); - let output_path = std::env::var("TEST_OUTPUT_PATH").unwrap(); + let output_path = std::env::var("DEBUG_JSON_OUTPUT_PATH").unwrap(); compare(&expected_path, &output_path); } diff --git a/cpp/libclang/integration_test/test_rules.bzl b/cpp/libclang/integration_test/test_rules.bzl new file mode 100644 index 00000000..e4e8d529 --- /dev/null +++ b/cpp/libclang/integration_test/test_rules.bzl @@ -0,0 +1,87 @@ +# ******************************************************************************* +# Copyright (c) 2026 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* +load("@rules_rust//rust:defs.bzl", "rust_test") +load("//cpp/libclang:cpp_parser.bzl", "CppParserInfo", "cpp_parser") + +def _cpp_parser_debug_json_impl(ctx): + debug_json = ctx.attr.parser[CppParserInfo].debug_json + if not debug_json: + fail("cpp_parser_debug_json requires a cpp_parser target with emit_debug_json = True") + + return [ + DefaultInfo( + files = depset([debug_json]), + runfiles = ctx.runfiles(files = [debug_json]), + ), + ] + +cpp_parser_debug_json = rule( + implementation = _cpp_parser_debug_json_impl, + attrs = { + "parser": attr.label( + mandatory = True, + providers = [CppParserInfo], + ), + }, +) + +def cpp_parser_integration_test( + name, + target, + expected_output, + srcs = None, + extra_args = None, + visibility = None): + if srcs == None: + srcs = ["run_test.rs"] + if extra_args == None: + extra_args = [] + if visibility == None: + visibility = ["//cpp/libclang/integration_test:__pkg__"] + + native.filegroup( + name = "expected_output", + srcs = expected_output, + visibility = visibility, + ) + + cpp_parser( + name = "parser", + emit_debug_json = True, + extra_args = extra_args, + target = target, + visibility = visibility, + ) + + cpp_parser_debug_json( + name = "debug_json", + parser = ":parser", + visibility = visibility, + ) + + rust_test( + name = name, + srcs = srcs, + data = [ + ":expected_output", + ":debug_json", + ], + env = { + "DEBUG_JSON_OUTPUT_PATH": "$(rootpath :debug_json)", + "EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)", + }, + visibility = visibility, + deps = [ + "//cpp/libclang/integration_test:libclang_test_framework", + ], + ) From 4c7ee7ab39d236e25206a787ca17f964d8f92bc4 Mon Sep 17 00:00:00 2001 From: Melody Ma Date: Thu, 18 Jun 2026 17:29:32 +0800 Subject: [PATCH 3/3] feat(rules_score): parse unit implementations with libclang --- bazel/rules/rules_score/private/unit.bzl | 103 ++++++++++++++++------- 1 file changed, 71 insertions(+), 32 deletions(-) diff --git a/bazel/rules/rules_score/private/unit.bzl b/bazel/rules/rules_score/private/unit.bzl index 60f58cf8..612d54b2 100644 --- a/bazel/rules/rules_score/private/unit.bzl +++ b/bazel/rules/rules_score/private/unit.bzl @@ -19,12 +19,32 @@ following S-CORE process guidelines. A unit is the smallest testable software element with associated design, implementation, and tests. """ +load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@lobster//:lobster.bzl", "subrule_gtest_report") +load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") load("@rules_rust//rust:defs.bzl", "rust_common") load("//bazel/rules/rules_score:providers.bzl", "CcDependencyInfo", "CertifiedScope", "SphinxSourcesInfo", "UnitDesignInfo", "UnitInfo") +load("//cpp/libclang:cpp_parser.bzl", "cpp_parser_action_internal_attrs", "cpp_parser_target_aspects", "has_cpp_parser_inputs", "run_cpp_parser_action") load(":cc_dependency_aspect.bzl", "cc_dependencies_aspect") +def _run_implementation_cpp_parser(ctx, impl, output_prefix): + return run_cpp_parser_action( + ctx, + target = impl, + output_prefix = output_prefix, + tool = ctx.attr._tool, + libclang = ctx.file._libclang, + llvm_cxx_builtin_include = ctx.attr._llvm_cxx_builtin_include, + llvm_extra_config_site = ctx.attr._llvm_extra_config_site, + log_level = ctx.attr._log_level[BuildSettingInfo].value, + ) + +def _target_output_prefix(ctx, target): + package_name = target.label.package.replace("/", "_") + target_name = target.label.name.replace("/", "_") + return "{}_{}_{}".format(ctx.label.name, package_name, target_name) + # ============================================================================ # Private Rule Implementation # ============================================================================ @@ -59,28 +79,41 @@ def _unit_impl(ctx): design_static_fbs_depset = depset(transitive = design_static_fbs) design_dynamic_fbs_depset = depset(transitive = design_dynamic_fbs) + # Generate FBS files for implementation targets supported by the libclang parser. + implementation_class_fbs = [] + collected_dependent_labels = [] + for impl in ctx.attr.implementation: + if CcDependencyInfo in impl: + collected_dependent_labels.append(impl[CcDependencyInfo].dependencies) + + if not has_cpp_parser_inputs(impl): + continue + + output_prefix = _target_output_prefix(ctx, impl) + parser_outputs = _run_implementation_cpp_parser(ctx, impl, output_prefix) + implementation_class_fbs.append(parser_outputs.class_fbs) + # Run each test executable via subrule_gtest_report and collect the XML outputs xml_files = [] for test_target in ctx.attr.tests: - pkg = test_target.label.package.replace("/", "_") - test_name = test_target.label.name.replace("/", "_") - unique_name = "{}_{}_{}_gtest_report".format(ctx.label.name, pkg, test_name) - xml = subrule_gtest_report(unique_name, test_target.files_to_run.executable, test_target.default_runfiles.files) + unique_name = "{}_gtest_report".format( + _target_output_prefix(ctx, test_target), + ) + xml = subrule_gtest_report( + unique_name, + test_target.files_to_run.executable, + test_target.default_runfiles.files, + ) xml_files.append(xml) tests_depset = depset(xml_files) # Combine all files for DefaultInfo all_files = depset( - xml_files, + xml_files + implementation_class_fbs, transitive = [design_depset], ) - collected_dependent_labels = [] - for impl in ctx.attr.implementation: - if CcDependencyInfo in impl: - collected_dependent_labels.append(impl[CcDependencyInfo].dependencies) - return [ DefaultInfo(files = all_files), CertifiedScope(transitive_scopes = depset(ctx.attr.scope)), @@ -103,32 +136,38 @@ def _unit_impl(ctx): # Rule Definition # ============================================================================ +_unit_attrs = { + "unit_design": attr.label_list( + mandatory = True, + providers = [UnitDesignInfo], + doc = "Unit design artifacts (unit_design targets only)", + ), + "implementation": attr.label_list( + mandatory = True, + providers = [[CcInfo], [rust_common.crate_info]], + aspects = [cc_dependencies_aspect] + cpp_parser_target_aspects(), + doc = "Implementation targets (cc_library, cc_binary, rust_library, rust_binary, etc.).", + ), + "scope": attr.string_list( + default = [], + doc = "Additional not explicitly named targets which are needed for the unit implementation", + ), + "tests": attr.label_list( + mandatory = True, + cfg = "exec", + doc = "Test targets that verify the unit (cc_test, py_test, rust_test, etc.)", + ), +} + +_unit_attrs.update(cpp_parser_action_internal_attrs()) + _unit = rule( implementation = _unit_impl, doc = "Defines a software unit with design, implementation, and tests for S-CORE process compliance", subrules = [subrule_gtest_report], - attrs = { - "unit_design": attr.label_list( - mandatory = True, - providers = [UnitDesignInfo], - doc = "Unit design artifacts (unit_design targets only)", - ), - "implementation": attr.label_list( - mandatory = True, - providers = [[CcInfo], [rust_common.crate_info]], - aspects = [cc_dependencies_aspect], - doc = "Implementation targets (cc_library, cc_binary, rust_library, rust_binary, etc.)", - ), - "scope": attr.string_list( - default = [], - doc = "Additional not explicitly named targets which are needed for the unit implementation", - ), - "tests": attr.label_list( - mandatory = True, - cfg = "exec", - doc = "Test targets that verify the unit (cc_test, py_test, rust_test, etc.)", - ), - }, + attrs = _unit_attrs, + toolchains = use_cc_toolchain(), + fragments = ["cpp"], ) # ============================================================================