source: trunk/dports/_resources/port1.0/group/compiler_blacklist_versions-1.0.tcl @ 101466

Last change on this file since 101466 was 101466, checked in by ciserlohn@…, 7 years ago

compiler_blacklist_versions: reintroduce '$' which got lost in r101464

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2# $Id: compiler_blacklist_versions-1.0.tcl 101466 2013-01-11 15:20:28Z ciserlohn@macports.org $
3#
4# Copyright (c) 2012 The MacPorts Project
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 are
9# met:
10#
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. Neither the name of The MacPorts Project nor the names of its
17#    contributors may be used to endorse or promote products derived from
18#    this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31#
32#
33# Including this PortGroup in a Portfile enhances the compiler.blacklist option
34# to support blacklisting only specific build numbers of the given compiler.
35#
36# Examples:
37#
38# Blacklist only clang build numbers less than 318.0.61:
39# compiler.blacklist-append {clang < 318.0.61}
40#
41# Blacklist only clang build numbers greater than or equal to 421.11.66:
42# compiler.blacklist-append {clang >= 421.11.66}
43#
44# Blacklist only clang build numbers greater than or equal to 421.11.66 but less than 444:
45# compiler.blacklist-append {clang >= 421.11.66 < 444}
46#
47# Blacklist all versions of clang (same as without this PortGroup):
48# compiler.blacklist-append clang
49#
50# Known limitations:
51#
52# Trying to remove an enhanced compiler.blacklist specification will not work
53# (it will silently do nothing):
54# compiler.blacklist-delete {clang >= 421.11.66}
55# Workaround:
56# compiler.blacklist-delete clang
57#
58# This PortGroup was created following this discussion:
59# http://lists.macosforge.org/pipermail/macports-dev/2012-November/021103.html
60
61option_proc compiler.blacklist compiler_blacklist_versions._set_compiler_blacklist
62
63proc compiler_blacklist_versions._set_compiler_blacklist {option action args} {
64    if {"set" != ${action}} return
65    foreach blacklist [option ${option}] {
66        if {[llength ${blacklist}] > 1} {
67            compiler.blacklist-delete ${blacklist}
68            set compiler [lindex ${blacklist} 0]
69            set comparisons [lrange ${blacklist} 1 end]
70            set compiler_version [compiler_blacklist_versions._get_compiler_version ${compiler}]
71            if {[compiler_blacklist_versions._matches_all_versions ${compiler} ${comparisons}]} {
72                if {[string equal ${compiler_version} ""]} {
73                    ui_debug "compiler ${compiler} blacklisted because not installed"
74                } else {
75                    ui_debug "compiler ${compiler} ${compiler_version} blacklisted because matches {${blacklist}}"
76                }
77                compiler.blacklist-append ${compiler}
78            } else {
79                ui_debug "compiler ${compiler} ${compiler_version} not blacklisted because does not match {${blacklist}}"
80            }
81        }
82    }
83}
84
85proc compiler_blacklist_versions._matches_all_versions {compiler comparisons} {
86    if {[llength ${comparisons}] % 2} {
87        return -code error "invalid/incomplete comparison specification \"${comparisons}\""
88    }
89    while {[llength ${comparisons}] > 0} {
90        set comparison_operator [lindex ${comparisons} 0]
91        set test_version [lindex ${comparisons} 1]
92        if {![compiler_blacklist_versions._version_matches ${compiler} ${comparison_operator} ${test_version}]} {
93            return 0
94        }
95        set comparisons [lrange ${comparisons} 2 end]
96    }
97    return 1
98}
99
100proc compiler_blacklist_versions._version_matches {compiler comparison_operator test_version} {
101    set actual_version [compiler_blacklist_versions._get_compiler_version ${compiler}]
102    if {[string equal ${actual_version} ""]} {
103        return 1
104    }
105    return [expr [vercmp ${actual_version} ${test_version}] ${comparison_operator} 0]
106}
107
108proc compiler_blacklist_versions._get_compiler_version {compiler} {
109    global compiler_blacklist_versions._compiler_versions
110    if {[info exists compiler_blacklist_versions._compiler_versions(${compiler})]} {
111        return [set compiler_blacklist_versions._compiler_versions(${compiler})]
112    }
113    switch ${compiler} {
114        clang {
115            set re {clang-([0-9.]+)}
116        }
117        gcc-4.0 -
118        gcc-4.2 -
119        apple-gcc-4.2 -
120        llvm-gcc-4.2 {
121            set re {build ([0-9.]+)}
122        }
123        default {
124            return -code error "don't know how to determine build number of compiler \"${compiler}\""
125        }
126    }
127    set cc [portconfigure::configure_get_compiler cc ${compiler}]
128    if {![file exists ${cc}]} return
129    regexp ${re} [exec ${cc} -v 2>@1] -> compiler_version
130    if {![info exists compiler_version]} {
131        return -code error "couldn't determine build number of compiler \"${compiler}\""
132    }
133    set compiler_blacklist_versions._compiler_versions(${compiler}) ${compiler_version}
134    return ${compiler_version}
135}
Note: See TracBrowser for help on using the repository browser.