Skip to content

Commit 6b19bf8

Browse files
committed
Switch to new AddPlatformTarget API
Preparation for upcoming PIO Core 4.4 (cherry picked from commit aea6b23)
1 parent e818486 commit 6b19bf8

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

builder/compat.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2014-present PlatformIO <[email protected]>
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from SCons.Script import AlwaysBuild, Import
16+
17+
18+
Import("env")
19+
20+
21+
# Added in PIO Core 4.4.0
22+
if not hasattr(env, "AddPlatformTarget"):
23+
24+
def AddPlatformTarget(
25+
env,
26+
name,
27+
dependencies,
28+
actions,
29+
title=None,
30+
description=None,
31+
always_build=True,
32+
):
33+
target = env.Alias(name, dependencies, actions)
34+
if always_build:
35+
AlwaysBuild(target)
36+
return target
37+
38+
env.AddMethod(AddPlatformTarget)

builder/main.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def get_esptoolpy_reset_flags(resetmethod):
138138
########################################################
139139

140140
env = DefaultEnvironment()
141+
env.SConscript("compat.py", exports="env")
141142
platform = env.PioPlatform()
142143

143144
env.Replace(
@@ -227,11 +228,11 @@ def get_esptoolpy_reset_flags(resetmethod):
227228
target_firm = env.DataToBin(
228229
join("$BUILD_DIR", env.get("SPIFFSNAME", "spiffs")), "$PROJECTDATA_DIR")
229230
AlwaysBuild(target_firm)
230-
AlwaysBuild(env.Alias("buildfs", target_firm))
231231
else:
232232
target_firm = env.ElfToBin(
233233
join("$BUILD_DIR", "${PROGNAME}"), target_elf)
234234

235+
env.AddPlatformTarget("buildfs", target_firm, None, "Build Filesystem Image")
235236
AlwaysBuild(env.Alias("nobuild", target_firm))
236237
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
237238

@@ -250,10 +251,13 @@ def get_esptoolpy_reset_flags(resetmethod):
250251
# Target: Print binary size
251252
#
252253

253-
target_size = env.Alias(
254-
"size", target_elf,
255-
env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"))
256-
AlwaysBuild(target_size)
254+
target_size = env.AddPlatformTarget(
255+
"size",
256+
target_elf,
257+
env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"),
258+
"Program Size",
259+
"Calculate program size",
260+
)
257261

258262
#
259263
# Target: Upload firmware or SPIFFS image
@@ -336,19 +340,24 @@ def get_esptoolpy_reset_flags(resetmethod):
336340
else:
337341
sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol)
338342

339-
env.AlwaysBuild(env.Alias(["upload", "uploadfs"], target_firm, upload_actions))
343+
env.AddPlatformTarget("upload", target_firm, upload_actions, "Upload")
344+
env.AddPlatformTarget("uploadfs", target_firm, upload_actions, "Upload Filesystem Image")
345+
env.AddPlatformTarget(
346+
"uploadfsota", target_firm, upload_actions, "Upload Filesystem Image OTA")
340347

341348
#
342349
# Target: Erase Flash
343350
#
344351

345-
AlwaysBuild(
346-
env.Alias("erase", None, [
347-
env.VerboseAction(env.AutodetectUploadPort,
348-
"Looking for serial port..."),
352+
env.AddPlatformTarget(
353+
"erase",
354+
None,
355+
[
356+
env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."),
349357
env.VerboseAction("$ERASECMD", "Erasing...")
350-
]))
351-
358+
],
359+
"Erase Flash",
360+
)
352361

353362
#
354363
# Information about obsolete method of specifying linker scripts

0 commit comments

Comments
 (0)