From ebadad145c7fdcdd5c8da09b7f26c2e22cc1397d Mon Sep 17 00:00:00 2001 From: Valerii Koval Date: Wed, 10 Jun 2020 17:16:17 +0300 Subject: [PATCH] Switch to new AddPlatformTarget API Preparation for upcoming PIO Core 4.4 --- builder/compat.py | 38 ++++++++++++++++++++++++++++++++++++++ builder/main.py | 32 +++++++++++++++++++++----------- 2 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 builder/compat.py diff --git a/builder/compat.py b/builder/compat.py new file mode 100644 index 0000000..b8dfe3d --- /dev/null +++ b/builder/compat.py @@ -0,0 +1,38 @@ +# Copyright 2014-present PlatformIO +# +# 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 SCons.Script import AlwaysBuild, Import + + +Import("env") + + +# Added in PIO Core 4.4.0 +if not hasattr(env, "AddPlatformTarget"): + + def AddPlatformTarget( + env, + name, + dependencies, + actions, + title=None, + description=None, + always_build=True, + ): + target = env.Alias(name, dependencies, actions) + if always_build: + AlwaysBuild(target) + return target + + env.AddMethod(AddPlatformTarget) diff --git a/builder/main.py b/builder/main.py index fb6acef..4ebde81 100644 --- a/builder/main.py +++ b/builder/main.py @@ -128,6 +128,7 @@ def __fetch_spiffs_size(target, source, env): env = DefaultEnvironment() +env.SConscript("compat.py", exports="env") platform = env.PioPlatform() board = env.BoardConfig() mcu = board.get("build.mcu", "esp32") @@ -224,11 +225,11 @@ else: target_firm = env.DataToBin( join("$BUILD_DIR", "${ESP32_SPIFFS_IMAGE_NAME}"), "$PROJECTDATA_DIR") AlwaysBuild(target_firm) - AlwaysBuild(env.Alias("buildfs", target_firm)) else: target_firm = env.ElfToBin( join("$BUILD_DIR", "${PROGNAME}"), target_elf) +env.AddPlatformTarget("buildfs", target_firm, None, "Build Filesystem Image") AlwaysBuild(env.Alias("nobuild", target_firm)) target_buildprog = env.Alias("buildprog", target_firm, target_firm) @@ -247,10 +248,13 @@ elif set(["checkprogsize", "upload"]) & set(COMMAND_LINE_TARGETS): # Target: Print binary size # -target_size = env.Alias("size", target_elf, - env.VerboseAction("$SIZEPRINTCMD", - "Calculating size $SOURCE")) -AlwaysBuild(target_size) +target_size = env.AddPlatformTarget( + "size", + target_elf, + env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"), + "Program Size", + "Calculate program size", +) # # Target: Upload firmware or SPIFFS image @@ -395,18 +399,24 @@ elif upload_protocol == "custom": else: sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol) -AlwaysBuild(env.Alias(["upload", "uploadfs"], target_firm, upload_actions)) +env.AddPlatformTarget("upload", target_firm, upload_actions, "Upload") +env.AddPlatformTarget("uploadfs", target_firm, upload_actions, "Upload Filesystem Image") +env.AddPlatformTarget( + "uploadfsota", target_firm, upload_actions, "Upload Filesystem Image OTA") # # Target: Erase Flash # -AlwaysBuild( - env.Alias("erase", None, [ - env.VerboseAction(env.AutodetectUploadPort, - "Looking for serial port..."), +env.AddPlatformTarget( + "erase", + None, + [ + env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."), env.VerboseAction("$ERASECMD", "Erasing...") - ])) + ], + "Erase Flash", +) # # Information about obsolete method of specifying linker scripts