Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "CDT/Developer/FAQ"

< CDT
m (Question)
(Extending CDT)
(39 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
== General ==
 
== General ==
  
* Is it fun writing code for the CDT?
+
=== Is it fun writing code for the CDT? ===
  
 
You betcha! And the Eclipse SDK is such a great environment to work in. We've pumped out quality code by the boat load without a lot of effort.
 
You betcha! And the Eclipse SDK is such a great environment to work in. We've pumped out quality code by the boat load without a lot of effort.
 +
 +
* Before you contribute, try reading [http://cdtdoug.blogspot.com/2008/02/code-like-you-wont-be-there-tomorrow.html Code like you won't be there tomorrow]
 +
 +
== Getting the source ==
 +
 +
=== How can I contribute to CDT? ===
 +
See '[[Getting started with CDT development]]', '[[CDT/contributing]]', '[[CDT/git]]'
 +
* [[EGit/User_Guide]] contains the egit documentation and information on getting started with git.
 +
* [[Git for Committers]] details using git in the Eclipse development process.  This document describes how to use git to maintain your own development lines and use the tools to generate patches for upstream submission.
  
 
== Release Engineering ==
 
== Release Engineering ==
  
* Where can I get the latest builds?
+
=== Where can I get the latest builds? ===
  
 
We have a build machine, [http://cdt.eclipse.org cdt.eclipse.org], that we use for our builds. You can access them from the builds section on its home page. You can also generate your own builds by checking out the CDT out of CVS and using the Export -> Deployable Feature menu item provided by the PDE.
 
We have a build machine, [http://cdt.eclipse.org cdt.eclipse.org], that we use for our builds. You can access them from the builds section on its home page. You can also generate your own builds by checking out the CDT out of CVS and using the Export -> Deployable Feature menu item provided by the PDE.
  
== Question ==
+
== Extending CDT ==
 +
Besides these FAQ, you may also see [https://wiki.eclipse.org/CDT/Developer/Code_Snippets Common code snippet]
  
* Can I find a method declare when my mouse point to a method for the CDT?
+
=== How can I programmatically create a new CDT project? ===
If you have a method selected in the Editor, pressing F3 will take you to the declaration (i.e. the ''prototype'') and Ctrl-F3 with take you to the definition (i.e. the ''body''). Both options are also available from the Context menu.
+
  
* Howto add menu items, submenu to CDT ''Source'' popup?
+
Check out those:
[http://wiki.eclipse.org/CDT/Developer/FAQ/popupMenu howto]
+
* ResourceHelper.createCDTProject(...) in plugin org.eclipse.cdt.core.tests
 +
* ManagedBuildTestHelper.createProject(...) in org.eclipse.cdt.managedbuilder.core.tests
 +
* BuildSystemTestHelper.createProject(...) in org.eclipse.cdt.managedbuilder.core.tests
 +
* CProjectDescriptionSerializationTests in org.eclipse.cdt.managedbuilder.core.tests
 +
They sport a few flavors of creating CDT projects.
  
== More? ==
+
=== How to substitute build variables in a string? ===
 +
You can use CdtVariableManager which will resolve environment variables, build variables, and eclipse variables:
  
Many more questions are answered in the "Working on the CDT" section of the  [http://wiki.eclipse.org/CDT/User/FAQ#Working_on_the_CDT general CDT FAQ].
+
<source lang="java">
 +
ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager();
 +
String resolvedValue = varManager.resolveValue(value, "", null, cfgDescription);
 +
</source>
  
See also the [http://cdt-devel-faq.wikidot.com unofficial CDT Developers FAQ].
+
=== How can I programmatically set an option in the project settings? ===
 +
Moved here: [https://wiki.eclipse.org/CDT/Developer/Code_Snippets#Programmatically_set_an_option_in_the_project_settings Code Snippets]
 +
 
 +
=== How do I contribute Include/Library paths or Macros to a project configuration using LanguageSettingsProvider extension point? ===
 +
 
 +
# Implement interface '''ILanguageSettingsProvider''' in your plugin. Most commonly:
 +
#* If you need to parse build output - extend '''AbstractBuildCommandParser''' (or even '''GCCBuildCommandParser''');
 +
#* If you need to run external program, perhaps on some event, and parse its output - extend '''ToolchainBuiltinSpecsDetector''' (or '''AbstractBuiltinSpecsDetector''');
 +
#* If you need a simple one just to persist the entries (and optionally edit them) - use '''LanguageSettingsGenericProvider'''. Typically there is no need to extend it, just use this class. If you really really need to extend - copy its implementation and start with that;
 +
#* for special logic that does not fit above - extend '''LanguageSettingsBaseProvider'''.
 +
# Add extension of '''org.eclipse.cdt.core.LanguageSettingsProvider''' extension point and specify your provider in "class" attribute.
 +
# In order to get providers created for new projects with New Project Wizard - use '''org.eclipse.cdt.managedbuilder.core.buildDefinitions''' extension point to associate the provider with your project type. Specify attribute "languageSettingsProviders" for element "configuration" or "toolchain". There is a brief description in the extension point schema which may be useful.
 +
# There is one more extension point '''org.eclipse.cdt.ui.LanguageSettingsProviderAssociation'''. You can define there a custom icon, allow or disallow editing in UI and provide a custom page for editing options in Options pane.
 +
 
 +
For more details see JavaDoc for '''ILanguageSettingsProvider''' and other classes. There is a number of providers implemented that way in CDT. Search plugin.xml files to find out how extensions of '''org.eclipse.cdt.core.LanguageSettingsProvider''' extension point are implemented.
 +
 
 +
=== How do I contribute Include/Library paths or Macros to a project configuration using externalSettingsProvider extension point? ===
 +
The external Settings Provider extension point can be used to register a build settings provider and have it dynamically called back at your own control.  You can use this to contribute paths to your build configuration, making decisions at runtime on what should be added.
 +
 
 +
# Use the org.eclipse.cdt.core.externalSettingsProvider extension point, give it an "ID"
 +
# Create a 'provider' element pointing at a class that extends CExternalSettingProvider
 +
# Register the class on your CDT projects by adding your settingsProvider ID to the configuration descriptions list of settings providers:
 +
##externalSettingsProviders = new LinkedHashSet<String>(Arrays.asList(ICConfigurationDescription.getExternalSettingsProviderIds()));
 +
##extSettings.add(ID)
 +
##ICConfigurationDescription.setExternalSettingsProviderIds(externalSettingsProviders.toArray(new String[0]));
 +
# You will get a call-back on:
 +
##public CExternalSetting[] getSettings(IProject project, ICConfigurationDescription cfgd) {
 +
# which allows you to return appropriate macros and includes for the given configuration desc.
 +
# CDT will cache this response, when there is a configuration change which may require a change to your settings, you should call:
 +
##cfgd.updateExternalSettingsProviders(new String[] {ID});
 +
 
 +
[https://bugs.eclipse.org/bugs/show_bug.cgi?id=222738 Bug 222738] has an attachment with a sample plugin employing this technique. You can download it to get started.
 +
 
 +
=== How to add new make targets in the "Make Target" view? ===
 +
 
 +
Something like that could do the trick:
 +
 
 +
<source lang="java">
 +
IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager();
 +
String[] ids = manager.getTargetBuilders(project);
 +
IMakeTarget target = manager.createTarget(project, "name", ids[0]);
 +
target.setStopOnError(false);
 +
target.setRunAllBuilders(false);
 +
target.setUseDefaultBuildCmd(true);
 +
target.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, "make");
 +
target.setBuildAttribute(IMakeTarget.BUILD_LOCATION, "/build/location");
 +
target.setBuildAttribute(IMakeTarget.BUILD_ARGUMENTS, "args");
 +
target.setBuildAttribute(IMakeTarget.BUILD_TARGET, "target");
 +
manager.addTarget(container, target);
 +
</source>
 +
 
 +
container here is a subfolder in the project where you wish to place the target.
 +
 
 +
=== I developed my own property page but my changes to configuration description are not being saved or being reversed. They are only saved if Cancel button is pressed? It's puzzling. ===
 +
 
 +
This happens because when user opens project properties CDT gets its own writeable configuration description to work with. If you get your own copy after that and save it it is going to be overwritten by that CDT configuration when user uses Apply or OK buttons. You need to apply your changes to that CDT configuration. You can get hold of it using call getResDesc() provided that your page extends AbstractCPropertyTab.
 +
 
 +
===  Writing to a Console in Eclipse ===
 +
[http://www.jevon.org/wiki/Writing_to_a_Console_in_Eclipse See solution based on MessageConsole]
 +
 
 +
=== Am I headless? ===
 +
[http://aniszczyk.org/2007/07/24/am-i-headless/ See solution based on Platform & PlatformUI]
 +
 
 +
== Hints ==
 +
 
 +
=== Can I find a method declare when my mouse point to a method for the CDT? ===
 +
If you have a method selected in the Editor, pressing F3 will take you to the declaration (i.e. the ''prototype'') and Ctrl-F3 with take you to the definition (i.e. the ''body''). Both options are also available from the Context menu.
 +
 
 +
 
 +
== More? ==
 +
* [https://wiki.eclipse.org/CDT/Developer/Code_Snippets Code Snippets] Snippets of code that are useful for cdt development. 
 +
* [http://wiki.eclipse.org/CDT/User/FAQ#Working_on_the_CDT CDT User FAQ] answers many more questions in the section "Working on the CDT".
 +
* [http://cdt-devel-faq.wikidot.com Andras Varga's CDT Developers FAQ] - unofficial but actually more solid FAQ. 
 +
* [http://wiki.eclipse.org/index.php/CDT CDT Wiki page] provides assorted collection of links.
  
 
[[Category:CDT]]
 
[[Category:CDT]]
 +
[[Category:FAQ]]

Revision as of 15:01, 15 October 2014

General

Is it fun writing code for the CDT?

You betcha! And the Eclipse SDK is such a great environment to work in. We've pumped out quality code by the boat load without a lot of effort.

Getting the source

How can I contribute to CDT?

See 'Getting started with CDT development', 'CDT/contributing', 'CDT/git'

  • EGit/User_Guide contains the egit documentation and information on getting started with git.
  • Git for Committers details using git in the Eclipse development process. This document describes how to use git to maintain your own development lines and use the tools to generate patches for upstream submission.

Release Engineering

Where can I get the latest builds?

We have a build machine, cdt.eclipse.org, that we use for our builds. You can access them from the builds section on its home page. You can also generate your own builds by checking out the CDT out of CVS and using the Export -> Deployable Feature menu item provided by the PDE.

Extending CDT

Besides these FAQ, you may also see Common code snippet

How can I programmatically create a new CDT project?

Check out those:

  • ResourceHelper.createCDTProject(...) in plugin org.eclipse.cdt.core.tests
  • ManagedBuildTestHelper.createProject(...) in org.eclipse.cdt.managedbuilder.core.tests
  • BuildSystemTestHelper.createProject(...) in org.eclipse.cdt.managedbuilder.core.tests
  • CProjectDescriptionSerializationTests in org.eclipse.cdt.managedbuilder.core.tests

They sport a few flavors of creating CDT projects.

How to substitute build variables in a string?

You can use CdtVariableManager which will resolve environment variables, build variables, and eclipse variables:

	ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager();
	String resolvedValue = varManager.resolveValue(value, "", null, cfgDescription);

How can I programmatically set an option in the project settings?

Moved here: Code Snippets

How do I contribute Include/Library paths or Macros to a project configuration using LanguageSettingsProvider extension point?

  1. Implement interface ILanguageSettingsProvider in your plugin. Most commonly:
    • If you need to parse build output - extend AbstractBuildCommandParser (or even GCCBuildCommandParser);
    • If you need to run external program, perhaps on some event, and parse its output - extend ToolchainBuiltinSpecsDetector (or AbstractBuiltinSpecsDetector);
    • If you need a simple one just to persist the entries (and optionally edit them) - use LanguageSettingsGenericProvider. Typically there is no need to extend it, just use this class. If you really really need to extend - copy its implementation and start with that;
    • for special logic that does not fit above - extend LanguageSettingsBaseProvider.
  2. Add extension of org.eclipse.cdt.core.LanguageSettingsProvider extension point and specify your provider in "class" attribute.
  3. In order to get providers created for new projects with New Project Wizard - use org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point to associate the provider with your project type. Specify attribute "languageSettingsProviders" for element "configuration" or "toolchain". There is a brief description in the extension point schema which may be useful.
  4. There is one more extension point org.eclipse.cdt.ui.LanguageSettingsProviderAssociation. You can define there a custom icon, allow or disallow editing in UI and provide a custom page for editing options in Options pane.

For more details see JavaDoc for ILanguageSettingsProvider and other classes. There is a number of providers implemented that way in CDT. Search plugin.xml files to find out how extensions of org.eclipse.cdt.core.LanguageSettingsProvider extension point are implemented.

How do I contribute Include/Library paths or Macros to a project configuration using externalSettingsProvider extension point?

The external Settings Provider extension point can be used to register a build settings provider and have it dynamically called back at your own control. You can use this to contribute paths to your build configuration, making decisions at runtime on what should be added.

  1. Use the org.eclipse.cdt.core.externalSettingsProvider extension point, give it an "ID"
  2. Create a 'provider' element pointing at a class that extends CExternalSettingProvider
  3. Register the class on your CDT projects by adding your settingsProvider ID to the configuration descriptions list of settings providers:
    1. externalSettingsProviders = new LinkedHashSet<String>(Arrays.asList(ICConfigurationDescription.getExternalSettingsProviderIds()));
    2. extSettings.add(ID)
    3. ICConfigurationDescription.setExternalSettingsProviderIds(externalSettingsProviders.toArray(new String[0]));
  4. You will get a call-back on:
    1. public CExternalSetting[] getSettings(IProject project, ICConfigurationDescription cfgd) {
  5. which allows you to return appropriate macros and includes for the given configuration desc.
  6. CDT will cache this response, when there is a configuration change which may require a change to your settings, you should call:
    1. cfgd.updateExternalSettingsProviders(new String[] {ID});

Bug 222738 has an attachment with a sample plugin employing this technique. You can download it to get started.

How to add new make targets in the "Make Target" view?

Something like that could do the trick:

	IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager();
	String[] ids = manager.getTargetBuilders(project);
	IMakeTarget target = manager.createTarget(project, "name", ids[0]);
	target.setStopOnError(false);
	target.setRunAllBuilders(false);
	target.setUseDefaultBuildCmd(true);
	target.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, "make");
	target.setBuildAttribute(IMakeTarget.BUILD_LOCATION, "/build/location");
	target.setBuildAttribute(IMakeTarget.BUILD_ARGUMENTS, "args");
	target.setBuildAttribute(IMakeTarget.BUILD_TARGET, "target");
	manager.addTarget(container, target);

container here is a subfolder in the project where you wish to place the target.

I developed my own property page but my changes to configuration description are not being saved or being reversed. They are only saved if Cancel button is pressed? It's puzzling.

This happens because when user opens project properties CDT gets its own writeable configuration description to work with. If you get your own copy after that and save it it is going to be overwritten by that CDT configuration when user uses Apply or OK buttons. You need to apply your changes to that CDT configuration. You can get hold of it using call getResDesc() provided that your page extends AbstractCPropertyTab.

Writing to a Console in Eclipse

See solution based on MessageConsole

Am I headless?

See solution based on Platform & PlatformUI

Hints

Can I find a method declare when my mouse point to a method for the CDT?

If you have a method selected in the Editor, pressing F3 will take you to the declaration (i.e. the prototype) and Ctrl-F3 with take you to the definition (i.e. the body). Both options are also available from the Context menu.


More?

Back to the top