Mac OS X Internals: A Systems Approach
2.13. Programming
Mac OS X includes an integrated development environment (IDE) called Xcode, numerous general-purpose and special-purpose libraries, compilers and interpreters for various programming languages, and a rich set of debugging and optimization tools. 2.13.1. Xcode
The development environment provided by Xcode has the following noteworthy features:
A new Xcode project can be instantiated from a large number of templates, depending on the type of application, programming language, target environment, and so on. Supported languages include AppleScript, C, C++, Java, Objective-C, and Objective-C++. Examples of supported templates include those for Automator Actions, Image Unit Plug-ins, Metadata Importers, Preference Panes, Screen Savers, and Sherlock Channels. Although Xcode is normally used through its graphical user interface, you can also work with existing Xcode projects from the command line. The xcodebuild command-line program can be used to build one or more targets contained in an Xcode project, optionally with a specific build style such as Development or Deployment. The pbprojectdump command-line program can be used to dump an Xcode project dictionary in a human-readable format, thus allowing you to view the project structure. If you must avoid Xcode altogether, you can manage your projects "manually"for example, by creating makefiles and tracking dependencies. Mac OS X includes the BSD and GNU versions of the make program: bsdmake and gnumake, respectively.
The back-end of the Xcode build system is based on the Jam product (/Developer/Private/jam) from Perforce Software, Inc.
2.13.2. Compilers and Libraries
Apple provides a customized and optimized version of the GNU C compiler with back-ends for multiple languages. As we saw earlier in this chapter, two Java compilers are included. Other compilers for a variety of languages are available both commercially[70] and freely.[71] The situation is similar for libraries: Several are included with Mac OS X and several can be compiled from source. In particular, Mac OS X includes some optimized, special-purpose libraries, for example, BLAS, LAPACK, vBigNum, vDSP, vImage, and vMathLib. All these libraries, which are meant for image processing or numerical and scientific computing, are accessible through the Accelerate umbrella framework (Accelerate.framework). [70] Commercially available compilers include those from Intel and Absoft Corporation. [71] Numerous open source compilers, interpreters, and libraries can be readily compiled from source on Mac OS X. In general, the difficulty of doing so is roughly on par with that on systems such as Linux and FreeBSD. 2.13.3. Interpreters
Several scripting languages are included in Mac OS X: AppleScript, Perl, PHP, Python,[72] Ruby, and Tcl. Multiple Unix shells are also included, such as bash, ksh, tcsh, and zsh. Mac OS X supports the Open Scripting Architecture (OSA), with AppleScript as the default (and only) installed language. Other languages for the OSA are available from third parties. [72] Python on Mac OS X includes bindings to Core Graphics. 2.13.3.1. AppleScript
AppleScript is the preferred scripting language on Mac OS X, providing direct control of many parts of the system as well as applications. For example, using AppleScript, you can write scripts to automate operations, exchange data with applications, or send commands to applications. AppleScript can be used inand acrossall application environments. For application-specific actions to be performed using AppleScript, the application must explicitly support AppleScript. Such support typically requires a data model that lends itself well to being manipulated externally. However, generic operations (such as launching an application) are supported automatically. Figure 229 shows a trivial AppleScript program that speaks the operating system version. You can use either the osascript command-line tool or the AppleScript editor (/Applications/AppleScript/Script Editor.app) to run this program. Figure 229. A trivial AppleScript program
osascript executes a script file, which may be either a textual version or a compiled version of an AppleScript program. The osacompile command[73] can be used to compile source files, the standard input, or other compiled scripts into a single script. [73] The osascript and osacompile commands will work with any installed scripting language that conforms to the OSA. 2.13.3.2. Automator
The Automator application is a visual tool for automating repetitive operations on Mac OS X. An Automator action is a modular unitan indivisible task from Automator's standpoint. For example, a task can create a directory, open a file, capture a screenshot, send an email message, or run a shell script. Multiple actions can be connected in a particular sequence to construct a workflow, which in turn is executed to perform the arbitrarily complex set of tasks that the workflow represents. An action may or may not require additional informationor argumentswhen it executes as part of a workflow. If additional information is required, the action displays a user interface consisting of text fields, checkboxes, buttons, pop-up menus, and so on. Automator includes a large number of predefined actions, but users can create their own actions using either AppleScript or Objective-C. A workflow is created visually by dragging or adding actions to a construction area. Finally, workflows can be saved for running later. 2.13.3.3. Command-Line Support
With each major release of Mac OS X, Apple has improved the system's command-line support by exposing more aspects of the system to be driven from the command line. In some cases, Apple has made command-line tools behave correctly and consistently. For example, in Mac OS X versions prior to 10.4, Unix-derived commands such as cp, mv, tar, and rsync did not handle certain aspects of Apple's HFS Plus file system correctly.[74] As still newer file system features such as metadata-based searching and access control lists (ACLs) were added in Mac OS X 10.4, the aforementioned commands were updated to behave consistently. [74] These commands were not aware of HFS Plus resource forks until Mac OS X 10.4. We will look at details of HFS Plus in Chapter 12. Let us consider a few other examples of using the command line in Mac OS X. The drutil command can be used to interact with the Disc Recording framework (DiscRecording.framework), which manages CD and DVD burners. Figure 230 shows an example of its use. Figure 230. Command-line interaction with the Disc Recording framework
The hdiutil command interacts with the Disk Images framework (DiskImages.framework), which is used for accessing and manipulating disk images. Figure 231 shows an example of its use. Figure 231. Command-line interaction with the Disk Images framework
The say command uses the Speech Synthesis Manager to convert input text to audible speech. The resultant speech data may be either played back or saved to an AIFF file. The sips[75] command provides basic image-processing functionality from the command line. It supports several image formats. Its goal is to allow quick and convenient desktop automation of common queries and operations on images. Figure 232 shows an example of using sips. [75] sips stands for Scriptable Image Processing System. Figure 232. Using the sips command to resample an image and convert its format
The Spotlight metadata search functionality is accessible from the command line. The mdls command lists the names and values of all metadata attributes associated with the specified files. The mdfind command can be used to find files matching a given query, optionally limiting the search to a specified directory. Moreover, mdfind can operate in "live" mode: It will continue to run until interrupted, while updating the number of matches. Figure 233 shows an example of using mdfind. Figure 233. Using the mdfind command to find files matching a given query
2.13.4. Tools
In addition to the development tools that are accessible through Xcode, Mac OS X provides a wide range of tools for analyzing, debugging, monitoring, profiling, and understanding both hardware and software.
Apple's general philosophy is to encourage programmers to use the highest possible level of abstraction as far as possible and to let the platform handle low-level details. This way, programmers can avoid using interfaces or system aspects that are likely to change during the evolution of Mac OS X. This approachparticularly when followed for end-user softwareis conducive to overall stability and a consistent user experience. 2.13.4.1. Debugging and Analysis Tools
The following are examples of debugging and analysis tools available on Mac OS X.
2.13.4.2. Computer Hardware Understanding Development Tools
The Computer Hardware Understanding Development (CHUD) package is a set of low-level tools that can be optionally installed on Mac OS X. CHUD tools include the following specific programs.
2.13.4.3. Visual Tools
Mac OS X also provides several visual design and programming tools, most of which we came across earlier in this chapter, for example, AppleScript Studio, Automator, AU Lab, Interface Builder, Quartz Composer, and Xcode class- and data-modeling tools. |
Категории