Skip to content

Commit 47bbfbb

Browse files
author
jan
committed
some tweeking based on windows tests and updating comments
1 parent da4ffc7 commit 47bbfbb

File tree

1 file changed

+54
-20
lines changed

1 file changed

+54
-20
lines changed

io.sloeber.core/src/io/sloeber/core/managers/WorkAround.java

+54-20
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
import io.sloeber.core.tools.Version;
2020

2121
/**
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
2426
*
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
2830
*
2931
* @author jan
3032
*
@@ -33,11 +35,11 @@
3335
public class WorkAround {
3436
// Each time this class is touched consider changing the String below to enforce
3537
// 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";
3739

3840
/**
3941
* 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
4143
* time
4244
*
4345
* @param platform
@@ -70,12 +72,15 @@ static synchronized public void applyKnownWorkArounds(ArduinoPlatform platform)
7072
}
7173

7274
/**
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.
7479
*
75-
* @param requestedFileToWorkAround
80+
* @param requestedFileToWorkAround the board.txt that you want to process
7681
*
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
7984
*/
8085
static synchronized public File MakeBoardsSloeberTxt(File requestedFileToWorkAround) {
8186
if (!requestedFileToWorkAround.exists()) {
@@ -105,13 +110,37 @@ static synchronized public File MakeBoardsSloeberTxt(File requestedFileToWorkAro
105110
try {
106111
String boardsTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n";
107112
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}\\\"\" ";
109121

110122
if (SystemUtils.IS_OS_WINDOWS) {
111123
// replace FI circuitplay32u4cat.build.usb_manufacturer="Adafruit"
112124
// with circuitplay32u4cat.build.usb_manufacturer=Adafruit
113125
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}\"' ";
114135
}
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 );
115144
FileUtils.write(boardsSloeberTXT, boardsTXT, Charset.defaultCharset());
116145
} catch (IOException e) {
117146
Common.log(new Status(IStatus.WARNING, Activator.getId(),
@@ -123,12 +152,16 @@ static synchronized public File MakeBoardsSloeberTxt(File requestedFileToWorkAro
123152
}
124153

125154
/**
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+
*
127160
*
128-
* @param requestedFileToWorkAround
161+
* @param requestedFileToWorkAround the platform.txt you want to process
129162
*
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
132165
*/
133166
public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
134167
if (!requestedFileToWorkAround.exists()) {
@@ -192,8 +225,10 @@ public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkA
192225
}
193226

194227
// 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}\\\"\" ");
197232

198233
if (SystemUtils.IS_OS_WINDOWS) {
199234
// replace FI '-DUSB_PRODUCT={build.usb_product}' with
@@ -214,8 +249,7 @@ public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkA
214249
platformTXT = platformTXT.replace(" -DARDUINO_BOARD=\"{build.board}\" ",
215250
" \"-DARDUINO_BOARD=\\\"{build.board}\\\"\" ");
216251

217-
}
218-
if(SystemUtils.IS_OS_LINUX) {
252+
} else {
219253
platformTXT = platformTXT.replace(" -DUSB_MANUFACTURER={build.usb_manufacturer} ",
220254
" '-DUSB_MANUFACTURER=\"{build.usb_manufacturer}\"' ");
221255
platformTXT = platformTXT.replace(" -DUSB_PRODUCT={build.usb_product} ",

0 commit comments

Comments
 (0)