Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Embedded Systems

Extending the Eclipse CDT Managed Build System


The heart of the build definitions you are creating will be the tool-chain. The tool-chain specifies which tools exist and which types of files they take as input and produce as output. If you have a set of tools whose outputs feed into the inputs of other tools (for instance, a compiler turns .c files into .o files, and the linker takes the .o files as input and creates an executable), then you have a tool-chain. You will define a tool-chain with two tools: A PostScript pretty printer that takes C and C++ source files and turns them into a .ps file, and a PDF converter that takes the .ps file as input and creates a PDF from it.

  1. Similar to the way you created a new projectType and configuration, right click on the configuration to create a new tool.
  2. Name the tool "PostScript Pretty Printer".
  3. Set the command attribute to "enscript".
  4. Set the natureFilter attribute to both. This tells the MBS to use this tool for both C and C++ projects.

You will add more information to the tool later. For now, you need to set the inputs and outputs of your tool:

  1. Create an inputType for the tool and set the name to "C Sources".
  2. You can either list out the file extensions manually via the sources attribute or specify an Eclipse content type via the sourceContentType attribute. Content types have the benefit of allowing the user to edit the list of extensions. For C source files, the content type defined by CDT is org.eclipse.cdt.core.cSource, so use that.
  3. Set the multipleOfType attribute to true. This tells MBS to feed all files of this type to one invocation of the tool. This way, the listings of all your source files will be conglomerated into one .ps file.
  4. Repeat steps 1 to 4 to create a "C++ Sources" inputType that uses org.eclipse.cdt.core.cxxSource as its content type.
  5. Create a new outputType node for the tool and set the name to "PostScript Files".
  6. Since there is no content type defined for PostScript files, let's simplify things and set the outputs attribute to "ps".
  7. Now you have a slight dilemma. Since you aren't generating one .ps file for each C or C++ source file, you have to figure out what to name the resulting .ps file. MBS lets you do this with the outputNames attribute. Set the attribute to "${BuildArtifactFileBaseName}.ps". This utilizes an MBS build macro in order to use the same file name that you specify for the final output of the project, along with the ps file extension. MBS defines many additional build macros, which you'll find listed in the CDT documentation.
  8. Set the buildVariable attribute to "PS_FILE". You will enter the same name when you define the inputType for the PDF converter tool below. This tells MBS that this output of the enscript tool is the input to the PDF converter tool.
  9. Most tools have command-line options that control the behavior of the tool. For your enscript tool, you will make the --pretty-print and -- color options available in the tool's property page. First, you need to create an optionCategory for the tool -- this lets you group options in the property page. After creating the optionCategory, set the id to ddj.example.prettyprinter.toolchain.optionCategory.General, and name it "General".
  10. Set the owner to "ddj.example.prettyprinter.toolchain.tool1" (that is, the tool you are defining).
  11. Next, you need to create an option for the tool. Set the id to "ddj.example.prettyprinter.toolchain.option.Pretty" and name it "Pretty-print source code". The name will be used in the property page as the caption for the option.
  12. Set the category to "ddj.example.prettyprinter.toolchain.optionCategory.General" (that is, the optionCategory you just created).
  13. Set the resourceFilter to project. This means that this option applies to the tool and cannot be set differently for an individual source file in the project.
  14. Set the valueType to boolean. MBS supports boolean, string, list of strings, enumerated, and other specialized option types. The valueType controls how the option value is displayed in the property page, what the valid values are, and other things.
  15. Set the defaultValue to true, since you want pretty printing turned on by default.
  16. Now add a second option with an id of ddj.example.prettyprinter.toolchain.option.Pretty, a name of "Print in color", and category, resourceFilter, valueType, and defaultValue set as above for the "pretty-print" option.
  17. To have MBS invoke the tool properly, backtrack to the tool node, go to the commandLinePattern attribute, and set it to "${command} ${flags} ${output_flag} ${output} ${inputs}". This tells MBS to format the command as enscript --pretty-print --color -o


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.