platform{} statement

René J. V. Bertin rjvbertin at gmail.com
Fri Jun 3 05:55:31 PDT 2016


Rainer Müller wrote:

> The definition of the platform proc is here:
> 
> 
https://trac.macports.org/browser/trunk/base/src/port1.0/portutil.tcl?rev=149111#L765
> 
> Extending that syntax with an optional code block after an "else"
> keyword would be possible.

Once I knew it was possible it wasn't very hard to figure out how. Is there a 
more efficient way to determine if an else keyword has been given (both in the 
parser and in the actual executor?

@@ -774,7 +780,13 @@
     if {$len < 2} {
         return -code error "Malformed platform specification"
     }
-    set code [lindex $args end]
+    set altcode ""
+    if {[lindex $args [expr ${len} - 2]] eq "else"} {
+        set code [lindex $args [expr ${len} - 3]]
+        set altcode [lindex $args end]
+    } else {
+        set code [lindex $args end]
+    }
     set os [lindex $args 0]
     set args [lrange $args 1 [expr {$len - 2}]]
 
@@ -799,6 +811,8 @@
     # Execute the code if this platform matches the platform we're on
     if {$match} {
         uplevel 1 $code
+    } elseif {${altcode} ne ""} {
+        uplevel 1 $altcode
     }
 }

Now the problem is going to be *not* to use this until it becomes official 
(except maybe through one of my own PortGroups) ...



More information about the macports-dev mailing list