77
88import java .util .ArrayList ;
99import java .util .List ;
10+ import java .util .Set ;
1011
1112/**
1213 * Class to hold ESP-IDF target information including preview status
1617 */
1718public class IDFTargets
1819{
20+ private static final Set <String > XTENSA_CHIPS = Set .of ("esp32" , "esp32s2" , "esp32s3" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
21+ private static final String XTENSA = "xtensa" ; //$NON-NLS-1$
22+ private static final String RISCV32 = "riscv32" ; //$NON-NLS-1$
23+ private static final String XTENSA_TOOLCHAIN_ID = XTENSA + "-%s-elf" ; //$NON-NLS-1$
24+ private static final String RISCV32_TOOLCHAIN_ID = RISCV32 + "-esp-elf" ; //$NON-NLS-1$
25+ private static final String XTENSA_UNIFIED_DIR = XTENSA + "-esp32-elf" ; //$NON-NLS-1$
26+ private static final String TOOLCHAIN_NAME = "toolchain-%s.cmake" ; //$NON-NLS-1$
1927 private List <IDFTarget > supportedTargets ;
2028 private List <IDFTarget > previewTargets ;
2129
@@ -130,20 +138,7 @@ public boolean isPreview()
130138 */
131139 public String getArchitecture ()
132140 {
133- switch (name )
134- {
135- case "esp32" : //$NON-NLS-1$
136- case "esp32s2" : //$NON-NLS-1$
137- case "esp32s3" : //$NON-NLS-1$
138- return "xtensa" ; //$NON-NLS-1$
139- case "esp32c2" : //$NON-NLS-1$
140- case "esp32c3" : //$NON-NLS-1$
141- case "esp32c6" : //$NON-NLS-1$
142- case "esp32h2" : //$NON-NLS-1$
143- case "esp32p4" : //$NON-NLS-1$
144- default :
145- return "riscv32" ; //$NON-NLS-1$
146- }
141+ return XTENSA_CHIPS .contains (name ) ? XTENSA : RISCV32 ;
147142 }
148143
149144 /**
@@ -153,20 +148,7 @@ public String getArchitecture()
153148 */
154149 public String getToolchainId ()
155150 {
156- switch (name )
157- {
158- case "esp32" : //$NON-NLS-1$
159- case "esp32s2" : //$NON-NLS-1$
160- case "esp32s3" : //$NON-NLS-1$
161- return "xtensa-" + name + "-elf" ; //$NON-NLS-1$ //$NON-NLS-2$
162- case "esp32c2" : //$NON-NLS-1$
163- case "esp32c3" : //$NON-NLS-1$
164- case "esp32c6" : //$NON-NLS-1$
165- case "esp32h2" : //$NON-NLS-1$
166- case "esp32p4" : //$NON-NLS-1$
167- default :
168- return "riscv32-esp-elf" ; //$NON-NLS-1$
169- }
151+ return XTENSA_CHIPS .contains (name ) ? String .format (XTENSA_TOOLCHAIN_ID , name ) : RISCV32_TOOLCHAIN_ID ;
170152 }
171153
172154 /**
@@ -205,56 +187,19 @@ public String getDebuggerPattern()
205187 */
206188 private String getExecutableName ()
207189 {
208- switch (name )
209- {
210- case "esp32" : //$NON-NLS-1$
211- case "esp32s2" : //$NON-NLS-1$
212- case "esp32s3" : //$NON-NLS-1$
213- return "xtensa-" + name + "-elf" ; // Target-specific executable names //$NON-NLS-1$ //$NON-NLS-2$
214- case "esp32c2" : //$NON-NLS-1$
215- case "esp32c3" : //$NON-NLS-1$
216- case "esp32c6" : //$NON-NLS-1$
217- case "esp32h2" : //$NON-NLS-1$
218- case "esp32p4" : //$NON-NLS-1$
219- default :
220- return "riscv32-esp-elf" ; // Unified executable name //$NON-NLS-1$
221- }
190+ return XTENSA_CHIPS .contains (name ) ? String .format (XTENSA_TOOLCHAIN_ID , name )
191+ : RISCV32_TOOLCHAIN_ID ;
222192 }
223193
224194 private String getTargetSpecificDirectoryName ()
225195 {
226- switch (name )
227- {
228- case "esp32" : //$NON-NLS-1$
229- case "esp32s2" : //$NON-NLS-1$
230- case "esp32s3" : //$NON-NLS-1$
231- return "xtensa-" + name + "-elf" ; // Target-specific directory names //$NON-NLS-1$ //$NON-NLS-2$
232- case "esp32c2" : //$NON-NLS-1$
233- case "esp32c3" : //$NON-NLS-1$
234- case "esp32c6" : //$NON-NLS-1$
235- case "esp32h2" : //$NON-NLS-1$
236- case "esp32p4" : //$NON-NLS-1$
237- default :
238- return "riscv32-esp-elf" ; // Same for both old and new //$NON-NLS-1$
239- }
196+ return XTENSA_CHIPS .contains (name ) ? String .format (XTENSA_TOOLCHAIN_ID , name )
197+ : RISCV32_TOOLCHAIN_ID ;
240198 }
241199
242200 private String getUnifiedDirectoryName ()
243201 {
244- switch (name )
245- {
246- case "esp32" : //$NON-NLS-1$
247- case "esp32s2" : //$NON-NLS-1$
248- case "esp32s3" : //$NON-NLS-1$
249- return "xtensa-esp-elf" ; // Unified directory name //$NON-NLS-1$
250- case "esp32c2" : //$NON-NLS-1$
251- case "esp32c3" : //$NON-NLS-1$
252- case "esp32c6" : //$NON-NLS-1$
253- case "esp32h2" : //$NON-NLS-1$
254- case "esp32p4" : //$NON-NLS-1$
255- default :
256- return "riscv32-esp-elf" ; //$NON-NLS-1$
257- }
202+ return XTENSA_CHIPS .contains (name ) ? XTENSA_UNIFIED_DIR : RISCV32_TOOLCHAIN_ID ;
258203 }
259204
260205 /**
@@ -264,7 +209,7 @@ private String getUnifiedDirectoryName()
264209 */
265210 public String getToolchainFileName ()
266211 {
267- return "toolchain-" + name + ".cmake" ; //$NON-NLS-1$ //$NON-NLS-2$
212+ return String . format ( TOOLCHAIN_NAME , name );
268213 }
269214 }
270215}
0 commit comments