source: trunk/base/src/port1.0/portdestroot.tcl @ 36914

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

restore previous destroot.cmd, undo build.cmd workaround

  • 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 36914 2008-05-18 18:35:37Z afb@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 destroot portresourcepath os.platform destroot.clean
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 ${portresourcepath}/install/macosx.mtree"
104    }
105    file mkdir "${destroot}/${prefix}"
106    system "cd \"${destroot}/${prefix}\" && ${mtree} -e -U -f ${portresourcepath}/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.