source: trunk/base/src/package1.0/portpkg.tcl @ 42662

Last change on this file since 42662 was 42662, checked in by raimue@…, 12 years ago

Merged revisions 34469,34852,34854-34855,34900,36952-36956,37507-37508,37511-37512,41040,41042-41046,41138-41139,41142-41143,41145,41151,41403,41458,41462-41463,42575,42626,42640-42641,42659 via svnmerge from
https://svn.macosforge.org/repository/macports/branches/variant-descs-14482/base

........

r34469 | raimue@… | 2008-02-26 07:08:09 +0100 (Tue, 26 Feb 2008) | 3 lines


port/port.tcl:
Reading from .config/variant_descriptions actually works

........

r34852 | raimue@… | 2008-03-09 02:45:22 +0100 (Sun, 09 Mar 2008) | 4 lines


macports1.0/macports.tcl:
New API: macports::getsourceconfigdir
Returns the path to .config for a porturl.

........

r34854 | raimue@… | 2008-03-09 03:11:27 +0100 (Sun, 09 Mar 2008) | 3 lines


port/port.tcl:
Use new API macports::getsourceconfigdir

........

r34855 | raimue@… | 2008-03-09 03:12:54 +0100 (Sun, 09 Mar 2008) | 3 lines


port/port.tcl:
Treat variant descriptions as strings to avoid problems with braces

........

r34900 | raimue@… | 2008-03-10 16:54:25 +0100 (Mon, 10 Mar 2008) | 3 lines


port/port.tcl:
Rename variable

........

r36952 | raimue@… | 2008-05-21 04:20:27 +0200 (Wed, 21 May 2008) | 3 lines


port/port.tcl:
Remove get_variant_desc, this will now be done in port1.0/portutil.tcl instead

........

r36953 | raimue@… | 2008-05-21 04:22:04 +0200 (Wed, 21 May 2008) | 3 lines


macports1.0/macports.tcl:
Give the worker access to variable porturl and proc getsourceconfigdir

........

r36954 | raimue@… | 2008-05-21 04:23:37 +0200 (Wed, 21 May 2008) | 3 lines


port1.0/tests:
Fix the portutil test after r36953

........

r36955 | raimue@… | 2008-05-21 05:01:11 +0200 (Wed, 21 May 2008) | 3 lines


macports1.0/macports.tcl:
Give worker access to getprotocol and getportdir as they are needed for getsourceconfigdir

........

r36956 | raimue@… | 2008-05-21 05:02:23 +0200 (Wed, 21 May 2008) | 3 lines


port1.0/portutil.tcl:
New proc variant_desc, reads global variant description file

........

r37507 | raimue@… | 2008-06-10 16:04:54 +0200 (Tue, 10 Jun 2008) | 4 lines


port1.0/portutil.tcl:
Don't warn about a missing description if it is set global,
but warn if the variant overrides the global description

........

r37508 | raimue@… | 2008-06-10 16:14:03 +0200 (Tue, 10 Jun 2008) | 3 lines


macports1.0/macports.tcl:
Use .resources instead of .config as it is a bit clearer, see #14553

........

r37511 | raimue@… | 2008-06-10 17:22:12 +0200 (Tue, 10 Jun 2008) | 5 lines


port1.0/portutil.tcl:
Switch back to this format:
name {description}
So this could be easily extended if ever needed.

........

r37512 | raimue@… | 2008-06-10 17:27:48 +0200 (Tue, 10 Jun 2008) | 3 lines


port1.0/portutil.tcl:
Add a warning if global variant description file could not be opened

........

r41040 | raimue@… | 2008-10-21 13:06:39 +0200 (Tue, 21 Oct 2008) | 4 lines


macports/macport.tcl:

  • New flag "default" for sources to indicate fallback for resources (group)
  • Add parameter to getsourceconfigdir to get path for a requested file

........

r41042 | raimue@… | 2008-10-21 13:11:44 +0200 (Tue, 21 Oct 2008) | 3 lines


macports1.0/macports.tcl:
Rename getsourceconfigdir to getportresourcepath

........

r41043 | raimue@… | 2008-10-21 13:15:16 +0200 (Tue, 21 Oct 2008) | 3 lines


port1.0/portutil.tcl:
Use getportresourcepath for the group files

........

r41044 | raimue@… | 2008-10-21 13:19:47 +0200 (Tue, 21 Oct 2008) | 3 lines


port1.0/portlint.tcl:
Use getresourcepath for group files

........

r41045 | raimue@… | 2008-10-21 13:20:36 +0200 (Tue, 21 Oct 2008) | 3 lines


port1.0/portmain.tcl:
Add a note that we should get rid of $portresourcepath in favor of [getportresourcepath]

........

r41046 | raimue@… | 2008-10-21 13:40:29 +0200 (Tue, 21 Oct 2008) | 3 lines


port1.0/portutil.tcl:
Missed one instance of getsourceconfigdir

........

r41138 | raimue@… | 2008-10-25 20:52:50 +0200 (Sat, 25 Oct 2008) | 3 lines


port1.0/portutil.tcl:
Use getportresourcepath for global variant descriptions

........

r41139 | raimue@… | 2008-10-25 21:23:15 +0200 (Sat, 25 Oct 2008) | 3 lines


port1.0/portmain.tcl:
Correct XXX tag

........

r41142 | raimue@… | 2008-10-25 23:11:30 +0200 (Sat, 25 Oct 2008) | 3 lines


port1.0/portfetch.tcl:
Use getportresourcepath

........

r41143 | raimue@… | 2008-10-25 23:12:04 +0200 (Sat, 25 Oct 2008) | 3 lines


port1.0/portdestroot.tcl:
Use getportresourcepath

........

r41145 | raimue@… | 2008-10-26 00:04:15 +0200 (Sun, 26 Oct 2008) | 3 lines


macports1.0/macports.tcl:
Fix a problem with URLs not using the file protocol

........

r41151 | raimue@… | 2008-10-26 03:09:54 +0100 (Sun, 26 Oct 2008) | 3 lines


macports1.0/macports.tcl:
Fix issues introduced in r41145, the file exists check was wrong

........

r41403 | raimue@… | 2008-11-01 22:59:21 +0100 (Sat, 01 Nov 2008) | 3 lines


port1.0/portutil.tcl:
Add a debug output which group files are used

........

r41458 | blb@… | 2008-11-03 22:58:28 +0100 (Mon, 03 Nov 2008) | 2 lines


Add [default] tag and description to sources.conf

........

r41462 | blb@… | 2008-11-04 02:12:28 +0100 (Tue, 04 Nov 2008) | 2 lines


No longer need to install resources with base

........

r41463 | blb@… | 2008-11-04 02:14:49 +0100 (Tue, 04 Nov 2008) | 4 lines


Move the install/ subdir (containing the mtree files) into .../share/macports
from the resources dir (the mtree contains a bit of install-time info, so it
shouldn't be with the resources stuff in the port tree)

........

r42575 | blb@… | 2008-11-25 01:53:05 +0100 (Tue, 25 Nov 2008) | 3 lines


Add script to handle upgrades through configure/make/make install and
the package, so [default] is added as appropriate to sources.conf

........

r42626 | raimue@… | 2008-11-27 02:21:15 +0100 (Thu, 27 Nov 2008) | 3 lines


package1.0/portpkg.tcl, package1.0/portmpkg.tcl:
Remove portresourcepath and use [getportresourcepath] instead

........

r42640 | raimue@… | 2008-11-27 11:49:32 +0100 (Thu, 27 Nov 2008) | 3 lines


package1.0/portrpm.tcl, package1.0/portsrpm.tcl:
Remove reference to portresurcepath which is not used at all

........

r42641 | raimue@… | 2008-11-27 11:52:12 +0100 (Thu, 27 Nov 2008) | 3 lines


port1.0/portmain.tcl:
Remove definition of portresourcepath as it is not used any more

........

r42659 | raimue@… | 2008-11-28 16:44:30 +0100 (Fri, 28 Nov 2008) | 3 lines


macports1.0/macports.tcl:
Rename portresourcepath from .resources to _resources

........

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.1 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
2# portpkg.tcl
3# $Id: portpkg.tcl 42662 2008-11-28 23:18:50Z raimue@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 portpkg 1.0
34package require portutil 1.0
35
36set org.macports.pkg [target_new org.macports.pkg pkg_main]
37target_runtype ${org.macports.pkg} always
38target_provides ${org.macports.pkg} pkg
39if {[option portarchivemode] == "yes"} {
40    target_requires ${org.macports.pkg} unarchive destroot
41} else {
42    target_requires ${org.macports.pkg} destroot
43}
44
45# define options
46options package.type package.destpath package.flat
47
48# Set defaults
49default package.destpath {${workpath}}
50default package.flat     false
51
52set_ui_prefix
53
54proc pkg_main {args} {
55    global portname portversion portrevision package.type package.destpath package.flat UI_PREFIX
56
57    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating pkg for %s-%s"] ${portname} ${portversion}]"
58
59    return [package_pkg $portname $portversion $portrevision]
60}
61
62proc package_pkg {portname portversion portrevision} {
63    global UI_PREFIX portdbpath destpath workpath prefix description package.destpath package.flat long_description homepage portpath porturl
64    global os.version os.major
65
66    set pkgpath ${package.destpath}/${portname}-${portversion}.pkg
67
68    if {[file readable $pkgpath] && ([file mtime ${pkgpath}] >= [file mtime ${portpath}/Portfile])} {
69        ui_msg "$UI_PREFIX [format [msgcat::mc "Package for %s-%s is up-to-date"] ${portname} ${portversion}]"
70        return 0
71    }
72
73    set packagemaker "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker"
74    if ([file exists "$packagemaker"]) {
75        set resourcepath ${workpath}/pkg_resources
76    } else {
77        set resourcepath "${pkgpath}/Contents/Resources"
78    }
79
80    set language "English"
81    system "mkdir -p -m 0755 ${resourcepath}/$language.lproj"
82       
83    # long_description, description, or homepage may not exist
84    foreach variable {long_description description homepage} {
85        if {![info exists $variable]} {
86            set pkg_$variable ""
87        } else {
88            set pkg_$variable [set $variable]
89        }
90    }
91    write_welcome_html ${resourcepath}/${language}.lproj/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
92    file copy -force -- [getportresourcepath $porturl "port1.0/package/background.tiff"] ${resourcepath}/${language}.lproj/background.tiff
93
94    foreach dir {etc var tmp} {
95        if ([file exists "${destpath}/$dir"]) {
96            # certain toplevel directories really are symlinks. leaving them as directories make pax lose the symlinks. that's bad.
97            system "mkdir -p ${destpath}/private/$dir; mv ${destpath}/$dir/* ${destpath}/private/$dir; rm -r \"${destpath}/$dir\""
98        }
99    }
100
101    if ([file exists "$packagemaker"]) {
102
103        ui_debug "Calling $packagemaker for $portname pkg"
104        if {${os.major} >= 9} {
105            if {${package.flat}} {
106                set pkgtarget "10.5"
107                set pkgresources ""
108                set infofile "${workpath}/PackageInfo"
109                write_package_info ${workpath}/PackageInfo $portname $portversion $portrevision
110            } else {
111                set pkgtarget "10.3"
112                set pkgresources " --resources ${resourcepath} --title \"$portname-$portversion\""
113                set infofile "${workpath}/Info.plist"
114                write_info_plist ${workpath}/Info.plist $portname $portversion $portrevision
115            }
116            system "PMResourceLocale=${language} $packagemaker -AppleLanguages \"(${language})\" --root ${destpath} --out ${pkgpath} ${pkgresources} --info $infofile --target $pkgtarget --domain system --id org.macports.$portname"
117        } else {
118            write_info_plist ${workpath}/Info.plist $portname $portversion $portrevision
119            write_description_plist ${workpath}/Description.plist $portname $portversion $description
120            system "$packagemaker -build -f ${destpath} -p ${pkgpath} -r ${resourcepath} -i ${workpath}/Info.plist -d ${workpath}/Description.plist"
121        }
122
123        file delete ${workpath}/Info.plist
124        file delete ${workpath}/PackageInfo
125        file delete ${workpath}/Description.plist
126        file delete -force ${workpath}/pkg_resources
127
128    } else {
129
130        write_PkgInfo ${pkgpath}/Contents/PkgInfo
131        write_info_plist ${pkgpath}/Contents/Info.plist $portname $portversion $portrevision
132
133        system "mkbom ${destpath} ${pkgpath}/Contents/Archive.bom"
134        system "cd ${destpath} && pax -x cpio -w -z . > ${pkgpath}/Contents/Archive.pax.gz"
135
136        write_description_plist ${resourcepath}/Description.plist $portname $portversion $description
137        write_sizes_file ${resourcepath}/Archive.sizes ${portname} ${portversion} ${pkgpath} ${destpath}
138
139    }
140
141    foreach dir {etc var tmp} {
142        if ([file exists "${destpath}/private/$dir"]) {
143            # restore any directories that were moved, to avoid confusing the rest of the ports system.
144            system "mv ${destpath}/private/$dir ${destpath}/$dir; rmdir ${destpath}/private 2>/dev/null"
145        }
146    }
147
148    return 0
149}
150
151proc write_PkgInfo {infofile} {
152    set infofd [open ${infofile} w+]
153    puts $infofd "pmkrpkg1"
154    close $infofd
155}
156
157# XXX: deprecated
158proc write_info_file {infofile portname portversion description} {
159    set infofd [open ${infofile} w+]
160    puts $infofd "Title ${portname}
161Version ${portversion}
162Description ${description}
163DefaultLocation /
164DeleteWarning
165
166### Package Flags
167
168NeedsAuthorization YES
169Required NO
170Relocatable NO
171RequiresReboot NO
172UseUserMask YES
173OverwritePermissions NO
174InstallFat NO
175RootVolumeOnly NO"
176    close $infofd
177}
178
179proc xml_escape {s} {
180    regsub -all {&} $s {\&} s
181    regsub -all {<} $s {\&lt;} s
182    regsub -all {>} $s {\&gt;} s
183    return $s
184}
185
186proc write_info_plist {infofile portname portversion portrevision} {
187    set portname [xml_escape $portname]
188    set portversion [xml_escape $portversion]
189    set portrevision [xml_escape $portrevision]
190
191    set infofd [open ${infofile} w+]
192    puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
193<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
194<plist version="1.0">
195    }
196    puts $infofd "<dict>
197    <key>CFBundleGetInfoString</key>
198    <string>${portname} ${portversion}</string>
199    <key>CFBundleIdentifier</key>
200    <string>org.macports.${portname}</string>
201    <key>CFBundleName</key>
202    <string>${portname}</string>
203    <key>CFBundleShortVersionString</key>
204    <string>${portversion}</string>
205    <key>IFMajorVersion</key>
206    <integer>${portrevision}</integer>
207    <key>IFMinorVersion</key>
208    <integer>0</integer>
209    <key>IFPkgFlagAllowBackRev</key>
210    <true/>
211    <key>IFPkgFlagAuthorizationAction</key>
212    <string>RootAuthorization</string>
213    <key>IFPkgFlagDefaultLocation</key>
214    <string>/</string>
215    <key>IFPkgFlagInstallFat</key>
216    <false/>
217    <key>IFPkgFlagIsRequired</key>
218    <false/>
219    <key>IFPkgFlagRelocatable</key>
220    <false/>
221    <key>IFPkgFlagRestartAction</key>
222    <string>NoRestart</string>
223    <key>IFPkgFlagRootVolumeOnly</key>
224    <false/>
225    <key>IFPkgFlagUpdateInstalledLanguages</key>
226    <false/>
227    <key>IFPkgFormatVersion</key>
228    <real>0.10000000149011612</real>
229</dict>
230</plist>"
231    close $infofd
232}
233
234proc write_description_plist {infofile portname portversion description} {
235    set portname [xml_escape $portname]
236    set portversion [xml_escape $portversion]
237    set description [xml_escape $description]
238
239    set infofd [open ${infofile} w+]
240    puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
241<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
242<plist version="1.0">
243    }
244    puts $infofd "<dict>
245    <key>IFPkgDescriptionDeleteWarning</key>
246    <string></string>
247    <key>IFPkgDescriptionDescription</key>
248    <string>${description}</string>
249    <key>IFPkgDescriptionTitle</key>
250    <string>${portname}</string>
251    <key>IFPkgDescriptionVersion</key>
252    <string>${portversion}</string>
253</dict>
254</plist>"
255    close $infofd
256}
257
258proc write_welcome_html {filename portname portversion long_description description homepage} {
259    set fd [open ${filename} w+]
260    if {$long_description == ""} {
261        set long_description $description
262    }
263
264    set portname [xml_escape $portname]
265    set portversion [xml_escape $portversion]
266    set long_description [xml_escape $long_description]
267    set description [xml_escape $description]
268    set homepage [xml_escape $homepage]
269       
270    puts $fd "
271<html lang=\"en\">
272<head>
273        <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">
274        <title>Install ${portname}</title>
275</head>
276<body>
277<font face=\"Helvetica\"><b>Welcome to the ${portname} for Mac OS X Installer</b></font>
278<p>
279<font face=\"Helvetica\">${long_description}</font>
280<p>"
281
282    if {$homepage != ""} {
283        puts $fd "<font face=\"Helvetica\"><a href=\"${homepage}\">${homepage}</a></font><p>"
284    }
285
286    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>
287</body>
288</html>"
289
290    close $fd
291}
292
293proc write_sizes_file {sizesfile portname portversion pkgpath destpath} {
294   
295    if {[catch {set numFiles [exec lsbom -s ${pkgpath}/Contents/Archive.bom | wc -l]} result]} {
296        return -code error [format [msgcat::mc "Reading package bom failed: %s"] $result]
297    }
298    if {[catch {set compressedSize [expr [dirSize ${pkgpath}] / 1024]} result]} {
299        return -code error [format [msgcat::mc "Error determining compressed size: %s"] $result]
300    }
301    if {[catch {set installedSize [expr [dirSize ${destpath}] / 1024]} result]} {
302        return -code error [format [msgcat::mc "Error determining installed size: %s"] $result]
303    }
304    if {[catch {set infoSize [file size ${pkgpath}/Contents/Info.plist]} result]} {
305       return -code error [format [msgcat::mc "Error determining plist file size: %s"] $result]
306    }
307    if {[catch {set bomSize [file size ${pkgpath}/Contents/Archive.bom]} result]} {
308        return -code error [format [msgcat::mc "Error determining bom file size: %s"] $result]
309    }
310    incr installedSize $infoSize
311    incr installedSize $bomSize
312       
313    set fd [open ${sizesfile} w+]
314    puts $fd "NumFiles $numFiles
315InstalledSize $installedSize
316CompressedSize $compressedSize"
317    close $fd
318}
319
320proc write_package_info {infofile portname portversion portrevision} {
321    set portname [xml_escape $portname]
322    set portversion [xml_escape $portversion]
323    set portrevision [xml_escape $portrevision]
324
325    set infofd [open ${infofile} w+]
326    puts $infofd "
327<pkg-info install-location=\"/\" relocatable=\"false\" auth=\"root\">
328</pkg-info>"
329    close $infofd
330}
Note: See TracBrowser for help on using the repository browser.