Skip to content

Commit

Permalink
feat: Output Conan 1.62 package for C++ generated code (eclipse-veloc…
Browse files Browse the repository at this point in the history
  • Loading branch information
doosuu committed Feb 20, 2024
1 parent 0c814d8 commit c4b5582
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
run: |
pip install -r requirements-dev.txt
pip install -r requirements.txt
pip install -r tests/requirements.txt
pip install -e .
- name: unit test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ dmypy.json
output/
velocitas_model/
out/
gen_model/

# test data repos
tests/data/vspec
Expand Down
13 changes: 3 additions & 10 deletions NOTICE-3RD-PARTY-CONTENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
| Dependency | Version | License |
|:-----------|:-------:|--------:|
|cfgv|3.4.0|MIT|
|coverage|7.4.0|Apache 2.0|
|distlib|0.3.8|Python Software Foundation License|
|exceptiongroup|1.2.0|MIT|
|filelock|3.13.1|The Unlicense (Unlicense)|
|identify|2.5.33|MIT|
|iniconfig|2.0.0|MIT|
|identify|2.5.34|MIT|
|mypy|1.8.0|MIT|
|mypy-extensions|1.0.0|MIT|
|nodeenv|1.8.0|BSD|
|packaging|23.2|Apache 2.0<br/>BSD|
|platformdirs|4.1.0|MIT|
|pluggy|1.4.0|MIT|
|pre-commit|3.6.0|MIT|
|pytest|7.4.4|MIT|
|pytest-cov|4.1.0|MIT|
|platformdirs|4.2.0|MIT|
|pre-commit|3.6.1|MIT|
|PyYAML|6.0.1|MIT|
|setuptools|58.1.0|MIT|
|tomli|2.0.1|MIT|
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
pytest
pytest-cov
pre-commit>=3.5.0
mypy
6 changes: 6 additions & 0 deletions src/velocitas/model_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@

"""Convert all vspec input files to Velocitas Python Vehicle Model."""

import os
import shutil
import sys
from typing import List

import vspec # type: ignore

from velocitas.model_generator.cpp.cpp_generator import VehicleModelCppGenerator
Expand Down Expand Up @@ -66,6 +69,9 @@ def generate_model(
print(f"Known extended attributes: {', '.join(ext_attributes_list)}")

try:
if os.path.exists(target_folder):
shutil.rmtree(target_folder)

tree = FileImport(input_file_path, include_dirs, strict, overlays).load_tree()

if language == "python":
Expand Down
43 changes: 34 additions & 9 deletions src/velocitas/model_generator/cpp/cpp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import os
import re
import shutil
from typing import List, Set

# Until vsspec issue will be fixed: https://github.com/COVESA/vss-tools/issues/208
Expand All @@ -34,7 +33,9 @@ def __init__(self, root_node: VSSNode, target_folder: str, root_namespace: str):
"""Initialize the c++ generator.
Args:
root (_type_): the vspec tree root node.
root_node (VSSNode): The root node of the VSS tree
target_folder (str): The path to the output folder
root_namespace (str): The root namespace to use to which VSS based namespaces will be appended
"""
self.root_node = root_node
self.target_folder = target_folder
Expand All @@ -59,12 +60,36 @@ def generate(self):
path = os.path.join(
self.root_path, *self.__to_folder_names(self.root_namespace_list)
)
if os.path.exists(path):
shutil.rmtree(path)

os.makedirs(path)

self.__gen_model(self.root_node, self.root_namespace_list, is_root=True)
self.__visit_nodes(self.root_node, self.root_namespace_list)
# self.__gen_cmake_project()
self.__gen_conan_package()

def __gen_conan_package(self):
path = os.path.join(self.target_folder, "conanfile.py")
with open(path, "w", encoding="utf-8") as file:
file.write(
"""from conans import ConanFile
class VehicleModelConan(ConanFile):
name = "vehicle-model"
version = "generated"
license = "Apache 2.0"
url = "https://github.com/eclipse-velocitas/vehicle-model-generator"
description = "Vehicle Model API auto-generated from Vehicle Signal Specification"
# No settings/options are necessary, this is header only
exports_sources = "include/*"
no_copy_source = True
# all SDK versions are supported at the moment
requires = "vehicle-app-sdk/[>=0.1]"
def package(self):
self.copy("*.hpp")
"""
)

def __visit_nodes(self, node: VSSNode, parent_namespace_list: List[str]):
"""Recursively render nodes."""
Expand Down Expand Up @@ -371,12 +396,12 @@ def __gen_model(self, node: VSSNode, namespace_list: List[str], is_root=False):

self.__gen_footer(namespace_list, node)

relative_header_path = os.path.join(
*self.__to_folder_names(namespace_list), f"{node.name}.hpp"
)

with open(
os.path.join(
self.root_path,
*self.__to_folder_names(namespace_list),
f"{node.name}.hpp",
),
os.path.join(self.root_path, relative_header_path),
"w",
encoding="utf-8",
) as file:
Expand Down
3 changes: 0 additions & 3 deletions src/velocitas/model_generator/python/python_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""VehicleModelPythonGenerator."""

import os
import shutil
from typing import List, Set

# Until vsspec issue will be fixed: https://github.com/COVESA/vss-tools/issues/208
Expand Down Expand Up @@ -52,8 +51,6 @@ def generate(self):
"""Generate python code for vehicle model."""
self.root_path = self.target_folder

if os.path.exists(self.root_path):
shutil.rmtree(self.root_path)
path = os.path.join(self.root_path, *self.root_package_list)
os.makedirs(path)

Expand Down
3 changes: 3 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-cov
conan==1.62.0
7 changes: 4 additions & 3 deletions tests/test_model_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
)
def test_generate(language: str, input_file_path: str, include_dir: str):
input_file_path = Path(__file__).parent.joinpath("data", input_file_path).__str__()
generate_model(input_file_path, language, "output", "vehicle")
generate_model(
input_file_path, language, "output", "vehicle", include_dir=include_dir
)

if language == "python":
subprocess.check_call([sys.executable, "-m", "pip", "install", "./output"])
assert compileall.compile_dir("./output", force=True)
elif language == "cpp":
# TODO: add a check if the package can be installed after generated model is a conan package
pass
subprocess.check_call(["conan", "export", "./output"])

0 comments on commit c4b5582

Please sign in to comment.