diff --git a/.isort.cfg b/.isort.cfg index 72280366..3dbd6d91 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,3 +1,3 @@ [settings] line_length=79 -known_third_party=click,requests,serial,SCons,pytest +known_third_party=click,requests,serial,SCons,pytest,bottle diff --git a/HISTORY.rst b/HISTORY.rst index db7910d7..2fbabd97 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,51 @@ Release History =============== +2.0.0 (2015-05-22) +------------------ + +* PlatformIO as :ref:`ci` (CI) tool for embedded projects + (`issue #108 `_) +* Initialise PlatformIO project for the specified IDE + (`issue #151 `_) +* PlatformIO CLI 2.0: "platform" related commands have been + moved to ``platformio platforms`` subcommand + (`issue #158 `_) +* Created `PlatformIO gitter.im `_ room + (`issue #174 `_) +* Global ``-f, --force`` option which will force to accept any + confirmation prompts + (`issue #152 `_) +* Run project with `platformio run --project-dir `_ option without changing the current working + directory + (`issue #192 `_) +* Control verbosity of `platformio run `_ command via ``-v/--verbose`` option +* Add library dependencies for build environment using + `install_libs `_ + option in ``platformio.ini`` + (`issue #134 `_) +* Specify libraries which are compatible with build environment using + `use_libs `_ + option in ``platformio.ini`` + (`issue #148 `_) +* Add more boards to PlatformIO project with + `platformio init --board `__ + command + (`issue #167 `_) +* Choose which library to update + (`issue #168 `_) +* Specify `platformio init --env-prefix `__ when initialise/update project + (`issue #182 `_) +* Added new Armstrap boards + (`issue #204 `_) +* Updated SDK for `espressif `__ + development platform to v1.1 + (`issue #179 `_) +* Disabled automatic updates by default for platforms, packages and libraries + (`issue #171 `_) +* Fixed bug with creating copies of source files + (`issue #177 `_) + 1.5.0 (2015-05-15) ------------------ @@ -42,8 +87,9 @@ Release History 1.6.3 version (`issue #156 `_) * Upgraded `Energia Framework `__ to 0101E0015 version (`issue #146 `_) -* Upgraded `Arduino Framework with Teensy Core `_ to - 1.22 version (`issue #162 `_, +* Upgraded `Arduino Framework with Teensy Core `_ + to 1.22 version + (`issue #162 `_, `issue #170 `_) * Fixed exceptions with PlatformIO auto-updates when Internet connection isn't active diff --git a/README.rst b/README.rst index 78813f08..41f28fc6 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ PlatformIO .. image:: https://travis-ci.org/platformio/platformio.svg?branch=develop :target: https://travis-ci.org/platformio/platformio :alt: Travis.CI Build Status -.. image:: https://ci.appveyor.com/api/projects/status/ee26e58de798rctd/branch/develop?svg=true +.. image:: https://ci.appveyor.com/api/projects/status/dku0h2rutfj0ctls/branch/develop?svg=true :target: https://ci.appveyor.com/project/ivankravets/platformio :alt: AppVeyor.CI Build Status .. image:: https://gemnasium.com/platformio/platformio.png @@ -46,6 +46,7 @@ and the missing library manager. * `Embedded Boards Explorer `_ * `Library Manager `_ * `User Guide `_ +* `Continuous Integration `_ * `IDE Integration `_ * `Articles about us `_ * `FAQ `_ @@ -75,7 +76,7 @@ settings for most popular `Embedded Boards `_. * Configurable `build -flags/-options `_ * Automatic **firmware uploading** * Integration with `development environments (IDE) `_ -* Ready for **Cloud Compiling** and **Continuous Integration** +* Ready for **Cloud Compiling** and `Continuous Integration `_ * Pre-built tool chains, frameworks for the popular `Hardware Platforms `_ .. image:: https://raw.githubusercontent.com/platformio/platformio-web/develop/app/images/platformio-embedded-development.png @@ -133,7 +134,7 @@ It has support for the most popular embedded platforms: * `Espressif `_ * `Freescale Kinetis `_ * `Nordic nRF51 `_ -* `NXP LPC. `_ +* `NXP LPC `_ * `ST STM32 `_ * `Teensy `_ * `TI MSP430 `_ diff --git a/docs/_static/droneci-platformio-integration-1.png b/docs/_static/droneci-platformio-integration-1.png new file mode 100644 index 00000000..303e30f6 Binary files /dev/null and b/docs/_static/droneci-platformio-integration-1.png differ diff --git a/docs/_static/droneci-platformio-integration-2.png b/docs/_static/droneci-platformio-integration-2.png new file mode 100644 index 00000000..9b76e479 Binary files /dev/null and b/docs/_static/droneci-platformio-integration-2.png differ diff --git a/docs/articles.rst b/docs/articles.rst index 07f04723..5f708816 100644 --- a/docs/articles.rst +++ b/docs/articles.rst @@ -4,11 +4,13 @@ Articles about us ================= .. note:: - If you've writeen article about PlatformIO and would like it listed on + If you've written article about PlatformIO and would like it listed on this page, `please edit this page `_. Here are recent articles about PlatformIO: +* May 11, 2015 - **IT Hare** - `From Web Developer to Embedded One: Interview with Ivan Kravets, The Guy Behind PlatformIO. Part II `_ +* May 4, 2015 - **IT Hare** - `From Web Developer to Embedded One: Interview with Ivan Kravets, The Guy Behind PlatformIO. Part I `_ * April 17, 2015 - **Michael Ball** - `PlatformIO - A Cross-Platform Code Builder and Missing Library Manager `_ * March 23, 2015 - **Atmel** - `Cross-board and cross-vendor embedded development with PlatformIO `_ * March 22, 2015 - **Mark VandeWettering** - `Discovered a new tool for embedded development: PlatformIO `_ diff --git a/docs/ci/appveyor.rst b/docs/ci/appveyor.rst new file mode 100644 index 00000000..65ca0eb9 --- /dev/null +++ b/docs/ci/appveyor.rst @@ -0,0 +1,213 @@ +.. _ci_appveyor: + +AppVeyor +======== + +`AppVeyor `_ is an open-source hosted, +distributed continuous integration service used to build and test projects +hosted at `GitHub `_ on Windows family +systems. + +AppVeyor is configured by adding a file named ``appveyor.yml``, which is a +`YAML `_ format text file, to the root +directory of the GitHub repository. + +AppVeyor automatically detects when a commit has been made and pushed to a +GitHub repository that is using AppVeyor, and each time this happens, it will +try to build the project using :ref:`cmd_ci` command. This includes commits to +all branches, not just to the master branch. AppVeyor will also build and run +pull requests. When that process has completed, it will notify a developer in +the way it has been configured to do so — for example, by sending an email +containing the build results (showing success or failure), or by posting a +message on an IRC channel. It can be configured to build project on a range of +different :ref:`platforms`. + +Integration +----------- + +Put ``appveyor.yml`` to the root directory of the GitHub repository. + +.. code-block:: yaml + + build: off + environment: + global: + WITH_COMPILER: "cmd /E:ON /V:ON /C .\\scripts\\appveyor\\run_with_compiler.cmd" + matrix: + - PLATFORMIO_CI_SRC: "path\\to\\source\\file.c" + PLATFORMIO_CI_SRC: "path\\to\\source\\file.ino" + PLATFORMIO_CI_SRC: "path\\to\\source\\directory" + WINDOWS_SDK_VERSION: "v7.0" + PYTHON_HOME: "C:\\Python27-x64" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "64" + install: + - "git submodule update --init --recursive" + - "powershell scripts\\appveyor\\install.ps1" + before_test: + - cmd: SET PATH=%PATH%;%PYTHON_HOME%;%PYTHON_HOME%\Scripts + test_script: + - '%WITH_COMPILER% %PYTHON_HOME%\\Scripts\\platformio ci --board=TYPE_1 --board=TYPE_2 --board=TYPE_N' + + +Then create ``scripts/appveyor`` folder and put these 2 scripts (they are the +same for the all projects, don't need to modify them): + +1. ``scripts/appveyor/install.ps1``: + +.. code-block:: PowerShell + + $BASE_URL = "https://www.python.org/ftp/python/" + $GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py" + $GET_PIP_PATH = "C:\get-pip.py" + + + function DownloadPython ($python_version, $platform_suffix) { + $webclient = New-Object System.Net.WebClient + $filename = "python-" + $python_version + $platform_suffix + ".msi" + $url = $BASE_URL + $python_version + "/" + $filename + + $basedir = $pwd.Path + "\" + $filepath = $basedir + $filename + if (Test-Path $filename) { + Write-Host "Reusing" $filepath + return $filepath + } + + # Download and retry up to 5 times in case of network transient errors. + Write-Host "Downloading" $filename "from" $url + $retry_attempts = 3 + for($i=0; $i -lt $retry_attempts; $i++){ + try { + $webclient.DownloadFile($url, $filepath) + break + } + Catch [Exception]{ + Start-Sleep 1 + } + } + Write-Host "File saved at" $filepath + return $filepath + } + + + function InstallPython ($python_version, $architecture, $python_home) { + Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home + if (Test-Path $python_home) { + Write-Host $python_home "already exists, skipping." + return $false + } + if ($architecture -eq "32") { + $platform_suffix = "" + } else { + $platform_suffix = ".amd64" + } + $filepath = DownloadPython $python_version $platform_suffix + Write-Host "Installing" $filepath "to" $python_home + $args = "/qn /i $filepath TARGETDIR=$python_home" + Write-Host "msiexec.exe" $args + Start-Process -FilePath "msiexec.exe" -ArgumentList $args -Wait -Passthru + Write-Host "Python $python_version ($architecture) installation complete" + return $true + } + + + function InstallPip ($python_home) { + $pip_path = $python_home + "/Scripts/pip.exe" + $python_path = $python_home + "/python.exe" + if (-not(Test-Path $pip_path)) { + Write-Host "Installing pip..." + $webclient = New-Object System.Net.WebClient + $webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH) + Write-Host "Executing:" $python_path $GET_PIP_PATH + Start-Process -FilePath "$python_path" -ArgumentList "$GET_PIP_PATH" -Wait -Passthru + } else { + Write-Host "pip already installed." + } + } + + function InstallPackage ($python_home, $pkg) { + $pip_path = $python_home + "/Scripts/pip.exe" + & $pip_path install -U $pkg + } + + function InstallScons ($python_home) { + Write-Host "Start installing Scons" + $pip_path = $python_home + "/Scripts/pip.exe" + & $pip_path install --egg "http://sourceforge.net/projects/scons/files/latest/download" + Write-Host "Scons installed" + } + + function main () { + InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON_HOME + InstallPip $env:PYTHON_HOME + InstallPackage $env:PYTHON_HOME setuptools + InstallPackage $env:PYTHON_HOME platformio + InstallScons $env:PYTHON_HOME + } + + main + +2. ``scripts/appveyor/run_with_compiler.cmd``: + +.. code-block:: guess + + @ECHO OFF + + SET COMMAND_TO_RUN=%* + SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows + + SET MAJOR_PYTHON_VERSION="%PYTHON_VERSION:~0,1%" + IF %MAJOR_PYTHON_VERSION% == "2" ( + SET WINDOWS_SDK_VERSION="v7.0" + ) ELSE IF %MAJOR_PYTHON_VERSION% == "3" ( + SET WINDOWS_SDK_VERSION="v7.1" + ) ELSE ( + ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%" + EXIT 1 + ) + + IF "%PYTHON_ARCH%"=="64" ( + ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture + SET DISTUTILS_USE_SDK=1 + SET MSSdk=1 + "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION% + "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 + ) ELSE ( + ECHO Using default MSVC build environment for 32 bit architecture + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 + ) + +For more details as for PlatformIO build process please look into :ref:`cmd_ci` +command. + +Examples +-------- + +1. Integration for `USB_Host_Shield_2.0 `_ + project. The ``appveyor.yml`` configuration file: + +.. code-block:: yaml + + build: off + environment: + global: + WITH_COMPILER: "cmd /E:ON /V:ON /C .\\scripts\\appveyor\\run_with_compiler.cmd" + matrix: + - PLATFORMIO_CI_SRC: "examples\\Bluetooth\\PS3SPP\\PS3SPP.ino" + PLATFORMIO_CI_SRC: "examples\\pl2303\\pl2303_gps\\pl2303_gps.ino" + WINDOWS_SDK_VERSION: "v7.0" + PYTHON_HOME: "C:\\Python27-x64" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "64" + install: + - "git submodule update --init --recursive" + - "powershell scripts\\appveyor\\install.ps1" + before_test: + - cmd: SET PATH=%PATH%;%PYTHON_HOME%;%PYTHON_HOME%\Scripts + - cmd: git clone https://github.com/xxxajk/spi4teensy3.git c:\spi4teensy + test_script: + - '%WITH_COMPILER% %PYTHON_HOME%\\Scripts\\platformio ci --lib="." --lib="c:\spi4teensy" --board=uno --board=teensy31 --board=due' diff --git a/docs/ci/circleci.rst b/docs/ci/circleci.rst new file mode 100644 index 00000000..61da49de --- /dev/null +++ b/docs/ci/circleci.rst @@ -0,0 +1,72 @@ +.. _ci_circleci: + +Circle CI +========= + +`Circle CI `_ is a hosted cloud +platform that provides hosted continuous integration, deployment, and testing +to `GitHub `_ repositories. + +Circle CI is configured by adding a file named ``circle.yml``, which is a +`YAML `_ format text file, to the root +directory of the GitHub repository. + +Circle CI automatically detects when a commit has been made and pushed to a +GitHub repository that is using Circle CI, and each time this happens, it will +try to build the project using :ref:`cmd_ci` command. This includes commits to +all branches, not just to the master branch. Circle CI will also build and run +pull requests. When that process has completed, it will notify a developer in +the way it has been configured to do so — for example, by sending an email +containing the build results (showing success or failure), or by posting a +message on an IRC channel. It can be configured to build project on a range of +different :ref:`platforms`. + +Integration +----------- + +Put ``circle.yml`` to the root directory of the GitHub repository. + +.. code-block:: yaml + + machine: + environment: + - PLATFORMIO_CI_SRC=path/to/source/file.c + - PLATFORMIO_CI_SRC=path/to/source/file.ino + - PLATFORMIO_CI_SRC=path/to/source/directory + + dependencies: + pre: + - sudo apt-get install python2.7-dev + - sudo python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + + test: + override: + - platformio ci --board=TYPE_1 --board=TYPE_2 --board=TYPE_N + + +For more details as for PlatformIO build process please look into :ref:`cmd_ci` +command. + +Examples +-------- + +1. Integration for `USB_Host_Shield_2.0 `_ + project. The ``circle.yml`` configuration file: + +.. code-block:: yaml + + machine: + environment: + PLATFORMIO_CI_SRC: examples/Bluetooth/PS3SPP/PS3SPP.ino + PLATFORMIO_CI_SRC: examples/pl2303/pl2303_gps/pl2303_gps.ino + + dependencies: + pre: + - sudo apt-get install python2.7-dev + - sudo python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + - wget https://github.com/xxxajk/spi4teensy3/archive/master.zip -O /tmp/spi4teensy3.zip + - unzip /tmp/spi4teensy3.zip -d /tmp + + test: + override: + - platformio ci --lib="." --lib="/tmp/spi4teensy3-master" --board=uno --board=teensy31 --board=due diff --git a/docs/ci/drone.rst b/docs/ci/drone.rst new file mode 100644 index 00000000..912b546b --- /dev/null +++ b/docs/ci/drone.rst @@ -0,0 +1,70 @@ +.. _ci_drone: + +Drone +===== + +`Drone `_ is a hosted continuous integration service. +It enables you to conveniently set up projects to automatically build, test, +and deploy as you make changes to your code to +`GitHub `_ and +`BitBucket `_ repositories. + +Drone is configured by modifying settings in your project control panel. + +Drone automatically detects when a commit has been made and pushed to a +GitHub repository that is using Drone, and each time this happens, it will +try to build the project using :ref:`cmd_ci` command. This includes commits to +all branches, not just to the master branch. Drone will also build and run +pull requests. When that process has completed, it will notify a developer in +the way it has been configured to do so — for example, by sending an email +containing the build results (showing success or failure). It can be +configured to build project on a range of different :ref:`platforms`. + +Integration +----------- + +Please fill all fields for your project in the Drone control panel: + +`Environment Variables`: + +.. code-block:: bash + + PLATFORMIO_CI_SRC=path/to/source/file.c + PLATFORMIO_CI_SRC=path/to/source/file.ino + PLATFORMIO_CI_SRC=path/to/source/directory + +`Commands`: + +.. code-block:: bash + + python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + platformio ci --board=TYPE_1 --board=TYPE_2 --board=TYPE_N + +.. image:: ../_static/droneci-platformio-integration-1.png + +For more details as for PlatformIO build process please look into :ref:`cmd_ci` +command. + +Examples +-------- + +1. Integration for `USB_Host_Shield_2.0 `_ + project. The ``circle.yml`` configuration file: + +`Environment Variables`: + +.. code-block:: bash + + PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP/PS3SPP.ino + PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps/pl2303_gps.ino + +`Commands`: + +.. code-block:: bash + + python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + wget https://github.com/xxxajk/spi4teensy3/archive/master.zip -O /tmp/spi4teensy3.zip + unzip /tmp/spi4teensy3.zip -d /tmp + platformio ci --lib="." --lib="/tmp/spi4teensy3-master" --board=uno --board=teensy31 --board=due + +.. image:: ../_static/droneci-platformio-integration-2.png diff --git a/docs/ci/index.rst b/docs/ci/index.rst new file mode 100644 index 00000000..480974bf --- /dev/null +++ b/docs/ci/index.rst @@ -0,0 +1,24 @@ +.. _ci: + +Continuous Integration +====================== + +`Continuous Integration (CI, wiki) `_ +is the practice, in software engineering, of merging all developer working +copies with a shared mainline several times a day. + +:ref:`cmd_ci` command is intended to be used in combination with the build +servers and the popular +`Continuous Integration Software `_. + +By integrating regularly, you can detect errors quickly, and locate them more +easily. + +.. toctree:: + :maxdepth: 2 + + appveyor + circleci + drone + shippable + travis diff --git a/docs/ci/shippable.rst b/docs/ci/shippable.rst new file mode 100644 index 00000000..9d27df52 --- /dev/null +++ b/docs/ci/shippable.rst @@ -0,0 +1,76 @@ +.. _ci_shippable: + +Shippable +========= + +`Shippable `_ is a hosted cloud +platform that provides hosted continuous integration, deployment, and testing +to `GitHub `_ and +`BitBucket `_ repositories. +Shippable's continuous integration service is built using Docker. + +Shippable is configured by adding a file named ``shippable.yml``, which is a +`YAML `_ format text file, to the root +directory of the GitHub repository or you can use your Travis CI configuration +file ``.travis.yml``. + +Shippable automatically detects when a commit has been made and pushed to a +GitHub repository that is using Shippable, and each time this happens, it will +try to build the project using :ref:`cmd_ci` command. This includes commits to +all branches, not just to the master branch. Shippable will also build and run +pull requests. When that process has completed, it will notify a developer in +the way it has been configured to do so — for example, by sending an email +containing the build results (showing success or failure), or by posting a +message on an IRC channel. It can be configured to build project on a range of +different :ref:`platforms`. + +Integration +----------- + +Please put ``shippable.yml`` or ``.travis.yml`` to the root directory of the +GitHub repository. + +.. code-block:: yaml + + language: python + python: + - "2.7" + + env: + - PLATFORMIO_CI_SRC=path/to/source/file.c + - PLATFORMIO_CI_SRC=path/to/source/file.ino + - PLATFORMIO_CI_SRC=path/to/source/directory + + install: + - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + + script: + - platformio ci --board=TYPE_1 --board=TYPE_2 --board=TYPE_N + + +For more details as for PlatformIO build process please look into :ref:`cmd_ci` +command. + +Examples +-------- + +1. Integration for `USB_Host_Shield_2.0 `_ + project. The ``shippable.yml`` or ``.travis.yml`` configuration file: + +.. code-block:: yaml + + language: python + python: + - "2.7" + + env: + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP/PS3SPP.ino + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps/pl2303_gps.ino + + install: + - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + - wget https://github.com/xxxajk/spi4teensy3/archive/master.zip -O /tmp/spi4teensy3.zip + - unzip /tmp/spi4teensy3.zip -d /tmp + + script: + - platformio ci --lib="." --lib="/tmp/spi4teensy3-master" --board=uno --board=teensy31 --board=due diff --git a/docs/ci/travis.rst b/docs/ci/travis.rst new file mode 100644 index 00000000..4c5e9e34 --- /dev/null +++ b/docs/ci/travis.rst @@ -0,0 +1,72 @@ +.. _ci_travis: + +Travis CI +========= + +`Travis CI `_ is an open-source hosted, +distributed continuous integration service used to build and test projects +hosted at `GitHub `_. + +Travis CI is configured by adding a file named ``.travis.yml``, which is a +`YAML `_ format text file, to the root +directory of the GitHub repository. + +Travis CI automatically detects when a commit has been made and pushed to a +GitHub repository that is using Travis CI, and each time this happens, it will +try to build the project using :ref:`cmd_ci` command. This includes commits to +all branches, not just to the master branch. Travis CI will also build and run +pull requests. When that process has completed, it will notify a developer in +the way it has been configured to do so — for example, by sending an email +containing the build results (showing success or failure), or by posting a +message on an IRC channel. It can be configured to build project on a range of +different :ref:`platforms`. + +Integration +----------- + +Please put ``.travis.yml`` to the root directory of the GitHub repository. + +.. code-block:: yaml + + language: python + python: + - "2.7" + + env: + - PLATFORMIO_CI_SRC=path/to/source/file.c + - PLATFORMIO_CI_SRC=path/to/source/file.ino + - PLATFORMIO_CI_SRC=path/to/source/directory + + install: + - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + + script: + - platformio ci --board=TYPE_1 --board=TYPE_2 --board=TYPE_N + + +For more details as for PlatformIO build process please look into :ref:`cmd_ci` +command. + +Examples +-------- + +1. Integration for `USB_Host_Shield_2.0 `_ + project. The ``.travis.yml`` configuration file: + +.. code-block:: yaml + + language: python + python: + - "2.7" + + env: + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP/PS3SPP.ino + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps/pl2303_gps.ino + + install: + - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + - wget https://github.com/xxxajk/spi4teensy3/archive/master.zip -O /tmp/spi4teensy3.zip + - unzip /tmp/spi4teensy3.zip -d /tmp + + script: + - platformio ci --lib="." --lib="/tmp/spi4teensy3-master" --board=uno --board=teensy31 --board=due diff --git a/docs/faq.rst b/docs/faq.rst index b86e0790..6065be35 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -69,6 +69,7 @@ If you are going to run *PlatformIO* from **subprocess**, you **MUST DISABLE** all prompts. It will allow you to avoid blocking. There are a few options: +- using :option:`platformio --force` option before each command - using environment variable :ref:`PLATFORMIO_SETTING_ENABLE_PROMPTS=No ` - disable global setting ``enable_prompts`` via :ref:`cmd_settings` command - masking under Continuous Integration system via environment variable @@ -87,7 +88,7 @@ Answered in `issue #144 `_ * For more detailed ``board`` information please scroll tables below by horizontal. +Armstrap +~~~~~~~~ + +.. list-table:: + :header-rows: 1 + + * - Type ``board`` + - Name + - Microcontroller + - Frequency + - Flash + - RAM + + * - ``armstrap_eagle1024`` + - `Armstrap Eagle 1024 `_ + - STM32F417VGT6 + - 168 MHz + - 1024 Kb + - 192 Kb + + * - ``armstrap_eagle2048`` + - `Armstrap Eagle 2048 `_ + - STM32F427VIT6 + - 168 MHz + - 2048 Kb + - 256 Kb + + * - ``armstrap_eagle512`` + - `Armstrap Eagle 512 `_ + - STM32F407VET6 + - 168 MHz + - 512 Kb + - 192 Kb + ST ~~ diff --git a/docs/frameworks/mbed.rst b/docs/frameworks/mbed.rst index 3bea58b5..1c909d13 100644 --- a/docs/frameworks/mbed.rst +++ b/docs/frameworks/mbed.rst @@ -527,6 +527,26 @@ Switch Science - 32 Kb - 4 Kb +Teensy +~~~~~~ + +.. list-table:: + :header-rows: 1 + + * - Type ``board`` + - Name + - Microcontroller + - Frequency + - Flash + - RAM + + * - ``teensy31`` + - `Teensy 3.1 `_ + - MK20DX256 + - 72 MHz + - 256 Kb + - 64 Kb + u-blox ~~~~~~ diff --git a/docs/frameworks/spl.rst b/docs/frameworks/spl.rst index 64d91979..1d131c34 100644 --- a/docs/frameworks/spl.rst +++ b/docs/frameworks/spl.rst @@ -27,6 +27,40 @@ Boards `PlatformIO Boards Explorer `_ * For more detailed ``board`` information please scroll tables below by horizontal. +Armstrap +~~~~~~~~ + +.. list-table:: + :header-rows: 1 + + * - Type ``board`` + - Name + - Microcontroller + - Frequency + - Flash + - RAM + + * - ``armstrap_eagle1024`` + - `Armstrap Eagle 1024 `_ + - STM32F417VGT6 + - 168 MHz + - 1024 Kb + - 192 Kb + + * - ``armstrap_eagle2048`` + - `Armstrap Eagle 2048 `_ + - STM32F427VIT6 + - 168 MHz + - 2048 Kb + - 256 Kb + + * - ``armstrap_eagle512`` + - `Armstrap Eagle 512 `_ + - STM32F407VET6 + - 168 MHz + - 512 Kb + - 192 Kb + ST ~~ diff --git a/docs/ide/eclipse.rst b/docs/ide/eclipse.rst index 6fd8fae1..2549c24d 100644 --- a/docs/ide/eclipse.rst +++ b/docs/ide/eclipse.rst @@ -15,15 +15,34 @@ registers, and disassembly viewers. This software can be used with: -* all availalbe :ref:`platforms` -* all availalbe :ref:`frameworks` +* all available :ref:`platforms` +* all available :ref:`frameworks` Refer to the `CDT Documentation `_ page for more detailed information. +.. contents:: + Integration ----------- +Project Generator +^^^^^^^^^^^^^^^^^ + +Since PlatformIO 2.0 you can generate Eclipse compatible project using +:option:`platformio init --ide` command: + +.. code-block:: shell + + platformio init --ide eclipse + +Then import this project via ``File > Import... > General > Existing Projects +into Workspace > Next`` and specify root directory where is located +:ref:`projectconf`. + +Manual Integration +^^^^^^^^^^^^^^^^^^ + More detailed information is located in PlatformIO blog: `Building and debugging Atmel AVR (Arduino-based) project using Eclipse IDE+PlatformIO `_. `More examples (TI MSP430, TI TIVA, etc.) `_ diff --git a/docs/ide/qtcreator.rst b/docs/ide/qtcreator.rst index 19705b5a..31bc7cde 100644 --- a/docs/ide/qtcreator.rst +++ b/docs/ide/qtcreator.rst @@ -7,10 +7,10 @@ The `Qt Creator `_ is an open source cr This software can be used with: -* all availalbe :ref:`platforms` -* all availalbe :ref:`frameworks` +* all available :ref:`platforms` +* all available :ref:`frameworks` -Refer to the `Sublime Text Documentation `_ +Refer to the `Qt-creator Manual `_ page for more detailed information. .. contents:: @@ -18,10 +18,26 @@ page for more detailed information. Integration ----------- -Setup New Project +Project Generator ^^^^^^^^^^^^^^^^^ -First of all, let's create new project from Qt Creator Start Page: ``New Project`` or using ``Menu: File → New File or Project``, then select project with ``Empty Qt Project`` type (``Other Project → Empty Qt Project``), fill ``Name``, ``Create in``. +Since PlatformIO 2.0 you can generate Eclipse compatible project using +:option:`platformio init --ide` command: + +.. code-block:: shell + + platformio init --ide qtcreator + +Then import this project via ``File > New File or Project > Import Project`` +and specify root directory where is located :ref:`projectconf`. + +Manual Integration +^^^^^^^^^^^^^^^^^^ + +Setup New Project +~~~~~~~~~~~~~~~~~ + +First of all, let's create new project from Qt Creator Start Page: ``New Project`` or using ``Menu: File > New File or Project``, then select project with ``Empty Qt Project`` type (``Other Project > Empty Qt Project``), fill ``Name``, ``Create in``. .. image:: ../_static/ide-platformio-qtcreator-1.png @@ -33,7 +49,7 @@ Secondly, we need to configure project with PlatformIO source code builder (clic .. image:: ../_static/ide-platformio-qtcreator-3.png -Thirdly, we need to add directories with header files using project file. Please fill this file with the next contents: +Thirdly, change project file by adding path to directories with header files. Please edit project file to match the following contents: .. code-block:: none @@ -52,12 +68,12 @@ Thirdly, we need to add directories with header files using project file. Please .. image:: ../_static/ide-platformio-qtcreator-4.png First program in Qt Creator -^^^^^^^^^^^^^^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~ Simple "Blink" project will consist from two files: - -1. Main "C" source file named ``main.c`` must be located in the ``src`` directory. -Let's create new text file named ``main.c`` using ``Menu: New File or Project → General → Text File``: +1. In the console, navigate to the root of your project folder and initialize platformio project with ``platformio init`` +2. The main "C" source file named ``main.c`` must be located in the ``src`` directory. +Let's create new text file named ``main.c`` using ``Menu: New File or Project > General > Text File``: .. image:: ../_static/ide-platformio-qtcreator-5.png @@ -81,11 +97,11 @@ Copy the source code which is described below to file ``main.c``. delay(1000); // wait for a second } -2. Project Configuration File named ``platformio.ini`` must be located in the project root directory. +3. Locate the project configuration file named ``platformio.ini`` at the root of the project directory and open it. .. image:: ../_static/ide-platformio-qtcreator-6.png -Copy the source code which is described below to it. +Edit the content to match the code described below. .. code-block:: none @@ -108,6 +124,6 @@ Copy the source code which is described below to it. Conclusion ---------- -Taking everything into account, we can build project with shortcut ``Ctrl+Shift+B`` or using ``Menu: Build → Build All``: +Taking everything into account, we can build project with shortcut ``Ctrl+Shift+B`` or using ``Menu: Build > Build All``: .. image:: ../_static/ide-platformio-qtcreator-7.png diff --git a/docs/ide/sublimetext.rst b/docs/ide/sublimetext.rst index 7e25f61c..af39f328 100644 --- a/docs/ide/sublimetext.rst +++ b/docs/ide/sublimetext.rst @@ -7,8 +7,8 @@ The `Sublime Text `_ is a cross-platform text and s This software can be used with: -* all availalbe :ref:`platforms` -* all availalbe :ref:`frameworks` +* all available :ref:`platforms` +* all available :ref:`frameworks` Refer to the `Sublime Text Documentation `_ page for more detailed information. @@ -18,11 +18,27 @@ page for more detailed information. Integration ----------- +Project Generator +^^^^^^^^^^^^^^^^^ + +Since PlatformIO 2.0 you can generate Eclipse compatible project using +:option:`platformio init --ide` command: + +.. code-block:: shell + + platformio init --ide sublimetext + +Then import this project via ``Project > Open Project...`` and specify root +directory where is located :ref:`projectconf`. + +Manual Integration +^^^^^^^^^^^^^^^^^^ + Initial configuration -^^^^^^^^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~~~~~~~~ First of all, we need to create "New Build System" with name "PlatformIO" -from ``Menu: Tools → Build System → New Build System`` and fill it like +from ``Menu: Tools > Build System > New Build System`` and fill it like described below: .. code-block:: bash @@ -48,16 +64,16 @@ Secondly, we need to select "PlatformIO" Build System from a list: .. image:: ../_static/ide-sublime-text-platformio-newproject-2.png After that, we can use the necessary commands from -``Menu: Tools → Command Palette`` or with ``Ctrl+Shift+P`` (Windows/Linux) +``Menu: Tools > Command Palette`` or with ``Ctrl+Shift+P`` (Windows/Linux) ``Cmd+Shift+P`` (Mac) shortcut. .. image:: ../_static/ide-sublime-text-platformio-newproject-3.png Command Hotkeys -~~~~~~~~~~~~~~~ +''''''''''''''' Sublime Text allows to bind own hotkey per command. Let's setup them -for PlatformIO commands using shortcut ``Menu: Preferences → Key-Bindings - User``: +for PlatformIO commands using shortcut ``Menu: Preferences > Key-Bindings - User``: .. image:: ../_static/ide-sublime-text-platformio-newproject-4.png @@ -76,12 +92,12 @@ In this case, the final code will look like: ] First program in Sublime Text -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Simple "Blink" project will consist from two files: 1. Main "C" source file named ``main.c`` must be located in the ``src`` directory. -Let's create new file named ``main.c`` using ``Menu: File → New File`` or shortcut ``Ctrl+N`` (Windows/Linux) ``Cmd+N`` (Mac) with the next contents: +Let's create new file named ``main.c`` using ``Menu: File > New File`` or shortcut ``Ctrl+N`` (Windows/Linux) ``Cmd+N`` (Mac) with the next contents: .. code-block:: c @@ -124,6 +140,6 @@ Copy the source code which is described below to it. Conclusion ---------- -Taking everything into account, we can open project directory in Sublime Text using ``Menu: File → Open Folder`` and build it with shortcut ``Ctrl+B`` (Windows/Linux) or ``Cmd+B`` (Mac), clean project with shortcut ``F11`` and upload firmware to target with shortcut ``F12``. +Taking everything into account, we can open project directory in Sublime Text using ``Menu: File > Open Folder`` and build it with shortcut ``Ctrl+B`` (Windows/Linux) or ``Cmd+B`` (Mac), clean project with shortcut ``F11`` and upload firmware to target with shortcut ``F12``. .. image:: ../_static/ide-sublime-text-platformio-newproject-5.png diff --git a/docs/ide/vim.rst b/docs/ide/vim.rst index 1840e510..ae1116f6 100644 --- a/docs/ide/vim.rst +++ b/docs/ide/vim.rst @@ -9,8 +9,8 @@ standalone application in a graphical user interface. This software can be used with: -* all availalbe :ref:`platforms` -* all availalbe :ref:`frameworks` +* all available :ref:`platforms` +* all available :ref:`frameworks` Integration ----------- diff --git a/docs/ide/visualstudio.rst b/docs/ide/visualstudio.rst index c5fc28d3..f5275532 100644 --- a/docs/ide/visualstudio.rst +++ b/docs/ide/visualstudio.rst @@ -7,8 +7,8 @@ The `Microsoft Visual Studio (Free) `_ is an integ This software can be used with: -* all availalbe :ref:`platforms` -* all availalbe :ref:`frameworks` +* all available :ref:`platforms` +* all available :ref:`frameworks` Refer to the `Visual Studio Documentation `_ page for more detailed information. @@ -18,10 +18,26 @@ page for more detailed information. Integration ----------- -Setup New Project +Project Generator ^^^^^^^^^^^^^^^^^ -First of all, let's create new project from Visual Studio Start Page: ``Start → New Project`` or using ``Menu: File → New → Project``, then select project with ``Makefile`` type (``Visual C++ → General → Makefile Project``), fill ``Project name``, ``Solution name``, ``Location`` fields and press OK button. +Since PlatformIO 2.0 you can generate Eclipse compatible project using +:option:`platformio init --ide` command: + +.. code-block:: shell + + platformio init --ide visualstudio + +Then import this project via ``File > Import ...`` and specify root directory +where is located :ref:`projectconf`. + +Manual Integration +^^^^^^^^^^^^^^^^^^ + +Setup New Project +~~~~~~~~~~~~~~~~~ + +First of all, let's create new project from Visual Studio Start Page: ``Start > New Project`` or using ``Menu: File > New > Project``, then select project with ``Makefile`` type (``Visual C++ > General > Makefile Project``), fill ``Project name``, ``Solution name``, ``Location`` fields and press OK button. .. image:: ../_static/ide-vs-platformio-newproject.png @@ -37,7 +53,7 @@ Release Configuration is the same as Debug, so on the next step we check "Same a .. image:: ../_static/ide-vs-platformio-newproject-3.png -Thirdly, we need to add directories with header files using project properties (right click on the project name or ``Alt-Enter`` shortcut) and add two directories to ``Configuration Properties → NMake → Include Search Path``: +Thirdly, we need to add directories with header files using project properties (right click on the project name or ``Alt-Enter`` shortcut) and add two directories to ``Configuration Properties > NMake > Include Search Path``: .. code-block:: none @@ -47,12 +63,12 @@ Thirdly, we need to add directories with header files using project properties ( .. image:: ../_static/ide-vs-platformio-newproject-5.png First program in Visual Studio -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Simple "Blink" project will consist from two files: 1. Main "C" source file named ``main.c`` must be located in the ``src`` directory. -Let's create new file named ``main.c`` using ``Menu: File → New File`` or shortcut ``Ctrl+N``: +Let's create new file named ``main.c`` using ``Menu: File > New File`` or shortcut ``Ctrl+N``: .. image:: ../_static/ide-vs-platformio-newproject-6.png @@ -103,6 +119,6 @@ Copy the source code which is described below to it. Conclusion ---------- -Taking everything into account, we can build project with shortcut ``Ctrl+Shift+B`` or using ``Menu: Build → Build Solution``: +Taking everything into account, we can build project with shortcut ``Ctrl+Shift+B`` or using ``Menu: Build > Build Solution``: .. image:: ../_static/ide-vs-platformio-newproject-8.png diff --git a/docs/index.rst b/docs/index.rst index 692057d7..8bb9fe21 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,7 +1,7 @@ PlatformIO: A cross-platform code builder and the missing library manager ========================================================================= -*Atmel AVR & SAM, Freescale Kinetis, Nordic nRF51, NXP LPC, ST STM32, +*Atmel AVR & SAM, Espressif, Freescale Kinetis, Nordic nRF51, NXP LPC, ST STM32, TI MSP430 & Tiva, Teensy, Arduino, mbed, libOpenCM3, etc.* .. image:: _static/platformio-logo.png @@ -29,6 +29,7 @@ Embedded Development. *Easier Than Ever.* * Built-in :ref:`Serial Port Monitor ` * Configurable build :ref:`-flags/-options ` * Integration with :ref:`development environments (IDE) ` +* Ready for Cloud Compiling and :ref:`ci` * Pre-built tool chains, :ref:`frameworks` for the popular Hardware Platforms Smart Code Builder. *Fast and Reliable.* @@ -63,6 +64,7 @@ Contents frameworks/index librarymanager/index userguide/index + ci/index ide articles FAQ diff --git a/docs/librarymanager/creating.rst b/docs/librarymanager/creating.rst index 1db24f56..88011f12 100644 --- a/docs/librarymanager/creating.rst +++ b/docs/librarymanager/creating.rst @@ -134,3 +134,4 @@ The registration requirements: Now, you can :ref:`register ` your library and allow others to :ref:`install ` it. + diff --git a/docs/platforms/creating_platform.rst b/docs/platforms/creating_platform.rst index 811a4038..656c6497 100644 --- a/docs/platforms/creating_platform.rst +++ b/docs/platforms/creating_platform.rst @@ -294,9 +294,124 @@ Installation 1. Create ``platforms`` directory in :ref:`projectconf_pio_home_dir` if it doesn't exists. 2. Copy ``test.py`` and ``test-builder.py`` files to ``platforms`` directory. -3. Search available platforms via :ref:`cmd_search` command. You should see +3. Search available platforms via :ref:`cmd_platforms_search` command. You should see ``test`` platform. -4. Install ``test`` platform via :ref:`cmd_install` command. +4. Install ``test`` platform via :ref:`cmd_platforms_install` command. Now, you can use ``test`` for the :ref:`projectconf_env_platform` option in :ref:`projectconf`. + +Example +------- + +Let's use the real example which was requested by our user in `issue 175 `_. Need to add support for uploading firmware using GDB to +:ref:`platform_ststm32`. + +First of all, need to create new folder ``platforms`` in :ref:`projectconf_pio_home_dir` +and copy there two files: + +1. Platform manifest file ``ststm32gdb.py`` with the next content: + +.. code-block:: python + + import os + + from platformio.platforms.ststm32 import Ststm32Platform + + + class Ststm32gdbPlatform(Ststm32Platform): + + """ + ST STM32 using GDB as uploader + + http://www.st.com/web/en/catalog/mmc/FM141/SC1169?sc=stm32 + """ + + def get_build_script(self): + + return os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "ststm32gdb-builder.py" + ) + +2. Build script file ``ststm32gdb-builder.py`` with the next content: + +.. code-block:: python + + """ + Builder for ST STM32 Series ARM microcontrollers with GDB upload. + """ + + from os.path import join + + from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default, + DefaultEnvironment, SConscript) + + + env = DefaultEnvironment() + + SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py"))) + + env.Replace( + UPLOADER=join( + "$PIOPACKAGES_DIR", "toolchain-gccarmnoneeabi", + "bin", "arm-none-eabi-gdb" + ), + UPLOADERFLAGS=[ + join("$BUILD_DIR", "firmware.elf"), + "-batch", + "-x", join("$PROJECT_DIR", "upload.gdb") + ], + + UPLOADCMD="$UPLOADER $UPLOADERFLAGS" + ) + + env.Append( + CPPDEFINES=[ + "${BOARD_OPTIONS['build']['variant'].upper()}" + ], + + LINKFLAGS=[ + "-nostartfiles", + "-nostdlib" + ] + ) + + # + # Target: Build executable and linkable firmware + # + + target_elf = env.BuildFirmware() + + # + # Target: Build the .bin file + # + + if "uploadlazy" in COMMAND_LINE_TARGETS: + target_firm = join("$BUILD_DIR", "firmware.bin") + else: + target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) + + # + # Target: Print binary size + # + + target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD") + AlwaysBuild(target_size) + + # + # Target: Upload by default .bin file + # + + upload = env.Alias( + ["upload", "uploadlazy"], target_firm, "$UPLOADCMD") + AlwaysBuild(upload) + + # + # Target: Define targets + # + + Default([target_firm, target_size]) + +Now, we should see ``ststm32gdb`` platform using :ref:`cmd_platforms_search` command output +and can install it via :ref:`platformio platforms install ststm32gdb ` command. diff --git a/docs/platforms/ststm32.rst b/docs/platforms/ststm32.rst index 4f2c5e40..3aaec0d5 100644 --- a/docs/platforms/ststm32.rst +++ b/docs/platforms/ststm32.rst @@ -73,6 +73,40 @@ Boards * For more detailed ``board`` information please scroll tables below by horizontal. +Armstrap +~~~~~~~~ + +.. list-table:: + :header-rows: 1 + + * - Type ``board`` + - Name + - Microcontroller + - Frequency + - Flash + - RAM + + * - ``armstrap_eagle1024`` + - `Armstrap Eagle 1024 `_ + - STM32F417VGT6 + - 168 MHz + - 1024 Kb + - 192 Kb + + * - ``armstrap_eagle2048`` + - `Armstrap Eagle 2048 `_ + - STM32F427VIT6 + - 168 MHz + - 2048 Kb + - 256 Kb + + * - ``armstrap_eagle512`` + - `Armstrap Eagle 512 `_ + - STM32F407VET6 + - 168 MHz + - 512 Kb + - 192 Kb + ST ~~ diff --git a/docs/projectconf.rst b/docs/projectconf.rst index df508ed5..698a8762 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -226,7 +226,7 @@ processes: * - Format - Scope - Description - * - ``Wp,option`` + * - ``-Wp,option`` - CPPFLAGS - Bypass the compiler driver and pass *option* directly through to the preprocessor @@ -309,6 +309,35 @@ but will be applied only for the project source code from This option can be overridden by global environment variable :ref:`envvar_PLATFORMIO_SRCBUILD_FLAGS`. +``install_libs`` +^^^^^^^^^^^^^^^^ + +Specify dependent libraries which should be installed before environment +process. The only library IDs are allowed. Multiple libraries can be passed +using comma ``,`` sign. + +You can obtain library IDs using :ref:`cmd_lib_search` command. + +Example: + +.. code-block:: ini + + [env:depends_on_some_libs] + install_libs = 1,13,19 + +``use_libs`` +^^^^^^^^^^^^ + +Specify libraries which should be used by ``Library Dependency Finder`` with +the highest priority. + +Example: + +.. code-block:: ini + + [env:libs_with_highest_priority] + use_libs = OneWire_ID1 + ``ignore_libs`` ^^^^^^^^^^^^^^^ diff --git a/docs/quickstart.rst b/docs/quickstart.rst index f9296061..a2336d16 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -9,8 +9,8 @@ Quickstart 1. :ref:`Install PlatformIO `. -2. Find board ``type`` on this :ref:`Embedded Boards ` page or - via :ref:`cmd_boards` command. +2. Find board ``type`` using `Embedded Boards Explorer `_ + or via :ref:`cmd_boards` command. 3. Initialize new PlatformIO based project via :ref:`cmd_init` command with the pre-configured environments for your boards: diff --git a/docs/userguide/cmd_ci.rst b/docs/userguide/cmd_ci.rst new file mode 100644 index 00000000..77d9d08b --- /dev/null +++ b/docs/userguide/cmd_ci.rst @@ -0,0 +1,110 @@ +.. _cmd_ci: + +platformio ci +============= + +.. contents:: + +Usage +----- + +.. code-block:: bash + + platformio ci [OPTIONS] [SRC] + + +Description +----------- + +:ref:`cmd_ci` command is conceived of as "hot key" for building project with +arbitrary source code structure. In a nutshell, using ``SRC`` and +:option:`platformio ci --lib` contents PlatformIO initialises via +:ref:`cmd_init` new project in :option:`platformio ci --build-dir` +with the build environments (using :option:`platformio ci --board` or +:option:`platformio ci --project-conf`) and processes them via :ref:`cmd_run` +command. + +For more details as for integration with the popular Continuous Integration +Systems please follow to :ref:`ci` page. + +.. note:: + :ref:`cmd_ci` command accepts **multiple** ``SRC`` arguments, + :option:`platformio ci --lib` and :option:`platformio ci --exclude` options + which can be a path to directory, file or + `Glob Pattern `_. + +.. note:: + You can omit ``SRC`` argument and set path (multiple paths are allowed + denoting with ``:``) to + ``PLATFORMIO_CI_SRC`` `Environment variable `_ + +Options +------- + +.. program:: platformio ci + +.. option:: + -l, --lib + +Source code which will be copied to ``%build_dir%/lib`` directly. + +If :option:`platformio ci --lib` is a path to file (not to directory), then +PlatformIO will create temporary directory within ``%build_dir%/lib`` and copy +the rest files into it. + + +.. option:: + --exclude + +Exclude directories and/-or files from :option:`platformio ci --build-dir`. The +path must be relative to PlatformIO project within +:option:`platformio ci --build-dir`. + +For example, exclude from project ``src`` directory: + +* ``examples`` folder +* ``*.h`` files from ``foo`` folder + +.. code-block:: bash + + platformio ci --exclude=src/examples --exclude=src/foo/*.h [SRC] + +.. option:: + -b, --board + +Build project with automatically pre-generated environments based on board +settings. + +For more details please look into :option:`platformio init --board`. + +.. option:: + --build-dir + +Path to directory where PlatformIO will initialise new project. By default it's +temporary directory within your operation system. + +.. note:: + + This directory will be removed at the end of build process. If you want to + keep it, please use :option:`platformio ci --keep-build-dir`. + +.. option:: + --keep-build-dir + +Don't remove :option:`platformio ci --build-dir` after build process. + +.. option:: + --project-conf + +Buid project using pre-configured :ref:`projectconf`. + +.. option:: + -v, --verbose + +Shows details about the results of processing environments. More details +:option:`platformio run --verbose` + +Examples +-------- + +For the examples please follow to :ref:`ci` page. diff --git a/docs/userguide/cmd_init.rst b/docs/userguide/cmd_init.rst index 4890adf1..02e140de 100644 --- a/docs/userguide/cmd_init.rst +++ b/docs/userguide/cmd_init.rst @@ -29,13 +29,15 @@ This command will create: Options ------- +.. program:: platformio init + .. option:: - --project-dir, -d + -d, --project-dir A path to the directory where *PlatformIO* will initialise new project. .. option:: - --board, -b + -b, --board If you specify board ``type`` (you can pass multiple ``--board`` options), then *PlatformIO* will automatically generate environment for :ref:`projectconf` and @@ -47,13 +49,32 @@ pre-fill these data: The full list with pre-configured boards is available here :ref:`platforms`. +.. option:: + --ide + +Initialise PlatformIO project for the specified IDE which can be imported later +via "Import Project" functionality. + +A list with supported IDE is available within ``platformio init --help`` command. +Also, please look into :ref:`ide` page. + .. option:: --disable-auto-uploading -If you initialise project with the specified ``--board``, then *PlatformIO* +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. +.. option:: + --env-prefix + +An environment prefix which will be used with pair in board type. + +For example, the default environment name for ``teensy_31`` board will +be ``[env:teensy_31]``. + + Examples -------- diff --git a/docs/userguide/cmd_run.rst b/docs/userguide/cmd_run.rst index 2dc833f4..468f22cd 100644 --- a/docs/userguide/cmd_run.rst +++ b/docs/userguide/cmd_run.rst @@ -22,6 +22,8 @@ Process environments which are defined in :ref:`projectconf` file Options ------- +.. program:: platformio run + .. option:: -e, --environment @@ -39,6 +41,27 @@ Process specified targets Upload port of embedded board. To print all available ports use :ref:`cmd_serialports` command +.. option:: + --build-dir + +Specify the path to project directory. By default, ``--build-dir`` is equal to +current working directory (``CWD``). + +.. option:: + -v, --verbose + +Shows details about the results of processing environments. Each instance of +``--verbose`` on the command line increases the verbosity level by one, so if +you need more details on the output, specify it twice. + +There 3 levels of verbosity: + +1. ``-v`` - output errors only +2. ``-vv`` - output errors and warnings +3. ``-vvv`` - output errors, warnings and additional information + +By default, verbosity level is set to 3 (maximum information). + Examples -------- diff --git a/docs/userguide/cmd_serialports.rst b/docs/userguide/cmd_serialports.rst index 360877ec..53bae993 100644 --- a/docs/userguide/cmd_serialports.rst +++ b/docs/userguide/cmd_serialports.rst @@ -24,6 +24,8 @@ List available `Serial Ports `_ Options ~~~~~~~ +.. program:: platformio serialports list + .. option:: --json-output @@ -99,6 +101,8 @@ To control *monitor* please use these "hot keys": Options ~~~~~~~ +.. program:: platformio serialports monitor + .. option:: -p, --port diff --git a/docs/userguide/cmd_update.rst b/docs/userguide/cmd_update.rst index b01cf9b4..60609fe2 100644 --- a/docs/userguide/cmd_update.rst +++ b/docs/userguide/cmd_update.rst @@ -16,7 +16,8 @@ Usage Description ----------- -Check or update installed :ref:`Platforms ` +Check or update installed :ref:`Platforms ` and +:ref:`Libraries ` Examples diff --git a/docs/userguide/index.rst b/docs/userguide/index.rst index a2db09ce..6c52a9e5 100644 --- a/docs/userguide/index.rst +++ b/docs/userguide/index.rst @@ -3,7 +3,35 @@ User Guide ========== -To print all available commands and options use: +.. contents:: + +Usage +----- + +.. code-block:: bash + + platformio [OPTIONS] COMMAND + +Options +------- + +.. program:: platformio + +.. option:: + --force, - f + +Force to accept any confirmation prompts. This option allows to avoid an issue +with :ref:`faq_troubleshooting_pioblocksprompt` + +.. option:: + --version + +Show the version of PlatformIO + +.. option:: + --help + +Show help for the available options and commands .. code-block:: bash @@ -11,19 +39,19 @@ To print all available commands and options use: $ platformio COMMAND --help +Commands +-------- + .. toctree:: :maxdepth: 2 cmd_boards + cmd_ci cmd_init - cmd_install platformio lib - cmd_list + platformio platforms cmd_run - cmd_search cmd_serialports cmd_settings - cmd_show - cmd_uninstall cmd_update cmd_upgrade diff --git a/docs/userguide/lib/cmd_install.rst b/docs/userguide/lib/cmd_install.rst index 854401b7..bb4dd95f 100644 --- a/docs/userguide/lib/cmd_install.rst +++ b/docs/userguide/lib/cmd_install.rst @@ -22,6 +22,8 @@ Install new library by specified Options ------- +.. program:: platformio lib install + .. option:: -v, --version diff --git a/docs/userguide/lib/cmd_list.rst b/docs/userguide/lib/cmd_list.rst index 2551704b..07c68bc3 100644 --- a/docs/userguide/lib/cmd_list.rst +++ b/docs/userguide/lib/cmd_list.rst @@ -21,6 +21,8 @@ List installed libraries Options ~~~~~~~ +.. program:: platformio lib list + .. option:: --json-output diff --git a/docs/userguide/lib/cmd_search.rst b/docs/userguide/lib/cmd_search.rst index 84899256..41bd8199 100644 --- a/docs/userguide/lib/cmd_search.rst +++ b/docs/userguide/lib/cmd_search.rst @@ -61,6 +61,8 @@ For more detail information please go to Options ------- +.. program:: platformio lib search + .. option:: -a, --author diff --git a/docs/userguide/lib/cmd_update.rst b/docs/userguide/lib/cmd_update.rst index f719fa13..f58fab4c 100644 --- a/docs/userguide/lib/cmd_update.rst +++ b/docs/userguide/lib/cmd_update.rst @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio lib update + platformio lib update [LIBRARY_ID] Description @@ -22,6 +22,8 @@ Check or update installed libraries Examples -------- +1. Update all installed libraries + .. code-block:: bash $ platformio lib update @@ -36,8 +38,23 @@ Examples # Updating [ 13 ] Adafruit-GFX library: # Versions: Current=a9e5bc4707, Latest=a9e5bc4707 [Up-to-date] # Updating [ 1 ] OneWire library: - # Versions: Current=2.2, Latest=2.2 [Up-to-date] + # Versions: Current=2.2, Latest=2.2 [Up-to-date] # Updating [ 4 ] IRremote library: # Versions: Current=f2dafe5030, Latest=f2dafe5030 [Up-to-date] # Updating [ 14 ] Adafruit-9DOF-Unified library: # Versions: Current=b2f07242ac, Latest=b2f07242ac [Up-to-date] + +2. Update specified libraries + +.. code-block:: bash + + $ platformio lib update 1 59 + # Updating [ 1 ] OneWire library: + # Versions: Current=2.2, Latest=2.2 [Up-to-date] + # Updating [ 59 ] USB-Host-Shield-20 library: + # Versions: Current=fcab83dcb3, Latest=c61f9ce1c2 [Out-of-date] + # The library #59 'USB-Host-Shield-20' has been successfully uninstalled! + # Installing library [ 59 ]: + # Downloading [####################################] 100% + # Unpacking [####################################] 100% + # The library #59 'USB-Host-Shield-20' has been successfully installed! diff --git a/docs/userguide/cmd_install.rst b/docs/userguide/platforms/cmd_install.rst similarity index 82% rename from docs/userguide/cmd_install.rst rename to docs/userguide/platforms/cmd_install.rst index 33557ca6..ced397f8 100644 --- a/docs/userguide/cmd_install.rst +++ b/docs/userguide/platforms/cmd_install.rst @@ -1,7 +1,7 @@ -.. _cmd_install: +.. _cmd_platforms_install: -platformio install -================== +platformio platforms install +============================ .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio install [OPTIONS] [PLATFORMS] + platformio platforms install [OPTIONS] [PLATFORMS] Description @@ -27,6 +27,8 @@ There are several predefined aliases for packages, such as: Options ------- +.. program:: platformio platforms install + .. option:: --with-package @@ -50,7 +52,7 @@ Examples .. code-block:: bash - $ platformio install timsp430 + $ platformio platforms install timsp430 Installing toolchain-timsp430 package: Downloading [####################################] 100% Unpacking [####################################] 100% @@ -68,7 +70,7 @@ Examples .. code-block:: bash - $ platformio install timsp430 --skip-default-package --with-package=uploader + $ platformio platforms install timsp430 --skip-default-package --with-package=uploader Installing tool-mspdebug package: Downloading [####################################] 100% Unpacking [####################################] 100% diff --git a/docs/userguide/cmd_list.rst b/docs/userguide/platforms/cmd_list.rst similarity index 86% rename from docs/userguide/cmd_list.rst rename to docs/userguide/platforms/cmd_list.rst index 1bc6b745..90e5d9a5 100644 --- a/docs/userguide/cmd_list.rst +++ b/docs/userguide/platforms/cmd_list.rst @@ -1,7 +1,7 @@ -.. _cmd_list: +.. _cmd_platforms_list: -platformio list -=============== +platformio platforms list +========================= .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio list [OPTIONS] + platformio platforms list [OPTIONS] Description @@ -21,6 +21,8 @@ List installed :ref:`Platforms ` Options ~~~~~~~ +.. program:: platformio platforms list + .. option:: --json-output @@ -31,7 +33,7 @@ Examples .. code-block:: bash - $ platformio list + $ platformio platforms list atmelavr with packages: toolchain-atmelavr, tool-avrdude, framework-arduinoavr, tool-micronucleus atmelsam with packages: framework-arduinosam, ldscripts, toolchain-gccarmnoneeabi, tool-bossac freescalekinetis with packages: framework-mbed, toolchain-gccarmnoneeabi diff --git a/docs/userguide/cmd_search.rst b/docs/userguide/platforms/cmd_search.rst similarity index 93% rename from docs/userguide/cmd_search.rst rename to docs/userguide/platforms/cmd_search.rst index 304c7fc6..20d9e42e 100644 --- a/docs/userguide/cmd_search.rst +++ b/docs/userguide/platforms/cmd_search.rst @@ -1,7 +1,7 @@ -.. _cmd_search: +.. _cmd_platforms_search: -platformio search -================= +platformio platforms search +=========================== .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio search QUERY [OPTIONS] + platformio platforms search QUERY [OPTIONS] Description @@ -21,6 +21,8 @@ Search for development :ref:`Platforms ` Options ~~~~~~~ +.. program:: platformio platforms search + .. option:: --json-output @@ -34,7 +36,7 @@ Examples .. code-block:: bash - $ platformio search + $ platformio platforms search atmelavr (available packages: ldscripts, toolchain-gccarmnoneeabi, tool-lm4flash, framework-opencm3, framework-energiativa) -------- Atmel AVR 8- and 32-bit MCUs deliver a unique combination of performance... @@ -75,7 +77,7 @@ Examples .. code-block:: bash - $ platformio search ti + $ platformio platforms search ti timsp430 (available packages: ldscripts, toolchain-gccarmnoneeabi, tool-lm4flash, framework-opencm3, framework-energiativa) -------- MSP430 microcontrollers (MCUs) from Texas Instruments (TI) are ... @@ -88,7 +90,7 @@ Examples .. code-block:: bash - $ platformio search mbed + $ platformio platforms search mbed freescalekinetis (available packages: ldscripts, toolchain-gccarmnoneeabi, tool-lm4flash, framework-opencm3, framework-energiativa) ---------------- Freescale Kinetis Microcontrollers is family of multiple hardware- and ... diff --git a/docs/userguide/cmd_show.rst b/docs/userguide/platforms/cmd_show.rst similarity index 81% rename from docs/userguide/cmd_show.rst rename to docs/userguide/platforms/cmd_show.rst index c109117f..1948b4f2 100644 --- a/docs/userguide/cmd_show.rst +++ b/docs/userguide/platforms/cmd_show.rst @@ -1,7 +1,7 @@ -.. _cmd_show: +.. _cmd_platforms_show: -platformio show -=============== +platformio platforms show +========================= .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio show PLATFORM + platformio platforms show PLATFORM Description @@ -24,7 +24,7 @@ Examples .. code-block:: bash - $ platformio show atmelavr + $ platformio platforms show atmelavr atmelavr - An embedded platform for Atmel AVR microcontrollers (with Arduino Framework) ---------- Package: toolchain-atmelavr diff --git a/docs/userguide/cmd_uninstall.rst b/docs/userguide/platforms/cmd_uninstall.rst similarity index 69% rename from docs/userguide/cmd_uninstall.rst rename to docs/userguide/platforms/cmd_uninstall.rst index ef6348f1..a7e307f9 100644 --- a/docs/userguide/cmd_uninstall.rst +++ b/docs/userguide/platforms/cmd_uninstall.rst @@ -1,7 +1,7 @@ -.. _cmd_uninstall: +.. _cmd_platforms_uninstall: -platformio uninstall -==================== +platformio platforms uninstall +============================== .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio uninstall PLATFORM + platformio platforms uninstall PLATFORM Description @@ -24,7 +24,7 @@ Examples .. code-block:: bash - $ platformio uninstall timsp430 + $ platformio platforms uninstall timsp430 Uninstalling toolchain-timsp430 package: [OK] Uninstalling tool-mspdebug package: [OK] Uninstalling framework-energiamsp430 package: [OK] diff --git a/docs/userguide/platforms/cmd_update.rst b/docs/userguide/platforms/cmd_update.rst new file mode 100644 index 00000000..398d9527 --- /dev/null +++ b/docs/userguide/platforms/cmd_update.rst @@ -0,0 +1,99 @@ +.. _cmd_platforms_update: + +platformio platforms update +=========================== + +.. contents:: + +Usage +----- + +.. code-block:: bash + + platformio platforms update + + +Description +----------- + +Check or update installed :ref:`Platforms ` + + +Examples +-------- + +.. code-block:: bash + + $ platformio platforms update + + Platform atmelavr + -------- + Updating toolchain-atmelavr package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-avrdude package: + Versions: Current=2, Latest=2 [Up-to-date] + Updating framework-arduinoavr package: + Versions: Current=12, Latest=12 [Up-to-date] + Updating tool-micronucleus package: + Versions: Current=1, Latest=1 [Up-to-date] + + Platform atmelsam + -------- + Updating framework-arduinosam package: + Versions: Current=3, Latest=3 [Up-to-date] + Updating ldscripts package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating toolchain-gccarmnoneeabi package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-bossac package: + Versions: Current=1, Latest=1 [Up-to-date] + + Platform stm32 + -------- + Updating toolchain-gccarmnoneeabi package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-stlink package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-spl package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-cmsis package: + Versions: Current=2, Latest=2 [Up-to-date] + Updating framework-opencm3 package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating ldscripts package: + Versions: Current=1, Latest=1 [Up-to-date] + + Platform teensy + -------- + Updating toolchain-atmelavr package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating ldscripts package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-arduinoteensy package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating toolchain-gccarmnoneeabi package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-teensy package: + Versions: Current=1, Latest=1 [Up-to-date] + + Platform timsp430 + -------- + Updating toolchain-timsp430 package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-mspdebug package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-energiamsp430 package: + Versions: Current=2, Latest=2 [Up-to-date] + + Platform titiva + -------- + Updating ldscripts package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating toolchain-gccarmnoneeabi package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-lm4flash package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-opencm3 package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-energiativa package: + Versions: Current=4, Latest=4 [Up-to-date] diff --git a/docs/userguide/platforms/index.rst b/docs/userguide/platforms/index.rst new file mode 100644 index 00000000..7a582752 --- /dev/null +++ b/docs/userguide/platforms/index.rst @@ -0,0 +1,22 @@ +.. _userguide_platforms: + +Platforms Manager +================= + +To print all available commands and options use: + +.. code-block:: bash + + $ platformio platforms --help + $ platformio platforms COMMAND --help + + +.. toctree:: + :maxdepth: 2 + + cmd_install + cmd_list + cmd_search + cmd_show + cmd_uninstall + cmd_update diff --git a/examples/atmelavr-and-arduino/arduino-external-libs/lib/Adafruit-GFX-Library b/examples/atmelavr-and-arduino/arduino-external-libs/lib/Adafruit-GFX-Library index b346ad0d..734b107c 160000 --- a/examples/atmelavr-and-arduino/arduino-external-libs/lib/Adafruit-GFX-Library +++ b/examples/atmelavr-and-arduino/arduino-external-libs/lib/Adafruit-GFX-Library @@ -1 +1 @@ -Subproject commit b346ad0df569c3b5d27c7e64656a3e1408fb8aa8 +Subproject commit 734b107c393e8a91d8c1d46a42f59a4dfb25b576 diff --git a/examples/espressif/esp8266-webserver/src/HelloServer.ino b/examples/espressif/esp8266-webserver/src/HelloServer.ino index 55cdf043..f996c534 100644 --- a/examples/espressif/esp8266-webserver/src/HelloServer.ino +++ b/examples/espressif/esp8266-webserver/src/HelloServer.ino @@ -1,29 +1,43 @@ #include #include #include +#include -const char* ssid = "*****"; -const char* password = "*****"; - +const char* ssid = "******"; +const char* password = "******"; +MDNSResponder mdns; ESP8266WebServer server(80); - + const int led = 13; - -void handle_root() { + +void handleRoot() { digitalWrite(led, 1); server.send(200, "text/plain", "hello from esp8266!"); - delay(100); + digitalWrite(led, 0); +} + +void handleNotFound(){ + digitalWrite(led, 1); + String message = "File Not Found\n\n"; + message += "URI: "; + message += server.uri(); + message += "\nMethod: "; + message += (server.method() == HTTP_GET)?"GET":"POST"; + message += "\nArguments: "; + message += server.args(); + message += "\n"; + for (uint8_t i=0; i # See LICENSE for details. -VERSION = (1, 5, 0) +VERSION = (2, 0, 0) __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/__main__.py b/platformio/__main__.py index fbd34974..a4e44146 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -31,20 +31,38 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904 mod = __import__("platformio.commands." + name, None, None, ["cli"]) except ImportError: - raise exception.UnknownCLICommand(name) + try: + return self._handle_obsolate_command(name) + except AttributeError: + raise exception.UnknownCLICommand(name) return mod.cli + @staticmethod + def _handle_obsolate_command(name): + if name in ("install", "list", "search", "show", "uninstall"): + click.secho( + "Warning! `platformio %s` command is obsoleted and will be " + "removed in the next release! Please use " + "`platformio platforms %s` instead." % (name, name), + fg="red" + ) + from platformio.commands import platforms + return getattr(platforms, "platforms_" + name) + raise AttributeError() + @click.command(cls=PlatformioCLI) @click.version_option(__version__, prog_name="PlatformIO") +@click.option("--force", "-f", is_flag=True, + help="Force to accept any confirmation prompts") @click.pass_context -def cli(ctx): - maintenance.on_platformio_start(ctx) +def cli(ctx, force): + maintenance.on_platformio_start(ctx, force) @cli.resultcallback() @click.pass_context -def process_result(ctx, result): +def process_result(ctx, result, force): # pylint: disable=W0613 maintenance.on_platformio_end(ctx, result) @@ -54,7 +72,7 @@ def main(): # /en/latest/security.html#insecureplatformwarning requests.packages.urllib3.disable_warnings() - cli(None) + cli(None, None) except Exception as e: # pylint: disable=W0703 if not isinstance(e, exception.ReturnErrorCode): maintenance.on_platformio_exception(e) diff --git a/platformio/app.py b/platformio/app.py index fe299d6a..c7776827 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -24,11 +24,11 @@ DEFAULT_SETTINGS = { }, "auto_update_platforms": { "description": "Automatically update platforms (Yes/No)", - "value": True + "value": False }, "auto_update_libraries": { "description": "Automatically update libraries (Yes/No)", - "value": True + "value": False }, "enable_telemetry": { "description": ("Shares commands, platforms and libraries usage" @@ -47,6 +47,11 @@ DEFAULT_SETTINGS = { } +SESSION_VARS = { + "force_option": False +} + + class State(object): def __init__(self, path=None): @@ -101,9 +106,12 @@ def set_state_item(name, value): def get_setting(name): - # disable prompts for Continuous Integration systems - if name == "enable_prompts" and getenv("CI", "").lower() == "true": - return False + if name == "enable_prompts": + # disable prompts for Continuous Integration systems + # and when global "--force" option is set + if any([getenv("CI", "").lower() == "true", + get_session_var("force_option")]): + return False _env_name = "PLATFORMIO_SETTING_%s" % name.upper() if _env_name in environ: @@ -127,3 +135,12 @@ def reset_settings(): with State() as data: if "settings" in data: del data['settings'] + + +def get_session_var(name, default=None): + return SESSION_VARS.get(name, default) + + +def set_session_var(name, value): + assert name in SESSION_VARS + SESSION_VARS[name] = value diff --git a/platformio/boards/espressif.json b/platformio/boards/espressif.json index 6c2b226c..100517a1 100644 --- a/platformio/boards/espressif.json +++ b/platformio/boards/espressif.json @@ -2,11 +2,11 @@ "esp01": { "build": { "core": "esp8266", - "extra_flags": "-DARDUINO_ESP8266_ESP01 -DARDUINO_ARCH_ESP8266", + "extra_flags": "-DARDUINO_ESP8266_ESP01 -DARDUINO_ARCH_ESP8266 -DESP8266", "f_cpu": "80000000L", - "ldscript": "esp8266.ld", + "ldscript": "esp8266.flash.512k.ld", "mcu": "esp8266", - "variant": "esp01" + "variant": "generic" }, "frameworks": ["arduino"], "name": "Espressif ESP8266 board", diff --git a/platformio/boards/ststm32.json b/platformio/boards/ststm32.json index 63c188ee..a5fd3475 100644 --- a/platformio/boards/ststm32.json +++ b/platformio/boards/ststm32.json @@ -330,5 +330,65 @@ }, "url": "https://developer.mbed.org/platforms/ST-Nucleo-L152RE/", "vendor": "ST" + }, + "armstrap_eagle512": { + "build": { + "core": "stm32", + "extra_flags": "-DSTM32F40_41xxx", + "f_cpu": "168000000L", + "ldscript": "armstrap_eagle_512.ld", + "cpu": "cortex-m4", + "mcu": "stm32f407vet6", + "variant": "stm32f4" + }, + "frameworks": ["cmsis", "spl"], + "name": "Armstrap Eagle 512", + "platform": "ststm32", + "upload": { + "maximum_ram_size": 196608, + "maximum_size": 524288 + }, + "url": "http://docs.armstrap.org/en/latest/hardware-overview.html", + "vendor": "Armstrap" + }, + "armstrap_eagle1024": { + "build": { + "core": "stm32", + "extra_flags": "-DSTM32F40_41xxx", + "f_cpu": "168000000L", + "ldscript": "armstrap_eagle_1024.ld", + "cpu": "cortex-m4", + "mcu": "stm32f417vgt6", + "variant": "stm32f4" + }, + "frameworks": ["cmsis", "spl"], + "name": "Armstrap Eagle 1024", + "platform": "ststm32", + "upload": { + "maximum_ram_size": 196608, + "maximum_size": 1048576 + }, + "url": "http://docs.armstrap.org/en/latest/hardware-overview.html", + "vendor": "Armstrap" + }, + "armstrap_eagle2048": { + "build": { + "core": "stm32", + "extra_flags": "-DSTM32F427_437xx", + "f_cpu": "168000000L", + "ldscript": "armstrap_eagle_2048.ld", + "cpu": "cortex-m4", + "mcu": "stm32f427vit6", + "variant": "stm32f4" + }, + "frameworks": ["cmsis", "spl"], + "name": "Armstrap Eagle 2048", + "platform": "ststm32", + "upload": { + "maximum_ram_size": 262144, + "maximum_size": 2091752 + }, + "url": "http://docs.armstrap.org/en/latest/hardware-overview.html", + "vendor": "Armstrap" } } \ No newline at end of file diff --git a/platformio/builder/main.py b/platformio/builder/main.py index a68aceb9..45ec63d6 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -37,6 +37,7 @@ commonvars.AddVariables( ("BUILD_FLAGS",), ("SRCBUILD_FLAGS",), ("IGNORE_LIBS",), + ("USE_LIBS",), # board options ("BOARD",), diff --git a/platformio/builder/scripts/espressif.py b/platformio/builder/scripts/espressif.py index 289f9955..ca4742c2 100644 --- a/platformio/builder/scripts/espressif.py +++ b/platformio/builder/scripts/espressif.py @@ -43,6 +43,8 @@ env.Replace( "-Os", # optimize for size "-mlongcalls", "-mtext-section-literals", + "-falign-functions=4", + "-U__STRICT_ANSI__", "-MMD" # output dependancy info ], @@ -70,12 +72,12 @@ env.Replace( UPLOADER=join("$PIOPACKAGES_DIR", "tool-esptool", "esptool"), UPLOADERFLAGS=[ "-vv", - "-cd", "none", + "-cd", "ck", "-cb", "$UPLOAD_SPEED", "-cp", "$UPLOAD_PORT", "-ca", "0x00000", "-cf", "${SOURCES[0]}", - "-ca", "0x40000", + "-ca", "0x10000", "-cf", "${SOURCES[1]}" ], UPLOADCMD='$UPLOADER $UPLOADERFLAGS' @@ -88,6 +90,9 @@ env.Append( "$UPLOADER", "-eo", "$SOURCES", "-bo", "${TARGETS[0]}", + "-bm", "qio", + "-bf", "40", + "-bz", "512K", "-bs", ".text", "-bs", ".data", "-bs", ".rodata", @@ -135,7 +140,7 @@ if "uploadlazy" in COMMAND_LINE_TARGETS: else: target_firm = env.ElfToBin( [join("$BUILD_DIR", "firmware_00000"), - join("$BUILD_DIR", "firmware_40000")], target_elf) + join("$BUILD_DIR", "firmware_10000")], target_elf) # diff --git a/platformio/builder/scripts/frameworks/arduino.py b/platformio/builder/scripts/frameworks/arduino.py index efded5f3..1761e0e9 100644 --- a/platformio/builder/scripts/frameworks/arduino.py +++ b/platformio/builder/scripts/frameworks/arduino.py @@ -46,8 +46,8 @@ elif env.get("PLATFORM") == "espressif": env.Prepend( CPPPATH=[join("$PLATFORMFW_DIR", "sdk", "include")], LIBPATH=[join("$PLATFORMFW_DIR", "sdk", "lib")], - LIBS=["hal", "phy", "net80211", "lwip", - "wpa", "main", "pp", "c", "gcc"] + LIBS=["smartconfig", "pp", "main", "wpa", "lwip", + "net80211", "phy", "hal", "gcc", "m"] ) env.Replace(PLATFORMFW_DIR=PLATFORMFW_DIR) @@ -106,20 +106,20 @@ env.Append( # if env.subst("${PLATFORMFW_DIR}")[-3:] == "sam": - env.VariantDir( + env.VariantDirWrap( join("$BUILD_DIR", "FrameworkCMSISInc"), join("$PLATFORMFW_DIR", "system", "CMSIS", "CMSIS", "Include") ) - env.VariantDir( + env.VariantDirWrap( join("$BUILD_DIR", "FrameworkDeviceInc"), join("$PLATFORMFW_DIR", "system", "CMSIS", "Device", "ATMEL") ) - env.VariantDir( + env.VariantDirWrap( join("$BUILD_DIR", "FrameworkLibSam"), join("$PLATFORMFW_DIR", "system", "libsam") ) - env.VariantDir( + env.VariantDirWrap( join("$BUILD_DIR", "FrameworkArduinoInc"), join("$PLATFORMFW_DIR", "cores", "${BOARD_OPTIONS['build']['core']}") ) diff --git a/platformio/builder/scripts/frameworks/cmsis.py b/platformio/builder/scripts/frameworks/cmsis.py index 6410c10f..2d8d55c7 100644 --- a/platformio/builder/scripts/frameworks/cmsis.py +++ b/platformio/builder/scripts/frameworks/cmsis.py @@ -25,7 +25,7 @@ env.Replace( PLATFORMFW_DIR=join("$PIOPACKAGES_DIR", "framework-cmsis") ) -env.VariantDir( +env.VariantDirWrap( join("$BUILD_DIR", "FrameworkCMSIS"), join("$PLATFORMFW_DIR", "cores", "${BOARD_OPTIONS['build']['core']}") ) diff --git a/platformio/builder/scripts/frameworks/energia.py b/platformio/builder/scripts/frameworks/energia.py index 67b4cc10..69bdb8fa 100644 --- a/platformio/builder/scripts/frameworks/energia.py +++ b/platformio/builder/scripts/frameworks/energia.py @@ -28,7 +28,7 @@ ENERGIA_VERSION = int( "version.txt")).read().replace(".", "").strip()) # include board variant -env.VariantDir( +env.VariantDirWrap( join("$BUILD_DIR", "FrameworkEnergiaVariant"), join("$PLATFORMFW_DIR", "variants", "${BOARD_OPTIONS['build']['variant']}") ) diff --git a/platformio/builder/scripts/frameworks/libopencm3.py b/platformio/builder/scripts/frameworks/libopencm3.py index a0336e77..72a762c5 100644 --- a/platformio/builder/scripts/frameworks/libopencm3.py +++ b/platformio/builder/scripts/frameworks/libopencm3.py @@ -138,7 +138,7 @@ if BOARD_BUILDOPTS.get("core") == "lm4f": CPPDEFINES=["LM4F"] ) -env.VariantDir( +env.VariantDirWrap( join("$BUILD_DIR", "FrameworkLibOpenCM3Variant"), join("$PLATFORMFW_DIR", "include") ) @@ -166,7 +166,7 @@ env.Replace( ) libs = [] -env.VariantDir( +env.VariantDirWrap( join("$BUILD_DIR", "FrameworkLibOpenCM3"), "$PLATFORMFW_DIR" ) diff --git a/platformio/builder/scripts/frameworks/mbed.py b/platformio/builder/scripts/frameworks/mbed.py index 763b85c3..e9e57ad0 100644 --- a/platformio/builder/scripts/frameworks/mbed.py +++ b/platformio/builder/scripts/frameworks/mbed.py @@ -134,7 +134,7 @@ def add_mbedlib(libname, libar): (libname.upper(), crc32(root))) if var_dir in env.get("CPPPATH"): continue - env.VariantDir(var_dir, root) + env.VariantDirWrap(var_dir, root) env.Append(CPPPATH=[var_dir]) @@ -221,7 +221,7 @@ if board_type in ("frdm_k22f", "frdm_k64f"): for lib_path in eixdata.get("CPPPATH"): _vdir = join("$BUILD_DIR", "FrameworkMbedInc%d" % crc32(lib_path)) - env.VariantDir(_vdir, join(variant_dir, lib_path)) + env.VariantDirWrap(_vdir, join(variant_dir, lib_path)) env.Append(CPPPATH=[_vdir]) env.Append( diff --git a/platformio/builder/scripts/frameworks/spl.py b/platformio/builder/scripts/frameworks/spl.py index fb7abbbb..130d8bf2 100644 --- a/platformio/builder/scripts/frameworks/spl.py +++ b/platformio/builder/scripts/frameworks/spl.py @@ -22,7 +22,7 @@ env.Replace( PLATFORMFW_DIR=join("$PIOPACKAGES_DIR", "framework-spl") ) -env.VariantDir( +env.VariantDirWrap( join("$BUILD_DIR", "FrameworkSPLInc"), join("$PLATFORMFW_DIR", "${BOARD_OPTIONS['build']['core']}", "variants", "${BOARD_OPTIONS['build']['variant']}", "inc") @@ -55,6 +55,8 @@ extra_flags = env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags") ignore_files = [] if "STM32F40_41xxx" in extra_flags: ignore_files += ["stm32f4xx_fmc.c"] +if "STM32F427_437xx" in extra_flags: + ignore_files += ["stm32f4xx_fsmc.c"] elif "STM32F303xC" in extra_flags: ignore_files += ["stm32f30x_hrtim.c"] elif "STM32L1XX_MD" in extra_flags: diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index a3566291..656473b7 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -2,11 +2,13 @@ # See LICENSE for details. import atexit +import json import re from os import getenv, listdir, remove, sep, walk from os.path import basename, dirname, isdir, isfile, join, normpath -from SCons.Script import Exit, SConscript, SConscriptChdir +from SCons.Script import (COMMAND_LINE_TARGETS, DefaultEnvironment, Exit, + SConscript, SConscriptChdir) from SCons.Util import case_sensitive_suffixes from platformio.util import pioversion_to_intstr @@ -26,7 +28,7 @@ def BuildFirmware(env): firmenv = env.Clone() vdirs = firmenv.VariantDirRecursive( - join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR") + join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR", duplicate=False) # build dependent libs deplibs = firmenv.BuildDependentLibraries("$PROJECTSRC_DIR") @@ -55,6 +57,19 @@ def BuildFirmware(env): *pioversion_to_intstr())] ) + if "envdump" in COMMAND_LINE_TARGETS: + print env.Dump() + Exit() + + if "idedata" in COMMAND_LINE_TARGETS: + _data = {"defines": [], "includes": []} + for item in env.get("VARIANT_DIRS", []): + _data['includes'].append(env.subst(item[1])) + for item in env.get("CPPDEFINES", []): + _data['defines'].append(env.subst(item)) + print json.dumps(_data) + Exit() + return firmenv.Program( join("$BUILD_DIR", "firmware"), [firmenv.GlobCXXFiles(vdir) for vdir in vdirs], @@ -89,6 +104,11 @@ def GlobCXXFiles(env, path): return files +def VariantDirWrap(env, variant_dir, src_dir, duplicate=True): + DefaultEnvironment().Append(VARIANT_DIRS=[(variant_dir, src_dir)]) + env.VariantDir(variant_dir, src_dir, duplicate) + + def VariantDirRecursive(env, variant_dir, src_dir, duplicate=True, ignore_pattern=None): if not ignore_pattern: @@ -100,7 +120,7 @@ def VariantDirRecursive(env, variant_dir, src_dir, duplicate=True, _var_dir = variant_dir + root.replace(src_dir, "") if any([s in _var_dir.lower() for s in ignore_pattern]): continue - env.VariantDir(_var_dir, _src_dir, duplicate) + env.VariantDirWrap(_var_dir, _src_dir, duplicate) variants.append(_var_dir) return variants @@ -142,9 +162,11 @@ def BuildLibrary(env, variant_dir, library_dir, ignore_files=None): def BuildDependentLibraries(env, src_dir): # pylint: disable=R0914 - INCLUDES_RE = re.compile(r"^\s*#include\s+(\<|\")([^\>\"\']+)(?:\>|\")", - re.M) + INCLUDES_RE = re.compile( + r"^\s*#include\s+(\<|\")([^\>\"\']+)(?:\>|\")", re.M) LIBSOURCE_DIRS = [env.subst(d) for d in env.get("LIBSOURCE_DIRS", [])] + USE_LIBS = [l.strip() for l in env.get("USE_LIBS", "").split(",") + if l.strip()] # start internal prototypes @@ -185,7 +207,10 @@ def BuildDependentLibraries(env, src_dir): # pylint: disable=R0914 if not isdir(lsd_dir): continue - for ld in listdir(lsd_dir): + for ld in USE_LIBS + listdir(lsd_dir): + if not isdir(join(lsd_dir, ld)): + continue + inc_path = normpath(join(lsd_dir, ld, self.name)) try: lib_dir = inc_path[:inc_path.index( @@ -216,6 +241,7 @@ def BuildDependentLibraries(env, src_dir): # pylint: disable=R0914 "libs": set(), "ordered": set() } + state = _process_src_dir(state, env.subst(src_dir)) result = [] @@ -371,7 +397,7 @@ def ConvertInoToCpp(env): if not data: return - tmpcpp_file = join(env.subst("$PROJECTSRC_DIR"), "piomain.cpp") + tmpcpp_file = join(env.subst("$PROJECTSRC_DIR"), "tmp_ino_to.cpp") with open(tmpcpp_file, "w") as f: f.write(data) @@ -386,6 +412,7 @@ def generate(env): env.AddMethod(BuildFirmware) env.AddMethod(ProcessFlags) env.AddMethod(GlobCXXFiles) + env.AddMethod(VariantDirWrap) env.AddMethod(VariantDirRecursive) env.AddMethod(BuildFramework) env.AddMethod(BuildLibrary) diff --git a/platformio/commands/boards.py b/platformio/commands/boards.py index 1bb89f21..0681623a 100644 --- a/platformio/commands/boards.py +++ b/platformio/commands/boards.py @@ -18,6 +18,7 @@ def cli(query, json_output): # pylint: disable=R0912 BOARDLIST_TPL = ("{type:<30} {mcu:<14} {frequency:<8} " " {flash:<7} {ram:<6} {name}") + terminal_width, _ = click.get_terminal_size() grpboards = {} for type_, data in get_boards().items(): @@ -31,12 +32,14 @@ def cli(query, json_output): # pylint: disable=R0912 if query.lower() not in search_data.lower(): continue - click.echo("\nPlatform: %s" % platform) - click.echo("-" * 75) + click.echo("") + click.echo("Platform: ", nl=False) + click.secho(platform, bold=True) + click.echo("-" * terminal_width) click.echo(BOARDLIST_TPL.format( type=click.style("Type", fg="cyan"), mcu="MCU", frequency="Frequency", flash="Flash", ram="RAM", name="Name")) - click.echo("-" * 75) + click.echo("-" * terminal_width) for type_, data in sorted(boards.items(), key=lambda b: b[1]['name']): if query: diff --git a/platformio/commands/ci.py b/platformio/commands/ci.py new file mode 100644 index 00000000..e4b48e07 --- /dev/null +++ b/platformio/commands/ci.py @@ -0,0 +1,146 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +import stat +from glob import glob +from os import chmod, environ, makedirs, remove +from os.path import abspath, basename, isdir, isfile, join +from shutil import copyfile, copytree, rmtree +from tempfile import mkdtemp + +import click + +from platformio import app +from platformio.commands.init import cli as cmd_init +from platformio.commands.run import cli as cmd_run +from platformio.exception import CIBuildEnvsEmpty +from platformio.util import get_boards + + +def validate_path(ctx, param, value): # pylint: disable=W0613 + invalid_path = None + for p in value: + if not glob(p): + invalid_path = p + break + try: + assert invalid_path is None + return value + except AssertionError: + raise click.BadParameter("Found invalid path: %s" % invalid_path) + + +def validate_boards(ctx, param, value): # pylint: disable=W0613 + unknown_boards = set(value) - set(get_boards().keys()) + try: + assert not unknown_boards + return value + except AssertionError: + raise click.BadParameter( + "%s. Please search for the board types using " + "`platformio boards` command" % ", ".join(unknown_boards)) + + +@click.command("ci", short_help="Continuous Integration") +@click.argument("src", nargs=-1, callback=validate_path) +@click.option("--lib", "-l", multiple=True, callback=validate_path) +@click.option("--exclude", multiple=True) +@click.option("--board", "-b", multiple=True, callback=validate_boards) +@click.option("--build-dir", default=mkdtemp, + type=click.Path(exists=True, file_okay=False, dir_okay=True, + writable=True, resolve_path=True)) +@click.option("--keep-build-dir", is_flag=True) +@click.option("--project-conf", + type=click.Path(exists=True, file_okay=True, dir_okay=False, + readable=True, resolve_path=True)) +@click.option("--verbose", "-v", count=True, default=3) +@click.pass_context +def cli(ctx, src, lib, exclude, board, # pylint: disable=R0913 + build_dir, keep_build_dir, project_conf, verbose): + + if not src: + src = environ.get("PLATFORMIO_CI_SRC", "").split(":") + if not src: + raise click.BadParameter("Missing argument 'src'") + + try: + app.set_session_var("force_option", True) + _clean_dir(build_dir) + + for dir_name, patterns in dict(lib=lib, src=src).iteritems(): + if not patterns: + continue + contents = [] + for p in patterns: + contents += glob(p) + _copy_contents(join(build_dir, dir_name), contents) + + if project_conf and isfile(project_conf): + copyfile(project_conf, join(build_dir, "platformio.ini")) + elif not board: + raise CIBuildEnvsEmpty() + + if exclude: + _exclude_contents(build_dir, exclude) + + # initialise project + ctx.invoke(cmd_init, project_dir=build_dir, board=board, + disable_auto_uploading=True) + + # process project + ctx.invoke(cmd_run, project_dir=build_dir, verbose=verbose) + finally: + if not keep_build_dir: + rmtree( + build_dir, onerror=lambda action, name, exc: + (chmod(name, stat.S_IWRITE), remove(name)) + ) + + +def _clean_dir(dirpath): + rmtree(dirpath) + makedirs(dirpath) + + +def _copy_contents(dst_dir, contents): + items = { + "dirs": set(), + "files": set() + } + + for path in contents: + path = abspath(path) + if isdir(path): + items['dirs'].add(path) + elif isfile(path): + items['files'].add(path) + + dst_dir_name = basename(dst_dir) + + if dst_dir_name == "src" and len(items['dirs']) == 1: + copytree(list(items['dirs']).pop(), dst_dir) + else: + makedirs(dst_dir) + for d in items['dirs']: + copytree(d, join(dst_dir, basename(d))) + + if not items['files']: + return + + if dst_dir_name == "lib": + dst_dir = join(dst_dir, mkdtemp(dir=dst_dir)) + + for f in items['files']: + copyfile(f, join(dst_dir, basename(f))) + + +def _exclude_contents(dst_dir, patterns): + contents = [] + for p in patterns: + contents += glob(join(dst_dir, p)) + for path in contents: + path = abspath(path) + if isdir(path): + rmtree(path) + elif isfile(path): + remove(path) diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 1c32ecca..4799d5fc 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -8,46 +8,53 @@ from shutil import copyfile import click from platformio import app, exception +from platformio.ide.projectgenerator import ProjectGenerator from platformio.util import get_boards, get_source_dir +def validate_boards(ctx, param, value): # pylint: disable=W0613 + unknown_boards = set(value) - set(get_boards().keys()) + try: + assert not unknown_boards + return value + except AssertionError: + raise click.BadParameter( + "%s. Please search for the board types using " + "`platformio boards` command" % ", ".join(unknown_boards)) + + @click.command("init", short_help="Initialize new PlatformIO based project") @click.option("--project-dir", "-d", default=getcwd, type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True)) -@click.option("--board", "-b", multiple=True, metavar="TYPE") +@click.option("--board", "-b", multiple=True, metavar="TYPE", + callback=validate_boards) +@click.option("--ide", + type=click.Choice(ProjectGenerator.get_supported_ides())) @click.option("--disable-auto-uploading", is_flag=True) -def cli(project_dir, board, disable_auto_uploading): - - project_file = join(project_dir, "platformio.ini") - src_dir = join(project_dir, "src") - lib_dir = join(project_dir, "lib") - if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): - raise exception.ProjectInitialized() - - builtin_boards = set(get_boards().keys()) - if board and not set(board).issubset(builtin_boards): - raise exception.UnknownBoard( - ", ".join(set(board).difference(builtin_boards))) +@click.option("--env-prefix", default="") +def cli(project_dir, board, ide, disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( - "\nWould you like to enable firmware auto-uploading when project " + "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("") if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( - "will be used for the new project.\n" + "will be used for project.\n" "You can specify another project directory via\n" - "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", + "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow" ) + click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) @@ -58,51 +65,75 @@ def cli(project_dir, board, disable_auto_uploading): click.echo("%s - Put here project specific or 3-rd party libraries" % click.style("lib", fg="cyan")) - if (not app.get_setting("enable_prompts") or - click.confirm("Do you want to continue?")): - - for d in (src_dir, lib_dir): - if not isdir(d): - makedirs(d) - if not isfile(project_file): - copyfile(join(get_source_dir(), "projectconftpl.ini"), - project_file) - if board: - fill_project_envs(project_file, board, disable_auto_uploading) - click.secho( - "Project 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" - ) - else: + if (app.get_setting("enable_prompts") and + not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() + project_file = join(project_dir, "platformio.ini") + src_dir = join(project_dir, "src") + lib_dir = join(project_dir, "lib") -def fill_project_envs(project_file, board_types, disable_auto_uploading): + for d in (src_dir, lib_dir): + if not isdir(d): + makedirs(d) + + if not isfile(project_file): + copyfile(join(get_source_dir(), "projectconftpl.ini"), + project_file) + + if board: + fill_project_envs( + project_file, board, disable_auto_uploading, env_prefix) + + if ide: + pg = ProjectGenerator(project_dir, ide) + 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(project_file, board_types, disable_auto_uploading, + env_prefix): builtin_boards = get_boards() content = [] - for type_ in board_types: - if type_ not in builtin_boards: - continue - else: - content.append("") + used_envs = [] + 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_] + 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") - content.append("[env:autogen_%s]" % type_) - content.append("platform = %s" % data['platform']) if frameworks: content.append("framework = %s" % frameworks[0]) - content.append("board = %s" % type_) + content.append("board = %s" % type_) content.append("%stargets = upload" % ("# " if disable_auto_uploading else "")) + if not content: + return + with open(project_file, "a") as f: + content.append("") f.write("\n".join(content)) diff --git a/platformio/commands/install.py b/platformio/commands/install.py deleted file mode 100644 index af476f43..00000000 --- a/platformio/commands/install.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import click - -from platformio.platforms.base import PlatformFactory - - -@click.command("install", short_help="Install new platforms") -@click.argument("platforms", nargs=-1) -@click.option("--with-package", multiple=True, metavar="") -@click.option("--without-package", multiple=True, metavar="") -@click.option("--skip-default-package", is_flag=True) -def cli(platforms, with_package, without_package, skip_default_package): - - for platform in platforms: - p = PlatformFactory.newPlatform(platform) - if p.install(with_package, without_package, skip_default_package): - click.secho("The platform '%s' has been successfully installed!" % - platform, fg="green") diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index 91c8dced..7bf31383 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -7,7 +7,7 @@ import click from platformio import app, exception from platformio.libmanager import LibraryManager -from platformio.util import get_api_result, get_lib_dir +from platformio.util import get_api_result LIBLIST_TPL = ("[{id:^14}] {name:<25} {compatibility:<30} " "\"{authornames}\": {description}") @@ -21,7 +21,9 @@ def echo_liblist_header(): authornames="Authors", description="Description" )) - click.echo("-" * 85) + + terminal_width, _ = click.get_terminal_size() + click.echo("-" * terminal_width) def echo_liblist_item(item): @@ -98,7 +100,7 @@ def lib_search(query, **filters): @click.option("-v", "--version") @click.pass_context def lib_install(ctx, libid, version): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() for id_ in libid: click.echo( "Installing library [ %s ]:" % click.style(str(id_), fg="green")) @@ -147,7 +149,7 @@ def lib_install_dependency(ctx, data): @cli.command("uninstall", short_help="Uninstall libraries") @click.argument("libid", type=click.INT, nargs=-1) def lib_uninstall(libid): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() for id_ in libid: info = lm.get_info(id_) if lm.uninstall(id_): @@ -158,7 +160,7 @@ def lib_uninstall(libid): @cli.command("list", short_help="List installed libraries") @click.option("--json-output", is_flag=True) def lib_list(json_output): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() items = lm.get_installed().values() if json_output: @@ -177,7 +179,7 @@ def lib_list(json_output): @cli.command("show", short_help="Show details about installed library") @click.argument("libid", type=click.INT) def lib_show(libid): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() info = lm.get_info(libid) click.secho(info['name'], fg="cyan") click.echo("-" * len(info['name'])) @@ -209,13 +211,18 @@ def lib_show(libid): @cli.command("update", short_help="Update installed libraries") +@click.argument("libid", type=click.INT, nargs=-1, required=False, + metavar="[LIBRARY_ID]") @click.pass_context -def lib_update(ctx): - lm = LibraryManager(get_lib_dir()) +def lib_update(ctx, libid): + lm = LibraryManager() for id_, latest_version in (lm.get_latest_versions() or {}).items(): + if libid and int(id_) not in libid: + continue + info = lm.get_info(int(id_)) - click.echo("Updating [ %s ] %s library:" % ( + click.echo("Updating [ %s ] %s library:" % ( click.style(id_, fg="yellow"), click.style(info['name'], fg="cyan"))) diff --git a/platformio/commands/list.py b/platformio/commands/list.py deleted file mode 100644 index c47a95b8..00000000 --- a/platformio/commands/list.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import json - -import click - -from platformio.platforms.base import PlatformFactory - - -@click.command("list", short_help="List installed platforms") -@click.option("--json-output", is_flag=True) -def cli(json_output): - - installed_platforms = PlatformFactory.get_platforms( - installed=True).keys() - installed_platforms.sort() - - data = [] - for platform in installed_platforms: - p = PlatformFactory.newPlatform(platform) - data.append({ - "name": platform, - "packages": p.get_installed_packages() - }) - - if json_output: - click.echo(json.dumps(data)) - else: - for item in data: - click.echo("{name:<20} with packages: {pkgs}".format( - name=click.style(item['name'], fg="cyan"), - pkgs=", ".join(item['packages']) - )) diff --git a/platformio/commands/platforms.py b/platformio/commands/platforms.py new file mode 100644 index 00000000..bdfae393 --- /dev/null +++ b/platformio/commands/platforms.py @@ -0,0 +1,155 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +import json +from datetime import datetime + +import click + +from platformio import app +from platformio.exception import PlatformNotInstalledYet +from platformio.pkgmanager import PackageManager +from platformio.platforms.base import PlatformFactory + + +@click.group(short_help="Platforms and Packages Manager") +def cli(): + pass + + +@cli.command("install", short_help="Install new platforms") +@click.argument("platforms", nargs=-1, required=True) +@click.option("--with-package", multiple=True, metavar="") +@click.option("--without-package", multiple=True, metavar="") +@click.option("--skip-default-package", is_flag=True) +def platforms_install(platforms, with_package, without_package, + skip_default_package): + for platform in platforms: + p = PlatformFactory.newPlatform(platform) + if p.install(with_package, without_package, skip_default_package): + click.secho("The platform '%s' has been successfully installed!" % + platform, fg="green") + + +@cli.command("list", short_help="List installed platforms") +@click.option("--json-output", is_flag=True) +def platforms_list(json_output): + + installed_platforms = PlatformFactory.get_platforms( + installed=True).keys() + installed_platforms.sort() + + data = [] + for platform in installed_platforms: + p = PlatformFactory.newPlatform(platform) + data.append({ + "name": platform, + "packages": p.get_installed_packages() + }) + + if json_output: + click.echo(json.dumps(data)) + else: + for item in data: + click.echo("{name:<20} with packages: {pkgs}".format( + name=click.style(item['name'], fg="cyan"), + pkgs=", ".join(item['packages']) + )) + + +@cli.command("search", short_help="Search for development platforms") +@click.argument("query", required=False) +@click.option("--json-output", is_flag=True) +def platforms_search(query, json_output): + + data = [] + platforms = PlatformFactory.get_platforms().keys() + platforms.sort() + for platform in platforms: + p = PlatformFactory.newPlatform(platform) + type_ = p.get_type() + description = p.get_description() + + if query == "all": + query = "" + + search_data = "%s %s %s" % (type_, description, p.get_packages()) + if query and query.lower() not in search_data.lower(): + continue + + data.append({ + "type": type_, + "description": description, + "packages": p.get_packages() + }) + + if json_output: + click.echo(json.dumps(data)) + else: + terminal_width, _ = click.get_terminal_size() + for item in data: + click.secho(item['type'], fg="cyan", nl=False) + click.echo(" (available packages: %s)" % ", ".join( + item.get("packages").keys())) + click.echo("-" * terminal_width) + click.echo(item['description']) + click.echo() + + +@cli.command("show", short_help="Show details about installed platform") +@click.argument("platform") +@click.pass_context +def platforms_show(ctx, platform): + + installed_platforms = PlatformFactory.get_platforms( + installed=True).keys() + + if platform not in installed_platforms: + if (not app.get_setting("enable_prompts") or + click.confirm("The platform '%s' has not been installed yet. " + "Would you like to install it now?" % platform)): + ctx.invoke(platforms_install, platforms=[platform]) + else: + raise PlatformNotInstalledYet(platform) + + p = PlatformFactory.newPlatform(platform) + click.echo("{name:<20} - {description} [ {url} ]".format( + name=click.style(p.get_type(), fg="cyan"), + description=p.get_description(), url=p.get_vendor_url())) + + installed_packages = PackageManager.get_installed() + for name in p.get_installed_packages(): + data = installed_packages[name] + pkgalias = p.get_pkg_alias(name) + click.echo("----------") + click.echo("Package: %s" % click.style(name, fg="yellow")) + if pkgalias: + click.echo("Alias: %s" % pkgalias) + click.echo("Version: %d" % int(data['version'])) + click.echo("Installed: %s" % datetime.fromtimestamp( + data['time']).strftime("%Y-%m-%d %H:%M:%S")) + + +@cli.command("uninstall", short_help="Uninstall platforms") +@click.argument("platforms", nargs=-1, required=True) +def platforms_uninstall(platforms): + + for platform in platforms: + p = PlatformFactory.newPlatform(platform) + if p.uninstall(): + click.secho("The platform '%s' has been successfully " + "uninstalled!" % platform, fg="green") + + +@cli.command("update", short_help="Update installed Platforms and Packages") +def platforms_update(): + + installed_platforms = PlatformFactory.get_platforms( + installed=True).keys() + installed_platforms.sort() + + for platform in installed_platforms: + click.echo("\nPlatform %s" % click.style(platform, fg="cyan")) + click.echo("--------") + p = PlatformFactory.newPlatform(platform) + p.update() diff --git a/platformio/commands/run.py b/platformio/commands/run.py index d4c5bd8a..b61544ba 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -2,6 +2,7 @@ # See LICENSE for details. from datetime import datetime +from os import chdir, getcwd from os.path import getmtime, isdir, join from shutil import rmtree from time import time @@ -9,7 +10,10 @@ from time import time import click from platformio import app, exception, telemetry, util -from platformio.commands.install import cli as cmd_install +from platformio.commands.lib import lib_install as cmd_lib_install +from platformio.commands.platforms import \ + platforms_install as cmd_platforms_install +from platformio.libmanager import LibraryManager from platformio.platforms.base import PlatformFactory @@ -17,110 +21,162 @@ from platformio.platforms.base import PlatformFactory @click.option("--environment", "-e", multiple=True, metavar="") @click.option("--target", "-t", multiple=True, metavar="") @click.option("--upload-port", metavar="") +@click.option("--project-dir", default=getcwd, + type=click.Path(exists=True, file_okay=False, dir_okay=True, + writable=True, resolve_path=True)) +@click.option("--verbose", "-v", count=True, default=3) @click.pass_context -def cli(ctx, environment, target, upload_port): +def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914 + project_dir, verbose): + initial_cwd = getcwd() + chdir(project_dir) + try: + config = util.get_project_config() - config = util.get_project_config() + if not config.sections(): + raise exception.ProjectEnvsNotAvailable() - if not config.sections(): - raise exception.ProjectEnvsNotAvailable() + unknown = set(environment) - set([s[4:] for s in config.sections()]) + if unknown: + raise exception.UnknownEnvNames(", ".join(unknown)) - unknown = set(environment) - set([s[4:] for s in config.sections()]) - if unknown: - raise exception.UnknownEnvNames(", ".join(unknown)) + # remove ".pioenvs" if project config is modified + _pioenvs_dir = util.get_pioenvs_dir() + if (isdir(_pioenvs_dir) and + getmtime(join(util.get_project_dir(), "platformio.ini")) > + getmtime(_pioenvs_dir)): + rmtree(_pioenvs_dir) - # remove ".pioenvs" if project config is modified - _pioenvs_dir = util.get_pioenvs_dir() - if (isdir(_pioenvs_dir) and - getmtime(join(util.get_project_dir(), "platformio.ini")) > - getmtime(_pioenvs_dir)): - rmtree(_pioenvs_dir) + results = [] + for section in config.sections(): + # skip main configuration section + if section == "platformio": + continue - found_error = False - _first_done = False - for section in config.sections(): - # skip main configuration section - if section == "platformio": - continue - elif section[:4] != "env:": - raise exception.InvalidEnvName(section) + if not section.startswith("env:"): + raise exception.InvalidEnvName(section) - envname = section[4:] - if environment and envname not in environment: - # echo("Skipped %s environment" % style(envname, fg="yellow")) - continue + envname = section[4:] + if environment and envname not in environment: + # echo("Skipped %s environment" % style(envname, fg="yellow")) + continue - options = {} - for k, v in config.items(section): - options[k] = v + if results: + click.echo() - if _first_done: - click.echo() + options = {} + for k, v in config.items(section): + options[k] = v - if not process_environment(ctx, envname, options, target, upload_port): - found_error = True - _first_done = True + ep = EnvironmentProcessor( + ctx, envname, options, target, upload_port, verbose) + results.append(ep.process()) - if found_error: - raise exception.ReturnErrorCode() + if not all(results): + raise exception.ReturnErrorCode() + finally: + chdir(initial_cwd) -def process_environment(ctx, name, options, targets, upload_port): - terminal_width, _ = click.get_terminal_size() - start_time = time() +class EnvironmentProcessor(object): - click.echo("[%s] Processing %s (%s)" % ( - datetime.now().strftime("%c"), - click.style(name, fg="cyan", bold=True), - ", ".join(["%s: %s" % (k, v) for k, v in options.iteritems()]) - )) - click.secho("-" * terminal_width, bold=True) + def __init__(self, cmd_ctx, name, options, # pylint: disable=R0913 + targets, upload_port, verbose): + self.cmd_ctx = cmd_ctx + self.name = name + self.options = options + self.targets = targets + self.upload_port = upload_port + self.verbose_level = int(verbose) - result = _run_environment(ctx, name, options, targets, upload_port) + def process(self): + terminal_width, _ = click.get_terminal_size() + start_time = time() - is_error = result['returncode'] != 0 - summary_text = " Took %.2f seconds " % (time() - start_time) - half_line = "=" * ((terminal_width - len(summary_text) - 10) / 2) - click.echo("%s [%s]%s%s" % ( - half_line, - (click.style(" ERROR ", fg="red", bold=True) - if is_error else click.style("SUCCESS", fg="green", bold=True)), - summary_text, - half_line - ), err=is_error) + click.echo("[%s] Processing %s (%s)" % ( + datetime.now().strftime("%c"), + click.style(self.name, fg="cyan", bold=True), + ", ".join(["%s: %s" % (k, v) for k, v in self.options.iteritems()]) + )) + click.secho("-" * terminal_width, bold=True) - return not is_error + result = self._run() + + is_error = result['returncode'] != 0 + summary_text = " Took %.2f seconds " % (time() - start_time) + half_line = "=" * ((terminal_width - len(summary_text) - 10) / 2) + click.echo("%s [%s]%s%s" % ( + half_line, + (click.style(" ERROR ", fg="red", bold=True) + if is_error else click.style("SUCCESS", fg="green", bold=True)), + summary_text, + half_line + ), err=is_error) + + return not is_error + + def _get_build_variables(self): + variables = ["PIOENV=" + self.name] + if self.upload_port: + variables.append("UPLOAD_PORT=%s" % self.upload_port) + for k, v in self.options.items(): + k = k.upper() + if k == "TARGETS" or (k == "UPLOAD_PORT" and self.upload_port): + continue + variables.append("%s=%s" % (k.upper(), v)) + return variables + + def _get_build_targets(self): + targets = [] + if self.targets: + targets = [t for t in self.targets] + elif "targets" in self.options: + targets = self.options['targets'].split() + return targets + + def _run(self): + if "platform" not in self.options: + raise exception.UndefinedEnvPlatform(self.name) + + platform = self.options['platform'] + build_vars = self._get_build_variables() + build_targets = self._get_build_targets() + + telemetry.on_run_environment(self.options, build_targets) + + # install platform and libs dependencies + _autoinstall_platform(self.cmd_ctx, platform) + if "install_libs" in self.options: + _autoinstall_libs(self.cmd_ctx, self.options['install_libs']) + + p = PlatformFactory.newPlatform(platform) + return p.run(build_vars, build_targets, self.verbose_level) -def _run_environment(ctx, name, options, targets, upload_port): - variables = ["PIOENV=" + name] - if upload_port: - variables.append("UPLOAD_PORT=%s" % upload_port) - for k, v in options.items(): - k = k.upper() - if k == "TARGETS" or (k == "UPLOAD_PORT" and upload_port): - continue - variables.append("%s=%s" % (k.upper(), v)) - - envtargets = [] - if targets: - envtargets = [t for t in targets] - elif "targets" in options: - envtargets = options['targets'].split() - - if "platform" not in options: - raise exception.UndefinedEnvPlatform(name) - platform = options['platform'] - - telemetry.on_run_environment(options, envtargets) - +def _autoinstall_platform(ctx, platform): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if (platform not in installed_platforms and ( not app.get_setting("enable_prompts") or click.confirm("The platform '%s' has not been installed yet. " "Would you like to install it now?" % platform))): - ctx.invoke(cmd_install, platforms=[platform]) + ctx.invoke(cmd_platforms_install, platforms=[platform]) - p = PlatformFactory.newPlatform(platform) - return p.run(variables, envtargets) + +def _autoinstall_libs(ctx, libids_list): + require_libs = [int(l.strip()) for l in libids_list.split(",")] + installed_libs = [ + l['id'] for l in LibraryManager().get_installed().values() + ] + + not_intalled_libs = set(require_libs) - set(installed_libs) + if not require_libs or not not_intalled_libs: + return + + if (not app.get_setting("enable_prompts") or + click.confirm( + "The libraries with IDs '%s' have not been installed yet. " + "Would you like to install them now?" % + ", ".join([str(i) for i in not_intalled_libs]) + )): + ctx.invoke(cmd_lib_install, libid=not_intalled_libs) diff --git a/platformio/commands/search.py b/platformio/commands/search.py deleted file mode 100644 index 4d9e1cc6..00000000 --- a/platformio/commands/search.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import json - -import click - -from platformio.platforms.base import PlatformFactory - - -@click.command("search", short_help="Search for development platforms") -@click.argument("query", required=False) -@click.option("--json-output", is_flag=True) -def cli(query, json_output): - - data = [] - platforms = PlatformFactory.get_platforms().keys() - platforms.sort() - for platform in platforms: - p = PlatformFactory.newPlatform(platform) - type_ = p.get_type() - description = p.get_description() - - if query == "all": - query = "" - - search_data = "%s %s %s" % (type_, description, p.get_packages()) - if query and query.lower() not in search_data.lower(): - continue - - data.append({ - "type": type_, - "description": description, - "packages": p.get_packages() - }) - - if json_output: - click.echo(json.dumps(data)) - else: - for item in data: - click.secho(item['type'], fg="cyan", nl=False) - click.echo(" (available packages: %s)" % ", ".join( - item.get("packages").keys())) - click.secho("-" * len(item['type']), fg="cyan") - click.echo(item['description']) - click.echo() diff --git a/platformio/commands/serialports.py b/platformio/commands/serialports.py index c52f27da..5c241d03 100644 --- a/platformio/commands/serialports.py +++ b/platformio/commands/serialports.py @@ -25,7 +25,7 @@ def serialports_list(json_output): for item in get_serialports(): click.secho(item['port'], fg="cyan") - click.echo("----------") + click.echo("-" * len(item['port'])) click.echo("Hardware ID: %s" % item['hwid']) click.echo("Description: %s" % item['description']) click.echo("") diff --git a/platformio/commands/settings.py b/platformio/commands/settings.py index f239559f..e600e197 100644 --- a/platformio/commands/settings.py +++ b/platformio/commands/settings.py @@ -16,6 +16,7 @@ def cli(): def settings_get(name): list_tpl = "{name:<40} {value:<35} {description}" + terminal_width, _ = click.get_terminal_size() click.echo(list_tpl.format( name=click.style("Name", fg="cyan"), @@ -23,7 +24,7 @@ def settings_get(name): click.style(" [Default]", fg="yellow")), description="Description" )) - click.echo("-" * 90) + click.echo("-" * terminal_width) for _name, _data in sorted(app.DEFAULT_SETTINGS.items()): if name and name != _name: diff --git a/platformio/commands/show.py b/platformio/commands/show.py deleted file mode 100644 index f0913ff9..00000000 --- a/platformio/commands/show.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -from datetime import datetime - -import click - -from platformio import app -from platformio.commands.install import cli as cmd_install -from platformio.exception import PlatformNotInstalledYet -from platformio.pkgmanager import PackageManager -from platformio.platforms.base import PlatformFactory - - -@click.command("show", short_help="Show details about installed platform") -@click.argument("platform") -@click.pass_context -def cli(ctx, platform): - - installed_platforms = PlatformFactory.get_platforms( - installed=True).keys() - - if platform not in installed_platforms: - if (not app.get_setting("enable_prompts") or - click.confirm("The platform '%s' has not been installed yet. " - "Would you like to install it now?" % platform)): - ctx.invoke(cmd_install, platforms=[platform]) - else: - raise PlatformNotInstalledYet(platform) - - p = PlatformFactory.newPlatform(platform) - click.echo("{name:<20} - {description} [ {url} ]".format( - name=click.style(p.get_type(), fg="cyan"), - description=p.get_description(), url=p.get_vendor_url())) - - installed_packages = PackageManager.get_installed() - for name in p.get_installed_packages(): - data = installed_packages[name] - pkgalias = p.get_pkg_alias(name) - click.echo("----------") - click.echo("Package: %s" % click.style(name, fg="yellow")) - if pkgalias: - click.echo("Alias: %s" % pkgalias) - click.echo("Version: %d" % int(data['version'])) - click.echo("Installed: %s" % datetime.fromtimestamp( - data['time']).strftime("%Y-%m-%d %H:%M:%S")) diff --git a/platformio/commands/uninstall.py b/platformio/commands/uninstall.py deleted file mode 100644 index a14569e2..00000000 --- a/platformio/commands/uninstall.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import click - -from platformio.platforms.base import PlatformFactory - - -@click.command("uninstall", short_help="Uninstall platforms") -@click.argument("platforms", nargs=-1) -def cli(platforms): - - for platform in platforms: - p = PlatformFactory.newPlatform(platform) - if p.uninstall(): - click.secho("The platform '%s' has been successfully " - "uninstalled!" % platform, fg="green") diff --git a/platformio/commands/update.py b/platformio/commands/update.py index 9091e31e..8afdc5ed 100644 --- a/platformio/commands/update.py +++ b/platformio/commands/update.py @@ -3,18 +3,14 @@ import click -from platformio.platforms.base import PlatformFactory +from platformio.commands.lib import lib_update as cmd_lib_update +from platformio.commands.platforms import \ + platforms_update as cmd_platforms_update -@click.command("update", short_help="Update installed platforms") -def cli(): - - installed_platforms = PlatformFactory.get_platforms( - installed=True).keys() - installed_platforms.sort() - - for platform in installed_platforms: - click.echo("\nPlatform %s" % click.style(platform, fg="cyan")) - click.echo("--------") - p = PlatformFactory.newPlatform(platform) - p.update() +@click.command("update", + short_help="Update installed Platforms, Packages and Libraries") +@click.pass_context +def cli(ctx): + ctx.invoke(cmd_platforms_update) + ctx.invoke(cmd_lib_update) diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py index 7e57579e..263401de 100644 --- a/platformio/commands/upgrade.py +++ b/platformio/commands/upgrade.py @@ -4,9 +4,8 @@ import click import requests -from platformio import __version__ +from platformio import __version__, util from platformio.exception import GetLatestVersionError -from platformio.util import exec_command @click.command("upgrade", @@ -22,9 +21,9 @@ def cli(): click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") - pip_result = exec_command(["pip", "install", "--upgrade", - "platformio"]) - pio_result = exec_command(["platformio", "--version"]) + pip_result = util.exec_command(["pip", "install", "--upgrade", + "platformio"]) + pio_result = util.exec_command(["platformio", "--version"]) if last in pio_result['out'].strip(): click.secho("PlatformIO has been successfully upgraded to %s" % @@ -37,7 +36,9 @@ def cli(): def get_latest_version(): try: pkgdata = requests.get( - "https://pypi.python.org/pypi/platformio/json").json() + "https://pypi.python.org/pypi/platformio/json", + headers=util.get_request_defheaders() + ).json() return pkgdata['info']['version'] except: raise GetLatestVersionError() diff --git a/platformio/downloader.py b/platformio/downloader.py index df9f5b64..7520446d 100644 --- a/platformio/downloader.py +++ b/platformio/downloader.py @@ -3,15 +3,16 @@ from email.utils import parsedate_tz from math import ceil +from os import environ from os.path import getsize, join from time import mktime -from click import progressbar -from requests import get +import click +import requests +from platformio import util from platformio.exception import (FDSHASumMismatch, FDSizeMismatch, FDUnrecognizedStatusCode) -from platformio.util import change_filemtime, exec_command class FileDownloader(object): @@ -27,7 +28,8 @@ class FileDownloader(object): self.set_destination(join(dest_dir, self._fname)) self._progressbar = None - self._request = get(url, stream=True) + self._request = requests.get(url, stream=True, + headers=util.get_request_defheaders()) if self._request.status_code != 200: raise FDUnrecognizedStatusCode(self._request.status_code, url) @@ -48,9 +50,14 @@ class FileDownloader(object): f = open(self._destination, "wb") chunks = int(ceil(self.get_size() / float(self.CHUNK_SIZE))) - with progressbar(length=chunks, label="Downloading") as pb: - for _ in pb: + if environ.get("CI") == "true": + click.echo("Downloading...") + for _ in range(0, chunks): f.write(next(itercontent)) + else: + with click.progressbar(length=chunks, label="Downloading") as pb: + for _ in pb: + f.write(next(itercontent)) f.close() self._request.close() @@ -66,11 +73,12 @@ class FileDownloader(object): dlsha1 = None try: - result = exec_command(["sha1sum", self._destination]) + result = util.exec_command(["sha1sum", self._destination]) dlsha1 = result['out'] except OSError: try: - result = exec_command(["shasum", "-a", "1", self._destination]) + result = util.exec_command( + ["shasum", "-a", "1", self._destination]) dlsha1 = result['out'] except OSError: pass @@ -83,7 +91,7 @@ class FileDownloader(object): def _preserve_filemtime(self, lmdate): timedata = parsedate_tz(lmdate) lmtime = mktime(timedata[:9]) - change_filemtime(self._destination, lmtime) + util.change_filemtime(self._destination, lmtime) def __del__(self): self._request.close() diff --git a/platformio/exception.py b/platformio/exception.py index 451e7761..22b5978a 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -96,12 +96,6 @@ class UnsupportedArchiveType(PlatformioException): MESSAGE = "Can not unpack file '%s'" -class ProjectInitialized(PlatformioException): - - MESSAGE = ("Project is already initialized. " - "Process it with `platformio run` command") - - class ProjectEnvsNotAvailable(PlatformioException): MESSAGE = "Please setup environments in `platformio.ini` file." @@ -171,6 +165,15 @@ class UpgraderFailed(PlatformioException): MESSAGE = "An error occurred while upgrading PlatformIO" +class CIBuildEnvsEmpty(PlatformioException): + + MESSAGE = ( + "Can't find PlatformIO build environments.\nPlease specify `--board` " + "or path to `platformio.ini` with predefined environments using " + "`--project-conf` option" + ) + + class SConsNotInstalled(PlatformioException): MESSAGE = ( diff --git a/platformio/ide/__init__.py b/platformio/ide/__init__.py new file mode 100644 index 00000000..ca6f0304 --- /dev/null +++ b/platformio/ide/__init__.py @@ -0,0 +1,2 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py new file mode 100644 index 00000000..fda18e9e --- /dev/null +++ b/platformio/ide/projectgenerator.py @@ -0,0 +1,102 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +import json +from glob import glob +from os import listdir, walk +from os.path import basename, isdir, join + +import bottle + +from platformio import util + + +class ProjectGenerator(object): + + def __init__(self, project_dir, ide): + self.project_dir = project_dir + self.ide = ide + self._tplvars = {} + + self._gather_tplvars() + + @staticmethod + def get_supported_ides(): + tpls_dir = join(util.get_source_dir(), "ide", "tpls") + return [d for d in listdir(tpls_dir) + if isdir(join(tpls_dir, d))] + + @staticmethod + def get_project_env(): + data = {} + config = util.get_project_config() + for section in config.sections(): + if not section.startswith("env:"): + continue + data['env_name'] = section[4:] + for k, v in config.items(section): + data[k] = v + return data + + @util.memoized + def get_project_build_data(self): + envdata = self.get_project_env() + if "env_name" not in envdata: + return None + result = util.exec_command( + ["platformio", "run", "-t", "idedata", "-e", envdata['env_name']] + ) + if result['returncode'] != 0 or '{"includes":' not in result['out']: + return None + + output = result['out'] + try: + start_index = output.index('\n{"includes":') + stop_index = output.rindex('}') + return json.loads(output[start_index + 1:stop_index + 1]) + except ValueError: + pass + + return None + + def get_project_name(self): + return basename(self.project_dir) + + @staticmethod + def get_srcfiles(): + result = [] + for root, _, files in walk(util.get_projectsrc_dir()): + for f in files: + result.append(join(root, f)) + return result + + def get_tpls(self): + tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide) + return glob(join(tpls_dir, ".*.tpl")) + glob(join(tpls_dir, "*.tpl")) + + def generate(self): + for tpl_path in self.get_tpls(): + file_name = basename(tpl_path)[:-4] + with open(join(self.project_dir, file_name), "w") as f: + f.write(self._render_tpl(tpl_path).encode("utf8")) + + def _render_tpl(self, tpl_path): + content = "" + with open(tpl_path) as f: + content = f.read() + return bottle.template(content, **self._tplvars) + + def _gather_tplvars(self): + self._tplvars.update(self.get_project_env()) + + build_data = self.get_project_build_data() + + self._tplvars.update({ + "project_name": self.get_project_name(), + "includes": (build_data['includes'] + if build_data and "includes" in build_data else []), + "defines": (build_data['defines'] + if build_data and "defines" in build_data else []), + "srcfiles": self.get_srcfiles(), + "project_dir": self.project_dir + }) diff --git a/platformio/ide/tpls/eclipse/.cproject.tpl b/platformio/ide/tpls/eclipse/.cproject.tpl new file mode 100644 index 00000000..ccd645ed --- /dev/null +++ b/platformio/ide/tpls/eclipse/.cproject.tpl @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platformio/ide/tpls/eclipse/.project.tpl b/platformio/ide/tpls/eclipse/.project.tpl new file mode 100644 index 00000000..ac49f548 --- /dev/null +++ b/platformio/ide/tpls/eclipse/.project.tpl @@ -0,0 +1,27 @@ + + + {{project_name}} + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/platformio/ide/tpls/qtcreator/platformio.pro.tpl b/platformio/ide/tpls/qtcreator/platformio.pro.tpl new file mode 100644 index 00000000..d809a9b3 --- /dev/null +++ b/platformio/ide/tpls/qtcreator/platformio.pro.tpl @@ -0,0 +1,24 @@ +win32 { + HOMEDIR += $$(USERPROFILE) +} +else { + HOMEDIR += $$(PWD) +} + +% for include in includes: +INCLUDEPATH += "{{include}}" +% end + +win32:INCLUDEPATH ~= s,/,\\,g + +% for define in defines: +DEFINES += "{{define}}" +% end + +OTHER_FILES += \ + platformio.ini + +SOURCES += \ + % for file in srcfiles: + {{file}} + % end diff --git a/platformio/ide/tpls/qtcreator/platformio.pro.user.tpl b/platformio/ide/tpls/qtcreator/platformio.pro.user.tpl new file mode 100644 index 00000000..72ecb9ad --- /dev/null +++ b/platformio/ide/tpls/qtcreator/platformio.pro.user.tpl @@ -0,0 +1,231 @@ + + + + + + EnvironmentId + {00248b6a-4380-4f03-8dea-a03053177907} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + {{project_name}} + {{project_name}} + qt.53.win32_mingw482_kit + 1 + 0 + 0 + + {{project_dir}} + + + true + --force run + platformio + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + --force run -t clean + platformio + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + {{project_dir}} + + + true + --force run + platformio + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + --force run -t clean + platformio + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + platformio + + Qt4ProjectManager.Qt4RunConfiguration:{{project_dir}}/platformio.pro + + platformio.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 16 + + + Version + 16 + + diff --git a/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl new file mode 100644 index 00000000..4c4855a2 --- /dev/null +++ b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl @@ -0,0 +1,45 @@ +{ + "build_systems": + [ + { + "cmd": + [ + "platformio", + "run" + ], + "name": "PlatformIO", + "variants": + [ + { + "cmd": + [ + "platformio", + "--force", + "run", + "--target", + "clean" + ], + "name": "Clean" + }, + { + "cmd": + [ + "platformio", + "--force", + "run", + "--target", + "upload" + ], + "name": "Upload" + } + ], + "working_dir": "${project_path:${folder}}" + } + ], + "folders": + [ + { + "path": "." + } + ] +} diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl new file mode 100644 index 00000000..1b4a764e --- /dev/null +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl @@ -0,0 +1,29 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {cad450ef-1a84-42d4-a5b5-a1736b8833d3} + + + + + + + + + Source Files\src + + + diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl new file mode 100644 index 00000000..1a069d7e --- /dev/null +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl @@ -0,0 +1,64 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {0FA9C3A8-452B-41EF-A418-9102B170F49F} + MakeFileProj + + + + Makefile + true + v120 + + + Makefile + false + v120 + + + + + + + + + + + + + platformio --force run + platformio --force run --target clean + {{";".join(defines)}} + {{";".join(includes)}} + + + platformio run + platformio run -t clean + {";".join(defines)}} + {{";".join(includes)}} + + + + + + + + + % for file in srcfiles: + + % end + + + + + diff --git a/platformio/libmanager.py b/platformio/libmanager.py index ae577d15..0dfd220d 100644 --- a/platformio/libmanager.py +++ b/platformio/libmanager.py @@ -8,19 +8,18 @@ from os.path import isdir, isfile, join from shutil import rmtree from tempfile import gettempdir -from platformio import telemetry +from platformio import telemetry, util from platformio.downloader import FileDownloader from platformio.exception import LibAlreadyInstalledError, LibNotInstalledError from platformio.unpacker import FileUnpacker -from platformio.util import get_api_result class LibraryManager(object): CONFIG_NAME = ".library.json" - def __init__(self, lib_dir): - self.lib_dir = lib_dir + def __init__(self, lib_dir=None): + self.lib_dir = lib_dir or util.get_lib_dir() @staticmethod def download(url, dest_dir): @@ -49,7 +48,7 @@ class LibraryManager(object): lib_ids = [str(item['id']) for item in self.get_installed().values()] if not lib_ids: return None - return get_api_result("/lib/version/" + str(",".join(lib_ids))) + return util.get_api_result("/lib/version/" + str(",".join(lib_ids))) def get_outdated(self): outdated = [] @@ -75,8 +74,10 @@ class LibraryManager(object): if self.is_installed(id_): raise LibAlreadyInstalledError() - dlinfo = get_api_result("/lib/download/" + str(id_), - dict(version=version) if version else None) + dlinfo = util.get_api_result( + "/lib/download/" + str(id_), + dict(version=version) if version else None + ) dlpath = None tmplib_dir = join(self.lib_dir, str(id_)) try: diff --git a/platformio/maintenance.py b/platformio/maintenance.py index 87d673d4..89d7fbd3 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -11,16 +11,19 @@ from time import time import click from platformio import __version__, app, exception, telemetry -from platformio.commands.install import cli as cmd_install from platformio.commands.lib import lib_update as cmd_libraries_update -from platformio.commands.update import cli as cli_update +from platformio.commands.platforms import \ + platforms_install as cmd_platforms_install +from platformio.commands.platforms import \ + platforms_update as cmd_platforms_update from platformio.commands.upgrade import get_latest_version from platformio.libmanager import LibraryManager from platformio.platforms.base import PlatformFactory -from platformio.util import get_home_dir, get_lib_dir +from platformio.util import get_home_dir -def on_platformio_start(ctx): +def on_platformio_start(ctx, force): + app.set_session_var("force_option", force) telemetry.on_command(ctx) after_upgrade(ctx) @@ -89,7 +92,7 @@ class Upgrader(object): remove(join(get_home_dir(), fname)) if prev_platforms: - ctx.invoke(cmd_install, platforms=prev_platforms) + ctx.invoke(cmd_platforms_install, platforms=prev_platforms) return True @@ -97,8 +100,7 @@ class Upgrader(object): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if installed_platforms: - ctx.invoke(cmd_install, platforms=installed_platforms) - ctx.invoke(cli_update) + ctx.invoke(cmd_platforms_install, platforms=installed_platforms) return True @@ -107,8 +109,12 @@ def after_upgrade(ctx): if last_version == __version__: return + terminal_width, _ = click.get_terminal_size() + # promotion - click.echo("\nIf you like %s, please:" % ( + click.echo("") + click.echo("*" * terminal_width) + click.echo("If you like %s, please:" % ( click.style("PlatformIO", fg="cyan") )) click.echo( @@ -121,7 +127,13 @@ def after_upgrade(ctx): click.style("give", fg="cyan"), click.style("https://github.com/platformio/platformio", fg="cyan") )) - click.secho("Thanks a lot!\n", fg="green") + click.echo("- %s for the new features/issues on Bountysource > %s" % ( + click.style("vote", fg="cyan"), + click.style("https://www.bountysource.com/teams/platformio/issues", + fg="cyan") + )) + click.echo("*" * terminal_width) + click.echo("") if last_version == "0.0.0": app.set_state_item("last_version", __version__) @@ -133,6 +145,8 @@ def after_upgrade(ctx): u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) + ctx.invoke(cmd_platforms_update) + click.secho("PlatformIO has been successfully upgraded to %s!\n" % __version__, fg="green") @@ -158,13 +172,19 @@ def check_platformio_upgrade(): Upgrader.version_to_int(__version__)): return + terminal_width, _ = click.get_terminal_size() + + click.echo("") + click.echo("*" * terminal_width) click.secho("There is a new version %s of PlatformIO available.\n" "Please upgrade it via " % latest_version, fg="yellow", nl=False) click.secho("platformio upgrade", fg="cyan", nl=False) click.secho(" command.\nChanges: ", fg="yellow", nl=False) - click.secho("http://docs.platformio.org/en/latest/history.html\n", + click.secho("http://docs.platformio.org/en/latest/history.html", fg="cyan") + click.echo("*" * terminal_width) + click.echo("") def check_internal_updates(ctx, what): @@ -183,28 +203,35 @@ def check_internal_updates(ctx, what): if p.is_outdated(): outdated_items.append(platform) elif what == "libraries": - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() outdated_items = lm.get_outdated() if not outdated_items: return + terminal_width, _ = click.get_terminal_size() + + click.echo("") + click.echo("*" * terminal_width) click.secho("There are the new updates for %s (%s)" % (what, ", ".join(outdated_items)), fg="yellow") if not app.get_setting("auto_update_" + what): click.secho("Please update them via ", fg="yellow", nl=False) - click.secho("`platformio %supdate`" % - ("lib " if what == "libraries" else ""), + click.secho("`platformio %s update`" % + ("lib" if what == "libraries" else "platforms"), fg="cyan", nl=False) - click.secho(" command.\n", fg="yellow") + click.secho(" command.", fg="yellow") else: click.secho("Please wait while updating %s ..." % what, fg="yellow") if what == "platforms": - ctx.invoke(cli_update) + ctx.invoke(cmd_platforms_update) elif what == "libraries": ctx.invoke(cmd_libraries_update) click.echo() telemetry.on_event(category="Auto", action="Update", label=what.title()) + + click.echo("*" * terminal_width) + click.echo("") diff --git a/platformio/pkgmanager.py b/platformio/pkgmanager.py index bd0e816f..b60332af 100644 --- a/platformio/pkgmanager.py +++ b/platformio/pkgmanager.py @@ -8,28 +8,24 @@ from time import time import click -from platformio import exception, telemetry +from platformio import exception, telemetry, util from platformio.app import get_state_item, set_state_item from platformio.downloader import FileDownloader from platformio.unpacker import FileUnpacker -from platformio.util import get_api_result, get_home_dir, get_systype class PackageManager(object): def __init__(self): - self._package_dir = join(get_home_dir(), "packages") + self._package_dir = join(util.get_home_dir(), "packages") if not isdir(self._package_dir): makedirs(self._package_dir) assert isdir(self._package_dir) @classmethod + @util.memoized def get_manifest(cls): - try: - return cls._cached_manifest - except AttributeError: - cls._cached_manifest = get_api_result("/packages/manifest") - return cls._cached_manifest + return util.get_api_result("/packages/manifest") @staticmethod def download(url, dest_dir, sha1=None): @@ -63,7 +59,7 @@ class PackageManager(object): raise exception.UnknownPackage(name) # check system platform - systype = get_systype() + systype = util.get_systype() builds = ([b for b in manifest[name] if b['system'] == "all" or systype in b['system']]) if not builds: diff --git a/platformio/platforms/atmelavr.py b/platformio/platforms/atmelavr.py index 9c7bc243..23486589 100644 --- a/platformio/platforms/atmelavr.py +++ b/platformio/platforms/atmelavr.py @@ -47,7 +47,7 @@ class AtmelavrPlatform(BasePlatform): else: BasePlatform.on_run_err(self, line) - def run(self, variables, targets): + def run(self, variables, targets, verbose): for v in variables: if "BOARD=" not in v: continue @@ -58,4 +58,4 @@ class AtmelavrPlatform(BasePlatform): tuploader = "tool-micronucleus" self.PACKAGES[tuploader]['alias'] = "uploader" break - return BasePlatform.run(self, variables, targets) + return BasePlatform.run(self, variables, targets, verbose) diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index 42398753..b1305c3f 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -119,7 +119,7 @@ class PlatformFactory(object): @staticmethod def get_clsname(type_): - return "%sPlatform" % type_.title() + return "%s%sPlatform" % (type_.upper()[0], type_.lower()[1:]) @staticmethod def load_module(type_, path): @@ -132,14 +132,16 @@ class PlatformFactory(object): return module @classmethod - def get_platforms(cls, installed=False): + @util.memoized + def _lookup_platforms(cls): platforms = {} for d in (util.get_home_dir(), util.get_source_dir()): pdir = join(d, "platforms") if not isdir(pdir): continue for p in listdir(pdir): - if p in ("__init__.py", "base.py") or not p.endswith(".py"): + if (p in ("__init__.py", "base.py") or not + p.endswith(".py")): continue type_ = p[:-3] path = join(pdir, p) @@ -152,6 +154,11 @@ class PlatformFactory(object): platforms[type_] = path except exception.UnknownPlatform: pass + return platforms + + @classmethod + def get_platforms(cls, installed=False): + platforms = cls._lookup_platforms() if not installed: return platforms @@ -183,6 +190,12 @@ class BasePlatform(object): def __init__(self): self._found_error = False + self._last_echo_line = None + + # 1 = errors + # 2 = 1 + warnings + # 3 = 2 + others + self._verbose_level = 3 def get_type(self): return self.__class__.__name__[:-8].lower() @@ -299,10 +312,12 @@ class BasePlatform(object): obsolated = pm.get_outdated() return not set(self.get_packages().keys()).isdisjoint(set(obsolated)) - def run(self, variables, targets): + def run(self, variables, targets, verbose): assert isinstance(variables, list) assert isinstance(targets, list) + self._verbose_level = int(verbose) + installed_platforms = PlatformFactory.get_platforms( installed=True).keys() installed_packages = PackageManager.get_installed() @@ -349,16 +364,34 @@ class BasePlatform(object): if self._found_error: result['returncode'] = 1 + if self._last_echo_line == ".": + click.echo("") + return result - def on_run_out(self, line): # pylint: disable=R0201 - fg = None - if "is up to date" in line: - fg = "green" - click.secho(line, fg=fg) + def on_run_out(self, line): + self._echo_line(line, level=3) - def on_run_err(self, line): # pylint: disable=R0201 + def on_run_err(self, line): is_error = self.LINE_ERROR_RE.search(line) is not None if is_error: self._found_error = True - click.secho(line, err=True, fg="red" if is_error else "yellow") + self._echo_line(line, level=1 if is_error else 2) + + def _echo_line(self, line, level): + assert 1 <= level <= 3 + + fg = ("red", "yellow", None)[level - 1] + if level == 3 and "is up to date" in line: + fg = "green" + + if level > self._verbose_level: + click.secho(".", fg=fg, err=level < 3, nl=False) + self._last_echo_line = "." + return + + if self._last_echo_line == ".": + click.echo("") + self._last_echo_line = line + + click.secho(line, fg=fg, err=level < 3) diff --git a/platformio/platforms/teensy.py b/platformio/platforms/teensy.py index cc79c3ee..07316d15 100644 --- a/platformio/platforms/teensy.py +++ b/platformio/platforms/teensy.py @@ -44,7 +44,7 @@ class TeensyPlatform(BasePlatform): def get_name(self): return "Teensy" - def run(self, variables, targets): + def run(self, variables, targets, verbose): for v in variables: if "BOARD=" not in v: continue @@ -56,4 +56,4 @@ class TeensyPlatform(BasePlatform): tpackage = "toolchain-gccarmnoneeabi" self.PACKAGES[tpackage]['alias'] = "toolchain" break - return BasePlatform.run(self, variables, targets) + return BasePlatform.run(self, variables, targets, verbose) diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 55b26f21..3662b7f4 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -12,8 +12,7 @@ from time import time import click import requests -from platformio import __version__, app -from platformio.util import exec_command, get_systype +from platformio import __version__, app, util class TelemetryBase(object): @@ -77,7 +76,7 @@ class MeasurementProtocol(TelemetryBase): dpdata.append("Click/%s" % click.__version__) # dpdata.append("Requests/%s" % requests.__version__) try: - result = exec_command(["scons", "--version"]) + result = util.exec_command(["scons", "--version"]) match = re.search(r"engine: v([\d\.]+)", result['out']) if match: dpdata.append("SCons/%s" % match.group(1)) @@ -86,7 +85,7 @@ class MeasurementProtocol(TelemetryBase): self['an'] = " ".join(dpdata) def _prefill_custom_data(self): - self['cd1'] = get_systype() + self['cd1'] = util.get_systype() self['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) self['cd4'] = 1 if app.get_setting("enable_prompts") else 0 @@ -96,7 +95,7 @@ class MeasurementProtocol(TelemetryBase): if not args: return - if args[0] in ("lib", "serialports", "settings"): + if args[0] in ("lib", "platforms", "serialports", "settings"): cmd_path = args[:2] else: cmd_path = args[:1] @@ -155,6 +154,7 @@ class MPDataPusher(threading.Thread): r = self.http_session().post( "https://ssl.google-analytics.com/collect", data=data, + headers=util.get_request_defheaders(), timeout=3 ) r.raise_for_status() diff --git a/platformio/unpacker.py b/platformio/unpacker.py index f80081dc..34cb3594 100644 --- a/platformio/unpacker.py +++ b/platformio/unpacker.py @@ -1,13 +1,13 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -from os import chmod +from os import chmod, environ from os.path import join, splitext from tarfile import open as tarfile_open from time import mktime from zipfile import ZipFile -from click import progressbar +import click from platformio.exception import UnsupportedArchiveType from platformio.util import change_filemtime @@ -81,7 +81,13 @@ class FileUnpacker(object): raise UnsupportedArchiveType(archpath) def start(self): - with progressbar(self._unpacker.get_items(), label="Unpacking") as pb: - for item in pb: + if environ.get("CI") == "true": + click.echo("Unpacking...") + for item in self._unpacker.get_items(): self._unpacker.extract_item(item, self._dest_dir) + else: + with click.progressbar(self._unpacker.get_items(), + label="Unpacking") as pb: + for item in pb: + self._unpacker.extract_item(item, self._dest_dir) return True diff --git a/platformio/util.py b/platformio/util.py index 82582573..6dbad199 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -1,6 +1,8 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. +import collections +import functools import json import os import re @@ -53,9 +55,45 @@ class AsyncPipe(Thread): self.join() +class memoized(object): + ''' + Decorator. Caches a function's return value each time it is called. + If called later with the same arguments, the cached value is returned + (not reevaluated). + https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize + ''' + + def __init__(self, func): + self.func = func + self.cache = {} + + def __call__(self, *args): + if not isinstance(args, collections.Hashable): + # uncacheable. a list, for instance. + # better to not cache than blow up. + return self.func(*args) + if args in self.cache: + return self.cache[args] + else: + value = self.func(*args) + self.cache[args] = value + return value + + def __repr__(self): + '''Return the function's docstring.''' + return self.func.__doc__ + + def __get__(self, obj, objtype): + '''Support instance methods.''' + return functools.partial(self.__call__, obj) + + def get_systype(): data = uname() - return ("%s_%s" % (data[0], data[4])).lower() + systype = data[0] + if data[4]: + systype += "_" + data[4] + return systype.lower() def pioversion_to_intstr(): @@ -207,19 +245,22 @@ def get_logicaldisks(): return disks +def get_request_defheaders(): + return {"User-Agent": "PlatformIO/%s %s" % ( + __version__, requests.utils.default_user_agent())} + + def get_api_result(path, params=None, data=None): result = None r = None try: - headers = {"User-Agent": "PlatformIO/%s %s" % ( - __version__, requests.utils.default_user_agent())} - if data: r = requests.post(__apiurl__ + path, params=params, data=data, - headers=headers) + headers=get_request_defheaders()) else: - r = requests.get(__apiurl__ + path, params=params, headers=headers) + r = requests.get(__apiurl__ + path, params=params, + headers=get_request_defheaders()) result = r.json() r.raise_for_status() except requests.exceptions.HTTPError as e: @@ -239,22 +280,24 @@ def get_api_result(path, params=None, data=None): return result -def get_boards(type_=None): +@memoized +def _lookup_boards(): boards = {} - try: - boards = get_boards._cache # pylint: disable=W0212 - except AttributeError: - bdirs = [join(get_source_dir(), "boards")] - if isdir(join(get_home_dir(), "boards")): - bdirs.append(join(get_home_dir(), "boards")) + bdirs = [join(get_source_dir(), "boards")] + if isdir(join(get_home_dir(), "boards")): + bdirs.append(join(get_home_dir(), "boards")) - for bdir in bdirs: - for json_file in os.listdir(bdir): - if not json_file.endswith(".json"): - continue - with open(join(bdir, json_file)) as f: - boards.update(json.load(f)) - get_boards._cache = boards # pylint: disable=W0212 + for bdir in bdirs: + for json_file in os.listdir(bdir): + if not json_file.endswith(".json"): + continue + with open(join(bdir, json_file)) as f: + boards.update(json.load(f)) + return boards + + +def get_boards(type_=None): + boards = _lookup_boards() if type_ is None: return boards @@ -264,33 +307,34 @@ def get_boards(type_=None): return boards[type_] -def get_frameworks(type_=None): +@memoized +def _lookup_frameworks(): frameworks = {} + frameworks_path = join( + get_source_dir(), "builder", "scripts", "frameworks") - try: - frameworks = get_frameworks._cache # pylint: disable=W0212 - except AttributeError: - frameworks_path = join( - get_source_dir(), "builder", "scripts", "frameworks") + frameworks_list = [f[:-3] for f in os.listdir(frameworks_path) + if not f.startswith("__") and f.endswith(".py")] + for _type in frameworks_list: + script_path = join(frameworks_path, "%s.py" % _type) + with open(script_path) as f: + fcontent = f.read() + assert '"""' in fcontent + _doc_start = fcontent.index('"""') + 3 + fdoc = fcontent[ + _doc_start:fcontent.index('"""', _doc_start)].strip() + doclines = [l.strip() for l in fdoc.splitlines() if l.strip()] + frameworks[_type] = { + "name": doclines[0], + "description": " ".join(doclines[1:-1]), + "url": doclines[-1], + "script": script_path + } + return frameworks - frameworks_list = [f[:-3] for f in os.listdir(frameworks_path) - if not f.startswith("__") and f.endswith(".py")] - for _type in frameworks_list: - script_path = join(frameworks_path, "%s.py" % _type) - with open(script_path) as f: - fcontent = f.read() - assert '"""' in fcontent - _doc_start = fcontent.index('"""') + 3 - fdoc = fcontent[ - _doc_start:fcontent.index('"""', _doc_start)].strip() - doclines = [l.strip() for l in fdoc.splitlines() if l.strip()] - frameworks[_type] = { - "name": doclines[0], - "description": " ".join(doclines[1:-1]), - "url": doclines[-1], - "script": script_path - } - get_frameworks._cache = frameworks # pylint: disable=W0212 + +def get_frameworks(type_=None): + frameworks = _lookup_frameworks() if type_ is None: return frameworks diff --git a/requirements.txt b/requirements.txt index ef3dfdda..9b707761 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ click==4.0 +bottle=0.12.8 colorama==0.3.3 pyserial==2.7 requests==2.7.0 diff --git a/scripts/appveyor/install.ps1 b/scripts/appveyor/install.ps1 index 3fb6cf28..311cb38d 100644 --- a/scripts/appveyor/install.ps1 +++ b/scripts/appveyor/install.ps1 @@ -74,7 +74,7 @@ function InstallPip ($python_home) { function InstallPackage ($python_home, $pkg) { $pip_path = $python_home + "/Scripts/pip.exe" - & $pip_path install $pkg + & $pip_path install -U $pkg } function main () { @@ -84,4 +84,4 @@ function main () { InstallPackage $env:PYTHON_HOME tox } -main \ No newline at end of file +main diff --git a/setup.py b/setup.py index 9a01f68c..41b5a586 100644 --- a/setup.py +++ b/setup.py @@ -18,13 +18,21 @@ setup( url=__url__, license=__license__, install_requires=[ + "bottle", "click>=3.0", "pyserial", "requests>=2.4.0", # "SCons" ] + (["colorama"] if system() == "Windows" else []), packages=find_packages(), - package_data={"platformio": ["projectconftpl.ini", "boards/*.json"]}, + package_data={ + "platformio": [ + "projectconftpl.ini", + "boards/*.json", + "ide/tpls/*/.*.tpl", + "ide/tpls/*/*.tpl" + ] + }, entry_points={ "console_scripts": [ "platformio = platformio.__main__:main" diff --git a/tests/commands/test_boards.py b/tests/commands/test_boards.py index 4a96d2e5..62a7f102 100644 --- a/tests/commands/test_boards.py +++ b/tests/commands/test_boards.py @@ -5,13 +5,15 @@ import json from os.path import isfile, join from platformio import util -from platformio.commands.boards import cli as boards_cli -from platformio.commands.install import cli as install_cli -from platformio.commands.search import cli as search_cli +from platformio.commands.boards import cli as cmd_boards +from platformio.commands.platforms import \ + platforms_install as cmd_platforms_install +from platformio.commands.platforms import \ + platforms_search as cmd_platforms_search def test_board_json_output(platformio_setup, clirunner, validate_cliresult): - result = clirunner.invoke(boards_cli, ["cortex", "--json-output"]) + result = clirunner.invoke(cmd_boards, ["cortex", "--json-output"]) validate_cliresult(result) boards = json.loads(result.output) assert isinstance(boards, dict) @@ -19,7 +21,7 @@ def test_board_json_output(platformio_setup, clirunner, validate_cliresult): def test_board_raw_output(platformio_setup, clirunner, validate_cliresult): - result = clirunner.invoke(boards_cli, ["energia"]) + result = clirunner.invoke(cmd_boards, ["energia"]) validate_cliresult(result) assert "titiva" in result.output @@ -29,7 +31,7 @@ def test_board_options(platformio_setup, clirunner, validate_cliresult): ["build", "platform", "upload", "name"]) # fetch available platforms - result = clirunner.invoke(search_cli, ["--json-output"]) + result = clirunner.invoke(cmd_platforms_search, ["--json-output"]) validate_cliresult(result) search_result = json.loads(result.output) assert isinstance(search_result, list) @@ -43,7 +45,7 @@ def test_board_options(platformio_setup, clirunner, validate_cliresult): def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke( - install_cli, [ + cmd_platforms_install, [ "ststm32", "--skip-default-package", "--with-package=ldscripts" diff --git a/tests/commands/test_init.py b/tests/commands/test_init.py index 0d816ff2..d354982e 100644 --- a/tests/commands/test_init.py +++ b/tests/commands/test_init.py @@ -46,9 +46,9 @@ def test_init_special_board(platformio_setup, clirunner, validate_cliresult): ("targets", "upload") ] - assert config.has_section("env:autogen_uno") + assert config.has_section("env:uno") assert len(set(expected_result).symmetric_difference( - set(config.items("env:autogen_uno")))) == 0 + set(config.items("env:uno")))) == 0 def test_init_disable_auto_uploading(platformio_setup, clirunner, @@ -64,11 +64,13 @@ def test_init_disable_auto_uploading(platformio_setup, clirunner, ("framework", "arduino"), ("board", "uno") ] - assert config.has_section("env:autogen_uno") + assert config.has_section("env:uno") assert len(set(expected_result).symmetric_difference( - set(config.items("env:autogen_uno")))) == 0 + set(config.items("env:uno")))) == 0 def test_init_incorrect_board(clirunner): result = clirunner.invoke(cli, ["-b", "missed_board"]) - assert isinstance(result.exception, exception.UnknownBoard) + assert result.exit_code == 2 + assert 'Error: Invalid value for "--board" / "-b"' in result.output + assert isinstance(result.exception, SystemExit) diff --git a/tests/commands/test_list.py b/tests/commands/test_list.py deleted file mode 100644 index e40b5926..00000000 --- a/tests/commands/test_list.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import json - -from platformio.commands.list import cli - - -def test_list_json_output(clirunner, validate_cliresult): - result = clirunner.invoke(cli, ["--json-output"]) - validate_cliresult(result) - list_result = json.loads(result.output) - assert isinstance(list_result, list) - assert len(list_result) - platforms = [item['name'] for item in list_result] - assert "titiva" in platforms - - -def test_list_raw_output(clirunner, validate_cliresult): - result = clirunner.invoke(cli) - validate_cliresult(result) - assert "teensy" in result.output diff --git a/tests/commands/test_platforms.py b/tests/commands/test_platforms.py new file mode 100644 index 00000000..310967a2 --- /dev/null +++ b/tests/commands/test_platforms.py @@ -0,0 +1,42 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +import json + +from platformio.commands.platforms import \ + platforms_list as cmd_platforms_list +from platformio.commands.platforms import \ + platforms_search as cmd_platforms_search + + +def test_list_json_output(clirunner, validate_cliresult): + result = clirunner.invoke(cmd_platforms_list, ["--json-output"]) + validate_cliresult(result) + list_result = json.loads(result.output) + assert isinstance(list_result, list) + assert len(list_result) + platforms = [item['name'] for item in list_result] + assert "titiva" in platforms + + +def test_list_raw_output(clirunner, validate_cliresult): + result = clirunner.invoke(cmd_platforms_list) + validate_cliresult(result) + assert "teensy" in result.output + + +def test_search_json_output(clirunner, validate_cliresult): + result = clirunner.invoke(cmd_platforms_search, + ["arduino", "--json-output"]) + validate_cliresult(result) + search_result = json.loads(result.output) + assert isinstance(search_result, list) + assert len(search_result) + platforms = [item['type'] for item in search_result] + assert "atmelsam" in platforms + + +def test_search_raw_output(clirunner, validate_cliresult): + result = clirunner.invoke(cmd_platforms_search, ["arduino"]) + validate_cliresult(result) + assert "teensy" in result.output diff --git a/tests/commands/test_search.py b/tests/commands/test_search.py deleted file mode 100644 index 4179f1b2..00000000 --- a/tests/commands/test_search.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import json - -from platformio.commands.search import cli - - -def test_search_json_output(clirunner, validate_cliresult): - result = clirunner.invoke(cli, ["arduino", "--json-output"]) - validate_cliresult(result) - search_result = json.loads(result.output) - assert isinstance(search_result, list) - assert len(search_result) - platforms = [item['type'] for item in search_result] - assert "atmelsam" in platforms - - -def test_search_raw_output(clirunner, validate_cliresult): - result = clirunner.invoke(cli, ["arduino"]) - validate_cliresult(result) - assert "teensy" in result.output