Switch between Build Configurations (release and debug) with a new project configuration option build_type // Resolve #2184
This commit is contained in:
@@ -142,7 +142,6 @@ env.AddPreAction(
|
||||
"Configuring upload protocol..."))
|
||||
|
||||
AlwaysBuild(env.Alias("debug", DEFAULT_TARGETS))
|
||||
AlwaysBuild(env.Alias("__debug", DEFAULT_TARGETS))
|
||||
AlwaysBuild(env.Alias("__test", DEFAULT_TARGETS))
|
||||
|
||||
##############################################################################
|
||||
|
||||
@@ -298,7 +298,7 @@ def ProcessDebug(env):
|
||||
if not env.subst("$PIODEBUGFLAGS"):
|
||||
env.Replace(PIODEBUGFLAGS=["-Og", "-g3", "-ggdb3"])
|
||||
env.Append(BUILD_FLAGS=list(env['PIODEBUGFLAGS']) +
|
||||
["-D__PLATFORMIO_DEBUG__"])
|
||||
["-D__PLATFORMIO_BUILD_DEBUG__"])
|
||||
unflags = ["-Os"]
|
||||
for level in [0, 1, 2]:
|
||||
for flag in ("O", "g", "ggdb"):
|
||||
|
||||
@@ -69,7 +69,7 @@ def _build_project_deps(env):
|
||||
if is_test:
|
||||
projenv.BuildSources("$BUILDTEST_DIR", "$PROJECTTEST_DIR",
|
||||
"$PIOTEST_SRC_FILTER")
|
||||
if not is_test or env.get("TEST_BUILD_PROJECT_SRC") == "true":
|
||||
if not is_test or env.GetProjectOption("test_build_project_src", False):
|
||||
projenv.BuildSources("$BUILDSRC_DIR", "$PROJECTSRC_DIR",
|
||||
env.get("SRC_FILTER"))
|
||||
|
||||
@@ -97,7 +97,8 @@ def BuildProgram(env):
|
||||
if not Util.case_sensitive_suffixes(".s", ".S"):
|
||||
env.Replace(AS="$CC", ASCOM="$ASPPCOM")
|
||||
|
||||
if set(["__debug", "debug"]) & set(COMMAND_LINE_TARGETS):
|
||||
if ("debug" in COMMAND_LINE_TARGETS
|
||||
or env.GetProjectOption("build_type") == "debug"):
|
||||
env.ProcessDebug()
|
||||
|
||||
# process extra flags from board
|
||||
|
||||
@@ -21,7 +21,7 @@ from hashlib import sha1
|
||||
from io import BytesIO
|
||||
from os.path import isfile
|
||||
|
||||
from platformio import VERSION, exception, util
|
||||
from platformio import exception, util
|
||||
from platformio.commands.platform import \
|
||||
platform_install as cmd_platform_install
|
||||
from platformio.commands.run import cli as cmd_run
|
||||
@@ -49,7 +49,14 @@ def escape_path(path):
|
||||
|
||||
def get_default_debug_env(config):
|
||||
default_envs = config.default_envs()
|
||||
return default_envs[0] if default_envs else config.envs()[0]
|
||||
all_envs = config.envs()
|
||||
for env in default_envs:
|
||||
if config.get("env:" + env, "build_type") == "debug":
|
||||
return env
|
||||
for env in all_envs:
|
||||
if config.get("env:" + env, "build_type") == "debug":
|
||||
return env
|
||||
return default_envs[0] if default_envs else all_envs[0]
|
||||
|
||||
|
||||
def validate_debug_options(cmd_ctx, env_options):
|
||||
@@ -141,7 +148,7 @@ def predebug_project(ctx, project_dir, env_name, preload, verbose):
|
||||
ctx.invoke(cmd_run,
|
||||
project_dir=project_dir,
|
||||
environment=[env_name],
|
||||
target=["__debug"] + (["upload"] if preload else []),
|
||||
target=["debug"] + (["upload"] if preload else []),
|
||||
verbose=verbose)
|
||||
if preload:
|
||||
time.sleep(5)
|
||||
@@ -206,7 +213,7 @@ def has_debug_symbols(prog_path):
|
||||
b".debug_abbrev": False,
|
||||
b" -Og": False,
|
||||
b" -g": False,
|
||||
b"__PLATFORMIO_DEBUG__": (3, 6) > VERSION[:2]
|
||||
b"__PLATFORMIO_BUILD_DEBUG__": False
|
||||
}
|
||||
with open(prog_path, "rb") as fp:
|
||||
last_data = b""
|
||||
|
||||
@@ -111,6 +111,8 @@ ProjectOptions = OrderedDict([
|
||||
buildenvvar="BOARD_FLASH_MODE"),
|
||||
|
||||
# Build
|
||||
ConfigEnvOption(name="build_type",
|
||||
type=click.Choice(["release", "debug"])),
|
||||
ConfigEnvOption(name="build_flags",
|
||||
multiple=True,
|
||||
sysenvvar="PLATFORMIO_BUILD_FLAGS",
|
||||
|
||||
Reference in New Issue
Block a user