source: trunk/base/portmgr/packaging/mpkgall.tcl @ 59836

Last change on this file since 59836 was 49059, checked in by toby@…, 11 years ago

Remove the deprecated dport* procs. Not sure if the portmgr stuff even still works, just did a basic search and replace.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 10.3 KB
Line 
1#!/usr/bin/env tclsh
2# mpkgall.tcl
3# $Id: mpkgall.tcl 49059 2009-04-02 17:28:01Z toby@macports.org $
4#
5# Copyright (c) 2003 Kevin Van Vechten <kevin@opendarwin.org>
6# Copyright (c) 2002 Apple Computer, Inc.
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
18#    may be used to endorse or promote products derived from this software
19#    without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31# POSSIBILITY OF SUCH DAMAGE.
32
33package require darwinports
34
35# globals
36set portdir .
37array set ui_options {}
38
39proc ui_prefix {priority} {
40        return ""
41}
42
43proc ui_channels {priority} {
44        return {}
45}
46
47# copy binary packages if they've already been built.
48
49proc copy_package_if_available {portname basepath destpath} {
50
51        set dependencies {}
52
53        # XXX: don't overwrite Apple X11
54        # XXX: probably should exclude KDE here too
55        if {$portname == "XFree86"} { return {} }
56       
57        if {[catch {set res [mportsearch "^$portname\$"]} error]} {
58                puts stderr "Internal error: port search failed: $error"
59                return
60        }
61        foreach {name array} $res {
62                array set portinfo $array
63                if {![info exists portinfo(name)]} { return -1 }
64                if {![info exists portinfo(version)]} { return -1 }
65                if {![info exists portinfo(categories)]} { return -1 }
66               
67                set portname $portinfo(name)
68                set portversion $portinfo(version)
69                set category [lindex $portinfo(categories) 0]
70               
71                set depends {}
72                if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
73                if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
74                #if {[info exists portinfo(depends_build)]} { eval "lappend depends $portinfo(depends_build)" }
75                foreach depspec $depends {
76                        set dep [lindex [split $depspec :] end]
77                        set result [copy_package_if_available $dep $basepath $destpath]
78                        if {$result == -1} { 
79                                return -1
80                        } else {
81                                eval "lappend dependencies $result"
82                        }
83                }
84               
85                set pkgname "${portname}-${portversion}.pkg"
86                lappend dependencies $pkgname
87                set pkgpath "${basepath}/${category}/${pkgname}"
88                if {[file readable "${pkgpath}/Contents/Info.plist"]} {
89                        puts stderr "copying package: ${pkgpath} to ${destpath}"
90                        if {[catch {system "cp -R ${pkgpath} ${destpath}/"} error]} {
91                                puts stderr "Internal error: $error"
92                        }
93                } else {
94                        puts stderr "package ${pkgname} not found"
95                        return -1
96                }
97        }
98       
99        return $dependencies
100}
101
102proc write_description_plist {infofile portname portversion description} {
103        set infofd [open ${infofile} w+]
104        puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
105<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
106<plist version="1.0">
107}
108        puts $infofd "<dict>
109        <key>IFPkgDescriptionDeleteWarning</key>
110        <string></string>
111        <key>IFPkgDescriptionDescription</key>
112        <string>${description}</string>
113        <key>IFPkgDescriptionTitle</key>
114        <string>${portname}</string>
115        <key>IFPkgDescriptionVersion</key>
116        <string>${portversion}</string>
117</dict>
118</plist>"
119        close $infofd
120}
121
122proc write_welcome_html {filename portname portversion long_description description homepage} {
123    set fd [open ${filename} w+]
124    if {$long_description == ""} {
125        set long_description $description
126    }
127
128puts $fd "
129<html lang=\"en\">
130<head>
131        <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">
132        <title>Install ${portname}</title>
133</head>
134<body>
135<font face=\"Helvetica\"><b>Welcome to the ${portname} for Mac OS X Installer</b></font>
136<p>
137<font face=\"Helvetica\">${long_description}</font>
138<p>"
139
140    if {$homepage != ""} {
141        puts $fd "<font face=\"Helvetica\">${homepage}</font><p>"
142    }
143
144    puts $fd "<font face=\"Helvetica\">This installer guides you through the steps necessary to install ${portname} ${portversion} for Mac OS X. To get started, click Continue.</font>
145</body>
146</html>"
147
148    close $fd
149}
150
151proc write_PkgInfo {infofile} {
152        set infofd [open ${infofile} w+]
153        puts $infofd "pmkrpkg1"
154        close $infofd
155}
156
157proc mpkg_write_info_plist {infofile portname portversion portrevision destination dependencies} {
158        set vers [split $portversion "."]
159       
160        if {[string index $destination end] != "/"} {
161                append destination /
162        }
163       
164        set depxml ""
165        foreach dep $dependencies {
166                append depxml "<dict>
167                        <key>IFPkgFlagPackageLocation</key>
168                        <string>${dep}</string>
169                        <key>IFPkgFlagPackageSelection</key>
170                        <string>selected</string>
171                </dict>
172                "
173        }
174
175        set infofd [open ${infofile} w+]
176        puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
177<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
178<plist version="1.0">
179}
180        puts $infofd "<dict>
181        <key>CFBundleGetInfoString</key>
182        <string>${portname} ${portversion}</string>
183        <key>CFBundleIdentifier</key>
184        <string>org.opendarwin.darwinports.mpkg.${portname}</string>
185        <key>CFBundleName</key>
186        <string>${portname}</string>
187        <key>CFBundleShortVersionString</key>
188        <string>${portversion}</string>
189        <key>IFMajorVersion</key>
190        <integer>${portrevision}</integer>
191        <key>IFMinorVersion</key>
192        <integer>0</integer>
193        <key>IFPkgFlagComponentDirectory</key>
194        <string>./Contents/Resources</string>
195        <key>IFPkgFlagPackageList</key>
196        <array>
197                ${depxml}</array>
198        <key>IFPkgFormatVersion</key>
199        <real>0.10000000149011612</real>
200</dict>
201</plist>"
202        close $infofd
203}
204
205
206# Standard procedures
207
208proc fatal args {
209    global argv0
210    puts stderr "$argv0: $args"
211    exit
212}
213
214# Main
215array set options [list]
216array set variations [list]
217#       set ui_options(ports_verbose) yes
218
219if {[catch {mportinit ui_options options variations} result]} {
220    puts "Failed to initialize ports system, $result"
221    exit 1
222}
223
224package require Pextlib
225
226# If no arguments were given, default to all ports.
227if {[llength $argv] == 0} {
228        lappend argv ".*"
229}
230
231foreach pname $argv {
232
233if {[catch {set res [mportsearch "^${pname}\$"]} result]} {
234        puts "port search failed: $result"
235        exit 1
236}
237
238foreach {name array} $res {
239        global prefix
240        array unset portinfo
241        array set portinfo $array
242
243        if {![info exists portinfo(porturl)]} {
244                puts stderr "Internal error: no porturl for $name"
245                continue
246        }
247       
248        set pkgbase "/darwinports/pkgs/"
249        set mpkgbase "/darwinports/mpkgs/"
250        set porturl $portinfo(porturl)
251        set prefix "/opt/local"
252
253        # Skip up-to-date packages
254        if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
255                if {[info exists portinfo(name)] &&
256                        [info exists portinfo(version)] &&
257                        [info exists portinfo(categories)]} {
258                        set portname $portinfo(name)
259                        set portversion $portinfo(version)
260                        set category [lindex $portinfo(categories) 0]
261                        set mpkgfile ${mpkgbase}/${category}/${portname}-${portversion}.mpkg/Contents/Info.plist
262                        if {[file readable $mpkgfile] && ([file mtime ${mpkgfile}] > [file mtime ${portpath}/Portfile])} {
263                                puts stderr "Skipping ${portname}-${portversion}; meta-package is up to date."
264                                continue
265                        }
266                }
267        }
268       
269        # Skipt packages which previously failed
270               
271        # Building the mpkg:
272        # - create an mpkg skeleton
273        # - copy dependent pkgs into Contents/Resources directory
274
275        set portname ""
276        set portversion ""
277        set description ""
278        set long_description ""
279        set homepage ""
280        set category ""
281
282        if {[info exists portinfo(name)]} {     set portname $portinfo(name) }
283        if {[info exists portinfo(version)]} { set portversion $portinfo(version) }
284        if {[info exists portinfo(description)]} { set description $portinfo(description) }
285        if {[info exists portinfo(long_description)]} { set long_description $portinfo(long_description) }
286        if {[info exists portinfo(homepage)]} { set homepage $portinfo(homepage) }
287        if {[info exists portinfo(categories)]} { set category [lindex $portinfo(categories) 0] }
288        if {[info exists portinfo(maintainers)]} { set maintainers $portinfo(maintainers) }
289       
290        puts "meta-packaging ${category}/${portname}-${portversion}"
291
292        set mpkgpath "${mpkgbase}/${category}/${portname}-${portversion}.mpkg"
293
294        if {[catch {system "mkdir -p -m 0755 ${mpkgpath}/Contents/Resources"} error]} {
295                puts stderr "Internal error: $error"
296        }
297       
298        # list of .pkg names for dependencies,
299        # built up by copy_package_if_available, and used in the Info.plist
300        set dependencies {}
301        set result [copy_package_if_available ${portname} $pkgbase "${mpkgpath}/Contents/Resources/"]
302        if {$result == -1} {
303                puts stderr "aborting; one or more dependencies was missing."
304                if {[catch {system "rm -R ${mpkgpath}"} error]} {
305                        puts stderr "Internal error: $error"
306                }
307                continue
308        } else {
309                set result [lsort -uniq $result]
310                eval "lappend dependencies $result"
311        }
312       
313        #
314        # Begin quote from portmpkg.tcl
315        #
316    write_PkgInfo ${mpkgpath}/Contents/PkgInfo
317    mpkg_write_info_plist ${mpkgpath}/Contents/Info.plist $portname $portversion $prefix $dependencies
318    write_description_plist ${mpkgpath}/Contents/Resources/Description.plist $portname $portversion $description
319    # long_description, description, or homepage may not exist
320    foreach variable {long_description description homepage} {
321        if {![info exists $variable]} {
322            set pkg_$variable ""
323        } else {
324            set pkg_$variable [set $variable]
325        }
326    }
327    write_welcome_html ${mpkgpath}/Contents/Resources/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
328    file copy -force -- /opt/local/share/darwinports/resources/port1.0/package/background.tiff \
329                        ${mpkgpath}/Contents/Resources/background.tiff
330        #
331        # End quote from portmpkg.tcl
332        #
333}
334
335}
336# end foreach pname
Note: See TracBrowser for help on using the repository browser.