diff --git a/HISTORY.rst b/HISTORY.rst index 10cdc7bc..429d8bad 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -14,6 +14,10 @@ Release History `#48 `_, `#50 `_, `#55 `_) +* Added `src_dir `__ + option to ``[platformio]`` section of + `platformio.ini `__ + which allows to redefine location to project's source directory * Added ``--json-output`` option to `platformio boards `__ and `platformio search `__ diff --git a/docs/projectconf.rst b/docs/projectconf.rst index 848bf6e3..6f531002 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -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 `__ project with own source directory. + [env:NAME] ---------- diff --git a/examples/atmelavr-and-arduino/arduino-own-src_dir/Blink/Blink.ino b/examples/atmelavr-and-arduino/arduino-own-src_dir/Blink/Blink.ino new file mode 100644 index 00000000..5408ce67 --- /dev/null +++ b/examples/atmelavr-and-arduino/arduino-own-src_dir/Blink/Blink.ino @@ -0,0 +1,22 @@ +/** + * Copyright (C) Ivan Kravets + * 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 +} diff --git a/examples/atmelavr-and-arduino/arduino-own-src_dir/README.rst b/examples/atmelavr-and-arduino/arduino-own-src_dir/README.rst new file mode 100644 index 00000000..02a88a40 --- /dev/null +++ b/examples/atmelavr-and-arduino/arduino-own-src_dir/README.rst @@ -0,0 +1,21 @@ +How to buid PlatformIO based project +==================================== + +1. `Install PlatformIO `_ +2. Download `source code with examples `_ +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 diff --git a/examples/atmelavr-and-arduino/arduino-own-src_dir/platformio.ini b/examples/atmelavr-and-arduino/arduino-own-src_dir/platformio.ini new file mode 100644 index 00000000..6a2952f0 --- /dev/null +++ b/examples/atmelavr-and-arduino/arduino-own-src_dir/platformio.ini @@ -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 diff --git a/examples/wiring-blink/src/main.cpp b/examples/wiring-blink/src/main.cpp index a97b5156..15159de9 100644 --- a/examples/wiring-blink/src/main.cpp +++ b/examples/wiring-blink/src/main.cpp @@ -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 diff --git a/platformio/builder/main.py b/platformio/builder/main.py index 1adf0589..5fcc2d51 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -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"), diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 6955a252..0952a0d7 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -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): diff --git a/platformio/util.py b/platformio/util.py index 0e410ba3..bee67da9 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -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"))