Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
336 changes: 178 additions & 158 deletions .cmake-format.py

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions .conan/test_packages/package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@

# === conanfile.py =====================================================================================================
# Sen Infrastructure
# Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
# See the LICENSE.txt file for more information.
# © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
# ======================================================================================================================

# test to consume conan package in conan v2 way
"""Module that defines a test_package test to consume conan package in conan v2 way."""

from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, CMakeToolchain


class TestPackageConan(ConanFile):
"""Conan file that specifies how a project is setup that uses Sen."""

settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
"""Defines the dependencies of Sen."""
self.requires(self.tested_reference_str)

def generate(self):
"""Generate the toolchain files."""
tc = CMakeToolchain(self, generator="Ninja")
tc.generate()

def build(self):
"""Configure and build Sen test_package."""
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
"""Defines a few test calls to ensure Sen works."""
if not cross_building(self):
self.run("sen --version", env="conanrun")
# TODO(SEN-1185): enable tests when possible
Expand Down
1 change: 0 additions & 1 deletion .conan/test_packages/package/my_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ add_sen_package(
target_sources(my_package PRIVATE ${_combined_schema})
target_link_libraries(my_package PRIVATE $<BUILD_INTERFACE:spdlog::spdlog>)
set_target_properties(my_package PROPERTIES FOLDER "examples/basic")
set_target_properties(my_package PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# TODO(SEN-1185): enable tests when possible
configure_file(config/my_package.yaml ${CMAKE_BINARY_DIR}/test_configs/my_package.yaml COPYONLY)
94 changes: 55 additions & 39 deletions .github/scripts/generate_matrix_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@
# See the LICENSE.txt file for more information.
# © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
# ======================================================================================================================
"""
Script to generate various forms of job matrices.
"""
import os
"""Script to generate various forms of job matrices."""

import argparse
import json
import os
import typing as tp
import argparse
from dataclasses import dataclass, is_dataclass, asdict
from dataclasses import asdict, dataclass, is_dataclass


def convert_dataclass_to_json(obj) -> dict:
"""Converts the given dataclass to json."""
if is_dataclass(obj):
return {
key: convert_dataclass_to_json(value)
for key, value in asdict(obj).items()
}
return {key: convert_dataclass_to_json(value) for key, value in asdict(obj).items()}

return obj


@dataclass(frozen=True, order=True)
class Compiler:
"""Compiler specification"""
"""Compiler specification."""

name: str
version: int
cc: str
Expand All @@ -36,13 +33,15 @@ class Compiler:

@dataclass(frozen=True, order=True)
class Container:
"""Container specification"""
"""Container specification."""

image: str


@dataclass(frozen=True, order=True)
class JobSpecification:
"""Pipeline job specification that defines the configuration options."""

name: str
os: str
runner: tp.Literal["ubuntu-latest", "windows-2022", "self-hosted", "ubuntu-24.04-arm"]
Expand All @@ -56,47 +55,65 @@ def as_json(self) -> dict:
return convert_dataclass_to_json(self)


def compute_jobs(release: bool, conan: bool) -> list[JobSpecification]:
def compute_jobs(release: bool, conan: bool) -> list[JobSpecification]: # noqa: ARG001
"""Computes the list of pipeline jobs that should run."""
jobs = []

# Add gcc jobs
if not release:
jobs.append(
JobSpecification("Basic GCC", "ubuntu-22.04", "self-hosted", None,
Compiler("gcc", 12, "gcc-12", "g++-12"), 17,
"Debug"))
JobSpecification(
"Basic GCC", "ubuntu-22.04", "self-hosted", None, Compiler("gcc", 12, "gcc-12", "g++-12"), 17, "Debug"
)
)
else:
jobs.append(
JobSpecification("Basic GCC", "ubuntu-22.04", "self-hosted", None,
Compiler("gcc", 12, "gcc-12", "g++-12"), 17,
"Release"))
JobSpecification(
"Basic GCC", "ubuntu-22.04", "self-hosted", None, Compiler("gcc", 12, "gcc-12", "g++-12"), 17, "Release"
)
)

# Add clang jobs
if not release:
jobs.append(
JobSpecification("Basic Clang", "ubuntu-24.04", "self-hosted",
None,
Compiler("clang", 20, "clang-20",
"clang++-20"), 17, "Debug"))
JobSpecification(
"Basic Clang",
"ubuntu-24.04",
"self-hosted",
None,
Compiler("clang", 20, "clang-20", "clang++-20"),
17,
"Debug",
)
)

# Add msvc jobs
if release:
jobs.append(
JobSpecification("Basic Windows", "windows", "windows-2022", None,
Compiler("msvc", 194, "cl", "cl"), 17, "Release"))
JobSpecification(
"Basic Windows", "windows", "windows-2022", None, Compiler("msvc", 194, "cl", "cl"), 17, "Release"
)
)
else:
jobs.append(
JobSpecification("Basic Windows", "windows", "windows-2022", None,
Compiler("msvc", 194, "cl", "cl"), 17, "Debug"))
JobSpecification(
"Basic Windows", "windows", "windows-2022", None, Compiler("msvc", 194, "cl", "cl"), 17, "Debug"
)
)

# Add amd64 jobs
if not release:
jobs.append(
JobSpecification("Basic Ubuntu arm", "ubuntu-24.04",
"ubuntu-24.04-arm", None,
Compiler("gcc_arm64", 12, "gcc-14",
"g++-14"), 17, "Debug"))
JobSpecification(
"Basic Ubuntu arm",
"ubuntu-24.04",
"ubuntu-24.04-arm",
None,
Compiler("gcc_arm64", 12, "gcc-14", "g++-14"),
17,
"Debug",
)
)

return sorted(jobs)

Expand All @@ -106,9 +123,8 @@ def generate_jobs_file(release: bool, conan: bool) -> None:
jobs = compute_jobs(release, conan)

if output_file := os.environ.get("GITHUB_OUTPUT"):
with open(output_file, "wt", encoding='utf-8') as matrix_file:
matrix_file.write(
f"jobs={json.dumps([j.as_json() for j in jobs])}")
with open(output_file, "w", encoding="utf-8") as matrix_file:
matrix_file.write(f"jobs={json.dumps([j.as_json() for j in jobs])}")
else:
print("Error: No output file specified to write to.")

Expand All @@ -117,18 +133,18 @@ def main() -> None:
"""Runs the job matrix generator."""
parser = argparse.ArgumentParser(
prog="generate_matrix_jobs",
description=
"Generates the list of required matrix jobs for various building needs."
description="Generates the list of required matrix jobs for various building needs.",
)
parser.add_argument(
"--release",
action=argparse.BooleanOptionalAction,
help="Generate the jobs needed for building release artifacts.")
help="Generate the jobs needed for building release artifacts.",
)
parser.add_argument(
"--conan",
action=argparse.BooleanOptionalAction,
help=
"Generate the jobs needed to ensure all required conan packages work.")
help="Generate the jobs needed to ensure all required conan packages work.",
)

args = parser.parse_args()

Expand Down
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,19 @@ repos:
hooks:
- id: cmake-format

- repo: https://github.com/jackdewinter/pymarkdown
rev: v0.9.20
hooks:
- id: pymarkdown
name: Checking markdown files
args: [--config, .pymarkdown.yaml, fix]

- repo: https://github.com/astral-sh/ruff-pre-commit.git
rev: v0.4.8
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

# Global Configuration
exclude: (examples/packages/hla_fom/.*|test/util/dummy_entities/hla/.*|.*.svg|.*.excalidraw|stl.tmLanguage.json)
34 changes: 34 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
line-length = 120
indent-width = 4
include = ["*.py"]

[format]
quote-style = "double"
indent-style = "space"
line-ending = "auto"

[lint]
select = [
"ARG",
"B",
"C",
"D",
"E",
"F",
"I",
"I",
"PLC",
"PLE",
"PLW",
"UP",
"W",
]
ignore = [
"D105", # The meaning of special member functions can be found in the python documentation
"D203", # Conflicts with D211(blank-line-before-class)
"D212", # Conflicts with D213(multi-line-summary-second-line)
]
preview = true

[lint.pydocstyle]
convention = "google"
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ if(SEN_BUILD_TESTS)
add_subdirectory(test/util/calls_on_removal)
add_subdirectory(test/util/publish_types_manually)
add_subdirectory(test/util/query_test)
add_subdirectory(test/support)
endif()

# coverage
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MyProjectConan(ConanFile):
self.requires("sen/[>=1.0]")
```

2. Run `conan install . --profile <your_conan_profile> --build=missing` to download Sen before running CMake.
1. Run `conan install . --profile <your_conan_profile> --build=missing` to download Sen before running CMake.

To ensure your system is able to find all paths, add the `bin` folder to your `PATH` environment variable (in Linux also
add it to the `LD_LIBRARY_PATH`). Check that everything works by running `sen shell`. You can play with the objects in the `local` session.
Expand Down
13 changes: 13 additions & 0 deletions apps/cli_gen/src/cpp/templates/struct_impl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,16 @@ sen::ConstTypeHandle<::sen::StructType> sen::MetaTypeTrait<{{ qualType }}>::meta
});
return type;
}

std::string sen::SerializationTraits<{{ qualType }}>::toJsonString(const {{ qualType }}& val)
{
::sen::Var var;
::sen::VariantTraits<{{ qualType }}>::valueToVariant(val, var);
return ::sen::toJson(var);
}

void sen::SerializationTraits<{{ qualType }}>::fromJsonString(const std::string& str, {{ qualType }}& val)
{
const ::sen::Var var = ::sen::fromJson(str);
::sen::VariantTraits<{{ qualType }}>::variantToValue(var, val);
}
13 changes: 13 additions & 0 deletions apps/cli_gen/src/cpp/templates/variant_impl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,16 @@ std::function<::sen::lang::Value(const void*)> sen::VariantTraits<{{ qualType }}
});
return type;
}

std::string sen::SerializationTraits<{{ qualType }}>::toJsonString(const {{ qualType }}& val)
{
::sen::Var var;
::sen::VariantTraits<{{ qualType }}>::valueToVariant(val, var);
return ::sen::toJson(var);
}

void sen::SerializationTraits<{{ qualType }}>::fromJsonString(const std::string& str, {{ qualType }}& val)
{
const ::sen::Var var = ::sen::fromJson(str);
::sen::VariantTraits<{{ qualType }}>::variantToValue(var, val);
}
19 changes: 18 additions & 1 deletion apps/cli_gen/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# ======================================================================================================================

set(hla_fom_gen_test_sources ${CMAKE_CURRENT_SOURCE_DIR})
set(working_dir ${CMAKE_BINARY_DIR}/bin)
set(working_dir $<TARGET_FILE_DIR:sen::cli_gen>)

# Test case 1
#
Expand Down Expand Up @@ -272,3 +272,20 @@ add_sen_integration_test(

# link them so the checker only runs if the generator succeeds
set_tests_properties(hla_fom_gen_integration_test_19 PROPERTIES ENVIRONMENT "PYTHONUNBUFFERED=1")

# Test case 20
#
# ModuleA-20 defines interactions with optional and required parameters
#
# Tests that the cli_gen generates MaybeXX types for optional parameters and standard types for required parameters
add_sen_integration_test(
hla_fom_gen_integration_test_20
COMMAND
${Python3_EXECUTABLE}
${hla_fom_gen_test_sources}/test20/test.py
WORKING_DIRECTORY ${working_dir}
REQ_DEPS cli_gen
)

# link them so the checker only runs if the generator succeeds
set_tests_properties(hla_fom_gen_integration_test_20 PROPERTIES ENVIRONMENT "PYTHONUNBUFFERED=1")
Loading
Loading