2017-06-05 16:02:39 +03:00
|
|
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
2015-11-18 17:16:17 +02:00
|
|
|
#
|
|
|
|
|
# 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.
|
2014-05-18 23:38:59 +03:00
|
|
|
|
2021-03-17 21:08:06 +02:00
|
|
|
import json
|
|
|
|
|
import os
|
2019-10-16 12:09:53 +03:00
|
|
|
import sys
|
2015-02-15 18:18:11 +02:00
|
|
|
from time import time
|
2014-05-18 23:38:59 +03:00
|
|
|
|
2019-06-13 13:08:53 +03:00
|
|
|
import click
|
2019-05-07 21:16:42 +03:00
|
|
|
from SCons.Script import ARGUMENTS # pylint: disable=import-error
|
|
|
|
|
from SCons.Script import COMMAND_LINE_TARGETS # pylint: disable=import-error
|
|
|
|
|
from SCons.Script import DEFAULT_TARGETS # pylint: disable=import-error
|
|
|
|
|
from SCons.Script import AllowSubstExceptions # pylint: disable=import-error
|
|
|
|
|
from SCons.Script import AlwaysBuild # pylint: disable=import-error
|
|
|
|
|
from SCons.Script import Default # pylint: disable=import-error
|
|
|
|
|
from SCons.Script import DefaultEnvironment # pylint: disable=import-error
|
2019-05-24 16:06:27 +03:00
|
|
|
from SCons.Script import Import # pylint: disable=import-error
|
2019-05-07 21:16:42 +03:00
|
|
|
from SCons.Script import Variables # pylint: disable=import-error
|
2014-05-18 23:38:59 +03:00
|
|
|
|
2020-05-19 22:37:05 +03:00
|
|
|
from platformio import compat, fs
|
2020-08-14 16:39:15 +03:00
|
|
|
from platformio.platform.base import PlatformBase
|
2019-05-16 21:03:15 +03:00
|
|
|
from platformio.proc import get_pythonexe_path
|
2019-09-27 14:13:53 +03:00
|
|
|
from platformio.project.helpers import get_project_dir
|
2015-02-15 18:02:59 +02:00
|
|
|
|
2016-07-17 00:48:59 +03:00
|
|
|
AllowSubstExceptions(NameError)
|
2014-05-18 23:38:59 +03:00
|
|
|
|
2019-05-30 17:08:00 +03:00
|
|
|
# append CLI arguments to build environment
|
|
|
|
|
clivars = Variables(None)
|
|
|
|
|
clivars.AddVariables(
|
2016-05-26 19:43:36 +03:00
|
|
|
("PLATFORM_MANIFEST",),
|
2014-11-22 23:55:17 +02:00
|
|
|
("BUILD_SCRIPT",),
|
2019-05-30 17:08:00 +03:00
|
|
|
("PROJECT_CONFIG",),
|
2014-05-18 23:38:59 +03:00
|
|
|
("PIOENV",),
|
2019-05-31 15:47:25 +03:00
|
|
|
("PIOTEST_RUNNING_NAME",),
|
2019-09-23 23:13:48 +03:00
|
|
|
("UPLOAD_PORT",),
|
2022-05-07 16:22:05 +03:00
|
|
|
("PROGRAM_ARGS",),
|
2019-09-27 14:13:53 +03:00
|
|
|
)
|
2014-05-18 23:38:59 +03:00
|
|
|
|
2016-08-27 19:30:38 +03:00
|
|
|
DEFAULT_ENV_OPTIONS = dict(
|
2015-03-04 21:21:10 +02:00
|
|
|
tools=[
|
2019-09-23 23:13:48 +03:00
|
|
|
"ar",
|
2019-11-15 15:10:43 +02:00
|
|
|
"cc",
|
|
|
|
|
"c++",
|
|
|
|
|
"link",
|
2022-04-10 19:21:03 +03:00
|
|
|
"pioasm",
|
2019-09-23 23:13:48 +03:00
|
|
|
"platformio",
|
|
|
|
|
"pioproject",
|
2022-04-21 18:11:49 +03:00
|
|
|
"pioplatform",
|
|
|
|
|
"piotest",
|
|
|
|
|
"piotarget",
|
2019-10-02 23:46:42 +03:00
|
|
|
"piomaxlen",
|
2019-09-23 23:13:48 +03:00
|
|
|
"piolib",
|
|
|
|
|
"pioupload",
|
2022-04-21 18:11:49 +03:00
|
|
|
"piosize",
|
|
|
|
|
"pioino",
|
2019-09-23 23:13:48 +03:00
|
|
|
"piomisc",
|
2022-04-09 12:53:22 +03:00
|
|
|
"piointegration",
|
2019-05-30 17:08:00 +03:00
|
|
|
],
|
2021-03-17 21:08:06 +02:00
|
|
|
toolpath=[os.path.join(fs.get_source_dir(), "builder", "tools")],
|
2019-05-30 17:08:00 +03:00
|
|
|
variables=clivars,
|
2015-08-03 15:08:54 +03:00
|
|
|
# Propagating External Environment
|
2021-03-17 21:08:06 +02:00
|
|
|
ENV=os.environ,
|
2015-02-15 18:18:11 +02:00
|
|
|
UNIX_TIME=int(time()),
|
2021-03-17 21:08:06 +02:00
|
|
|
BUILD_DIR=os.path.join("$PROJECT_BUILD_DIR", "$PIOENV"),
|
|
|
|
|
BUILD_SRC_DIR=os.path.join("$BUILD_DIR", "src"),
|
|
|
|
|
BUILD_TEST_DIR=os.path.join("$BUILD_DIR", "test"),
|
2022-04-09 12:53:22 +03:00
|
|
|
COMPILATIONDB_PATH=os.path.join("$PROJECT_DIR", "compile_commands.json"),
|
2018-05-14 22:13:42 -07:00
|
|
|
LIBPATH=["$BUILD_DIR"],
|
2017-03-31 18:55:19 +03:00
|
|
|
PROGNAME="program",
|
2021-03-17 21:08:06 +02:00
|
|
|
PROG_PATH=os.path.join("$BUILD_DIR", "$PROGNAME$PROGSUFFIX"),
|
2019-09-23 23:13:48 +03:00
|
|
|
PYTHONEXE=get_pythonexe_path(),
|
2020-10-26 18:23:28 +02:00
|
|
|
IDE_EXTRA_DATA={},
|
2019-09-23 23:13:48 +03:00
|
|
|
)
|
2014-05-18 23:38:59 +03:00
|
|
|
|
2021-01-27 16:10:13 +02:00
|
|
|
# Declare command verbose messages
|
|
|
|
|
command_strings = dict(
|
|
|
|
|
ARCOM="Archiving",
|
|
|
|
|
LINKCOM="Linking",
|
|
|
|
|
RANLIBCOM="Indexing",
|
|
|
|
|
ASCOM="Compiling",
|
|
|
|
|
ASPPCOM="Compiling",
|
|
|
|
|
CCCOM="Compiling",
|
|
|
|
|
CXXCOM="Compiling",
|
|
|
|
|
)
|
2016-08-27 19:30:38 +03:00
|
|
|
if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
|
2021-01-27 16:10:13 +02:00
|
|
|
for name, value in command_strings.items():
|
|
|
|
|
DEFAULT_ENV_OPTIONS["%sSTR" % name] = "%s $TARGET" % (value)
|
2016-08-27 19:30:38 +03:00
|
|
|
|
|
|
|
|
env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS)
|
2016-07-17 00:48:59 +03:00
|
|
|
|
2019-05-30 17:08:00 +03:00
|
|
|
# Load variables from CLI
|
2019-06-03 13:30:35 +03:00
|
|
|
env.Replace(
|
|
|
|
|
**{
|
|
|
|
|
key: PlatformBase.decode_scons_arg(env[key])
|
2019-09-23 23:13:48 +03:00
|
|
|
for key in list(clivars.keys())
|
|
|
|
|
if key in env
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-30 17:08:00 +03:00
|
|
|
|
2019-09-27 14:13:53 +03:00
|
|
|
# Setup project optional directories
|
|
|
|
|
config = env.GetProjectConfig()
|
|
|
|
|
env.Replace(
|
|
|
|
|
PROJECT_DIR=get_project_dir(),
|
2021-10-24 18:19:40 +03:00
|
|
|
PROJECT_CORE_DIR=config.get("platformio", "core_dir"),
|
|
|
|
|
PROJECT_PACKAGES_DIR=config.get("platformio", "packages_dir"),
|
|
|
|
|
PROJECT_WORKSPACE_DIR=config.get("platformio", "workspace_dir"),
|
|
|
|
|
PROJECT_LIBDEPS_DIR=config.get("platformio", "libdeps_dir"),
|
|
|
|
|
PROJECT_INCLUDE_DIR=config.get("platformio", "include_dir"),
|
|
|
|
|
PROJECT_SRC_DIR=config.get("platformio", "src_dir"),
|
2021-12-03 17:01:42 +02:00
|
|
|
PROJECTSRC_DIR="$PROJECT_SRC_DIR", # legacy for dev/platform
|
2021-10-24 18:19:40 +03:00
|
|
|
PROJECT_TEST_DIR=config.get("platformio", "test_dir"),
|
|
|
|
|
PROJECT_DATA_DIR=config.get("platformio", "data_dir"),
|
2021-12-02 22:16:37 +02:00
|
|
|
PROJECTDATA_DIR="$PROJECT_DATA_DIR", # legacy for dev/platform
|
2021-10-24 18:19:40 +03:00
|
|
|
PROJECT_BUILD_DIR=config.get("platformio", "build_dir"),
|
|
|
|
|
BUILD_CACHE_DIR=config.get("platformio", "build_cache_dir"),
|
2019-09-27 14:13:53 +03:00
|
|
|
LIBSOURCE_DIRS=[
|
2021-10-24 18:19:40 +03:00
|
|
|
config.get("platformio", "lib_dir"),
|
2021-03-17 21:08:06 +02:00
|
|
|
os.path.join("$PROJECT_LIBDEPS_DIR", "$PIOENV"),
|
2021-10-24 18:19:40 +03:00
|
|
|
config.get("platformio", "globallib_dir"),
|
2019-09-27 14:13:53 +03:00
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
2021-11-12 15:17:25 +02:00
|
|
|
if int(ARGUMENTS.get("ISATTY", 0)):
|
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
click._compat.isatty = lambda stream: True
|
|
|
|
|
|
|
|
|
|
if compat.IS_WINDOWS and sys.version_info >= (3, 8) and os.getcwd().startswith("\\\\"):
|
|
|
|
|
click.secho("!!! WARNING !!!\t\t" * 3, fg="red")
|
2020-05-19 22:37:05 +03:00
|
|
|
click.secho(
|
2021-11-12 15:17:25 +02:00
|
|
|
"Your project is located on a mapped network drive but the "
|
|
|
|
|
"current command-line shell does not support the UNC paths.",
|
|
|
|
|
fg="yellow",
|
|
|
|
|
)
|
|
|
|
|
click.secho(
|
|
|
|
|
"Please move your project to a physical drive or check this workaround: "
|
|
|
|
|
"https://bit.ly/3kuU5mP\n",
|
2020-05-20 20:57:55 +03:00
|
|
|
fg="yellow",
|
|
|
|
|
)
|
2020-05-19 22:37:05 +03:00
|
|
|
|
2019-09-27 14:13:53 +03:00
|
|
|
if env.subst("$BUILD_CACHE_DIR"):
|
2021-03-17 21:08:06 +02:00
|
|
|
if not os.path.isdir(env.subst("$BUILD_CACHE_DIR")):
|
|
|
|
|
os.makedirs(env.subst("$BUILD_CACHE_DIR"))
|
2019-09-27 14:13:53 +03:00
|
|
|
env.CacheDir("$BUILD_CACHE_DIR")
|
2019-06-15 18:53:13 +03:00
|
|
|
|
2021-10-08 19:02:45 +03:00
|
|
|
is_clean_all = "cleanall" in COMMAND_LINE_TARGETS
|
|
|
|
|
if env.GetOption("clean") or is_clean_all:
|
|
|
|
|
env.PioClean(is_clean_all)
|
2019-05-30 23:33:57 +03:00
|
|
|
env.Exit(0)
|
2021-10-08 19:02:45 +03:00
|
|
|
|
|
|
|
|
if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
|
2019-11-03 22:22:40 +02:00
|
|
|
click.echo("Verbose mode can be enabled via `-v, --verbose` option")
|
|
|
|
|
|
2020-02-06 17:19:48 +02:00
|
|
|
# Dynamically load dependent tools
|
|
|
|
|
if "compiledb" in COMMAND_LINE_TARGETS:
|
|
|
|
|
env.Tool("compilation_db")
|
|
|
|
|
|
2021-03-17 21:08:06 +02:00
|
|
|
if not os.path.isdir(env.subst("$BUILD_DIR")):
|
|
|
|
|
os.makedirs(env.subst("$BUILD_DIR"))
|
2019-05-30 23:33:57 +03:00
|
|
|
|
2019-05-30 17:08:00 +03:00
|
|
|
env.LoadProjectOptions()
|
|
|
|
|
env.LoadPioPlatform()
|
2016-05-26 19:43:36 +03:00
|
|
|
|
2015-12-05 23:21:16 +02:00
|
|
|
env.SConscriptChdir(0)
|
2019-10-16 12:09:53 +03:00
|
|
|
env.SConsignFile(
|
2021-03-17 21:08:06 +02:00
|
|
|
os.path.join(
|
|
|
|
|
"$BUILD_DIR", ".sconsign%d%d" % (sys.version_info[0], sys.version_info[1])
|
|
|
|
|
)
|
2019-10-16 12:09:53 +03:00
|
|
|
)
|
2017-06-30 00:15:49 +03:00
|
|
|
|
2018-03-20 19:24:05 +02:00
|
|
|
for item in env.GetExtraScripts("pre"):
|
2017-06-30 00:15:49 +03:00
|
|
|
env.SConscript(item, exports="env")
|
|
|
|
|
|
2015-12-05 23:21:16 +02:00
|
|
|
env.SConscript("$BUILD_SCRIPT")
|
2015-06-19 15:29:22 +03:00
|
|
|
|
2015-12-11 15:17:38 +02:00
|
|
|
if "UPLOAD_FLAGS" in env:
|
2018-05-05 21:15:50 +03:00
|
|
|
env.Prepend(UPLOADERFLAGS=["$UPLOAD_FLAGS"])
|
2019-06-01 14:36:07 +03:00
|
|
|
if env.GetProjectOption("upload_command"):
|
|
|
|
|
env.Replace(UPLOADCMD=env.GetProjectOption("upload_command"))
|
2015-12-11 15:17:38 +02:00
|
|
|
|
2018-03-20 19:24:05 +02:00
|
|
|
for item in env.GetExtraScripts("post"):
|
2017-06-30 00:15:49 +03:00
|
|
|
env.SConscript(item, exports="env")
|
2015-06-19 15:29:22 +03:00
|
|
|
|
2018-06-04 14:09:48 +03:00
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
|
# Checking program size
|
2020-02-05 18:15:44 +02:00
|
|
|
if env.get("SIZETOOL") and not (
|
|
|
|
|
set(["nobuild", "sizedata"]) & set(COMMAND_LINE_TARGETS)
|
|
|
|
|
):
|
2018-06-04 14:09:48 +03:00
|
|
|
env.Depends(["upload", "program"], "checkprogsize")
|
|
|
|
|
# Replace platform's "size" target with our
|
|
|
|
|
_new_targets = [t for t in DEFAULT_TARGETS if str(t) != "size"]
|
|
|
|
|
Default(None)
|
|
|
|
|
Default(_new_targets)
|
|
|
|
|
Default("checkprogsize")
|
|
|
|
|
|
2020-02-06 17:19:48 +02:00
|
|
|
if "compiledb" in COMMAND_LINE_TARGETS:
|
|
|
|
|
env.Alias("compiledb", env.CompilationDatabase("$COMPILATIONDB_PATH"))
|
|
|
|
|
|
2018-06-04 14:09:48 +03:00
|
|
|
# Print configured protocols
|
2019-09-23 23:13:48 +03:00
|
|
|
env.AddPreAction(
|
|
|
|
|
["upload", "program"],
|
|
|
|
|
env.VerboseAction(
|
|
|
|
|
lambda source, target, env: env.PrintUploadInfo(),
|
|
|
|
|
"Configuring upload protocol...",
|
|
|
|
|
),
|
|
|
|
|
)
|
2018-06-04 14:09:48 +03:00
|
|
|
|
2021-03-19 20:25:30 +02:00
|
|
|
AlwaysBuild(env.Alias("__debug", DEFAULT_TARGETS))
|
2018-06-04 14:09:48 +03:00
|
|
|
AlwaysBuild(env.Alias("__test", DEFAULT_TARGETS))
|
|
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
2015-06-19 15:29:22 +03:00
|
|
|
if "envdump" in COMMAND_LINE_TARGETS:
|
2019-11-03 22:22:40 +02:00
|
|
|
click.echo(env.Dump())
|
2016-09-02 18:45:19 +03:00
|
|
|
env.Exit(0)
|
2015-06-19 15:29:22 +03:00
|
|
|
|
2021-04-24 18:01:35 +03:00
|
|
|
if set(["_idedata", "idedata"]) & set(COMMAND_LINE_TARGETS):
|
2022-03-27 22:34:22 +03:00
|
|
|
projenv = None
|
2019-12-24 23:43:21 +02:00
|
|
|
try:
|
|
|
|
|
Import("projenv")
|
|
|
|
|
except: # pylint: disable=bare-except
|
|
|
|
|
projenv = env
|
2022-04-09 12:53:22 +03:00
|
|
|
data = projenv.DumpIntegrationData(env)
|
2022-05-14 16:29:41 +03:00
|
|
|
# dump to file for the further reading by project.helpers.load_build_metadata
|
2021-08-28 13:10:07 +03:00
|
|
|
with open(
|
|
|
|
|
projenv.subst(os.path.join("$BUILD_DIR", "idedata.json")),
|
|
|
|
|
mode="w",
|
|
|
|
|
encoding="utf8",
|
|
|
|
|
) as fp:
|
2021-03-19 13:46:27 +02:00
|
|
|
json.dump(data, fp)
|
|
|
|
|
click.echo("\n%s\n" % json.dumps(data)) # pylint: disable=undefined-variable
|
2019-06-03 17:44:41 +03:00
|
|
|
env.Exit(0)
|
2019-09-27 14:18:35 +03:00
|
|
|
|
|
|
|
|
if "sizedata" in COMMAND_LINE_TARGETS:
|
|
|
|
|
AlwaysBuild(
|
|
|
|
|
env.Alias(
|
2019-09-27 17:22:21 +03:00
|
|
|
"sizedata",
|
|
|
|
|
DEFAULT_TARGETS,
|
|
|
|
|
env.VerboseAction(env.DumpSizeData, "Generating memory usage report..."),
|
2019-09-27 14:18:35 +03:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Default("sizedata")
|