source: trunk/source/cocoa-ide/build-application.lisp @ 9348

Last change on this file since 9348 was 9348, checked in by mikel, 13 years ago

added support and documentation for user-defined Info.plist objects

File size: 4.1 KB
Line 
1;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: cl-user -*-
2;;;; ***********************************************************************
3;;;; FILE IDENTIFICATION
4;;;;
5;;;; Name:          build-application.lisp
6;;;; Version:       0.9
7;;;; Project:       Cocoa application builder
8;;;; Purpose:       the in-process application builder
9;;;;
10;;;; ***********************************************************************
11
12(require "builder-utilities")
13
14(in-package :ccl)
15
16
17;;; TODO:
18;;;  1. make a way to specify a user-defined Info.plist in build-application
19;;;  2. make a way to specify a user-defined app delegate in build-application
20
21;;; BUILD-APPLICATION
22;;; ------------------------------------------------------------------------
23;;; Builds an application bundle and saves an executable lisp image
24;;; into it. Populates the bundle directory with the files needed to
25;;; run the lisp image when the bundle is double-clicked.
26
27(defun build-application (&key
28                          (name $default-application-bundle-name)
29                          (type-string $default-application-type-string)
30                          (creator-string $default-application-creator-string)
31                          (directory (current-directory))
32                          (copy-ide-resources t) ; whether to copy the IDE's resources
33                          (info-plist nil) ; optional user-defined info-plist
34                          (nibfiles nil) ; a list of user-specified nibfiles
35                                        ; to be copied into the app bundle
36                          (main-nib-name) ; the name of the nib that is to be loaded
37                                        ; as the app's main. this name gets written
38                                        ; into the Info.plist on the "NSMainNibFile" key
39                          (application-class 'gui::cocoa-application)
40                          (toplevel-function nil))
41
42  (let* ((info-plist (or info-plist ; if the user supplied one then we use it
43                         (if copy-ide-resources 
44                             ;; otherwise: if copying resources use ide's
45                             (get-ide-bundle-info-plist)
46                             ;; else, create a new one
47                             (make-info-dict))))
48         (ide-bundle-path (get-ide-bundle-path))
49         ;; create the bundle directory
50         (app-bundle (make-application-bundle :name name :project-path directory))
51         (image-path (namestring (path app-bundle "Contents" "MacOS" name))))
52    ;; maybe copy IDE resources to the bundle
53    (when copy-ide-resources
54      (recursive-copy-directory (path ide-bundle-path "Contents" "Resources/")
55                                (path app-bundle  "Contents" "Resources/")
56                                :if-exists :overwrite))
57    ;; write Info.plist
58    (write-info-plist info-plist (path app-bundle "Contents" "Info.plist")
59                      name type-string creator-string :main-nib-name main-nib-name)
60    ;; write Pkginfo
61    (write-pkginfo (path app-bundle "Contents" "PkgInfo") type-string creator-string)
62    ;; copy any user nibfiles into the bundle
63    (when nibfiles
64      (let ((nib-paths (mapcar #'pathname nibfiles)))
65        (assert (and (every #'probe-file nib-paths))
66                (nibfiles)
67                "The nibfiles parameter must be a list of valid pathnames to existing files or directories")
68        (dolist (n nib-paths)
69          (let ((dest (path app-bundle  "Contents" "Resources" "English.lproj/")))
70            (copy-nibfile n dest :if-exists :overwrite)))))
71    ;; save the application image into the bundle
72    (save-application image-path
73                      :application-class application-class
74                      :toplevel-function toplevel-function
75                      :prepend-kernel t)))
76
77#|
78(require :build-application)
79(load "/usr/local/ccl/trunk/source/cocoa-ide/builder-utilities.lisp")
80(load "/usr/local/ccl/trunk/source/cocoa-ide/build-application.lisp")
81(ccl::build-application :name "Foo"
82                        :directory "/Users/mikel/Desktop"
83                        :copy-ide-resources t)
84|#
Note: See TracBrowser for help on using the repository browser.