powertrain-build/docs/powertrain_build.md
Axel Andersson 816553f1bc Added powertrain-build entrypoint
The entrypoint will make it easier to install powertrain-build to an
isolated venv without having to call python -m powertrain_build.

Change-Id: I3850c97d17707f9bc03640bd1d997508637d97ba
2024-10-30 10:33:42 +01:00

10 KiB
Raw Permalink Blame History

powertrain_build


[TOC]

Requirements

powertrain_build is supported on Python versions 3.6 through 3.13.

Basic Usage

Code generation is done from git bash and the generated code is committed. The TargetLink GUI is currently lean and all projects are initialized in Matlab through running:

Projects/Init_PyBuild.m

This works the same way for Embedded coder projects, for example:

actuation-arbitration-manager-simulink-logic/Projects/Init_PyBuild.m

NOTE: Examples in upcoming chapters use Python version 3.6.

Code generate a model

In git bash:

py -3.6 -m powertrain_build.wrapper --codegen --models Models/ICEAES/VcAesTx/VcAesTx.mdl

CLI Entrypoint

If the Python bin/Scripts folder has been added to the PATH, you can also use powertrain-build's CLI entrypoint in a similar way:

powertrain-build wrapper --codegen --models Models/ICEAES/VcAesTx/VcAesTx.mdl

In general, the python call

python -m powertrain_build.submodule.subsubmodule <args>

corresponds to the CLI entrypoint call

powertrain-build submodule subsubmodule <args>

Run

powertrain-build --help

for more information on how to use the CLI entrypoint.

Set Matlab 2017 as Environmental Variable

Add New User Variables click 'New...' and add if you want to run python from command line

MatInstl2017 "C:\Program Files\MATLAB\R2017b\bin\matlab.exe"

or

MatInstl2017 "/c/Program\ Files/MATLAB/R2017b/bin/matlab.exe"

if you want to generate code from bash.

When a new environment variable has been added you need to restart git bash/command window.

See picture below for details.

MatlabEnvVar

Code generate with Embedded Coder with Matlab2019b

py -3.6 -m powertrain_build.wrapper --codegen --matlab-bin "C:\MATLAB_2019_b\bin\matlab.exe" --models Models/STEER/VcSteer/VcSteer.mdl

In git bash:

py -3.6 -m powertrain_build.wrapper --update --models Models/ICEAES/VcAesTx/VcAesTx.mdl

Update and Code generate a model

In git bash:

py -3.6 -m powertrain_build.wrapper --update --codegen --models Models/ICEAES/VcAesTx/VcAesTx.mdl

Code generation and build

To code generate and build a complete project ABC_123:

py -3.6 -m powertrain_build.wrapper --codegen --build ABC_123

Build a project

You can either use the wrapper:

py -3.6 -m powertrain_build.wrapper --build ABC_123

Detailed build options

py -3.6 -m powertrain_build.wrapper --help

The powertrain_build wrapper has many options, we'll explain them in detail here:

--update This option uses Matlab scripts to migrate models from the old build system to powertrain_build. Once powertrain_build is officially in use, all source code should already have been converted.

--codegen Runs TargetLink to generate C source code from the Matlab models. This should be done before changes are submitted for review. If the generated code is missing, the build system will reject your changes.

--build Reads configuration files and sets up preprocessor flags.

--models=Models/SSP/MODEL/MODEL.mdl Allows selective building and code generation, useful for testing individual changes. Multiple model paths can be entered, separated by comma signs.

--dry-run Dry run mode. No actual changes are done, can be used to test configuration.

--matlab-bin MATLAB_BIN matlab arguments currently path to the matlab binary to use. Defaults to C:\MATLABR2017b_x64\bin\matlab.exe. If you have Matlab installed in the wrong place you can use:

py -3.6 -m powertrain_build.wrapper --codegen --models Models/ICEAES/VcAesTx/VcAesTx.mdl --matlab-bin="C:\Program Files\MATLAB\R2017b\bin\matlab.exe"

NOTE: Building a project (--build) does not work if a model requires a preprocessor directive that does not exist in any configuration file.

Errors

Wrong installation path of Matlab 2017B

Wrong installation path of Matlab 2017B. You would get this fault trace:

$ py -3.6 -m powertrain_build.wrapper --codegen --models Models/PVCTM/VcScHmi/VcScHmi.mdl
2024-09-09 13:45:36,512 - C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\__init__.py - INFO - Current powertrain-build version is 0.1.1.dev1
2024-09-09 13:45:36,623 - C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\__init__.py - WARNING - powertrain-build version does not match requirements!
2024-09-09 13:45:37,215 - C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py - INFO - Affected models: Models/PVCTM/VcScHmi/VcScHmi.mdl
INFO:C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py:Affected models: Models/PVCTM/VcScHmi/VcScHmi.mdl
2024-09-09 13:45:37,215 - C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py - INFO - Preparing workspace for powertrain-build!
INFO:C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py:Preparing workspace for powertrain-build!
2024-09-09 13:45:37,215 - C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py - INFO - Running powertrain-build generate code!
INFO:C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py:Running powertrain-build generate code!
Traceback (most recent call last):
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\pt_matlab.py", line 392, in run_m_script
    p_matlab.run(command=" ".join(cmd))
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\pt_win32.py", line 67, in run
    self.startup_info,
pywintypes.error: (2, 'CreateProcess', 'The system cannot find the file specified.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py", line 502, in <module>
    sys.exit(main())
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py", line 498, in main
    return wrapper.run()
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py", line 408, in run
    exit_code |= self.build_automation(mode="codegen")
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\wrapper.py", line 351, in build_automation
    self.run_m_script(script_name, wrap_cmd=False, attempts=2)
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\pt_matlab.py", line 423, in run_m_script
    if p_matlab.poll() == pt_win32.STILL_ACTIVE:
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python36\lib\site-packages\powertrain_build\pt_win32.py", line 131, in poll
    return win32process.GetExitCodeProcess(self.process_handle)
pywintypes.error: (6, 'GetExitCodeProcess', 'The handle is invalid.')

NOTE: Instead of pywintypes.error: (2, 'CreateProcess', 'The system cannot find the file specified.') you might get pywintypes.error: (5, CreateProcess, Access is denied.).

Solution:

  1. Set an environmental label: MatlabEnvVar.

  2. Specify your Matlab path using the --matlab-bin argument:

    py -3.6 -m powertrain_build.wrapper --codegen --models Models/ICEAES/VcAesTx/VcAesTx.mdl --matlab-bin="C:\Program Files\MATLAB\R2017b\bin\matlab.exe"
    

What to commit

Using powertrain_build we need to commit:

  • Model file and if needed m-file
  • All updated files in Models/SSPXXX/VcXxxYyy/pybuild_cfg
  • Files like config_VcXxxYyy.json
  • All updated files in Models/SSPXXX/VcXxxYyy/pybuild_src
  • Files like tl_defines_XxxYyy.h, VcXxxYyy.h, VcXxxYyy.c, VcXxxYyy.a2l, VcXxxYyy_OPortMvd_LocalDefs.h
  • Files in tests if needed
  • Configuration files, e.g. ConfigDocuments/SPM_Codeswitch_Setup.csv, see pre processor directives.
gitrepo/
├── ConfigDocuments/
│   ├── .
│   ├── .
│   ├── .
│   ├── SPM_Codeswitch_Setup.csv
│   ├── SPM_Codeswitch_Setup_ICE.csv
│   ├── SPM_Codeswitch_Setup_PVC.csv
│   ├── .
│   ├── .
│   ├── .
├── Models/
│   └── PVCTM/
│       └── VcPvcDemo/
│           ├── pybuild_cfg/
│           │   ├── config_VcPvcDemo.json
│           │   └── VcPvcDemo.yaml
│           ├── pybuild_src/
│           │   ├── tl_defines_PvcDemo.h
│           │   ├── VcPvcDemo.a2l
│           │   ├── VcPvcDemo.c
│           │   ├── VcPvcDemo.h
│           │   └── VcPvcDemo_OPortMvd_LocalDefs.h
│           ├── tests/
│           │   ├── _cumulated_code_coverage_
│           │   │   ├── ctcpost_merge_options.txt
│           │   │   └── experiment.spec
│           │   ├── VcPvcDemo_UnitTests
│           │   │   ├── 00_test_setup
│           │   │   │   ├── dataset.DCM
│           │   │   │   ├── sut_config.txt
│           │   │   │   ├── sut_interface.py
│           │   │   │   └── twTest.sil
│           │   │   ├── 01_stimulus
│           │   │   │   └── U_VcPvcDemo_ExplorativeStimulus.py
│           │   │   └── 02_watchers
│           │   │       └── U_VcPvcDemo_watcher.py
│           │   ├── ctc_env.bat
│           │   └── project.testweaver
│           ├── VcPvcDemo.mdl
│           ├── VcPvcDemo_par

Summary of signals in powertrain_build

Signal Summary

Signal Interface Tool

Signal Interface Tool

Signal Interface Inconsistency

Signal inconsistency in check