source: trunk/base/src/port1.0/portmpkg.tcl @ 1607

Last change on this file since 1607 was 1607, checked in by landonf (Landon Fuller), 18 years ago

Pull contents out of registry, and do not set package destination to install prefix
This allows us to support ports who have files that must be installed in /

  • Property svn:eol-style set to native
File size: 6.5 KB
Line 
1# et:ts=4
2# portpackage.tcl
3#
4# Copyright (c) 2002 Apple Computer, Inc.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
16#    may be used to endorse or promote products derived from this software
17#    without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGE.
30#
31
32package provide portmpkg 1.0
33package require portutil 1.0
34
35set com.apple.mpkg [target_new com.apple.mpkg mpkg_main]
36${com.apple.mpkg} set runtype always
37${com.apple.mpkg} provides mpkg
38${com.apple.mpkg} requires package
39
40# define options
41options package.type package.destpath
42
43set UI_PREFIX "---> "
44
45proc mpkg_main {args} {
46    global portname portversion package.type package.destpath UI_PREFIX
47
48    # Make sure the destination path exists.
49    system "mkdir -p ${package.destpath}"
50
51    # For now we only support pkg and tarball package types.
52    switch -exact -- ${package.type} {
53        pkg {
54            return [package_mpkg $portname $portversion]
55        }
56        default {
57            ui_error "Do not know how to generate package of type ${package.type}"
58            return -code error "Unknown package type: ${package.type}"
59        }
60    }
61}
62
63proc package_mpkg {portname portversion} {
64    global portdbpath destpath workpath contents prefix portresourcepath description package.destpath long_description homepage depends_run depends_lib
65
66        # get the union of depends_run and depends_lib, ignore everything but the portfile.
67        set depends {}
68        if {[info exists depends_run]} {eval "lappend depends $depends_run"}
69        if {[info exists depends_lib]} {eval "lappend depends $depends_lib"}
70        set ports {}
71        foreach depspec $depends {
72                set depname [lindex [split $depspec :] 2]
73
74                # nasty hack
75                if {$depname != "XFree86"} {
76                        lappend ports $depname
77                }
78        }
79        set ports [lsort -unique $ports]
80
81        set pkgpath ${package.destpath}/${portname}.pkg
82        set mpkgpath ${package.destpath}/${portname}.mpkg
83        system "mkdir -p -m 0755 ${mpkgpath}/Contents/Resources"
84
85        if {[llength $ports] > 0} {
86                set dependencies {}
87               
88                # Create mpkgs for each of our dependencies inside our resources directory.
89                foreach port $ports {
90                        if {[catch {set res [dportsearch "^$port\$"]} result]} {
91                                ui_error "port search failed: $result"
92                                return 1
93                        }
94                        foreach {name array} $res {
95                                array set portinfo $array
96                               
97                                if [info exists portinfo(porturl)] {
98                                        # only the prefix gets passed to the worker.
99                                        set worker [dportopen $portinfo(porturl) [list prefix $prefix package.destpath ${mpkgpath}/Contents/Resources]]
100                                        if {[info exists portinfo(depends_run)] || [info exists portinfo(depends_lib)]} {
101                                                dportexec $worker mpkg
102                                                lappend dependencies ${portinfo(name)}.mpkg
103                                                # Remove intermediate .pkg, since the .pkg will have been copied into the .mpkg resources directory.
104                                                system "rm -R ${mpkgpath}/Contents/Resources/${portinfo(name)}.pkg"
105                                        } else {
106                                                dportexec $worker package
107                                                lappend dependencies ${portinfo(name)}.pkg
108                                        }
109                                }
110                               
111                                unset portinfo
112                        }
113                }
114        }
115       
116        # copy our own pkg into the mpkg
117        system "cp -RPp ${pkgpath} ${mpkgpath}/Contents/Resources/"
118        lappend dependencies ${portname}.pkg
119       
120    write_PkgInfo ${mpkgpath}/Contents/PkgInfo
121    write_info_file ${mpkgpath}/Contents/Resources/${portname}.info $portname $portversion $description
122    mpkg_write_info_plist ${mpkgpath}/Contents/Info.plist $portname $portversion $prefix $dependencies
123    write_description_plist ${mpkgpath}/Contents/Resources/Description.plist $portname $portversion $description
124    # long_description, description, or homepage may not exist
125    foreach variable {long_description description homepage} {
126        if {![info exists $variable]} {
127            set pkg_$variable ""
128        } else {
129            set pkg_$variable [set $variable]
130        }
131    }
132    write_welcome_rtf ${mpkgpath}/Contents/Resources/Welcome.rtf $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
133    file copy -force -- ${portresourcepath}/package/background.tiff ${mpkgpath}/Contents/Resources/background.tiff
134
135        return 0
136}
137
138proc mpkg_write_info_plist {infofile portname portversion destination dependencies} {
139        set vers [split $portversion "."]
140        set major [lindex $vers 0]
141        set minor [lindex $vers 1]
142        if {$major == ""} {set major "0"}
143        if {$minor == ""} {set minor "0"}
144       
145        if {[string index $destination end] != "/"} {
146                append destination /
147        }
148       
149        set depxml ""
150        foreach dep $dependencies {
151                append depxml "<dict>
152                        <key>IFPkgFlagPackageLocation</key>
153                        <string>${dep}</string>
154                        <key>IFPkgFlagPackageSelection</key>
155                        <string>selected</string>
156                </dict>
157                "
158        }
159
160        set infofd [open ${infofile} w+]
161        puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
162<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
163<plist version="1.0">
164}
165        puts $infofd "<dict>
166        <key>CFBundleGetInfoString</key>
167        <string>${portname} ${portversion}</string>
168        <key>CFBundleIdentifier</key>
169        <string>org.opendarwin.darwinports.mpkg.${portname}</string>
170        <key>CFBundleName</key>
171        <string>${portname}</string>
172        <key>CFBundleShortVersionString</key>
173        <string>${portversion}</string>
174        <key>IFMajorVersion</key>
175        <integer>${major}</integer>
176        <key>IFMinorVersion</key>
177        <integer>${minor}</integer>
178        <key>IFPkgFlagComponentDirectory</key>
179        <string>./Contents/Resources</string>
180        <key>IFPkgFlagPackageList</key>
181        <array>
182                ${depxml}</array>
183        <key>IFPkgFormatVersion</key>
184        <real>0.10000000149011612</real>
185</dict>
186</plist>"
187        close $infofd
188}
Note: See TracBrowser for help on using the repository browser.