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 | ;; copy IDE resources into the application bundle |
---|
70 | (recursive-copy-directory (path ide-bundle-path "Contents" "Resources/") |
---|
71 | (path app-bundle "Contents" "Resources/")) |
---|
72 | ;; copy user-supplied nibfiles into the bundle |
---|
73 | (when nibfiles |
---|
74 | (let ((nib-paths (mapcar #'pathname nibfiles))) |
---|
75 | (assert (and (every #'probe-file nib-paths) |
---|
76 | (every #'directoryp nib-paths)) |
---|
77 | (nibfiles) |
---|
78 | "The nibfiles parameter must be a list of valid pathnames to existing directories") |
---|
79 | ;; for each input nibfile, construct the destination path and copy it to that path |
---|
80 | ;; checking first whether doing so would clobber an existing nib. if it would, |
---|
81 | ;; signal an error |
---|
82 | (dolist (n nib-paths) |
---|
83 | ;; TODO: handle cases where there are nibs for languages other than English |
---|
84 | (let ((dest (path app-bundle "Contents" "Resources" "English.lproj/" (namestring (basename n))))) |
---|
85 | (if (probe-file dest) |
---|
86 | (error "The destination nibfile '~A' already exists" dest) |
---|
87 | (recursive-copy-directory n dest)))))) |
---|
88 | ;; save the application image |
---|
89 | (save-application image-path |
---|
90 | :application-class application-class |
---|
91 | :toplevel-function toplevel-function |
---|
92 | :prepend-kernel t))) |
---|
93 | |
---|
94 | |
---|
95 | |
---|