TweetFollow Us on Twitter

March 96 - MPW TIPS AND TRICKS: Using ToolServer From CodeWarrior

MPW TIPS AND TRICKS: Using ToolServer From CodeWarrior

Tim Maroney

Last issue's column discussed various ways of using ToolServer. I looked forward to deeper integration of MPW scripts into other development systems, in a stirring plea that must have brought tears to the eyes of many an overly sensitive reader. In this column, I'll show just how self-fulfilling a prophecy can be: I'll explain how to use a generic ToolServer plug-in compiler with the popular Metrowerks CodeWarrior development system.

BEYOND THE WORKSHEET

CodeWarrior already comes with ToolServer support in the form of an integrated Worksheet window, similar to the MPW Shell Worksheet. Simply choose Start ToolServer from the Tools menu and you can issue all kinds of shell commands. It's like a miniature MPW Shell inside CodeWarrior. What more could you ask for?

Ten bonus points for reading skills if you could tell that that wasn't really a rhetorical question. The Worksheet is useful but it falls short of full integration. True, you can execute a Make command from CodeWarrior's Worksheet, but it would be even better to integrate MPW tools and scripts into the default CodeWarrior build sequence.

Let's say you have a SOM build -- that is, you're using IBM's System Object Model as implemented on the Macintosh in the form of "SOMObjects for MacOS(TM)". Before too long, it's likely that the current preprocessing approach to SOM will be just a fading (though still traumatic) memory, and that CodeWarrior and MPW will have direct-to-SOM compilers. For now, though, building with SOM requires running MPW tools and scripts to generate include files which are then processed by the C or C++ compiler.

Error prevention is one of the basic principles of user friendliness. You can invoke the SOM compiler from a makefile and run it in the CodeWarrior worksheet before you build, but if you're like me, short-term memory loss from a misspent youth will cause you to forget to run the makefile from time to time, leading to bizarre errors and gratuitous hair-tearing behaviors. MPW makefiles provide another rich source of errors by requiring you to track your own include files.

It's more convenient to simply give the single menu command Make than to bring up the Worksheet, enter "BuildProgram MyBuildFile", wait for the build to finish, and then give the Make menu command. One could only wish that CodeWarrior had a built-in SOM compiler.

A BUILT-IN SOM COMPILER (AND MORE)

Thanks to CodeWarrior's new plug-in compiler architecture (available starting with CW7), you can add build rules that invoke ToolServer scripts automatically to compile ".idl" files, or any other type of file. I've created a generic ToolServer plug-in for CodeWarrior (found on this issue's CD) that allows you to set up different command lines for different filename extensions. It will automatically track include files as well, if you want it to. It should be powerful enough for most applications, but if you need something different, you can take the source code and hack it endlessly to your own nefarious purposes.

To install the plug-in compiler, put the compiler file ToolFrontEnd into the Compilers folder of the CodeWarrior Plugins folder of your CodeWarrior application folder, and the preferences file ToolFrontEnd Panel into the Preferences folder of CodeWarrior Plugins. To set it up, first decide which filename extensions you want to run through ToolServer; in this example, we'll be doing the ".idl" files used by SOM. Give the Preferences menu command in CodeWarrior, go to the Targets panel, and attach the ToolFrontEnd compiler to source files of the appropriate type and extension.

Finally, go to the new ToolFrontEnd panel in Preferences and enter the command line you want to execute for files of this extension. The ToolFrontEnd panel is shown in Figure 1. Like all software, this is a work in progress, so it may look slightly different by the time it reaches you.

Figure 1. The ToolFrontEnd preferences panel

The pop-up menu allows you to enter different commands for different filename extensions. Bind each extension to the ToolFrontEnd compiler from the Target panel.

The Script Include File will be executed before your command line. This lets you set up variables and aliases that may be useful for your scripts and tools. The same include file is used for all filename extensions. The include file can be anywhere in the project's access paths. Here I'm using an include file named "cwtsinclude," which sets up a few handy variables. You don't need to specify any include file if you don't want one.

Your source file can be preprocessed to find include files. I've provided a default preprocessor that deals with #include specifications. You can add other preprocessors -- see the documentation and sample code that come with the software. Each include file will be added to CodeWarrior's internal list of dependencies for the source file, so the source file will automatically be rebuilt when an include file changes. If you don't want to scan for include files, choose None from the pop-up menu.

All include files should be in the CodeWarrior project's access paths. The project's access paths will be combined into the IncludeFiles variable, prefixed with the Path Parameter shown in the panel. This variable is available to all scripts executed from the plug-in.

All commands will be executed in the ToolServer context, so they'll use any startup scripts you've installed. See the notes from last issue's column about minimizing dependencies, though; all your requirements should be fulfilled by files you explicitly execute or by the Script Include File specified in the panel. Otherwise you'll run into configuration synchronization problems when restoring archived builds or sharing sources with your team members.

When the plug-in compiler executes scripts, ToolServer's current directory will have been set to the folder containing the project file. The following variables will be set up:

  • {IncludeFiles} -- the parameterized include path list
  • {ProjectFolder} -- the full pathname of the folder containing the current project file
  • {SourceFile} -- the full pathname of the source file being compiled
  • {SourceFileStem} -- the root or stem of the
  • name of the source file (for instance, the stem of "MyPanels.idl" would be "MyPanels")
Generally speaking, you'll probably want to create a front-end script for the plug-in compiler, rather than enter a raw MPW command line in the panel. This allows you to specify any number of parameters, redirections, and so on in a script file without worrying about the text editing limits in the modal dialog. The command line you specify can be up to 255 characters long. The SOM compiler has a lot of options, so I've put all the ones I use into a script file named "cwsomc."

All diagnostic output will appear in the CodeWarrior error window. All standard output will be ignored. Internal errors in the plug-in will appear as alerts.

Due to a limitation in the current plug-in API, CodeWarrior doesn't know about dependencies involving compilers that put out source files. While the SOM compiler will emit, for instance, a ".xh" include file that will be included by a ".cp" file later in the build process, there is currently no way for CodeWarrior to know that the ".cp" file depends on the ".idl" file from which the ".xh" file was generated. This will be fixed in a future version of the API, and I'll add functionality to the ToolFrontEnd plug-in to support this feature when it becomes available. For now, since CodeWarrior compiles files in the order they appear in the project file, just put ".idl" files above ".cp" files.

UNDER THE HOOD

Source code is provided with ToolFrontEnd, so you can get a detailed peek at its insides and mutate it to your own needs. A quick overview may be useful here, though.

ToolFrontEnd sends commands to ToolServer in the form of Apple events, as described in last issue's column. It builds a command in memory that is a short multiline script with semicolons separating the commands. The last command of this script is the one you typed in the preferences panel. At the start of the script are commands that set the four variables described above. The diagnostic output is extracted from the 'diag' parameter of the reply Apple event returned from ToolServer, and the error code is extracted from the 'stat' parameter. All this is done using a slightly modified version of the sample code for communicating with SourceServer that I provided in this column in Issue 23; the Apple event conventions of SourceServer and ToolServer are much the same.

The plug-in was built by starting with the sample code provided with CodeWarrior. I didn't have to make any large-scale changes to the structure -- Metrowerks deserves kudos for the quality of their sample code and their clean API. There are two code modules to be built, one for the preferences panel and one for the compiler itself. Library routines are provided for common operations like registering a dependency and getting a stored preferences record. The sample compiler already contained an include file parser, which I broke out into a separate module to allow customization for different file types.

THE BEST OF TWO WORLDS

Though I've shown just one example, many different things can be done with the ToolFrontEnd plug-in. One of my friends is using a third-party version of the UNIX(TM) tool yacc (Yet Another Compiler-Compiler), which is delivered as an MPW tool. Thanks to this plug-in, he no longer has to switch between the MPW Shell and CodeWarrior constantly. You could also define your own macro language to preprocess your source files, or add your own original compilers. And of course, using ToolServer scripts from the compiler is fully compatible with using the CodeWarrior ToolServer Worksheet window for other tasks such as installing software. The Worksheet is also useful for testing and debugging scripts you'll use with ToolFrontEnd. I haven't provided a linker plug-in, but the API is similar and the compiler plug-in could easily be adapted to this purpose.

With ToolFrontEnd, the friendliness of CodeWarrior and the power of MPW celebrate a hieros gamos (or sacred union, if that's Greek to you). The fruit of this union is an all-in-one development environment from which you can execute your entire build process, no matter how complicated, without changing contexts or inviting errors. Those whose souls are devoid of romance may prefer to contemplate the consequences of increased productivity for their next performance review -- in either case, enjoy in good humor and good health!

TIM MARONEY depends on calcium for his structural integrity and potassium for the generation of axonic spikes in his nervous system. His recent reading includes Mysticism and Philosophy by W. T. Stace, Popper Selections edited by David Miller, Seth, God of Confusion by H. Te Velde, Abrahadabra by Rodney Orpheus, Hathor and Thoth by Dr. C. J. Bleeker, Making Monsters by Rochard Ofshe and Ethan Watters, and Soul Music by Terry Pratchett. A thoroughgoing nominalist, Tim doesn't believe in either tables or natural laws, but his contract work at Apple remains stubbornly limited by his desk and by the flow of time.*

Thanks to Rick Mann and Greg Robbins for reviewing this column.*

 
AAPL
$105.22
Apple Inc.
+0.39
MSFT
$46.13
Microsoft Corpora
+1.11
GOOG
$539.78
Google Inc.
-4.20

MacTech Search:
Community Search:

Software Updates via MacUpdate

OS X Server 4.0 - For OS X 10.10 Yosemit...
Designed for OS X and iOS devices, OS X Server makes it easy to share files, schedule meetings, synchronize contacts, develop software, host your own website, publish wikis, configure Mac, iPhone,... Read more
TotalFinder 1.6.12 - Adds tabs, hotkeys,...
TotalFinder is a universally acclaimed navigational companion for your Mac. Enhance your Mac's Finder with features so smart and convenient, you won't believe you ever lived without them. Tab-based... Read more
BusyCal 2.6.3 - Powerful calendar app wi...
BusyCal is an award-winning desktop calendar that combines personal productivity features for individuals with powerful calendar sharing capabilities for families and workgroups. BusyCal's unique... Read more
calibre 2.7 - Complete e-library managem...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more
Skitch 2.7.3 - Take screenshots, annotat...
With Skitch, taking, annotating, and sharing screenshots or images is as fun as it is simple.Communicate and collaborate with images using Skitch and its intuitive, engaging drawing and annotating... Read more
Delicious Library 3.3.2 - Import, browse...
Delicious Library allows you to import, browse, and share all your books, movies, music, and video games with Delicious Library. Run your very own library from your home or office using our... Read more
Art Text 2.4.8 - Create high quality hea...
Art Text is an OS X application for creating high quality textual graphics, headings, logos, icons, Web site elements, and buttons. Thanks to multi-layer support, creating complex graphics is no... Read more
Live Interior 3D Pro 2.9.6 - Powerful an...
Live Interior 3D Pro is a powerful yet very intuitive interior designing application. View Video Tutorials It has every feature of Live Interior 3D Standard, plus some exclusive ones: Create multi... Read more
The Hit List 1.1.7 - Advanced reminder a...
The Hit List manages the daily chaos of your modern life. It's easy to learn - it's as easy as making lists. And it's powerful enough to let you plan, then forget, then act when the time is right.... Read more
jAlbum Pro 12.2.4 - Organize your digita...
jAlbum Pro has all the features you love in jAlbum, but comes with a commercial license. With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code!... Read more

Latest Forum Discussions

See All

Rami Ismail Opens Up distribute​() for D...
Rami Ismail Opens Up distribute​() for Developers Posted by Jessica Fisher on October 24th, 2014 [ permalink ] Rami Ismail, Chief Executive of Business and Development at indie game studio | Read more »
Great Hitman GO Goes on Sale and Gets Ne...
Great Hitman GO Goes on Sale and Gets New Update – Say That Three Times Fast Posted by Jessica Fisher on October 24th, 2014 [ permalink ] | Read more »
Rival Stars Basketball Review
Rival Stars Basketball Review By Jennifer Allen on October 24th, 2014 Our Rating: :: RESTRICTIVE BUT FUNUniversal App - Designed for iPhone and iPad Rival Stars Basketball is a fun mixture of basketball and card collecting but its... | Read more »
Rubicon Development Makes Over a Dozen o...
Rubicon Development Makes Over a Dozen of Their Games Free For This Weekend Only Posted by Jessica Fisher on October 24th, 2014 [ permalink ] | Read more »
I Am Dolphin Review
I Am Dolphin Review By Jennifer Allen on October 24th, 2014 Our Rating: :: NEARLY FIN-TASTICUniversal App - Designed for iPhone and iPad Swim around and eat nearly everything that moves in I Am Dolphin, a fun Ecco-ish kind of game... | Read more »
nPlayer looks to be the ultimate choice...
Developed by Newin Inc, nPlayer may seem like your standard video player – but is aiming to be the best in its field by providing high quality video play performance and support for a huge number of video formats and codecs. User reviews include... | Read more »
Fighting Fantasy: Caverns of the Snow Wi...
Fighting Fantasy: Caverns of the Snow Witch Review By Jennifer Allen on October 24th, 2014 Our Rating: :: CLASSY STORYTELLINGUniversal App - Designed for iPhone and iPad Fighting Fantasy: Caverns of the Snow Witch is a sterling... | Read more »
A Few Days Left (Games)
A Few Days Left 1.01 Device: iOS Universal Category: Games Price: $3.99, Version: 1.01 (iTunes) Description: Screenshots are in compliance to App Store's 4+ age rating! Please see App Preview for real game play! **Important: Make... | Read more »
Toca Boo (Education)
Toca Boo 1.0.2 Device: iOS Universal Category: Education Price: $2.99, Version: 1.0.2 (iTunes) Description: BOO! Did I scare you!? My name is Bonnie and my family loves to spook! Do you want to scare them back? Follow me and I'll... | Read more »
Intuon (Games)
Intuon 1.1 Device: iOS Universal Category: Games Price: $.99, Version: 1.1 (iTunes) Description: Join the battle with your intuition in a new hardcore game Intuon! How well do you trust your intuition? Can you find a needle in a... | Read more »

Price Scanner via MacPrices.net

Weekend sale: 13-inch 128GB MacBook Air for $...
Best Buy has the 2014 13-inch 1.4GHz 128GB MacBook Air on sale for $849.99, or $150 off MSRP, on their online store. Choose free home shipping or free local store pickup (if available). Price valid... Read more
Nimbus Note Cross=Platform Notes Utility
Nimbus Note will make sure you never forget or lose your valuable data again. Create and edit notes, save web pages, screenshots and any other type of data – and share it all with your friends and... Read more
NewerTech’s Snuglet Makes MagSafe 2 Power Con...
NewerTech has introduced the Snuglet, a precision-manufactured ring designed to sit inside your MagSafe 2 connector port, providing a more snug fit to prevent your power cable from unintentional... Read more
Apple Planning To Sacrifice Gross Margins To...
Digitimes Research’s Jim Hsiao says its analysts believe Apple is planning to sacrifice its gross margins to save its tablet business, which has recently fallen into decline. They project that Apple’... Read more
Who’s On Now? – First Instant-Connect Search...
It’s nighttime and your car has broken down on the side of the highway. You need a tow truck right away, so you open an app on your iPhone, search for the closest tow truck and send an instant... Read more
13-inch 2.5GHz MacBook Pro on sale for $949,...
Best Buy has the 13″ 2.5GHz MacBook Pro available for $949.99 on their online store. Choose free shipping or free instant local store pickup (if available). Their price is $150 off MSRP. Price is... Read more
Save up to $125 on Retina MacBook Pros
B&H Photo has the new 2014 13″ and 15″ Retina MacBook Pros on sale for up to $125 off MSRP. Shipping is free, and B&H charges NY sales tax only. They’ll also include free copies of Parallels... Read more
Apple refurbished Time Capsules available sta...
The Apple Store has certified refurbished Time Capsules available for up to $60 off MSRP. Apple’s one-year warranty is included with each Time Capsule, and shipping is free: - 2TB Time Capsule: $255... Read more
Textilus New Word, Notes and PDF Processor fo...
Textilus is new word-crunching, notes, and PDF processor designed exclusively for the iPad. I haven’t had time to thoroughly check it out yet, but it looks great and early reviews are positive.... Read more
WD My Passport Pro Bus-Powered Thunderbolt RA...
WD’s My Passport Pro RAID solution is powered by an integrated Thunderbolt cable for true portability and speeds as high as 233 MB/s. HighlightsOverviewSpecifications Transfer, Back Up And Edit In... Read more

Jobs Board

*Apple* Solutions Consultant - Apple Inc. (U...
…important role that the ASC serves is that of providing an excellent Apple Customer Experience. Responsibilities include: * Promoting Apple products and solutions Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.