Allow to run project with platformio run –project-dir option without changing the current working directory // Resolve #192

This commit is contained in:
Ivan Kravets
2015-05-06 17:29:58 +01:00
parent 04f246ea9d
commit eeeed1ba08
3 changed files with 54 additions and 36 deletions

View File

@ -11,6 +11,9 @@ Release History
(`issue #174 <https://github.com/platformio/platformio/issues/174>`_)
* Added global ``-f, --force`` option which will force to accept any
confirmation prompts (`issue #152 <https://github.com/platformio/platformio/issues/152>`_)
* Allowed to run project with `platformio run --project-dir <http://docs.platformio.org/en/latest/userguide/cmd_run.html#cmdoption--project-dir>`_ option without changing the current working
directory
(`issue #192 <https://github.com/platformio/platformio/issues/192>`_)
* Allowed to add library dependencies for build environment using
`install_libs <http://docs.platformio.org/en/latest/projectconf.html#install-libs>`_
option in ``platformio.ini``

View File

@ -39,6 +39,12 @@ 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``).
Examples
--------

View File

@ -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
@ -20,9 +21,14 @@ from platformio.platforms.base import PlatformFactory
@click.option("--environment", "-e", multiple=True, metavar="<environment>")
@click.option("--target", "-t", multiple=True, metavar="<target>")
@click.option("--upload-port", metavar="<upload port>")
@click.option("--project-dir", default=getcwd,
type=click.Path(exists=True, file_okay=False, dir_okay=True,
writable=True, resolve_path=True))
@click.pass_context
def cli(ctx, environment, target, upload_port):
def cli(ctx, environment, target, upload_port, project_dir):
initial_cwd = getcwd()
chdir(project_dir)
try:
config = util.get_project_config()
if not config.sections():
@ -60,12 +66,15 @@ def cli(ctx, environment, target, upload_port):
if _first_done:
click.echo()
if not process_environment(ctx, envname, options, target, upload_port):
if not process_environment(
ctx, envname, options, target, upload_port):
found_error = True
_first_done = True
if found_error:
raise exception.ReturnErrorCode()
finally:
chdir(initial_cwd)
def process_environment(ctx, name, options, targets, upload_port):