-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add an action for generating configuration for SCADE Display mo…
…del (#65)
- Loading branch information
Showing
15 changed files
with
914 additions
and
6 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
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%" |
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,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 }}" |
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,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
19
doc/source/display-actions/examples/display-generate.yml.txt
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,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 |
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,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 |
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,6 @@ | ||
Model/specification_Code | ||
Model/specification_Exe | ||
log.txt | ||
env.txt | ||
err.txt | ||
*.dll |
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,4 @@ | ||
@echo off | ||
call TestGetSdyTargetDir.bat | ||
if errorlevel 1 (echo test error) | ||
|
Oops, something went wrong.