source: trunk/base/src/package1.0/portmpkg.tcl @ 30781

Last change on this file since 30781 was 30781, checked in by afb@…, 13 years ago

pass package.flat option on

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