19
19
import io .sloeber .core .tools .Version ;
20
20
21
21
/**
22
- * A class to apply workarounds to installed packages workaround are done after
23
- * installation at usage of boards.txt file at usage of platform.txt file
22
+ * A class to apply workarounds to installed packages.
23
+ * Workaround are done after installation and
24
+ * at usage of boards.txt or platform.txt file
25
+ * currently there are noworkarounds for programmers.trx
24
26
*
25
- * The first line of the worked around files contain a key A newer version of
26
- * sloeber that has a different workaround shuld change the key in this way the
27
- * worked around files can be persisted and updated when needed
27
+ * The first line of the worked around files contain a key.
28
+ * A newer version of sloeber that has a different workaround should change the key.
29
+ * This way the worked around files can be persisted and updated when needed
28
30
*
29
31
* @author jan
30
32
*
33
35
public class WorkAround {
34
36
// Each time this class is touched consider changing the String below to enforce
35
37
// updates
36
- private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created workaound file V1.00.test 4 " ;
38
+ private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created workaound file V1.00.test 11 " ;
37
39
38
40
/**
39
41
* workarounds done at installation time. I try to keep those at a minimum but
40
- * none platform.txt and boards.txt workarounds need to be doine during install
42
+ * none platform.txt and boards.txt workarounds need to be done during install
41
43
* time
42
44
*
43
45
* @param platform
@@ -70,12 +72,15 @@ static synchronized public void applyKnownWorkArounds(ArduinoPlatform platform)
70
72
}
71
73
72
74
/**
73
- * create a workedaround boards.txt and return that filz
75
+ * Get the a workaround boards.txt and if needed create/update it
76
+ * This method takes a boards.txt file and returns a worked around file.
77
+ * The worked around file is persisted on disk for easy debugging/ reduce code impact
78
+ * and performance.
74
79
*
75
- * @param requestedFileToWorkAround
80
+ * @param requestedFileToWorkAround the board.txt that you want to process
76
81
*
77
- * @return the worked around file or requestedFileToWorkAround is it does not
78
- * exist or error
82
+ * @return the worked around file or requestedFileToWorkAround if it does not
83
+ * exist or an error occurred
79
84
*/
80
85
static synchronized public File MakeBoardsSloeberTxt (File requestedFileToWorkAround ) {
81
86
if (!requestedFileToWorkAround .exists ()) {
@@ -105,13 +110,37 @@ static synchronized public File MakeBoardsSloeberTxt(File requestedFileToWorkAro
105
110
try {
106
111
String boardsTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n " ;
107
112
boardsTXT += FileUtils .readFileToString (requestedFileToWorkAround , Charset .defaultCharset ());
108
- boardsTXT = boardsTXT .replace ("\r \n " , "\n " );
113
+
114
+ boardsTXT = boardsTXT .replace ("\r \n " ,"\n " );
115
+ //because I search for spaces around string as delimiters I add a space at the end of the line
116
+ boardsTXT = boardsTXT .replace ("\n " , " \n " );
117
+
118
+ String correctMAN =" \" -DUSB_MANUFACTURER=\\ \" {build.usb_manufacturer}\\ \" \" " ;
119
+ String correctPROD =" \" -DUSB_PRODUCT=\\ \" {build.usb_product}\\ \" \" " ;
120
+ String correctBOARD =" \" -DARDUINO_BOARD=\\ \" {build.board}\\ \" \" " ;
109
121
110
122
if (SystemUtils .IS_OS_WINDOWS ) {
111
123
// replace FI circuitplay32u4cat.build.usb_manufacturer="Adafruit"
112
124
// with circuitplay32u4cat.build.usb_manufacturer=Adafruit
113
125
boardsTXT = boardsTXT .replaceAll ("(\\ S+\\ .build\\ .usb\\ S+)=\\ \" (.+)\\ \" " , "$1=$2" );
126
+
127
+ // quoting fixes for embedutils ['\"]?(-DMBEDTLS_\S+)=\\?"(mbedtls\S+?)\\?\"["']? \"$1=\\\"$2\\\"\"
128
+ boardsTXT = boardsTXT .replaceAll (" ['\\ \" ]?(-DMBEDTLS_\\ S+)=\\ \\ ?\" (mbedtls\\ S+?)\\ \\ ?\\ \" [\" ']? " ,
129
+ " \\ \" $1=\\ \\ \\ \" $2\\ \\ \\ \" \\ \" " );
130
+
131
+ } else {
132
+ correctMAN =" '-DUSB_MANUFACTURER=\" {build.usb_manufacturer}\" ' " ;
133
+ correctPROD =" '-DUSB_PRODUCT=\" {build.usb_product}\" '" ;
134
+ correctBOARD =" '-DARDUINO_BOARD=\" {build.board}\" ' " ;
114
135
}
136
+ // some providers put -DUSB_PRODUCT={build.usb_product} in boards.txt
137
+ boardsTXT = boardsTXT .replace (" \" -DUSB_MANUFACTURER={build.usb_manufacturer}\" " ,correctMAN );
138
+ boardsTXT = boardsTXT .replace (" \" -DUSB_PRODUCT={build.usb_product}\" " ,correctPROD );
139
+ boardsTXT = boardsTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,correctBOARD );
140
+
141
+ boardsTXT = boardsTXT .replace (" '-DUSB_MANUFACTURER={build.usb_manufacturer}' " ,correctMAN );
142
+ boardsTXT = boardsTXT .replace (" '-DUSB_PRODUCT={build.usb_product}' " ,correctPROD );
143
+ boardsTXT = boardsTXT .replace (" '-DARDUINO_BOARD=\" {build.board}' " ,correctBOARD );
115
144
FileUtils .write (boardsSloeberTXT , boardsTXT , Charset .defaultCharset ());
116
145
} catch (IOException e ) {
117
146
Common .log (new Status (IStatus .WARNING , Activator .getId (),
@@ -123,12 +152,16 @@ static synchronized public File MakeBoardsSloeberTxt(File requestedFileToWorkAro
123
152
}
124
153
125
154
/**
126
- * create a workedaround platform.txt and return that filz
155
+ * * Get the a workaround platform.txt and if needed create/update it
156
+ * This method takes a platform.txt file and returns a worked around file.
157
+ * The worked around file is persisted on disk for easy debugging/ reduce code impact
158
+ * and performance.
159
+ *
127
160
*
128
- * @param requestedFileToWorkAround
161
+ * @param requestedFileToWorkAround the platform.txt you want to process
129
162
*
130
- * @return the worked around file or requestedFileToWorkAround is it does not
131
- * exist or error
163
+ * @return the worked around file or requestedFileToWorkAround if it does not
164
+ * exist or an error occurred
132
165
*/
133
166
public synchronized static File MakePlatformSloeberTXT (File requestedFileToWorkAround ) {
134
167
if (!requestedFileToWorkAround .exists ()) {
@@ -192,8 +225,10 @@ public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkA
192
225
}
193
226
194
227
// for adafruit nfr
195
- platformTXT = platformTXT .replace ("-DARDUINO_BSP_VERSION=\" {version}\" " ,
196
- "\" -DARDUINO_BSP_VERSION=\\ \" {version}\\ \" \" " );
228
+ platformTXT = platformTXT .replace (" -DARDUINO_BSP_VERSION=\" {version}\" " ,
229
+ " \" -DARDUINO_BSP_VERSION=\\ \" {version}\\ \" \" " );
230
+ platformTXT = platformTXT .replace (" '-DARDUINO_BSP_VERSION=\" {version}\" ' " ,
231
+ " \" -DARDUINO_BSP_VERSION=\\ \" {version}\\ \" \" " );
197
232
198
233
if (SystemUtils .IS_OS_WINDOWS ) {
199
234
// replace FI '-DUSB_PRODUCT={build.usb_product}' with
@@ -214,8 +249,7 @@ public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkA
214
249
platformTXT = platformTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,
215
250
" \" -DARDUINO_BOARD=\\ \" {build.board}\\ \" \" " );
216
251
217
- }
218
- if (SystemUtils .IS_OS_LINUX ) {
252
+ } else {
219
253
platformTXT = platformTXT .replace (" -DUSB_MANUFACTURER={build.usb_manufacturer} " ,
220
254
" '-DUSB_MANUFACTURER=\" {build.usb_manufacturer}\" ' " );
221
255
platformTXT = platformTXT .replace (" -DUSB_PRODUCT={build.usb_product} " ,
0 commit comments