Skip to content

Commit 6bdcb04

Browse files
committed
Target list based on JSON and support for any combination of targets
1 parent 303bad3 commit 6bdcb04

File tree

4 files changed

+89
-32
lines changed

4 files changed

+89
-32
lines changed

tools/config_editor/app.py

+36-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"""
2525

2626
import argparse
27+
import json
2728
import os
2829
import platform
2930
import sys
@@ -95,6 +96,7 @@ class ConfigEditorApp(App):
9596
ROOT_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
9697

9798
# Set the application options
99+
supported_targets = []
98100
setting_enable_copy = True
99101

100102
# Options to be set by the command line arguments
@@ -119,7 +121,8 @@ def on_mount(self) -> None:
119121
print("Python version: " + sys.version)
120122
print("Root path: " + self.ROOT_PATH)
121123
print("Script path: " + self.SCRIPT_PATH)
122-
print("Target: " + str(self.setting_target))
124+
print("Supported Targets: " + ", ".join(self.supported_targets))
125+
print("Default targets: " + self.setting_target)
123126
print("Enable Copy: " + str(self.setting_enable_copy))
124127
print("Arduino Path: " + str(self.setting_arduino_path))
125128
print("Arduino Branch: " + str(self.setting_arduino_branch))
@@ -136,6 +139,9 @@ def arduino_default_path():
136139
else: # Windows and MacOS
137140
return os.path.join(home, "Documents", "Arduino", "hardware", "espressif", "esp32")
138141

142+
def check_arduino_path():
143+
return os.path.isdir(arduino_default_path())
144+
139145
def main() -> None:
140146
# Set the PYTHONUNBUFFERED environment variable to "1" to disable the output buffering
141147
os.environ['PYTHONUNBUFFERED'] = "1"
@@ -147,21 +153,39 @@ def main() -> None:
147153

148154
app = ConfigEditorApp()
149155

156+
target_choices = []
157+
158+
# Parse build JSON file
159+
build_json_path = os.path.join(app.ROOT_PATH, "configs", "builds.json")
160+
if os.path.isfile(build_json_path):
161+
with open(build_json_path, "r") as build_json_file:
162+
build_json = json.load(build_json_file)
163+
for target in build_json["targets"]:
164+
try:
165+
default = False if target["skip"] else True
166+
except:
167+
default = True
168+
target_choices.append((target["target"], default))
169+
else:
170+
print("Error: configs/builds.json file not found.")
171+
exit(1)
172+
173+
target_choices.sort(key=lambda x: x[0])
174+
150175
parser = argparse.ArgumentParser(description="Configure and compile the ESP32 Arduino static libraries")
151176

152-
target_choices = ("all", "esp32", "esp32s2", "esp32s3", "esp32c2", "esp32c3", "esp32c6", "esp32h2")
153177
parser.add_argument("-t", "--target",
154178
metavar="<target>",
155179
type=str,
156-
default="all",
157-
choices=target_choices,
180+
default="default",
158181
required=False,
159-
help="Target to be compiled. Choose from: " + ", ".join(target_choices))
182+
help="Comma separated list of targets to be compiled. Choose from: " + ", ".join([x[0] for x in target_choices])
183+
+ ". Default: All except " + ", ".join([x[0] for x in target_choices if not x[1]]))
160184

161185
parser.add_argument("--copy",
162186
type=bool,
163187
action=argparse.BooleanOptionalAction,
164-
default=True,
188+
default=True if check_arduino_path() else False,
165189
required=False,
166190
help="Enable/disable copying the compiled libraries to arduino-esp32. Enabled by default")
167191

@@ -205,6 +229,12 @@ def main() -> None:
205229
args = parser.parse_args()
206230

207231
# Set the options in the app
232+
if args.target.strip() == "default":
233+
args.target = ",".join([x[0] for x in target_choices if x[1]])
234+
elif args.target.strip() == "all":
235+
args.target = ",".join([x[0] for x in target_choices])
236+
237+
app.supported_targets = [x[0] for x in target_choices]
208238
app.setting_target = args.target
209239
app.setting_enable_copy = args.copy
210240
app.setting_arduino_path = os.path.abspath(args.arduino_path)

tools/config_editor/compile.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ def compile_libs(self) -> None:
7272

7373
label = self.query_one("#compile-title", Static)
7474
self.child_process = None
75-
target = self.app.setting_target
75+
if self.app.setting_target == ",".join(self.app.supported_targets):
76+
target = "all targets"
77+
else:
78+
target = self.app.setting_target.replace(",", ", ").upper()
7679

77-
label.update("Compiling for " + target.upper())
78-
self.print_info("======== Compiling for " + target.upper() + " ========")
80+
label.update("Compiling for " + target)
81+
self.print_info("======== Compiling for " + target + " ========")
7982

80-
command = ["./build.sh", "-t", target, "-D", self.app.setting_debug_level]
83+
command = ["./build.sh", "-t", self.app.setting_target, "-D", self.app.setting_debug_level]
8184

8285
#command.append("--help") # For testing output without compiling
8386

@@ -112,14 +115,14 @@ def compile_libs(self) -> None:
112115
print("Process might have terminated")
113116

114117
if not self.child_process:
115-
self.print_error("Compilation failed for " + target.upper() + "Child process failed to start")
116-
label.update("Compilation failed for " + target.upper() + "Child process failed to start")
118+
self.print_error("Compilation failed for " + target + "Child process failed to start")
119+
label.update("Compilation failed for " + target + "Child process failed to start")
117120
return
118121
else:
119122
self.child_process.wait()
120123

121124
if self.child_process.returncode != 0:
122-
self.print_error("Compilation failed for " + target.upper() + ". Return code: " + str(self.child_process.returncode))
125+
self.print_error("Compilation failed for " + target + ". Return code: " + str(self.child_process.returncode))
123126
self.print_error("Errors:")
124127
try:
125128
for error in self.child_process.stderr:
@@ -128,10 +131,10 @@ def compile_libs(self) -> None:
128131
self.child_process.stderr.close()
129132
except Exception as e:
130133
print("Error reading child process errors: " + str(e))
131-
label.update("Compilation failed for " + target.upper())
134+
label.update("Compilation failed for " + target)
132135
else:
133-
self.print_success("Compilation successful for " + target.upper())
134-
label.update("Compilation successful for " + target.upper())
136+
self.print_success("Compilation successful for " + target)
137+
label.update("Compilation successful for " + target)
135138

136139
def on_button_pressed(self, event: Button.Pressed) -> None:
137140
# Event handler called when a button is pressed

tools/config_editor/settings.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import math
2+
13
from textual import on
24
from textual.app import ComposeResult
35
from textual.binding import Binding
46
from textual.containers import VerticalScroll, Container, Horizontal
57
from textual.screen import Screen
68
from textual.events import ScreenResume
7-
from textual.widgets import Header, Button, Switch, Label, Footer
9+
from textual.widgets import Header, Button, Switch, Label, Footer, Checkbox
810

911
from widgets import LabelledInput, LabelledSelect
1012

@@ -17,7 +19,6 @@ class SettingsScreen(Screen):
1719
Binding("escape", "app.pop_screen", "Discard")
1820
]
1921

20-
target_select: LabelledSelect
2122
enable_copy_switch: Switch
2223
arduino_path_input: LabelledInput
2324
arduino_branch_input: LabelledInput
@@ -26,7 +27,13 @@ class SettingsScreen(Screen):
2627
idf_debug_select: LabelledSelect
2728

2829
def action_save(self) -> None:
29-
self.app.setting_target = self.target_select.get_select_value()
30+
checkboxes = self.query(Checkbox)
31+
self.app.setting_target = ""
32+
for checkbox in checkboxes:
33+
if checkbox.value:
34+
if self.app.setting_target:
35+
self.app.setting_target += ","
36+
self.app.setting_target += checkbox.id.replace("-checkbox", "")
3037
print("Target setting updated: " + self.app.setting_target)
3138

3239
self.app.setting_enable_copy = self.enable_copy_switch.value
@@ -61,7 +68,12 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
6168
def on_resume(self) -> None:
6269
# Event handler called every time the screen is activated
6370
print("Settings screen resumed. Updating settings.")
64-
self.target_select.set_select_value(self.app.setting_target)
71+
targets = self.app.setting_target.split(",")
72+
checkboxes = self.query(Checkbox)
73+
for checkbox in checkboxes:
74+
checkbox.value = False
75+
if checkbox.id.replace("-checkbox", "") in targets:
76+
checkbox.value = True
6577
self.enable_copy_switch.value = self.app.setting_enable_copy
6678
if self.app.setting_enable_copy:
6779
self.arduino_path_input.visible = True
@@ -85,18 +97,11 @@ def compose(self) -> ComposeResult:
8597
# Compose the target selection screen
8698
yield Header()
8799
with VerticalScroll(id="settings-scroll-container"):
88-
target_options = [
89-
("All", "all"),
90-
("ESP32", "esp32"),
91-
("ESP32-S2", "esp32s2"),
92-
("ESP32-S3", "esp32s3"),
93-
("ESP32-C2 (ESP8684)", "esp32c2"),
94-
("ESP32-C3", "esp32c3"),
95-
("ESP32-C6", "esp32c6"),
96-
("ESP32-H2", "esp32h2")
97-
]
98-
self.target_select = LabelledSelect("Compilation Target", target_options, allow_blank=False, id="target-select")
99-
yield self.target_select
100+
101+
yield Label("Compilation Targets", id="settings-target-label")
102+
with Container(id="settings-target-container"):
103+
for target in self.app.supported_targets:
104+
yield Checkbox(target.upper(), id=target + "-checkbox")
100105

101106
with Horizontal(classes="settings-switch-container"):
102107
self.enable_copy_switch = Switch(value=self.app.setting_enable_copy, id="enable-copy-switch")
@@ -136,4 +141,9 @@ def compose(self) -> ComposeResult:
136141
def on_mount(self) -> None:
137142
# Event handler called when the screen is mounted for the first time
138143
self.sub_title = "Settings"
144+
target_container = self.query_one("#settings-target-container")
145+
# Height needs to be 3 for each row of targets + 1
146+
height_value = str(int(math.ceil(len(self.app.supported_targets) / int(target_container.styles.grid_size_columns)) * 3 + 1))
147+
print("Target container height: " + height_value)
148+
target_container.styles.height = height_value
139149
print("Settings screen mounted")

tools/config_editor/style.tcss

+14
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ Button {
128128
align: center middle;
129129
}
130130

131+
#settings-target-label {
132+
margin-left: 1;
133+
}
134+
135+
#settings-target-container {
136+
layout: grid;
137+
grid-size: 4;
138+
}
139+
140+
#settings-target-container Checkbox {
141+
width: 100%;
142+
margin-right: -1;
143+
}
144+
131145
.settings-button {
132146
margin: 1;
133147
min-width: 100%;

0 commit comments

Comments
 (0)