14
14
15
15
import org .eclipse .cdt .core .settings .model .ICConfigurationDescription ;
16
16
import org .eclipse .cdt .managedbuilder .core .BuildException ;
17
+ import org .eclipse .cdt .managedbuilder .core .IBuildObject ;
17
18
import org .eclipse .cdt .managedbuilder .core .IConfiguration ;
18
19
import org .eclipse .cdt .managedbuilder .core .IInputType ;
19
20
import org .eclipse .cdt .managedbuilder .core .IOutputType ;
24
25
import org .eclipse .cdt .managedbuilder .internal .macros .FileContextData ;
25
26
import org .eclipse .cdt .managedbuilder .macros .BuildMacroException ;
26
27
import org .eclipse .cdt .managedbuilder .macros .IBuildMacroProvider ;
28
+ import org .eclipse .cdt .managedbuilder .makegen .IManagedDependencyCalculator ;
27
29
import org .eclipse .cdt .managedbuilder .makegen .IManagedDependencyCommands ;
28
30
import org .eclipse .cdt .managedbuilder .makegen .IManagedDependencyGenerator2 ;
29
31
import org .eclipse .cdt .managedbuilder .makegen .IManagedDependencyGeneratorType ;
@@ -39,22 +41,81 @@ public class MakeRule {
39
41
private Map <String , List <IFile >> myDependencies = new HashMap <>(); //Macro file target map
40
42
private ITool myTool = null ;
41
43
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 ) {
43
47
addPrerequisite (inputType , inputFile );
44
48
addTarget (outputType , outFile );
45
49
myTool = tool ;
46
- calculateDependencies ();
50
+ calculateDependencies (caller );
47
51
}
48
52
49
- private void calculateDependencies () {
53
+ private void calculateDependencies (ArduinoGnuMakefileGenerator caller ) {
50
54
myDependencies .clear ();
51
55
//TOFIX the stuff below should be calculated
52
56
boolean toolGeneratesDependencyFiles = true ;
53
57
if (!toolGeneratesDependencyFiles ) {
54
58
return ;
55
59
}
56
- IPath [] deps = myTool .getAdditionalDependencies ();
57
60
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 ;
58
119
}
59
120
60
121
public HashSet <IFile > getPrerequisites () {
0 commit comments