source: trunk/base/src/port1.0/portextract.tcl

Last change on this file was 121711, checked in by jmr@…, 6 years ago

use parallel bzip2 if available

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1# et:ts=4
2# portextract.tcl
3# $Id: portextract.tcl 121711 2014-07-04 18:20:06Z jmr@macports.org $
4#
5# Copyright (c) 2005, 2007-2011, 2013 The MacPorts Project
6# Copyright (c) 2002 - 2003 Apple Inc.
7# Copyright (c) 2007 Markus W. Weissmann <mww@macports.org>
8# All rights reserved.
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions
12# are met:
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in the
17#    documentation and/or other materials provided with the distribution.
18# 3. Neither the name of Apple Inc. nor the names of its contributors
19#    may be used to endorse or promote products derived from this software
20#    without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32# POSSIBILITY OF SUCH DAMAGE.
33#
34
35package provide portextract 1.0
36package require portutil 1.0
37
38set org.macports.extract [target_new org.macports.extract portextract::extract_main]
39target_provides ${org.macports.extract} extract
40target_requires ${org.macports.extract} main fetch checksum
41target_prerun ${org.macports.extract} portextract::extract_start
42
43namespace eval portextract {
44}
45
46# define options
47options extract.only extract.mkdir extract.asroot
48commands extract
49
50# Set up defaults
51default extract.asroot no
52# XXX call out to code in portutil.tcl XXX
53# This cleans the distfiles list of all site tags
54default extract.only {[portextract::disttagclean $distfiles]}
55
56default extract.dir {${workpath}}
57default extract.cmd {[findBinary gzip ${portutil::autoconf::gzip_path}]}
58default extract.pre_args -dc
59default extract.post_args {"| ${portutil::autoconf::tar_command} -xf -"}
60default extract.mkdir no
61
62set_ui_prefix
63
64# XXX
65# Helper function for portextract.tcl that strips all tag names from a list
66# Used to clean ${distfiles} for setting the ${extract.only} default
67proc portextract::disttagclean {list} {
68    if {"$list" == ""} {
69        return $list
70    }
71    foreach name $list {
72        lappend val [getdistname $name]
73    }
74    return $val
75}
76
77proc portextract::extract_start {args} {
78    global UI_PREFIX extract.dir extract.mkdir use_bzip2 use_lzma use_xz use_zip use_7z use_lzip use_dmg
79
80    ui_notice "$UI_PREFIX [format [msgcat::mc "Extracting %s"] [option subport]]"
81
82    # create any users and groups needed by the port
83    handle_add_users
84
85    # should the distfiles be extracted to worksrcpath instead?
86    if {[tbool extract.mkdir]} {
87        global worksrcpath
88        ui_debug "Extracting to subdirectory worksrcdir"
89        file mkdir ${worksrcpath}
90        set extract.dir ${worksrcpath}
91    }
92    if {[tbool use_bzip2]} {
93        if {![catch {findBinary lbzip2} result]} {
94            option extract.cmd $result
95        } else {
96            option extract.cmd [findBinary bzip2 ${portutil::autoconf::bzip2_path}]
97        }
98    } elseif {[tbool use_lzma]} {
99        option extract.cmd [findBinary lzma ${portutil::autoconf::lzma_path}]
100    } elseif {[tbool use_xz]} {
101        option extract.cmd [findBinary xz ${portutil::autoconf::xz_path}]
102    } elseif {[tbool use_zip]} {
103        option extract.cmd [findBinary unzip ${portutil::autoconf::unzip_path}]
104        option extract.pre_args -q
105        option extract.post_args "-d ${extract.dir}"
106    } elseif {[tbool use_7z]} {
107        option extract.cmd [binaryInPath "7za"]
108        option extract.pre_args x
109        option extract.post_args ""
110    } elseif {[tbool use_lzip]} {
111        option extract.cmd [binaryInPath "lzip"]
112        option extract.pre_args "-dc"
113        #option extract.post_args ""
114    } elseif {[tbool use_dmg]} {
115        global distname extract.cmd
116        set dmg_mount [mkdtemp "/tmp/mports.XXXXXXXX"]
117        option extract.cmd [findBinary hdiutil ${portutil::autoconf::hdiutil_path}]
118        option extract.pre_args attach
119        option extract.post_args "-private -readonly -nobrowse -mountpoint \\\"${dmg_mount}\\\" && cd \\\"${dmg_mount}\\\" && [findBinary find ${portutil::autoconf::find_path}] . -depth -perm -+r -print0 | [findBinary cpio ${portutil::autoconf::cpio_path}] -0 -p -d -m -u \\\"${extract.dir}/${distname}\\\"; status=\$?; cd / && ${extract.cmd} detach \\\"${dmg_mount}\\\" && [findBinary rmdir ${portutil::autoconf::rmdir_path}] \\\"${dmg_mount}\\\"; exit \$status"
120    }
121}
122
123proc portextract::extract_main {args} {
124    global UI_PREFIX filespath worksrcpath extract.dir usealtworkpath altprefix use_dmg
125
126    if {![exists distfiles] && ![exists extract.only]} {
127        # nothing to do
128        return 0
129    }
130
131    foreach distfile [option extract.only] {
132        ui_info "$UI_PREFIX [format [msgcat::mc "Extracting %s"] $distfile]"
133        if {[file exists $filespath/$distfile]} {
134            option extract.args "'$filespath/$distfile'"
135        } elseif {![file exists "[option distpath]/$distfile"] && !$usealtworkpath && [file exists "${altprefix}[option distpath]/$distfile"]} {
136            option extract.args "'${altprefix}[option distpath]/$distfile'"
137        } else {
138            option extract.args "'[option distpath]/$distfile'"
139        }
140
141        # If the MacPorts user does not have the privileges to mount a
142        # DMG then hdiutil will fail with this error:
143        #   hdiutil: attach failed - Device not configured
144        # So elevate back to root.
145        if {[tbool use_dmg]} {
146            elevateToRoot {extract dmg}
147        }
148        set code [catch {command_exec extract} result]
149        if {[tbool use_dmg]} {
150            dropPrivileges
151        }
152        if {$code} {
153            return -code error "$result"
154        }
155
156        # start gsoc08-privileges
157        chownAsRoot ${extract.dir}
158        # end gsoc08-privileges
159    }
160    return 0
161}
Note: See TracBrowser for help on using the repository browser.