Decentralized architecture for development platforms // Issue #479

This commit is contained in:
Ivan Kravets committed 2016-05-26 19:43:36 +03:00
1 parent 349b159a7b
commit d68eb28629
40 files changed
+1269 -1042

No files matched your search

+10 -50
View File
@@ -1,4 +1,4 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
# Copyright 2014-present Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -22,23 +22,18 @@ from time import time
from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, Variables
from platformio import util
from platformio.exception import UnknownBoard
# AllowSubstExceptions()
# allow common variables from INI file
commonvars = Variables(None)
commonvars.AddVariables(
("PLATFORM_MANIFEST",),
("BUILD_SCRIPT",),
("EXTRA_SCRIPT",),
("PIOENV",),
("PLATFORM",),
# package aliases
("PIOPACKAGE_TOOLCHAIN",),
("PIOPACKAGE_FRAMEWORK",),
("PIOPACKAGE_UPLOADER",),
# options
("FRAMEWORK",),
("BUILD_FLAGS",),
@@ -67,9 +62,9 @@ commonvars.AddVariables(
DefaultEnvironment(
tools=[
"gcc", "g++", "as", "ar", "gnulink",
"platformio", "pioupload", "pioar", "piomisc"
"platformio", "devplatform", "pioupload", "pioar", "piomisc"
],
toolpath=[join("$PIOBUILDER_DIR", "tools")],
toolpath=[join(util.get_source_dir(), "builder", "tools")],
variables=commonvars,
# Propagating External Environment
@@ -85,15 +80,11 @@ DefaultEnvironment(
PROJECTDATA_DIR=util.get_projectdata_dir(),
PIOENVS_DIR=util.get_pioenvs_dir(),
PIOBUILDER_DIR=join(util.get_source_dir(), "builder"),
PIOPACKAGES_DIR=join("$PIOHOME_DIR", "packages"),
BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"),
BUILDSRC_DIR=join("$BUILD_DIR", "src"),
LIBSOURCE_DIRS=[
"$PROJECTLIB_DIR",
util.get_lib_dir(),
join("$PLATFORMFW_DIR", "libraries")
util.get_lib_dir()
],
PYTHONEXE=normpath(sys.executable)
@@ -106,58 +97,27 @@ for k in commonvars.keys():
if k in env:
env[k] = base64.b64decode(env[k])
env.Prepend(LIBPATH=[join("$PIOPACKAGES_DIR", "ldscripts")])
if "BOARD" in env:
try:
env.Replace(BOARD_OPTIONS=util.get_boards(env.subst("$BOARD")))
except UnknownBoard as e:
env.Exit("Error: %s" % str(e))
for k in commonvars.keys():
if (k in env or
not any([k.startswith("BOARD_"), k.startswith("UPLOAD_")])):
continue
_opt, _val = k.lower().split("_", 1)
if _opt == "board":
_opt = "build"
if _val in env['BOARD_OPTIONS'][_opt]:
env.Replace(**{k: "${BOARD_OPTIONS['%s']['%s']}" % (_opt, _val)})
if "ldscript" in env.get("BOARD_OPTIONS", {}).get("build", {}):
env.Replace(
LDSCRIPT_PATH="${BOARD_OPTIONS['build']['ldscript']}"
)
if env['PLATFORM'] != env.get("BOARD_OPTIONS", {}).get("platform"):
env.Exit(
"Error: '%s' platform doesn't support this board. "
"Use '%s' platform instead." % (
env['PLATFORM'], env.get("BOARD_OPTIONS", {}).get("platform")))
env.LoadDevPlatform(commonvars)
# Parse library names
for opt in ("LIB_IGNORE", "LIB_USE"):
if opt not in env:
continue
env[opt] = [l.strip() for l in env[opt].split(",") if l.strip()]
if env.subst("$PIOPACKAGE_TOOLCHAIN"):
env.PrependENVPath(
"PATH",
env.subst(join("$PIOPACKAGES_DIR", "$PIOPACKAGE_TOOLCHAIN", "bin"))
)
# handle custom variable from system environment
# Handle custom variables from system environment
for var in ("BUILD_FLAGS", "SRC_BUILD_FLAGS", "SRC_FILTER", "EXTRA_SCRIPT",
"UPLOAD_PORT", "UPLOAD_FLAGS"):
k = "PLATFORMIO_%s" % var
if environ.get(k):
env[var] = environ.get(k)
env.SConscriptChdir(0)
env.SConsignFile(join("$PIOENVS_DIR", ".sconsign.dblite"))
env.SConscript("$BUILD_SCRIPT")
if "UPLOAD_FLAGS" in env:
env.Append(UPLOADERFLAGS=["$UPLOAD_FLAGS"])
+107
View File
@@ -0,0 +1,107 @@
# Copyright 2014-present Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from os.path import isdir, isfile, join
from SCons.Script import COMMAND_LINE_TARGETS
from platformio import exception, util
from platformio.managers.platform import PlatformFactory
@util.memoized
def initDevPlatform(name):
return PlatformFactory.newPlatform(name)
def DevPlatform(env):
variables = {}
for key in ("board", "framework"):
if key not in env:
continue
variables[key] = env[key.upper()]
p = initDevPlatform(env['PLATFORM_MANIFEST'])
p.configure_default_packages(variables, COMMAND_LINE_TARGETS)
return p
def BoardConfig(env, board=None):
p = initDevPlatform(env['PLATFORM_MANIFEST'])
try:
config = p.board_config(board if board else env['BOARD'])
except exception.UnknownBoard as e:
env.Exit("Error: %s" % str(e))
return config
def GetFrameworkScript(env, framework):
p = env.DevPlatform()
frameworks = p.get_frameworks()
assert frameworks and framework in frameworks
script_path = env.subst(frameworks[framework]['script'])
if not isfile(script_path):
script_path = join(p.get_dir(), script_path)
return script_path
def LoadDevPlatform(env, variables):
p = env.DevPlatform()
installed_packages = p.get_installed_packages()
# Add toolchains and uploaders to $PATH
for name in installed_packages.keys():
type_ = p.get_package_type(name)
if type_ not in ("toolchain", "uploader"):
continue
path = p.get_package_dir(name)
if isdir(join(path, "bin")):
path = join(path, "bin")
env.PrependENVPath("PATH", path)
# Platform specific LD Scripts
if isdir(join(p.get_dir(), "ldscripts")):
env.Prepend(LIBPATH=[join(p.get_dir(), "ldscripts")])
if "BOARD" not in env:
return
board_config = env.BoardConfig()
for k in variables.keys():
if (k in env or
not any([k.startswith("BOARD_"), k.startswith("UPLOAD_")])):
continue
_opt, _val = k.lower().split("_", 1)
if _opt == "board":
_opt = "build"
if _val in board_config.get(_opt):
env.Replace(**{k: board_config.get("%s.%s" % (_opt, _val))})
if "build.ldscript" in board_config:
env.Replace(
LDSCRIPT_PATH=board_config.get("build.ldscript")
)
def exists(_):
return True
def generate(env):
env.AddMethod(DevPlatform)
env.AddMethod(BoardConfig)
env.AddMethod(GetFrameworkScript)
env.AddMethod(LoadDevPlatform)
return env
+21 -20
View File
@@ -1,4 +1,4 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
# Copyright 2014-present Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ from glob import glob
from os import environ, listdir, remove
from os.path import isdir, isfile, join
from platformio.util import exec_command, where_is_program
from platformio import util
class InoToCPPConverter(object):
@@ -143,8 +143,6 @@ def ConvertInoToCpp(env):
def DumpIDEData(env):
BOARD_CORE = env.get("BOARD_OPTIONS", {}).get("build", {}).get("core")
def get_includes(env_):
includes = []
# includes from used framework and libs
@@ -164,15 +162,18 @@ def DumpIDEData(env):
lsd_dir = env_.subst(d)
_append_lib_includes(env_, lsd_dir, includes)
# includes from toolchain
toolchain_dir = env_.subst(
join("$PIOPACKAGES_DIR", "$PIOPACKAGE_TOOLCHAIN"))
toolchain_incglobs = [
join(toolchain_dir, "*", "include*"),
join(toolchain_dir, "lib", "gcc", "*", "*", "include*")
]
for g in toolchain_incglobs:
includes.extend(glob(g))
# includes from toolchains
p = env.DevPlatform()
for name in p.get_installed_packages().keys():
if p.get_package_type(name) != "toolchain":
continue
toolchain_dir = p.get_package_dir(name)
toolchain_incglobs = [
join(toolchain_dir, "*", "include*"),
join(toolchain_dir, "lib", "gcc", "*", "*", "include*")
]
for g in toolchain_incglobs:
includes.extend(glob(g))
return includes
@@ -186,9 +187,10 @@ def DumpIDEData(env):
if name in env_.get("LIB_IGNORE", []):
continue
if name == "__cores__":
if isdir(join(libs_dir, name, BOARD_CORE)):
board_core = env_.BoardConfig().get("build.core")
if isdir(join(libs_dir, name, board_core)):
_append_lib_includes(
env_, join(libs_dir, name, BOARD_CORE), includes)
env_, join(libs_dir, name, board_core), includes)
return
include = (
@@ -208,10 +210,9 @@ def DumpIDEData(env):
defines.append(env_.subst(item).replace('\\"', '"'))
# special symbol for Atmel AVR MCU
board = env_.get("BOARD_OPTIONS", {})
if board and board['platform'] == "atmelavr":
if env.subst("$PLATFORM") == "atmelavr":
defines.append(
"__AVR_%s__" % board['build']['mcu'].upper()
"__AVR_%s__" % env.BoardConfig().get("build.mcu").upper()
.replace("ATMEGA", "ATmega")
.replace("ATTINY", "ATtiny")
)
@@ -226,7 +227,7 @@ def DumpIDEData(env):
"includes": get_includes(env_),
"cc_flags": env_.subst(LINTCCOM),
"cxx_flags": env_.subst(LINTCXXCOM),
"cxx_path": where_is_program(
"cxx_path": util.where_is_program(
env_.subst("$CXX"), env_.subst("${ENV['PATH']}"))
}
@@ -254,7 +255,7 @@ def GetCompilerType(env):
try:
sysenv = environ.copy()
sysenv['PATH'] = str(env['ENV']['PATH'])
result = exec_command([env.subst("$CC"), "-v"], env=sysenv)
result = util.exec_command([env.subst("$CC"), "-v"], env=sysenv)
except OSError:
return None
if result['returncode'] != 0:
+7 -5
View File
@@ -1,4 +1,4 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
# Copyright 2014-present Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -83,14 +83,16 @@ def AutodetectUploadPort(env):
env.Replace(UPLOAD_PORT=item['disk'])
break
else:
board_build_opts = env.get("BOARD_OPTIONS", {}).get("build", {})
board_hwids = []
if "BOARD" in env and "build.hwids" in env.BoardConfig():
board_hwids = env.BoardConfig().get("build.hwids")
for item in get_serialports():
if "VID:PID" not in item['hwid']:
continue
env.Replace(UPLOAD_PORT=item['port'])
for hwid in board_build_opts.get("hwid", []):
board_hwid = ("%s:%s" % (hwid[0], hwid[1])).replace("0x", "")
if board_hwid in item['hwid']:
for hwid in board_hwids:
hwid_str = ("%s:%s" % (hwid[0], hwid[1])).replace("0x", "")
if hwid_str in item['hwid']:
break
if "UPLOAD_PORT" in env:
+8 -8
View File
@@ -1,4 +1,4 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
# Copyright 2014-present Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -43,9 +43,8 @@ def BuildProgram(env):
)
# process extra flags from board
env.ProcessFlags([
env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags")
])
if "BOARD" in env and "build.extra_flags" in env.BoardConfig():
env.ProcessFlags([env.BoardConfig().get("build.extra_flags")])
# remove base flags
env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))
# apply user flags
@@ -208,20 +207,21 @@ def BuildFrameworks(env, frameworks):
if not frameworks or "uploadlazy" in COMMAND_LINE_TARGETS:
return
board_frameworks = env.get("BOARD_OPTIONS", {}).get("frameworks", [])
board_frameworks = []
if "BOARD" in env:
board_frameworks = env.BoardConfig().get("frameworks", [])
if frameworks == ["platformio"]:
if board_frameworks:
frameworks.insert(0, board_frameworks[0])
else:
env.Exit("Error: Please specify board type")
env.Exit("Error: Please specify `board` in `platformio.ini`")
for f in frameworks:
if f in ("arduino", "energia"):
env.ConvertInoToCpp()
if f in board_frameworks:
SConscript(env.subst(
join("$PIOBUILDER_DIR", "scripts", "frameworks", "%s.py" % f)))
SConscript(env.GetFrameworkScript(f))
else:
env.Exit("Error: This board doesn't support %s framework!" % f)