Skip to content

Commit

Permalink
feat: Add an action for generating configuration for SCADE Display mo…
Browse files Browse the repository at this point in the history
…del (#65)
  • Loading branch information
ansloddos authored Sep 18, 2024
1 parent 3856521 commit 522b2a5
Show file tree
Hide file tree
Showing 15 changed files with 914 additions and 6 deletions.
36 changes: 35 additions & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ jobs:
- name: "Upload code target directory to artifacts"
uses: actions/upload-artifact@v4
with:
name: "code-target-directory"
name: "scade-suite-code-target-directory"
path: "${{ steps.suite-code-generate.outputs.target-directory }}/*.*"
retention-days: 7
if-no-files-found: error
Expand Down Expand Up @@ -418,6 +418,40 @@ jobs:
retention-days: 7
if-no-files-found: error

- name: "Generate code with display-generate"
uses: ./display-generate
id: display-generate-code
with:
scade-dir: ${{ steps.get-scade-dir.outputs.scade-directory }}
project: "tests/display-generate/Model/Model.etp"
configuration: "Code"
checkout: false

- name: "Upload code target directory to artifacts"
uses: actions/upload-artifact@v4
with:
name: "scade-display-code-target-directory"
path: "${{ steps.display-generate-code.outputs.target-directory }}/*.*"
retention-days: 7
if-no-files-found: error

- name: "Generate standalone with display-generate"
uses: ./display-generate
id: display-generate-standalone
with:
scade-dir: ${{ steps.get-scade-dir.outputs.scade-directory }}
project: "tests/display-generate/Model/Model.etp"
configuration: "Windows"
checkout: false

- name: "Upload standalone target directory to artifacts"
uses: actions/upload-artifact@v4
with:
name: "scade-display-standalone-target-directory"
path: "${{ steps.display-generate-standalone.outputs.target-directory }}/*.*"
retention-days: 7
if-no-files-found: error

tests:
name: "All Tests"
needs: [display-tests, python-tests, unit-tests, suite-tests]
Expand Down
38 changes: 38 additions & 0 deletions display-generate/SdyGenerate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@echo off

rem parameters:
rem %1: SCADE installation directory, e.g. C:\Program Files\ANSYS Inc\v242\SCADE
rem %2: project
rem %3: configuration

:: check if there are 3 parameters
if ["%~3"]==[""] (
@echo Usage: %0 ^<SCADE directory^> ^<SCADE project^> ^<SCADE configuration^>
exit /B 1
)

:: check the correctness of the SCADE installation directory
if not exist "%~1\SCADE Display\bin\ScadeDisplayConsole.exe" (
@echo Error: file ^<%~s1\SCADE Display\bin\ScadeDisplayConsole.exe^> does not exist
exit /B 1
)
set SCADE_DISPLAY_CONSOLE_EXE=%~1\SCADE Display\bin\ScadeDisplayConsole.exe

:: check if the project exists
if not exist "%2" (
@echo Error: file ^<%~s2^> does not exist
exit /B 1
)

:: check if the project exists
if not exist "%2" (
@echo Error: file ^<%~s2^> does not exist
exit /B 1
)
set PROJECT=%~2

:: retrieve the configuration
set CONF=%~3

@echo Generate model for %PROJECT% using the configuration %CONF%
"%SCADE_DISPLAY_CONSOLE_EXE%" batch generate "%PROJECT%" -conf "%CONF%"
85 changes: 85 additions & 0 deletions display-generate/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# display-generate
name: 'Generate the configuration from a SCADE Display model'

description: |
The ``display-generate`` action executes ``ScadeDisplayConsole.exe batch generate`` on a SCADE Display project
for a given configuration.
Using a configuration type 'Code', the code will be generated.
Using a configuration type 'Windows', a standalone executable will be produced.
inputs:

scade-dir:
description: >
Ansys SCADE installation directory.
required: true

project:
description: >
Path of the SCADE Display project.
required: true

configuration:
description: >
Configuration to use for generation.
required: true

# Optional inputs
checkout:
description: >
Whether to clone the repository on the CI/CD machine.
default: 'true'
required: false

outputs:

target-directory:
description: >
Path of the target directory where the code is generated.
value: ${{ steps.get.outputs.target-directory }}

runs:
using: "composite"
steps:

- name: "Install Git and clone project"
uses: actions/checkout@v4
if: ${{ inputs.checkout == 'true' }}

- name: "Retrieve target directory for the configuration"
shell: cmd
id: get
run: |
:: get_sdy_target_dir.py echoes on stdout target-directory=<computed directory>
"${{ inputs.scade-dir }}\SCADE\bin\scade.exe" -script "${{ inputs.project }}" "${{ github.action_path }}\get_sdy_target_dir.py" "main('${{ inputs.configuration }}')" >> %GITHUB_OUTPUT%
- name: "Generate configuration"
shell: cmd
id: generate
run: |
:: Call SdyGenerate.bat
call "${{ github.action_path }}\SdyGenerate.bat" "${{ inputs.scade-dir }}" "${{ inputs.project }}" "${{ inputs.configuration }}"
69 changes: 69 additions & 0 deletions display-generate/get_sdy_target_dir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import sys

from scade.model.project.stdproject import Project
from scade.model.project.stdproject import get_roots as get_projects


def get_sdy_target_dir(project: Project, name: str) -> int:
for configuration in project.configurations:
if configuration.name == name:
break
else:
# report a message on stderr, return status not reported by scade.exe -script
print(
"%s: no such configuration for %s" % (name, project.pathname),
file=sys.stderr,
)
return 1
# compute the macros usable to define the target directory
tool = "SDY"
# retrieve source
prop = "CONFSOURCE"
source = project.get_scalar_tool_prop_def(tool, prop, "", configuration)
# retrieve outdir
prop = "CONFOUTPUT"
target_dir = project.get_scalar_tool_prop_def(tool, prop, "", configuration)
# extract model name without '.sgfx' suffix
model_name = os.path.splitext(source)[0]
# replace %ModelName% with the model name
target_dir = target_dir.replace("%ModelName%", model_name)
# make the directory absolute with respect to the project
target_dir = os.path.normpath(
os.path.join(os.path.dirname(project.pathname), target_dir)
)
# print the results as the definition of an environment variables
print("target-directory=%s" % target_dir)
# report a message on stderr, return status not reported by scade.exe -script
print("Command completed.", file=sys.stderr)
return 0


def main(name: str):
# entry point with scade.exe -script
# there must be one and only one project
projects = get_projects()
assert len(projects) == 1
get_sdy_target_dir(projects[0], name)
19 changes: 19 additions & 0 deletions doc/source/display-actions/examples/display-generate.yml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
display-generate:
name: "Generate code basic example"
runs-on: [self-hosted, 'SCADE']
steps:
- name: "Generate configuration"
uses: ansys/scade-actions/display-generate@{{ version }}
id: generate-code
with:
scade-dir: 'C:\Program Files\Ansys Inc\v242\SCADE'
project: 'Model\Model.etp'
configuration: 'Code'

- name: "Upload generated code to artifacts"
uses: actions/upload-artifact@v4
with:
name: "generated-code"
path: {{ "${{ steps.generate-code.outputs.target-directory }}/*.*" }}
retention-days: 7
if-no-files-found: error
23 changes: 23 additions & 0 deletions doc/source/display-actions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ SCADE Display Actions

Execute SCADE Display command line tools on models.

Generate configuration
----------------------

.. jinja:: display-generate

{{ description }}

{{ inputs_table }}

{{ outputs_table }}

Example
+++++++

{% for filename, title in examples %}
.. dropdown:: {{ title }}
:animate: fade-in

.. literalinclude:: examples/{{ filename }}
:language: yaml

{% endfor %}

Create report
-------------

Expand Down
6 changes: 3 additions & 3 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ see each of the following cards:
Set up Python environments for SCADE and
run the test suite for a SCADE Python library.

.. grid-item-card:: :octicon:`terminal` SCADE Suite actions
.. grid-item-card:: :octicon:`cpu` SCADE Suite actions
:link: suite-actions/index
:link-type: doc

Execute SCADE Suite command line tools on models.

.. grid-item-card:: :octicon:`terminal` SCADE Test actions
.. grid-item-card:: :octicon:`checklist` SCADE Test actions
:link: test-actions/index
:link-type: doc

Execute SCADE Test command line tools on models.

.. grid-item-card:: :octicon:`terminal` SCADE Display actions
.. grid-item-card:: :octicon:`device-desktop` SCADE Display actions
:link: display-actions/index
:link-type: doc

Expand Down
4 changes: 2 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pytest]
# remove --cov for debugging
# addopts = --ignore=tests/python-pyproject --ignore=tests/python-setup --basetemp=tmp
addopts = --ignore=tests/python-pyproject --ignore=tests/python-setup --basetemp=tmp --cov=. --cov-report html --cov-branch
addopts = --ignore=tests/python-pyproject --ignore=tests/python-setup --basetemp=tmp
# addopts = --ignore=tests/python-pyproject --ignore=tests/python-setup --basetemp=tmp --cov=. --cov-report html --cov-branch
6 changes: 6 additions & 0 deletions tests/display-generate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Model/specification_Code
Model/specification_Exe
log.txt
env.txt
err.txt
*.dll
4 changes: 4 additions & 0 deletions tests/display-generate/CallTestGetSdyTargetDir.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
call TestGetSdyTargetDir.bat
if errorlevel 1 (echo test error)

Loading

0 comments on commit 522b2a5

Please sign in to comment.