use of org.eclipse.cdt.managedbuilder.core.IFolderInfo in project arduino-eclipse-plugin by Sloeber.
the class ArduinoGnuMakefileGenerator method populateDummyTargets.
public static boolean populateDummyTargets(IResourceInfo rcInfo, IFile makefile, boolean force) throws CoreException, IOException {
if (makefile == null || !makefile.exists())
return false;
// Get the contents of the dependency file
InputStream contentStream = makefile.getContents(false);
StringBuilder inBuilder = null;
try (Reader in = new InputStreamReader(contentStream)) {
int chunkSize = contentStream.available();
inBuilder = new StringBuilder(chunkSize);
char[] readBuilder = new char[chunkSize];
int n = in.read(readBuilder);
while (n > 0) {
inBuilder.append(readBuilder);
n = in.read(readBuilder);
}
contentStream.close();
in.close();
}
// The rest of this operation is equally expensive, so
// if we are doing an incremental build, only update the
// files that do not have a comment
String inBuilderString = inBuilder.toString();
if (!force && inBuilderString.startsWith(COMMENT_SYMBOL)) {
return false;
}
// Try to determine if this file already has dummy targets defined.
// If so, we will only add the comment.
//
String[] builderLines = inBuilderString.split("[\\r\\n]");
for (String builderLine : builderLines) {
if (builderLine.endsWith(":")) {
//
StringBuilder outBuilder = addDefaultHeader();
outBuilder.append(inBuilder);
save(outBuilder, makefile);
return true;
}
}
// Reconstruct the buffer tokens into useful chunks of dependency
// information
Vector<String> bufferTokens = new Vector<>(Arrays.asList(inBuilderString.split("\\s")));
Vector<String> deps = new Vector<>(bufferTokens.size());
Iterator<String> tokenIter = bufferTokens.iterator();
while (tokenIter.hasNext()) {
String token = tokenIter.next();
if (token.lastIndexOf("\\") == token.length() - 1 && token.length() > 1) {
// end
while (tokenIter.hasNext()) {
String nextToken = tokenIter.next();
token += WHITESPACE + nextToken;
if (!nextToken.endsWith("\\")) {
break;
}
}
}
deps.add(token);
}
deps.trimToSize();
// Now find the header file dependencies and make dummy targets for them
boolean save = false;
StringBuilder outBuilder = null;
// If we are doing an incremental build, only update the files that do
// not have a comment
String firstToken;
try {
firstToken = deps.get(0);
} catch (ArrayIndexOutOfBoundsException e) {
// This makes no sense so bail
return false;
}
// Put the generated comments in the output buffer
if (!firstToken.startsWith(COMMENT_SYMBOL)) {
outBuilder = addDefaultHeader();
} else {
outBuilder = new StringBuilder();
}
// output
if (firstToken.startsWith("-n")) {
// Now let's parse:
// Win32 outputs -n '<path>/<file>.d <path>/'
// POSIX outputs -n <path>/<file>.d <path>/
// Get the dep file name
String secondToken;
try {
secondToken = deps.get(1);
} catch (ArrayIndexOutOfBoundsException e) {
secondToken = new String();
}
if (secondToken.startsWith("'")) {
// This is the Win32 implementation of echo (MinGW without MSYS)
outBuilder.append(secondToken.substring(1) + WHITESPACE);
} else {
outBuilder.append(secondToken + WHITESPACE);
}
// The relative path to the build goal comes next
String thirdToken;
try {
thirdToken = deps.get(2);
} catch (ArrayIndexOutOfBoundsException e) {
thirdToken = new String();
}
int lastIndex = thirdToken.lastIndexOf("'");
if (lastIndex != -1) {
if (lastIndex == 0) {
outBuilder.append(WHITESPACE);
} else {
outBuilder.append(thirdToken.substring(0, lastIndex - 1));
}
} else {
outBuilder.append(thirdToken);
}
// Followed by the target output by the compiler plus ':'
// If we see any empty tokens here, assume they are the result of
// a line feed output by "echo" and skip them
String fourthToken;
int nToken = 3;
try {
do {
fourthToken = deps.get(nToken++);
} while (fourthToken.length() == 0);
} catch (ArrayIndexOutOfBoundsException e) {
fourthToken = new String();
}
outBuilder.append(fourthToken + WHITESPACE);
// Followed by the actual dependencies
try {
for (String nextElement : deps) {
if (nextElement.endsWith("\\")) {
outBuilder.append(nextElement + NEWLINE + WHITESPACE);
} else {
outBuilder.append(nextElement + WHITESPACE);
}
}
} catch (IndexOutOfBoundsException e) {
/* JABA is not going to write this code */
}
} else {
outBuilder.append(inBuilder);
}
outBuilder.append(NEWLINE);
save = true;
IFolderInfo fo = null;
if (rcInfo instanceof IFolderInfo) {
fo = (IFolderInfo) rcInfo;
} else {
IConfiguration c = rcInfo.getParent();
fo = (IFolderInfo) c.getResourceInfo(rcInfo.getPath().removeLastSegments(1), false);
}
// Dummy targets to add to the makefile
for (String dummy : deps) {
IPath dep = new Path(dummy);
String extension = dep.getFileExtension();
if (fo.isHeaderFile(extension)) {
/*
* The formatting here is <dummy_target>:
*/
outBuilder.append(dummy + COLON + NEWLINE + NEWLINE);
}
}
// Write them out to the makefile
if (save) {
save(outBuilder, makefile);
return true;
}
return false;
}
use of org.eclipse.cdt.managedbuilder.core.IFolderInfo in project usbdm-eclipse-plugins by podonoghue.
the class ToolchainValueHandler method listConfigs.
void listConfigs(IBuildObject configuration) {
String configTypeID = "net.sourceforge.usbdm.cdt.toolchain.processor.mcpu";
System.err.println("ToolchainValueHandler.isEnumValueAppropriate()");
// first we check the preference for this project, if it exists
IConfiguration config = null;
if (configuration instanceof IConfiguration) {
config = (IConfiguration) configuration;
} else if (configuration instanceof IFolderInfo) {
IFolderInfo folderInfo = (IFolderInfo) configuration;
config = folderInfo.getParent();
}
if (config == null) {
System.err.println("ToolchainValueHandler.isEnumValueAppropriate() config not found");
}
IToolChain toolChain = config.getToolChain();
ITool[] tools = toolChain.getTools();
IOption CPUListOption = null;
for (int i = 0; i < tools.length; i++) {
System.err.println("ToolchainValueHandler.isEnumValueAppropriate() Checking tool: " + tools[i].getId());
if (tools[i].getOptionBySuperClassId(configTypeID) != null) {
CPUListOption = tools[i].getOptionBySuperClassId(configTypeID);
}
}
if (CPUListOption == null) {
System.err.println("ToolchainValueHandler.isEnumValueAppropriate() CPUListOption not found");
}
}
Aggregations