3
3
import static io .sloeber .managedBuild .Internal .ManagebBuildCommon .*;
4
4
import static io .sloeber .managedBuild .Internal .ManagedBuildConstants .*;
5
5
6
- import java .util .ArrayList ;
7
6
import java .util .Collection ;
8
- import java .util .HashSet ;
9
- import java .util .List ;
10
- import java .util .Map .Entry ;
11
7
import java .util .Set ;
12
8
13
- import org .eclipse .cdt .core .settings .model .util .IPathSettingsContainerVisitor ;
14
- import org .eclipse .cdt .core .settings .model .util .PathSettingsContainer ;
15
- import org .eclipse .cdt .managedbuilder .core .IOutputType ;
16
- import org .eclipse .cdt .managedbuilder .core .ITool ;
17
- import org .eclipse .cdt .managedbuilder .internal .core .ManagedMakeMessages ;
18
- import org .eclipse .cdt .managedbuilder .makegen .IManagedDependencyGeneratorType ;
9
+ import org .eclipse .cdt .managedbuilder .core .IConfiguration ;
19
10
import org .eclipse .core .resources .IContainer ;
20
11
import org .eclipse .core .resources .IFile ;
21
12
import org .eclipse .core .resources .IProject ;
22
13
import org .eclipse .core .resources .IResource ;
23
14
import org .eclipse .core .runtime .CoreException ;
24
15
import org .eclipse .core .runtime .IPath ;
25
- import org .eclipse .core .runtime .Path ;
26
16
27
17
public class SrcMakeGenerator {
28
18
29
- private ArduinoGnuMakefileGenerator caller ;
30
-
31
- SrcMakeGenerator (ArduinoGnuMakefileGenerator theCaller ) {
32
- caller = theCaller ;
33
- }
34
-
35
- private IProject getProject () {
36
- return caller .getProject ();
37
- }
38
-
39
- public void populateSourcesMakefile (IFile fileHandle , PathSettingsContainer toolInfos ,
19
+ static public void generateSourceMakefile (IProject project , IConfiguration config , Set <String > macroNames ,
40
20
Collection <IContainer > subDirs ) throws CoreException {
41
21
// Add the comment
42
22
StringBuffer buffer = addDefaultHeader ();
43
- // Determine the set of macros
44
- toolInfos .accept (new IPathSettingsContainerVisitor () {
45
- @ Override
46
- public boolean visit (PathSettingsContainer container ) {
47
- ToolInfoHolder h = (ToolInfoHolder ) container .getValue ();
48
- ITool [] buildTools = h .buildTools ;
49
- HashSet <String > handledInputExtensions = new HashSet <>();
50
- String buildMacro ;
51
- for (ITool buildTool : buildTools ) {
52
- if (buildTool .getCustomBuildStep ())
53
- continue ;
54
- // Add the known sources macros
55
- String [] extensionsList = buildTool .getAllInputExtensions ();
56
- for (String ext : extensionsList ) {
57
- // create a macro of the form "EXTENSION_SRCS :="
58
- String extensionName = ext ;
59
- if (!handledInputExtensions .contains (extensionName )) {
60
- handledInputExtensions .add (extensionName );
61
- buildMacro = getSourceMacroName (extensionName ).toString ();
62
- if (!caller .buildSrcVars .containsKey (buildMacro )) {
63
- caller .buildSrcVars .put (buildMacro , new ArrayList <IPath >());
64
- }
65
- // Add any generated dependency file macros
66
- IManagedDependencyGeneratorType depType = buildTool
67
- .getDependencyGeneratorForExtension (extensionName );
68
- if (depType != null ) {
69
- int calcType = depType .getCalculatorType ();
70
- if (calcType == IManagedDependencyGeneratorType .TYPE_COMMAND
71
- || calcType == IManagedDependencyGeneratorType .TYPE_BUILD_COMMANDS
72
- || calcType == IManagedDependencyGeneratorType .TYPE_PREBUILD_COMMANDS ) {
73
- buildMacro = getDepMacroName (extensionName ).toString ();
74
- if (!caller .buildDepVars .containsKey (buildMacro )) {
75
- caller .buildDepVars .put (buildMacro , new ArduinoGnuDependencyGroupInfo (
76
- buildMacro ,
77
- (calcType != IManagedDependencyGeneratorType .TYPE_PREBUILD_COMMANDS )));
78
- }
79
- if (!caller .buildOutVars .containsKey (buildMacro )) {
80
- caller .buildOutVars .put (buildMacro , new ArrayList <IPath >());
81
- }
82
- }
83
- }
84
- }
85
- }
86
- // Add the specified output build variables
87
- IOutputType [] outTypes = buildTool .getOutputTypes ();
88
- if (outTypes != null && outTypes .length > 0 ) {
89
- for (IOutputType outputType : outTypes ) {
90
- buildMacro = outputType .getBuildVariable ();
91
- if (!caller .buildOutVars .containsKey (buildMacro )) {
92
- caller .buildOutVars .put (buildMacro , new ArrayList <IPath >());
93
- }
94
- }
95
- } else {
96
- // For support of pre-CDT 3.0 integrations.
97
- buildMacro = OBJS_MACRO ;
98
- if (!caller .buildOutVars .containsKey (buildMacro )) {
99
- caller .buildOutVars .put (buildMacro , new ArrayList <IPath >());
100
- }
101
- }
102
- }
103
- return true ;
104
- }
105
- });
106
23
// Add the macros to the makefile
107
- for (Entry <String , List <IPath >> entry : caller .buildSrcVars .entrySet ()) {
108
- String macroName = new Path (entry .getKey ()).toOSString ();
109
- buffer .append (macroName ).append (WHITESPACE ).append (":=" ).append (WHITESPACE ).append (NEWLINE ); //$NON-NLS-1$
110
- }
111
- Set <Entry <String , List <IPath >>> set = caller .buildOutVars .entrySet ();
112
- for (Entry <String , List <IPath >> entry : set ) {
113
- String macroName = new Path (entry .getKey ()).toOSString ();
24
+ for (String macroName : macroNames ) {
114
25
buffer .append (macroName ).append (WHITESPACE ).append (":=" ).append (WHITESPACE ).append (NEWLINE ); //$NON-NLS-1$
115
26
}
116
27
// Add a list of subdirectories to the makefile
117
- buffer .append (NEWLINE ).append (addSubdirectories (subDirs ));
118
- // Save the file
119
- save (buffer , fileHandle );
120
- }
121
-
122
- /*************************************************************************
123
- * S O U R C E S (sources.mk) M A K E F I L E M E T H O D S
124
- ************************************************************************/
125
- private StringBuffer addSubdirectories (Collection <IContainer > subDirs ) {
126
- IProject project = getProject ();
127
- StringBuffer buffer = new StringBuffer ();
28
+ buffer .append (NEWLINE );
128
29
// Add the comment
129
30
buffer .append (COMMENT_SYMBOL ).append (WHITESPACE ).append (MOD_LIST_MESSAGE ).append (NEWLINE );
130
31
buffer .append ("SUBDIRS := " ).append (LINEBREAK ); //$NON-NLS-1$
131
32
// Get all the module names
132
33
for (IResource container : subDirs ) {
133
- caller .updateMonitor (ManagedMakeMessages .getFormattedString (
134
- "MakefileGenerator.message.adding.source.folder" , container .getFullPath ().toOSString ())); //$NON-NLS-1$
135
- // Check the special case where the module is the project root
136
34
if (container .getFullPath () == project .getFullPath ()) {
137
35
buffer .append (DOT ).append (WHITESPACE ).append (LINEBREAK );
138
36
} else {
@@ -141,6 +39,30 @@ private StringBuffer addSubdirectories(Collection<IContainer> subDirs) {
141
39
}
142
40
}
143
41
buffer .append (NEWLINE );
144
- return buffer ;
42
+ // Save the file
43
+ IFile fileHandle = project .getFile (config .getName () + '/' + SRCSFILE_NAME );
44
+ save (buffer , fileHandle );
145
45
}
46
+
47
+ /**
48
+ * The makefile generator generates a Macro for each type of output, other than
49
+ * final artifact, created by the build.
50
+ *
51
+ * @param fileHandle
52
+ * The file that should be populated with the output
53
+ */
54
+ protected static void generateObjectsMakefile (IProject project , IConfiguration config , Set <String > outputMacros )
55
+ throws CoreException {
56
+ StringBuffer macroBuffer = new StringBuffer ();
57
+ macroBuffer .append (addDefaultHeader ());
58
+
59
+ for (String macroName : outputMacros ) {
60
+ macroBuffer .append (macroName ).append (MAKE_EQUAL );
61
+ macroBuffer .append (NEWLINE );
62
+ macroBuffer .append (NEWLINE );
63
+ }
64
+ IFile fileHandle = project .getFile (config .getName () + '/' + OBJECTS_MAKFILE );
65
+ save (macroBuffer , fileHandle );
66
+ }
67
+
146
68
}
0 commit comments