source: trunk/base/src/port1.0/portpackage.tcl @ 845

Last change on this file since 845 was 845, checked in by jkh, 18 years ago

Import package.dir properly.

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1# ex:ts=4
2# portpackage.tcl
3#
4# Copyright (c) 2002 Apple Computer, Inc.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
16#    may be used to endorse or promote products derived from this software
17#    without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGE.
30#
31
32package provide portpackage 1.0
33package require portutil 1.0
34
35register com.apple.package target package_main always
36register com.apple.package provides packager
37register com.apple.package requires registry
38
39# define options
40options package.type package.dir
41
42# Set defaults
43default package.type tarball
44default package.dir ""
45
46set UI_PREFIX "---> "
47
48proc package_main {args} {
49    global portname portversion package.type UI_PREFIX
50
51    set rfile [registry_exists $portname $portversion]
52    if ![string length $rfile] {
53        ui_error "Package ${portname}-${portversion} not installed on this system"
54        return -code error "Package ${portname}-${portversion} not installed on this system"
55    }
56    ui_msg "$UI_PREFIX Creating ${package.type} package for ${portname}-${portversion}"
57    if [regexp .bz2$ $rfile] {
58        set fd [open "|bunzip2 -c $rfile" r]
59    } else {
60        set fd [open $rfile r]
61    }
62    set entry [read $fd]
63    close $fd
64
65    # For now the only package type we support is "tarball" but move that
66    # into another routine anyway so that this is abstract enough.
67
68    return [package_tarball $portname $portversion $entry]
69}
70
71# Make a tarball version of a package.  This is our "built-in" packaging
72# method.
73proc package_tarball {portname portversion entry} {
74    global ports_verbose portdbpath package.dir
75
76    set rfile [registry_exists $portname $portversion]
77    set ix [lsearch $entry contents]
78    if {$ix >= 0} {
79        set contents [lindex $entry [incr ix]]
80        set plist [mkstemp /tmp/XXXXXXXX]
81        set pfile [lindex $plist 0]
82        foreach f $contents {
83            set fname [lindex $f 0]
84            puts $pfile $fname
85        }
86        puts $pfile $rfile
87        close $pfile
88        if [tbool ports_verbose] {
89            set verbose v
90        } else {
91            set verbose ""
92        }
93        if [file isdirectory ${package.dir}] {
94            set ptarget ${package.dir}/${portname}-${portversion}.tar.gz
95        } else {
96            set ptarget ${portname}-${portversion}.tar.gz
97        }
98        if [catch {system "gnutar -T [lindex $plist 1] -czPp${verbose}f ${ptarget}"} err] {
99            ui_error "Package creation failed - gnutar returned error status: $err"
100            ui_info "Failed packing list left in [lindex $plist 1]"
101            return -code error "Package creation failed - gnutar returned error status: $err"
102        }
103        exec rm [lindex $plist 1]
104    } else {
105        ui_error "Bad registry entry for ${portname}-${portversion}, no contents"
106        return -code error "Bad registry entry for ${portname}-${portversion}, no contents"
107    }
108    return 0
109}
Note: See TracBrowser for help on using the repository browser.