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

Last change on this file since 116518 was 116518, checked in by cal@…, 7 years ago

portmgr/packaging: whitespace only, unify whitespace, reindent

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 10.2 KB
Line 
1#!/usr/bin/env tclsh
2# mpkgall.tcl
3# $Id: mpkgall.tcl 116518 2014-01-27 15:39:11Z cal@macports.org $
4#
5# Copyright (c) 2003 Kevin Van Vechten <kevin@opendarwin.org>
6# Copyright (c) 2002 Apple 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 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//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 eq ""} {
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 ne ""} {
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] ne "/"} {
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//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        if {[catch {set res [mportsearch "^${pname}\$"]} result]} {
233                puts "port search failed: $result"
234                exit 1
235        }
236
237        foreach {name array} $res {
238                global prefix
239                array unset portinfo
240                array set portinfo $array
241
242                if {![info exists portinfo(porturl)]} {
243                        puts stderr "Internal error: no porturl for $name"
244                        continue
245                }
246
247                set pkgbase "/darwinports/pkgs/"
248                set mpkgbase "/darwinports/mpkgs/"
249                set porturl $portinfo(porturl)
250                set prefix "/opt/local"
251
252                # Skip up-to-date packages
253                if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
254                        if {[info exists portinfo(name)] &&
255                                [info exists portinfo(version)] &&
256                                [info exists portinfo(categories)]} {
257                                set portname $portinfo(name)
258                                set portversion $portinfo(version)
259                                set category [lindex $portinfo(categories) 0]
260                                set mpkgfile ${mpkgbase}/${category}/${portname}-${portversion}.mpkg/Contents/Info.plist
261                                if {[file readable $mpkgfile] && ([file mtime ${mpkgfile}] > [file mtime ${portpath}/Portfile])} {
262                                        puts stderr "Skipping ${portname}-${portversion}; meta-package is up to date."
263                                        continue
264                                }
265                        }
266                }
267
268                # Skipt packages which previously failed
269
270                # Building the mpkg:
271                # - create an mpkg skeleton
272                # - copy dependent pkgs into Contents/Resources directory
273
274                set portname ""
275                set portversion ""
276                set description ""
277                set long_description ""
278                set homepage ""
279                set category ""
280
281                if {[info exists portinfo(name)]} {     set portname $portinfo(name) }
282                if {[info exists portinfo(version)]} { set portversion $portinfo(version) }
283                if {[info exists portinfo(description)]} { set description $portinfo(description) }
284                if {[info exists portinfo(long_description)]} { set long_description $portinfo(long_description) }
285                if {[info exists portinfo(homepage)]} { set homepage $portinfo(homepage) }
286                if {[info exists portinfo(categories)]} { set category [lindex $portinfo(categories) 0] }
287                if {[info exists portinfo(maintainers)]} { set maintainers $portinfo(maintainers) }
288
289                puts "meta-packaging ${category}/${portname}-${portversion}"
290
291                set mpkgpath "${mpkgbase}/${category}/${portname}-${portversion}.mpkg"
292
293                if {[catch {system "mkdir -p -m 0755 ${mpkgpath}/Contents/Resources"} error]} {
294                        puts stderr "Internal error: $error"
295                }
296
297                # list of .pkg names for dependencies,
298                # built up by copy_package_if_available, and used in the Info.plist
299                set dependencies {}
300                set result [copy_package_if_available ${portname} $pkgbase "${mpkgpath}/Contents/Resources/"]
301                if {$result == -1} {
302                        puts stderr "aborting; one or more dependencies was missing."
303                        if {[catch {system "rm -R ${mpkgpath}"} error]} {
304                                puts stderr "Internal error: $error"
305                        }
306                        continue
307                } else {
308                        set result [lsort -uniq $result]
309                        eval "lappend dependencies $result"
310                }
311
312                #
313                # Begin quote from portmpkg.tcl
314                #
315                write_PkgInfo ${mpkgpath}/Contents/PkgInfo
316                mpkg_write_info_plist ${mpkgpath}/Contents/Info.plist $portname $portversion $prefix $dependencies
317                write_description_plist ${mpkgpath}/Contents/Resources/Description.plist $portname $portversion $description
318                # long_description, description, or homepage may not exist
319                foreach variable {long_description description homepage} {
320                        if {![info exists $variable]} {
321                                set pkg_$variable ""
322                        } else {
323                                set pkg_$variable [set $variable]
324                        }
325                }
326                write_welcome_html ${mpkgpath}/Contents/Resources/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
327                file copy -force -- /opt/local/share/darwinports/resources/port1.0/package/background.tiff \
328                        ${mpkgpath}/Contents/Resources/background.tiff
329                #
330                # End quote from portmpkg.tcl
331                #
332        }
333}
334# end foreach pname
Note: See TracBrowser for help on using the repository browser.