source: trunk/base/src/port1.0/portdestroot.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: 13.3 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# portdestroot.tcl
3# $Id: portdestroot.tcl 42662 2008-11-28 23:18:50Z raimue@macports.org $
4#
5# Copyright (c) 2002 - 2003 Apple Computer, Inc.
6# Copyright (c) 2004 - 2005 Robert Shaw <rshaw@opendarwin.org>
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#
33
34package provide portdestroot 1.0
35package require portutil 1.0
36
37set org.macports.destroot [target_new org.macports.destroot destroot_main]
38target_provides ${org.macports.destroot} destroot
39target_requires ${org.macports.destroot} main fetch extract checksum patch configure build
40target_prerun ${org.macports.destroot} destroot_start
41target_postrun ${org.macports.destroot} destroot_finish
42
43# define options
44options destroot.target destroot.destdir destroot.clean destroot.keepdirs destroot.umask
45options destroot.violate_mtree
46options startupitem.create startupitem.requires startupitem.init
47options startupitem.name startupitem.start startupitem.stop startupitem.restart
48options startupitem.type startupitem.executable
49options startupitem.pidfile startupitem.logfile startupitem.logevents startupitem.netchange
50options startupitem.uniquename startupitem.plist startupitem.location
51commands destroot
52
53# Set defaults
54default destroot.dir {${build.dir}}
55default destroot.cmd {${build.cmd}}
56default destroot.pre_args {${destroot.target}}
57default destroot.target install
58default destroot.post_args {${destroot.destdir}}
59default destroot.destdir {DESTDIR=${destroot}}
60default destroot.umask {$system_options(destroot_umask)}
61default destroot.clean no
62default destroot.keepdirs ""
63default destroot.violate_mtree no
64
65default startupitem.name        {${portname}}
66default startupitem.uniquename  {org.macports.${startupitem.name}}
67default startupitem.plist       {${startupitem.uniquename}.plist}
68default startupitem.location    LaunchDaemons
69default startupitem.init        ""
70default startupitem.start       ""
71default startupitem.stop        ""
72default startupitem.restart     ""
73default startupitem.requires    ""
74default startupitem.executable  ""
75default startupitem.type        {$system_options(startupitem_type)}
76default startupitem.pidfile     ""
77default startupitem.logfile     ""
78default startupitem.logevents   no
79default startupitem.netchange   no
80
81set_ui_prefix
82
83namespace eval destroot {
84    # Save old umask
85    variable oldmask
86}
87
88proc destroot_start {args} {
89    global UI_PREFIX prefix portname porturl destroot os.platform destroot.clean portsharepath
90    global destroot::oldmask destroot.umask
91   
92    ui_msg "$UI_PREFIX [format [msgcat::mc "Staging %s into destroot"] ${portname}]"
93
94    set oldmask [umask ${destroot.umask}]
95    set mtree ${portutil::autoconf::mtree_path}
96   
97    if { ${destroot.clean} == "yes" } {
98        system "rm -Rf \"${destroot}\""
99    }
100   
101    file mkdir "${destroot}"
102    if { ${os.platform} == "darwin" } {
103        system "cd \"${destroot}\" && ${mtree} -e -U -f [file join ${portsharepath} install macosx.mtree]"
104    }
105    file mkdir "${destroot}/${prefix}"
106    system "cd \"${destroot}/${prefix}\" && ${mtree} -e -U -f [file join ${portsharepath} install prefix.mtree]"
107}
108
109proc destroot_main {args} {
110    command_exec destroot
111    return 0
112}
113
114proc destroot_finish {args} {
115    global UI_PREFIX destroot prefix portname startupitem.create destroot::oldmask destroot.violate_mtree
116    global os.platform os.version
117
118    # Create startup-scripts/items
119    if {[tbool startupitem.create]} {
120        package require portstartupitem 1.0
121        startupitem_create
122    }
123
124    # Prune empty directories in ${destroot}
125    set exclude_dirs [list]
126    set exclude_phrase ""
127    foreach path [option destroot.keepdirs] {
128        if {![file isdirectory ${path}]} {
129            xinstall -m 0755 -d ${path}
130        }
131        if {![file exists ${path}/.turd_${portname}]} {
132            xinstall -c -m 0644 /dev/null ${path}/.turd_${portname}
133        }
134        lappend exclude_dirs "-path \"${path}\""
135    }
136    if { [llength ${exclude_dirs}] > 0 } {
137        set exclude_phrase "! \\( [join ${exclude_dirs} " -or "] \\)"
138    }
139    catch {system "find \"${destroot}\" -depth -type d ${exclude_phrase} -exec rmdir -- \{\} \\; 2>/dev/null"}
140
141    # Compress all manpages with gzip (instead)
142    # but NOT on Jaguar (Darwin 6.x)
143    if {![regexp {darwin6} "${os.platform}${os.version}"]} {
144        set manpath "${destroot}${prefix}/share/man"
145        if {[file isdirectory ${manpath}] && [file type ${manpath}] == "directory"} {
146            ui_info "$UI_PREFIX [format [msgcat::mc "Compressing man pages for %s"] ${portname}]"
147            set found 0
148            set manlinks [list]
149            foreach mandir [readdir "${manpath}"] {
150                if {![regexp {^(cat|man)(.)$} ${mandir} match ignore manindex]} { continue }
151                set mandirpath [file join ${manpath} ${mandir}]
152                if {[file isdirectory ${mandirpath}] && [file type ${mandirpath}] == "directory"} {
153                    ui_debug "Scanning ${mandir}"
154                    foreach manfile [readdir ${mandirpath}] {
155                        set manfilepath [file join ${mandirpath} ${manfile}]
156                        if {[file isfile ${manfilepath}] && [file type ${manfilepath}] == "file"} {
157                            if {[regexp "^(.*\[.\]${manindex}\[a-z\]*)\[.\]gz\$" ${manfile} gzfile manfile]} {
158                                set found 1
159                                system "cd ${manpath} && \
160                                gunzip -f [file join ${mandir} ${gzfile}] && \
161                                gzip -9vf [file join ${mandir} ${manfile}]"
162                            } elseif {[regexp "^(.*\[.\]${manindex}\[a-z\]*)\[.\]bz2\$" ${manfile} bz2file manfile]} {
163                                set found 1
164                                system "cd ${manpath} && \
165                                bunzip2 -f [file join ${mandir} ${bz2file}] && \
166                                gzip -9vf [file join ${mandir} ${manfile}]"
167                            } elseif {[regexp "\[.\]${manindex}\[a-z\]*\$" ${manfile}]} {
168                                set found 1
169                                system "cd ${manpath} && \
170                                gzip -9vf [file join ${mandir} ${manfile}]"
171                            }
172                            set gzmanfile ${manfile}.gz
173                            set gzmanfilepath [file join ${mandirpath} ${gzmanfile}]
174                            if {[file exists ${gzmanfilepath}]} {
175                                set desired 00444
176                                set current [file attributes ${gzmanfilepath} -permissions]
177                                if {$current != $desired} {
178                                    ui_info "[file join ${mandir} ${gzmanfile}]: changing permissions from $current to $desired"
179                                    file attributes ${gzmanfilepath} -permissions $desired
180                                }
181                            }
182                        } elseif {[file type ${manfilepath}] == "link"} {
183                            lappend manlinks [file join ${mandir} ${manfile}]
184                        }
185                    }
186                }
187            }
188            if {$found == 1} {
189                # check man page links and rename/repoint them if necessary
190                foreach manlink $manlinks {
191                    set manlinkpath [file join $manpath $manlink]
192                    # if link destination is not gzipped, check it
193                    set manlinksrc [file readlink $manlinkpath]
194                    if {![regexp "\[.\]gz\$" ${manlinksrc}]} {
195                        set mandir [file dirname $manlink]
196                        set mandirpath [file join $manpath $mandir]
197                        set pwd [pwd]
198                        if {[catch {_cd $mandirpath} err]} {
199                            puts $err
200                            return
201                        }
202                        # if gzipped destination exists, fix link
203                        if {[file isfile ${manlinksrc}.gz]} {
204                            # if actual link name does not end with gz, rename it
205                            if {![regexp "\[.\]gz\$" ${manlink}]} {
206                                ui_debug "renaming link: $manlink to ${manlink}.gz"
207                                file rename $manlinkpath ${manlinkpath}.gz
208                                set manlink ${manlink}.gz
209                                set manlinkpath [file join $manpath $manlink]
210                            }
211                            # repoint the link
212                            ui_debug "repointing link: $manlink from $manlinksrc to ${manlinksrc}.gz"
213                            file delete $manlinkpath
214                            system "ln -s \"${manlinksrc}.gz\" \"$manlinkpath\""
215                        }
216                        _cd $pwd
217                    }
218                }
219            } else {
220                ui_debug "No man pages found to compress."
221            }
222        }
223    } else {
224        ui_debug "No man page compression on ${os.platform}${os.version}."
225    }
226
227    if [file exists "${destroot}${prefix}/share/info/dir"] {
228        ui_debug "Deleting stray info/dir file."
229        file delete "${destroot}${prefix}/share/info/dir"
230    }
231
232    # test for violations of mtree
233    if { ${destroot.violate_mtree} != "yes" } {
234        ui_debug "checking for mtree violations"
235        set mtree_violation "no"
236
237        set prefixPaths [list bin etc include lib libexec sbin share src var www Applications Developer Library]
238
239        set pathsToCheck [list /]
240        while {[llength $pathsToCheck] > 0} {
241            set pathToCheck [lshift pathsToCheck]
242            foreach file [glob -nocomplain -directory $destroot$pathToCheck .* *] {
243                if {[file tail $file] eq "." || [file tail $file] eq ".."} {
244                    continue
245                }
246                if {[string equal -length [string length $destroot] $destroot $file]} {
247                    # just double-checking that $destroot is a prefix, as is appropriate
248                    set dfile [file join / [string range $file [string length $destroot] end]]
249                } else {
250                    throw MACPORTS "Unexpected filepath `${file}' while checking for mtree violations"
251                }
252                if {$dfile eq $prefix} {
253                    # we've found our prefix
254                    foreach pfile [glob -nocomplain -tails -directory $file .* *] {
255                        if {$pfile eq "." || $pfile eq ".."} {
256                            continue
257                        }
258                        if {[lsearch -exact $prefixPaths $pfile] == -1} {
259                            ui_warn "violation by [file join $dfile $pfile]"
260                            set mtree_violation "yes"
261                        }
262                    }
263                } elseif {[string equal -length [expr [string length $dfile] + 1] $dfile/ $prefix]} {
264                    # we've found a subpath of our prefix
265                    lpush pathsToCheck $dfile
266                } else {
267                    # these files are outside of the prefix
268                    switch $dfile {
269                        /Applications -
270                        /Developer -
271                        /Library { ui_debug "port installs files in $dfile" }
272                        default {
273                            ui_warn "violation by $dfile"
274                            set mtree_violation "yes"
275                        }
276                    }
277                }
278            }
279        }
280
281        # abort here only so all violations can be observed
282        if { ${mtree_violation} != "no" } {
283            ui_warn "[format [msgcat::mc "%s violates the layout of the ports-filesystems!"] [option portname]]"
284            ui_warn "Please fix or indicate this misbehavior (if it is intended), it will be an error in future releases!"
285            # error "mtree violation!"
286        }
287    } else {
288        ui_warn "[format [msgcat::mc "%s requests to install files outside the common directory structure!"] [option portname]]"
289    }
290
291    # Restore umask
292    umask $oldmask
293
294    return 0
295}
Note: See TracBrowser for help on using the repository browser.