Search in sources :

Example 6 with IFolderInfo

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) InputStreamReader(java.io.InputStreamReader) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IFolderInfo(org.eclipse.cdt.managedbuilder.core.IFolderInfo) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) Vector(java.util.Vector)

Example 7 with IFolderInfo

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");
    }
}
Also used : IToolChain(org.eclipse.cdt.managedbuilder.core.IToolChain) IOption(org.eclipse.cdt.managedbuilder.core.IOption) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) IFolderInfo(org.eclipse.cdt.managedbuilder.core.IFolderInfo) ITool(org.eclipse.cdt.managedbuilder.core.ITool)

Aggregations

IFolderInfo (org.eclipse.cdt.managedbuilder.core.IFolderInfo)7 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)4 ITool (org.eclipse.cdt.managedbuilder.core.ITool)4 IFileInfo (org.eclipse.cdt.managedbuilder.core.IFileInfo)3 IOption (org.eclipse.cdt.managedbuilder.core.IOption)3 IToolChain (org.eclipse.cdt.managedbuilder.core.IToolChain)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 Vector (java.util.Vector)2 IResourceInfo (org.eclipse.cdt.managedbuilder.core.IResourceInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)1 IBuildObject (org.eclipse.cdt.managedbuilder.core.IBuildObject)1 IManagedCommandLineGenerator (org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator)1 IManagedCommandLineInfo (org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo)1 FileContextData (org.eclipse.cdt.managedbuilder.internal.macros.FileContextData)1