mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
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:
@ -14,6 +14,10 @@ Release History
|
|||||||
`#48 <https://github.com/ivankravets/platformio/issues/48>`_,
|
`#48 <https://github.com/ivankravets/platformio/issues/48>`_,
|
||||||
`#50 <https://github.com/ivankravets/platformio/issues/50>`_,
|
`#50 <https://github.com/ivankravets/platformio/issues/50>`_,
|
||||||
`#55 <https://github.com/ivankravets/platformio/issues/55>`_)
|
`#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
|
* Added ``--json-output`` option to
|
||||||
`platformio boards <http://docs.platformio.org/en/latest/userguide/cmd_boards.html>`__
|
`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>`__
|
and `platformio search <http://docs.platformio.org/en/latest/userguide/cmd_search.html>`__
|
||||||
|
@ -19,6 +19,12 @@ The sections and their allowable values are described below.
|
|||||||
|
|
||||||
A ``platformio`` section is used for overriding default configuration options
|
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
|
Options
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
|
||||||
@ -33,15 +39,27 @@ external libraries, service data and etc.
|
|||||||
A default value is user's home directory: *Unix* - ``~/.platformio``,
|
A default value is user's home directory: *Unix* - ``~/.platformio``,
|
||||||
Windows - ``%HOMEPATH%\.platformio``.
|
Windows - ``%HOMEPATH%\.platformio``.
|
||||||
|
|
||||||
|
|
||||||
``lib_dir``
|
``lib_dir``
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^
|
||||||
|
|
||||||
This directory is used to store external libraries downloaded by
|
This directory is used to store external libraries downloaded by
|
||||||
:ref:`librarymanager`.
|
:ref:`librarymanager`.
|
||||||
|
|
||||||
A default value is ``$PIO_HOME_DIR/lib``.
|
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]
|
[env:NAME]
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
}
|
21
examples/atmelavr-and-arduino/arduino-own-src_dir/README.rst
Normal file
21
examples/atmelavr-and-arduino/arduino-own-src_dir/README.rst
Normal 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
|
@ -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
|
@ -11,7 +11,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#ifndef LED_PIN
|
#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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ DefaultEnvironment(
|
|||||||
|
|
||||||
PIOHOME_DIR=util.get_home_dir(),
|
PIOHOME_DIR=util.get_home_dir(),
|
||||||
PROJECT_DIR=util.get_project_dir(),
|
PROJECT_DIR=util.get_project_dir(),
|
||||||
|
PROJECTSRC_DIR=util.get_projectsrc_dir(),
|
||||||
PIOENVS_DIR=util.get_pioenvs_dir(),
|
PIOENVS_DIR=util.get_pioenvs_dir(),
|
||||||
|
|
||||||
PIOBUILDER_DIR=join(util.get_source_dir(), "builder"),
|
PIOBUILDER_DIR=join(util.get_source_dir(), "builder"),
|
||||||
|
@ -38,10 +38,10 @@ def ProcessGeneral(env):
|
|||||||
def BuildFirmware(env, corelibs):
|
def BuildFirmware(env, corelibs):
|
||||||
firmenv = env.Clone()
|
firmenv = env.Clone()
|
||||||
vdirs = firmenv.VariantDirRecursive(
|
vdirs = firmenv.VariantDirRecursive(
|
||||||
join("$BUILD_DIR", "src"), join("$PROJECT_DIR", "src"))
|
join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR")
|
||||||
|
|
||||||
# build dependent libs
|
# build dependent libs
|
||||||
deplibs = firmenv.BuildDependentLibraries(join("$PROJECT_DIR", "src"))
|
deplibs = firmenv.BuildDependentLibraries("$PROJECTSRC_DIR")
|
||||||
|
|
||||||
# append specified LD_SCRIPT
|
# append specified LD_SCRIPT
|
||||||
if "LDSCRIPT_PATH" in firmenv:
|
if "LDSCRIPT_PATH" in firmenv:
|
||||||
@ -255,8 +255,8 @@ def ConvertInoToCpp(env):
|
|||||||
remove(f)
|
remove(f)
|
||||||
|
|
||||||
tmpcpp = []
|
tmpcpp = []
|
||||||
items = (env.Glob(join("$PROJECT_DIR", "src", "*.ino")) +
|
items = (env.Glob(join("$PROJECTSRC_DIR", "*.ino")) +
|
||||||
env.Glob(join("$PROJECT_DIR", "src", "*.pde")))
|
env.Glob(join("$PROJECTSRC_DIR", "*.pde")))
|
||||||
for item in items:
|
for item in items:
|
||||||
cppfile = item.get_path()[:-3] + "cpp"
|
cppfile = item.get_path()[:-3] + "cpp"
|
||||||
if isfile(cppfile):
|
if isfile(cppfile):
|
||||||
|
@ -56,16 +56,22 @@ def get_systype():
|
|||||||
return ("%s_%s" % (data[0], data[4])).lower()
|
return ("%s_%s" % (data[0], data[4])).lower()
|
||||||
|
|
||||||
|
|
||||||
def get_home_dir():
|
def _get_projconf_option_dir(option_name):
|
||||||
home_dir = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = get_project_config()
|
config = get_project_config()
|
||||||
if (config.has_section("platformio") and
|
if (config.has_section("platformio") and
|
||||||
config.has_option("platformio", "home_dir")):
|
config.has_option("platformio", option_name)):
|
||||||
home_dir = config.get("platformio", "home_dir")
|
option_dir = config.get("platformio", option_name)
|
||||||
|
if option_dir.startswith("~"):
|
||||||
|
option_dir = expanduser(option_dir)
|
||||||
|
return abspath(option_dir)
|
||||||
except exception.NotPlatformProject:
|
except exception.NotPlatformProject:
|
||||||
pass
|
pass
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_home_dir():
|
||||||
|
home_dir = _get_projconf_option_dir("home_dir")
|
||||||
|
|
||||||
if not home_dir:
|
if not home_dir:
|
||||||
home_dir = join(expanduser("~"), ".platformio")
|
home_dir = join(expanduser("~"), ".platformio")
|
||||||
@ -78,17 +84,12 @@ def get_home_dir():
|
|||||||
|
|
||||||
|
|
||||||
def get_lib_dir():
|
def get_lib_dir():
|
||||||
try:
|
lib_dir = _get_projconf_option_dir("lib_dir")
|
||||||
config = get_project_config()
|
|
||||||
if (config.has_section("platformio") and
|
if not lib_dir:
|
||||||
config.has_option("platformio", "lib_dir")):
|
lib_dir = join(get_home_dir(), "lib")
|
||||||
lib_dir = config.get("platformio", "lib_dir")
|
|
||||||
if lib_dir.startswith("~"):
|
return lib_dir
|
||||||
lib_dir = expanduser(lib_dir)
|
|
||||||
return abspath(lib_dir)
|
|
||||||
except exception.NotPlatformProject:
|
|
||||||
pass
|
|
||||||
return join(get_home_dir(), "lib")
|
|
||||||
|
|
||||||
|
|
||||||
def get_source_dir():
|
def get_source_dir():
|
||||||
@ -99,6 +100,15 @@ def get_project_dir():
|
|||||||
return os.getcwd()
|
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():
|
def get_pioenvs_dir():
|
||||||
return os.getenv("PIOENVS_DIR", join(get_project_dir(), ".pioenvs"))
|
return os.getenv("PIOENVS_DIR", join(get_project_dir(), ".pioenvs"))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user