Skip to content

Commit 9da75b8

Browse files
authored
Merge pull request #1500 from Sloeber/#1498_Support_for_static_libraries
#1498 support for static libraries
2 parents a4ffb72 + 2cd4052 commit 9da75b8

File tree

7 files changed

+133
-112
lines changed

7 files changed

+133
-112
lines changed

io.sloeber.core/plugin.xml

+17-12
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.1} ${FLAGS} -D__IN_ECLIPSE__=1 -x c++ ${INPUTS} ${recipe.cpp.o.pattern.2} -o ${OUTPUT} ${recipe.cpp.o.pattern.3} ${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.1} ${FLAGS} -D__IN_ECLIPSE__=1 ${INPUTS} ${recipe.c.o.pattern.2} -o ${OUTPUT} ${recipe.c.o.pattern.3} ${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"
@@ -242,7 +242,7 @@
242242
id="io.sloeber.compiler.c.link.output"
243243
name="%outputType.C.link.name"
244244
nameProvider="io.sloeber.core.toolchain.LinkNameProvider"
245-
outputs="o"
245+
outputs="O"
246246
primaryOutput="true">
247247
</outputType>
248248
<outputType
@@ -257,7 +257,7 @@
257257
<tool
258258
announcement="%tool.Arduino.S.announcement"
259259
command="${recipe.S.o.pattern}"
260-
commandLinePattern="${recipe.S.o.pattern.1} ${FLAGS} ${INPUTS} ${recipe.S.o.pattern.2} -o ${OUTPUT} ${recipe.S.o.pattern.3} ${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.1} ${FLAGS} ${archive_file_path} ${INPUTS} ${recipe.ar.pattern.2} ${recipe.ar.pattern.3} ${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.1} ${FLAGS} ${INPUTS} ${recipe.c.combine.pattern.2} ${archive_file_path} ${recipe.c.combine.pattern.3} ${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"
@@ -342,17 +342,22 @@
342342
outputs="elf"
343343
primaryOutput="true">
344344
</outputType>
345-
<inputType
345+
<inputType
346346
buildVariable="LINK_OBJ"
347347
id="io.sloeber.tool.combiner.ob.input"
348348
multipleOfType="true"
349349
name="%inputType.linker.name"
350350
primaryInput="true"
351351
sources="O">
352-
<additionalInput
353-
kind="additionaldependency"
354-
paths="$(AR)">
355-
</additionalInput>
352+
</inputType>
353+
<inputType
354+
buildVariable="AR"
355+
id="io.sloeber.tool.combiner.ar.input"
356+
multipleOfType="true"
357+
name="Build Archives"
358+
option="ARCHIVES"
359+
primaryInput="false"
360+
sources="ar">
356361
</inputType>
357362
</tool>
358363
<tool
@@ -385,7 +390,7 @@
385390
<tool
386391
announcement="%tool.printsize.announcement"
387392
command="${sloeber.size.switch} "
388-
commandLinePattern="${COMMAND}"
393+
commandLinePattern="${sloeber.size.switch} "
389394
id="io.sloeber.tool.size"
390395
isAbstract="false"
391396
name="%tool.printsize.name">

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

-41
Original file line numberDiff line numberDiff line change
@@ -960,47 +960,6 @@ private Map<String, String> getEnvVarsPostProcessing(Map<String, String> vars) {
960960

961961
Map<String, String> extraVars = new HashMap<>();
962962

963-
// split the recipes so we can add the input and output markers as cdt needs
964-
// them
965-
String recipeKeys[] = { RECIPE_C_to_O, RECIPE_CPP_to_O, RECIPE_S_to_O, RECIPE_SIZE, RECIPE_AR,
966-
RECIPE_C_COMBINE };
967-
for (String recipeKey : recipeKeys) {
968-
String recipe = vars.get(recipeKey);
969-
if (null == recipe) {
970-
continue;
971-
}
972-
973-
// Sloeber should split o, -o {output} but to be safe that needs a regex so I
974-
// simply delete the -o
975-
if (!RECIPE_C_COMBINE.equals(recipeKey)) {
976-
recipe = recipe.replace(" -o ", " "); //$NON-NLS-1$ //$NON-NLS-2$
977-
}
978-
String recipeParts[] = recipe.split(
979-
"(\"\\$\\{object_file}\")|(\\$\\{object_files})|(\"\\$\\{source_file}\")|(\"[^\"]*\\$\\{archive_file}\")|(\"[^\"]*\\$\\{archive_file_path}\")", //$NON-NLS-1$
980-
3);
981-
982-
switch (recipeParts.length) {
983-
case 0:
984-
extraVars.put(recipeKey + DOT + '1', "echo no command for \"{KEY}\".".replace(KEY_TAG, recipeKey)); //$NON-NLS-1$
985-
break;
986-
case 1:
987-
extraVars.put(recipeKey + DOT + '1', recipeParts[0]);
988-
break;
989-
case 2:
990-
extraVars.put(recipeKey + DOT + '1', recipeParts[0]);
991-
extraVars.put(recipeKey + DOT + '2', recipeParts[1]);
992-
break;
993-
case 3:
994-
extraVars.put(recipeKey + DOT + '1', recipeParts[0]);
995-
extraVars.put(recipeKey + DOT + '2', recipeParts[1]);
996-
extraVars.put(recipeKey + DOT + '3', recipeParts[2]);
997-
998-
break;
999-
default:
1000-
// this should never happen as the split is limited to 3
1001-
}
1002-
}
1003-
1004963
ArrayList<String> objcopyCommand = new ArrayList<>();
1005964
for (Entry<String, String> curVariable : vars.entrySet()) {
1006965
String name = curVariable.getKey();

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

-6
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,6 @@ private HashMap<String, String> getEnvVars(String configKey) {
403403
+ makeEnvironmentVar(ENV_KEY_BUILD_GENERIC_PATH) + pathDelimiter + makeEnvironmentVar("PATH")); //$NON-NLS-1$
404404
}
405405

406-
// Set the codeAnalyzer compile commands
407-
allVars.put(CODAN_C_to_O,
408-
"${recipe.c.o.pattern.1} -D__IN_ECLIPSE__=1 ${recipe.c.o.pattern.2} ${recipe.c.o.pattern.3} ${sloeber.extra.compile} ${sloeber.extra.c.compile} ${sloeber.extra.all}"); //$NON-NLS-1$
409-
allVars.put(CODAN_CPP_to_O,
410-
"${recipe.cpp.o.pattern.1} -D__IN_ECLIPSE__=1 -x c++ ${recipe.cpp.o.pattern.2} ${recipe.cpp.o.pattern.3} ${sloeber.extra.compile} ${sloeber.extra.cpp.compile} ${sloeber.extra.all}"); //$NON-NLS-1$
411-
412406
return allVars;
413407
}
414408

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

+3-2
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

+29-4
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) {
@@ -1646,6 +1648,17 @@ protected boolean addRuleForTool(ITool tool, StringBuffer buffer, boolean bTarge
16461648
// resolve any remaining macros in the command after it has been
16471649
// generated
16481650
try {
1651+
//TOFIX JABA heavy hack to get the combiner to work properly
1652+
//if the command contains ${ARCHIVES}
1653+
//remove the ${AR}
1654+
//replace ${ARCHIVES} with ${AR}
1655+
String ARCHIVES = " ${ARCHIVES} ";
1656+
String AR = " $(AR) ";
1657+
if (buildCmd.contains(ARCHIVES)) {
1658+
buildCmd = buildCmd.replace(AR, " ");
1659+
buildCmd = buildCmd.replace(ARCHIVES, AR);
1660+
}
1661+
//end JABA heavy hack
16491662
String resolvedCommand = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(
16501663
buildCmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE,
16511664
new FileContextData(null, null, null, tool));
@@ -2212,7 +2225,7 @@ private IManagedCommandLineInfo generateToolCommandLineInfo(ITool tool, String s
22122225
}
22132226
IManagedCommandLineGenerator gen = tool.getCommandLineGenerator();
22142227
return gen.generateCommandLineInfo(tool, cmd, flags, outputFlag, outputPrefix, outputName, inputResources,
2215-
tool.getCommandLinePattern());
2228+
getToolCommandLinePattern(tool));
22162229
}
22172230

22182231
/**
@@ -2577,7 +2590,7 @@ && containsSpecialCharacters(sourceLocation.toOSString()))
25772590
// Call the command line generator
25782591
IManagedCommandLineGenerator cmdLGen = tool.getCommandLineGenerator();
25792592
cmdLInfo = cmdLGen.generateCommandLineInfo(tool, cmd, flags, outflag, outputPrefix,
2580-
OUT_MACRO + otherPrimaryOutputs, inputStrings, tool.getCommandLinePattern());
2593+
OUT_MACRO + otherPrimaryOutputs, inputStrings, getToolCommandLinePattern(tool));
25812594
} else {
25822595
outflag = tool.getOutputFlag();
25832596
outputPrefix = tool.getOutputPrefix();
@@ -4525,4 +4538,16 @@ private ToolInfoHolder getToolInfo(IPath path, boolean create) {
45254538
}
45264539
return h;
45274540
}
4541+
4542+
private String getToolCommandLinePattern(ITool tool) {
4543+
String orgPattern = tool.getCommandLinePattern();
4544+
if (orgPattern.contains("$")) {
4545+
//if the pattern contains a space no use to try to expand it
4546+
return orgPattern;
4547+
}
4548+
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
4549+
ICConfigurationDescription confDesc = prjDesc.getConfigurationByName(config.getName());
4550+
return Common.getBuildEnvironmentVariable(confDesc, orgPattern, orgPattern, false);
4551+
4552+
}
45284553
}
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,26 @@
11
package io.sloeber.core.toolchain;
22

3-
import org.eclipse.cdt.core.CCorePlugin;
4-
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
5-
import org.eclipse.cdt.core.model.CoreModel;
6-
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
7-
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
3+
import static io.sloeber.core.common.Const.*;
4+
85
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
96
import org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector;
107

11-
import io.sloeber.core.common.Const;
12-
13-
@SuppressWarnings({"nls","unused"})
14-
public class ArduinoLanguageProvider extends GCCBuiltinSpecsDetector{
15-
16-
17-
18-
@Override
19-
protected String getCompilerCommand(String languageId) {
20-
String ret = new String();
21-
22-
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(currentProject);
23-
if (prjDesc == null)
24-
return ret;
25-
ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
26-
27-
String codanVarName = new String();
28-
if (languageId.equals("org.eclipse.cdt.core.gcc")) {
29-
codanVarName = Const.CODAN_C_to_O;
30-
} else if (languageId.equals("org.eclipse.cdt.core.g++")) {
31-
codanVarName = Const.CODAN_CPP_to_O;
32-
} else {
33-
ManagedBuilderCorePlugin.error(
34-
"Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId());
35-
}
8+
@SuppressWarnings({ "nls", "unused" })
9+
public class ArduinoLanguageProvider extends GCCBuiltinSpecsDetector {
3610

37-
try {
38-
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
39-
ret = envManager.getVariable(codanVarName, confDesc, false).getValue();
40-
} catch (Exception e) {
41-
ret = new String();
42-
}
11+
@Override
12+
protected String getCompilerCommand(String languageId) {
4313

14+
if (languageId.equals("org.eclipse.cdt.core.gcc")) {
15+
return "${" + CODAN_C_to_O + "}";
16+
} else if (languageId.equals("org.eclipse.cdt.core.g++")) {
17+
return "${" + CODAN_CPP_to_O + "}";
18+
} else {
19+
ManagedBuilderCorePlugin.error(
20+
"Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId());
21+
}
4422

45-
return ret;
46-
}
23+
return null;
24+
}
4725

4826
}

0 commit comments

Comments
 (0)