Skip to content

Commit ebadad1

Browse files
committed
Switch to new AddPlatformTarget API
Preparation for upcoming PIO Core 4.4
1 parent dd2f11b commit ebadad1

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def __fetch_spiffs_size(target, source, env):
128128

129129

130130
env = DefaultEnvironment()
131+
env.SConscript("compat.py", exports="env")
131132
platform = env.PioPlatform()
132133
board = env.BoardConfig()
133134
mcu = board.get("build.mcu", "esp32")
@@ -224,11 +225,11 @@ def __fetch_spiffs_size(target, source, env):
224225
target_firm = env.DataToBin(
225226
join("$BUILD_DIR", "${ESP32_SPIFFS_IMAGE_NAME}"), "$PROJECTDATA_DIR")
226227
AlwaysBuild(target_firm)
227-
AlwaysBuild(env.Alias("buildfs", target_firm))
228228
else:
229229
target_firm = env.ElfToBin(
230230
join("$BUILD_DIR", "${PROGNAME}"), target_elf)
231231

232+
env.AddPlatformTarget("buildfs", target_firm, None, "Build Filesystem Image")
232233
AlwaysBuild(env.Alias("nobuild", target_firm))
233234
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
234235

@@ -247,10 +248,13 @@ def __fetch_spiffs_size(target, source, env):
247248
# Target: Print binary size
248249
#
249250

250-
target_size = env.Alias("size", target_elf,
251-
env.VerboseAction("$SIZEPRINTCMD",
252-
"Calculating size $SOURCE"))
253-
AlwaysBuild(target_size)
251+
target_size = env.AddPlatformTarget(
252+
"size",
253+
target_elf,
254+
env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"),
255+
"Program Size",
256+
"Calculate program size",
257+
)
254258

255259
#
256260
# Target: Upload firmware or SPIFFS image
@@ -395,18 +399,24 @@ def __fetch_spiffs_size(target, source, env):
395399
else:
396400
sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol)
397401

398-
AlwaysBuild(env.Alias(["upload", "uploadfs"], target_firm, upload_actions))
402+
env.AddPlatformTarget("upload", target_firm, upload_actions, "Upload")
403+
env.AddPlatformTarget("uploadfs", target_firm, upload_actions, "Upload Filesystem Image")
404+
env.AddPlatformTarget(
405+
"uploadfsota", target_firm, upload_actions, "Upload Filesystem Image OTA")
399406

400407
#
401408
# Target: Erase Flash
402409
#
403410

404-
AlwaysBuild(
405-
env.Alias("erase", None, [
406-
env.VerboseAction(env.AutodetectUploadPort,
407-
"Looking for serial port..."),
411+
env.AddPlatformTarget(
412+
"erase",
413+
None,
414+
[
415+
env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."),
408416
env.VerboseAction("$ERASECMD", "Erasing...")
409-
]))
417+
],
418+
"Erase Flash",
419+
)
410420

411421
#
412422
# Information about obsolete method of specifying linker scripts

0 commit comments

Comments
 (0)