Ticket #51706: patch-platform-command.2.diff

File patch-platform-command.2.diff, 2.0 KB (added by RJVB (René Bertin), 6 years ago)
  • src/port1.0/portutil.tcl

    diff --git a/src/port1.0/portutil.tcl b/src/port1.0/portutil.tcl
    index 1b010331..fd538d3e 100644
    a b proc variant_desc {porturl variant} { 
    769769# Portfile level procedure to provide support for declaring platform-specifics
    770770# Basically, just a fancy 'if', so that Portfiles' platform declarations can
    771771# be more readable, and support arch and version specifics
    772 proc platform {args} {
     772proc platform {os args} {
    773773    global os.platform os.subplatform os.arch os.major
    774774
    775     set len [llength $args]
    776     if {$len < 2} {
     775    if {[llength $args] < 1} {
    777776        return -code error "Malformed platform specification"
    778777    }
    779     set code [lindex $args end]
    780     set os [lindex $args 0]
    781     set args [lrange $args 1 [expr {$len - 2}]]
     778    set len 1
     779    if {[lindex $args end-1] eq "else"} {
     780        set code [lindex $args end-2]
     781        set altcode [lindex $args end]
     782        set consumed 3
     783    } else {
     784        set code [lindex $args end]
     785        set altcode ""
     786        set consumed 1
     787    }
    782788
    783     foreach arg $args {
     789    foreach arg [lrange $args 0 end-$consumed] {
    784790        if {[regexp {(^[0-9]+$)} $arg match result]} {
    785791            set release $result
     792            set len [expr $len + 1]
    786793        } elseif {[regexp {([a-zA-Z0-9]*)} $arg match result]} {
    787794            set arch $result
     795            set len [expr $len + 1]
    788796        }
    789797    }
    790798
    791799    set match 0
    792800    # 'os' could be a platform or an arch when it's alone
    793     if {$len == 2 && ($os eq ${os.platform} || $os eq ${os.subplatform} || $os eq ${os.arch})} {
     801    if {$len == 1 && ($os eq ${os.platform} || $os eq ${os.subplatform} || $os eq ${os.arch})} {
    794802        set match 1
    795803    } elseif {($os eq ${os.platform} || $os eq ${os.subplatform})
    796804              && (![info exists release] || ${os.major} == $release)
    proc platform {args} { 
    801809    # Execute the code if this platform matches the platform we're on
    802810    if {$match} {
    803811        uplevel 1 $code
     812    } elseif {${altcode} ne ""} {
     813        uplevel 1 $altcode
    804814    }
    805815}
    806816