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

C/C++

Extending the Eclipse CDT Managed Build System


Now it's time to add the PDF converter tool:

  1. Add another tool to the Pretty Printer tool-chain and set the name to "PDF Converter".
  2. Set the natureFilter to both.
  3. Set the command as "ps2pdf".
  4. Set the commandLinePattern to "${command} ${inputs} ${output}".
  5. Add an input type for the tool that takes .ps files as source.
    1. Use the buildVariable "PS_FILE" for this input.
    2. Set multipleOfType to false.
    3. Set primaryInput to true.
  6. Add an output type for the tool that outputs .pdf files. Set the primaryInputType for this output to be the id of the input type that you created in step 5.
  7. There is one last bit of housekeeping: Go back to the tool-chain node and set the targetTool attribute to be the id of the PDF Converter tool.

    At this point, you have all your tools nicely defined, but still lack one crucial piece. The MBS needs to know what utility will actually do the build. In this case, you will use the GNU make utility. Luckily, CDT already includes a GNU makefile generator and a definition for a GNU Make builder that you can simply reuse. If you wished to use some other utility to do the build (nmake, shell scripts, batch files, and the like), you could define your own makefile generator and build definition. For now, you'll just specify that your tool-chain uses the existing GNU Make definitions. If you have access to the CDT source code, see org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml.

    1. Create a new builder node under the tool-chain.
    2. Set the name to "GNU Make".
    3. Set the superclass attribute to cdt.managedbuild.target.gnu.builder. This tells MBS that your builder inherits its attributes from CDT's builder, unless you specify different attributes here.

    You should now have a working set of build definitions. If you switch to the plugin.xml tab of the manifest editor, you can see the resulting XML description of your plug-in, which should look something like Listing Three. Save your file and then build the workspace.

    
    <?xml version="1.0" encoding="UTF-8"?>
    <?eclipse version="3.0"?>
    <plugin>
      <extension
            id="ddj.example.prettyprinter.toolchain"
            name="Pretty-Printer"
            point="org.eclipse.cdt.managedbuilder.core.buildDefinitions">
         <projectType
               id="ddj.example.prettyprinter.toolchain.projectType1"
               isAbstract="false"
               name="Pretty-Printer">
            <configuration
                  artifactExtension="pdf"
                  cleanCommand="rm -f"
                  description="default configuration"
                  id="ddj.example.prettyprinter.toolchain.configuration1"
                  name="Default">
               <toolChain
                     id="ddj.example.prettyprinter.toolchain.toolChain1"
                     isAbstract="false"
                     name="Pretty Printer Toolchain"
                     targetTool="ddj.example.prettyprinter.toolchain.tool2">
                  <tool
                        command="enscript"
                        commandLinePattern="${command} ${flags} ${output_flag} ${output} ${inputs}"
                        id="ddj.example.prettyprinter.toolchain.tool1"
                        isAbstract="false"
                        name="PostScript PrettyPrinter"
                        natureFilter="both"
                        outputFlag="-o">
                     <inputType
                           id="ddj.example.prettyprinter.toolchain.inputType1"
                           multipleOfType="true"
                           name="C Sources"
                           primaryInput="true"
                           sourceContentType="org.eclipse.cdt.core.cSource"/>
                     <inputType
                           id="ddj.example.prettyprinter.toolchain.inputType2"
                           multipleOfType="true"
                           name="C++ Sources"
                           primaryInput="true"
                           sourceContentType="org.eclipse.cdt.core.cxxSource"/>
                     <outputType
                           buildVariable="PS_FILE"
                           id="ddj.example.prettyprinter.toolchain.outputType1"
                           name="PostScript Files"
                           outputs="ps"
                           outputNames="${BuildArtifactFileBaseName}.ps"
                           primaryOutput="true"/>
                     <optionCategory
                           id="ddj.example.prettyprinter.toolchain.optionCategory.General"
                           name="General"
                           owner="ddj.example.prettyprinter.toolchain.tool1"/>
                     <option
                           category="ddj.example.prettyprinter.toolchain.optionCategory.General"
                           command="--pretty-print"
                           defaultValue="true"
                           id="ddj.example.prettyprinter.toolchain.option.Pretty"
                           isAbstract="false"
                           name="Pretty-print source code"
                           resourceFilter="project"
                           valueType="boolean"/>
                     <option
                           category="ddj.example.prettyprinter.toolchain.optionCategory.General"
                           command="--color"
                           id="ddj.example.prettyprinter.toolchain.option.Color"
                           isAbstract="false"
                           name="Print in color"
                           resourceFilter="project"
                           defaultValue="true"
                           valueType="boolean"/>
                  </tool>
                  <tool
                        command="ps2pdf"
                        commandLinePattern="${command} ${inputs} ${output}"
                        id="ddj.example.prettyprinter.toolchain.tool2"
                        isAbstract="false"
                        name="PDF Converter"
                        natureFilter="both">
                     <inputType
                           buildVariable="PS_FILE"
                           id="ddj.example.prettyprinter.toolchain.inputType3"
                           multipleOfType="false"
                           name="PostScript Files"
                           primaryInput="true"
                           sources="ps"/>
                     <outputType
                           id="ddj.example.prettyprinter.toolchain.outputType2"
                           name="PDF Files"
                           outputs="pdf"
                           primaryInputType="ddj.example.prettyprinter.toolchain.inputType3"
                           primaryOutput="true"/>
                  </tool>
                  <builder
                        id="ddj.example.prettyprinter.toolchain.builder1"
                        isAbstract="false"
                        isVariableCaseSensitive="false"
                        name="GNU Make"
                        superClass="cdt.managedbuild.target.gnu.builder"/>
               </toolChain>
            </configuration>
         </projectType>
      </extension>
    
    </plugin>
    
    
    Listing Three: plugin.xml

    You should now be able to debug the workspace as an Eclipse application; that is, by using Eclipse to debug itself with your new plug-in included.

    1. Select Debug... from the Run menu.
    2. Select Eclipse Application from the list of launch configuration types and press the New button. All of the default settings should be sufficient, so press the Debug button. Eclipse should then launch as a runtime-workbench.

    If you're in the C/C++ Perspective in Eclipse, use the File>New>Managed Make C++ Project menu item to create a new project. You will see a New Project wizard. Specify a name and location for your project, then click Next. You then see a page that lets you select a project type (Figure 2). In the Project Type drop-down, select the Pretty Printer project type that you created and press Finish.

    [Click image to view at full size]
    Figure 2: Project Type Selection Page


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.