diff --git a/HISTORY.rst b/HISTORY.rst index 2839f032..9e90581f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,19 @@ Release History PlatformIO 2.0 -------------- +2.5.0 (2015-12-08) +~~~~~~~~~~~~~~~~~~ + +* Improved code builder for parallel builds (up to 4 times faster than before) +* Generate `.travis.yml `__ + CI and `.gitignore` files for embedded projects by default + (`issue #354 `_) +* Removed prompt with "auto-uploading" from `platformio init `__ + command and added ``--enable-auto-uploading`` option + (`issue #352 `_) +* Fixed incorrect behaviour of `platformio serialports monitor `__ + in pair with PySerial 3.0 + 2.4.1 (2015-12-01) ~~~~~~~~~~~~~~~~~~ @@ -219,7 +232,7 @@ PlatformIO 2.0 * Automatically detect upload port using VID:PID board settings (`issue #231 `_) * Improved detection of build changes -* Avoided ``LibInstallDependencyError`` when more then 1 library is found +* Avoided ``LibInstallDependencyError`` when more than 1 library is found (`issue #229 `_) 2.1.0 (2015-06-03) diff --git a/docs/_static/ci-travis-logo.png b/docs/_static/ci-travis-logo.png new file mode 100644 index 00000000..7a684634 Binary files /dev/null and b/docs/_static/ci-travis-logo.png differ diff --git a/docs/articles.rst b/docs/articles.rst index 8e2262a5..104462a8 100644 --- a/docs/articles.rst +++ b/docs/articles.rst @@ -23,12 +23,15 @@ Here are recent articles about PlatformIO: 2015 ^^^^ +* Dec 01, 2015 - **Tateno Yuichi** - `ESP8266 を CUI で開発する (Develop a ESP8266 in CUI, Japanese) `_ * Nov 29, 2015 - **Keith Hughes** - `Using PlatformIO for Embedded Projects `_ * Nov 22, 2015 - **Michał Seroczyński** - `Using PlatformIO to get started with Arduino in CLion IDE `_ * Nov 09, 2015 - **ÁLvaro García Gómez** - `Programar con Arduino "The good way" (Programming with Arduino "The good way", Spanish) `_ * Nov 06, 2015 - **nocd5** - `PlatformIOでmbedをオフラインビルドしSTM32 Nucleoボードでmrubyを使う (Use mruby in the offline build for STM32 Nucleo board with mbed and PlatformIO, Japanese) `_ +* Oct 21, 2015 - **Vittorio Zaccaria** - `Using a cheap STM32 Nucleo to teach remote sensor monitoring `_ * Oct 18, 2015 - **Nico Coetzee** - `First Arduino I2C Experience with PlatformIO `_ * Oct 01, 2015 - **Mistan** - `Compile and Upload Arduino Sketch with PlatformIO for Raspberry Pi Running Arch Linux `_ +* Sep 30, 2015 - **Jay Wiggins** - `PlatformIO Investigation `_ * Sep 01, 2015 - **Thomas P. Weldon, Ph.D.** - `Improvised MBED FRDM-K64F Eclipse/PlatformIO Setup and Software Installation `_ * Aug 08, 2015 - **Josh Glendenning** - `Armstrap Eagle and PlatformIO `_ * Aug 01, 2015 - **Russell Davis** - `PlatformIO on the Raspberry Pi `_ diff --git a/docs/ci/travis.rst b/docs/ci/travis.rst index 691018cf..ad1949ee 100644 --- a/docs/ci/travis.rst +++ b/docs/ci/travis.rst @@ -14,6 +14,13 @@ Travis CI ========= +.. image:: ../_static/ci-travis-logo.png + :target: https://docs.travis-ci.com/user/integration/platformio/ + + +**Travis CI** `officially supports `_ +**PlatformIO for Embedded Builds.** + `Travis CI `_ is an open-source hosted, distributed continuous integration service used to build and test projects hosted at `GitHub `_. diff --git a/docs/ide/arduino.rst b/docs/ide/arduino.rst index b2af515a..8348c046 100644 --- a/docs/ide/arduino.rst +++ b/docs/ide/arduino.rst @@ -28,12 +28,21 @@ This software can be used with: Refer to the `Arduino Getting Started `_ page for Installation instructions. +.. contents:: + Integration ----------- More detailed information is located in PlatformIO blog: `Integration of PlatformIO library manager to Arduino IDE `_. +Articles / Manuals +------------------ + +* `Integration of PlatformIO library manager to Arduino and Energia IDEs `_ + +See the full list with :ref:`articles`. + Screenshot ---------- diff --git a/docs/ide/atom.rst b/docs/ide/atom.rst index 346747d3..7c418b4d 100644 --- a/docs/ide/atom.rst +++ b/docs/ide/atom.rst @@ -34,6 +34,13 @@ Integration Using `Atom Packages `_ please install `platomformio `_ package. +Articles / Manuals +------------------ + +* `Arduino Development in Atom Editor `_ + +See a full list with :ref:`articles`. + Screenshot ---------- diff --git a/docs/ide/clion.rst b/docs/ide/clion.rst index 3360b1f6..84f8720f 100644 --- a/docs/ide/clion.rst +++ b/docs/ide/clion.rst @@ -57,6 +57,11 @@ There are 3 predefined targets for building: * ``PLATFORMIO_UPLOAD`` - build and upload (if no errors) * ``PLATFORMIO_CLEAN`` - clean compiled objects and etc. +.. warning:: + The libraries which are added, installed or used in the project + after generating process wont be reflected in IDE. To fix it you + need to reinitialize project using :ref:`cmd_init` (repeat it). + .. warning:: PlatformIO generates empty project by default and **code auto-completion will not work!** To enable auto-completion please choose one of: @@ -73,6 +78,14 @@ There are 3 predefined targets for building: Active discussion is located in `PlatformIO issue #132 `_. +Articles / Manuals +------------------ + +* `Using PlatformIO to get started with Arduino in CLion IDE `_ +* `Programar con Arduino "The good way" (Programming with Arduino "The good way", Spanish) `_ + +See a full list with :ref:`articles`. + Screenshot ---------- diff --git a/docs/ide/eclipse.rst b/docs/ide/eclipse.rst index 62f9c045..a2c9c227 100644 --- a/docs/ide/eclipse.rst +++ b/docs/ide/eclipse.rst @@ -37,9 +37,6 @@ page for more detailed information. Integration ----------- -Project Generator -^^^^^^^^^^^^^^^^^ - Since PlatformIO 2.0 you can generate Eclipse compatible project using :option:`platformio init --ide` command. Please choose board type using :ref:`cmd_boards` command and run: @@ -56,12 +53,19 @@ Then: 2. Open source file from ``src`` directory (``*.c, *.cpp, *.ino, etc.``) 3. Build project: ``Menu: Project > Build Project``. +.. warning:: + The libraries which are added, installed or used in the project + after generating process wont be reflected in IDE. To fix it you + need to reinitialize project using :ref:`cmd_init` (repeat it). -Manual Integration -^^^^^^^^^^^^^^^^^^ +Articles / Manuals +------------------ * `Building and debugging Atmel AVR (Arduino-based) project using Eclipse IDE+PlatformIO `_ * `Improvised MBED FRDM-K64F Eclipse/PlatformIO Setup and Software Installation `_ +* `Learning Arduino GitHub Repository `_ + +See a full list with :ref:`articles`. Screenshot ---------- diff --git a/docs/ide/energia.rst b/docs/ide/energia.rst index abad3d2a..e108ce99 100644 --- a/docs/ide/energia.rst +++ b/docs/ide/energia.rst @@ -28,12 +28,21 @@ This software can be used with: Refer to the `Energia Getting Started `_ page for Installation instructions. +.. contents:: + Integration ----------- More detailed information is located in PlatformIO blog: `Integration of PlatformIO library manager to Energia IDE `_. +Articles / Manuals +------------------ + +* `Integration of PlatformIO library manager to Arduino and Energia IDEs `_ + +See the full list with :ref:`articles`. + Screenshot ----------- diff --git a/docs/ide/qtcreator.rst b/docs/ide/qtcreator.rst index 6474bfd2..0ab90709 100644 --- a/docs/ide/qtcreator.rst +++ b/docs/ide/qtcreator.rst @@ -85,6 +85,11 @@ Then: .. image:: ../_static/ide-platformio-qtcreator-3.png :target: http://docs.platformio.org/en/latest/_static/ide-platformio-qtcreator-3.png +.. warning:: + The libraries which are added, installed or used in the project + after generating process wont be reflected in IDE. To fix it you + need to reinitialize project using :ref:`cmd_init` (repeat it). + Manual Integration ^^^^^^^^^^^^^^^^^^ diff --git a/docs/ide/vim.rst b/docs/ide/vim.rst index d97d3912..e0d06cde 100644 --- a/docs/ide/vim.rst +++ b/docs/ide/vim.rst @@ -23,6 +23,8 @@ This software can be used with: * all available :ref:`platforms` * all available :ref:`frameworks` +.. contents:: + Integration ----------- @@ -60,6 +62,13 @@ make firmware and upload it. If hotkey doesn't work for you, try to add this line ``nnoremap :make`` to ``~/.vimrc`` +Articles / Manuals +------------------ + +* `コマンドラインでArduino開発 : vim + platformio (Arduino development at the command line: VIM + PlatformIO, Japanese) `_ + +See a full list with :ref:`articles`. + Screenshot ---------- diff --git a/docs/ide/visualstudio.rst b/docs/ide/visualstudio.rst index 2e680694..af40d21e 100644 --- a/docs/ide/visualstudio.rst +++ b/docs/ide/visualstudio.rst @@ -52,6 +52,11 @@ Then: 2. Open source file from ``src`` directory (``*.c, *.cpp, *.ino, etc.``) 3. Build project: ``Menu: Build > Build Solution``. +.. warning:: + The libraries which are added, installed or used in the project + after generating process wont be reflected in IDE. To fix it you + need to reinitialize project using :ref:`cmd_init` (repeat it). + Manual Integration ^^^^^^^^^^^^^^^^^^ diff --git a/docs/index.rst b/docs/index.rst index d393c262..b912dd51 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -99,11 +99,19 @@ Contents Platforms & Boards frameworks/index +.. toctree:: + :caption: Library Manager + :maxdepth: 2 + + Quickstart + User Guide + librarymanager/config + librarymanager/creating + .. toctree:: :caption: Integration :maxdepth: 2 - librarymanager/index ci/index ide diff --git a/docs/librarymanager/config.rst b/docs/librarymanager/config.rst index db169136..d6ae06a6 100644 --- a/docs/librarymanager/config.rst +++ b/docs/librarymanager/config.rst @@ -336,6 +336,6 @@ A list of example patterns. This field is predefined with default value: .. code-block:: javascript "examples": [ - "[Ee]xamples/*/*.ini", + "[Ee]xamples/*/*.ino", "[Ee]xamples/*/*.pde" ] diff --git a/docs/librarymanager/index.rst b/docs/librarymanager/index.rst index c9dc5f15..43974d67 100644 --- a/docs/librarymanager/index.rst +++ b/docs/librarymanager/index.rst @@ -14,10 +14,6 @@ Library Manager =============== -.. - - *"The missing library manager for development platforms"* [#]_ - *PlatformIO Library Manager* allows you to organize external embedded libraries. You can search for new libraries via @@ -27,12 +23,4 @@ You can search for new libraries via You don't need to bother for finding the latest version of library. Due to :ref:`cmd_lib_update` command you will have up-to-date external libraries. -.. toctree:: - :maxdepth: 2 - - config - creating - User Guide <../userguide/lib/index.rst> - -.. [#] Inspired by `npm `_ and `bower - `_ package managers for web. +.. image:: ../_static/platformio-demo-lib.gif diff --git a/docs/projectconf.rst b/docs/projectconf.rst index b259395f..448a0a2e 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -440,13 +440,17 @@ Example, specify own upload command for :ref:`platform_atmelavr`: # uncomment line below to see environment variables # print env.Dump() -See built-in examples of `PlatformIO build scripts `_. + +* see built-in examples of `PlatformIO build scripts `_. +* take a look on related users questions: `#351 `_, + `#236 `_, + `#247 `_ ``targets`` ^^^^^^^^^^^ A list with targets which will be processed by :ref:`cmd_run` command by -default. You can enter more then one target separated with "space". Which +default. You can enter more than one target separated with "space". Which targets are supported is described in :option:`platformio run --target`. **Tip!** You can use these targets like an option to diff --git a/docs/userguide/cmd_init.rst b/docs/userguide/cmd_init.rst index 41c7b2ab..69702b05 100644 --- a/docs/userguide/cmd_init.rst +++ b/docs/userguide/cmd_init.rst @@ -27,7 +27,7 @@ Usage Description ----------- -Initialize new PlatformIO based project. +Initialize new PlatformIO based project or update existing with new data. This command will create: @@ -36,6 +36,8 @@ This command will create: * ``src`` - a source directory. Put your source files here * ``lib`` - a directory for the project specific (private) libraries. PlatformIO will compile them to static libraries and link to executable file +* ``.travis.yml`` configuration file (template) for Continuous Integration + with :ref:`ci_travis` .. note:: The source code of each library should be placed in separate directory. @@ -74,12 +76,11 @@ A list with supported IDE is available within ``platformio init --help`` command Also, please look into :ref:`ide` page. .. option:: - --disable-auto-uploading + --enable-auto-uploading If you initialise project with the specified :option:`platformio init --board`, then *PlatformIO* -will create environment with enabled firmware auto-uploading. This option -allows you to disable firmware auto-uploading by default. +will create environment with enabled firmware auto-uploading. .. option:: --env-prefix @@ -138,9 +139,6 @@ Examples $ platformio init --board uno - Would you like to enable firmware auto-uploading when project is successfully built using `platformio run` command? - Don't forget that you can upload firmware manually using `platformio run --target upload` command. [y/N]: y - The current working directory *** will be used for the new project. You can specify another project directory via `platformio init -d %PATH_TO_THE_PROJECT_DIR%` command. diff --git a/docs/userguide/index.rst b/docs/userguide/index.rst index 46449298..39f844a0 100644 --- a/docs/userguide/index.rst +++ b/docs/userguide/index.rst @@ -59,7 +59,6 @@ Commands cmd_boards cmd_ci cmd_init - platformio lib platformio platforms cmd_run cmd_serialports diff --git a/platformio/__init__.py b/platformio/__init__.py index 2b369209..662e56a0 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -VERSION = (2, 4, 1) +VERSION = (2, 5, 0) __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/__main__.py b/platformio/__main__.py index e5e35aee..813558bb 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -46,7 +46,7 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904 try: return self._handle_obsolate_command(name) except AttributeError: - raise exception.UnknownCLICommand(name) + raise click.UsageError('No such command "%s"' % name, ctx) return mod.cli @staticmethod diff --git a/platformio/builder/main.py b/platformio/builder/main.py index b3c1b34a..dbe503ea 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -41,8 +41,7 @@ from os import environ from os.path import isfile, join from time import time -from SCons.Script import (COMMAND_LINE_TARGETS, DefaultEnvironment, Exit, - SConscript, SConscriptChdir, Variables) +from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, Variables from platformio.exception import UnknownBoard @@ -141,10 +140,10 @@ if "BOARD" in env: ) if env['PLATFORM'] != env.get("BOARD_OPTIONS", {}).get("platform"): - Exit("Error: '%s' platform doesn't support this board. " - "Use '%s' platform instead." % ( - env['PLATFORM'], - env.get("BOARD_OPTIONS", {}).get("platform"))) + env.Exit( + "Error: '%s' platform doesn't support this board. " + "Use '%s' platform instead." % ( + env['PLATFORM'], env.get("BOARD_OPTIONS", {}).get("platform"))) for opt in ("LIB_IGNORE", "LIB_USE"): @@ -158,16 +157,18 @@ if env.subst("$PIOPACKAGE_TOOLCHAIN"): env.subst(join("$PIOPACKAGES_DIR", "$PIOPACKAGE_TOOLCHAIN", "bin")) ) -SConscriptChdir(0) -SConscript(env.subst("$BUILD_SCRIPT")) +env.SConscriptChdir(0) +env.SConsignFile(join("$PIOENVS_DIR", ".sconsign.dblite")) +env.SConscript("$BUILD_SCRIPT") -if environ.get("PLATFORMIO_EXTRA_SCRIPT", env.get("EXTRA_SCRIPT", None)): - SConscript(environ.get("PLATFORMIO_EXTRA_SCRIPT", env.get("EXTRA_SCRIPT"))) +if environ.get("PLATFORMIO_EXTRA_SCRIPT", env.get("EXTRA_SCRIPT")): + env.SConscript( + environ.get("PLATFORMIO_EXTRA_SCRIPT", env.get("EXTRA_SCRIPT"))) if "envdump" in COMMAND_LINE_TARGETS: print env.Dump() - Exit() + env.Exit() if "idedata" in COMMAND_LINE_TARGETS: print json.dumps(env.DumpIDEData()) - Exit() + env.Exit() diff --git a/platformio/builder/scripts/frameworks/mbed.py b/platformio/builder/scripts/frameworks/mbed.py index be0e4da2..e300d5f2 100644 --- a/platformio/builder/scripts/frameworks/mbed.py +++ b/platformio/builder/scripts/frameworks/mbed.py @@ -26,13 +26,16 @@ the mbed Developer Community. http://mbed.org/ """ +from __future__ import print_function + import re +import sys import xml.etree.ElementTree as ElementTree from binascii import crc32 from os import getenv, walk from os.path import basename, isfile, join, normpath -from SCons.Script import DefaultEnvironment, Exit +from SCons.Script import DefaultEnvironment env = DefaultEnvironment() @@ -119,8 +122,10 @@ def add_mbedlib(libname, libar): lib_dir = join(env.subst("$PLATFORMFW_DIR"), "libs", libname) if not isfile(join(lib_dir, "TARGET_%s" % variant, "TOOLCHAIN_GCC_ARM", "lib%s.a" % libar)): - Exit("Error: %s board doesn't support %s library!" % - (env.get("BOARD"), libname)) + print ( + "Warning: %s board doesn't have native support for '%s' library!" % + (env.get("BOARD"), libname), file=sys.stderr) + return env.Append( LIBPATH=[ diff --git a/platformio/commands/ci.py b/platformio/commands/ci.py index 71d05fb2..8e409508 100644 --- a/platformio/commands/ci.py +++ b/platformio/commands/ci.py @@ -99,8 +99,7 @@ def cli(ctx, src, lib, exclude, board, # pylint: disable=R0913 _exclude_contents(build_dir, exclude) # initialise project - ctx.invoke(cmd_init, project_dir=build_dir, board=board, - disable_auto_uploading=True) + ctx.invoke(cmd_init, project_dir=build_dir, board=board) # process project ctx.invoke(cmd_run, project_dir=build_dir, verbose=verbose) diff --git a/platformio/commands/init.py b/platformio/commands/init.py index f58654db..9709b8ae 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -45,21 +45,11 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613 callback=validate_boards) @click.option("--ide", type=click.Choice(ProjectGenerator.get_supported_ides())) -@click.option("--disable-auto-uploading", is_flag=True) +@click.option("--enable-auto-uploading", is_flag=True) @click.option("--env-prefix", default="") @click.pass_context def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 - disable_auto_uploading, env_prefix): - - # ask about auto-uploading - if board and app.get_setting("enable_prompts"): - disable_auto_uploading = not click.confirm( - "Would you like to enable firmware auto-uploading when project " - "is successfully built using `platformio run` command? \n" - "Don't forget that you can upload firmware manually using " - "`platformio run --target upload` command." - ) - click.echo("") + enable_auto_uploading, env_prefix): if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) @@ -93,9 +83,108 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 if not isdir(d): makedirs(d) - if not isfile(join(lib_dir, "readme.txt")): - with open(join(lib_dir, "readme.txt"), "w") as f: - f.write(""" + init_lib_readme(lib_dir) + init_ci_conf(project_dir) + init_cvs_ignore(project_dir) + + if not isfile(project_file): + copyfile(join(get_source_dir(), "projectconftpl.ini"), + project_file) + + if board: + fill_project_envs( + ctx, project_file, board, enable_auto_uploading, env_prefix, + ide is not None + ) + + if ide: + if not board: + raise exception.BoardNotDefined() + if len(board) > 1: + click.secho( + "Warning! You have initialised project with more than 1 board" + " for the specified IDE.\n" + "However, the IDE features (code autocompletion, syntax lint)" + " have been configured for the first board '%s' from your list" + " '%s'." % (board[0], ", ".join(board)), + fg="yellow" + ) + pg = ProjectGenerator( + project_dir, ide, board[0]) + pg.generate() + + click.secho( + "\nProject has been successfully initialized!\nUseful commands:\n" + "`platformio run` - process/build project from the current " + "directory\n" + "`platformio run --target upload` or `platformio run -t upload` " + "- upload firmware to embedded board\n" + "`platformio run --target clean` - clean project (remove compiled " + "files)\n" + "`platformio run --help` - additional information", + fg="green" + ) + + +def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals + ctx, project_file, board_types, enable_auto_uploading, + env_prefix, force_download): + builtin_boards = get_boards() + content = [] + used_envs = [] + used_platforms = [] + + with open(project_file) as f: + used_envs = [l.strip() for l in f.read().splitlines() if + l.strip().startswith("[env:")] + + for type_ in board_types: + data = builtin_boards[type_] + used_platforms.append(data['platform']) + env_name = "[env:%s%s]" % (env_prefix, type_) + + if env_name in used_envs: + continue + + content.append("") + content.append(env_name) + content.append("platform = %s" % data['platform']) + + # find default framework for board + frameworks = data.get("frameworks") + if frameworks: + content.append("framework = %s" % frameworks[0]) + + content.append("board = %s" % type_) + if enable_auto_uploading: + content.append("targets = upload") + + if force_download and used_platforms: + _install_dependent_platforms(ctx, used_platforms) + + if not content: + return + + with open(project_file, "a") as f: + content.append("") + f.write("\n".join(content)) + + +def _install_dependent_platforms(ctx, platforms): + installed_platforms = PlatformFactory.get_platforms(installed=True).keys() + if set(platforms) <= set(installed_platforms): + return + ctx.invoke( + cli_platforms_install, + platforms=list(set(platforms) - set(installed_platforms)) + ) + + +def init_lib_readme(lib_dir): + if isfile(join(lib_dir, "readme.txt")): + return + with open(join(lib_dir, "readme.txt"), "w") as f: + f.write(""" This directory is intended for the project specific (private) libraries. PlatformIO will compile them to static libraries and link to executable file. @@ -135,77 +224,81 @@ http://docs.platformio.org/en/latest/projectconf.html#lib-install """) - if not isfile(project_file): - copyfile(join(get_source_dir(), "projectconftpl.ini"), - project_file) - if board: - fill_project_envs( - ctx, project_file, board, disable_auto_uploading, env_prefix) - - if ide: - pg = ProjectGenerator(project_dir, ide, board[0] if board else None) - pg.generate() - - click.secho( - "\nProject has been successfully initialized!\nUseful commands:\n" - "`platformio run` - process/build project from the current " - "directory\n" - "`platformio run --target upload` or `platformio run -t upload` " - "- upload firmware to embedded board\n" - "`platformio run --target clean` - clean project (remove compiled " - "files)", - fg="green" - ) - - -def fill_project_envs(ctx, project_file, board_types, disable_auto_uploading, - env_prefix): - builtin_boards = get_boards() - content = [] - used_envs = [] - used_platforms = [] - - with open(project_file) as f: - used_envs = [l.strip() for l in f.read().splitlines() if - l.strip().startswith("[env:")] - - for type_ in board_types: - data = builtin_boards[type_] - used_platforms.append(data['platform']) - env_name = "[env:%s%s]" % (env_prefix, type_) - - if env_name in used_envs: - continue - - content.append("") - content.append(env_name) - content.append("platform = %s" % data['platform']) - - # find default framework for board - frameworks = data.get("frameworks") - if frameworks: - content.append("framework = %s" % frameworks[0]) - - content.append("board = %s" % type_) - content.append("%stargets = upload" % ("# " if disable_auto_uploading - else "")) - - _install_dependent_platforms(ctx, used_platforms) - - if not content: +def init_ci_conf(project_dir): + if isfile(join(project_dir, ".travis.yml")): return - - with open(project_file, "a") as f: - content.append("") - f.write("\n".join(content)) + with open(join(project_dir, ".travis.yml"), "w") as f: + f.write("""# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/latest/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/latest/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# -def _install_dependent_platforms(ctx, platforms): - installed_platforms = PlatformFactory.get_platforms(installed=True).keys() - if set(platforms) <= set(installed_platforms): +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=TYPE_1 --board=TYPE_2 --board=TYPE_N +""") + + +def init_cvs_ignore(project_dir): + if isfile(join(project_dir, ".gitignore")): return - ctx.invoke( - cli_platforms_install, - platforms=list(set(platforms) - set(installed_platforms)) - ) + with open(join(project_dir, ".gitignore"), "w") as f: + f.write(".pioevs") diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index 883f2c9f..7a988900 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -159,7 +159,7 @@ def lib_install_dependency(ctx, data): ctx.invoke(lib_install, libid=[result['items'][0]['id']]) else: click.secho( - "Conflict: More then one dependent libraries have been found " + "Conflict: More than one dependent libraries have been found " "by request %s:" % json.dumps(data), fg="red") echo_liblist_header() diff --git a/platformio/commands/serialports.py b/platformio/commands/serialports.py index 6c6e58ff..5c091c26 100644 --- a/platformio/commands/serialports.py +++ b/platformio/commands/serialports.py @@ -57,10 +57,10 @@ if int(PYSERIAL_VERSION[0]) == 3: help="Enable RTS/CTS flow control, default=Off") @click.option("--xonxoff", is_flag=True, help="Enable software flow control, default=Off") - @click.option("--rts", default="0", type=click.Choice(["0", "1"]), - help="Set initial RTS line state, default=0") - @click.option("--dtr", default="0", type=click.Choice(["0", "1"]), - help="Set initial DTR line state, default=0") + @click.option("--rts", default=None, type=click.Choice(["0", "1"]), + help="Set initial RTS line state") + @click.option("--dtr", default=None, type=click.Choice(["0", "1"]), + help="Set initial DTR line state") @click.option("--encoding", default="UTF-8", help="Set the encoding for the serial port (e.g. hexlify, " "Latin1, UTF-8), default: UTF-8") diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py index 761644bb..eb190c50 100644 --- a/platformio/commands/upgrade.py +++ b/platformio/commands/upgrade.py @@ -32,7 +32,6 @@ def cli(): fg="yellow") cmds = ( - ["pip", "install", "--upgrade", "pip", "setuptools"], ["pip", "install", "--upgrade", "platformio"], ["platformio", "--version"] ) @@ -60,7 +59,11 @@ def cli(): if not r: raise exception.UpgradeError( "\n".join([str(cmd), str(e)])) - if ("Permission denied" in r['err'] and + permission_errors = ( + "permission denied", + "not permitted" + ) + if (any([m in r['err'].lower() for m in permission_errors]) and "windows" not in util.get_systype()): click.secho(""" ----------------- @@ -68,7 +71,7 @@ Permission denied ----------------- You need the `sudo` permission to install Python packages. Try -> sudo platformio upgrade +> sudo pip install -U platformio WARNING! Don't use `sudo` for the rest PlatformIO commands. """, fg="yellow", err=True) diff --git a/platformio/exception.py b/platformio/exception.py index 74491f70..48d109ae 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -48,10 +48,11 @@ class PlatformNotInstalledYet(PlatformioException): "Use `platformio platforms install` command" -class UnknownCLICommand(PlatformioException): +class BoardNotDefined(PlatformioException): - MESSAGE = "Unknown command '%s'. Please use `platformio --help`"\ - " to see all available commands" + MESSAGE = "You need to specify board type using `-b` or `--board` "\ + "option. Supported boards list is available via "\ + " `platformio boards` command" class UnknownBoard(PlatformioException): @@ -201,6 +202,7 @@ class UpgradeError(PlatformioException): MESSAGE = """%s +* Upgrade using `pip install -U platformio` * Try different installation/upgrading steps: http://docs.platformio.org/en/latest/installation.html """ diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 7e90574c..28132e58 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -20,12 +20,12 @@ from os.path import abspath, basename, expanduser, isdir, join, relpath import bottle import click -from platformio import util +from platformio import exception, util class ProjectGenerator(object): - def __init__(self, project_dir, ide, board=None): + def __init__(self, project_dir, ide, board): self.project_dir = project_dir self.ide = ide self.board = board @@ -50,7 +50,7 @@ class ProjectGenerator(object): data = {"env_name": section[4:]} for k, v in config.items(section): data[k] = v - if self.board and self.board == data.get("board"): + if self.board == data.get("board"): break return data @@ -68,16 +68,15 @@ class ProjectGenerator(object): ["platformio", "-f", "run", "-t", "idedata", "-e", envdata['env_name'], "-d", self.project_dir] ) + if result['returncode'] != 0 or '"includes":' not in result['out']: - return data + raise exception.PlatformioException( + "\n".join([result['out'], result['err']])) output = result['out'] - try: - start_index = output.index('\n{"') - stop_index = output.rindex('}') - data = json.loads(output[start_index + 1:stop_index + 1]) - except ValueError: - pass + start_index = output.index('\n{"') + stop_index = output.rindex('}') + data = json.loads(output[start_index + 1:stop_index + 1]) return data diff --git a/platformio/maintenance.py b/platformio/maintenance.py index dc5a2861..5d5d9496 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -141,8 +141,8 @@ def after_upgrade(ctx): (click.style("follow", fg="cyan"), click.style("https://twitter.com/PlatformIO_Org", fg="cyan")) ) - click.echo("- %s us a star on GitHub > %s" % ( - click.style("give", fg="cyan"), + click.echo("- %s it on GitHub! > %s" % ( + click.style("star", fg="cyan"), click.style("https://github.com/platformio/platformio", fg="cyan") )) click.echo("*" * terminal_width) diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index c4488dd1..16c8901c 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -15,6 +15,7 @@ import os import re from imp import load_source +from multiprocessing import cpu_count from os.path import isdir, isfile, join import click @@ -389,6 +390,8 @@ class BasePlatform(object): [ "scons", "-Q", + "-j %d" % self.get_job_nums(), + "--warn=no-no-parallel-support", "-f", join(util.get_source_dir(), "builder", "main.py") ] + variables + targets, stdout=util.AsyncPipe(self.on_run_out), @@ -432,3 +435,10 @@ class BasePlatform(object): self._last_echo_line = line click.secho(line, fg=fg, err=level < 3) + + @staticmethod + def get_job_nums(): + try: + return cpu_count() + except NotImplementedError: + return 1 diff --git a/setup.py b/setup.py index 6696f001..f9cefef4 100644 --- a/setup.py +++ b/setup.py @@ -71,10 +71,9 @@ setup( "Topic :: Software Development :: Build Tools", "Topic :: Software Development :: Compilers" ], - keywords=( - "iot builder library manager embedded development ide continuous " - "integration atmel avr sam espressif esp freescale kinetis nordic " - "nrf51 nxp lpc silicon labs efm32 st stm32 ti msp430 tiva teensy " - "arduino mbed libopencm3" - ) + keywords=[ + "iot", "build tool", "compiler", "builder", "library manager", + "embedded", "ci", "continuous integration", "arduino", "mbed", + "framework", "ide", "ide integration", "library.json" + ] ) diff --git a/tests/commands/test_init.py b/tests/commands/test_init.py index db1178d4..8812876f 100644 --- a/tests/commands/test_init.py +++ b/tests/commands/test_init.py @@ -16,7 +16,7 @@ from os import makedirs, getcwd from os.path import getsize, isdir, isfile, join from platformio.commands.init import cli -from platformio import exception, util +from platformio import util def validate_pioproject(pioproject_dir): @@ -53,8 +53,7 @@ def test_init_special_board(platformio_setup, clirunner, validate_cliresult): expected_result = [ ("platform", str(uno['platform'])), ("framework", str(uno['frameworks'][0])), - ("board", "uno"), - ("targets", "upload") + ("board", "uno") ] assert config.has_section("env:uno") @@ -62,18 +61,19 @@ def test_init_special_board(platformio_setup, clirunner, validate_cliresult): set(config.items("env:uno")))) == 0 -def test_init_disable_auto_uploading(platformio_setup, clirunner, - validate_cliresult): +def test_init_enable_auto_uploading(platformio_setup, clirunner, + validate_cliresult): with clirunner.isolated_filesystem(): result = clirunner.invoke(cli, - ["-b", "uno", "--disable-auto-uploading"]) + ["-b", "uno", "--enable-auto-uploading"]) validate_cliresult(result) validate_pioproject(getcwd()) config = util.get_project_config() expected_result = [ ("platform", "atmelavr"), ("framework", "arduino"), - ("board", "uno") + ("board", "uno"), + ("targets", "upload") ] assert config.has_section("env:uno") assert len(set(expected_result).symmetric_difference(