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

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

put skeleton in place for batch project builder

File size: 6.2 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                          (toplevel-function nil))
43
44  (let* ((info-plist (or info-plist ; if the user supplied one then we use it
45                         (if copy-ide-resources 
46                             ;; otherwise: if copying resources use ide's
47                             (get-ide-bundle-info-plist)
48                             ;; else, create a new one
49                             (make-info-dict))))
50         (ide-bundle-path (get-ide-bundle-path))
51         ;; create the bundle directory
52         (app-bundle (make-application-bundle :name name :project-path directory))
53         (image-path (namestring (path app-bundle "Contents" "MacOS" name))))
54    ;; maybe copy IDE resources to the bundle
55    (when copy-ide-resources
56      (recursive-copy-directory (path ide-bundle-path "Contents" "Resources/")
57                                (path app-bundle  "Contents" "Resources/")
58                                :if-exists :overwrite))
59    ;; write Info.plist
60    (write-info-plist info-plist (path app-bundle "Contents" "Info.plist")
61                      name type-string creator-string :main-nib-name main-nib-name)
62    ;; write Pkginfo
63    (write-pkginfo (path app-bundle "Contents" "PkgInfo") type-string creator-string)
64    ;; copy any user nibfiles into the bundle
65    (when nibfiles
66      (let ((nib-paths (mapcar #'pathname nibfiles)))
67        (assert (and (every #'probe-file nib-paths))
68                (nibfiles)
69                "The nibfiles parameter must be a list of valid pathnames to existing files or directories")
70        (dolist (n nib-paths)
71          (let ((dest (path app-bundle  "Contents" "Resources" "English.lproj/")))
72            (copy-nibfile n dest :if-exists :overwrite)))))
73    ;; save the application image into the bundle
74    (save-application image-path
75                      :application-class application-class
76                      :toplevel-function toplevel-function
77                      :prepend-kernel t)))
78
79;;; BUILD-APPLICATION-PROJECT
80;;; ------------------------------------------------------------------------
81;;; Runs a separate process that builds an application bundle and
82;;; saves an executable lisp image into it. Populates the bundle
83;;; directory with the files needed to run the lisp image when the
84;;; bundle is double-clicked. Pass a lisp source file as the value for
85;;; :project-file; the builder loads that file before saving the
86;;; application. The intended use of the project file is to load any
87;;; Lisp code that should be a part of the image before saving it.
88
89(defun build-application-project (&key
90                                  (name $default-application-bundle-name)
91                                  (project-file nil)
92                                  (type-string $default-application-type-string)
93                                  (creator-string $default-application-creator-string)
94                                  (directory (current-directory))
95                                  (copy-ide-resources t) ; whether to copy the IDE's resources
96                                  (info-plist nil) ; optional user-defined info-plist
97                                  (nibfiles nil) ; a list of user-specified nibfiles
98                                        ; to be copied into the app bundle
99                                  (main-nib-name) ; the name of the nib that is to be loaded
100                                        ; as the app's main. this name gets written
101                                        ; into the Info.plist on the "NSMainNibFile" key
102                                  (application-class 'gui::cocoa-application)
103                                  (toplevel-function nil))
104  ;; 1. build the command line for the remote ccl process
105  ;;  - require all the needed subsystems:
106  ;;    - cocoa
107  ;;    - builder-utilities
108  ;;    - build-application
109  ;;  - load the project file
110  ;;  - call build-application
111  ;; 2. run the remote process with the constructed command line
112  )
113
114#|
115(require :build-application)
116(load "/usr/local/ccl/trunk/source/cocoa-ide/builder-utilities.lisp")
117(load "/usr/local/ccl/trunk/source/cocoa-ide/build-application.lisp")
118(ccl::build-application :name "Foo"
119                        :directory "/Users/mikel/Desktop"
120                        :copy-ide-resources t)
121|#
Note: See TracBrowser for help on using the repository browser.