Skip to content

Commit 87129e4

Browse files
author
jantje
committed
implementation for #387
1 parent 2acfa55 commit 87129e4

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/common/Const.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,6 @@ public class Const {
177177
public static final String POST_PROCESSING_BOARDS_TXT = "post_processing_boards.txt"; //$NON-NLS-1$
178178
public static final String PRE_PROCESSING_PLATFORM_TXT = "pre_processing_platform.txt"; //$NON-NLS-1$
179179
public static final String POST_PROCESSING_PLATFORM_TXT = "post_processing_platform.txt"; //$NON-NLS-1$
180+
public static final String DEFINE_IN_ECLIPSE = "__IN_ECLIPSE__"; //$NON-NLS-1$
180181

181182
}

it.baeyens.arduino.core/src/it/baeyens/arduino/toolchain/ArduinoLanguageProvider.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import it.baeyens.arduino.common.Common;
2323
import it.baeyens.arduino.common.Const;
2424

25-
public class ArduinoLanguageProvider extends ToolchainBuiltinSpecsDetector implements ILanguageSettingsEditableProvider {
25+
public class ArduinoLanguageProvider extends ToolchainBuiltinSpecsDetector
26+
implements ILanguageSettingsEditableProvider {
2627
// ID must match the tool-chain definition in
2728
// org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point
2829
private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$
@@ -34,12 +35,15 @@ private enum State {
3435
private State state = State.NONE;
3536

3637
private static final AbstractOptionParser[] optionParsers = {
37-
new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL), //$NON-NLS-1$ //$NON-NLS-2$
38+
new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", //$NON-NLS-1$ //$NON-NLS-2$
39+
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL),
3840
new IncludePathOptionParser("#include <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), //$NON-NLS-1$ //$NON-NLS-2$
3941
new IncludePathOptionParser("#framework <(\\S.*)>", "$1", //$NON-NLS-1$ //$NON-NLS-2$
4042
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.FRAMEWORKS_MAC),
41-
new MacroOptionParser("#define\\s+(\\S*\\(.*?\\))\\s*(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
42-
new MacroOptionParser("#define\\s+(\\S*)\\s*(\\S*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
43+
new MacroOptionParser("#define\\s+(\\S*\\(.*?\\))\\s*(.*)", "$1", "$2", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
44+
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
45+
new MacroOptionParser("#define\\s+(\\S*)\\s*(\\S*)", "$1", "$2", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
46+
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), };
4347

4448
@Override
4549
public String getToolchainId() {
@@ -105,7 +109,8 @@ protected List<String> parseOptions(String lineIn) {
105109
}
106110

107111
@Override
108-
public void startup(ICConfigurationDescription cfgDescription, IWorkingDirectoryTracker cwdTracker1) throws CoreException {
112+
public void startup(ICConfigurationDescription cfgDescription, IWorkingDirectoryTracker cwdTracker1)
113+
throws CoreException {
109114
super.startup(cfgDescription, cwdTracker1);
110115

111116
this.state = State.NONE;
@@ -148,45 +153,54 @@ protected String getCompilerCommand(String languageId) {
148153
try {
149154
buildFolder.create(true, true, null);
150155
} catch (CoreException e) {
151-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "failed to create folder " + confDesc.getName(), e)); //$NON-NLS-1$
156+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
157+
"failed to create folder " + confDesc.getName(), e)); //$NON-NLS-1$
152158
}
153159
}
154160
// End of Bug fix for CDT 8.1 fixed in 8.2
155161
if (languageId.equals("org.eclipse.cdt.core.gcc")) { //$NON-NLS-1$
156162
try {
157-
compilerCommand = envManager.getVariable(Const.ENV_KEY_recipe_c_o_pattern, confDesc, true).getValue().replace(" -o ", " "); //$NON-NLS-1$ //$NON-NLS-2$
163+
compilerCommand = envManager.getVariable(Const.ENV_KEY_recipe_c_o_pattern, confDesc, true).getValue()
164+
.replace(" -o ", " "); //$NON-NLS-1$ //$NON-NLS-2$
158165
} catch (Exception e) {
159166
compilerCommand = Const.EMPTY_STRING;
160167
}
161-
IEnvironmentVariable op1 = envManager.getVariable(Const.ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS, confDesc, true);
162-
IEnvironmentVariable op2 = envManager.getVariable(Const.ENV_KEY_JANTJE_ADDITIONAL_C_COMPILE_OPTIONS, confDesc, true);
168+
IEnvironmentVariable op1 = envManager.getVariable(Const.ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS, confDesc,
169+
true);
170+
IEnvironmentVariable op2 = envManager.getVariable(Const.ENV_KEY_JANTJE_ADDITIONAL_C_COMPILE_OPTIONS,
171+
confDesc, true);
163172
if (op1 != null) {
164173
compilerCommand = compilerCommand + ' ' + op1.getValue();
165174
}
166175
if (op2 != null) {
167176
compilerCommand = compilerCommand + ' ' + op2.getValue();
168177
}
169-
compilerCommand = compilerCommand + " -D__IN_ECLIPSE__=1"; //$NON-NLS-1$
178+
compilerCommand = compilerCommand + " -D" + Const.DEFINE_IN_ECLIPSE + "=1"; //$NON-NLS-1$
170179
} else if (languageId.equals("org.eclipse.cdt.core.g++")) { //$NON-NLS-1$
171180
try {
172-
compilerCommand = envManager.getVariable(Const.ENV_KEY_recipe_cpp_o_pattern, confDesc, true).getValue().replace(" -o ", " "); //$NON-NLS-1$//$NON-NLS-2$
181+
compilerCommand = envManager.getVariable(Const.ENV_KEY_recipe_cpp_o_pattern, confDesc, true).getValue()
182+
.replace(" -o ", " "); //$NON-NLS-1$//$NON-NLS-2$
173183
} catch (Exception e) {
174184
compilerCommand = Const.EMPTY_STRING;
175185
}
176-
IEnvironmentVariable op1 = envManager.getVariable(Const.ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS, confDesc, true);
177-
IEnvironmentVariable op2 = envManager.getVariable(Const.ENV_KEY_JANTJE_ADDITIONAL_CPP_COMPILE_OPTIONS, confDesc, true);
186+
IEnvironmentVariable op1 = envManager.getVariable(Const.ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS, confDesc,
187+
true);
188+
IEnvironmentVariable op2 = envManager.getVariable(Const.ENV_KEY_JANTJE_ADDITIONAL_CPP_COMPILE_OPTIONS,
189+
confDesc, true);
178190
if (op1 != null) {
179191
compilerCommand = compilerCommand + ' ' + op1.getValue();
180192
}
181193
if (op2 != null) {
182194
compilerCommand = compilerCommand + ' ' + op2.getValue();
183195
}
184-
compilerCommand = compilerCommand + " -D__IN_ECLIPSE__=1"; //$NON-NLS-1$
196+
compilerCommand = compilerCommand + " -D" + Const.DEFINE_IN_ECLIPSE + "=1"; //$NON-NLS-1$
185197
} else {
186-
ManagedBuilderCorePlugin.error("Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId()); //$NON-NLS-1$ //$NON-NLS-2$
198+
ManagedBuilderCorePlugin.error(
199+
"Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId()); //$NON-NLS-1$ //$NON-NLS-2$
187200
}
188201

189-
String ret = compilerCommand.replaceAll(" -MMD ", " ").replaceAll("[^\\\\]\"\"", Const.EMPTY_STRING).replaceAll(" ", " "); // remove //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
202+
String ret = compilerCommand.replaceAll(" -MMD ", " ").replaceAll("[^\\\\]\"\"", Const.EMPTY_STRING) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
203+
.replaceAll(" ", " "); // remove //$NON-NLS-1$ //$NON-NLS-2$
190204
// "" except \""
191205
// and
192206
// double

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/PdePreprocessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public static void processProject(IProject iProject) throws CoreException {
154154
} else {
155155
// concatenate the parts and make the .ino.cpp file
156156
String output = header + includeHeaderPart + body + includeCodePart;
157+
// Make sure the file is not procesed by Arduino IDE
158+
output = "#ifdef " + Const.DEFINE_IN_ECLIPSE + NEWLINE + output + NEWLINE + "#endif" + NEWLINE; //$NON-NLS-1$ //$NON-NLS-2$
157159
Helpers.addFileToProject(iProject, new Path(tempFile), new ByteArrayInputStream(output.getBytes()),
158160
null);
159161
}

0 commit comments

Comments
 (0)