Skip to content

Commit 9560dfd

Browse files
author
jantje
committed
Fix for #311
This is a huge step in my understanding of the build process. It creates a incremental builder that is added by the arduino nature that runs before the cdt builder and makes the .ino.cpp file. This setup has lots of benefits.
1 parent 6e24e3e commit 9560dfd

File tree

13 files changed

+288
-148
lines changed

13 files changed

+288
-148
lines changed

it.baeyens.arduino.core/plugin.xml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@
3737
-->
3838
<extension point="org.eclipse.core.resources.natures"
3939
id="it.baeyens.arduinonature"
40-
name="Arduino Nature" >
40+
name="arduinoNature" >
4141
<runtime>
4242
<run class="it.baeyens.arduino.natures.ArduinoNature" />
4343
</runtime>
4444
<requires-nature id="org.eclipse.cdt.core.cnature"/>
45+
<requires-nature
46+
id="org.eclipse.cdt.core.ccnature">
47+
</requires-nature>
4548
</extension>
4649
<!--
4750
#######################################################################################
@@ -445,10 +448,11 @@
445448
<!-- TODO: Consider renaming as base. -->
446449
<configuration
447450
artifactExtension="hex"
448-
cleanCommand="rm -rf"
451+
cleanCommand="rm -f"
449452
id="it.baeyens.arduino.core.configuration.release"
450453
languageSettingsProviders="it.baeyens.arduino.languageSettingsProvider"
451-
name="%configuration.name">
454+
name="%configuration.name"
455+
prebuildStep="it.baeyens.arduino.core.command.generate.cpp">
452456
<toolChain
453457
archList="all"
454458
id="it.baeyens.arduino.core.toolChain.release"
@@ -823,6 +827,20 @@ priority="high"/>
823827
</enablement>
824828
</decorator>
825829
</extension>
830+
<extension
831+
id="it.baeyens.arduino.core.inoToCpp"
832+
name="Convert Ino to CPP files"
833+
point="org.eclipse.core.resources.builders">
834+
<builder
835+
callOnEmptyDelta="true"
836+
hasNature="false"
837+
isConfigurable="false"
838+
supportsConfigurations="true">
839+
<run
840+
class="it.baeyens.arduino.core.builder.inoToCpp">
841+
</run>
842+
</builder>
843+
</extension>
826844

827845
</plugin>
828846

it.baeyens.arduino.core/src/it/baeyens/arduino/actions/BuildHandler.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
import org.eclipse.core.runtime.preferences.InstanceScope;
1717
import org.eclipse.ui.PlatformUI;
1818

19-
import it.baeyens.arduino.common.Const;
2019
import it.baeyens.arduino.common.Common;
20+
import it.baeyens.arduino.common.Const;
2121
import it.baeyens.arduino.listeners.ProjectExplorerListener;
22-
import it.baeyens.arduino.tools.PdePreprocessor;
2322

2423
/**
25-
* This id a handler to connect the plugin.xml to the code for building the code This method forces a save all before building
24+
* This id a handler to connect the plugin.xml to the code for building the code
25+
* This method forces a save all before building
2626
*
2727
* @author jan
2828
*
@@ -68,11 +68,6 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
6868
default:
6969
PlatformUI.getWorkbench().saveAllEditors(false);
7070
for (int curProject = 0; curProject < SelectedProjects.length; curProject++) {
71-
try {
72-
PdePreprocessor.processProject(SelectedProjects[curProject]);
73-
} catch (CoreException e) {
74-
e.printStackTrace();
75-
}
7671
this.mBuildJob = new BuildJobHandler(SelectedProjects[curProject]);
7772
this.mBuildJob.setPriority(Job.INTERACTIVE);
7873
this.mBuildJob.schedule();
@@ -82,9 +77,10 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
8277
protected IStatus run(IProgressMonitor monitor) {
8378
try {
8479
String buildflag = "FuStatub"; //$NON-NLS-1$
85-
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't', '/', 'e', 'c', 'l', 'i',
86-
'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a', 'd', '/', 'b', 'u', 'i', 'l', 'd', 'S', 't', 'a', 'r', 't',
87-
'.', 'h', 't', 'm', 'l', '?', 'b', '=' };
80+
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i',
81+
't', '/', 'e', 'c', 'l', 'i', 'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a',
82+
'd', '/', 'b', 'u', 'i', 'l', 'd', 'S', 't', 'a', 'r', 't', '.', 'h', 't', 'm', 'l',
83+
'?', 'b', '=' };
8884
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(Const.NODE_ARDUINO);
8985
int curFsiStatus = myScope.getInt(buildflag, 0) + 1;
9086
myScope.putInt(buildflag, curFsiStatus);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package it.baeyens.arduino.core.builder;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.core.resources.IProject;
6+
import org.eclipse.core.resources.IResource;
7+
import org.eclipse.core.resources.IResourceDelta;
8+
import org.eclipse.core.resources.IResourceDeltaVisitor;
9+
import org.eclipse.core.resources.IncrementalProjectBuilder;
10+
import org.eclipse.core.runtime.CoreException;
11+
import org.eclipse.core.runtime.IProgressMonitor;
12+
13+
import it.baeyens.arduino.tools.PdePreprocessor;
14+
15+
public class inoToCpp extends IncrementalProjectBuilder {
16+
17+
class SampleDeltaVisitor implements IResourceDeltaVisitor {
18+
/*
19+
* (non-Javadoc)
20+
*
21+
* @see
22+
* org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.
23+
* core.resources.IResourceDelta)
24+
*/
25+
public boolean visit(IResourceDelta delta) throws CoreException {
26+
IResource resource = delta.getResource();
27+
if (resource.getFileExtension() != null) {
28+
if (resource.getFileExtension().equalsIgnoreCase("ino")
29+
|| resource.getFileExtension().equalsIgnoreCase("pde")) {
30+
try {
31+
PdePreprocessor.processProject(getProject());
32+
} catch (CoreException e) {
33+
e.printStackTrace();
34+
}
35+
return false;
36+
}
37+
}
38+
return true;
39+
}
40+
}
41+
42+
public static final String BUILDER_ID = "it.baeyens.arduino.core.inoToCpp";
43+
44+
/*
45+
* (non-Javadoc)
46+
*
47+
* @see org.eclipse.core.internal.events.InternalBuilder#build(int,
48+
* java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
49+
*/
50+
protected IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
51+
throws CoreException {
52+
if (kind == FULL_BUILD) {
53+
fullBuild(monitor);
54+
} else {
55+
IResourceDelta delta = getDelta(getProject());
56+
if (delta == null) {
57+
fullBuild(monitor);
58+
} else {
59+
incrementalBuild(delta, monitor);
60+
}
61+
}
62+
return null;
63+
}
64+
65+
protected void clean(IProgressMonitor monitor) throws CoreException {
66+
// delete markers set and files created
67+
68+
}
69+
70+
protected void fullBuild(final IProgressMonitor monitor) throws CoreException {
71+
try {
72+
PdePreprocessor.processProject(getProject());
73+
} catch (CoreException e) {
74+
e.printStackTrace();
75+
}
76+
}
77+
78+
protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
79+
// the visitor does the work.
80+
delta.accept(new SampleDeltaVisitor());
81+
82+
}
83+
}

it.baeyens.arduino.core/src/it/baeyens/arduino/listeners/ConfigurationChangeListener.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package it.baeyens.arduino.listeners;
2+
/*** Message from jan baeyens
3+
* this listener makes sure that when you change from one configuration to another
4+
* the correct hardware libraries are attached to the project
5+
* for instance you can have a project with 2 configurations
6+
* one for teensy
7+
* one for arduino uno
8+
*
9+
*
10+
* when you use the spi library the library is a completely different library
11+
* this code takes care that you use the correct library when switching configuration
12+
*
13+
*/
214

315
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
416
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
517
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
618
import org.eclipse.core.runtime.IStatus;
719
import org.eclipse.core.runtime.Status;
820

9-
import it.baeyens.arduino.common.Const;
1021
import it.baeyens.arduino.common.Common;
22+
import it.baeyens.arduino.common.Const;
1123
import it.baeyens.arduino.tools.Helpers;
1224
import it.baeyens.arduino.tools.Libraries;
1325

it.baeyens.arduino.core/src/it/baeyens/arduino/listeners/IndexerListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package it.baeyens.arduino.listeners;
22

3+
/**
4+
* his index listener makes ity possible to detect missing libraries
5+
* if configured to do so libraries are added automatically to the project
6+
*/
37
import java.util.HashSet;
48
import java.util.Set;
59

it.baeyens.arduino.core/src/it/baeyens/arduino/listeners/ProjectExplorerListener.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package it.baeyens.arduino.listeners;
2+
/**
3+
* this listener listens for changes in the project explorer
4+
* This is so we can know which project(s) you are currently working
5+
* on
6+
*/
27

38
import java.util.ArrayList;
49
import java.util.List;
@@ -45,7 +50,8 @@ public void selectionChanged(IWorkbenchPart part, ISelection newSelection) {
4550
for (Object element : ((IStructuredSelection) newSelection).toList()) {
4651
if (element instanceof IAdaptable) {
4752
@SuppressWarnings("cast") // this is needed for the oracle
48-
// sdk
53+
// sdk as it needs the cast and
54+
// otherwise I have a warning
4955
IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
5056
if (resource != null) {
5157
allSelectedprojects.add(resource.getProject());

it.baeyens.arduino.core/src/it/baeyens/arduino/natures/ArduinoNature.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
package it.baeyens.arduino.natures;
22

3+
import org.eclipse.core.resources.ICommand;
34
import org.eclipse.core.resources.IProject;
5+
import org.eclipse.core.resources.IProjectDescription;
46
import org.eclipse.core.resources.IProjectNature;
57
import org.eclipse.core.runtime.CoreException;
8+
import org.eclipse.core.runtime.NullProgressMonitor;
9+
10+
import it.baeyens.arduino.common.Const;
11+
import it.baeyens.arduino.core.builder.inoToCpp;
612

713
public class ArduinoNature implements IProjectNature {
14+
public static final String NATURE_ID = Const.ArduinoNatureID;
815
private IProject myProject = null;
916

1017
@Override
1118
public void configure() throws CoreException {
12-
// Jaba is not going to write this code
19+
IProjectDescription description = myProject.getDescription();
20+
// add builder to project
21+
ICommand command = description.newCommand();
22+
ICommand[] commands = description.getBuildSpec();
23+
command.setBuilderName(inoToCpp.BUILDER_ID);
24+
ICommand[] newCommands = new ICommand[commands.length + 1];
25+
26+
// Add it before other builders.
27+
System.arraycopy(commands, 0, newCommands, 1, commands.length);
28+
newCommands[0] = command;
29+
description.setBuildSpec(newCommands);
30+
31+
myProject.setDescription(description, new NullProgressMonitor());
1332
}
1433

1534
@Override

0 commit comments

Comments
 (0)