source: release/1.4/source/cocoa-ide/build-application.lisp @ 13049

Last change on this file since 13049 was 13049, checked in by rme, 10 years ago

Merge trunk changes r13033 through 13035, r13048.

File size: 4.8 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 app delegate in build-application
19;;;  2. review function names. consider renaming BUILD-APPLICATION to
20;;;     SAVE-APPLICATION-BUNDLE, to better distinguish the in-process
21;;;     save-to-a-bundle function from the out-of-process batch version
22
23;;; BUILD-APPLICATION
24;;; ------------------------------------------------------------------------
25;;; Builds an application bundle and saves an executable lisp image
26;;; into it. Populates the bundle directory with the files needed to
27;;; run the lisp image when the bundle is double-clicked.
28
29(defun build-application (&key
30                          (name $default-application-bundle-name)
31                          (type-string $default-application-type-string)
32                          (creator-string $default-application-creator-string)
33                          (directory (current-directory))
34                          (copy-ide-resources t) ; whether to copy the IDE's resources
35                          (info-plist nil) ; optional user-defined info-plist
36                          (nibfiles nil) ; a list of user-specified nibfiles
37                                        ; to be copied into the app bundle
38                          (main-nib-name) ; the name of the nib that is to be loaded
39                                        ; as the app's main. this name gets written
40                                        ; into the Info.plist on the "NSMainNibFile" key
41                          (application-class 'gui::cocoa-application)
42                          (private-frameworks nil)
43                          (toplevel-function nil)
44                          (altconsole t))
45
46  (let* ((info-plist (or info-plist ; if the user supplied one then we use it
47                         (if copy-ide-resources 
48                             ;; otherwise: if copying resources use ide's
49                             (get-ide-bundle-info-plist)
50                             ;; else, create a new one
51                             (make-info-dict))))
52         (ide-bundle-path (get-ide-bundle-path))
53         ;; create the bundle directory
54         (app-bundle (make-application-bundle :name name :project-path directory))
55         (executable-dir (bundle-executable-path app-bundle))
56         (image-path (namestring (path executable-dir (bundle-executable-name name)))))
57    ;; maybe copy IDE resources to the bundle
58    (when copy-ide-resources
59      (recursive-copy-directory (path ide-bundle-path "Contents" "Resources/")
60                                (path app-bundle  "Contents" "Resources/")
61                                :test #'not-vc-control-file
62                                :if-exists :overwrite))
63    ;; write Info.plist
64    (write-info-plist info-plist (path app-bundle "Contents" "Info.plist")
65                      name type-string creator-string :main-nib-name main-nib-name)
66    ;; write Pkginfo
67    (write-pkginfo (path app-bundle "Contents" "PkgInfo") type-string creator-string)
68    ;; copy any user nibfiles into the bundle
69    (when nibfiles
70      (let ((nib-paths (mapcar #'pathname nibfiles)))
71        (assert (and (every #'probe-file nib-paths))
72                (nibfiles)
73                "The nibfiles parameter must be a list of valid pathnames to existing files or directories")
74        (dolist (n nib-paths)
75          (let ((dest (path app-bundle  "Contents" "Resources" "English.lproj/")))
76            (copy-nibfile n dest :if-exists :overwrite)))))
77    ;; copy any private frameworks into the bundle
78    (copy-private-frameworks private-frameworks app-bundle)
79    ;; install the AltConsole application if requested
80    (when altconsole
81      (install-altconsole app-bundle))
82    ;; save the application image into the bundle
83    (save-application image-path
84                      :application-class application-class
85                      :toplevel-function toplevel-function
86                      :prepend-kernel t
87                      #+windows-target #+windows-target
88                      :application-type :gui)))
89
90
91
92#|
93(require :build-application)
94(load "/usr/local/ccl/trunk/source/cocoa-ide/builder-utilities.lisp")
95(load "/usr/local/ccl/trunk/source/cocoa-ide/build-application.lisp")
96(ccl::build-application :name "Foo"
97                        :directory "/Users/mikel/Desktop"
98                        :copy-ide-resources t)
99|#
Note: See TracBrowser for help on using the repository browser.