Search in sources :

Example 1 with IResourceInfo

use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project arduino-eclipse-plugin by Sloeber.

the class ArduinoGnuMakefileGenerator method regenerateDependencies.

/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator#
	 * regenerateDependencies()
	 */
@Override
public void regenerateDependencies(boolean force) throws CoreException {
    // A hack for the pre-3.x GCC compilers is to put dummy targets for deps
    final IWorkspaceRoot root = CCorePlugin.getWorkspace().getRoot();
    final CoreException[] es = new CoreException[1];
    this.toolInfos.accept(new IPathSettingsContainerVisitor() {

        @SuppressWarnings("synthetic-access")
        @Override
        public boolean visit(PathSettingsContainer container) {
            ToolInfoHolder h = (ToolInfoHolder) container.getValue();
            // Collect the methods that will need to be called
            List<String> depExts = new ArrayList<>();
            IManagedDependencyGenerator2[] postProcessors = new IManagedDependencyGenerator2[h.buildTools.length];
            boolean callPopulateDummyTargets = collectDependencyGeneratorInformation(h, depExts, postProcessors);
            // Is there anyone to call if we do find dependency files?
            if (!callPopulateDummyTargets) {
                int i;
                for (i = 0; i < postProcessors.length; i++) {
                    if (postProcessors[i] != null)
                        break;
                }
                if (i == postProcessors.length)
                    return true;
            }
            IResourceInfo rcInfo = ArduinoGnuMakefileGenerator.this.config.getResourceInfo(container.getPath(), false);
            for (IPath path : getDependencyMakefiles(h)) {
                // The path to search for the dependency makefile
                IPath relDepFilePath = ArduinoGnuMakefileGenerator.this.topBuildDir.append(path);
                IFile depFile = root.getFile(relDepFilePath);
                if (depFile == null || !depFile.isAccessible())
                    continue;
                try {
                    callDependencyPostProcessors(rcInfo, h, depFile, postProcessors, callPopulateDummyTargets, true);
                } catch (CoreException e) {
                    es[0] = e;
                    return false;
                }
            }
            return true;
        }
    });
    if (es[0] != null)
        throw es[0];
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IPathSettingsContainerVisitor(org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor) PathSettingsContainer(org.eclipse.cdt.core.settings.model.util.PathSettingsContainer) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) List(java.util.List) ArrayList(java.util.ArrayList) IResourceInfo(org.eclipse.cdt.managedbuilder.core.IResourceInfo)

Example 2 with IResourceInfo

use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project arduino-eclipse-plugin by Sloeber.

the class ArduinoGnuMakefileGenerator method deleteBuildTarget.

private void deleteBuildTarget(IResource deletedFile) {
    // Get the project relative path of the file
    String fileName = getFileName(deletedFile);
    String srcExtension = deletedFile.getFileExtension();
    IPath folderPath = inFullPathFromOutFullPath(deletedFile.getFullPath().removeLastSegments(1));
    if (folderPath != null) {
        folderPath = folderPath.removeFirstSegments(1);
    } else {
        folderPath = new Path(new String());
    }
    IResourceInfo rcInfo = this.config.getResourceInfo(folderPath, false);
    if (rcInfo instanceof IFileInfo) {
        rcInfo = this.config.getResourceInfo(folderPath.removeLastSegments(1), false);
    }
    String targetExtension = ((IFolderInfo) rcInfo).getOutputExtension(srcExtension);
    if (!targetExtension.isEmpty())
        fileName += DOT + targetExtension;
    IPath projectRelativePath = deletedFile.getProjectRelativePath().removeLastSegments(1);
    IPath targetFilePath = getBuildWorkingDir().append(projectRelativePath).append(fileName);
    IResource depFile = this.project.findMember(targetFilePath);
    if (depFile != null && depFile.exists()) {
        try {
            depFile.delete(true, this.monitor);
        } catch (CoreException e) {
        // This had better be allowed during a build
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFileInfo(org.eclipse.cdt.managedbuilder.core.IFileInfo) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IFolderInfo(org.eclipse.cdt.managedbuilder.core.IFolderInfo) IResource(org.eclipse.core.resources.IResource) IResourceInfo(org.eclipse.cdt.managedbuilder.core.IResourceInfo)

Example 3 with IResourceInfo

use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project arduino-eclipse-plugin by Sloeber.

the class ArduinoGnuMakefileGenerator method getFolderToolInfo.

private ToolInfoHolder getFolderToolInfo(IPath _path) {
    IPath path = _path;
    IResourceInfo rcInfo = this.config.getResourceInfo(path, false);
    while (rcInfo instanceof IFileInfo) {
        path = path.removeLastSegments(1);
        rcInfo = this.config.getResourceInfo(path, false);
    }
    return getToolInfo(path, false);
}
Also used : IFileInfo(org.eclipse.cdt.managedbuilder.core.IFileInfo) IPath(org.eclipse.core.runtime.IPath) IResourceInfo(org.eclipse.cdt.managedbuilder.core.IResourceInfo)

Example 4 with IResourceInfo

use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project arduino-eclipse-plugin by Sloeber.

the class ArduinoGnuMakefileGenerator method initToolInfos.

private void initToolInfos() {
    this.toolInfos = PathSettingsContainer.createRootContainer();
    IResourceInfo[] rcInfos = this.config.getResourceInfos();
    for (IResourceInfo rcInfo : rcInfos) {
        if (rcInfo.isExcluded())
            /* && !((ResourceInfo)rcInfo).isRoot() */
            continue;
        ToolInfoHolder h = getToolInfo(rcInfo.getPath(), true);
        if (rcInfo instanceof IFolderInfo) {
            IFolderInfo fo = (IFolderInfo) rcInfo;
            h.buildTools = fo.getFilteredTools();
            h.buildToolsUsed = new boolean[h.buildTools.length];
            h.gnuToolInfos = new ArduinoManagedBuildGnuToolInfo[h.buildTools.length];
        } else {
            IFileInfo fi = (IFileInfo) rcInfo;
            h.buildTools = fi.getToolsToInvoke();
            h.buildToolsUsed = new boolean[h.buildTools.length];
            h.gnuToolInfos = new ArduinoManagedBuildGnuToolInfo[h.buildTools.length];
        }
    }
}
Also used : IFileInfo(org.eclipse.cdt.managedbuilder.core.IFileInfo) IFolderInfo(org.eclipse.cdt.managedbuilder.core.IFolderInfo) IResourceInfo(org.eclipse.cdt.managedbuilder.core.IResourceInfo)

Example 5 with IResourceInfo

use of org.eclipse.cdt.managedbuilder.core.IResourceInfo in project arduino-eclipse-plugin by Sloeber.

the class ArduinoGnuMakefileGenerator method generateDependencies.

/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator
	 * #generateDependencies()
	 */
@Override
public void generateDependencies() throws CoreException {
    final PathSettingsContainer postProcs = PathSettingsContainer.createRootContainer();
    // Note: PopulateDummyTargets is a hack for the pre-3.x GCC compilers
    // Collect the methods that will need to be called
    this.toolInfos.accept(new IPathSettingsContainerVisitor() {

        @SuppressWarnings("synthetic-access")
        @Override
        public boolean visit(PathSettingsContainer container) {
            ToolInfoHolder h = (ToolInfoHolder) container.getValue();
            List<String> depExts = new ArrayList<>();
            IManagedDependencyGenerator2[] postProcessors = new IManagedDependencyGenerator2[h.buildTools.length];
            boolean callPopulateDummyTargets = collectDependencyGeneratorInformation(h, depExts, postProcessors);
            // Is there anyone to call if we do find dependency files?
            if (!callPopulateDummyTargets) {
                int i;
                for (i = 0; i < postProcessors.length; i++) {
                    if (postProcessors[i] != null)
                        break;
                }
                if (i == postProcessors.length)
                    return true;
            }
            PathSettingsContainer child = postProcs.getChildContainer(container.getPath(), true, true);
            DepInfo di = new DepInfo();
            di.depExts = depExts;
            di.postProcessors = postProcessors;
            di.callPopulateDummyTargets = callPopulateDummyTargets;
            child.setValue(di);
            return true;
        }
    });
    IWorkspaceRoot root = CCorePlugin.getWorkspace().getRoot();
    for (IResource res : getSubdirList()) {
        // The builder creates a subdir with same name as source in the
        // build location
        IContainer subDir = (IContainer) res;
        IPath projectRelativePath = subDir.getProjectRelativePath();
        IResourceInfo rcInfo = this.config.getResourceInfo(projectRelativePath, false);
        PathSettingsContainer cr = postProcs.getChildContainer(rcInfo.getPath(), false, true);
        if (cr == null || cr.getValue() == null)
            continue;
        DepInfo di = (DepInfo) cr.getValue();
        ToolInfoHolder h = getToolInfo(projectRelativePath);
        IPath buildRelativePath = this.topBuildDir.append(projectRelativePath);
        IFolder buildFolder = root.getFolder(buildRelativePath);
        if (buildFolder == null)
            continue;
        if (!buildFolder.exists())
            continue;
        // Find all of the dep files in the generated subdirectories
        IResource[] files = buildFolder.members();
        for (IResource file : files) {
            String fileExt = file.getFileExtension();
            for (String ext : di.depExts) {
                if (ext.equals(fileExt)) {
                    IFile depFile = root.getFile(file.getFullPath());
                    if (depFile == null)
                        continue;
                    callDependencyPostProcessors(rcInfo, h, depFile, di.postProcessors, di.callPopulateDummyTargets, false);
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IPathSettingsContainerVisitor(org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor) PathSettingsContainer(org.eclipse.cdt.core.settings.model.util.PathSettingsContainer) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) List(java.util.List) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IResourceInfo(org.eclipse.cdt.managedbuilder.core.IResourceInfo) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IResourceInfo (org.eclipse.cdt.managedbuilder.core.IResourceInfo)9 IPath (org.eclipse.core.runtime.IPath)7 ArrayList (java.util.ArrayList)5 IResource (org.eclipse.core.resources.IResource)5 IFileInfo (org.eclipse.cdt.managedbuilder.core.IFileInfo)4 List (java.util.List)3 IPathSettingsContainerVisitor (org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor)2 PathSettingsContainer (org.eclipse.cdt.core.settings.model.util.PathSettingsContainer)2 BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)2 IFolderInfo (org.eclipse.cdt.managedbuilder.core.IFolderInfo)2 IInputType (org.eclipse.cdt.managedbuilder.core.IInputType)2 IOption (org.eclipse.cdt.managedbuilder.core.IOption)2 ITool (org.eclipse.cdt.managedbuilder.core.ITool)2 IFile (org.eclipse.core.resources.IFile)2 IFolder (org.eclipse.core.resources.IFolder)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 CoreException (org.eclipse.core.runtime.CoreException)2 LinkedHashMap (java.util.LinkedHashMap)1 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)1 IOutputType (org.eclipse.cdt.managedbuilder.core.IOutputType)1