Search in sources :

Example 1 with PathSettingsContainer

use of org.eclipse.cdt.core.settings.model.util.PathSettingsContainer 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 PathSettingsContainer

use of org.eclipse.cdt.core.settings.model.util.PathSettingsContainer in project arduino-eclipse-plugin by Sloeber.

the class ArduinoGnuMakefileGenerator method populateSourcesMakefile.

protected void populateSourcesMakefile(IFile fileHandle) throws CoreException {
    // Add the comment
    StringBuilder builder1 = addDefaultHeader();
    // Determine the set of macros
    this.toolInfos.accept(new IPathSettingsContainerVisitor() {

        @Override
        public boolean visit(PathSettingsContainer container) {
            ToolInfoHolder h = (ToolInfoHolder) container.getValue();
            ITool[] buildTools = h.buildTools;
            HashSet<String> handledInputExtensions = new HashSet<>();
            String buildMacro;
            for (ITool buildTool : buildTools) {
                if (buildTool.getCustomBuildStep())
                    continue;
                // Add the known sources macros
                String[] extensionsList = buildTool.getAllInputExtensions();
                for (String ext : extensionsList) {
                    // create a macro of the form "EXTENSION_SRCS :="
                    String extensionName = ext;
                    if (// !getOutputExtensions().contains(extensionName) &&
                    !handledInputExtensions.contains(extensionName)) {
                        handledInputExtensions.add(extensionName);
                        buildMacro = getSourceMacroName(extensionName).toString();
                        if (!ArduinoGnuMakefileGenerator.this.buildSrcVars.containsKey(buildMacro)) {
                            ArduinoGnuMakefileGenerator.this.buildSrcVars.put(buildMacro, new ArrayList<IPath>());
                        }
                        // Add any generated dependency file macros
                        IManagedDependencyGeneratorType depType = buildTool.getDependencyGeneratorForExtension(extensionName);
                        if (depType != null) {
                            int calcType = depType.getCalculatorType();
                            if (calcType == IManagedDependencyGeneratorType.TYPE_COMMAND || calcType == IManagedDependencyGeneratorType.TYPE_BUILD_COMMANDS || calcType == IManagedDependencyGeneratorType.TYPE_PREBUILD_COMMANDS) {
                                buildMacro = getDepMacroName(extensionName).toString();
                                if (!ArduinoGnuMakefileGenerator.this.buildDepVars.containsKey(buildMacro)) {
                                    ArduinoGnuMakefileGenerator.this.buildDepVars.put(buildMacro, new ArduinoGnuDependencyGroupInfo(buildMacro, (calcType != IManagedDependencyGeneratorType.TYPE_PREBUILD_COMMANDS)));
                                }
                                if (!ArduinoGnuMakefileGenerator.this.buildOutVars.containsKey(buildMacro)) {
                                    ArduinoGnuMakefileGenerator.this.buildOutVars.put(buildMacro, new ArrayList<IPath>());
                                }
                            }
                        }
                    }
                }
                // Add the specified output build variables
                IOutputType[] outTypes = buildTool.getOutputTypes();
                if (outTypes != null && outTypes.length > 0) {
                    for (IOutputType outputType : outTypes) {
                        buildMacro = outputType.getBuildVariable();
                        if (!ArduinoGnuMakefileGenerator.this.buildOutVars.containsKey(buildMacro)) {
                            ArduinoGnuMakefileGenerator.this.buildOutVars.put(buildMacro, new ArrayList<IPath>());
                        }
                    }
                } else {
                    // For support of pre-CDT 3.0 integrations.
                    buildMacro = OBJS_MACRO;
                    if (!ArduinoGnuMakefileGenerator.this.buildOutVars.containsKey(buildMacro)) {
                        ArduinoGnuMakefileGenerator.this.buildOutVars.put(buildMacro, new ArrayList<IPath>());
                    }
                }
            }
            return true;
        }
    });
    // Add the macros to the makefile
    for (Entry<String, List<IPath>> entry : this.buildSrcVars.entrySet()) {
        String macroName = new Path(entry.getKey()).toOSString();
        builder1.append(macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE);
    }
    Set<Entry<String, List<IPath>>> set = this.buildOutVars.entrySet();
    for (Entry<String, List<IPath>> entry : set) {
        String macroName = new Path(entry.getKey()).toOSString();
        builder1.append(macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE);
    }
    // Add a list of subdirectories to the makefile
    builder1.append(NEWLINE + addSubdirectories());
    // Save the file
    save(builder1, fileHandle);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IPathSettingsContainerVisitor(org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor) ITool(org.eclipse.cdt.managedbuilder.core.ITool) IManagedDependencyGeneratorType(org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGeneratorType) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) Entry(java.util.Map.Entry) ICSettingEntry(org.eclipse.cdt.core.settings.model.ICSettingEntry) CSourceEntry(org.eclipse.cdt.core.settings.model.CSourceEntry) PathSettingsContainer(org.eclipse.cdt.core.settings.model.util.PathSettingsContainer) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) IOutputType(org.eclipse.cdt.managedbuilder.core.IOutputType)

Example 3 with PathSettingsContainer

use of org.eclipse.cdt.core.settings.model.util.PathSettingsContainer 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)

Example 4 with PathSettingsContainer

use of org.eclipse.cdt.core.settings.model.util.PathSettingsContainer in project arduino-eclipse-plugin by Sloeber.

the class ArduinoGnuMakefileGenerator method getToolInfo.

private ToolInfoHolder getToolInfo(IPath path, boolean create) {
    PathSettingsContainer child = this.toolInfos.getChildContainer(path, create, create);
    ToolInfoHolder h = null;
    if (child != null) {
        h = (ToolInfoHolder) child.getValue();
        if (h == null && create) {
            h = new ToolInfoHolder();
            child.setValue(h);
        }
    }
    return h;
}
Also used : PathSettingsContainer(org.eclipse.cdt.core.settings.model.util.PathSettingsContainer)

Aggregations

PathSettingsContainer (org.eclipse.cdt.core.settings.model.util.PathSettingsContainer)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IPathSettingsContainerVisitor (org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor)3 IPath (org.eclipse.core.runtime.IPath)3 IResourceInfo (org.eclipse.cdt.managedbuilder.core.IResourceInfo)2 IFile (org.eclipse.core.resources.IFile)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Entry (java.util.Map.Entry)1 CSourceEntry (org.eclipse.cdt.core.settings.model.CSourceEntry)1 ICSettingEntry (org.eclipse.cdt.core.settings.model.ICSettingEntry)1 ICSourceEntry (org.eclipse.cdt.core.settings.model.ICSourceEntry)1 IOutputType (org.eclipse.cdt.managedbuilder.core.IOutputType)1 ITool (org.eclipse.cdt.managedbuilder.core.ITool)1 IManagedDependencyGeneratorType (org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGeneratorType)1 IContainer (org.eclipse.core.resources.IContainer)1 IFolder (org.eclipse.core.resources.IFolder)1 IResource (org.eclipse.core.resources.IResource)1