Skip to content

Commit 09c6ce2

Browse files
author
jantje
committed
#1126 the subdir.mk now also contains the dependencies
I'm not yet happy with the use of caller
1 parent 7d81113 commit 09c6ce2

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

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

+65-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
1616
import org.eclipse.cdt.managedbuilder.core.BuildException;
17+
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
1718
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
1819
import org.eclipse.cdt.managedbuilder.core.IInputType;
1920
import org.eclipse.cdt.managedbuilder.core.IOutputType;
@@ -24,6 +25,7 @@
2425
import org.eclipse.cdt.managedbuilder.internal.macros.FileContextData;
2526
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
2627
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
28+
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCalculator;
2729
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCommands;
2830
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator2;
2931
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGeneratorType;
@@ -39,22 +41,81 @@ public class MakeRule {
3941
private Map<String, List<IFile>> myDependencies = new HashMap<>(); //Macro file target map
4042
private ITool myTool = null;
4143

42-
public MakeRule(ITool tool, IInputType inputType, IFile inputFile, IOutputType outputType, IFile outFile) {
44+
//TOFIX get rid of caller argument
45+
public MakeRule(ArduinoGnuMakefileGenerator caller, ITool tool, IInputType inputType, IFile inputFile,
46+
IOutputType outputType, IFile outFile) {
4347
addPrerequisite(inputType, inputFile);
4448
addTarget(outputType, outFile);
4549
myTool = tool;
46-
calculateDependencies();
50+
calculateDependencies(caller);
4751
}
4852

49-
private void calculateDependencies() {
53+
private void calculateDependencies(ArduinoGnuMakefileGenerator caller) {
5054
myDependencies.clear();
5155
//TOFIX the stuff below should be calculated
5256
boolean toolGeneratesDependencyFiles = true;
5357
if (!toolGeneratesDependencyFiles) {
5458
return;
5559
}
56-
IPath[] deps = myTool.getAdditionalDependencies();
5760

61+
for (Entry<IInputType, List<IFile>> curprerequisite : myPrerequisites.entrySet()) {
62+
IInputType curInputType = curprerequisite.getKey();
63+
IManagedDependencyGeneratorType t = curInputType.getDependencyGenerator();
64+
if (t == null) {
65+
continue;
66+
}
67+
List<IFile> files = curprerequisite.getValue();
68+
String depkey = curInputType.getBuildVariable() + "_DEPS";
69+
for (IFile file : files) {
70+
IResourceInfo rcInfo = caller.getConfig().getResourceInfo(file.getFullPath(), false);
71+
int calcType = t.getCalculatorType();
72+
73+
IManagedDependencyGenerator2 depGen = (IManagedDependencyGenerator2) t;
74+
IBuildObject buildContext = rcInfo;
75+
IManagedDependencyInfo depInfo = depGen.getDependencySourceInfo(file.getProjectRelativePath(), file,
76+
buildContext, myTool, caller.getBuildWorkingDir());
77+
78+
// if (calcType== IManagedDependencyGeneratorType.TYPE_CUSTOM) {
79+
if (depInfo instanceof IManagedDependencyCalculator) {
80+
IManagedDependencyCalculator depCalculator = (IManagedDependencyCalculator) depInfo;
81+
IPath[] addlDeps = calculateDependenciesForSource(caller, depCalculator);
82+
IPath[] addlTargets = depCalculator.getAdditionalTargets();
83+
// }
84+
}
85+
if (depInfo instanceof IManagedDependencyCommands) {
86+
IManagedDependencyCommands tmp = (IManagedDependencyCommands) depInfo;
87+
IPath[] addlTargets = tmp.getDependencyFiles();
88+
List<IFile> depFiles = new LinkedList<>();
89+
for (IPath curPath : addlTargets) {
90+
depFiles.add(caller.getProject().getFile(caller.getBuildWorkingDir().append(curPath)));
91+
}
92+
myDependencies.put(depkey, depFiles);
93+
}
94+
}
95+
}
96+
}
97+
98+
/**
99+
* Returns the dependency <code>IPath</code>s relative to the build directory
100+
*
101+
* @param depCalculator
102+
* the dependency calculator
103+
* @return IPath[] that are relative to the build directory
104+
*/
105+
private IPath[] calculateDependenciesForSource(ArduinoGnuMakefileGenerator caller,
106+
IManagedDependencyCalculator depCalculator) {
107+
IPath[] addlDeps = depCalculator.getDependencies();
108+
if (addlDeps != null) {
109+
for (int i = 0; i < addlDeps.length; i++) {
110+
if (!addlDeps[i].isAbsolute()) {
111+
// Convert from project relative to build directory relative
112+
IPath absolutePath = caller.getProject().getLocation().append(addlDeps[i]);
113+
addlDeps[i] = ManagedBuildManager.calculateRelativePath(caller.getTopBuildDir().getLocation(),
114+
absolutePath);
115+
}
116+
}
117+
}
118+
return addlDeps;
58119
}
59120

60121
public HashSet<IFile> getPrerequisites() {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private List<MakeRule> getMakeRules(IContainer module) {
191191
//We found a tool that provides a outputfile for our source file
192192
//TOFIX if this is a multiple to one we should only create one MakeRule
193193
IPath correctOutputPath = new Path(config.getName()).append(outputFile);
194-
MakeRule newMakeRule = new MakeRule(tool, inputType, inputFile, outputType,
194+
MakeRule newMakeRule = new MakeRule(caller, tool, inputType, inputFile, outputType,
195195
project.getFile(correctOutputPath));
196196

197197
makeRules.add(newMakeRule);

0 commit comments

Comments
 (0)