Allow to launch own extra script before firmware building/uploading processes // Resolve #239

This commit is contained in:
Ivan Kravets
2015-06-19 15:29:22 +03:00
parent 8e95bfb464
commit 829d5781a5
6 changed files with 80 additions and 31 deletions

View File

@ -4,10 +4,13 @@ Release History
2.2.0 (2015-??-??) 2.2.0 (2015-??-??)
------------------ ------------------
* Allowed to specify own path to the linker script (ld) using * Launch own extra script before firmware building/uploading processes
`build_flags <http://docs.platformio.org/en/latest/projectconf.html#build-flags>`__ option (`issue #239 <https://github.com/platformio/platformio/issues/239>`_)
* Specify own path to the linker script (ld) using
`build_flags <http://docs.platformio.org/en/latest/projectconf.html#build-flags>`__
option
(`issue #233 <https://github.com/platformio/platformio/issues/233>`_) (`issue #233 <https://github.com/platformio/platformio/issues/233>`_)
* Allowed to specify library compatibility with the all platforms/frameworks * Specify library compatibility with the all platforms/frameworks
using ``*`` symbol in using ``*`` symbol in
`library.json <http://docs.platformio.org/en/latest/librarymanager/config.html>`__ `library.json <http://docs.platformio.org/en/latest/librarymanager/config.html>`__
* Fixed ``stk500v2_command(): command failed`` * Fixed ``stk500v2_command(): command failed``

View File

@ -84,6 +84,13 @@ PLATFORMIO_LDF_CYCLIC
Allows to set :ref:`projectconf` option :ref:`projectconf_ldf_cyclic`. Allows to set :ref:`projectconf` option :ref:`projectconf_ldf_cyclic`.
.. _envvar_PLATFORMIO_EXTRA_SCRIPT:
PLATFORMIO_EXTRA_SCRIPT
~~~~~~~~~~~~~~~~~~~~~~~
Allows to set :ref:`projectconf` option :ref:`projectconf_extra_script`.
Settings Settings
-------- --------

View File

@ -384,6 +384,43 @@ Example:
[env:libs_with_enabled_ldf_cyclic] [env:libs_with_enabled_ldf_cyclic]
ldf_cyclic = True ldf_cyclic = True
.. _projectconf_extra_script:
``extra_script``
^^^^^^^^^^^^^^^^
Allows to launch extra script using `SCons <http://www.scons.org>`_ software
construction tool. For more details please follow to "Construction Environments"
section of
`SCons documentation <http://www.scons.org/doc/production/HTML/scons-user.html#chap-environments>`_.
This option can be set by global environment variable
:ref:`envvar_PLATFORMIO_EXTRA_SCRIPT`.
Example, specify own upload command for :ref:`platform_atmelavr`:
``platformio.ini``:
.. code-block:: ini
[env:env_with_specific_extra_script]
platform = atmelavr
extra_script = /path/to/extra_script.py
``extra_script.py``:
.. code-block:: python
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Replace(UPLOADHEXCMD='"$UPLOADER" --uploader --flags')
# uncomment line below to see environment variables
# print env.Dump()
See built-in examples of `PlatformIO build scripts <https://github.com/platformio/platformio/tree/develop/platformio/builder/scripts>`_.
.. _projectconf_examples: .. _projectconf_examples:

View File

@ -1,7 +1,7 @@
# Copyright (C) Ivan Kravets <me@ikravets.com> # Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details. # See LICENSE for details.
VERSION = (2, 2, "0.dev1") VERSION = (2, 2, "0.dev2")
__version__ = ".".join([str(s) for s in VERSION]) __version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio" __title__ = "platformio"

View File

@ -11,11 +11,13 @@ except ImportError:
break break
from platformio import util from platformio import util
import json
from os import getenv
from os.path import isfile, join from os.path import isfile, join
from time import time from time import time
from SCons.Script import (DefaultEnvironment, Exit, SConscript, from SCons.Script import (COMMAND_LINE_TARGETS, DefaultEnvironment, Exit,
SConscriptChdir, Variables) SConscript, SConscriptChdir, Variables)
from platformio.exception import UnknownBoard from platformio.exception import UnknownBoard
@ -25,6 +27,7 @@ from platformio.exception import UnknownBoard
commonvars = Variables(None) commonvars = Variables(None)
commonvars.AddVariables( commonvars.AddVariables(
("BUILD_SCRIPT",), ("BUILD_SCRIPT",),
("EXTRA_SCRIPT",),
("PIOENV",), ("PIOENV",),
("PLATFORM",), ("PLATFORM",),
@ -123,3 +126,14 @@ env.PrependENVPath(
SConscriptChdir(0) SConscriptChdir(0)
SConscript(env.subst("$BUILD_SCRIPT")) SConscript(env.subst("$BUILD_SCRIPT"))
if getenv("PLATFORMIO_EXTRA_SCRIPT", env.get("EXTRA_SCRIPT", None)):
SConscript(getenv("PLATFORMIO_EXTRA_SCRIPT", env.get("EXTRA_SCRIPT")))
if "envdump" in COMMAND_LINE_TARGETS:
print env.Dump()
Exit()
if "idedata" in COMMAND_LINE_TARGETS:
print json.dumps(env.DumpIDEData())
Exit()

View File

@ -2,14 +2,12 @@
# See LICENSE for details. # See LICENSE for details.
import atexit import atexit
import json
import re import re
from glob import glob from glob import glob
from os import getenv, listdir, remove, sep, walk from os import getenv, listdir, remove, sep, walk
from os.path import basename, dirname, isdir, isfile, join, normpath from os.path import basename, dirname, isdir, isfile, join, normpath
from SCons.Script import (COMMAND_LINE_TARGETS, DefaultEnvironment, Exit, from SCons.Script import DefaultEnvironment, Exit, SConscript
SConscript, SConscriptChdir)
from SCons.Util import case_sensitive_suffixes from SCons.Util import case_sensitive_suffixes
from platformio.util import pioversion_to_intstr from platformio.util import pioversion_to_intstr
@ -27,50 +25,41 @@ def BuildFirmware(env):
env.ProcessFlags() env.ProcessFlags()
env.BuildFramework() env.BuildFramework()
firmenv = env.Clone() vdirs = env.VariantDirRecursive(
vdirs = firmenv.VariantDirRecursive(
join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR", duplicate=False) join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR", duplicate=False)
# build dependent libs # build dependent libs
deplibs = firmenv.BuildDependentLibraries("$PROJECTSRC_DIR") deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")
# append specified LD_SCRIPT # append specified LD_SCRIPT
if ("LDSCRIPT_PATH" in firmenv and if ("LDSCRIPT_PATH" in env and
not any(["-Wl,-T" in f for f in firmenv['LINKFLAGS']])): not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
firmenv.Append( env.Append(
LINKFLAGS=["-Wl,-T", "$LDSCRIPT_PATH"] LINKFLAGS=["-Wl,-T", "$LDSCRIPT_PATH"]
) )
# enable "cyclic reference" for linker # enable "cyclic reference" for linker
firmenv.Prepend( env.Prepend(
_LIBFLAGS="-Wl,--start-group " _LIBFLAGS="-Wl,--start-group "
) )
firmenv.Append( env.Append(
_LIBFLAGS=" -Wl,--end-group" _LIBFLAGS=" -Wl,--end-group"
) )
# Handle SRCBUILD_FLAGS # Handle SRCBUILD_FLAGS
if getenv("PLATFORMIO_SRCBUILD_FLAGS", None): if getenv("PLATFORMIO_SRCBUILD_FLAGS", None):
firmenv.MergeFlags(getenv("PLATFORMIO_SRCBUILD_FLAGS")) env.MergeFlags(getenv("PLATFORMIO_SRCBUILD_FLAGS"))
if "SRCBUILD_FLAGS" in env: if "SRCBUILD_FLAGS" in env:
firmenv.MergeFlags(env['SRCBUILD_FLAGS']) env.MergeFlags(env['SRCBUILD_FLAGS'])
firmenv.Append( env.Append(
CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format( CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(
*pioversion_to_intstr())] *pioversion_to_intstr())]
) )
if "envdump" in COMMAND_LINE_TARGETS: return env.Program(
print env.Dump()
Exit()
if "idedata" in COMMAND_LINE_TARGETS:
print json.dumps(env.DumpIDEData())
Exit()
return firmenv.Program(
join("$BUILD_DIR", "firmware"), join("$BUILD_DIR", "firmware"),
[firmenv.GlobCXXFiles(vdir) for vdir in vdirs], [env.GlobCXXFiles(vdir) for vdir in vdirs],
LIBS=env.get("LIBS", []) + deplibs, LIBS=env.get("LIBS", []) + deplibs,
LIBPATH=env.get("LIBPATH", []) + ["$BUILD_DIR"], LIBPATH=env.get("LIBPATH", []) + ["$BUILD_DIR"],
PROGSUFFIX=".elf" PROGSUFFIX=".elf"
@ -136,7 +125,6 @@ def BuildFramework(env):
for f in env['FRAMEWORK'].split(","): for f in env['FRAMEWORK'].split(","):
framework = f.strip().lower() framework = f.strip().lower()
if framework in env.get("BOARD_OPTIONS", {}).get("frameworks"): if framework in env.get("BOARD_OPTIONS", {}).get("frameworks"):
SConscriptChdir(0)
SConscript( SConscript(
env.subst(join("$PIOBUILDER_DIR", "scripts", "frameworks", env.subst(join("$PIOBUILDER_DIR", "scripts", "frameworks",
"%s.py" % framework)) "%s.py" % framework))