Skip to content

Commit e4dc006

Browse files
author
jan
committed
Put the arduino size command in a bat file and run it this way #1671
1 parent 34c3798 commit e4dc006

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

io.sloeber.core/src/io/sloeber/core/api/CompileDescription.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public String getEnvValue() {
222222
switch (this) {
223223
case ARDUINO_WAY:
224224
if(isWindows) {
225-
return "wsl -- ${sloeber.size_command.awk}"; //$NON-NLS-1$
225+
return "arduino-size.bat"; //$NON-NLS-1$
226226
}
227227
return "${sloeber.size_command.awk}"; //$NON-NLS-1$
228228
case AVR_ALTERNATIVE:

io.sloeber.core/src/io/sloeber/core/builder/SloeberBuilderExtension.java

+41-1
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,14 @@ public void beforeAddingSourceRules(IAutoBuildMakeRules makeRules,
6969
makeRules.getSourceFilesToBuild().add(sloeberInoCppFile);
7070
}
7171
generateAwkFile(autoBuildConfData);
72+
generateArduinoSizeCommandFile(autoBuildConfData);
73+
7274
super.beforeAddingSourceRules(makeRules, autoBuildConfData);
7375
}
7476

77+
78+
79+
7580
@Override
7681
public boolean invokeBuild(IBuilder builder, int kind, String targetName, IAutoBuildConfigurationDescription autoData,
7782
IMarkerGenerator markerGenerator, IConsole console, IProgressMonitor monitor) throws CoreException {
@@ -122,6 +127,33 @@ public SloeberBuilderExtension() {
122127
// Nothing to do here
123128
}
124129

130+
131+
@SuppressWarnings("nls")
132+
private static void generateArduinoSizeCommandFile(IAutoBuildConfigurationDescription autoBuildConfData) {
133+
if(!isWindows) {
134+
return;
135+
}
136+
IFile sizeCommandIFile = autoBuildConfData.getBuildFolder().getFile("arduino-size.bat");
137+
SloeberConfiguration confDesc = SloeberConfiguration.getFromAutoBuildConfDesc(autoBuildConfData);
138+
139+
File sizeCommandFile = sizeCommandIFile.getLocation().toFile();
140+
String content = Common.getBuildEnvironmentVariable(confDesc, "sloeber.size_command.awk", EMPTY);
141+
142+
try {
143+
if (sizeCommandFile.exists()) {
144+
String curContent = FileUtils.readFileToString(sizeCommandFile, Charset.defaultCharset());
145+
if (!curContent.equals(content)) {
146+
sizeCommandFile.delete();
147+
}
148+
}
149+
if (!sizeCommandFile.exists()) {
150+
FileUtils.write(sizeCommandFile, content, Charset.defaultCharset());
151+
}
152+
} catch (IOException e) {
153+
e.printStackTrace();
154+
}
155+
}
156+
125157
@SuppressWarnings("nls")
126158
private static void generateAwkFile(IAutoBuildConfigurationDescription autoBuildConfData) {
127159
IFile sizeAwkFile1 = autoBuildConfData.getBuildFolder().getFile("size.awk");
@@ -144,7 +176,15 @@ private static void generateAwkFile(IAutoBuildConfigurationDescription autoBuild
144176
awkContent += "\"}";
145177

146178
try {
147-
FileUtils.write(sizeAwkFile, awkContent, Charset.defaultCharset());
179+
if (sizeAwkFile.exists()) {
180+
String curContent = FileUtils.readFileToString(sizeAwkFile, Charset.defaultCharset());
181+
if (!curContent.equals(awkContent)) {
182+
sizeAwkFile.delete();
183+
}
184+
}
185+
if (!sizeAwkFile.exists()) {
186+
FileUtils.write(sizeAwkFile, awkContent, Charset.defaultCharset());
187+
}
148188
} catch (IOException e) {
149189
e.printStackTrace();
150190
}

0 commit comments

Comments
 (0)