Search in sources :

Example 1 with IFileInfo

use of org.eclipse.cdt.managedbuilder.core.IFileInfo 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 2 with IFileInfo

use of org.eclipse.cdt.managedbuilder.core.IFileInfo 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 3 with IFileInfo

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

the class ArduinoGnuMakefileGenerator method addRuleForSource.

/**
 * Create a rule for this source file. We create a pattern rule if possible.
 * This is an example of a pattern rule:
 * <relative_path>/%.<outputExtension>: ../<relative_path>/%.
 * <inputExtension>
 *
 * @echo Building file: $<
 * @echo Invoking tool xxx
 * @echo <tool> <flags> <output_flag><output_prefix>$@ $<
 * @<tool> <flags> <output_flag><output_prefix>$@ $< && \ echo -n
 *         $(@:%.o=%.d) ' <relative_path>/' >> $(@:%.o=%.d) && \ <tool> -P
 *         -MM -MG <flags> $< >> $(@:%.o=%.d)
 * @echo Finished building: $<
 * @echo ' ' Note that the macros all come from the build model and are
 *       resolved to a real command before writing to the module makefile,
 *       so a real command might look something like: source1/%.o:
 *       ../source1/%.cpp
 * @echo Building file: $<
 * @echo Invoking tool xxx
 * @echo g++ -g -O2 -c -I/cygdrive/c/eclipse/workspace/Project/headers -o$@
 *       $< @g++ -g -O2 -c -I/cygdrive/c/eclipse/workspace/Project/headers
 *       -o$@ $< && \ echo -n $(@:%.o=%.d) ' source1/' >> $(@:%.o=%.d) && \
 *       g++ -P -MM -MG -g -O2 -c
 *       -I/cygdrive/c/eclipse/workspace/Project/headers $< >> $(@:%.o=%.d)
 * @echo Finished building: $<
 * @echo ' '
 * @param relativePath
 *            top build output directory relative path of the current output
 *            directory
 * @param buffer
 *            buffer to populate with the build rule
 * @param resource
 *            the source file for this invocation of the tool
 * @param sourceLocation
 *            the full path of the source
 * @param rcInfo
 *            the IResourceInfo associated with this file or null
 * @param generatedSource
 *            <code>true</code> if the resource is a generated output
 * @param enumeratedOutputs
 *            vector of the filenames that are the output of this rule
 */
@SuppressWarnings("null")
protected void addRuleForSource(String relativePath, StringBuffer buffer, IResource resource, IPath sourceLocation, IResourceInfo rcInfo, boolean generatedSource, List<IPath> generatedDepFiles, List<IPath> enumeratedOutputs) {
    String fileName = sourceLocation.removeFileExtension().lastSegment();
    String inputExtension = sourceLocation.getFileExtension();
    String outputExtension = null;
    ITool tool = null;
    if (rcInfo instanceof IFileInfo) {
        IFileInfo fi = (IFileInfo) rcInfo;
        ITool[] tools = fi.getToolsToInvoke();
        if (tools != null && tools.length > 0) {
            tool = tools[0];
        }
    } else {
        IFolderInfo foInfo = (IFolderInfo) rcInfo;
        tool = foInfo.getToolFromInputExtension(inputExtension);
    }
    ToolInfoHolder h = getToolInfo(rcInfo.getPath());
    if (tool != null)
        outputExtension = tool.getOutputExtension(inputExtension);
    if (outputExtension == null)
        outputExtension = EMPTY_STRING;
    // Get the dependency generator information for this tool and file
    // extension
    IManagedDependencyGenerator oldDepGen = null;
    IManagedDependencyGenerator2 depGen = null;
    IManagedDependencyInfo depInfo = null;
    IManagedDependencyCommands depCommands = null;
    IManagedDependencyPreBuild depPreBuild = null;
    IPath[] depFiles = null;
    boolean doDepGen = false;
    {
        IManagedDependencyGeneratorType t = null;
        if (tool != null)
            t = tool.getDependencyGeneratorForExtension(inputExtension);
        if (t != null) {
            int calcType = t.getCalculatorType();
            if (calcType <= IManagedDependencyGeneratorType.TYPE_OLD_TYPE_LIMIT) {
                oldDepGen = (IManagedDependencyGenerator) t;
                doDepGen = (calcType == IManagedDependencyGeneratorType.TYPE_COMMAND);
                if (doDepGen) {
                    IPath depFile = Path.fromOSString(relativePath + fileName + DOT + DEP_EXT);
                    getDependencyMakefiles(h).add(depFile);
                    generatedDepFiles.add(depFile);
                }
            } else {
                depGen = (IManagedDependencyGenerator2) t;
                doDepGen = (calcType == IManagedDependencyGeneratorType.TYPE_BUILD_COMMANDS);
                IBuildObject buildContext = rcInfo;
                depInfo = depGen.getDependencySourceInfo(resource.getProjectRelativePath(), resource, buildContext, tool, getBuildWorkingDir());
                if (calcType == IManagedDependencyGeneratorType.TYPE_BUILD_COMMANDS) {
                    depCommands = (IManagedDependencyCommands) depInfo;
                    depFiles = depCommands.getDependencyFiles();
                } else if (calcType == IManagedDependencyGeneratorType.TYPE_PREBUILD_COMMANDS) {
                    depPreBuild = (IManagedDependencyPreBuild) depInfo;
                    depFiles = depPreBuild.getDependencyFiles();
                }
                if (depFiles != null) {
                    for (IPath depFile : depFiles) {
                        getDependencyMakefiles(h).add(depFile);
                        generatedDepFiles.add(depFile);
                    }
                }
            }
        }
    }
    // Figure out the output paths
    String optDotExt = EMPTY_STRING;
    if (outputExtension.length() > 0)
        optDotExt = DOT + outputExtension;
    List<IPath> ruleOutputs = new ArrayList<>();
    List<IPath> enumeratedPrimaryOutputs = new ArrayList<>();
    List<IPath> enumeratedSecondaryOutputs = new ArrayList<>();
    // JABA
    this.usedOutType = tool.getPrimaryOutputType();
    calculateOutputsForSource(tool, relativePath, resource, sourceLocation, ruleOutputs, enumeratedPrimaryOutputs, enumeratedSecondaryOutputs);
    enumeratedOutputs.addAll(enumeratedPrimaryOutputs);
    enumeratedOutputs.addAll(enumeratedSecondaryOutputs);
    String primaryOutputName = null;
    if (enumeratedPrimaryOutputs.size() > 0) {
        primaryOutputName = escapeWhitespaces(enumeratedPrimaryOutputs.get(0).toOSString());
    } else {
        primaryOutputName = escapeWhitespaces(relativePath + fileName + optDotExt);
    }
    String otherPrimaryOutputs = EMPTY_STRING;
    for (int i = 1; i < enumeratedPrimaryOutputs.size(); i++) {
        otherPrimaryOutputs += WHITESPACE + escapeWhitespaces(enumeratedPrimaryOutputs.get(i).toOSString());
    }
    // Output file location needed for the file-specific build macros
    IPath outputLocation = Path.fromOSString(primaryOutputName);
    if (!outputLocation.isAbsolute()) {
        outputLocation = getPathForResource(this.project).append(getBuildWorkingDir()).append(primaryOutputName);
    }
    // A separate rule is needed for the resource in the case where explicit
    // file-specific macros
    // are referenced, or if the resource contains special characters in its
    // path (e.g., whitespace)
    /*
		 * fix for 137674 We only need an explicit rule if one of the following
		 * is true: - The resource is linked, and its full path to its real
		 * location contains special characters - The resource is not linked,
		 * but its project relative path contains special characters
		 */
    boolean resourceNameRequiresExplicitRule = (resource.isLinked() && containsSpecialCharacters(sourceLocation.toOSString())) || (!resource.isLinked() && containsSpecialCharacters(resource.getProjectRelativePath().toOSString()));
    boolean needExplicitRuleForFile = resourceNameRequiresExplicitRule || BuildMacroProvider.getReferencedExplitFileMacros(tool).length > 0 || BuildMacroProvider.getReferencedExplitFileMacros(tool.getToolCommand(), IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool)).length > 0;
    // Get and resolve the command
    String cmd = tool.getToolCommand();
    try {
        String resolvedCommand = null;
        if (!needExplicitRuleForFile) {
            resolvedCommand = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(cmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
        } else {
            // if we need an explicit rule then don't use any builder
            // variables, resolve everything
            // to explicit strings
            resolvedCommand = ManagedBuildManager.getBuildMacroProvider().resolveValue(cmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
        }
        if ((resolvedCommand = resolvedCommand.trim()).length() > 0)
            cmd = resolvedCommand;
    } catch (BuildMacroException e) {
    /* JABA is not going to write this code */
    }
    String defaultOutputName = EMPTY_STRING;
    String primaryDependencyName = EMPTY_STRING;
    String patternPrimaryDependencyName = EMPTY_STRING;
    String home = (generatedSource) ? DOT : ROOT;
    String resourcePath = null;
    boolean patternRule = true;
    boolean isItLinked = false;
    if (resource.isLinked(IResource.CHECK_ANCESTORS)) {
        // it IS linked, so use the actual location
        isItLinked = true;
        resourcePath = sourceLocation.toOSString();
        // Need a hardcoded rule, not a pattern rule, as a linked file
        // can reside in any path
        defaultOutputName = escapeWhitespaces(relativePath + fileName + optDotExt);
        primaryDependencyName = escapeWhitespaces(resourcePath);
        patternRule = false;
    } else {
        // Use the relative path (not really needed to store per se but in
        // the future someone may want this)
        resourcePath = relativePath;
        // The rule and command to add to the makefile
        if (rcInfo instanceof IFileInfo || needExplicitRuleForFile) {
            // Need a hardcoded rule, not a pattern rule
            defaultOutputName = escapeWhitespaces(resourcePath + fileName + optDotExt);
            patternRule = false;
        } else {
            defaultOutputName = relativePath + WILDCARD + optDotExt;
        }
        primaryDependencyName = escapeWhitespaces(home + FILE_SEPARATOR + resourcePath + fileName + DOT + inputExtension);
        patternPrimaryDependencyName = home + FILE_SEPARATOR + resourcePath + WILDCARD + DOT + inputExtension;
    }
    // end fix for PR 70491
    // If the tool specifies a dependency calculator of
    // TYPE_BUILD_COMMANDS,
    // ask whether
    // the dependency commands are "generic" (i.e., we can use a pattern
    // rule)
    boolean needExplicitDependencyCommands = false;
    if (depCommands != null) {
        needExplicitDependencyCommands = !depCommands.areCommandsGeneric();
    }
    // things
    if (patternRule) {
        patternRule = false;
        // Make sure that at least one of the rule outputs contains a %.
        for (int i = 0; i < ruleOutputs.size(); i++) {
            String ruleOutput = ruleOutputs.get(i).toOSString();
            if (ruleOutput.indexOf('%') >= 0) {
                patternRule = true;
                break;
            }
        }
        if (patternRule) {
            patternRule = !needExplicitDependencyCommands;
        }
    }
    // Begin building the rule for this source file
    String buildRule = EMPTY_STRING;
    if (patternRule) {
        if (ruleOutputs.size() == 0) {
            buildRule += defaultOutputName;
        } else {
            boolean first = true;
            for (int i = 0; i < ruleOutputs.size(); i++) {
                String ruleOutput = ruleOutputs.get(i).toOSString();
                if (ruleOutput.indexOf('%') >= 0) {
                    if (first) {
                        first = false;
                    } else {
                        buildRule += WHITESPACE;
                    }
                    buildRule += ruleOutput;
                }
            }
        }
    } else {
        buildRule += primaryOutputName;
    }
    String buildRuleDependencies = primaryDependencyName;
    String patternBuildRuleDependencies = patternPrimaryDependencyName;
    // Other additional inputs
    // Get any additional dependencies specified for the tool in other
    // InputType elements and AdditionalInput elements
    IPath[] addlDepPaths = tool.getAdditionalDependencies();
    for (IPath addlDepPath : addlDepPaths) {
        // Translate the path from project relative to build directory
        // relative
        IPath addlPath = addlDepPath;
        if (!(addlPath.toString().startsWith("$("))) {
            if (!addlPath.isAbsolute()) {
                IPath tempPath = this.project.getLocation().append(new Path(ensureUnquoted(addlPath.toString())));
                if (tempPath != null) {
                    addlPath = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), tempPath);
                }
            }
        }
        String suitablePath = ensurePathIsGNUMakeTargetRuleCompatibleSyntax(addlPath.toOSString());
        buildRuleDependencies += WHITESPACE + suitablePath;
        patternBuildRuleDependencies += WHITESPACE + suitablePath;
    }
    buildRule += COLON + WHITESPACE + (patternRule ? patternBuildRuleDependencies : buildRuleDependencies);
    // it or the commands to build the file
    if (getRuleList().contains(buildRule)) {
    // TODO: Should we assert that this is a pattern rule?
    } else {
        getRuleList().add(buildRule);
        // Echo starting message
        buffer.append(buildRule + NEWLINE);
        buffer.append(TAB + AT + escapedEcho(MESSAGE_START_FILE + WHITESPACE + IN_MACRO));
        buffer.append(TAB + AT + escapedEcho(tool.getAnnouncement()));
        // there are any pre-tool commands.
        if (depCommands != null) {
            String[] preToolCommands = depCommands.getPreToolDependencyCommands();
            if (preToolCommands != null && preToolCommands.length > 0) {
                for (String preCmd : preToolCommands) {
                    try {
                        String resolvedCommand;
                        IBuildMacroProvider provider = ManagedBuildManager.getBuildMacroProvider();
                        if (!needExplicitRuleForFile) {
                            resolvedCommand = provider.resolveValueToMakefileFormat(preCmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
                        } else {
                            // if we need an explicit rule then don't use
                            // any builder
                            // variables, resolve everything to explicit
                            // strings
                            resolvedCommand = provider.resolveValue(preCmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
                        }
                        if (resolvedCommand != null)
                            buffer.append(resolvedCommand).append(NEWLINE);
                    } catch (BuildMacroException e) {
                    /* JABA is not going to write this code */
                    }
                }
            }
        }
        // Generate the command line
        Vector<String> inputs = new Vector<>();
        inputs.add(IN_MACRO);
        // Other additional inputs
        // Get any additional dependencies specified for the tool in other
        // InputType elements and AdditionalInput elements
        IPath[] addlInputPaths = getAdditionalResourcesForSource(tool);
        for (IPath addlInputPath : addlInputPaths) {
            // Translate the path from project relative to build directory
            // relative
            IPath addlPath = addlInputPath;
            if (!(addlPath.toString().startsWith("$("))) {
                if (!addlPath.isAbsolute()) {
                    IPath tempPath = getPathForResource(this.project).append(addlPath);
                    if (tempPath != null) {
                        addlPath = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), tempPath);
                    }
                }
            }
            inputs.add(addlPath.toOSString());
        }
        String[] inputStrings = inputs.toArray(new String[inputs.size()]);
        String[] flags = null;
        // Get the tool command line options
        try {
            flags = tool.getToolCommandFlags(sourceLocation, outputLocation);
        } catch (BuildException ex) {
            // TODO add some routines to catch this
            flags = EMPTY_STRING_ARRAY;
        }
        // it wants added to the command line
        if (depCommands != null) {
            flags = addDependencyOptions(depCommands, flags);
        }
        IManagedCommandLineInfo cmdLInfo = null;
        String outflag = null;
        String outputPrefix = null;
        if (rcInfo instanceof IFileInfo || needExplicitRuleForFile || needExplicitDependencyCommands) {
            outflag = tool.getOutputFlag();
            outputPrefix = tool.getOutputPrefix();
            // Call the command line generator
            IManagedCommandLineGenerator cmdLGen = tool.getCommandLineGenerator();
            cmdLInfo = cmdLGen.generateCommandLineInfo(tool, cmd, flags, outflag, outputPrefix, OUT_MACRO + otherPrimaryOutputs, inputStrings, tool.getCommandLinePattern());
        } else {
            // config.getOutputFlag(outputExtension);
            outflag = tool.getOutputFlag();
            // config.getOutputPrefix(outputExtension);
            outputPrefix = tool.getOutputPrefix();
            // Call the command line generator
            cmdLInfo = generateToolCommandLineInfo(tool, inputExtension, flags, outflag, outputPrefix, OUT_MACRO + otherPrimaryOutputs, inputStrings, sourceLocation, outputLocation);
        }
        // The command to build
        String buildCmd;
        if (cmdLInfo != null) {
            buildCmd = cmdLInfo.getCommandLine();
        } else {
            StringBuffer buildFlags = new StringBuffer();
            for (String flag : flags) {
                if (flag != null) {
                    buildFlags.append(flag).append(WHITESPACE);
                }
            }
            buildCmd = cmd + WHITESPACE + buildFlags.toString().trim() + WHITESPACE + outflag + WHITESPACE + outputPrefix + OUT_MACRO + otherPrimaryOutputs + WHITESPACE + IN_MACRO;
        }
        // generated
        try {
            String resolvedCommand;
            IBuildMacroProvider provider = ManagedBuildManager.getBuildMacroProvider();
            if (!needExplicitRuleForFile) {
                resolvedCommand = provider.resolveValueToMakefileFormat(buildCmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
            } else {
                // if we need an explicit rule then don't use any builder
                // variables, resolve everything to explicit strings
                resolvedCommand = provider.resolveValue(buildCmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
            }
            if ((resolvedCommand = resolvedCommand.trim()).length() > 0)
                buildCmd = resolvedCommand;
        } catch (BuildMacroException e) {
        /* JABA is not going to write this code */
        }
        // buffer.append(TAB).append(AT).append(escapedEcho(buildCmd));
        // buffer.append(TAB).append(AT).append(buildCmd);
        buffer.append(TAB).append(buildCmd);
        // Determine if there are any dependencies to calculate
        if (doDepGen) {
            // Get the dependency rule out of the generator
            String[] depCmds = null;
            if (oldDepGen != null) {
                depCmds = new String[1];
                depCmds[0] = oldDepGen.getDependencyCommand(resource, ManagedBuildManager.getBuildInfo(this.project));
            } else {
                if (depCommands != null) {
                    depCmds = depCommands.getPostToolDependencyCommands();
                }
            }
            if (depCmds != null) {
                for (String depCmd : depCmds) {
                    // Resolve any macros in the dep command after it has
                    // been generated.
                    // Note: do not trim the result because it will strip
                    // out necessary tab characters.
                    buffer.append(WHITESPACE).append(LOGICAL_AND).append(WHITESPACE).append(LINEBREAK);
                    try {
                        if (!needExplicitRuleForFile) {
                            depCmd = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(depCmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
                        } else {
                            depCmd = ManagedBuildManager.getBuildMacroProvider().resolveValue(depCmd, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
                        }
                    } catch (BuildMacroException e) {
                    /* JABA is not going to do this */
                    }
                    buffer.append(depCmd);
                }
            }
        }
        // Echo finished message
        buffer.append(NEWLINE);
        buffer.append(TAB + AT + escapedEcho(MESSAGE_FINISH_FILE + WHITESPACE + IN_MACRO));
        buffer.append(TAB + AT + ECHO_BLANK_LINE + NEWLINE);
    }
    // Determine if there are calculated dependencies
    IPath[] addlDeps = null;
    IPath[] addlTargets = null;
    String calculatedDependencies = null;
    boolean addedDepLines = false;
    String depLine;
    if (oldDepGen != null && oldDepGen.getCalculatorType() != IManagedDependencyGeneratorType.TYPE_COMMAND) {
        addlDeps = oldCalculateDependenciesForSource(oldDepGen, tool, relativePath, resource);
    } else {
        if (depGen != null && depGen.getCalculatorType() == IManagedDependencyGeneratorType.TYPE_CUSTOM) {
            if (depInfo instanceof IManagedDependencyCalculator) {
                IManagedDependencyCalculator depCalculator = (IManagedDependencyCalculator) depInfo;
                addlDeps = calculateDependenciesForSource(depCalculator);
                addlTargets = depCalculator.getAdditionalTargets();
            }
        }
    }
    if (addlDeps != null && addlDeps.length > 0) {
        calculatedDependencies = new String();
        for (IPath addlDep : addlDeps) {
            calculatedDependencies += WHITESPACE + escapeWhitespaces(addlDep.toOSString());
        }
    }
    if (calculatedDependencies != null) {
        depLine = primaryOutputName + COLON + calculatedDependencies + NEWLINE;
        if (!getDepLineList().contains(depLine)) {
            getDepLineList().add(depLine);
            addedDepLines = true;
            buffer.append(depLine);
        }
    }
    // Add any additional outputs here using dependency lines
    Vector<IPath> addlOutputs = new Vector<>();
    if (enumeratedPrimaryOutputs.size() > 1) {
        // output
        for (int i = 1; i < enumeratedPrimaryOutputs.size(); i++) addlOutputs.add(enumeratedPrimaryOutputs.get(i));
    }
    addlOutputs.addAll(enumeratedSecondaryOutputs);
    if (addlTargets != null) {
        for (IPath addlTarget : addlTargets) addlOutputs.add(addlTarget);
    }
    for (int i = 0; i < addlOutputs.size(); i++) {
        depLine = escapeWhitespaces(addlOutputs.get(i).toOSString()) + COLON + WHITESPACE + primaryOutputName;
        if (calculatedDependencies != null)
            depLine += calculatedDependencies;
        depLine += NEWLINE;
        if (!getDepLineList().contains(depLine)) {
            getDepLineList().add(depLine);
            addedDepLines = true;
            buffer.append(depLine);
        }
    }
    if (addedDepLines) {
        buffer.append(NEWLINE);
    }
    // get the rule to build the dependency file
    if (depPreBuild != null && depFiles != null) {
        addedDepLines = false;
        String[] preBuildCommands = depPreBuild.getDependencyCommands();
        if (preBuildCommands != null) {
            depLine = "";
            // Can we use a pattern rule?
            patternRule = !isItLinked && !needExplicitRuleForFile && depPreBuild.areCommandsGeneric();
            // Begin building the rule
            for (int i = 0; i < depFiles.length; i++) {
                if (i > 0)
                    depLine += WHITESPACE;
                if (patternRule) {
                    optDotExt = EMPTY_STRING;
                    String depExt = depFiles[i].getFileExtension();
                    if (depExt != null && depExt.length() > 0)
                        optDotExt = DOT + depExt;
                    depLine += escapeWhitespaces(relativePath + WILDCARD + optDotExt);
                } else {
                    depLine += escapeWhitespaces((depFiles[i]).toOSString());
                }
            }
            depLine += COLON + WHITESPACE + (patternRule ? patternBuildRuleDependencies : buildRuleDependencies);
            if (!getDepRuleList().contains(depLine)) {
                getDepRuleList().add(depLine);
                addedDepLines = true;
                buffer.append(depLine + NEWLINE);
                buffer.append(TAB + AT + escapedEcho(MESSAGE_START_DEPENDENCY + WHITESPACE + OUT_MACRO));
                for (String preBuildCommand : preBuildCommands) {
                    depLine = preBuildCommand;
                    // Resolve macros
                    try {
                        if (!needExplicitRuleForFile) {
                            depLine = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(depLine, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
                        } else {
                            depLine = ManagedBuildManager.getBuildMacroProvider().resolveValue(depLine, EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE, new FileContextData(sourceLocation, outputLocation, null, tool));
                        }
                    } catch (BuildMacroException e) {
                    // JABA is not going to write this code
                    }
                    // buffer.append(TAB + AT + escapedEcho(depLine));
                    // buffer.append(TAB + AT + depLine + NEWLINE);
                    buffer.append(TAB + depLine + NEWLINE);
                }
            }
            if (addedDepLines) {
                buffer.append(TAB + AT + ECHO_BLANK_LINE + NEWLINE);
            }
        }
    }
}
Also used : IManagedDependencyCalculator(org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCalculator) ArrayList(java.util.ArrayList) IFolderInfo(org.eclipse.cdt.managedbuilder.core.IFolderInfo) IManagedDependencyGeneratorType(org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGeneratorType) IBuildObject(org.eclipse.cdt.managedbuilder.core.IBuildObject) BuildMacroException(org.eclipse.cdt.managedbuilder.macros.BuildMacroException) IManagedDependencyGenerator2(org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator2) IManagedDependencyCommands(org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCommands) IBuildMacroProvider(org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider) Vector(java.util.Vector) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IManagedDependencyGenerator(org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator) IPath(org.eclipse.core.runtime.IPath) IManagedCommandLineGenerator(org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator) FileContextData(org.eclipse.cdt.managedbuilder.internal.macros.FileContextData) IManagedDependencyInfo(org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyInfo) ITool(org.eclipse.cdt.managedbuilder.core.ITool) IFileInfo(org.eclipse.cdt.managedbuilder.core.IFileInfo) IManagedCommandLineInfo(org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo) IManagedDependencyPreBuild(org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyPreBuild) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException)

Example 4 with IFileInfo

use of org.eclipse.cdt.managedbuilder.core.IFileInfo 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 IFileInfo

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

the class ArduinoGnuMakefileGenerator method addFragmentMakefileEntriesForSource.

/*
	 * (non-Javadoc Adds the entries for a particular source file to the
	 * fragment makefile
	 *
	 * @param buildVarToRuleStringMap map of build variable names to the list of
	 * files assigned to the variable
	 *
	 * @param ruleBuffer buffer to add generated nmakefile text to
	 *
	 * @param folder the top level build output directory
	 *
	 * @param relativePath build output directory relative path of the current
	 * output directory
	 *
	 * @param resource the source file for this invocation of the tool - this
	 * may be null for a generated output
	 *
	 * @param sourceLocation the full path of the source
	 *
	 * @param resConfig the IResourceConfiguration associated with this file or
	 * null
	 *
	 * @param varName the build variable to add this invocation's outputs to if
	 * <code>null</code>, use the file extension to find the name
	 *
	 * @param generatedSource if <code>true</code>, this file was generated by
	 * another tool in the tool-chain
	 */
protected void addFragmentMakefileEntriesForSource(LinkedHashMap<String, String> buildVarToRuleStringMap, StringBuffer ruleBuffer, IFolder folder, String relativePath, IResource resource, IPath sourceLocation, IResourceInfo rcInfo, String varName, boolean generatedSource) {
    // Determine which tool, if any, builds files with this extension
    String ext = sourceLocation.getFileExtension();
    ITool tool = null;
    // Use the tool from the resource configuration if there is one
    if (rcInfo instanceof IFileInfo) {
        IFileInfo fi = (IFileInfo) rcInfo;
        ITool[] tools = fi.getToolsToInvoke();
        if (tools != null && tools.length > 0) {
            tool = tools[0];
            // if(!tool.getCustomBuildStep())
            addToBuildVar(buildVarToRuleStringMap, ext, varName, relativePath, sourceLocation, generatedSource);
        }
    }
    ToolInfoHolder h = getToolInfo(rcInfo.getPath());
    ITool[] buildTools = h.buildTools;
    // if(tool == null && rcInfo.getPath().segmentCount() != 0){
    if (tool == null) {
        h = getToolInfo(Path.EMPTY);
        buildTools = h.buildTools;
        for (ITool buildTool : buildTools) {
            if (buildTool.buildsFileType(ext)) {
                tool = buildTool;
                addToBuildVar(buildVarToRuleStringMap, ext, varName, relativePath, sourceLocation, generatedSource);
                break;
            }
        }
    }
    if (tool != null) {
        // Generate the rule to build this source file
        IInputType primaryInputType = tool.getPrimaryInputType();
        IInputType inputType = tool.getInputType(ext);
        if ((primaryInputType != null && !primaryInputType.getMultipleOfType()) || (inputType == null && tool != this.config.calculateTargetTool())) {
            // Try to add the rule for the file
            List<IPath> generatedOutputs = new ArrayList<>();
            List<IPath> generatedDepFiles = new ArrayList<>();
            // MODED moved JABA JAn Baeyens get the out type from the add
            // source call
            this.usedOutType = null;
            addRuleForSource(relativePath, ruleBuffer, resource, sourceLocation, rcInfo, generatedSource, generatedDepFiles, generatedOutputs);
            // to the variable
            if (generatedDepFiles.size() > 0) {
                for (int k = 0; k < generatedDepFiles.size(); k++) {
                    IPath generatedDepFile = generatedDepFiles.get(k);
                    addMacroAdditionFile(buildVarToRuleStringMap, getDepMacroName(ext).toString(), (generatedDepFile.isAbsolute() ? "" : DOTSLASH) + generatedDepFile.toOSString());
                }
            }
            // If the generated outputs of this tool are input to another
            // tool,
            // 1. add the output to the appropriate macro
            // 2. If the tool does not have multipleOfType input, generate
            // the rule.
            // IOutputType outType = tool.getPrimaryOutputType();
            // MODED
            // moved JABA JAn Baeyens get the out type from the add source
            // call
            String buildVariable = null;
            if (this.usedOutType != null) {
                if (tool.getCustomBuildStep()) {
                    // tool does not currently define a build variable
                    if (generatedOutputs.size() > 0) {
                        IPath firstOutput = generatedOutputs.get(0);
                        String firstExt = firstOutput.getFileExtension();
                        ToolInfoHolder tmpH = getFolderToolInfo(rcInfo.getPath());
                        ITool[] tmpBuildTools = tmpH.buildTools;
                        for (ITool tmpBuildTool : tmpBuildTools) {
                            if (tmpBuildTool.buildsFileType(firstExt)) {
                                String bV = tmpBuildTool.getPrimaryInputType().getBuildVariable();
                                if (bV.length() > 0) {
                                    buildVariable = bV;
                                    break;
                                }
                            }
                        }
                    }
                } else {
                    buildVariable = this.usedOutType.getBuildVariable();
                }
            } else {
                // For support of pre-CDT 3.0 integrations.
                buildVariable = OBJS_MACRO;
            }
            for (int k = 0; k < generatedOutputs.size(); k++) {
                IPath generatedOutput;
                IResource generateOutputResource;
                if (generatedOutputs.get(k).isAbsolute()) {
                    // TODO: Should we use relative paths when possible
                    // (e.g., see MbsMacroSupplier.calculateRelPath)
                    generatedOutput = generatedOutputs.get(k);
                    // If this file has an absolute path, then the
                    // generateOutputResource will not be correct
                    // because the file is not under the project. We use
                    // this resource in the calls to the dependency
                    // generator
                    generateOutputResource = this.project.getFile(generatedOutput);
                } else {
                    generatedOutput = getPathForResource(this.project).append(getBuildWorkingDir()).append(generatedOutputs.get(k));
                    generateOutputResource = this.project.getFile(getBuildWorkingDir().append(generatedOutputs.get(k)));
                }
                IResourceInfo nextRcInfo;
                if (rcInfo instanceof IFileInfo) {
                    nextRcInfo = this.config.getResourceInfo(rcInfo.getPath().removeLastSegments(1), false);
                } else {
                    nextRcInfo = rcInfo;
                }
                addFragmentMakefileEntriesForSource(buildVarToRuleStringMap, ruleBuffer, folder, relativePath, generateOutputResource, generatedOutput, nextRcInfo, buildVariable, true);
            }
        }
    } else {
        // If this is a secondary input, add it to build vars
        if (varName == null) {
            for (ITool buildTool : buildTools) {
                if (buildTool.isInputFileType(ext)) {
                    addToBuildVar(buildVarToRuleStringMap, ext, varName, relativePath, sourceLocation, generatedSource);
                    break;
                }
            }
        } else // If this generated output is identified as a secondary output, add
        // the file to the build variable
        {
            IOutputType[] secondaryOutputs = this.config.getToolChain().getSecondaryOutputs();
            if (secondaryOutputs.length > 0) {
                if (isSecondaryOutputVar(h, secondaryOutputs, varName)) {
                    addMacroAdditionFile(buildVarToRuleStringMap, varName, relativePath, sourceLocation, generatedSource);
                }
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ITool(org.eclipse.cdt.managedbuilder.core.ITool) IFileInfo(org.eclipse.cdt.managedbuilder.core.IFileInfo) IInputType(org.eclipse.cdt.managedbuilder.core.IInputType) IResource(org.eclipse.core.resources.IResource) IResourceInfo(org.eclipse.cdt.managedbuilder.core.IResourceInfo) IOutputType(org.eclipse.cdt.managedbuilder.core.IOutputType)

Aggregations

IFileInfo (org.eclipse.cdt.managedbuilder.core.IFileInfo)5 IResourceInfo (org.eclipse.cdt.managedbuilder.core.IResourceInfo)4 IPath (org.eclipse.core.runtime.IPath)4 IFolderInfo (org.eclipse.cdt.managedbuilder.core.IFolderInfo)3 ArrayList (java.util.ArrayList)2 ITool (org.eclipse.cdt.managedbuilder.core.ITool)2 IResource (org.eclipse.core.resources.IResource)2 Path (org.eclipse.core.runtime.Path)2 Vector (java.util.Vector)1 BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)1 IBuildObject (org.eclipse.cdt.managedbuilder.core.IBuildObject)1 IInputType (org.eclipse.cdt.managedbuilder.core.IInputType)1 IManagedCommandLineGenerator (org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator)1 IManagedCommandLineInfo (org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo)1 IOutputType (org.eclipse.cdt.managedbuilder.core.IOutputType)1 FileContextData (org.eclipse.cdt.managedbuilder.internal.macros.FileContextData)1 BuildMacroException (org.eclipse.cdt.managedbuilder.macros.BuildMacroException)1 IBuildMacroProvider (org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider)1 IManagedDependencyCalculator (org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCalculator)1 IManagedDependencyCommands (org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCommands)1