Add src_dir option to [platformio] section of platformio.ini which allows to redefine location to project’s source directory // Resolve #83

This commit is contained in:
Ivan Kravets
2015-02-22 22:24:22 +02:00
parent e17ce83499
commit 46ae4c1a83
9 changed files with 125 additions and 23 deletions

View File

@ -14,6 +14,10 @@ Release History
`#48 <https://github.com/ivankravets/platformio/issues/48>`_,
`#50 <https://github.com/ivankravets/platformio/issues/50>`_,
`#55 <https://github.com/ivankravets/platformio/issues/55>`_)
* Added `src_dir <http://docs.platformio.org/en/latest/projectconf.html#src-dir>`__
option to ``[platformio]`` section of
`platformio.ini <http://docs.platformio.org/en/latest/projectconf.html>`__
which allows to redefine location to project's source directory
* Added ``--json-output`` option to
`platformio boards <http://docs.platformio.org/en/latest/userguide/cmd_boards.html>`__
and `platformio search <http://docs.platformio.org/en/latest/userguide/cmd_search.html>`__

View File

@ -19,6 +19,12 @@ The sections and their allowable values are described below.
A ``platformio`` section is used for overriding default configuration options
.. note::
Relative path is allowed for directory option:
* ``~`` will be expanded to user's home directory
* ``../`` or ``..\`` go up to one folder
Options
~~~~~~~
@ -33,15 +39,27 @@ external libraries, service data and etc.
A default value is user's home directory: *Unix* - ``~/.platformio``,
Windows - ``%HOMEPATH%\.platformio``.
``lib_dir``
^^^^^^^^^^^^
^^^^^^^^^^^
This directory is used to store external libraries downloaded by
:ref:`librarymanager`.
A default value is ``$PIO_HOME_DIR/lib``.
``src_dir``
^^^^^^^^^^^
The path to project's source directory. PlatformIO uses it for :ref:`cmd_run`
command.
A default value is ``$PROJECT_DIR/src``.
.. note::
This option is useful for people who migrate from Arduino/Energia IDEs where
source directory should have the same name like the main source file.
See `example <https://github.com/ivankravets/platformio/tree/develop/examples/atmelavr-and-arduino/arduino-own-src_dir>`__ project with own source directory.
[env:NAME]
----------

View File

@ -0,0 +1,22 @@
/**
* Copyright (C) Ivan Kravets <me@ikravets.com>
* See LICENSE for details.
*/
#ifndef LED_PIN
#define LED_PIN 13 // Most Arduino boards already have a LED attached to pin 13 on the board itself
#endif
void setup()
{
pinMode(LED_PIN, OUTPUT); // set pin as output
}
void loop()
{
digitalWrite(LED_PIN, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(LED_PIN, LOW); // set the LED off
delay(1000); // wait for a second
}

View File

@ -0,0 +1,21 @@
How to buid PlatformIO based project
====================================
1. `Install PlatformIO <http://docs.platformio.org/en/latest/installation.html>`_
2. Download `source code with examples <https://github.com/ivankravets/platformio/archive/develop.zip>`_
3. Extract ZIP archive
4. Run these commands:
.. code-block:: bash
# Change directory to example
> cd platformio-develop/examples/arduino-own-src_dir
# Process example project
> platformio run
# Upload firmware
> platformio run --target upload
# Clean build files
> platformio run --target clean

View File

@ -0,0 +1,26 @@
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[platformio]
src_dir = Blink
[env:arduino_uno]
platform = atmelavr
framework = arduino
board = uno

View File

@ -11,7 +11,7 @@
#include "Arduino.h"
#ifndef LED_PIN
#define LED_PIN 13 // Most Arduino boards already have an LED attached to pin 13 on the board itself
#define LED_PIN 13 // Most Arduino boards already have a LED attached to pin 13 on the board itself
#endif

View File

@ -58,6 +58,7 @@ DefaultEnvironment(
PIOHOME_DIR=util.get_home_dir(),
PROJECT_DIR=util.get_project_dir(),
PROJECTSRC_DIR=util.get_projectsrc_dir(),
PIOENVS_DIR=util.get_pioenvs_dir(),
PIOBUILDER_DIR=join(util.get_source_dir(), "builder"),

View File

@ -38,10 +38,10 @@ def ProcessGeneral(env):
def BuildFirmware(env, corelibs):
firmenv = env.Clone()
vdirs = firmenv.VariantDirRecursive(
join("$BUILD_DIR", "src"), join("$PROJECT_DIR", "src"))
join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR")
# build dependent libs
deplibs = firmenv.BuildDependentLibraries(join("$PROJECT_DIR", "src"))
deplibs = firmenv.BuildDependentLibraries("$PROJECTSRC_DIR")
# append specified LD_SCRIPT
if "LDSCRIPT_PATH" in firmenv:
@ -255,8 +255,8 @@ def ConvertInoToCpp(env):
remove(f)
tmpcpp = []
items = (env.Glob(join("$PROJECT_DIR", "src", "*.ino")) +
env.Glob(join("$PROJECT_DIR", "src", "*.pde")))
items = (env.Glob(join("$PROJECTSRC_DIR", "*.ino")) +
env.Glob(join("$PROJECTSRC_DIR", "*.pde")))
for item in items:
cppfile = item.get_path()[:-3] + "cpp"
if isfile(cppfile):

View File

@ -56,16 +56,22 @@ def get_systype():
return ("%s_%s" % (data[0], data[4])).lower()
def get_home_dir():
home_dir = None
def _get_projconf_option_dir(option_name):
try:
config = get_project_config()
if (config.has_section("platformio") and
config.has_option("platformio", "home_dir")):
home_dir = config.get("platformio", "home_dir")
config.has_option("platformio", option_name)):
option_dir = config.get("platformio", option_name)
if option_dir.startswith("~"):
option_dir = expanduser(option_dir)
return abspath(option_dir)
except exception.NotPlatformProject:
pass
return None
def get_home_dir():
home_dir = _get_projconf_option_dir("home_dir")
if not home_dir:
home_dir = join(expanduser("~"), ".platformio")
@ -78,17 +84,12 @@ def get_home_dir():
def get_lib_dir():
try:
config = get_project_config()
if (config.has_section("platformio") and
config.has_option("platformio", "lib_dir")):
lib_dir = config.get("platformio", "lib_dir")
if lib_dir.startswith("~"):
lib_dir = expanduser(lib_dir)
return abspath(lib_dir)
except exception.NotPlatformProject:
pass
return join(get_home_dir(), "lib")
lib_dir = _get_projconf_option_dir("lib_dir")
if not lib_dir:
lib_dir = join(get_home_dir(), "lib")
return lib_dir
def get_source_dir():
@ -99,6 +100,15 @@ def get_project_dir():
return os.getcwd()
def get_projectsrc_dir():
src_dir = _get_projconf_option_dir("src_dir")
if not src_dir:
src_dir = join(get_project_dir(), "src")
return src_dir
def get_pioenvs_dir():
return os.getenv("PIOENVS_DIR", join(get_project_dir(), ".pioenvs"))