Switch to new AddPlatformTarget API

Preparation for upcoming PIO Core 4.4
This commit is contained in:
Valerii Koval
2020-06-10 17:16:17 +03:00
parent dd2f11b5cb
commit ebadad145c
2 changed files with 59 additions and 11 deletions
+38
View File
@@ -0,0 +1,38 @@
# Copyright 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 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)
+21 -11
View File
@@ -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