Changeset 9333


Ignore:
Timestamp:
Apr 30, 2008, 3:33:45 PM (11 years ago)
Author:
mikel
Message:

altered the bundle builder so that the user controls whether to copy resources and read the Info.plist from the IDE when invoking build-application

Location:
trunk/source/cocoa-ide
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/build-application.lisp

    r9309 r9333  
    1414(in-package :ccl)
    1515
    16 ;;; about copying nibfiles
    1716
    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 
     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
    3020(defun build-application (&key
    3121                          (name $default-application-bundle-name)
     
    4232                          (toplevel-function nil))
    4333
    44   (let* ((ide-bundle (#/mainBundle ns:ns-bundle))
     34  (let* ((info-plist (if copy-ide-resources
     35                         (get-ide-bundle-info-plist)
     36                         (make-info-dict)))
     37         (ide-bundle (#/mainBundle ns:ns-bundle))
    4538         (ide-bundle-path-nsstring (#/bundlePath ide-bundle))
    4639         (ide-bundle-path (pathname
     
    4841                            (lisp-string-from-nsstring ide-bundle-path-nsstring))))
    4942         ;; create the bundle directory
    50          (app-bundle (make-application-bundle name type-string creator-string directory
    51                                               :main-nib-name main-nib-name))
     43         (app-bundle (make-application-bundle :name name
     44                                              :project-path directory))
    5245         (image-path (namestring (path app-bundle "Contents" "MacOS" name))))
    5346    ;; copy IDE resources to the bundle
     
    5649                                (path app-bundle  "Contents" "Resources/")
    5750                                :if-exists :overwrite))
     51    ;; write Info.plist
     52    (write-info-plist info-plist (path app-bundle "Contents" "Info.plist")
     53                      name type-string creator-string :main-nib-name main-nib-name)
     54    ;; write Pkginfo
     55    (write-pkginfo (path app-bundle "Contents" "PkgInfo")
     56                   type-string creator-string)
    5857    ;; copy user nibfiles into the bundle
    5958    (when nibfiles
  • trunk/source/cocoa-ide/builder-utilities.lisp

    r9309 r9333  
    1818;;; resource directories, and magic files used by OSX applications.
    1919
    20 ;;; DEFAULTS
    21 ;;; Some useful default values for use when creating application bundles
     20(defun %temp-nsstring (s) (#/autorelease (%make-nsstring s)))
     21
     22;;; Info Defaults
     23;;; Some useful values for use when creating application bundles
    2224
    2325(defparameter $default-application-bundle-name "MyApplication")
     
    2729
    2830;;; defaults related to Info.plist files
    29 
     31(defparameter $cfbundle-development-region-key #@"CFBundleDevelopmentRegion")
    3032(defparameter $default-info-plist-development-region "English")
     33
     34(defparameter $cfbundle-executable-key #@"CFBundleExecutable")
    3135(defparameter $default-info-plist-executable $default-application-bundle-name)
    32 (defparameter $default-info-plist-getInfo-string (format nil "~A Copyright ~C 2008"
    33                                                          $default-application-version-number
    34                                                          #\Copyright_Sign))
    35 (defparameter $default-info-plist-help-book-folder (format nil "~AHelp" $default-application-bundle-name))
    36 (defparameter $default-info-plist-help-book-name (format nil "~A Help" $default-application-bundle-name))
    37 (defparameter $default-info-plist-icon-file (format nil "~A.icns" $default-application-bundle-name))
    38 (defparameter $default-info-plist-bundle-identifier (format nil "com.clozure.ccl.apps.~A"
    39                                                             (string-downcase $default-application-bundle-name)))
    40 (defparameter $default-info-dictionary-version "6.0")
    41 (defparameter $default-info-plist-bundle-name $default-application-bundle-name)
     36
     37(defparameter $cfbundle-getinfo-string-key #@"CFBundleGetInfoString")
     38(defparameter $default-info-plist-getInfo-string "\"1.0 Copyright © 2008\"")
     39
     40(defparameter $cfbundle-help-book-folder-key #@"CFBundleHelpBookFolder")
     41(defparameter $default-info-plist-help-book-folder "MyApplicationHelp")
     42
     43(defparameter $cfbundle-help-book-name-key #@"CFBundleHelpBookName")
     44(defparameter $default-info-plist-help-book-name "\"MyApplication Help\"")
     45
     46(defparameter $cfbundle-icon-file-key #@"CFBundleIconFile")
     47(defparameter $default-info-plist-icon-file "\"MyApplication.icns\"")
     48
     49(defparameter $cfbundle-bundle-identifier-key #@"CFBundleIdentifier")
     50(defparameter $default-info-plist-bundle-identifier "\"com.clozure.apps.myapplication\"")
     51
     52(defparameter $cfbundle-dictionary-version-key #@"CFBundleInfoDictionaryVersion")
     53(defparameter $default-info-dictionary-version "\"6.0\"")
     54
     55(defparameter $cfbundle-bundle-name-key #@"CFBundleName")
     56(defparameter $default-info-plist-bundle-name "MyApplication")
     57
     58(defparameter $cfbundle-bundle-package-type-key #@"CFBundlePackageType")
    4259(defparameter $default-info-plist-bundle-package-type "APPL")
    43 (defparameter $default-info-plist-short-version-string $default-application-version-number)
     60
     61(defparameter $cfbundle-short-version-string-key #@"CFBundleShortVersionString")
     62(defparameter $default-info-plist-short-version-string "\"1.0\"")
     63
     64(defparameter $cfbundle-bundle-signature-key #@"CFBundleSignature")
    4465(defparameter $default-info-plist-bundle-signature "OMCL")
    45 (defparameter $default-info-plist-version $default-application-version-number)
    46 (defparameter $default-info-plist-has-localized-display-name 0)
    47 (defparameter $default-info-plist-minimum-system-version "10.5")
     66
     67(defparameter $cfbundle-version-key #@"CFBundleVersion")
     68(defparameter $default-info-plist-version "\"1.0\"")
     69
     70(defparameter $ls-has-localized-display-name-key #@"LSHasLocalizedDisplayName")
     71(defparameter $default-info-plist-has-localized-display-name "0")
     72
     73(defparameter $ls-minimum-system-version-key #@"LSMinimumSystemVersion")
     74(defparameter $default-info-plist-minimum-system-version "\"10.5\"")
     75
     76(defparameter $ns-main-nib-file-key #@"NSMainNibFile")
    4877(defparameter $default-info-plist-main-nib-file "MainMenu")
     78
     79(defparameter $ns-principal-class-key #@"NSPrincipalClass")
    4980(defparameter $default-info-plist-principal-class "LispApplication")
    50 
    5181
    5282;;; COPY-NIBFILE (srcnib dest-directory &key (if-exists :overwrite))
     
    121151    (format out "~A~A" package-type bundle-signature)))
    122152
    123 ;;; MAKE-INFO-PLIST
     153;;; MAKE-INFO-DICT
    124154;;; returns a newly-created NSDictionary with contents
    125155;;; specified by the input parameters
    126 (defun make-info-plist (&key
    127                         (development-region $default-info-plist-development-region)
    128                         (executable $default-info-plist-executable)
    129                         (getinfo-string $default-info-plist-getinfo-string)
    130                         (help-book-folder $default-info-plist-help-book-folder)
    131                         (help-book-name $default-info-plist-help-book-name)
    132                         (icon-file $default-info-plist-icon-file)
    133                         (bundle-identifier $default-info-plist-bundle-identifier)
    134                         (dictionary-version $default-info-dictionary-version)
    135                         (bundle-name $default-info-plist-bundle-name)
    136                         (bundle-package-type $default-info-plist-bundle-package-type)
    137                         (short-version-string $default-info-plist-short-version-string)
    138                         (bundle-signature $default-info-plist-bundle-signature)
    139                         (version $default-info-plist-version)
    140                         (has-localized-display-name $default-info-plist-has-localized-display-name)
    141                         (minimum-system-version $default-info-plist-minimum-system-version)
    142                         (main-nib-file $default-info-plist-main-nib-file)
    143                         (principal-class $default-info-plist-principal-class))
    144   (error "Not yet implemented"))
     156(defun make-info-dict (&key
     157                       (development-region $default-info-plist-development-region)
     158                       (executable $default-info-plist-executable)
     159                       (getinfo-string $default-info-plist-getinfo-string)
     160                       (help-book-folder $default-info-plist-help-book-folder)
     161                       (help-book-name $default-info-plist-help-book-name)
     162                       (icon-file $default-info-plist-icon-file)
     163                       (bundle-identifier $default-info-plist-bundle-identifier)
     164                       (dictionary-version $default-info-dictionary-version)
     165                       (bundle-name $default-info-plist-bundle-name)
     166                       (bundle-package-type $default-info-plist-bundle-package-type)
     167                       (short-version-string $default-info-plist-short-version-string)
     168                       (bundle-signature $default-info-plist-bundle-signature)
     169                       (version $default-info-plist-version)
     170                       (has-localized-display-name $default-info-plist-has-localized-display-name)
     171                       (minimum-system-version $default-info-plist-minimum-system-version)
     172                       (main-nib-file $default-info-plist-main-nib-file)
     173                       (principal-class $default-info-plist-principal-class))
     174  (#/dictionaryWithObjectsAndKeys: ns:ns-dictionary
     175                                   (%temp-nsstring development-region) $cfbundle-development-region-key
     176                                   (%temp-nsstring executable) $cfbundle-executable-key
     177                                   (%temp-nsstring getinfo-string) $cfbundle-getinfo-string-key
     178                                   (%temp-nsstring help-book-folder) $cfbundle-help-book-folder-key
     179                                   (%temp-nsstring help-book-name) $cfbundle-help-book-name-key
     180                                   (%temp-nsstring icon-file) $cfbundle-icon-file-key
     181                                   (%temp-nsstring bundle-identifier) $cfbundle-bundle-identifier-key
     182                                   (%temp-nsstring dictionary-version) $cfbundle-dictionary-version-key
     183                                   (%temp-nsstring bundle-name) $cfbundle-bundle-name-key
     184                                   (%temp-nsstring bundle-package-type) $cfbundle-bundle-package-type-key
     185                                   (%temp-nsstring short-version-string) $cfbundle-short-version-string-key
     186                                   (%temp-nsstring bundle-signature) $cfbundle-bundle-signature-key
     187                                   (%temp-nsstring version) $cfbundle-version-key
     188                                   (%temp-nsstring has-localized-display-name) $ls-has-localized-display-name-key
     189                                   (%temp-nsstring minimum-system-version) $ls-minimum-system-version-key
     190                                   (%temp-nsstring main-nib-file) $ns-main-nib-file-key
     191                                   (%temp-nsstring principal-class) $ns-principal-class-key
     192                                   +null-ptr+))
    145193
    146194;;; READ-INFO-PLIST info-path
     
    158206                                       info-path-str))))
    159207
    160 ;;; WRITE-INFO-PLIST path name package-type bundle-signature
    161 ;;; Reads the Info.plist file of the running IDE application
    162 ;;; into an NSMutableDictionary; sets the name, package-type,
    163 ;;; and bundle-signature from the inputs; writes the changed
    164 ;;; dictionary to a new Info.plist file at PATH.
    165 ;;;
    166 ;;; TODO: this function is extremely specialized to the case
    167 ;;;       of writing an Info.plist for an app bundle that is
    168 ;;;       copied from the IDE. Should separate the IDE-specific
    169 ;;;       behavior from more general behavior that can be used
    170 ;;;       by the batch builder, which does not depend on the IDE.
    171 (defun write-info-plist (out-path name package-type bundle-signature
     208(defun info-dict-from-specification (spec)
     209  (cond
     210    ((typep spec 'ns:ns-dictionary) spec)
     211    ((and (typep spec 'pathname)
     212          (string-equal (pathname-type spec) "plist")
     213          (probe-file spec)) (read-info-plist spec))
     214    (t (error "Argument to INFO-DICT-FROM-SPECIFICATION must be the pathname of a valid plist file or an instance of NSDictionary"))))
     215
     216;;; WRITE-INFO-PLIST info-plist path name package-type bundle-signature
     217;;; sets the name, package-type, and bundle-signature of the
     218;;; info-plist from the inputs; writes the changed dictionary to a new
     219;;; Info.plist file at PATH.
     220
     221(defun write-info-plist (info-dict out-path name package-type bundle-signature
    172222                         &key main-nib-name)
    173   ;; read the Info.plist of the IDE app, change
    174   ;; the fields needed, write the results to PATH
     223  ;; change the fields needed, write the results to PATH
    175224  (assert (or (null main-nib-name)
    176225              (stringp main-nib-name))
     
    178227          "The main-nib-name must be a string or NIL, not ~S" main-nib-name)
    179228  (with-autorelease-pool
    180     (let* ((bundle-name-key (%make-nsstring "CFBundleName"))
    181            (bundle-name-str (%make-nsstring name))
    182            (type-key (%make-nsstring "CFBundlePackageType"))
     229    (let* ((bundle-name-str (%make-nsstring name))
    183230           (type-str (%make-nsstring package-type))
    184            (sig-key (%make-nsstring "CFBundleSignature"))
    185231           (sig-str (%make-nsstring bundle-signature))
    186            (ide-bundle (#/mainBundle ns:ns-bundle))
    187            (ide-bundle-path-nsstring (#/bundlePath ide-bundle))
    188            (ide-bundle-path (ensure-directory-pathname
    189                              (lisp-string-from-nsstring ide-bundle-path-nsstring)))
    190            (ide-plist-path-str (namestring (path ide-bundle-path
    191                                                  "Contents" "Info.plist")))
    192            (info-dict (read-info-plist ide-plist-path-str))
    193            (app-name-key (%make-nsstring "CFBundleExecutable"))
    194232           (app-name-str (%make-nsstring name))
    195233           (app-plist-path-str (%make-nsstring (namestring out-path))))
    196       (#/setValue:forKey: info-dict bundle-name-str bundle-name-key)
    197       (#/setValue:forKey: info-dict app-name-str app-name-key)
    198       (#/setValue:forKey: info-dict type-str type-key)
    199       (#/setValue:forKey: info-dict sig-str sig-key)
     234      (#/setValue:forKey: info-dict bundle-name-str $cfbundle-bundle-name-key)
     235      (#/setValue:forKey: info-dict app-name-str $cfbundle-executable-key)
     236      (#/setValue:forKey: info-dict type-str $cfbundle-bundle-package-type-key)
     237      (#/setValue:forKey: info-dict sig-str $cfbundle-bundle-signature-key)
    200238      (when main-nib-name
    201239        (#/setValue:forKey: info-dict
    202240                            (%make-nsstring main-nib-name)
    203                             #@"NSMainNibFile"))
     241                            $ns-main-nib-file-key))
    204242      (#/writeToFile:atomically: info-dict app-plist-path-str #$YES))))
    205243
    206 
     244(defun get-ide-bundle-info-plist ()
     245  (let* ((ide-bundle (#/mainBundle ns:ns-bundle))
     246         (ide-bundle-path-nsstring (#/bundlePath ide-bundle))
     247         (ide-bundle-path (ensure-directory-pathname
     248                           (lisp-string-from-nsstring ide-bundle-path-nsstring)))
     249         (ide-plist-path-str (namestring (path ide-bundle-path
     250                                               "Contents" "Info.plist"))))
     251    (read-info-plist ide-plist-path-str)))
    207252
    208253;;; MAKE-APPLICATION-BUNDLE name package-type bundle-signature project-path
    209254;;; Build the directory structure of a Cocoa application bundle and
    210255;;; populate it with the required PkgInfo and Info.plist files.
    211 (defun make-application-bundle (name package-type bundle-signature project-path
    212                                 &key main-nib-name)
     256(defun make-application-bundle (&key
     257                                (name $default-application-bundle-name)
     258                                (project-path (current-directory)))
    213259  (let* ((app-bundle (path project-path
    214                            (ensure-directory-pathname (concatenate 'string name ".app"))))
     260                           (ensure-directory-pathname (concatenate 'string name ".app"))))
    215261         (contents-dir (path app-bundle (ensure-directory-pathname "Contents")))
    216262         (macos-dir (path contents-dir (ensure-directory-pathname "MacOS")))
     
    219265    (ensure-directories-exist macos-dir)
    220266    (ensure-directories-exist rsrc-dir)
    221     (write-info-plist (path app-bundle "Contents" "Info.plist")
    222                       name package-type bundle-signature :main-nib-name main-nib-name)
    223     (write-pkginfo (path app-bundle "Contents" "PkgInfo")
    224                    package-type bundle-signature)
    225267    app-bundle))
Note: See TracChangeset for help on using the changeset viewer.