Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bazel/rules/rules_score/examples/seooc/unit_2/bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace unit_2 {
// SampleComponent.REQ_COMP_005
class Bar final {
public:
explicit Bar(std::unique_ptr<unit_1::Foo>);
explicit Bar(std::unique_ptr<unit_1::Foo> foo);
bool AssertNumber() const;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
@startuml unit_2_class_diagram

namespace unit_1 {
class Foo {
{final}
class Foo <<final>>{
--
+ GetNumber() : uint8_t
+ SetNumber(value : uint8_t) : void
}
}

namespace unit_2 {
class Bar {
{final}
class Bar <<final>>{
--
- foo_ : unique_ptr<unit_1::Foo>
--
Expand Down
34 changes: 33 additions & 1 deletion bazel/rules/rules_score/private/unit.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ 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_action_toolchains", "cpp_parser_target_aspects", "has_cpp_parser_inputs", "run_cpp_parser_action")
load(":cc_dependency_aspect.bzl", "cc_dependencies_aspect")
load(":validation.bzl", "PROFILES", "VALIDATION_ATTRS", "run_validation")
load(":verbosity.bzl", "VERBOSITY_ATTR", "get_log_level")

def _run_implementation_cpp_parser(ctx, impl, output_prefix):
return run_cpp_parser_action(
Expand All @@ -42,6 +44,21 @@ def _target_output_prefix(ctx, target):
target_name = target.label.name.replace("/", "_")
return "{}_{}_{}".format(ctx.label.name, package_name, target_name)

def _run_validation(ctx, design_class_fbs, implementation_class_fbs):
return run_validation(
ctx = ctx,
validation_cli = ctx.executable._validation_cli,
profile = PROFILES.UNIT,
input_bundle = {
"design_classes": [f.path for f in design_class_fbs],
"implementation_classes": [f.path for f in implementation_class_fbs],
},
inputs = design_class_fbs + implementation_class_fbs,
mnemonic = "UnitValidate",
maturity = ctx.attr.maturity,
log_level = get_log_level(ctx),
)

# ============================================================================
# Private Rule Implementation
# ============================================================================
Expand Down Expand Up @@ -105,9 +122,15 @@ def _unit_impl(ctx):

tests_depset = depset(xml_files)

validation_log = _run_validation(
ctx,
design_static_fbs_depset.to_list(),
implementation_class_fbs,
)

# Combine all files for DefaultInfo
all_files = depset(
xml_files + implementation_class_fbs,
xml_files + implementation_class_fbs + [validation_log.file],
transitive = [design_depset],
)

Expand All @@ -119,6 +142,8 @@ def _unit_impl(ctx):
unit_design = design_depset,
unit_design_static_fbs = design_static_fbs_depset,
unit_design_dynamic_fbs = design_dynamic_fbs_depset,
implementation_class_fbs = depset(implementation_class_fbs),
implementation_sequence_fbs = depset(),
implementation = depset(ctx.attr.implementation),
tests = tests_depset,
dependent_labels = depset(transitive = collected_dependent_labels),
Expand Down Expand Up @@ -155,9 +180,16 @@ _unit_attrs = {
cfg = "exec",
doc = "Test targets that verify the unit (cc_test, py_test, rust_test, etc.)",
),
"maturity": attr.string(
default = "release",
values = ["release", "development"],
doc = "Maturity level of the unit. 'release' treats validation findings as errors; 'development' emits warnings and continues.",
),
}

_unit_attrs.update(cpp_parser_action_internal_attrs())
_unit_attrs.update(VALIDATION_ATTRS)
_unit_attrs.update(VERBOSITY_ATTR)

_unit = rule(
implementation = _unit_impl,
Expand Down
1 change: 1 addition & 0 deletions bazel/rules/rules_score/private/validation.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
PROFILES = struct(
ARCHITECTURAL_DESIGN = "architectural-design",
DEPENDABLE_ELEMENT = "dependable-element",
UNIT = "unit",
)

VALIDATION_ATTRS = {
Expand Down
2 changes: 2 additions & 0 deletions bazel/rules/rules_score/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ UnitInfo = provider(
"unit_design": "Depset of design artifact files (PlantUML diagrams, RST documents, etc.).",
"unit_design_static_fbs": "Depset of FlatBuffers binaries generated from static unit_design diagrams.",
"unit_design_dynamic_fbs": "Depset of FlatBuffers binaries generated from dynamic unit_design diagrams.",
"implementation_class_fbs": "Depset of FlatBuffers binaries generated from implementation class diagrams.",
"implementation_sequence_fbs": "Depset of FlatBuffers binaries generated from implementation sequence diagrams.",
"implementation": "Depset of implementation targets (cc_library, rust_library, etc.).",
"tests": "Depset of test targets (cc_test, rust_test, etc.).",
"dependent_labels": "Depset of Labels that this unit's implementation depends on transitively (used for certification scope validation).",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"methods": [
{
"name": "Car",
"return_type": "void",
"return_type": null,
"parameters": [
{
"is_variadic": false,
Expand Down Expand Up @@ -101,7 +101,7 @@
"methods": [
{
"name": "~ITransport",
"return_type": "void",
"return_type": null,
"parameters": [],
"modifiers": [
"Virtual",
Expand Down Expand Up @@ -149,7 +149,7 @@
"methods": [
{
"name": "VehicleBase",
"return_type": "void",
"return_type": null,
"parameters": [
{
"is_variadic": false,
Expand All @@ -165,7 +165,7 @@
},
{
"name": "~VehicleBase",
"return_type": "void",
"return_type": null,
"parameters": [],
"modifiers": [
"Virtual",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"visibility": "private"
}
],
"source_file": "./cpp/libclang/integration_test/cases/include_3rdparty/transport.h",
"source_file": "cpp/libclang/integration_test/cases/include_3rdparty/transport.h",
"source_line": 19
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"methods": [
{
"name": "~ITransport",
"return_type": "void",
"return_type": null,
"parameters": [],
"modifiers": [
"Virtual",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"methods": [
{
"name": "~IService",
"return_type": "void",
"return_type": null,
"parameters": [],
"modifiers": [
"Virtual",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"methods": [
{
"name": "~Base",
"return_type": "void",
"return_type": null,
"parameters": [],
"modifiers": [
"Virtual",
Expand Down
16 changes: 8 additions & 8 deletions cpp/libclang/integration_test/cases/simple_enums/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"template_parameters": null,
"type_aliases": [],
"variables": [],
"source_file": null,
"source_line": null
"source_file": "cpp/libclang/integration_test/cases/simple_enums/transport.h",
"source_line": 25
},
"MyNamespace::Direction": {
"id": "MyNamespace::Direction",
Expand Down Expand Up @@ -59,8 +59,8 @@
"template_parameters": null,
"type_aliases": [],
"variables": [],
"source_file": null,
"source_line": null
"source_file": "cpp/libclang/integration_test/cases/simple_enums/transport.h",
"source_line": 35
},
"RGBColor": {
"id": "RGBColor",
Expand All @@ -86,8 +86,8 @@
"template_parameters": null,
"type_aliases": [],
"variables": [],
"source_file": null,
"source_line": null
"source_file": "cpp/libclang/integration_test/cases/simple_enums/transport.h",
"source_line": 17
},
"MyNamespace::Direction3D": {
"id": "MyNamespace::Direction3D",
Expand Down Expand Up @@ -125,8 +125,8 @@
"template_parameters": null,
"type_aliases": [],
"variables": [],
"source_file": null,
"source_line": null
"source_file": "cpp/libclang/integration_test/cases/simple_enums/transport.h",
"source_line": 43
}
},
"functions": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"methods": [
{
"name": "Car",
"return_type": "void",
"return_type": null,
"parameters": [
{
"name": "name",
Expand Down
8 changes: 6 additions & 2 deletions cpp/libclang/src/visitor/src/class_parser_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,13 @@ pub fn to_workspace_relative_or_abs_path(abs_path: std::path::PathBuf) -> String
// so golden files stay portable across machines.
if let Ok(cwd) = std::env::current_dir() {
if let Ok(rel) = abs_path.strip_prefix(&cwd) {
return rel.to_string_lossy().into_owned();
return normalize_source_path(rel.to_string_lossy().as_ref());
}
}

abs_path.to_string_lossy().into_owned()
normalize_source_path(abs_path.to_string_lossy().as_ref())
}

fn normalize_source_path(path: &str) -> String {
path.strip_prefix("./").unwrap_or(path).to_string()
}
15 changes: 9 additions & 6 deletions cpp/libclang/src/visitor/src/class_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl ClassVisitor {
}
}

fn parse_source_location(entity: &Entity) -> (Option<String>, Option<u32>) {
pub(crate) fn parse_source_location(entity: &Entity) -> (Option<String>, Option<u32>) {
let Some(location) = entity.get_location() else {
return (None, None);
};
Expand Down Expand Up @@ -207,10 +207,13 @@ fn parse_method(entity: &Entity, parsed_method_type: &ParsedMethodType) -> Optio
.map(|methods| !methods.is_empty())
.unwrap_or(false);

let return_type = entity
.get_result_type()
.map(|ret| render_type_for_display(&ret, &parsed_method_type.return_type))
.unwrap_or_else(|| "void".to_string());
let return_type = if matches!(kind, EntityKind::Constructor | EntityKind::Destructor) {
None
} else {
entity
.get_result_type()
.map(|ret| render_type_for_display(&ret, &parsed_method_type.return_type))
};

let mut parameters = Vec::new();
let method_is_variadic = entity.get_type().map(|t| t.is_variadic()).unwrap_or(false);
Expand All @@ -233,7 +236,7 @@ fn parse_method(entity: &Entity, parsed_method_type: &ParsedMethodType) -> Optio

Some(Method {
name,
return_type: Some(return_type),
return_type,
visibility: parse_visibility(entity),
parameters,
template_parameters: None,
Expand Down
5 changes: 5 additions & 0 deletions cpp/libclang/src/visitor/src/enum_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
// SPDX-License-Identifier: Apache-2.0
////////////////////////////////////////////////////////////////////////////////////
use crate::class_visitor::parse_source_location;
use crate::context::VisitContext;
use crate::visitor::AstVisitor;
use clang::Entity;
Expand All @@ -34,12 +35,16 @@ impl EnumVisitor {
} else {
name.clone()
};
let (source_file, source_line) = parse_source_location(&entity);

Some(SimpleEntity {
id: full_qualified_id,
name,
enclosing_namespace_id: namespace_id,
entity_type: EntityType::Enum,
enum_literals: get_literals(entity),
source_file,
source_line,
..Default::default()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@
],
"template_parameters": null,
"enum_literals": [],
"source_file": "class_diagram_cpp_members",
"source_file": "class_diagram_cpp_members.puml",
"source_line": 16,
"variables": [],
"relationships": []
}
],
"relationships": [],
"source_files": [
"class_diagram_cpp_members"
"class_diagram_cpp_members.puml"
],
"version": null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"value": 11
}
],
"source_file": "class_diagram_enum_value_sequence",
"source_file": "class_diagram_enum_value_sequence.puml",
"source_line": 17,
"variables": [],
"relationships": []
Expand Down Expand Up @@ -67,7 +67,7 @@
"value": 11
}
],
"source_file": "class_diagram_enum_value_sequence",
"source_file": "class_diagram_enum_value_sequence.puml",
"source_line": 29,
"variables": [],
"relationships": []
Expand Down Expand Up @@ -102,15 +102,15 @@
"value": 2
}
],
"source_file": "class_diagram_enum_value_sequence",
"source_file": "class_diagram_enum_value_sequence.puml",
"source_line": 39,
"variables": [],
"relationships": []
}
],
"relationships": [],
"source_files": [
"class_diagram_enum_value_sequence"
"class_diagram_enum_value_sequence.puml"
],
"version": null
}
Expand Down
Loading
Loading