Skip to content

Commit 863f5d3

Browse files
author
jantje
committed
#1498 environ names as toolPattern and expand them in gnuMakefileGen
By expanding the environment name I can match the platform.sloeber.txt with what CDT wants. This makes for a better match between the sloeber run commands and the arduino IDE run commands Only the combiner does not place the archives in the same place as Arduino IDE
1 parent 0e62027 commit 863f5d3

File tree

4 files changed

+68
-47
lines changed

4 files changed

+68
-47
lines changed

io.sloeber.core/plugin.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
<tool
163163
announcement="%tool.Arduino.CPP.announcement"
164164
command="${recipe.cpp.o.pattern}"
165-
commandLinePattern="${recipe.cpp.o.pattern} ${FLAGS} -D__IN_ECLIPSE__=1 ${INPUTS} -o ${OUTPUT} ${sloeber.extra.compile} ${sloeber.extra.cpp.compile} ${sloeber.extra.all}"
165+
commandLinePattern="recipe.cpp.o.pattern"
166166
errorParsers="org.eclipse.cdt.core.GCCErrorParser"
167167
id="io.sloeber.tool.sketch.compiler.cpp"
168168
name="%tool.Arduino.CPP2O.name"
@@ -209,7 +209,7 @@
209209
<tool
210210
announcement="%tool.Arduino.C.announcement"
211211
command="${recipe.c.o.pattern}"
212-
commandLinePattern="${recipe.c.o.pattern} ${FLAGS} -D__IN_ECLIPSE__=1 ${INPUTS} -o ${OUTPUT} ${sloeber.extra.compile} ${sloeber.extra.c.compile} ${sloeber.extra.all}"
212+
commandLinePattern="recipe.c.o.pattern"
213213
errorParsers="org.eclipse.cdt.core.GCCErrorParser"
214214
id="io.sloeber.tool.compiler.c"
215215
name="%tool.Arduino.C2O.name"
@@ -257,7 +257,7 @@
257257
<tool
258258
announcement="%tool.Arduino.S.announcement"
259259
command="${recipe.S.o.pattern}"
260-
commandLinePattern="${recipe.S.o.pattern} ${FLAGS} ${INPUTS} -o ${OUTPUT} ${sloeber.extra.assembly} ${sloeber.extra.all}"
260+
commandLinePattern="recipe.S.o.pattern"
261261
errorParsers="org.eclipse.cdt.core.GCCErrorParser"
262262
id="io.sloeber.tool.sketch.compiler.s"
263263
name="%tool.Arduino.S20.name"
@@ -304,7 +304,7 @@
304304
<tool
305305
announcement="%tool.Arduino.archiver.announcement"
306306
command="${recipe.ar.pattern}"
307-
commandLinePattern="${recipe.ar.pattern} ${FLAGS} ${archive_file_path} ${INPUTS} ${sloeber.extra_archive} ${sloeber.extra_all}"
307+
commandLinePattern="recipe.ar.pattern"
308308
errorParsers="org.eclipse.cdt.core.GLDErrorParser"
309309
id="io.sloeber.tool.ar"
310310
name="%tool.archiver.name">
@@ -329,7 +329,7 @@
329329
<tool
330330
announcement="%tool.Arduino.combiner.announcement"
331331
command="${recipe.c.combine.pattern}"
332-
commandLinePattern="${sloeber.pre.link}${recipe.c.combine.pattern} ${FLAGS} ${INPUTS} ${AR} ${sloeber.extra_all} ${sloeber.extra.link}${sloeber.post.link}"
332+
commandLinePattern="recipe.c.combine.pattern"
333333
errorParsers="org.eclipse.cdt.core.GLDErrorParser"
334334
id="io.sloeber.tool.combine"
335335
name="%tool.combiner.name"
@@ -396,7 +396,7 @@
396396
<tool
397397
announcement="%tool.printsize.announcement"
398398
command="${sloeber.size.switch} "
399-
commandLinePattern="${COMMAND}"
399+
commandLinePattern="${sloeber.size.switch} "
400400
id="io.sloeber.tool.size"
401401
isAbstract="false"
402402
name="%tool.printsize.name">

io.sloeber.core/src/io/sloeber/core/common/Common.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ static public String getBuildEnvironmentVariable(IProject project, String config
171171

172172
/**
173173
*
174-
* Provides the build environment variable based on project and string This
174+
* Provides the build environment variable based on project default
175+
* configuration and string This
175176
* method does not add any knowledge.(like adding A.)
176177
*
177178
* @param project
@@ -185,7 +186,7 @@ static public String getBuildEnvironmentVariable(IProject project, String config
185186
*/
186187
static public String getBuildEnvironmentVariable(IProject project, String envName, String defaultvalue) {
187188
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
188-
return getBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), envName, defaultvalue);
189+
return getBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), envName, defaultvalue, true);
189190
}
190191

191192
/**

io.sloeber.core/src/io/sloeber/core/toolchain/ArduinoGnuMakefileGenerator.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848

4949
import org.apache.commons.io.FileUtils;
5050
import org.eclipse.cdt.core.CCorePlugin;
51+
import org.eclipse.cdt.core.model.CoreModel;
5152
import org.eclipse.cdt.core.settings.model.CSourceEntry;
5253
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
54+
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
5355
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
5456
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
5557
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
@@ -906,7 +908,7 @@ public MultiStatus regenerateMakefiles() throws CoreException {
906908
IFile sizeAwkFile1 = root.getFile(topBuildDir.append("size.awk"));
907909
File sizeAwkFile = sizeAwkFile1.getLocation().toFile();
908910
String regex = Common.getBuildEnvironmentVariable(confDesc, "recipe.size.regex", EMPTY);
909-
String awkContent = "/" + regex + "/ {arduino_size += $2 }\n";
911+
String awkContent = "/" + regex + "/ {arduino_size += $2 }\n";
910912
regex = Common.getBuildEnvironmentVariable(confDesc, "recipe.size.regex.data", EMPTY);
911913
awkContent += "/" + regex + "/ {arduino_data += $2 }\n";
912914
regex = Common.getBuildEnvironmentVariable(confDesc, "recipe.size.regex.eeprom", EMPTY);
@@ -1628,7 +1630,7 @@ protected boolean addRuleForTool(ITool tool, StringBuffer buffer, boolean bTarge
16281630
String[] cmdInputs = inputs.toArray(new String[inputs.size()]);
16291631
IManagedCommandLineGenerator gen = tool.getCommandLineGenerator();
16301632
IManagedCommandLineInfo cmdLInfo = gen.generateCommandLineInfo(tool, command, flags, outflag, outputPrefix,
1631-
primaryOutputs, cmdInputs, tool.getCommandLinePattern());
1633+
primaryOutputs, cmdInputs, getToolCommandLinePattern(tool));
16321634
// The command to build
16331635
String buildCmd = null;
16341636
if (cmdLInfo == null) {
@@ -2212,7 +2214,7 @@ private IManagedCommandLineInfo generateToolCommandLineInfo(ITool tool, String s
22122214
}
22132215
IManagedCommandLineGenerator gen = tool.getCommandLineGenerator();
22142216
return gen.generateCommandLineInfo(tool, cmd, flags, outputFlag, outputPrefix, outputName, inputResources,
2215-
tool.getCommandLinePattern());
2217+
getToolCommandLinePattern(tool));
22162218
}
22172219

22182220
/**
@@ -2577,7 +2579,7 @@ && containsSpecialCharacters(sourceLocation.toOSString()))
25772579
// Call the command line generator
25782580
IManagedCommandLineGenerator cmdLGen = tool.getCommandLineGenerator();
25792581
cmdLInfo = cmdLGen.generateCommandLineInfo(tool, cmd, flags, outflag, outputPrefix,
2580-
OUT_MACRO + otherPrimaryOutputs, inputStrings, tool.getCommandLinePattern());
2582+
OUT_MACRO + otherPrimaryOutputs, inputStrings, getToolCommandLinePattern(tool));
25812583
} else {
25822584
outflag = tool.getOutputFlag();
25832585
outputPrefix = tool.getOutputPrefix();
@@ -4525,4 +4527,16 @@ private ToolInfoHolder getToolInfo(IPath path, boolean create) {
45254527
}
45264528
return h;
45274529
}
4530+
4531+
private String getToolCommandLinePattern(ITool tool) {
4532+
String orgPattern = tool.getCommandLinePattern();
4533+
if (orgPattern.contains("$")) {
4534+
//if the pattern contains a space no use to try to expand it
4535+
return orgPattern;
4536+
}
4537+
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
4538+
ICConfigurationDescription confDesc = prjDesc.getConfigurationByName(config.getName());
4539+
return Common.getBuildEnvironmentVariable(confDesc, orgPattern, orgPattern, false);
4540+
4541+
}
45284542
}

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

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
public class WorkAround extends Const {
4646
// Each time this class is touched consider changing the String below to enforce
4747
// updates
48-
private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created workaound file V1.05.test 05 ";
48+
private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created TXT file V2.00.test 04 ";
4949

5050
/**
5151
* workarounds done at installation time. I try to keep those at a minimum but
@@ -318,51 +318,57 @@ private static String platformApplyStandardWorkArounds(String inPlatformTxt) {
318318
String platformTXT = inPlatformTxt;
319319
String searchPlatformTXT = "\n" + inPlatformTxt;
320320

321-
//C o need the input and output file stuff removed as CDT wants thes at the command level
322-
String inCORecipe = findLineStartingWith(platformTXT, RECIPE_C_to_O);
323-
if (null != inCORecipe) {
324-
String outCORecipe = inCORecipe.replace(" -o ", " ");
325-
outCORecipe = outCORecipe.replace(" \"{source_file}\"", " ");
326-
outCORecipe = outCORecipe.replace(" \"{object_file}\"", " ");
327-
platformTXT = platformTXT.replace(inCORecipe, outCORecipe);
321+
String origRecipe = findLineStartingWith(platformTXT, RECIPE_C_to_O);
322+
if (null != origRecipe) {
323+
String changed = origRecipe.replace("\"{source_file}\"", "{INPUTS}");
324+
changed = changed.replace("\"{object_file}\"", "{OUTPUT}");
325+
changed = changed.replace("{includes}", "{FLAGS} -D__IN_ECLIPSE__=1");
326+
changed = changed + " {sloeber.extra.compile} {sloeber.extra.c.compile} {sloeber.extra.all}";
327+
platformTXT = platformTXT.replace(origRecipe, changed);
328328
}
329329

330-
//Cpp o need the input and output file stuff removed as CDT wants thes at the command level
331-
String inCppORecipe = findLineStartingWith(platformTXT, RECIPE_CPP_to_O);
332-
if (null != inCppORecipe) {
333-
String outCppORecipe = inCppORecipe.replace(" -o ", " ");
334-
outCppORecipe = outCppORecipe.replace(" \"{source_file}\"", " ");
335-
outCppORecipe = outCppORecipe.replace(" \"{object_file}\"", " ");
336-
platformTXT = platformTXT.replace(inCppORecipe, outCppORecipe);
330+
origRecipe = findLineStartingWith(platformTXT, RECIPE_CPP_to_O);
331+
if (null != origRecipe) {
332+
String changed = origRecipe.replace("\"{source_file}\"", "{INPUTS}");
333+
changed = changed.replace("\"{object_file}\"", "{OUTPUT}");
334+
changed = changed.replace("{includes}", "{FLAGS} -D__IN_ECLIPSE__=1");
335+
changed = changed + " {sloeber.extra.compile} {sloeber.extra.cpp.compile} {sloeber.extra.all}";
336+
platformTXT = platformTXT.replace(origRecipe, changed);
337337
}
338338

339-
//S o need the input and output file stuff removed as CDT wants thes at the command level
340-
String inSORecipe = findLineStartingWith(platformTXT, RECIPE_S_to_O);
341-
if (null != inSORecipe) {
342-
String outSORecipe = inSORecipe.replace(" -o ", " ");
343-
outSORecipe = outSORecipe.replace(" \"{source_file}\"", " ");
344-
outSORecipe = outSORecipe.replace(" \"{object_file}\"", " ");
345-
platformTXT = platformTXT.replace(inSORecipe, outSORecipe);
339+
origRecipe = findLineStartingWith(platformTXT, RECIPE_S_to_O);
340+
if (null != origRecipe) {
341+
String changed = origRecipe.replace("\"{source_file}\"", "{INPUTS}");
342+
changed = changed.replace("\"{object_file}\"", "{OUTPUT}");
343+
changed = changed.replace("{includes}", "{FLAGS} -D__IN_ECLIPSE__=1");
344+
changed = changed + " {sloeber.extra.assembly} {sloeber.extra.all}";
345+
platformTXT = platformTXT.replace(origRecipe, changed);
346346
}
347347

348-
//Archiver needs the "{archive_file_path}" "{object_file}" file stuff removed as CDT wants thes at the command level
349-
String inArRecipe = findLineStartingWith(platformTXT, RECIPE_AR);
350-
if (null != inArRecipe) {
351-
String outArRecipe = inArRecipe.replace(" {archive_file_path} ", " ");
352-
outArRecipe = outArRecipe.replace(" {object_file}", " ");
353-
platformTXT = platformTXT.replace(inArRecipe, outArRecipe);
348+
origRecipe = findLineStartingWith(platformTXT, RECIPE_AR);
349+
if (null != origRecipe) {
350+
//archives should get a different key but for now I didn't get that to work
351+
String changed = origRecipe.replace("\"{archive_file_path}\"", "{OUTPUT}");
352+
changed = changed.replace("{archive_file_path}", "{OUTPUT}");
353+
changed = changed.replace("\"{object_file}\"", "{INPUTS}");
354+
changed = changed.replace("{object_file}", "{INPUTS}");
355+
changed = changed + " {sloeber.extra_archive} {sloeber.extra_all}";
356+
platformTXT = platformTXT.replace(origRecipe, changed);
354357
}
355358

356-
String inCombineRecipe = findLineStartingWith(platformTXT, RECIPE_C_COMBINE);
357-
if (null != inArRecipe) {
359+
origRecipe = findLineStartingWith(platformTXT, RECIPE_C_COMBINE);
360+
if (null != origRecipe) {
358361
// the fix below seems no longer needed but is still on august 2021
359362
// Arduino treats core differently so we need to change the location of directly
360363
// referenced files this manifests only in the combine recipe
361-
String outCombineRecipe = inCombineRecipe.replaceAll("(\\{build\\.path})(/core)?/sys", "$1/core/core/sys");
362-
363-
outCombineRecipe = outCombineRecipe.replace(" \"{build.path}/{archive_file}\"", " ");
364-
outCombineRecipe = outCombineRecipe.replace(" {object_files}", " ");
365-
platformTXT = platformTXT.replace(inCombineRecipe, outCombineRecipe);
364+
String changed = origRecipe.replaceAll("(\\{build\\.path})(/core)?/sys", "$1/core/core/sys");
365+
366+
changed = changed.replace(" \"{build.path}/{archive_file}\"", " {ARCHIVES}");
367+
changed = changed.replace(" {object_files}", " ${FLAGS} {INPUTS}");
368+
String[] splits = changed.split("=", 2);
369+
changed = splits[0] + "={sloeber.pre.link}" + splits[1]
370+
+ " {sloeber.extra_all} {sloeber.extra.link}{sloeber.post.link}";
371+
platformTXT = platformTXT.replace(origRecipe, changed);
366372
}
367373

368374
// replace tools.x.y* {path}

0 commit comments

Comments
 (0)