From 491f36caf4ba29031bac8d27ab2304b9a7472936 Mon Sep 17 00:00:00 2001 From: George Dadunashvili Date: Tue, 12 May 2026 14:02:23 +0200 Subject: [PATCH] plant_uml_parser: create a public rule to parse groups of UML files --- .../private/architectural_design.bzl | 43 +++++++++++++++++-- bazel/rules/rules_score/rules_score.bzl | 2 + 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/bazel/rules/rules_score/private/architectural_design.bzl b/bazel/rules/rules_score/private/architectural_design.bzl index eabb8b4..56bd154 100644 --- a/bazel/rules/rules_score/private/architectural_design.bzl +++ b/bazel/rules/rules_score/private/architectural_design.bzl @@ -52,10 +52,13 @@ def _run_puml_parser(ctx, puml_file): lobster_output = ctx.actions.declare_file( "{}/{}.lobster".format(ctx.label.name, file_stem), ) + json_output = ctx.actions.declare_file( + "{}/{}.logic.ast.json".format(ctx.label.name, file_stem), + ) ctx.actions.run( inputs = [puml_file], - outputs = [fbs_output, lobster_output], + outputs = [fbs_output, lobster_output, json_output], executable = ctx.executable._puml_parser, arguments = [ "--file", @@ -65,12 +68,14 @@ def _run_puml_parser(ctx, puml_file): "--lobster-output-dir", lobster_output.dirname, "--log-level", - get_log_level(ctx), + # gToDo: log level needs to be debug for ast.json to be generated + "debug", + # get_log_level(ctx), ], progress_message = "Parsing PlantUML diagram: %s" % puml_file.short_path, ) - return fbs_output, lobster_output + return fbs_output, lobster_output, json_output def _parse_puml_diagrams(ctx, files): """Run the PlantUML parser on all .puml/.plantuml files in a list. @@ -226,6 +231,38 @@ _architectural_design = rule( **VERBOSITY_ATTR ), ) +def _parse_puml_diagrams_impl(ctx): + print(ctx.attr.files) + print(ctx.files.files[0]) + # gToDo: shaky mit [0] + fbs_output, lobster_output, json_output = _run_puml_parser(ctx, ctx.files.files[0]) + return [ + DefaultInfo( + files = depset([fbs_output, lobster_output, json_output]), + ), + ] + +parse_puml_diagrams = rule( + implementation = _parse_puml_diagrams_impl, + doc = "Helper rule to run the PlantUML parser on a list of .puml files and produce FlatBuffers binaries and lobster files.", + attrs = { + "files": attr.label( + mandatory = True, + doc = "List of .puml/.plantuml files to parse", + allow_single_file = True, + ), + "_puml_parser": attr.label( + default = Label("@score_tooling//plantuml/parser:parser"), + executable = True, + cfg = "exec", + doc = "PlantUML parser tool that generates FlatBuffers from .puml files", + ), + "_verbosity": attr.label( + default = Label("//bazel/rules/rules_score:verbosity"), + doc = "Verbosity level build setting (warn/info/debug).", + ), + }, +) # ============================================================================ # Public Macro diff --git a/bazel/rules/rules_score/rules_score.bzl b/bazel/rules/rules_score/rules_score.bzl index 3df157f..68f1cb1 100644 --- a/bazel/rules/rules_score/rules_score.bzl +++ b/bazel/rules/rules_score/rules_score.bzl @@ -20,6 +20,7 @@ load( load( "//bazel/rules/rules_score/private:architectural_design.bzl", _architectural_design = "architectural_design", + _parse_puml_diagrams = "parse_puml_diagrams", ) load( "//bazel/rules/rules_score/private:assumed_system_requirements.bzl", @@ -71,6 +72,7 @@ load( ) architectural_design = _architectural_design +parse_puml_diagrams = _parse_puml_diagrams assumptions_of_use = _assumptions_of_use assumed_system_requirements = _assumed_system_requirements component_requirements = _component_requirements