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

+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)