Search in sources :

Example 1 with IInputType

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

the class ArduinoGnuMakefileGenerator method addTargetsRules.

/**
 * Returns the targets rules. The targets make file (top makefile) contains:
 * 1 the rule for the final target tool 2 the rules for all of the tools
 * that use multipleOfType in their primary input type 3 the rules for all
 * tools that use the output of #2 tools
 *
 * @param outputVarsAdditionsList
 *            list to add needed build output variables to
 * @param managedProjectOutputs
 *            Other projects in the workspace that this project depends upon
 * @return StringBuffer
 */
private StringBuffer addTargetsRules(ITool targetTool, List<String> outputVarsAdditionsList, List<String> managedProjectOutputs, boolean postbuildStep) {
    StringBuffer buffer = new StringBuffer();
    // Add the comment
    buffer.append(COMMENT_SYMBOL + WHITESPACE + ManagedMakeMessages.getResourceString(BUILD_TOP) + NEWLINE);
    ToolInfoHolder h = (ToolInfoHolder) this.toolInfos.getValue();
    ITool[] buildTools = h.buildTools;
    boolean[] buildToolsUsed = h.buildToolsUsed;
    // Get the target tool and generate the rule
    if (targetTool != null) {
        // we quote it anyway just in case it starts to use it in future.
        if (addRuleForTool(targetTool, buffer, true, ensurePathIsGNUMakeTargetRuleCompatibleSyntax(this.buildTargetName), this.buildTargetExt, outputVarsAdditionsList, managedProjectOutputs, postbuildStep)) {
            // Mark the target tool as processed
            for (int i = 0; i < buildTools.length; i++) {
                if (targetTool == buildTools[i]) {
                    buildToolsUsed[i] = true;
                }
            }
        }
    } else {
        buffer.append(TAB + AT + escapedEcho(MESSAGE_NO_TARGET_TOOL + WHITESPACE + OUT_MACRO));
    }
    // the only "multipleOfType" tool is the "target" tool
    for (int i = 0; i < buildTools.length; i++) {
        ITool tool = buildTools[i];
        IInputType type = tool.getPrimaryInputType();
        if (type != null && type.getMultipleOfType()) {
            if (!buildToolsUsed[i]) {
                addRuleForTool(tool, buffer, false, null, null, outputVarsAdditionsList, null, false);
                // Mark the target tool as processed
                buildToolsUsed[i] = true;
                // Look for tools that consume the output
                generateRulesForConsumers(tool, outputVarsAdditionsList, buffer);
            }
        }
    }
    // Add the comment
    buffer.append(COMMENT_SYMBOL + WHITESPACE + ManagedMakeMessages.getResourceString(BUILD_TARGETS) + NEWLINE);
    // Always add a clean target
    buffer.append("clean:" + NEWLINE);
    buffer.append(TAB + "-$(RM)" + WHITESPACE);
    for (Entry<String, List<IPath>> entry : this.buildOutVars.entrySet()) {
        String macroName = entry.getKey();
        buffer.append("$(" + macroName + ")");
    }
    String outputPrefix = EMPTY_STRING;
    if (targetTool != null) {
        outputPrefix = targetTool.getOutputPrefix();
    }
    String completeBuildTargetName = outputPrefix + this.buildTargetName;
    if (this.buildTargetExt.length() > 0) {
        completeBuildTargetName = completeBuildTargetName + DOT + this.buildTargetExt;
    }
    // if (completeBuildTargetName.contains(" ")) {
    // buffer.append(WHITESPACE + "\"" + completeBuildTargetName + "\"");
    // } else {
    // buffer.append(WHITESPACE + completeBuildTargetName);
    // }
    buffer.append(NEWLINE);
    buffer.append(TAB + DASH + AT + ECHO_BLANK_LINE + NEWLINE);
    return buffer;
}
Also used : IInputType(org.eclipse.cdt.managedbuilder.core.IInputType) List(java.util.List) ArrayList(java.util.ArrayList) ITool(org.eclipse.cdt.managedbuilder.core.ITool)

Example 2 with IInputType

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

the class ArduinoGnuMakefileGenerator method generateRulesForConsumers.

/**
 * @param outputVarsAdditionsList
 *            list to add needed build output variables to
 * @param buffer
 *            buffer to add rules to
 */
private void generateRulesForConsumers(ITool generatingTool, List<String> outputVarsAdditionsList, StringBuffer buffer) {
    // Generate a build rule for any tool that consumes the output of this
    // tool
    ToolInfoHolder h = (ToolInfoHolder) this.toolInfos.getValue();
    ITool[] buildTools = h.buildTools;
    boolean[] buildToolsUsed = h.buildToolsUsed;
    IOutputType[] outTypes = generatingTool.getOutputTypes();
    for (IOutputType outType : outTypes) {
        String[] outExts = outType.getOutputExtensions(generatingTool);
        String outVariable = outType.getBuildVariable();
        if (outExts != null) {
            for (String outExt : outExts) {
                for (int k = 0; k < buildTools.length; k++) {
                    ITool tool = buildTools[k];
                    if (!buildToolsUsed[k]) {
                        // Also has to match build variables if specified
                        IInputType inType = tool.getInputType(outExt);
                        if (inType != null) {
                            String inVariable = inType.getBuildVariable();
                            if ((outVariable == null && inVariable == null) || (outVariable != null && inVariable != null && outVariable.equals(inVariable))) {
                                if (addRuleForTool(buildTools[k], buffer, false, null, null, outputVarsAdditionsList, null, false)) {
                                    buildToolsUsed[k] = true;
                                    // Look for tools that consume the
                                    // output
                                    generateRulesForConsumers(buildTools[k], outputVarsAdditionsList, buffer);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IInputType(org.eclipse.cdt.managedbuilder.core.IInputType) ITool(org.eclipse.cdt.managedbuilder.core.ITool) IOutputType(org.eclipse.cdt.managedbuilder.core.IOutputType)

Example 3 with IInputType

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

Example 4 with IInputType

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

the class ArduinoManagedBuildGnuToolInfo method calculateInputs.

/*
	 * Other Methods
	 */
public boolean calculateInputs(ArduinoGnuMakefileGenerator makeGen, IConfiguration config, IResource[] projResources, ToolInfoHolder h, boolean lastChance) {
    // Get the inputs for this tool invocation
    // Note that command inputs that are also dependencies are also added to
    // the command dependencies list
    /*
		 * The priorities for determining the names of the inputs of a tool are:
		 * 1. If an option is specified, use the value of the option. 2. If a
		 * build variable is specified, use the files that have been added to
		 * the build variable as the output(s) of other build steps. 3. Use the
		 * file extensions and the resources in the project
		 */
    boolean done = true;
    // Inputs for the
    Vector<String> myCommandInputs = new Vector<>();
    // tool command
    // line
    // Dependencies
    Vector<String> myCommandDependencies = new Vector<>();
    // for the
    // make
    // rule
    // Complete
    Vector<String> myEnumeratedInputs = new Vector<>();
    // list of
    // individual
    // inputs
    IInputType[] inTypes = this.tool.getInputTypes();
    if (inTypes != null && inTypes.length > 0) {
        for (IInputType type : inTypes) {
            // Inputs
            Vector<String> itCommandInputs = new Vector<>();
            // for
            // the
            // tool
            // command
            // line
            // for
            // this
            // input-type
            // Dependencies
            Vector<String> itCommandDependencies = new Vector<>();
            // for
            // the
            // make
            // rule
            // for
            // this
            // input-type
            // Complete
            Vector<String> itEnumeratedInputs = new Vector<>();
            // list
            // of
            // individual
            // inputs
            // for
            // this
            // input-type
            String variable = type.getBuildVariable();
            boolean primaryInput = type.getPrimaryInput();
            boolean useFileExts = false;
            IOption option = this.tool.getOptionBySuperClassId(type.getOptionId());
            IOption assignToOption = this.tool.getOptionBySuperClassId(type.getAssignToOptionId());
            // Option?
            if (option != null) {
                try {
                    List<String> inputs = new ArrayList<>();
                    int optType = option.getValueType();
                    if (optType == IOption.STRING) {
                        inputs.add(option.getStringValue());
                    } else if (optType == IOption.STRING_LIST || optType == IOption.LIBRARIES || optType == IOption.OBJECTS || optType == IOption.INCLUDE_FILES || optType == IOption.LIBRARY_PATHS || optType == IOption.LIBRARY_FILES || optType == IOption.MACRO_FILES) {
                        @SuppressWarnings("unchecked") List<String> valueList = (List<String>) option.getValue();
                        inputs = valueList;
                        this.tool.filterValues(optType, inputs);
                        this.tool.filterValues(optType, inputs);
                    }
                    for (int j = 0; j < inputs.size(); j++) {
                        String inputName = inputs.get(j);
                        try {
                            // try to resolve the build macros in the output
                            // names
                            String resolved = null;
                            // TODO: support other special characters
                            if (// $NON-NLS-1$
                            inputName.indexOf(" ") != -1) {
                                // resolve to string
                                resolved = // $NON-NLS-1$
                                ManagedBuildManager.getBuildMacroProvider().resolveValue(// $NON-NLS-1$
                                inputName, // $NON-NLS-1$
                                "", // $NON-NLS-1$
                                " ", IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(option, this.tool));
                            } else {
                                // resolve to makefile variable format
                                resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(// $NON-NLS-1$
                                inputName, // $NON-NLS-1$
                                "", // $NON-NLS-1$
                                " ", IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(option, this.tool));
                            }
                            if ((resolved = resolved.trim()).length() > 0)
                                inputName = resolved;
                        } catch (BuildMacroException e) {
                        // JABA is not
                        // going to add
                        // code
                        }
                        if (primaryInput) {
                            itCommandDependencies.add(j, inputName);
                        } else {
                            itCommandDependencies.add(inputName);
                        }
                    // NO - itCommandInputs.add(inputName);
                    // NO - itEnumeratedInputs.add(inputName);
                    }
                } catch (BuildException ex) {
                // JABA is not going to add
                // code
                }
            } else {
                // Build Variable?
                if (variable.length() > 0) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    String cmdVariable = variable = "$(" + variable + ")";
                    itCommandInputs.add(cmdVariable);
                    if (primaryInput) {
                        itCommandDependencies.add(0, cmdVariable);
                    } else {
                        itCommandDependencies.add(cmdVariable);
                    }
                    // If there is an output variable with the same name,
                    // get
                    // the files associated with it.
                    List<String> outMacroList = makeGen.getBuildVariableList(h, variable, ArduinoGnuMakefileGenerator.PROJECT_RELATIVE, null, true);
                    if (outMacroList != null) {
                        itEnumeratedInputs.addAll(outMacroList);
                    } else {
                        // extensions below
                        if (lastChance) {
                            useFileExts = true;
                        } else {
                            done = false;
                            break;
                        }
                    }
                }
                // Use file extensions
                if (variable.length() == 0 || useFileExts) {
                    // if (type.getMultipleOfType()) {
                    // Calculate EnumeratedInputs using the file extensions
                    // and the resources in the project
                    // Note: This is only correct for tools with
                    // multipleOfType == true, but for other tools
                    // it gives us an input resource for generating default
                    // names
                    // Determine the set of source input macros to use
                    HashSet<String> handledInputExtensions = new HashSet<>();
                    String[] exts = type.getSourceExtensions(this.tool);
                    if (projResources != null) {
                        for (IResource rc : projResources) {
                            if (rc.getType() == IResource.FILE) {
                                String fileExt = rc.getFileExtension();
                                // fix for NPE, bugzilla 99483
                                if (fileExt == null) {
                                    // $NON-NLS-1$
                                    fileExt = "";
                                }
                                for (int k = 0; k < exts.length; k++) {
                                    if (fileExt.equals(exts[k])) {
                                        if (!useFileExts) {
                                            if (!handledInputExtensions.contains(fileExt)) {
                                                handledInputExtensions.add(fileExt);
                                                String buildMacro = // $NON-NLS-1$
                                                "$(" + makeGen.getSourceMacroName(fileExt).toString() + // $NON-NLS-1$
                                                ")";
                                                itCommandInputs.add(buildMacro);
                                                if (primaryInput) {
                                                    itCommandDependencies.add(0, buildMacro);
                                                } else {
                                                    itCommandDependencies.add(buildMacro);
                                                }
                                            }
                                        }
                                        if (type.getMultipleOfType() || itEnumeratedInputs.size() == 0) {
                                            // Add a path that is relative
                                            // to the project directory
                                            itEnumeratedInputs.add(rc.getProjectRelativePath().toOSString());
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                // }
                }
            }
            // Get any additional inputs specified in the manifest file or
            // the project file
            IAdditionalInput[] addlInputs = type.getAdditionalInputs();
            if (addlInputs != null) {
                for (int j = 0; j < addlInputs.length; j++) {
                    IAdditionalInput addlInput = addlInputs[j];
                    int kind = addlInput.getKind();
                    if (kind == IAdditionalInput.KIND_ADDITIONAL_INPUT || kind == IAdditionalInput.KIND_ADDITIONAL_INPUT_DEPENDENCY) {
                        String[] paths = addlInput.getPaths();
                        if (paths != null) {
                            for (int k = 0; k < paths.length; k++) {
                                String path = paths[k];
                                itEnumeratedInputs.add(path);
                                // to build directory relative
                                if (!(path.startsWith("$("))) {
                                    // $NON-NLS-1$
                                    IResource addlResource = this.project.getFile(path);
                                    if (addlResource != null) {
                                        IPath addlPath = addlResource.getLocation();
                                        if (addlPath != null) {
                                            path = ManagedBuildManager.calculateRelativePath(makeGen.getTopBuildDir(), addlPath).toOSString();
                                        }
                                    }
                                }
                                itCommandInputs.add(path);
                            }
                        }
                    }
                }
            }
            // input(s) as the value of that option
            if (assignToOption != null && option == null) {
                try {
                    int optType = assignToOption.getValueType();
                    if (optType == IOption.STRING) {
                        // $NON-NLS-1$
                        String optVal = "";
                        for (int j = 0; j < itCommandInputs.size(); j++) {
                            if (j != 0) {
                                // $NON-NLS-1$
                                optVal += " ";
                            }
                            optVal += itCommandInputs.get(j);
                        }
                        ManagedBuildManager.setOption(config, this.tool, assignToOption, optVal);
                    } else if (optType == IOption.STRING_LIST || optType == IOption.LIBRARIES || optType == IOption.OBJECTS || optType == IOption.INCLUDE_FILES || optType == IOption.LIBRARY_PATHS || optType == IOption.LIBRARY_FILES || optType == IOption.MACRO_FILES) {
                        // TODO: do we need to do anything with undefs here?
                        // Mote that when using the enumerated inputs, the
                        // path(s) must be translated from project relative
                        // to top build directory relative
                        String[] paths = new String[itEnumeratedInputs.size()];
                        for (int j = 0; j < itEnumeratedInputs.size(); j++) {
                            paths[j] = itEnumeratedInputs.get(j);
                            IResource enumResource = this.project.getFile(paths[j]);
                            if (enumResource != null) {
                                IPath enumPath = enumResource.getLocation();
                                if (enumPath != null) {
                                    paths[j] = ManagedBuildManager.calculateRelativePath(makeGen.getTopBuildDir(), enumPath).toOSString();
                                }
                            }
                        }
                        ManagedBuildManager.setOption(config, this.tool, assignToOption, paths);
                    } else if (optType == IOption.BOOLEAN) {
                        if (itEnumeratedInputs.size() > 0) {
                            ManagedBuildManager.setOption(config, this.tool, assignToOption, true);
                        } else {
                            ManagedBuildManager.setOption(config, this.tool, assignToOption, false);
                        }
                    } else if (optType == IOption.ENUMERATED || optType == IOption.TREE) {
                        if (itCommandInputs.size() > 0) {
                            ManagedBuildManager.setOption(config, this.tool, assignToOption, itCommandInputs.firstElement());
                        }
                    }
                    itCommandInputs.removeAllElements();
                // itEnumeratedInputs.removeAllElements();
                } catch (BuildException ex) {
                // JABA is not going to add
                // code
                }
            }
            myCommandInputs.addAll(itCommandInputs);
            myCommandDependencies.addAll(itCommandDependencies);
            myEnumeratedInputs.addAll(itEnumeratedInputs);
        }
    } else {
        // For support of pre-CDT 3.0 integrations.
        if (this.bIsTargetTool) {
            // NOTE WELL: This only supports the case of a single
            // "target tool"
            // with the following characteristics:
            // 1. The tool consumes exactly all of the object files produced
            // by other tools in the build and produces a single output
            // 2. The target name comes from the configuration artifact name
            // The rule looks like:
            // <targ_prefix><target>.<extension>: $(OBJS) <refd_project_1
            // ... refd_project_n>
            // $NON-NLS-1$
            myCommandInputs.add("$(OBJS)");
            // $NON-NLS-1$
            myCommandInputs.add("$(USER_OBJS)");
            // $NON-NLS-1$
            myCommandInputs.add("$(LIBS)");
        } else {
        // Rule will be generated by addRuleForSource
        }
    }
    if (done) {
        this.commandInputs.addAll(myCommandInputs);
        this.commandDependencies.addAll(0, myCommandDependencies);
        this.enumeratedInputs.addAll(myEnumeratedInputs);
        this.inputsCalculated = true;
        return true;
    }
    return false;
}
Also used : OptionContextData(org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData) IPath(org.eclipse.core.runtime.IPath) IOption(org.eclipse.cdt.managedbuilder.core.IOption) ArrayList(java.util.ArrayList) IAdditionalInput(org.eclipse.cdt.managedbuilder.core.IAdditionalInput) BuildMacroException(org.eclipse.cdt.managedbuilder.macros.BuildMacroException) IInputType(org.eclipse.cdt.managedbuilder.core.IInputType) ArrayList(java.util.ArrayList) List(java.util.List) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) Vector(java.util.Vector) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 5 with IInputType

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

the class ArduinoGnuMakefileGenerator method getAdditionalResourcesForSource.

/**
 * Returns any additional resources specified for the tool in other
 * InputType elements and AdditionalInput elements
 */
protected IPath[] getAdditionalResourcesForSource(ITool tool) {
    List<IPath> allRes = new ArrayList<>();
    IInputType[] types = tool.getInputTypes();
    for (IInputType type : types) {
        // Additional resources come from 2 places.
        // 1. From AdditionalInput childen
        IPath[] res = type.getAdditionalResources();
        for (IPath re : res) {
            allRes.add(re);
        }
        // 2. From InputTypes that other than the primary input type
        if (!type.getPrimaryInput() && type != tool.getPrimaryInputType()) {
            String var = type.getBuildVariable();
            if (var != null && var.length() > 0) {
                allRes.add(Path.fromOSString("$(" + type.getBuildVariable() + ")"));
            } else {
                // Use file extensions
                String[] typeExts = type.getSourceExtensions(tool);
                for (IResource projectResource : this.projectResources) {
                    if (projectResource.getType() == IResource.FILE) {
                        String fileExt = projectResource.getFileExtension();
                        if (fileExt == null) {
                            fileExt = new String();
                        }
                        for (String typeExt : typeExts) {
                            if (fileExt.equals(typeExt)) {
                                allRes.add(projectResource.getProjectRelativePath());
                                break;
                            }
                        }
                    }
                }
            }
            // If an assignToOption has been specified, set the value of the
            // option to the inputs
            IOption assignToOption = tool.getOptionBySuperClassId(type.getAssignToOptionId());
            IOption option = tool.getOptionBySuperClassId(type.getOptionId());
            if (assignToOption != null && option == null) {
                try {
                    int optType = assignToOption.getValueType();
                    IResourceInfo rcInfo = tool.getParentResourceInfo();
                    if (rcInfo != null) {
                        if (optType == IOption.STRING) {
                            String optVal = new String();
                            for (int j = 0; j < allRes.size(); j++) {
                                if (j != 0) {
                                    optVal += " ";
                                }
                                String resPath = allRes.get(j).toString();
                                if (!resPath.startsWith("$(")) {
                                    IResource addlResource = this.project.getFile(resPath);
                                    if (addlResource != null) {
                                        IPath addlPath = addlResource.getLocation();
                                        if (addlPath != null) {
                                            resPath = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), addlPath).toString();
                                        }
                                    }
                                }
                                optVal += ManagedBuildManager.calculateRelativePath(getTopBuildDir(), Path.fromOSString(resPath)).toString();
                            }
                            ManagedBuildManager.setOption(rcInfo, tool, assignToOption, optVal);
                        } else if (optType == IOption.STRING_LIST || optType == IOption.LIBRARIES || optType == IOption.OBJECTS || optType == IOption.INCLUDE_FILES || optType == IOption.LIBRARY_PATHS || optType == IOption.LIBRARY_FILES || optType == IOption.MACRO_FILES) {
                            // TODO: do we need to do anything with undefs
                            // here?
                            // Note that the path(s) must be translated from
                            // project relative
                            // to top build directory relative
                            String[] paths = new String[allRes.size()];
                            for (int j = 0; j < allRes.size(); j++) {
                                paths[j] = allRes.get(j).toString();
                                if (!paths[j].startsWith("$(")) {
                                    IResource addlResource = this.project.getFile(paths[j]);
                                    if (addlResource != null) {
                                        IPath addlPath = addlResource.getLocation();
                                        if (addlPath != null) {
                                            paths[j] = ManagedBuildManager.calculateRelativePath(getTopBuildDir(), addlPath).toString();
                                        }
                                    }
                                }
                            }
                            ManagedBuildManager.setOption(rcInfo, tool, assignToOption, paths);
                        } else if (optType == IOption.BOOLEAN) {
                            boolean b = false;
                            if (allRes.size() > 0)
                                b = true;
                            ManagedBuildManager.setOption(rcInfo, tool, assignToOption, b);
                        } else if (optType == IOption.ENUMERATED || optType == IOption.TREE) {
                            if (allRes.size() > 0) {
                                String s = allRes.get(0).toString();
                                ManagedBuildManager.setOption(rcInfo, tool, assignToOption, s);
                            }
                        }
                        allRes.clear();
                    }
                } catch (BuildException ex) {
                /* JABA is not going to write this code */
                }
            }
        }
    }
    return allRes.toArray(new IPath[allRes.size()]);
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IOption(org.eclipse.cdt.managedbuilder.core.IOption) IInputType(org.eclipse.cdt.managedbuilder.core.IInputType) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) IResource(org.eclipse.core.resources.IResource) IResourceInfo(org.eclipse.cdt.managedbuilder.core.IResourceInfo)

Aggregations

IInputType (org.eclipse.cdt.managedbuilder.core.IInputType)6 ArrayList (java.util.ArrayList)5 IResource (org.eclipse.core.resources.IResource)4 IPath (org.eclipse.core.runtime.IPath)4 List (java.util.List)3 ITool (org.eclipse.cdt.managedbuilder.core.ITool)3 Vector (java.util.Vector)2 BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)2 IAdditionalInput (org.eclipse.cdt.managedbuilder.core.IAdditionalInput)2 IOption (org.eclipse.cdt.managedbuilder.core.IOption)2 IOutputType (org.eclipse.cdt.managedbuilder.core.IOutputType)2 IResourceInfo (org.eclipse.cdt.managedbuilder.core.IResourceInfo)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 IFileInfo (org.eclipse.cdt.managedbuilder.core.IFileInfo)1 OptionContextData (org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData)1 BuildMacroException (org.eclipse.cdt.managedbuilder.macros.BuildMacroException)1 IManagedDependencyGeneratorType (org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGeneratorType)1