Search in sources :

Example 1 with IConfiguration

use of org.eclipse.cdt.managedbuilder.core.IConfiguration in project linuxtools by eclipse.

the class CProjectBuildHelpers method isOptionCheckedInCDTTool.

/**
 * <h1>Check if an option is set</h1>
 * Same as {@link #isOptionCheckedInCDT(IProject project, String optionIDString) isOptionChecked_inCDT },
 * except you specify tool name manually. <br>
 *
 * (e.g you need to check something that's not supported in the implementation above.
 * @param project         the IProject project which will be read to check if it is c or cpp
 * @param optionIDString  for example <code> gnu.cpp.compiler.option.debugging.codecov </code>
 * @param toolSuperClassId  superclass id of the parent tool. see {@link #helperGetToolSuperClassId helper_GetToolSuperClassId}
 * @return                true if the option is set
 */
private static boolean isOptionCheckedInCDTTool(IProject project, String optionIDString, String toolSuperClassId) {
    IConfiguration activeConf = helperGetActiveConfiguration(project);
    // Get Compiler tool.
    ITool gccCompileriTool = helperGetGccCompilerToolBySuperClass(toolSuperClassId, activeConf);
    // (Get immutable option: This is like a 'template' that we will use to get the actual option)
    IOption optionTemplate = gccCompileriTool.getOptionById(optionIDString);
    // Check that we got a good option.
    if (optionTemplate == null) {
        MessageDialogSyncedRunnable.openErrorSyncedRunnable(ProfilingMessages.errorTitle, ProfilingMessages.errorGetOptionTemplate);
        return false;
    }
    // (Now we acquire the actual option from which we can read the value)
    try {
        IOption mutableOptionToSet = gccCompileriTool.getOptionToSet(optionTemplate, false);
        return (boolean) mutableOptionToSet.getValue();
    } catch (BuildException e) {
        // This is reached if the template that was provided was bad.
        MessageDialogSyncedRunnable.openErrorSyncedRunnable(ProfilingMessages.errorTitle, ProfilingMessages.errorGetOptionForWriting);
    }
    return false;
}
Also used : IOption(org.eclipse.cdt.managedbuilder.core.IOption) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) ITool(org.eclipse.cdt.managedbuilder.core.ITool)

Example 2 with IConfiguration

use of org.eclipse.cdt.managedbuilder.core.IConfiguration in project linuxtools by eclipse.

the class CProjectBuildHelpers method getProjectType.

/**
 * <h1>Finds out the type of the project as defined by {@link ProjectBuildType ProjectBuildType}.</h1>
 *
 * <p> A project can be of different types.<br>
 * Common types are:
 *  - Autotools<br>
 *  - Managed Make project<br>
 *  - Manual Makefiles<br></p>
 *
 * <p>
 * Some dialogues (initially in gCov and gProf) distinguish between these when displaying dialogues. This code is used
 * by these dialogues.
 * </p>
 *
 * <p>
 * The method was written with extensibility in mind. <br>
 * Other routines check for autotools/Managed make, and if those are not present, then it shows generic advice about
 * adding flags. MAKEFILE per-se isn't really checked. I.e this means that it should be safe to add additional
 * project types.
 * </p>
 *
 * @param project  project for which you want to get the type.
 * @return (enum)  projectType : <br>
 *         AUTO_TOOLS, <br>
 *         MANAGED_MAKEFILE, <br>
 *         OTHER <br>
 */
public static ProjectBuildType getProjectType(IProject project) {
    // Autotools has an 'Autotools' nature by which we can identify it.
    if (isAutoTools(project)) {
        return ProjectBuildType.AUTO_TOOLS;
    }
    IConfiguration defaultConfiguration = helperGetActiveConfiguration(project);
    IBuilder builder = defaultConfiguration.getBuilder();
    Boolean projIsManaged = builder.isManagedBuildOn();
    // MANAGED PROJECT
    if (projIsManaged) {
        return ProjectBuildType.MANAGED_MAKEFILE;
    } else {
        // E.g a manual makefile.
        return ProjectBuildType.OTHER;
    }
}
Also used : IBuilder(org.eclipse.cdt.managedbuilder.core.IBuilder) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Example 3 with IConfiguration

use of org.eclipse.cdt.managedbuilder.core.IConfiguration in project usbdm-eclipse-plugins by podonoghue.

the class CDTProjectManager method createUSBDMProject.

/**
 * Create USBDM CDT project
 *
 * @param paramMap      Parameters for project (from Wizard dialogue)
 * @param monitor       Progress monitor
 *
 * @return  Created project
 *
 * @throws Exception
 */
public IProject createUSBDMProject(Map<String, String> paramMap, IProgressMonitor progressMonitor) throws Exception {
    SubMonitor monitor = SubMonitor.convert(progressMonitor);
    // Create model project and accompanied descriptions
    IProject project;
    try {
        monitor.beginTask("Create configuration", 100);
        String projectName = MacroSubstitute.substitute(paramMap.get(UsbdmConstants.PROJECT_NAME_KEY), paramMap);
        String directoryPath = MacroSubstitute.substitute(paramMap.get(UsbdmConstants.PROJECT_HOME_PATH_KEY), paramMap);
        String projectType = MacroSubstitute.substitute(paramMap.get(UsbdmConstants.PROJECT_OUTPUT_TYPE_KEY), paramMap);
        InterfaceType interfaceType = InterfaceType.valueOf(paramMap.get(UsbdmConstants.INTERFACE_TYPE_KEY));
        boolean hasCCNature = Boolean.valueOf(paramMap.get(UsbdmConstants.HAS_CC_NATURE_KEY));
        String artifactName = MacroSubstitute.substitute(paramMap.get(UsbdmConstants.PROJECT_ARTIFACT_KEY), paramMap);
        if ((artifactName == null) || (artifactName.length() == 0)) {
            artifactName = "${ProjName}";
        }
        project = createProject(projectName, directoryPath, hasCCNature, monitor.newChild(70));
        CoreModel coreModel = CoreModel.getDefault();
        // Create project description
        ICProjectDescription projectDescription = coreModel.createProjectDescription(project, false);
        Assert.isNotNull(projectDescription, "createProjectDescription returned null");
        // Create one configuration description
        ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
        IProjectType type = ManagedBuildManager.getProjectType(projectType);
        Assert.isNotNull(type, "project type not found");
        ManagedProject mProj = new ManagedProject(project, type);
        info.setManagedProject(mProj);
        IConfiguration[] cfgs = type.getConfigurations();
        Assert.isNotNull(cfgs, "configurations not found");
        Assert.isTrue(cfgs.length > 0, "no configurations found in the project type");
        String configurationName = null;
        String os = System.getProperty("os.name");
        switch(interfaceType) {
            case T_ARM:
                configurationName = ARM_CONFIGURATION_ID;
                break;
            case T_CFV1:
            case T_CFVX:
                configurationName = COLDFIRE_CONFIGURATION_ID;
                break;
        }
        for (IConfiguration configuration : cfgs) {
            String configId = configuration.getId();
            if (!configId.startsWith(configurationName)) {
                continue;
            }
            String id = ManagedBuildManager.calculateChildId(configuration.getId(), null);
            Configuration config = new Configuration(mProj, (Configuration) configuration, id, false, true, false);
            config.setArtifactName(artifactName);
            CConfigurationData data = config.getConfigurationData();
            Assert.isNotNull(data, "data is null for created configuration");
            projectDescription.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
        }
        Assert.isTrue(projectDescription.getConfigurations().length > 0, "No Configurations!");
        coreModel.setProjectDescription(project, projectDescription);
        // }
        if (!(hasCCNature && !project.hasNature(CCProjectNature.CC_NATURE_ID))) {
            CCProjectNature.addCCNature(project, monitor.newChild(5));
        }
        CoreModel.getDefault().updateProjectDescriptions(new IProject[] { project }, monitor);
        if (!(hasCCNature && !project.hasNature(CCProjectNature.CC_NATURE_ID))) {
            CCProjectNature.addCCNature(project, monitor.newChild(5));
        }
    } finally {
        monitor.done();
    }
    return project;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) Configuration(org.eclipse.cdt.managedbuilder.internal.core.Configuration) IProjectType(org.eclipse.cdt.managedbuilder.core.IProjectType) SubMonitor(org.eclipse.core.runtime.SubMonitor) CConfigurationData(org.eclipse.cdt.core.settings.model.extension.CConfigurationData) IProject(org.eclipse.core.resources.IProject) InterfaceType(net.sourceforge.usbdm.constants.UsbdmSharedConstants.InterfaceType) CoreModel(org.eclipse.cdt.core.model.CoreModel) ManagedBuildInfo(org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo) ManagedProject(org.eclipse.cdt.managedbuilder.internal.core.ManagedProject) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Example 4 with IConfiguration

use of org.eclipse.cdt.managedbuilder.core.IConfiguration in project usbdm-eclipse-plugins by podonoghue.

the class DisassembleCFileHandler method execute.

// public static void pipeStream(InputStream input, OutputStream output)
// throws IOException {
// 
// byte buffer[] = new byte[1024];
// int numRead = 0;
// 
// while (input.available() > 0) {
// numRead = input.read(buffer);
// output.write(buffer, 0, numRead);
// }
// output.flush();
// }
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String os = System.getProperty("os.name");
    boolean isLinux = (os != null) && os.toUpperCase().contains("LINUX");
    Object source = HandlerUtil.getCurrentSelection(event);
    // System.err.println("Event source = "+source.toString()+"\n class = "+source.getClass().toString());
    if (!(source instanceof TreeSelection)) {
        // System.err.println("Source is not an instance of TreeSelection");
        return null;
    }
    TreeSelection selection = (TreeSelection) source;
    if (!(selection.getFirstElement() instanceof IBinary)) {
        // System.err.println("Selection.getFirstElement() is not an instance of org.eclipse.cdt.core.model.IBinary");
        return null;
    }
    IBinary binary = (IBinary) selection.getFirstElement();
    IResource resource = binary.getUnderlyingResource();
    IPath resourcePath = resource.getLocation();
    IPath dissassemblyPath = resourcePath.removeFileExtension().addFileExtension("lis");
    // Get Environment (path etc)
    CoreModel cdtCoreModel = org.eclipse.cdt.core.model.CoreModel.getDefault();
    ICProjectDescription cProjectDescription = cdtCoreModel.getProjectDescription(resource.getProject());
    ICConfigurationDescription cConfigurationDescription = cProjectDescription.getActiveConfiguration();
    IContributedEnvironment contributedEnvironment = CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment();
    IEnvironmentVariable[] environmentVariablesArray = contributedEnvironment.getVariables(cConfigurationDescription);
    HashMap<String, String> environmentMap = new HashMap<String, String>();
    for (IEnvironmentVariable ev : environmentVariablesArray) {
        String name = ev.getName();
        if ((!isLinux) && name.equals("PATH")) {
            name = "Path";
        }
        // System.err.println("Adding Environment variable: "+name+" => "+ev.getValue());
        environmentMap.put(name, ev.getValue());
    }
    // String resourceName = resource.getName();
    // System.err.println("resourceName = "+resourceName);
    IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(resource);
    IConfiguration configuration = buildInfo.getDefaultConfiguration();
    // System.err.println("configuration = "+configuration);
    // Find lister tool in configuration
    ITool[] toolArray = configuration.getTools();
    ITool tool = null;
    for (ITool t : toolArray) {
        Pattern p = Pattern.compile("net\\.sourceforge\\.usbdm\\.cdt\\..*\\.toolchain\\.lister\\..*");
        if (p.matcher(t.getId()).matches()) {
            tool = configuration.getTool(t.getId());
            break;
        }
    }
    if (tool == null) {
        return null;
    }
    // System.err.println("tool.getName = "+tool.getName());
    // System.err.println("tool.getToolCommand = "+tool.getToolCommand());
    // Get command line generator
    IManagedCommandLineGenerator commandLineGenerator = tool.getCommandLineGenerator();
    // Get command line
    try {
        String[] inputs = { resourcePath.lastSegment() };
        IManagedCommandLineInfo commandLineInfo = commandLineGenerator.generateCommandLineInfo(tool, tool.getToolCommand(), tool.getToolCommandFlags(resourcePath, dissassemblyPath), "", ">", dissassemblyPath.lastSegment(), inputs, "${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}");
        // System.err.println("cl.toString() = "+commandLineInfo.toString());
        // System.err.println("cl.getCommandLine() = "+commandLineInfo.getCommandLine());
        String[] commandArray = null;
        if (isLinux) {
            // Construct command (Use cmd for PATH changes!)
            ArrayList<String> command = new ArrayList<String>(20);
            command.add("/bin/sh");
            command.add("-c");
            command.add(commandLineInfo.getCommandLine());
            commandArray = (String[]) command.toArray(new String[command.size()]);
        } else {
            // Construct command (Use cmd for PATH changes!)
            ArrayList<String> command = new ArrayList<String>(20);
            command.add("cmd.exe");
            command.add("/C");
            command.add(commandLineInfo.getCommandLine());
            commandArray = (String[]) command.toArray(new String[command.size()]);
        }
        // Run command
        // System.err.println("Running...");
        ProcessBuilder pb = new ProcessBuilder(commandArray);
        pb.environment().putAll(environmentMap);
        File commandFile = findExecutableOnPath(pb.environment().get("PATH"), commandLineInfo.getCommandName());
        if (commandFile != null) {
        // System.err.println("commandFile.toPath() = "+ commandFile.toPath());
        // System.err.println("pwd = "+ resourcePath.removeLastSegments(1).toFile());
        }
        // System.err.println("=================== Environment variables ===================");
        // for (String envName : pb.environment().keySet()) {
        // System.err.println("Environment variable: "+envName+" => "+pb.environment().get(envName));
        // }
        // System.err.println("=================== End of Environment variables ===================");
        pb.redirectInput(Redirect.INHERIT);
        pb.redirectError(Redirect.INHERIT);
        pb.redirectOutput(Redirect.INHERIT);
        pb.directory(resourcePath.removeLastSegments(1).toFile());
        // System.err.println("WD =" + pb.directory());
        Process p = pb.start();
        // System.err.println("Waiting...");
        p.waitFor();
    // System.err.println("Exit value = " + p.waitFor());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (BuildException e) {
        e.printStackTrace();
    }
    try {
        // Refresh parent directory so file is visible
        resource.getParent().refreshLocal(1, null);
    } catch (CoreException e) {
        e.printStackTrace();
    }
    try {
        // Open disassembled file in editor
        IPath asmPath = resource.getFullPath().removeFileExtension().addFileExtension("lis");
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IDE.openEditor(page, ResourcesPlugin.getWorkspace().getRoot().getFile(asmPath));
    } catch (PartInitException e) {
        e.printStackTrace();
    }
    // System.err.println("Completed");
    return null;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeSelection(org.eclipse.jface.viewers.TreeSelection) PartInitException(org.eclipse.ui.PartInitException) Pattern(java.util.regex.Pattern) IPath(org.eclipse.core.runtime.IPath) IManagedCommandLineGenerator(org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator) IBinary(org.eclipse.cdt.core.model.IBinary) IOException(java.io.IOException) ITool(org.eclipse.cdt.managedbuilder.core.ITool) IContributedEnvironment(org.eclipse.cdt.core.envvar.IContributedEnvironment) IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) CoreException(org.eclipse.core.runtime.CoreException) IManagedCommandLineInfo(org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo) CoreModel(org.eclipse.cdt.core.model.CoreModel) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEnvironmentVariable(org.eclipse.cdt.core.envvar.IEnvironmentVariable) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 5 with IConfiguration

use of org.eclipse.cdt.managedbuilder.core.IConfiguration in project usbdm-eclipse-plugins by podonoghue.

the class ProjectUtilities method changeExcludedItem.

private static void changeExcludedItem(IProject project, String targetPath, boolean isFolder, boolean excluded, IProgressMonitor progressMonitor) throws CoreException, BuildException {
    IPath path = project.getFolder(targetPath).getProjectRelativePath();
    System.err.println(String.format("changeExcludedItem(target=%s, isfolder=%s, exclude=%s)", path.toString(), Boolean.toString(isFolder), Boolean.toString(excluded)));
    // ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project, true);
    // ICConfigurationDescription configDecriptions[] = projectDescription.getConfigurations();
    // for (ICConfigurationDescription configDescription : configDecriptions) {
    // // Exclude in each configuration
    // System.err.println(String.format("Excluding in configuration %s", configDescription.toString()));
    // ICSourceEntry[] sourceEntries         = configDescription.getSourceEntries();
    // ICSourceEntry[] modifiedSourceEntries = CDataUtil.setExcludedIfPossible(path, isFolder, excluded, sourceEntries);
    // configDescription.setSourceEntries(modifiedSourceEntries);
    // }
    // CoreModel.getDefault().setProjectDescription(project, projectDescription);
    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    IConfiguration[] configurations = info.getManagedProject().getConfigurations();
    for (IConfiguration configuration : configurations) {
        // Exclude in each configuration
        System.err.println(String.format("Excluding in configuration %s", configuration.toString()));
        ICSourceEntry[] sourceEntries = configuration.getSourceEntries();
        ICSourceEntry[] modifiedSourceEntries = CDataUtil.setExcludedIfPossible(path, isFolder, excluded, sourceEntries);
        configuration.setSourceEntries(modifiedSourceEntries);
    }
}
Also used : IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) IPath(org.eclipse.core.runtime.IPath) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Aggregations

IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)27 ITool (org.eclipse.cdt.managedbuilder.core.ITool)11 IOption (org.eclipse.cdt.managedbuilder.core.IOption)9 IToolChain (org.eclipse.cdt.managedbuilder.core.IToolChain)9 IManagedBuildInfo (org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo)6 BuildException (org.eclipse.cdt.managedbuilder.core.BuildException)5 CoreException (org.eclipse.core.runtime.CoreException)5 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)4 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)4 IFolderInfo (org.eclipse.cdt.managedbuilder.core.IFolderInfo)4 BuildConfigurationData (org.eclipse.cdt.managedbuilder.internal.dataprovider.BuildConfigurationData)4 ArrayList (java.util.ArrayList)3 ToolInformationData (net.sourceforge.usbdm.constants.ToolInformationData)3 IPath (org.eclipse.core.runtime.IPath)3 UsbdmSharedSettings (net.sourceforge.usbdm.constants.UsbdmSharedSettings)2 CoreModel (org.eclipse.cdt.core.model.CoreModel)2 CConfigurationData (org.eclipse.cdt.core.settings.model.extension.CConfigurationData)2 IBuilder (org.eclipse.cdt.managedbuilder.core.IBuilder)2 IManagedProject (org.eclipse.cdt.managedbuilder.core.IManagedProject)2 Configuration (org.eclipse.cdt.managedbuilder.internal.core.Configuration)2