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

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

fixed pathname bug in builder-utilities

File size: 4.6 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;;; about copying nibfiles
17
18;;; when building an app bundle, we copy nibfiles from the development
19;;; environment appplication bundle into the newly-created application
20;;; bundle. If user-supplied nibfiles are given the same names as
21;;; nibfiles from the development environment, we signal an error and
22;;; refuse to copy the user nibfiles. This treatment ensures that users
23;;; will not accidentally clobber dev-environment nibfiles, but also
24;;; means that they must give unique names to their own nibs in order
25;;; to use them with their saved applications.
26
27;;; in future, we may add options to suppress the copying of
28;;; dev-environment nibfiles.
29
30(defun build-application (&key
31                          (name "MyApplication")
32                          (type-string "APPL")
33                          (creator-string "OMCL")
34                          (directory (current-directory))
35                          (nibfiles nil) ; a list of user-specified nibfiles
36                                         ; to be copied into the app bundle
37                          (main-nib-name); the name of the nib that is to be loaded
38                                         ; as the app's main. this name gets written
39                                         ; into the Info.plist on the "NSMainNibFile" key
40                          (application-class 'cocoa-application)
41                          (toplevel-function nil)
42                          (swank-loader nil)
43                          (autostart-swank-on-port nil))
44  ;;; if the path to swank-loader.lisp is given, then load
45  ;;; swank before building the application
46  (when swank-loader
47    (assert (probe-file swank-loader)(swank-loader)
48            "Swank loader not found at path '~A'" swank-loader)
49    (load swank-loader)
50    ;; when autostart-swank-on-port is also given, setup
51    ;; swank to start up on launch (still don't know how
52    ;; we're actually going to do this)
53    (when autostart-swank-on-port
54      (assert (integerp autostart-swank-on-port)(autostart-swank-on-port)
55              "The port for :autostart-swank-on-port must be an integer or nil, not '~S'"
56              autostart-swank-on-port)
57      ;; if we get this far, setup the swank autostart
58      ;; (however we're going to do that...)
59      ))
60  ;;; build the application
61  (let* ((ide-bundle (#/mainBundle ns:ns-bundle))
62         (ide-bundle-path-nsstring (#/bundlePath ide-bundle))
63         (ide-bundle-path (pathname 
64                           (ensure-directory-pathname 
65                            (lisp-string-from-nsstring ide-bundle-path-nsstring))))
66         (app-bundle (make-application-bundle name type-string creator-string directory
67                                              :main-nib-name main-nib-name))
68         (image-path (namestring (path app-bundle "Contents" "MacOS" name))))
69
70    ;; copy IDE resources into the application bundle
71    (recursive-copy-directory (path ide-bundle-path "Contents" "Resources/")
72                              (path app-bundle  "Contents" "Resources/"))
73    ;; copy user-supplied nibfiles into the bundle
74    (when nibfiles
75      (let ((nib-paths (mapcar #'pathname nibfiles)))
76        (assert (and (every #'probe-file nib-paths)
77                     (every #'directoryp nib-paths))
78                (nibfiles)
79                "The nibfiles parameter must be a list of valid pathnames to existing directories")
80        ;; for each input nibfile, construct the destination path and copy it to that path
81        ;; checking first whether doing so would clobber an existing nib. if it would,
82        ;; signal an error
83        (dolist (n nib-paths)
84          ;; TODO: handle cases where there are nibs for languages other than English
85          (let ((dest (path app-bundle  "Contents" "Resources" "English.lproj/" (namestring (basename n)))))
86            (if (probe-file dest)
87                (error "The destination nibfile '~A' already exists" dest)
88                (recursive-copy-directory n dest))))))
89    ;; save the application image
90    (save-application image-path
91                      :application-class application-class
92                      :toplevel-function toplevel-function
93                      :prepend-kernel t)))
94
95
96
Note: See TracBrowser for help on using the repository browser.