-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
717 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
{ | ||
"mandatory": { | ||
"python": [ | ||
"gcovr==5.2", | ||
"conan==1.50.0", | ||
"kconfiglib==14.1.0", | ||
"autopep8==1.6.0", | ||
"pytest==7.1.2", | ||
"hammocking==0.2.3" | ||
], | ||
"python_trusted_hosts": [ | ||
"pypi.org", | ||
"files.pythonhosted.org" | ||
], | ||
"scoop": [ | ||
"cmake", | ||
"mingw-winlibs-llvm-ucrt", | ||
"python" | ||
], | ||
"scoop_repos": [ | ||
"versions@https://github.com/ScoopInstaller/Versions" | ||
] | ||
} | ||
"mandatory": { | ||
"python": [ | ||
"gcovr==5.2", | ||
"conan==1.50.0", | ||
"kconfiglib==14.1.0", | ||
"autopep8==1.6.0", | ||
"pytest==7.1.2", | ||
"hammocking==0.2.3", | ||
"textx==3.0.0", | ||
"cookiecutter==2.1.1" | ||
], | ||
"python_trusted_hosts": [ | ||
"pypi.org", | ||
"files.pythonhosted.org" | ||
], | ||
"scoop": [ | ||
"cmake", | ||
"mingw-winlibs-llvm-ucrt", | ||
"python" | ||
], | ||
"scoop_repos": [ | ||
"versions@https://github.com/ScoopInstaller/Versions" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@echo off | ||
|
||
set this_dir=%~dp0 | ||
|
||
pushd %this_dir% | ||
|
||
set PYTHONPATH=%this_dir%;%PYTHONPATH% | ||
python src/creator/creator.py %* | ||
|
||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
testpaths = | ||
tests |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from pathlib import Path | ||
|
||
|
||
def to_path(input_path: str, check_if_exists: bool = True) -> Path: | ||
return_path = Path(input_path) | ||
if not check_if_exists or return_path.exists(): | ||
return return_path.absolute() | ||
else: | ||
raise FileNotFoundError(input_path) | ||
|
||
|
||
def existing_path(input_path: str) -> Path: | ||
return to_path(input_path, True) | ||
|
||
|
||
def non_existing_path(input_path: str) -> Path: | ||
return to_path(input_path, False) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import argparse | ||
import dataclasses | ||
import logging | ||
from pathlib import Path | ||
from typing import Dict, List | ||
|
||
from cookiecutter.main import cookiecutter | ||
|
||
from src.common.common import existing_path | ||
from src.creator.project_artifacts import ProjectArtifacts | ||
|
||
|
||
@dataclasses.dataclass | ||
class Variant: | ||
flavor: str | ||
subsystem: str | ||
|
||
@classmethod | ||
def from_string(cls, variant: str): | ||
return cls(*variant.split('/')) | ||
|
||
|
||
class ProjectGenerator: | ||
def __init__(self, name: str, variants: List[Variant]): | ||
self.logger = logging.getLogger(__name__) | ||
self.project_description = self.create_project_description(name, variants) | ||
|
||
@staticmethod | ||
def create_project_description(name: str, variants: List[Variant]) -> Dict: | ||
project_description = {'name': name, 'variants': {}} | ||
for index, variant in enumerate(variants): | ||
project_description['variants'][f"{index}"] = { | ||
'flavor': variant.flavor, | ||
'subsystem': variant.subsystem | ||
} | ||
return project_description | ||
|
||
@property | ||
def project_template_path(self) -> Path: | ||
return Path(__file__).parent.joinpath('templates/project') | ||
|
||
@property | ||
def variant_template_path(self) -> Path: | ||
return Path(__file__).parent.joinpath('templates/variant') | ||
|
||
@property | ||
def project_name(self) -> str: | ||
return self.project_description['name'] | ||
|
||
def materialize(self, out_dir: Path) -> Path: | ||
project_artifacts = ProjectArtifacts(out_dir.joinpath(self.project_name)) | ||
result_path = cookiecutter(str(self.project_template_path), | ||
output_dir=f"{out_dir}", | ||
no_input=True, | ||
extra_context=self.project_description) | ||
for variant in self.project_description['variants'].values(): | ||
self.add_variant(variant, project_artifacts.variants_dir) | ||
self.logger.info(f"Project created under: {result_path}") | ||
return Path(result_path) | ||
|
||
def add_variant(self, variant_description: Dict, out_dir: Path): | ||
result_path = cookiecutter(str(self.variant_template_path), | ||
output_dir=f"{out_dir}", | ||
no_input=True, | ||
extra_context=variant_description, | ||
overwrite_if_exists=True) | ||
self.logger.info(f"Variant created under: {result_path}") | ||
return Path(result_path) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Project creator') | ||
parser.add_argument('--name', required=True, type=str, | ||
help="Project name. A directory with this name will be created in the <out_dir>.") | ||
parser.add_argument('--variant', required=True, action='append', type=Variant.from_string, | ||
help="Variant name as <flavor>/<subsystem>. E.g. FLV1/SYS1. This option can be used multiple times.") | ||
parser.add_argument('--out_dir', required=True, type=existing_path, | ||
help="Target directory where the project folder will be created.") | ||
arguments = parser.parse_args() | ||
ProjectGenerator(arguments.name, arguments.variant).materialize(arguments.out_dir) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pathlib import Path | ||
|
||
from src.creator.variant import Variant | ||
|
||
|
||
class ProjectArtifacts: | ||
def __init__(self, project_root_dir: Path): | ||
self.project_root_dir = project_root_dir | ||
self.variants_dir = self.root_dir.joinpath('variants') | ||
self.src_dir = self.root_dir.joinpath('src') | ||
self.test_dir = self.root_dir.joinpath('test') | ||
|
||
@property | ||
def root_dir(self) -> Path: | ||
return self.project_root_dir | ||
|
||
@property | ||
def build_script(self) -> Path: | ||
return self.root_dir.joinpath('build.bat') | ||
|
||
def get_build_dir(self, variant: Variant, build_kit: str) -> Path: | ||
return self.root_dir.joinpath(f"build/{variant}/{build_kit}") | ||
|
||
def get_variant_dir(self, variant: Variant) -> Path: | ||
return self.variants_dir.joinpath(f"{variant.flavor}/{variant.subsystem}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import List | ||
|
||
from src.creator.variant import Variant | ||
|
||
|
||
class SplProject: | ||
def __init__(self, parent, name: str, variants: List[Variant]): | ||
self.parent = parent | ||
self.name = name | ||
self.variants = variants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "project", | ||
"variants": { | ||
"1": { | ||
"flavor": "flavor", | ||
"subsystem": "subsystem" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/creator/templates/project/{{cookiecutter.name}}/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Binary output dir, not recommended to push binary results to Git. | ||
/build | ||
|
||
# Output directory of test results | ||
/test/output | ||
|
||
# What: Python: byte-compiled / optimized / DLL files | ||
# Why: automatically created by Python during script execution | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
/.pytest_cache |
9 changes: 9 additions & 0 deletions
9
src/creator/templates/project/{{cookiecutter.name}}/.vscode/cmake-kits.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{ | ||
"name": "prod" | ||
}, | ||
{ | ||
"name": "test", | ||
"toolchainFile": "tools/toolchains/gcc/toolchain.cmake" | ||
} | ||
] |
18 changes: 18 additions & 0 deletions
18
src/creator/templates/project/{{cookiecutter.name}}/.vscode/cmake-variants.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"variant": { | ||
"choices": { | ||
{%- for variant in cookiecutter.variants.values() -%} | ||
"{{ variant["flavor"] }}/{{ variant["subsystem"] }}": { | ||
"buildType": "{{ variant["flavor"] }}_{{ variant["subsystem"] }}", | ||
"long": "select to build variant '{{ variant["flavor"] }}/{{ variant["subsystem"] }}'", | ||
"settings": { | ||
"FLAVOR": "{{ variant["flavor"] }}", | ||
"SUBSYSTEM": "{{ variant["subsystem"] }}" | ||
}, | ||
"short": "{{ variant["flavor"] }}/{{ variant["subsystem"] }}" | ||
}{{ ", " if not loop.last else "" }} | ||
{%- endfor -%} | ||
}, | ||
"default": "{{ cookiecutter.variants["0"]["flavor"] }}/{{ cookiecutter.variants["0"]["subsystem"] }}" | ||
} | ||
} |
Oops, something went wrong.