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
41 changes: 2 additions & 39 deletions bazel/rules/rules_score/examples/seooc/safety_analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,11 @@
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

load("@trlc//:trlc.bzl", "trlc_requirements", "trlc_requirements_test")
load(
"//bazel/rules/rules_score:rules_score.bzl",
"fmea",
)

# FMEA
trlc_requirements(
name = "sample_fmea_failure_modes",
srcs = [
"sample_fmea_failure_modes.trlc",
],
spec = [
"@score_tooling//bazel/rules/rules_score/trlc/config:score_requirements_model",
],
visibility = ["//visibility:public"],
)

trlc_requirements(
name = "sample_fmea_control_measures",
srcs = [
"sample_fmea_control_measures.trlc",
],
spec = [
"@score_tooling//bazel/rules/rules_score/trlc/config:score_requirements_model",
],
visibility = ["//visibility:public"],
deps = [
":sample_fmea_failure_modes",
],
)

trlc_requirements_test(
name = "sample_fmea_test",
reqs = [
":sample_fmea_control_measures",
],
visibility = ["//visibility:public"],
)

# FTA

filegroup(
Expand All @@ -64,10 +29,8 @@ filegroup(
fmea(
name = "sample_fmea",
arch_design = "//bazel/rules/rules_score/examples/seooc/design:sample_seooc_design",
controlmeasures = [
":sample_fmea_control_measures",
],
failuremodes = [":sample_fmea_failure_modes"],
controlmeasures = ["sample_fmea_control_measures.trlc"],
failuremodes = ["sample_fmea_failure_modes.trlc"],
root_causes = [":sample_fta"],
visibility = ["//visibility:public"],
)
1 change: 0 additions & 1 deletion bazel/rules/rules_score/private/architectural_design.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def _architectural_design_impl(ctx):
SphinxSourcesInfo(
srcs = sphinx_srcs,
deps = sphinx_srcs,
ancillary = depset(),
),
]

Expand Down
1 change: 0 additions & 1 deletion bazel/rules/rules_score/private/assumptions_of_use.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def _assumptions_of_use_impl(ctx):
SphinxSourcesInfo(
srcs = all_srcs,
deps = depset(transitive = transitive),
ancillary = depset(),
),
]

Expand Down
1 change: 0 additions & 1 deletion bazel/rules/rules_score/private/component.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def _component_impl(ctx):
SphinxSourcesInfo(
srcs = req_sphinx_depset,
deps = sphinx_depset,
ancillary = depset(),
),
]

Expand Down
20 changes: 8 additions & 12 deletions bazel/rules/rules_score/private/dependability_analysis.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,21 @@ load("//bazel/rules/rules_score/private:lobster_config.bzl", "format_lobster_sou
# Private Helpers
# ============================================================================

def _collect_analysis_providers(sa, rst_srcs_list, rst_deps_list, rst_ancillary_list, lobster_files):
def _collect_analysis_providers(sa, rst_srcs_list, rst_deps_list, lobster_files):
"""Collect analysis providers from a single sub-analysis target.

Updates the provided lists/dicts in-place.

Args:
sa: A sub-analysis target (fmea or security).
rst_srcs_list: List of depsets to extend with SphinxSourcesInfo.srcs.
rst_deps_list: List of depsets to extend with SphinxSourcesInfo.deps.
rst_ancillary_list: List of depsets to extend with SphinxSourcesInfo.ancillary.
lobster_files: Dict to update with AnalysisInfo.lobster_files
(canonical name → File).
sa: A sub-analysis target (fmea or security).
rst_srcs_list: List of depsets to extend with SphinxSourcesInfo.srcs.
rst_deps_list: List of depsets to extend with SphinxSourcesInfo.deps.
lobster_files: Dict to update with AnalysisInfo.lobster_files
(canonical name → File).
"""
if SphinxSourcesInfo in sa:
rst_srcs_list.append(sa[SphinxSourcesInfo].srcs)
rst_deps_list.append(sa[SphinxSourcesInfo].deps)
rst_ancillary_list.append(sa[SphinxSourcesInfo].ancillary)
if AnalysisInfo in sa:
lobster_files.update(sa[AnalysisInfo].lobster_files)

Expand Down Expand Up @@ -76,7 +74,6 @@ def _dependability_analysis_impl(ctx):

rst_srcs_transitive = [dfa_rst_files]
rst_deps_transitive = [dfa_rst_files]
rst_ancillary_transitive = []
lobster_files = {} # canonical name → File, merged from all sub-analyses

# -------------------------------------------------------------------------
Expand All @@ -85,15 +82,15 @@ def _dependability_analysis_impl(ctx):
fmea_output_files = []
for sa in ctx.attr.fmea:
fmea_output_files.append(sa[DefaultInfo].files)
_collect_analysis_providers(sa, rst_srcs_transitive, rst_deps_transitive, rst_ancillary_transitive, lobster_files)
_collect_analysis_providers(sa, rst_srcs_transitive, rst_deps_transitive, lobster_files)

# -------------------------------------------------------------------------
# Collect from security_analysis targets
# -------------------------------------------------------------------------
security_output_files = []
for sa in ctx.attr.security_analysis:
security_output_files.append(sa[DefaultInfo].files)
_collect_analysis_providers(sa, rst_srcs_transitive, rst_deps_transitive, rst_ancillary_transitive, lobster_files)
_collect_analysis_providers(sa, rst_srcs_transitive, rst_deps_transitive, lobster_files)

# Architectural design sphinx deps (optional)
if ctx.attr.arch_design and SphinxSourcesInfo in ctx.attr.arch_design:
Expand Down Expand Up @@ -185,7 +182,6 @@ def _dependability_analysis_impl(ctx):
SphinxSourcesInfo(
srcs = all_rst_srcs,
deps = all_rst_deps,
ancillary = depset(transitive = rst_ancillary_transitive),
),
]

Expand Down
27 changes: 8 additions & 19 deletions bazel/rules/rules_score/private/dependable_element.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ _INTEGRITY_LEVEL_RANK = {level: rank for rank, level in enumerate(_INTEGRITY_LEV
# ============================================================================

def _get_sphinx_files(target):
return target[SphinxSourcesInfo].srcs.to_list()
return target[SphinxSourcesInfo].deps.to_list()

def _filter_doc_files(files):
"""Filter files to only include documentation files.
Expand Down Expand Up @@ -249,13 +249,17 @@ def _process_artifact_files(ctx, artifact_name, label):
output_files = []
index_refs = []

# Get and filter files
# deps contains all files to symlink (own srcs + transitive children);
# srcs are the toctree entries for this rule only.
all_files = _get_sphinx_files(label)
doc_files = _filter_doc_files(all_files)

if not doc_files:
return (output_files, index_refs)

# Build a lookup of srcs paths so we know which files are toctree entries.
srcs_paths = {f.path: True for f in label[SphinxSourcesInfo].srcs.to_list()}

# Find common directory to preserve hierarchy
common_dir = _find_common_directory(doc_files)

Expand All @@ -273,28 +277,13 @@ def _process_artifact_files(ctx, artifact_name, label):
)
output_files.append(output_file)

# Add to index if it's a document file
if _is_document_file(artifact_file):
# Add to toctree index only for files directly owned by this rule.
if _is_document_file(artifact_file) and artifact_file.path in srcs_paths:
doc_ref = (artifact_name + "/" + relative_path) \
.replace(".rst", "") \
.replace(".md", "")
index_refs.append(doc_ref)

# Symlink ancillary files (present for sub-toctrees / .. uml:: resolution,
# but NOT added to the outer toctree index).
if SphinxSourcesInfo in label:
for anc_file in label[SphinxSourcesInfo].ancillary.to_list():
if anc_file.extension not in ["rst", "md", "puml", "plantuml", "png", "svg", "inc", "json"]:
continue
relative_path = _compute_relative_path(anc_file, _find_common_directory([anc_file]))
output_file = _create_artifact_symlink(
ctx,
artifact_name,
anc_file,
relative_path,
)
output_files.append(output_file)

return (output_files, index_refs)

def _process_artifact_type(ctx, artifact_name):
Expand Down
Loading
Loading