Search in sources :

Example 1 with IOutputType

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

the class ArduinoGnuMakefileGenerator method calculateSecondaryOutputs.

protected List<String> calculateSecondaryOutputs(IOutputType[] secondaryOutputs) {
    ToolInfoHolder h = (ToolInfoHolder) this.toolInfos.getValue();
    ITool[] buildTools = h.buildTools;
    List<String> buildVars = new ArrayList<>();
    for (int i = 0; i < buildTools.length; i++) {
        // Add the specified output build variables
        IOutputType[] outTypes = buildTools[i].getOutputTypes();
        if (outTypes != null && outTypes.length > 0) {
            for (int j = 0; j < outTypes.length; j++) {
                IOutputType outType = outTypes[j];
                // superclass with this id
                thisType: for (int k = 0; k < secondaryOutputs.length; k++) {
                    IOutputType matchType = outType;
                    do {
                        if (matchType.getId().equals(secondaryOutputs[k].getId())) {
                            buildVars.add(outType.getBuildVariable());
                            break thisType;
                        }
                        matchType = matchType.getSuperClass();
                    } while (matchType != null);
                }
            }
        }
    }
    return buildVars;
}
Also used : ArrayList(java.util.ArrayList) ITool(org.eclipse.cdt.managedbuilder.core.ITool) IOutputType(org.eclipse.cdt.managedbuilder.core.IOutputType)

Example 2 with IOutputType

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

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

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

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

the class ArduinoManagedBuildGnuToolInfo method calculateOutputs.

/*
	 * The priorities for determining the names of the outputs of a tool are: 1.
	 * If the tool is the build target and primary output, use artifact name &
	 * extension 2. If an option is specified, use the value of the option 3. If
	 * a nameProvider is specified, call it 4. If outputNames is specified, use
	 * it 5. Use the name pattern to generate a transformation macro so that the
	 * source names can be transformed into the target names using the built-in
	 * string substitution functions of <code>make</code>.
	 *
	 * NOTE: If an option is not specified and this is not the primary output
	 * type, the outputs from the type are not added to the command line
	 */
public boolean calculateOutputs(ArduinoGnuMakefileGenerator makeGen, IConfiguration config, HashSet<String> handledInputExtensions, boolean lastChance) {
    boolean done = true;
    Vector<String> myCommandOutputs = new Vector<>();
    Vector<String> myEnumeratedPrimaryOutputs = new Vector<>();
    Vector<String> myEnumeratedSecondaryOutputs = new Vector<>();
    HashMap<String, List<IPath>> myOutputMacros = new HashMap<>();
    // The next two fields are used together
    Vector<String> myBuildVars = new Vector<>();
    Vector<Vector<String>> myBuildVarsValues = new Vector<>();
    // Get the outputs for this tool invocation
    IOutputType[] outTypes = this.tool.getOutputTypes();
    if (outTypes != null && outTypes.length > 0) {
        for (int i = 0; i < outTypes.length; i++) {
            Vector<String> typeEnumeratedOutputs = new Vector<>();
            IOutputType type = outTypes[i];
            String outputPrefix = type.getOutputPrefix();
            if (config != null) {
                try {
                    outputPrefix = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(// $NON-NLS-1$
                    outputPrefix, // $NON-NLS-1$
                    "", // $NON-NLS-1$
                    " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, config);
                } catch (BuildMacroException e) {
                // JABA is not going to add
                // code
                }
            }
            String variable = type.getBuildVariable();
            boolean multOfType = type.getMultipleOfType();
            boolean primaryOutput = (type == this.tool.getPrimaryOutputType());
            IOption option = this.tool.getOptionBySuperClassId(type.getOptionId());
            IManagedOutputNameProvider nameProvider = type.getNameProvider();
            String[] outputNames = type.getOutputNames();
            // use artifact name & extension
            if (this.bIsTargetTool && primaryOutput) {
                String outputName = outputPrefix + this.targetName;
                if (this.targetExt.length() > 0) {
                    outputName += (DOT + this.targetExt);
                }
                myCommandOutputs.add(outputName);
                typeEnumeratedOutputs.add(outputName);
            // But this doesn't use any output macro...
            } else // 2. If an option is specified, use the value of the option
            if (option != null) {
                try {
                    List<String> outputs = new ArrayList<>();
                    int optType = option.getValueType();
                    if (optType == IOption.STRING) {
                        outputs.add(outputPrefix + 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> value = (List<String>) option.getValue();
                        outputs = value;
                        this.tool.filterValues(optType, outputs);
                        // Add outputPrefix to each if necessary
                        if (outputPrefix.length() > 0) {
                            for (int j = 0; j < outputs.size(); j++) {
                                outputs.set(j, outputPrefix + outputs.get(j));
                            }
                        }
                    }
                    for (int j = 0; j < outputs.size(); j++) {
                        String outputName = outputs.get(j);
                        try {
                            // try to resolve the build macros in the output
                            // names
                            String resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(// $NON-NLS-1$
                            outputName, // $NON-NLS-1$
                            "", // $NON-NLS-1$
                            " ", IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(option, this.tool));
                            if ((resolved = resolved.trim()).length() > 0)
                                outputs.set(j, resolved);
                        } catch (BuildMacroException e) {
                        // JABA is not
                        // going to add
                        // code
                        }
                    }
                    // NO - myCommandOutputs.addAll(outputs);
                    typeEnumeratedOutputs.addAll(outputs);
                    if (variable.length() > 0) {
                        List<IPath> outputPaths = new ArrayList<>();
                        for (int j = 0; j < outputs.size(); j++) {
                            outputPaths.add(Path.fromOSString(outputs.get(j)));
                        }
                        if (myOutputMacros.containsKey(variable)) {
                            List<IPath> currList = myOutputMacros.get(variable);
                            currList.addAll(outputPaths);
                            myOutputMacros.put(variable, currList);
                        } else {
                            myOutputMacros.put(variable, outputPaths);
                        }
                    }
                } catch (BuildException ex) {
                // JABA is not going to add
                // code
                }
            } else // 3. If a nameProvider is specified, call it
            if (nameProvider != null) {
                // The inputs must have been calculated before we can do
                // this
                IPath[] outNames = null;
                if (!this.inputsCalculated) {
                    done = false;
                } else {
                    Vector<String> inputs = getEnumeratedInputs();
                    IPath[] inputPaths = new IPath[inputs.size()];
                    for (int j = 0; j < inputPaths.length; j++) {
                        inputPaths[j] = Path.fromOSString(inputs.get(j));
                    }
                    // if (inputPaths.length == 0) {
                    try {
                        IManagedOutputNameProviderJaba newNameProvider = (IManagedOutputNameProviderJaba) nameProvider;
                        outNames = newNameProvider.getOutputNames(this.project, config, this.tool, inputPaths);
                    } catch (Exception e) {
                        // The provided class is not a
                        // IManagedOutputNameProviderJaba class;
                        Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "The provided class is not of type IManagedOutputNameProviderJaba", // $NON-NLS-1$
                        e));
                    }
                    // JABA end of insertion
                    if (outNames != null) {
                        for (int j = 0; j < outNames.length; j++) {
                            String outputName = outNames[j].toOSString();
                            try {
                                // try to resolve the build macros in the
                                // output names
                                String resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(// $NON-NLS-1$
                                outputName, // $NON-NLS-1$
                                "", // $NON-NLS-1$
                                " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, config);
                                if ((resolved = resolved.trim()).length() > 0) {
                                    outputName = resolved;
                                    outNames[j] = Path.fromOSString(resolved);
                                }
                            } catch (BuildMacroException e) {
                            // JABA is not
                            // going to add
                            // code
                            }
                            if (primaryOutput) {
                                myCommandOutputs.add(outputName);
                            }
                            typeEnumeratedOutputs.add(outputName);
                        }
                    }
                }
                if (variable.length() > 0 && outNames != null) {
                    if (myOutputMacros.containsKey(variable)) {
                        List<IPath> currList = myOutputMacros.get(variable);
                        currList.addAll(Arrays.asList(outNames));
                        myOutputMacros.put(variable, currList);
                    } else {
                        myOutputMacros.put(variable, new ArrayList<>(Arrays.asList(outNames)));
                    }
                }
            } else // 4. If outputNames is specified, use it
            if (outputNames != null) {
                if (outputNames.length > 0) {
                    for (int j = 0; j < outputNames.length; j++) {
                        String outputName = outputNames[j];
                        try {
                            // try to resolve the build macros in the output
                            // names
                            String resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(// $NON-NLS-1$
                            outputName, // $NON-NLS-1$
                            "", // $NON-NLS-1$
                            " ", IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(option, this.tool));
                            if ((resolved = resolved.trim()).length() > 0)
                                outputNames[j] = resolved;
                        } catch (BuildMacroException e) {
                        // JABA is not
                        // going to add
                        // code
                        }
                    }
                    List<String> namesList = Arrays.asList(outputNames);
                    if (primaryOutput) {
                        myCommandOutputs.addAll(namesList);
                    }
                    typeEnumeratedOutputs.addAll(namesList);
                    if (variable.length() > 0) {
                        List<IPath> outputPaths = new ArrayList<>();
                        for (int j = 0; j < namesList.size(); j++) {
                            outputPaths.add(Path.fromOSString(namesList.get(j)));
                        }
                        if (myOutputMacros.containsKey(variable)) {
                            List<IPath> currList = myOutputMacros.get(variable);
                            currList.addAll(outputPaths);
                            myOutputMacros.put(variable, currList);
                        } else {
                            myOutputMacros.put(variable, outputPaths);
                        }
                    }
                }
            } else {
                // <code>make</code>.
                if (multOfType) {
                    // This case is not handled - a nameProvider or
                    // outputNames must be specified
                    List<String> errList = new ArrayList<>();
                    // $NON-NLS-1$
                    errList.add(ManagedMakeMessages.getResourceString("MakefileGenerator.error.no.nameprovider"));
                    myCommandOutputs.addAll(errList);
                } else {
                    String namePattern = type.getNamePattern();
                    if (namePattern == null || namePattern.length() == 0) {
                        namePattern = outputPrefix + IManagedBuilderMakefileGenerator.WILDCARD;
                        String outExt = (type.getOutputExtensions(this.tool))[0];
                        if (outExt != null && outExt.length() > 0) {
                            namePattern += DOT + outExt;
                        }
                    } else if (outputPrefix.length() > 0) {
                        namePattern = outputPrefix + namePattern;
                    }
                    // this
                    if (!this.inputsCalculated) {
                        done = false;
                    } else {
                        Vector<String> inputs = getEnumeratedInputs();
                        String fileName;
                        if (inputs.size() > 0) {
                            // Get the input file name
                            fileName = (Path.fromOSString(inputs.get(0))).removeFileExtension().lastSegment();
                            // the raw macro name.
                            if (fileName.startsWith("$(") && fileName.endsWith(")")) {
                                // $NON-NLS-1$ //$NON-NLS-2$
                                fileName = fileName.substring(2, fileName.length() - 1);
                            }
                        } else {
                            // $NON-NLS-1$
                            fileName = "default";
                        }
                        // Replace the % with the file name
                        if (primaryOutput) {
                            // $NON-NLS-1$
                            myCommandOutputs.add(namePattern.replaceAll("%", fileName));
                        }
                        // $NON-NLS-1$
                        typeEnumeratedOutputs.add(namePattern.replaceAll("%", fileName));
                        if (variable.length() > 0) {
                            List<IPath> outputs = new ArrayList<>();
                            outputs.add(Path.fromOSString(fileName));
                            if (myOutputMacros.containsKey(variable)) {
                                List<IPath> currList = myOutputMacros.get(variable);
                                currList.addAll(outputs);
                                myOutputMacros.put(variable, currList);
                            } else {
                                myOutputMacros.put(variable, outputs);
                            }
                        }
                    }
                }
            }
            if (variable.length() > 0) {
                myBuildVars.add(variable);
                myBuildVarsValues.add(typeEnumeratedOutputs);
            }
            if (primaryOutput) {
                myEnumeratedPrimaryOutputs.addAll(typeEnumeratedOutputs);
            } else {
                myEnumeratedSecondaryOutputs.addAll(typeEnumeratedOutputs);
            }
        }
    } else {
        if (this.bIsTargetTool) {
            String outputPrefix = this.tool.getOutputPrefix();
            String outputName = outputPrefix + this.targetName;
            if (this.targetExt.length() > 0) {
                outputName += (DOT + this.targetExt);
            }
            myCommandOutputs.add(outputName);
            myEnumeratedPrimaryOutputs.add(outputName);
        } else {
        // For support of pre-CDT 3.0 integrations.
        // NOTE WELL: This only supports the case of a single
        // "target tool"
        // that consumes exactly all of the object files, $OBJS,
        // produced
        // by other tools in the build and produces a single output
        }
    }
    // Add the output macros of this tool to the buildOutVars map
    Set<Entry<String, List<IPath>>> entrySet = myOutputMacros.entrySet();
    for (Entry<String, List<IPath>> entry : entrySet) {
        String macroName = entry.getKey();
        List<IPath> newMacroValue = entry.getValue();
        Map<String, List<IPath>> map = makeGen.getBuildOutputVars();
        if (map.containsKey(macroName)) {
            List<IPath> macroValue = map.get(macroName);
            macroValue.addAll(newMacroValue);
            map.put(macroName, macroValue);
        } else {
            map.put(macroName, newMacroValue);
        }
    }
    this.outputVariablesCalculated = true;
    if (done) {
        this.commandOutputs.addAll(myCommandOutputs);
        this.enumeratedPrimaryOutputs.addAll(myEnumeratedPrimaryOutputs);
        this.enumeratedSecondaryOutputs.addAll(myEnumeratedSecondaryOutputs);
        this.outputVariables.addAll(myOutputMacros.keySet());
        this.outputsCalculated = true;
        for (int i = 0; i < myBuildVars.size(); i++) {
            makeGen.addMacroAdditionFiles(makeGen.getTopBuildOutputVars(), myBuildVars.get(i), myBuildVarsValues.get(i));
        }
        return true;
    }
    return false;
}
Also used : HashMap(java.util.HashMap) IOption(org.eclipse.cdt.managedbuilder.core.IOption) Entry(java.util.Map.Entry) BuildMacroException(org.eclipse.cdt.managedbuilder.macros.BuildMacroException) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector) IOutputType(org.eclipse.cdt.managedbuilder.core.IOutputType) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) OptionContextData(org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData) IPath(org.eclipse.core.runtime.IPath) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) BuildMacroException(org.eclipse.cdt.managedbuilder.macros.BuildMacroException) IManagedOutputNameProvider(org.eclipse.cdt.managedbuilder.core.IManagedOutputNameProvider) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException)

Aggregations

IOutputType (org.eclipse.cdt.managedbuilder.core.IOutputType)7 ArrayList (java.util.ArrayList)6 ITool (org.eclipse.cdt.managedbuilder.core.ITool)5 IPath (org.eclipse.core.runtime.IPath)4 List (java.util.List)3 BuildMacroException (org.eclipse.cdt.managedbuilder.macros.BuildMacroException)3 Entry (java.util.Map.Entry)2 BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)2 IInputType (org.eclipse.cdt.managedbuilder.core.IInputType)2 IManagedOutputNameProvider (org.eclipse.cdt.managedbuilder.core.IManagedOutputNameProvider)2 IOption (org.eclipse.cdt.managedbuilder.core.IOption)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Vector (java.util.Vector)1 CSourceEntry (org.eclipse.cdt.core.settings.model.CSourceEntry)1 ICSettingEntry (org.eclipse.cdt.core.settings.model.ICSettingEntry)1