mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Fixed an issue when "build_src_flags" were applied outside project scope // Resolve #4277
This commit is contained in:
@ -12,6 +12,11 @@ PlatformIO Core 6
|
||||
|
||||
**A professional collaborative platform for declarative, safety-critical, and test-driven embedded development.**
|
||||
|
||||
6.0.2 (2022-??-??)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Fixed an issue when the `build_src_flags <https://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-src-flags>`__ were applied outside the project scope (`issue #4277 <https://github.com/platformio/platformio-core/issues/4277>`_)
|
||||
|
||||
6.0.1 (2022-05-17)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -1027,14 +1027,15 @@ def IsCompatibleLibBuilder(env, lb, verbose=int(ARGUMENTS.get("PIOVERBOSE", 0)))
|
||||
return True
|
||||
|
||||
|
||||
def GetLibBuilders(env): # pylint: disable=too-many-branches
|
||||
if DefaultEnvironment().get("__PIO_LIB_BUILDERS", None) is not None:
|
||||
def GetLibBuilders(_): # pylint: disable=too-many-branches
|
||||
env = DefaultEnvironment()
|
||||
if env.get("__PIO_LIB_BUILDERS", None) is not None:
|
||||
return sorted(
|
||||
DefaultEnvironment()["__PIO_LIB_BUILDERS"],
|
||||
env["__PIO_LIB_BUILDERS"],
|
||||
key=lambda lb: 0 if lb.is_dependent else 1,
|
||||
)
|
||||
|
||||
DefaultEnvironment().Replace(__PIO_LIB_BUILDERS=[])
|
||||
env.Replace(__PIO_LIB_BUILDERS=[])
|
||||
|
||||
verbose = int(ARGUMENTS.get("PIOVERBOSE", 0))
|
||||
found_incompat = False
|
||||
@ -1060,13 +1061,13 @@ def GetLibBuilders(env): # pylint: disable=too-many-branches
|
||||
)
|
||||
continue
|
||||
if env.IsCompatibleLibBuilder(lb):
|
||||
DefaultEnvironment().Append(__PIO_LIB_BUILDERS=[lb])
|
||||
env.Append(__PIO_LIB_BUILDERS=[lb])
|
||||
else:
|
||||
found_incompat = True
|
||||
|
||||
for lb in env.get("EXTRA_LIB_BUILDERS", []):
|
||||
if env.IsCompatibleLibBuilder(lb):
|
||||
DefaultEnvironment().Append(__PIO_LIB_BUILDERS=[lb])
|
||||
env.Append(__PIO_LIB_BUILDERS=[lb])
|
||||
else:
|
||||
found_incompat = True
|
||||
|
||||
@ -1077,7 +1078,7 @@ def GetLibBuilders(env): # pylint: disable=too-many-branches
|
||||
"ldf-compat-mode\n"
|
||||
)
|
||||
|
||||
return DefaultEnvironment()["__PIO_LIB_BUILDERS"]
|
||||
return env["__PIO_LIB_BUILDERS"]
|
||||
|
||||
|
||||
def ConfigureProjectLibBuilder(env):
|
||||
@ -1126,7 +1127,9 @@ def ConfigureProjectLibBuilder(env):
|
||||
if lb.depbuilders:
|
||||
_print_deps_tree(lb, level + 1)
|
||||
|
||||
print(1, env.get("CPPDEFINES"))
|
||||
project = ProjectAsLibBuilder(env, "$PROJECT_DIR")
|
||||
print(2, env.get("CPPDEFINES"))
|
||||
ldf_mode = LibBuilderBase.lib_ldf_mode.fget(project) # pylint: disable=no-member
|
||||
|
||||
click.echo("LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf")
|
||||
@ -1137,6 +1140,7 @@ def ConfigureProjectLibBuilder(env):
|
||||
|
||||
project.install_dependencies()
|
||||
|
||||
print(3, env.get("CPPDEFINES"))
|
||||
lib_builders = env.GetLibBuilders()
|
||||
click.echo("Found %d compatible libraries" % len(lib_builders))
|
||||
|
||||
|
@ -143,6 +143,7 @@ def ProcessProgramDeps(env):
|
||||
|
||||
def ProcessProjectDeps(env):
|
||||
project_lib_builder = env.ConfigureProjectLibBuilder()
|
||||
projenv = project_lib_builder.env
|
||||
|
||||
# prepend project libs to the beginning of list
|
||||
env.Prepend(LIBS=project_lib_builder.build())
|
||||
@ -155,13 +156,6 @@ def ProcessProjectDeps(env):
|
||||
}
|
||||
)
|
||||
|
||||
projenv = env.Clone()
|
||||
|
||||
# CPPPATH from dependencies
|
||||
projenv.PrependUnique(CPPPATH=project_lib_builder.env.get("CPPPATH"))
|
||||
# extra build flags from `platformio.ini`
|
||||
projenv.ProcessFlags(env.get("SRC_BUILD_FLAGS"))
|
||||
|
||||
if "test" in env.GetBuildType():
|
||||
projenv.BuildSources(
|
||||
"$BUILD_TEST_DIR", "$PROJECT_TEST_DIR", "$PIOTEST_SRC_FILTER"
|
||||
|
@ -29,6 +29,8 @@ def test_build_flags(clirunner, validate_cliresult, tmpdir):
|
||||
[env:native]
|
||||
platform = native
|
||||
extra_scripts = extra.py
|
||||
lib_ldf_mode = deep+
|
||||
build_src_flags = -DI_AM_ONLY_SRC_FLAG
|
||||
build_flags =
|
||||
; -DCOMMENTED_MACRO
|
||||
%s ; inline comment
|
||||
@ -46,6 +48,12 @@ projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO")
|
||||
|
||||
tmpdir.mkdir("src").join("main.cpp").write(
|
||||
"""
|
||||
#ifdef I_AM_ONLY_SRC_FLAG
|
||||
#include <component.h>
|
||||
#else
|
||||
#error "I_AM_ONLY_SRC_FLAG"
|
||||
#endif
|
||||
|
||||
#if !defined(TEST_INT) || TEST_INT != 13
|
||||
#error "TEST_INT"
|
||||
#endif
|
||||
@ -54,6 +62,10 @@ projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO")
|
||||
#error "TEST_STR_SPACE"
|
||||
#endif
|
||||
|
||||
#ifndef I_AM_COMPONENT
|
||||
#error "I_AM_COMPONENT"
|
||||
#endif
|
||||
|
||||
#ifndef POST_SCRIPT_MACRO
|
||||
#error "POST_SCRIPT_MACRO"
|
||||
#endif
|
||||
@ -66,6 +78,27 @@ int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
component_dir = tmpdir.mkdir("lib").mkdir("component")
|
||||
component_dir.join("component.h").write(
|
||||
"""
|
||||
#define I_AM_COMPONENT
|
||||
|
||||
#ifndef I_AM_ONLY_SRC_FLAG
|
||||
#error "I_AM_ONLY_SRC_FLAG"
|
||||
#endif
|
||||
|
||||
void dummy(void);
|
||||
"""
|
||||
)
|
||||
component_dir.join("component.cpp").write(
|
||||
"""
|
||||
#ifdef I_AM_ONLY_SRC_FLAG
|
||||
#error "I_AM_ONLY_SRC_FLAG"
|
||||
#endif
|
||||
|
||||
void dummy(void ) {};
|
||||
"""
|
||||
)
|
||||
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
validate_cliresult(result)
|
||||
|
@ -41,6 +41,8 @@ def test_warning_line(clirunner, validate_cliresult):
|
||||
validate_cliresult(result)
|
||||
assert 'basic.ino:16:14: warning: #warning "Line number is 16"' in result.output
|
||||
assert 'basic.ino:46:2: warning: #warning "Line number is 46"' in result.output
|
||||
result = clirunner.invoke(cmd_ci, [join(EXAMPLES_DIR, "strmultilines"), "-b", "uno"])
|
||||
result = clirunner.invoke(
|
||||
cmd_ci, [join(EXAMPLES_DIR, "strmultilines"), "-b", "uno"]
|
||||
)
|
||||
validate_cliresult(result)
|
||||
assert 'main.ino:75:2: warning: #warning "Line 75"' in result.output
|
||||
|
Reference in New Issue
Block a user