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

Last change on this file was 116449, checked in by cal@…, 7 years ago

port1.0: Tcl cleanup, from a patch by Gustaf Neumann

  • removed numeric comparisons where not necessary
  • braced expressions to allow for bytecode compilation
  • removed unneeded calls to expr
  • added brackets around if conditions
  • quoted match expressions
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1# et:ts=4
2# portpatch.tcl
3# $Id: portpatch.tcl 116449 2014-01-25 16:57:17Z cal@macports.org $
4#
5# Copyright (c) 2004, 2006-2007, 2009-2011 The MacPorts Project
6# Copyright (c) 2002 - 2003 Apple Inc.
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 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 portpatch 1.0
35package require portutil 1.0
36
37set org.macports.patch [target_new org.macports.patch portpatch::patch_main]
38target_provides ${org.macports.patch} patch
39target_requires ${org.macports.patch} main fetch checksum extract
40
41namespace eval portpatch {
42}
43
44set_ui_prefix
45
46# Add command patch
47commands patch
48
49options patch.asroot
50# Set up defaults
51default patch.asroot no
52default patch.dir {${worksrcpath}}
53default patch.cmd {[portpatch::build_getpatchtype]}
54default patch.pre_args -p0
55
56proc portpatch::build_getpatchtype {args} {
57    if {![exists patch.type]} {
58        return [findBinary patch $portutil::autoconf::patch_path]
59    }
60    switch -exact -- [option patch.type] {
61        gnu {
62            return [findBinary gpatch $portutil::autoconf::gnupatch_path]
63        }
64        default {
65            ui_warn "[format [msgcat::mc "Unknown patch.type %s, using 'patch'"] [option patch.type]]"
66            return [findBinary patch $portutil::autoconf::patch_path]
67        }
68    }
69}
70
71proc portpatch::patch_main {args} {
72    global UI_PREFIX usealtworkpath altprefix
73
74    # First make sure that patchfiles exists and isn't stubbed out.
75    if {![exists patchfiles] || [option patchfiles] eq ""} {
76        return 0
77    }
78
79    ui_notice "$UI_PREFIX [format [msgcat::mc "Applying patches to %s"] [option subport]]"
80
81    foreach patch [option patchfiles] {
82        set patch_file [getdistname $patch]
83        if {[file exists [option filespath]/$patch_file]} {
84            lappend patchlist [option filespath]/$patch_file
85        } elseif {[file exists [option distpath]/$patch_file]} {
86            lappend patchlist [option distpath]/$patch_file
87        } elseif {!$usealtworkpath && [file exists "${altprefix}[option distpath]/$patch_file"]} {
88            lappend patchlist "${altprefix}[option distpath]/$patch_file"
89        } else {
90            return -code error [format [msgcat::mc "Patch file %s is missing"] $patch]
91        }
92    }
93    if {![info exists patchlist]} {
94        return -code error [msgcat::mc "Patch files missing"]
95    }
96
97    set gzcat "[findBinary gzip $portutil::autoconf::gzip_path] -dc"
98    set bzcat "[findBinary bzip2 $portutil::autoconf::bzip2_path] -dc"
99    foreach patch $patchlist {
100        ui_info "$UI_PREFIX [format [msgcat::mc "Applying %s"] [file tail $patch]]"
101        switch -- [file extension $patch] {
102            .Z -
103            .gz {command_exec patch "$gzcat \"$patch\" | (" ")"}
104            .bz2 {command_exec patch "$bzcat \"$patch\" | (" ")"}
105            default {command_exec patch "" "< '$patch'"}
106        }
107    }
108    return 0
109}
Note: See TracBrowser for help on using the repository browser.