Skip to content

Commit

Permalink
add '--with-build' option
Browse files Browse the repository at this point in the history
  • Loading branch information
ussserrr committed Feb 27, 2019
1 parent 744ff47 commit 19070fb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@ stm32pio changelog:

ver. 0.74 (27.02.19):
- New: new internal _get_project_path() function (more clean main script)
- New: optional '--with-build' option for 'new' mode allowing to make an initial build to save a time
- Changed: util.py functions now raising the exceptions instead of forcing the exit
- Changed: test '.ioc' file is updated to the latest STM32CubeMX version (5.1.0 at the moment)
- Changed: documentation improvements
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Small cross-platform Python app that can create and update [PlatformIO](https://
- Update existing project after adding/changing hardware options from CubeMX
- Clean-up the project (WARNING: it deletes ALL content of 'path' except the `.ioc` file!)
- *[optional]* Automatically run your favorite editor in the end
- *[optional]* Make an initial build of the project


## Restrictions
Expand Down Expand Up @@ -37,6 +38,8 @@ Basically, you need to follow such pattern:

Refer to Example section on more detailed steps.

stm32pio will create an accessory file 'cubemx-script' in your project directory that contains commands passed to CubeMX. You can safely delete it (it will be created again on the next run) or edit corresponding to your goals.

Check `settings.py` to make sure that all user-specific parameters are valid. Run
```bash
$ python3 stm32pio.py --help
Expand Down
8 changes: 4 additions & 4 deletions stm32pio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
logger = logging.getLogger('')


# How you start Java from command line?
# (default is OK) How do you start Java from command line? (edit if Java not in PATH)
java_cmd = 'java'

# We trying to guess STM32CubeMX location. You can just avoid this and hard-code it. Note that STM32CubeMX will be
# called as 'java -jar'
# (default is OK) We trying to guess STM32CubeMX location. You can just avoid this and hard-code it.
# Note that STM32CubeMX will be called as 'java -jar CUBEMX'
# macOS default: 'Applications' folder
if my_os == 'Darwin':
cubemx_path = "/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources/STM32CubeMX"
Expand All @@ -27,7 +27,7 @@
# (default is OK) choose a file name in which we store the CubeMX script
cubemx_script_filename = 'cubemx-script'

# (default is OK)
# (default is OK) see CubeMX user manual PDF to see other useful options
cubemx_script_text = "config load {cubemx_ioc_full_filename}\n" \
"generate code {project_path}\n" \
"exit\n"
Expand Down
4 changes: 4 additions & 0 deletions stm32pio/stm32pio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
parser_new.add_argument('-b', '--board', dest='board', help="PlatformIO name of the board", required=True)
parser_new.add_argument('--start-editor', dest='editor', help="use specified editor to open PlatformIO project",
choices=['atom', 'vscode', 'sublime'], required=False)
parser_new.add_argument('--with-build', action='store_true', help="initiate a build after project generation",
required=False)

parser_generate = subparsers.add_parser('generate', help="generate CubeMX code")
parser_generate.add_argument('-d', '--directory', dest='project_path',
Expand Down Expand Up @@ -70,6 +72,8 @@

if args.editor:
util.start_editor(args.project_path, args.editor)
if args.with_build:
util.pio_build(args.project_path)

elif args.subcommand == 'generate':
util.generate_code(args.project_path)
Expand Down
26 changes: 26 additions & 0 deletions stm32pio/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,32 @@ def start_editor(dirty_path, editor):



def pio_build(dirty_path):
"""
Initiate a build of the PlatformIO project by the PlatformIO ('run' command)
Args:
dirty_path: path to the project
"""

project_path = _get_project_path(dirty_path)


logger.info("starting PlatformIO build...")
if logger.level <= logging.DEBUG:
result = subprocess.run(['platformio', 'run', '-d', project_path])
else:
result = subprocess.run(['platformio', 'run', '-d', project_path, '--silent'])
# Or, for Python 3.7 and above:
# result = subprocess.run(['platformio', 'run', '-d', project_path, '--silent'], capture_output=True)
if result.returncode != 0:
logger.error("PlatformIO build error")
raise Exception("PlatformIO error")
else:
logger.info("successful PlatformIO build")



def clean(dirty_path):
"""
Clean-up the project folder and preserve only a '.ioc' file
Expand Down

0 comments on commit 19070fb

Please sign in to comment.