Skip to content

Commit 24bea2b

Browse files
author
jantje
committed
#1126 All seems fine except for the makefile rules
I want to check in as I did lots of changes Building doesn't work anymore as the top level rules are missing
1 parent 09c6ce2 commit 24bea2b

8 files changed

+918
-1128
lines changed

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

+277-448
Large diffs are not rendered by default.

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

+419-429
Large diffs are not rendered by default.

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

+42-12
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import static io.sloeber.managedBuild.Internal.ManagedBuildConstants.*;
55

66
import java.util.Arrays;
7-
import java.util.HashMap;
87
import java.util.HashSet;
8+
import java.util.LinkedHashMap;
9+
import java.util.LinkedHashSet;
910
import java.util.LinkedList;
1011
import java.util.List;
1112
import java.util.Map;
@@ -36,9 +37,9 @@
3637

3738
public class MakeRule {
3839

39-
private Map<IOutputType, List<IFile>> myTargets = new HashMap<>(); //Macro file target map
40-
private Map<IInputType, List<IFile>> myPrerequisites = new HashMap<>();//Macro file prerequisites map
41-
private Map<String, List<IFile>> myDependencies = new HashMap<>(); //Macro file target map
40+
private Map<IOutputType, List<IFile>> myTargets = new LinkedHashMap<>(); //Macro file target map
41+
private Map<IInputType, List<IFile>> myPrerequisites = new LinkedHashMap<>();//Macro file prerequisites map
42+
private Map<String, List<IFile>> myDependencies = new LinkedHashMap<>(); //Macro file target map
4243
private ITool myTool = null;
4344

4445
//TOFIX get rid of caller argument
@@ -80,7 +81,7 @@ private void calculateDependencies(ArduinoGnuMakefileGenerator caller) {
8081
IManagedDependencyCalculator depCalculator = (IManagedDependencyCalculator) depInfo;
8182
IPath[] addlDeps = calculateDependenciesForSource(caller, depCalculator);
8283
IPath[] addlTargets = depCalculator.getAdditionalTargets();
83-
// }
84+
//TOFIX when is this call path used?
8485
}
8586
if (depInfo instanceof IManagedDependencyCommands) {
8687
IManagedDependencyCommands tmp = (IManagedDependencyCommands) depInfo;
@@ -126,22 +127,51 @@ public HashSet<IFile> getPrerequisites() {
126127
return ret;
127128
}
128129

129-
public HashSet<IFile> getTargets() {
130-
HashSet<IFile> ret = new HashSet<>();
130+
public Set<IFile> getTargetFiles() {
131+
Set<IFile> ret = new HashSet<>();
131132
for (List<IFile> cur : myTargets.values()) {
132133
ret.addAll(cur);
133134
}
134135
return ret;
135136
}
136137

137-
public HashSet<String> getMacros() {
138-
HashSet<String> ret = new HashSet<>();
138+
public Set<IFile> getDependencyFiles() {
139+
Set<IFile> ret = new HashSet<>();
140+
for (List<IFile> cur : myDependencies.values()) {
141+
ret.addAll(cur);
142+
}
143+
return ret;
144+
}
145+
146+
public Map<IOutputType, List<IFile>> getTargets() {
147+
return myTargets;
148+
}
149+
150+
public Set<String> getAllMacros() {
151+
Set<String> ret = getTargetMacros();
152+
ret.addAll(getPrerequisiteMacros());
153+
ret.addAll(getDependecyMacros());
154+
return ret;
155+
}
156+
157+
public Set<String> getTargetMacros() {
158+
HashSet<String> ret = new LinkedHashSet<>();
139159
for (IOutputType cur : myTargets.keySet()) {
140160
ret.add(cur.getBuildVariable());
141161
}
162+
return ret;
163+
}
164+
165+
public Set<String> getPrerequisiteMacros() {
166+
HashSet<String> ret = new LinkedHashSet<>();
142167
for (IInputType cur : myPrerequisites.keySet()) {
143168
ret.add(cur.getBuildVariable());
144169
}
170+
return ret;
171+
}
172+
173+
public Set<String> getDependecyMacros() {
174+
HashSet<String> ret = new LinkedHashSet<>();
145175
for (String cur : myDependencies.keySet()) {
146176
ret.add(cur);
147177
}
@@ -215,8 +245,8 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
215245
String cmd = myTool.getToolCommand();
216246
//For now assume 1 target with 1 or more prerequisites
217247
// if there is more than 1 prerequisite we take the flags of the first prerequisite only
218-
HashSet<IFile> local_targets = getTargets();
219-
HashSet<IFile> local_prerequisites = getPrerequisites();
248+
Set<IFile> local_targets = getTargetFiles();
249+
Set<IFile> local_prerequisites = getPrerequisites();
220250
if (local_targets.size() != 1) {
221251
System.err.println("Only 1 target per build rule is supported in this managed build"); //$NON-NLS-1$
222252
return new StringBuffer();
@@ -314,7 +344,7 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
314344
}
315345

316346
private Set<String> getBuildFlags(IFile buildFolder, IConfiguration config, IFile sourceFile, IFile outputFile) {
317-
Set<String> flags = new HashSet<>();
347+
Set<String> flags = new LinkedHashSet<>();
318348
// Get the tool command line options
319349
try {
320350

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

+22-19
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,29 @@ static public StringBuffer getSourceMacroName(String extensionName) {
109109
}
110110

111111
public static void save(StringBuffer buffer, IFile file) throws CoreException {
112-
String encoding = null;
113-
try {
114-
encoding = file.getCharset();
115-
} catch (CoreException ce) {
116-
// use no encoding
117-
}
118-
byte[] bytes = null;
119-
if (encoding != null) {
120-
try {
121-
bytes = buffer.toString().getBytes(encoding);
122-
} catch (Exception e) {
123-
/* JABA is not going to write this code */
124-
}
112+
113+
byte[] bytes = buffer.toString().getBytes();
114+
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
115+
if (file.exists()) {
116+
file.setContents(stream, true, false, null);
125117
} else {
126-
bytes = buffer.toString().getBytes();
118+
IFolder fileFolder = file.getProject().getFolder(file.getParent().getProjectRelativePath());
119+
createFolder(fileFolder);
120+
file.create(stream, false, null);
127121
}
128-
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
129-
// use a platform operation to update the resource contents
130-
boolean force = true;
131-
file.setContents(stream, force, false, null);
122+
file.setDerived(true, null);
123+
}
124+
125+
public static void createFolder(IFolder folder) throws CoreException {
126+
// Create or get the handle for the build directory
127+
if (folder.exists()) {
128+
return;
129+
}
130+
if (!folder.getParent().exists()) {
131+
createFolder(folder.getFolder(".."));
132+
}
133+
folder.create(true, true, null);
134+
folder.setDerived(true, null);
132135
}
133136

134137
/**
@@ -484,7 +487,7 @@ public static void addMacroAdditionPrefix(LinkedHashMap<String, String> map, Str
484487
boolean addPrefix) {
485488
// there is no entry in the map, so create a buffer for this macro
486489
StringBuffer tempBuffer = new StringBuffer();
487-
tempBuffer.append(macroName).append(WHITESPACE).append(MACRO_ADDITION_PREFIX_SUFFIX);
490+
tempBuffer.append(macroName).append(MACRO_ADDITION_PREFIX_SUFFIX);
488491
if (addPrefix) {
489492
tempBuffer.append(new Path(MACRO_ADDITION_ADDPREFIX_HEADER).append(relativePath)
490493
.append(MACRO_ADDITION_ADDPREFIX_SUFFIX).toOSString());

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public class ManagedBuildConstants {
7070
public static final String OBJS_MACRO = "OBJS";
7171
public static final String MACRO_ADDITION_ADDPREFIX_HEADER = "${addprefix ";
7272
public static final String MACRO_ADDITION_ADDPREFIX_SUFFIX = "," + WHITESPACE + LINEBREAK;
73-
public static final String JAVA_ADDITION = "+=";
74-
public static final String MACRO_ADDITION_PREFIX_SUFFIX = JAVA_ADDITION + WHITESPACE + LINEBREAK;
73+
public static final String MAKE_ADDITION = " +=";
74+
public static final String MAKE_EQUAL = " :=";
75+
public static final String MACRO_ADDITION_PREFIX_SUFFIX = MAKE_ADDITION + LINEBREAK;
7576
public static final String PREBUILD = "pre-build";
7677
public static final String MAINBUILD = "main-build";
7778
public static final String POSTBUILD = "post-build";

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

+29-107
Original file line numberDiff line numberDiff line change
@@ -3,136 +3,34 @@
33
import static io.sloeber.managedBuild.Internal.ManagebBuildCommon.*;
44
import static io.sloeber.managedBuild.Internal.ManagedBuildConstants.*;
55

6-
import java.util.ArrayList;
76
import java.util.Collection;
8-
import java.util.HashSet;
9-
import java.util.List;
10-
import java.util.Map.Entry;
117
import java.util.Set;
128

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;
1910
import org.eclipse.core.resources.IContainer;
2011
import org.eclipse.core.resources.IFile;
2112
import org.eclipse.core.resources.IProject;
2213
import org.eclipse.core.resources.IResource;
2314
import org.eclipse.core.runtime.CoreException;
2415
import org.eclipse.core.runtime.IPath;
25-
import org.eclipse.core.runtime.Path;
2616

2717
public class SrcMakeGenerator {
2818

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,
4020
Collection<IContainer> subDirs) throws CoreException {
4121
// Add the comment
4222
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-
});
10623
// 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) {
11425
buffer.append(macroName).append(WHITESPACE).append(":=").append(WHITESPACE).append(NEWLINE); //$NON-NLS-1$
11526
}
11627
// 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);
12829
// Add the comment
12930
buffer.append(COMMENT_SYMBOL).append(WHITESPACE).append(MOD_LIST_MESSAGE).append(NEWLINE);
13031
buffer.append("SUBDIRS := ").append(LINEBREAK); //$NON-NLS-1$
13132
// Get all the module names
13233
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
13634
if (container.getFullPath() == project.getFullPath()) {
13735
buffer.append(DOT).append(WHITESPACE).append(LINEBREAK);
13836
} else {
@@ -141,6 +39,30 @@ private StringBuffer addSubdirectories(Collection<IContainer> subDirs) {
14139
}
14240
}
14341
buffer.append(NEWLINE);
144-
return buffer;
42+
// Save the file
43+
IFile fileHandle = project.getFile(config.getName() + '/' + SRCSFILE_NAME);
44+
save(buffer, fileHandle);
14545
}
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+
14668
}

0 commit comments

Comments
 (0)