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

Last change on this file since 1015 was 1015, checked in by kevin, 18 years ago

Remove 'register' proc.
Now targets have a handle to the target object directly. Alleviates need for
unique names, and simplifies pre-${target}/post-${target} implementation.
Will allow for future enhancement to options and variants.

  • Property svn:eol-style set to native
File size: 4.0 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
35set com.apple.package [target_new com.apple.package package_main]
36${com.apple.package} set runtype always
37${com.apple.package} provides packager
38${com.apple.package} requires registry
39
40# define options
41options package.type package.dir
42
43# Set defaults
44default package.type tarball
45default package.dir ""
46
47set UI_PREFIX "---> "
48
49proc package_main {args} {
50    global portname portversion package.type UI_PREFIX
51
52    set rfile [registry_exists $portname $portversion]
53    if ![string length $rfile] {
54        ui_error "Package ${portname}-${portversion} not installed on this system"
55        return -code error "Package ${portname}-${portversion} not installed on this system"
56    }
57    ui_msg "$UI_PREFIX Creating ${package.type} package for ${portname}-${portversion}"
58    if [regexp .bz2$ $rfile] {
59        set fd [open "|bunzip2 -c $rfile" r]
60    } else {
61        set fd [open $rfile r]
62    }
63    set entry [read $fd]
64    close $fd
65
66    # For now the only package type we support is "tarball" but move that
67    # into another routine anyway so that this is abstract enough.
68
69    return [package_tarball $portname $portversion $entry]
70}
71
72# Make a tarball version of a package.  This is our "built-in" packaging
73# method.
74proc package_tarball {portname portversion entry} {
75    global ports_verbose portdbpath package.dir
76
77    set rfile [registry_exists $portname $portversion]
78    set ix [lsearch $entry contents]
79    if {$ix >= 0} {
80        set contents [lindex $entry [incr ix]]
81        set plist [mkstemp /tmp/XXXXXXXX]
82        set pfile [lindex $plist 0]
83        foreach f $contents {
84            set fname [lindex $f 0]
85            puts $pfile $fname
86        }
87        puts $pfile $rfile
88        close $pfile
89        if [tbool ports_verbose] {
90            set verbose v
91        } else {
92            set verbose ""
93        }
94        if [file isdirectory ${package.dir}] {
95            set ptarget ${package.dir}/${portname}-${portversion}.tar.gz
96        } else {
97            set ptarget ${portname}-${portversion}.tar.gz
98        }
99        if [catch {system "gnutar -T [lindex $plist 1] -czPp${verbose}f ${ptarget}"} err] {
100            ui_error "Package creation failed - gnutar returned error status: $err"
101            ui_info "Failed packing list left in [lindex $plist 1]"
102            return -code error "Package creation failed - gnutar returned error status: $err"
103        }
104        exec rm [lindex $plist 1]
105    } else {
106        ui_error "Bad registry entry for ${portname}-${portversion}, no contents"
107        return -code error "Bad registry entry for ${portname}-${portversion}, no contents"
108    }
109    return 0
110}
Note: See TracBrowser for help on using the repository browser.