Ticket #51689: preserve_runtime_libraries-1.0.tcl

File preserve_runtime_libraries-1.0.tcl, 4.1 KB (added by RJVB (René Bertin), 8 years ago)
Line 
1# -*- coding: utf-8; mode: tcl; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; truncate-lines: t -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
2# $Id:$
3
4# Copyright (c) 2015 The MacPorts Project
5# Copyright (c) 2016 R.J.V. Bertin
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions are
10# met:
11#
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
18#    contributors may be used to endorse or promote products derived from
19#    this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32#
33#
34# Usage:
35# PortGroup     preserve_runtime_libraries 1.0
36#
37# in the post-destroot, call preserve_libraries with the directory
38# holding the libraries to preserve and a filename pattern. Example:
39#
40# post-destroot {
41#   preserve_libraries ${prefix}/lib libwebp*.*.dylib
42# }
43#
44# This will create a copy of the pre-existing libraries not installed
45# by the current ${subport} to be stored in ${prefix}/${srcdir}/previous/${subport}
46# with a symlink in ${prefix}/${srcdir} .
47# Using a special repository makes it immediately clear which port a
48# legacy runtime belongs to; the symlink makes it easy to test whether
49# the copy is still used.
50
51# Note that ports that depend on poppler via poppler-qt4-mac or
52# poppler-qt5-mac do not need this trick to avoid rebuilding.
53
54# set libraries_to_preserve ""
55proc preserve_libraries {srcdir pattern} {
56    global prefix subport destroot
57    if {[variant_isset preserve_runtime_libraries]} {
58        if {[file type ${srcdir}] eq "directory"} {
59            set prevdir "previous/${subport}"
60            xinstall -m 755 -d ${destroot}${srcdir}/${prevdir}
61            foreach l [glob -nocomplain ${srcdir}/${pattern} ${srcdir}/${prevdir}/${pattern}] {
62                if {[file type ${l}] ne "link"} {
63                    set lib [file tail ${l}]
64                    set prevlib [file join ${destroot}${srcdir}/${prevdir} ${lib}]
65                    if {![file exists ${prevlib}] && ![file exists ${destroot}${l}]} {
66                        ui_info "Preserving previous runtime shared library ${l} as ${prevlib}"
67                        copy ${l} ${prevlib}
68                        ln -s [file join ${prevdir} [file tail ${l}]] ${destroot}${srcdir}/${lib}
69                    }
70                }
71            }
72        } else {
73            ui_warn "Source for previous runtime libraries (${srcdir}) should be a directory"
74        }
75    } else {
76        ui_debug "The preserve_runtime_libraries variant isn't set; ignoring the call to preserve_libraries"
77    }
78}
79
80variant preserve_runtime_libraries description {Experimental variant that preserves the pre-existing runtime \
81                                        libraries to ease the rebuilding load during upgrades.} {}
82
83# kate: backspace-indents true; indent-pasted-text true; indent-width 4; keep-extra-spaces true; remove-trailing-spaces modified; replace-tabs true; replace-tabs-save true; syntax Tcl/Tk; tab-indents true; tab-width 4;
84