Skip to content

Commit 1010f39

Browse files
author
jantje
committed
#1126 still redesigning checking in due to to much change
The makefile is starting to get populated
1 parent 24bea2b commit 1010f39

10 files changed

+881
-1862
lines changed

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ArduinoGnuMakefileGenerator.java

+324-406
Large diffs are not rendered by default.

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ArduinoManagedBuildGnuToolInfo.java

-1,052
This file was deleted.

io.sloeber.core/src/io/sloeber/managedBuild/Internal/MakeRule.java

+83-153
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package io.sloeber.managedBuild.Internal;
2+
3+
import java.util.HashMap;
4+
import java.util.HashSet;
5+
import java.util.LinkedHashSet;
6+
import java.util.Map;
7+
import java.util.Map.Entry;
8+
import java.util.Set;
9+
10+
import org.eclipse.cdt.managedbuilder.core.IInputType;
11+
import org.eclipse.cdt.managedbuilder.core.IOutputType;
12+
import org.eclipse.cdt.managedbuilder.core.ITool;
13+
import org.eclipse.core.resources.IFile;
14+
15+
public class MakeRules {
16+
private Set<MakeRule> myMakeRules = new LinkedHashSet<>();
17+
18+
public void addRule(MakeRule newMakeRule) {
19+
if (newMakeRule.isSimpleRule()) {
20+
Map<IOutputType, Set<IFile>> targets = newMakeRule.getTargets();
21+
22+
IOutputType outputType = null;
23+
IFile correctOutputPath = null;
24+
for (Entry<IOutputType, Set<IFile>> curTarget : targets.entrySet()) {
25+
outputType = curTarget.getKey();
26+
correctOutputPath = curTarget.getValue().toArray(new IFile[1])[0];
27+
}
28+
MakeRule makerule = findTarget(outputType, correctOutputPath);
29+
if (makerule != null) {
30+
Map<IInputType, Set<IFile>> prerequisites = newMakeRule.getPrerequisites();
31+
32+
IInputType inputType = null;
33+
Set<IFile> files = null;
34+
35+
for (Entry<IInputType, Set<IFile>> curTarget : prerequisites.entrySet()) {
36+
inputType = curTarget.getKey();
37+
files = curTarget.getValue();
38+
}
39+
newMakeRule.addPrerequisites(inputType, files);
40+
}
41+
}
42+
myMakeRules.add(newMakeRule);
43+
}
44+
45+
public MakeRule findTarget(IOutputType outputType, IFile correctOutputPath) {
46+
for (MakeRule makeRule : myMakeRules) {
47+
for (Entry<IOutputType, Set<IFile>> target : makeRule.getTargets().entrySet()) {
48+
if ((target.getKey() == outputType) && (target.getValue().contains(correctOutputPath))) {
49+
return makeRule;
50+
}
51+
}
52+
}
53+
return null;
54+
}
55+
56+
public void addRule(ITool tool, IInputType inputType, String macroName, Set<IFile> InputFiles,
57+
IOutputType outputType, IFile correctOutputFile) {
58+
MakeRule newMakeRule = findTarget(outputType, correctOutputFile);
59+
if (newMakeRule == null) {
60+
newMakeRule = new MakeRule(tool, inputType, InputFiles, outputType, correctOutputFile);
61+
}
62+
newMakeRule.addPrerequisites(inputType, InputFiles);
63+
addRule(newMakeRule);
64+
65+
}
66+
67+
public int size() {
68+
return myMakeRules.size();
69+
}
70+
71+
public void addRules(MakeRules makeRules) {
72+
for (MakeRule makeRule : makeRules.getMakeRules()) {
73+
addRule(makeRule);
74+
}
75+
}
76+
77+
public Map<IOutputType, Set<IFile>> getTargets() {
78+
Map<IOutputType, Set<IFile>> ret = new HashMap<>();
79+
for (MakeRule makeRule : myMakeRules) {
80+
ret.putAll(makeRule.getTargets());
81+
}
82+
return ret;
83+
}
84+
85+
public Set<String> getMacroNames() {
86+
Set<String> ret = new HashSet<>();
87+
for (MakeRule makeRule : myMakeRules) {
88+
ret.addAll(makeRule.getAllMacros());
89+
}
90+
return ret;
91+
}
92+
93+
public Set<IFile> getMacroElements(String macroName) {
94+
Set<IFile> ret = new HashSet<>();
95+
for (MakeRule makeRule : myMakeRules) {
96+
ret.addAll(makeRule.getMacroElements(macroName));
97+
}
98+
return ret;
99+
}
100+
101+
public Set<MakeRule> getMakeRules() {
102+
return myMakeRules;
103+
}
104+
105+
}

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ManagebBuildCommon.java

+25
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,31 @@ static public IManagedOutputNameProviderJaba getJABANameProvider(IOutputType iTy
605605
//ignore errors
606606
}
607607
}
608+
String[] outputNames = type.getOutputNames();
609+
if (outputNames != null && outputNames.length > 0) {
610+
String outputName = outputNames[0];
611+
return new IManagedOutputNameProviderJaba() {
612+
613+
@Override
614+
public IPath getOutputName(IProject project, IConfiguration cConf, ITool tool, IPath inputName) {
615+
return new Path(outputName);
616+
//return project.getFile(cConf.getName()).getFullPath().append(outputName);
617+
}
618+
};
619+
}
620+
621+
String[] outputExtensions = type.getOutputExtensionsAttribute();
622+
if (outputExtensions != null && outputExtensions.length > 0) {
623+
String outputExtension = outputExtensions[0];
624+
return new IManagedOutputNameProviderJaba() {
625+
626+
@Override
627+
public IPath getOutputName(IProject project, IConfiguration cConf, ITool tool, IPath inputName) {
628+
return inputName.addFileExtension(outputExtension);
629+
}
630+
};
631+
}
632+
608633
return null;
609634
}
610635

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ManagedBuildConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@ public class ManagedBuildConstants {
9494
public static final String INPUTS_PRM_NAME = "INPUTS";
9595
public static final String VARIABLE_PREFIX = "${";
9696
public static final String VARIABLE_SUFFIX = "}";
97+
public static final String DEPENDENCY_SUFFIX = "_DEPS";
9798

9899
}

io.sloeber.core/src/io/sloeber/managedBuild/Internal/SubDirMakeGenerator.java

+50-72
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
import java.util.HashSet;
88
import java.util.LinkedHashMap;
99
import java.util.LinkedHashSet;
10-
import java.util.List;
1110
import java.util.Map;
1211
import java.util.Set;
1312

1413
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
15-
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
1614
import org.eclipse.cdt.managedbuilder.core.IInputType;
1715
import org.eclipse.cdt.managedbuilder.core.IOutputType;
18-
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
1916
import org.eclipse.cdt.managedbuilder.core.ITool;
2017
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
2118
import org.eclipse.core.resources.IContainer;
@@ -31,12 +28,18 @@
3128
public class SubDirMakeGenerator {
3229
private ArduinoGnuMakefileGenerator caller;
3330
private Set<MakeRule> myMakeRules = new LinkedHashSet<>();
34-
private IContainer myModule;
31+
private IFile myMakefile;
3532

3633
SubDirMakeGenerator(ArduinoGnuMakefileGenerator theCaller, IContainer module) {
3734
caller = theCaller;
38-
myModule = module;
39-
getMakeRules();
35+
IProject project = getProject();
36+
IPath buildRoot = getBuildWorkingDir();
37+
if (buildRoot == null) {
38+
return;
39+
}
40+
IPath moduleOutputPath = buildRoot.append(module.getProjectRelativePath());
41+
myMakefile = project.getFile(moduleOutputPath.append(MODFILE_NAME));
42+
getMakeRulesFromSourceFiles(module);
4043
}
4144

4245
public Set<String> getDependecyMacros() {
@@ -63,6 +66,10 @@ public Set<String> getTargetMacros() {
6366
return ret;
6467
}
6568

69+
public Set<MakeRule> getMakeRules() {
70+
return myMakeRules;
71+
}
72+
6673
public Set<String> getPrerequisiteMacros() {
6774
HashSet<String> ret = new LinkedHashSet<>();
6875
for (MakeRule curMakeRule : myMakeRules) {
@@ -87,8 +94,8 @@ public Set<IFile> getDependencyFiles() {
8794
return ret;
8895
}
8996

90-
public Map<IOutputType, List<IFile>> getTargets() {
91-
Map<IOutputType, List<IFile>> ret = new LinkedHashMap<>();
97+
public Map<IOutputType, Set<IFile>> getTargets() {
98+
Map<IOutputType, Set<IFile>> ret = new LinkedHashMap<>();
9299
for (MakeRule curMakeRule : myMakeRules) {
93100
ret.putAll(curMakeRule.getTargets());
94101
}
@@ -119,22 +126,13 @@ private IProject getProject() {
119126
* generated for each project directory/subdirectory that contains source files.
120127
*/
121128
public void generateMakefile() throws CoreException {
122-
//create the parent folder on disk and file in eclispe
123-
IProject project = getProject();
124-
IPath buildRoot = getBuildWorkingDir();
125-
if (buildRoot == null) {
126-
return;
127-
}
128-
IPath moduleOutputPath = buildRoot.append(myModule.getProjectRelativePath());
129-
IFile modMakefile = project.getFile(moduleOutputPath.append(MODFILE_NAME));
130-
131129
//generate the file content
132130
StringBuffer makeBuf = addDefaultHeader();
133131
makeBuf.append(GenerateMacros());
134132
makeBuf.append(GenerateRules(getConfig()));
135133

136134
// Save the files
137-
save(makeBuf, modMakefile);
135+
save(makeBuf, myMakefile);
138136
}
139137

140138
private StringBuffer GenerateMacros() {
@@ -179,85 +177,65 @@ private StringBuffer GenerateRules(IConfiguration config) {
179177
}
180178

181179
//Get the rules for the source files
182-
private void getMakeRules() {
180+
private void getMakeRulesFromSourceFiles(IContainer module) {
183181
myMakeRules.clear();
184182
IConfiguration config = getConfig();
185183
IProject project = getProject();
186184

187185
// Visit the resources in this folder
188186
try {
189-
for (IResource resource : myModule.members()) {
187+
for (IResource resource : module.members()) {
190188
if (resource.getType() != IResource.FILE) {
191189
//only handle files
192190
continue;
193191
}
194192
IFile inputFile = (IFile) resource;
193+
String ext = inputFile.getFileExtension();
194+
if (ext == null || ext.isBlank()) {
195+
continue;
196+
}
195197
IPath rcProjRelPath = inputFile.getProjectRelativePath();
196198
if (!caller.isSource(rcProjRelPath)) {
197199
// this resource is excluded from build
198200
continue;
199201
}
200-
IResourceInfo rcInfo = config.getResourceInfo(rcProjRelPath, false);
201-
String ext = rcProjRelPath.getFileExtension();
202202

203-
ITool tool = null;
204-
//try to find tool
205-
if (rcInfo instanceof IFileInfo) {
206-
IFileInfo fi = (IFileInfo) rcInfo;
207-
ITool[] tools = fi.getToolsToInvoke();
208-
if (tools != null && tools.length > 0) {
209-
tool = tools[0];
210-
}
211-
}
212-
213-
//No tool found yet try other way
214-
if (tool == null) {
215-
ToolInfoHolder h = ToolInfoHolder.getToolInfo(caller, rcInfo.getPath());
216-
ITool buildTools[] = h.buildTools;
217-
h = ToolInfoHolder.getToolInfo(caller, Path.EMPTY);
218-
buildTools = h.buildTools;
219-
for (ITool buildTool : buildTools) {
220-
if (buildTool.buildsFileType(ext)) {
221-
tool = buildTool;
222-
break;
203+
for (ITool tool : config.getTools()) {
204+
for (IInputType inputType : tool.getInputTypes()) {
205+
if (!inputType.isSourceExtension(tool, ext)) {
206+
continue;
207+
}
208+
for (IOutputType outputType : tool.getOutputTypes()) {
209+
IManagedOutputNameProviderJaba nameProvider = getJABANameProvider(outputType);
210+
if (nameProvider == null) {
211+
continue;
212+
}
213+
IPath outputFile = nameProvider.getOutputName(getProject(), config, tool,
214+
resource.getProjectRelativePath());
215+
if (outputFile == null) {
216+
continue;
217+
}
218+
//We found a tool that provides a outputfile for our source file
219+
//TOFIX if this is a multiple to one we should only create one MakeRule
220+
IPath correctOutputPath = new Path(config.getName()).append(outputFile);
221+
MakeRule newMakeRule = new MakeRule(tool, inputType, inputFile, outputType,
222+
project.getFile(correctOutputPath));
223+
newMakeRule.addDependencies(caller);
224+
225+
myMakeRules.add(newMakeRule);
223226
}
224227
}
225228
}
226229

227-
//We found a tool get the other info
228-
//TOFIX we should simply loop over all available tools
229-
if (tool == null) {
230-
continue;
231-
}
232-
233-
// Generate the rule to build this source file
234-
//TOFIX check wether this tool can handle this file
235-
IInputType inputType = tool.getPrimaryInputType();
236-
if (inputType == null) {
237-
inputType = tool.getInputType(ext);
238-
}
239-
240-
for (IOutputType outputType : tool.getOutputTypes()) {
241-
IManagedOutputNameProviderJaba nameProvider = getJABANameProvider(outputType);
242-
if (nameProvider == null) {
243-
continue;
244-
}
245-
IPath outputFile = nameProvider.getOutputName(getProject(), config, tool,
246-
resource.getProjectRelativePath());
247-
if (outputFile != null) {
248-
//We found a tool that provides a outputfile for our source file
249-
//TOFIX if this is a multiple to one we should only create one MakeRule
250-
IPath correctOutputPath = new Path(config.getName()).append(outputFile);
251-
MakeRule newMakeRule = new MakeRule(caller, tool, inputType, inputFile, outputType,
252-
project.getFile(correctOutputPath));
253-
254-
myMakeRules.add(newMakeRule);
255-
}
256-
}
257230
}
258231
} catch (CoreException e) {
259232
// TODO Auto-generated catch block
260233
e.printStackTrace();
261234
}
262235
}
236+
237+
public boolean isEmpty() {
238+
return myMakeRules.size() == 0;
239+
}
240+
263241
}

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ToolInfoHolder.java

-44
This file was deleted.

0 commit comments

Comments
 (0)