Significantly improved support for Pre & Post Actions

This commit is contained in:
Ivan Kravets
2022-06-28 19:36:49 +03:00
parent 1f096fe03f
commit 3363b3a516
5 changed files with 69 additions and 6 deletions

View File

@ -13,7 +13,7 @@ PlatformIO Core 6
**A professional collaborative platform for declarative, safety-critical, and test-driven embedded development.**
6.0.3 (2022-??-??)
6.1.0 (2022-??-??)
~~~~~~~~~~~~~~~~~~
* **Device Manager**
@ -36,9 +36,14 @@ PlatformIO Core 6
* **Build System**
- Significantly improved support for `Pre & Post Actions <https://docs.platformio.org/en/latest/scripting/actions.html>`__
* Allowed to declare actions in the `PRE-type scripts <https://docs.platformio.org/en/latest/scripting/launch_types.html>`__ even if the target is not ready yet
* Allowed library maintainers to use Pre & Post Actions in the library `extraScript <https://docs.platformio.org/en/latest/manifests/library-json/fields/build/extrascript.html>`__
- Allowed to ``Import("projenv")`` in a library extra script (`issue #4305 <https://github.com/platformio/platformio-core/issues/4305>`_)
- Documented `Stringification <https://docs.platformio.org/en/latest/projectconf/section_env_build.html#stringification>`__ converting a macro argument into a string constant (`issue #4310 <https://github.com/platformio/platformio-core/issues/4310>`_)
- Added ``env.StringifyMacro(value)`` helper function for the `Advanced Scripting <https://docs.platformio.org/en/latest/scripting/index.html>`__
- Allowed to ``Import("projenv")`` in a library extra script (`issue #4305 <https://github.com/platformio/platformio-core/issues/4305>`_)
- Fixed an issue when the `build_unflags <https://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-unflags>`__ operation ignores a flag value (`issue #4309 <https://github.com/platformio/platformio-core/issues/4309>`_)
- Fixed an issue when the `build_unflags <https://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-unflags>`__ option was not applied to the ``ASPPFLAGS`` scope
- Fixed an issue on Windows OS when flags were wrapped to the temporary file while generating the `Compilation database "compile_commands.json" <https://docs.platformio.org/en/latest/integration/compile_commands.html>`__

2
docs

Submodule docs updated: d24f9a649c...54d25a92c9

View File

@ -53,6 +53,7 @@ DEFAULT_ENV_OPTIONS = dict(
"cc",
"c++",
"link",
"piohooks",
"pioasm",
"platformio",
"pioproject",
@ -221,6 +222,8 @@ env.AddPreAction(
AlwaysBuild(env.Alias("__debug", DEFAULT_TARGETS))
AlwaysBuild(env.Alias("__test", DEFAULT_TARGETS))
env.ProcessDelayedActions()
##############################################################################
if "envdump" in COMMAND_LINE_TARGETS:

View File

@ -0,0 +1,42 @@
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
#
# 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
def AddActionWrapper(handler):
def wraps(env, files, action):
nodes = env.arg2nodes(files, env.fs.Entry)
unknown_nodes = [node for node in nodes if not node.exists()]
if unknown_nodes:
env.Append(**{"_PIO_DELAYED_ACTIONS": [(handler, unknown_nodes, action)]})
return handler([node for node in nodes if node.exists()], action)
return wraps
def ProcessDelayedActions(env):
for func, nodes, action in env.get("_PIO_DELAYED_ACTIONS", []):
func(nodes, action)
def generate(env):
env.Replace(**{"_PIO_DELAYED_ACTIONS": []})
env.AddMethod(AddActionWrapper(env.AddPreAction), "AddPreAction")
env.AddMethod(AddActionWrapper(env.AddPostAction), "AddPostAction")
env.AddMethod(ProcessDelayedActions)
def exists(_):
return True

View File

@ -17,7 +17,7 @@ from pathlib import Path
from platformio.run.cli import cli as cmd_run
def test_build_flags(clirunner, validate_cliresult, tmpdir):
def test_generic_build(clirunner, validate_cliresult, tmpdir):
build_flags = [
("-D TEST_INT=13", "-DTEST_INT=13"),
("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"),
@ -28,7 +28,9 @@ def test_build_flags(clirunner, validate_cliresult, tmpdir):
"""
[env:native]
platform = native
extra_scripts = extra.py
extra_scripts =
pre:pre_script.py
post_script.py
lib_ldf_mode = deep+
build_src_flags = -DI_AM_ONLY_SRC_FLAG
build_flags =
@ -38,7 +40,17 @@ build_flags =
% " ".join([f[0] for f in build_flags])
)
tmpdir.join("extra.py").write(
tmpdir.join("pre_script.py").write(
"""
Import("env")
def post_prog_action(source, target, env):
print("post_prog_action is called")
env.AddPostAction("$PROG_PATH", post_prog_action)
"""
)
tmpdir.join("post_script.py").write(
"""
Import("projenv")
@ -102,6 +114,7 @@ void dummy(void ) {};
result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
validate_cliresult(result)
assert "post_prog_action is called" in result.output
build_output = result.output[result.output.find("Scanning dependencies...") :]
for flag in build_flags:
assert flag[1] in build_output, flag