Skip to content

Commit aea6b23

Browse files
committed
Switch to new AddPlatformTarget API
Preparation for upcoming PIO Core 4.4
1 parent 2ecd737 commit aea6b23

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
@@ -142,6 +142,7 @@ def get_esptoolpy_reset_flags(resetmethod):
142142
########################################################
143143

144144
env = DefaultEnvironment()
145+
env.SConscript("compat.py", exports="env")
145146
platform = env.PioPlatform()
146147

147148
env.Replace(
@@ -231,11 +232,11 @@ def get_esptoolpy_reset_flags(resetmethod):
231232
target_firm = env.DataToBin(
232233
join("$BUILD_DIR", env.get("FSIMAGENAME", "fs")), "$PROJECTDATA_DIR")
233234
AlwaysBuild(target_firm)
234-
AlwaysBuild(env.Alias("buildfs", target_firm))
235235
else:
236236
target_firm = env.ElfToBin(
237237
join("$BUILD_DIR", "${PROGNAME}"), target_elf)
238238

239+
env.AddPlatformTarget("buildfs", target_firm, None, "Build Filesystem Image")
239240
AlwaysBuild(env.Alias("nobuild", target_firm))
240241
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
241242

@@ -254,10 +255,13 @@ def get_esptoolpy_reset_flags(resetmethod):
254255
# Target: Print binary size
255256
#
256257

257-
target_size = env.Alias(
258-
"size", target_elf,
259-
env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"))
260-
AlwaysBuild(target_size)
258+
target_size = env.AddPlatformTarget(
259+
"size",
260+
target_elf,
261+
env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"),
262+
"Program Size",
263+
"Calculate program size",
264+
)
261265

262266
#
263267
# Target: Upload firmware or filesystem image
@@ -340,19 +344,24 @@ def get_esptoolpy_reset_flags(resetmethod):
340344
else:
341345
sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol)
342346

343-
env.AlwaysBuild(env.Alias(["upload", "uploadfs"], target_firm, upload_actions))
347+
env.AddPlatformTarget("upload", target_firm, upload_actions, "Upload")
348+
env.AddPlatformTarget("uploadfs", target_firm, upload_actions, "Upload Filesystem Image")
349+
env.AddPlatformTarget(
350+
"uploadfsota", target_firm, upload_actions, "Upload Filesystem Image OTA")
344351

345352
#
346353
# Target: Erase Flash
347354
#
348355

349-
AlwaysBuild(
350-
env.Alias("erase", None, [
351-
env.VerboseAction(env.AutodetectUploadPort,
352-
"Looking for serial port..."),
356+
env.AddPlatformTarget(
357+
"erase",
358+
None,
359+
[
360+
env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."),
353361
env.VerboseAction("$ERASECMD", "Erasing...")
354-
]))
355-
362+
],
363+
"Erase Flash",
364+
)
356365

357366
#
358367
# Information about obsolete method of specifying linker scripts

0 commit comments

Comments
 (0)