[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to set include paths programmatically?

Hi,

I'm interested in this too. Currently I'm using Eclipse3.4.2 and CDT5.0.2.

I have the facility to start a debug session in Eclipse from a command line, by specifying the desired executable file (built outside of Eclipse with a makefile) and a buildlog file. I then use the buildlog, which consists of compilation lines containing -D (macros) and -I (includes) directives and wire this into Project properties > C/C++ Build > Discovery Options > "Load build output from file" ( Scanner Configuration Discovery Profile org.eclipse.cdt.make.core.ScannerConfigurationDiscoveryProfile). The starting point for this in my code is useBuildOutput() below.

I get to the point where the "Load build output from file" text field is populated and a Load is done, but the equivalent of the user pressing Apply or OK is not done - this is the thing I'm still missing.

I'll shortly be migrating to use Galileo which I believe has improved support for includes and macros using some kind of heuirstics ??? collection. I'm looking forward to the situation being eased with this, but would still like to get my automatic build log thing working.

Once Eclipse has an accurate list of includes and macros any conditional compilation sections in your code (lots in our users') source editing really comes into its own with delightful features like highlighting inactive code and folding etc which really improve legibility.

Sorry for the hijack if this is not what you meant.

cheers john




    private void useBuildOutput(IProject project) {
        String buildOutputFilePath = getBuildOutputFilePath();
        if(!buildOutputFilePath.isEmpty()) {
            /*
             * Populate the Project properties > C/C++ Build > Discovery Options > "Load build output from file" text field
             * with the filename specified with -buildlog.
             */
            IScannerConfigBuilderInfo2 buildInfo = setScannerConfigBuildOutput(project, buildOutputFilePath);

            /*
             * "Push" the Load button
             */
            performBuildOutputLoad(project, buildInfo);
            
            /*
             * Equivalent of PerformOK to consolidate the new build output scanner info and update the
             * project properties > C/C++ General > Paths and symbols > Includes and Symbols tabs
             */
            // TODO: complete this step. Currently don't know how to!
            updateSC(project, buildInfo);

            /*
             * Display the includes and macros in the execute from command line log.
             * TODO: it would be good just to display the ones we've added rather than the whole lot.
             */
            //logIncludePathsAndMacros(project);
        }
    }

    /*
     * Copied fragements from
     * org.eclipse.cdt.build.core.scannerconfig.ScannerConfigNature.initializeDiscoveryOptions
     * This was commented out with a FIXME warning.
     */
    public IScannerConfigBuilderInfo2 setScannerConfigBuildOutput(IProject project, String buildOutputFilePath) {
        IScannerConfigBuilderInfo2 buildInfo = null;
        try {
            /*
             * Choose the correct profile to use dependent on language; C | CPP.
             * TODO: detect language from the project or active configuration and architecture (st40/st200).
             */
            String profileId = MY_SCANNER_CONFIG_DISCOVERY_PROFILE_ID_C;
            
            buildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(project, profileId);
            buildInfo.setAutoDiscoveryEnabled(true);
            buildInfo.setProblemReportingEnabled(true);
            buildInfo.setBuildOutputParserEnabled(true);
            buildInfo.setBuildOutputFileActionEnabled(true);
            buildInfo.setBuildOutputFilePath(buildOutputFilePath);
            buildInfo.save();
        }
        catch (CoreException e) {
            e.printStackTrace();
            ManagedBuilderCorePlugin.log(e);
        }
        return buildInfo;
    }    
    
    private void performBuildOutputLoad(IProject project, IScannerConfigBuilderInfo2 buildInfo) {
        Job readerJob = new BuildOutputReaderJob(project, buildInfo);        
        readerJob.setPriority(Job.LONG);
        readerJob.schedule();
    }    

    private boolean updateSC(IProject project, IScannerConfigBuilderInfo2 buildInfo) {
        boolean result = false;

        result = SCJobsUtil.readBuildOutputFile(project, buildInfo, null);
        result = SCJobsUtil.getProviderScannerInfo(project, buildInfo, null);
        result = SCJobsUtil.updateScannerConfiguration(project, buildInfo, null);

        Workspace myworkspace = (Workspace) project.getWorkspace();
        myworkspace.broadcastPostChange();        
        try {
            buildInfo.save();
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result;
    }



Purely for debugging I can observe the includes and macros that have been set using this:

    private void logIncludePathsAndMacros(IProject project) {
        ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project);
        ICConfigurationDescription activeConfiguration = projectDescription.getActiveConfiguration(); // or another config
        ICFolderDescription folderDescription = activeConfiguration.getRootFolderDescription(); // or use getResourceDescription(IResource), or pick one from getFolderDescriptions()
        ICLanguageSetting[] languageSettings = folderDescription.getLanguageSettings();
        int id = 0;
        for(int i=0; i<languageSettings.length; i++) {
            String langId = languageSettings[i].getLanguageId();
            if(langId.contains("org.eclipse.cdt.core.gcc")) {
                id = i;
                break;
            }
        }
        ICLanguageSetting lang = languageSettings[id];

        /*
         * display includes
         */
        ICLanguageSettingEntry[] includePathSettings = lang.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
        writeToConsole("Project includes paths:");
        for(int i=0; i<includePathSettings.length; i++) {
            String ip = includePathSettings[i].toString();
            writeToConsole(ip);
        }
        
        /*
         * display macros
         */
        ICLanguageSettingEntry[] macroSettings = lang.getSettingEntries(ICSettingEntry.MACRO);

        writeToConsole("\nProject macros:");
        for(int i=0; i<macroSettings.length; i++) {
            String ip = macroSettings[i].toString();
            writeToConsole(ip);
        }
    }    




On 25/02/2010 08:53, George Russell wrote:
Hi all,

I am wondering how I can set the CDT's include paths either programmatically or in a configuration file?

At the moment, the include lines of source files are reported as warnings in the CDT editor, and I'd like to avoid forcing users to set up paths manually when it can be automated or pre-set.

Regards,
George

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev

-- 
      john moule
      software engineer
      stmicroelectronics ltd
      1000 aztec west
      bristol bs32 4sq
      uk
   t  +44 (0)1454 462481
TINA  065 2481