Skip to content

Commit f7b754a

Browse files
committed
feat(tools): add option to execute steps only on a specific system
At present, the steps are executed unconditionally. With this modification, we can restrict each step individually to determine if it should run on a particular system. For instance, we can execute different commands on different systems. This is achieved by adding a new key, "system," to the step dictionary, with possible values being Linux, Windows, and Darwin. Signed-off-by: Frantisek Hrbata <[email protected]>
1 parent dfcc0b2 commit f7b754a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tools/idf_py_actions/diag/recipes/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ variable, format it as `${NAME}`, such as `${IDF_PATH}`.
9090
Brief description of the `step`, displayed in the `idf.py diag` progress
9191
beneath the `recipe` description.
9292

93+
* system: string (optional)
94+
Can be used to restrict the operating system on which the step will be
95+
executed. It should be Linux, Darwin, or Windows. If specified, the step
96+
will only run on the designated system.
97+
9398
* output: string (optional)
9499

95100
Global output directory for the `step`. This directory serves as the main

tools/idf_py_actions/diag_ext.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import atexit
44
import difflib
55
import os
6+
import platform
67
import re
78
import shutil
89
import sys
@@ -292,7 +293,7 @@ def validate_recipe(recipe: Dict) -> None:
292293
dependencies and to provide more informative error messages.
293294
"""
294295
recipe_keys = ['description', 'tags', 'output', 'steps']
295-
step_keys = ['name', 'cmds', 'output']
296+
step_keys = ['name', 'cmds', 'output', 'system']
296297
recipe_description = recipe.get('description')
297298
recipe_tags = recipe.get('tags')
298299
recipe_output = recipe.get('output')
@@ -333,6 +334,7 @@ def validate_recipe(recipe: Dict) -> None:
333334
step_name = step.get('name')
334335
step_output = step.get('output')
335336
step_cmds = step.get('cmds')
337+
step_system = step.get('system')
336338

337339
if not step_name:
338340
raise RuntimeError(f'Recipe step is missing "name" key')
@@ -345,6 +347,12 @@ def validate_recipe(recipe: Dict) -> None:
345347
if step_output:
346348
if type(step_output) is not str:
347349
raise RuntimeError(f'Step "output" key is not of type "str"')
350+
if step_system:
351+
if type(step_system) is not str:
352+
raise RuntimeError(f'Step "system" key is not of type "str"')
353+
if step_system not in ['Linux', 'Windows', 'Darwin']:
354+
raise RuntimeError((f'Unknown "system" key value "{step_system}", '
355+
f'expecting "Linux", "Windows" or "Darwin"'))
348356

349357
for cmd in step_cmds:
350358
if 'exec' in cmd:
@@ -731,6 +739,12 @@ def process_recipe(recipe: Dict) -> None:
731739
"""execute commands for every stage in a recipe"""
732740
for step in recipe['steps']:
733741
step_name = step['name']
742+
step_system = step.get('system')
743+
744+
if step_system and step_system != platform.system():
745+
dbg(f'Skipping step "{step_name}" for "{step_system}"')
746+
continue
747+
734748
dbg(f'Processing step "{step_name}"')
735749
print(f'* {step_name}')
736750
for cmd in step['cmds']:
@@ -975,6 +989,7 @@ def create(action: str,
975989
dbg(f'Recipe variables: {recipe_variables}')
976990
dbg(f'Project directory: {project_dir}')
977991
dbg(f'Build directory: {build_dir}')
992+
dbg(f'System: {platform.system()}')
978993

979994
if list_recipes:
980995
# List recipes command

0 commit comments

Comments
 (0)