[43475] trunk/base/src

perry at macports.org perry at macports.org
Wed Dec 10 19:58:00 PST 2008


Revision: 43475
          http://trac.macports.org/changeset/43475
Author:   perry at macports.org
Date:     2008-12-10 19:58:00 -0800 (Wed, 10 Dec 2008)
Log Message:
-----------
port/port.tcl, port1.0/portutil.tcl - Addressed Ticket #15628.
* 'port variants' now shows default variants, conflicts and requires.
* 'port info' shows the default variants using the new key in PortInfo,
  _variants.
* PortInfo(_variants) maps a variant's name to an array that contains the
  following keys: conflicts, description, is_default and requires.
* PortInfo(_variants) should (probably) eventually replace PortInfo(variants).

Modified Paths:
--------------
    trunk/base/src/port/port.tcl
    trunk/base/src/port1.0/portutil.tcl

Modified: trunk/base/src/port/port.tcl
===================================================================
--- trunk/base/src/port/port.tcl	2008-12-11 03:56:21 UTC (rev 43474)
+++ trunk/base/src/port/port.tcl	2008-12-11 03:58:00 UTC (rev 43475)
@@ -1475,16 +1475,15 @@
             if {[info exists portinfo(variants)]} {
                 global global_variations
 
-                # Get the default variants
-                if {[info exists portinfo(default_variants)]} {
-                    array set default_variants $portinfo(default_variants)
-                } else {
-                    array set default_variants ""
-                }
+                # Get the variants associated with this Portfile.
+                array set variants $portinfo(_variants)
 
                 set joiner ""
                 set vars ""
                 foreach v [lsort $portinfo(variants)] {
+                    # Get the variant's information.
+                    array set variant $variants($v)
+
                     set mod ""
                     if {[info exists variations($v)]} {
                         # selected by command line, prefixed with +/-
@@ -1492,9 +1491,8 @@
                     } elseif {[info exists global_variations($v)]} {
                         # selected by variants.conf, prefixed with (+)/(-)
                         set mod "($global_variations($v))"
-                    } elseif {[info exists default_variants($v)]} {
-                        # selected by default_variants, prefixed with [+]/[-]
-                        set mod "\[$default_variants($v)\]"
+                    } elseif {$variant(is_default) == "+"} {
+                        set mod "\[+\]"
                     }
                     append vars "$joiner$mod$v"
                     set joiner ", "
@@ -2102,33 +2100,32 @@
         }
     
         # if this fails the port doesn't have any variants
-        if {![info exists portinfo(variants)]} {
+        if { ! [ info exists portinfo(_variants) ] } {
             puts "$portname has no variants"
         } else {
-            # Get the default variants
-            if {[info exists portinfo(default_variants)]} {
-                array set default_variants $portinfo(default_variants)
-            } else {
-                array set default_variants ""
-            }
-            # Get the variant descriptions
-            if {[info exists portinfo(variant_desc)]} {
-                array set descs $portinfo(variant_desc)
-            } else {
-                array set descs ""
-            }
+            array set variants $portinfo(_variants)
 
             # print out all the variants
             puts "$portname has the variants:"
-            foreach v $portinfo(variants) {
-                if {[info exists descs($v)] && $descs($v) != ""} {
-                    puts -nonewline "\t$v: [string trim $descs($v)]"
-                } else {
-                    puts -nonewline "\t$v"
+            foreach vname [ lsort [ array names variants ] ] {
+                array set vinfo $variants($vname)
+
+                puts -nonewline "\t$vname:"
+                if { [ info exists vinfo(description) ] } {
+                    puts -nonewline " [ string trim $vinfo(description) ]"
                 }
-                if {[info exists default_variants($v)] && $default_variants($v) != ""} {
-                    puts -nonewline { [default]}
+                if { [ info exists vinfo(is_default) ] \
+                     && $vinfo(is_default) == "+" } {
+                    puts -nonewline "\n\t  * is a default variant"
                 }
+                if { [ info exists vinfo(conflicts) ] \
+                    && $vinfo(conflicts) != "" } {
+                    puts -nonewline "\n\t  * conflicts with [ string trim $vinfo(conflicts) ]"
+                }
+                if { [ info exists vinfo(requires) ] \
+                    && $vinfo(requires) != "" } {
+                    puts -nonewline "\n\t  * requires [ string trim $vinfo(requires) ]"
+                }
                 puts ""
             }
         }

Modified: trunk/base/src/port1.0/portutil.tcl
===================================================================
--- trunk/base/src/port1.0/portutil.tcl	2008-12-11 03:56:21 UTC (rev 43474)
+++ trunk/base/src/port1.0/portutil.tcl	2008-12-11 03:58:00 UTC (rev 43475)
@@ -413,7 +413,24 @@
 # Portfile level procedure to provide support for declaring variants
 proc variant {args} {
     global all_variants PortInfo porturl
-    
+
+    # Perhaps a little self-explanatory ;), but PortInfo(_variants) contains
+    # the variants associated with a Portfile.  Each key, the variant's name,
+    # maps to an array, the variant, which contains the following keys:
+    #   * conflicts
+    #   * description
+    #   * is_default
+    #   * requires
+    # XXX: PortInfo(_variants)'s contents *should* eventually replace
+    #      PortInfo(variants)'s contents.  Once I've finished transitioning the
+    #      code to use the new format, I will rename PortInfo(_variants) as
+    #      PortInfo(variants) (and hopefully everything will continue to work).
+    #      -- perry
+    if { ! [ info exists PortInfo(_variants) ] } {
+        set PortInfo(_variants) {}
+    }
+    array set variants $PortInfo(_variants)
+
     set len [llength $args]
     set code [lindex $args end]
     set args [lrange $args 0 [expr $len - 2]]
@@ -448,6 +465,20 @@
         # This variant was already defined. Remove it from the dlist.
         variant_remove_ditem $variant_provides
     } else {
+        # Create an array to contain the variant's information.
+        if { ! [ info exists variants($variant_provides) ] } {
+            set variants($variant_provides) {}
+        }
+        array set variant $variants($variant_provides)
+    
+        # Set conflicts (if any).
+        set vconflicts [ join [ lsort [ ditem_key $ditem conflicts ] ] ]
+        if { $vconflicts != "" } {
+            array set variant [ list conflicts $vconflicts ]
+        } else {
+            array set variant [ list conflicts "" ]
+        }
+
         lappend PortInfo(variants) $variant_provides
         set vdesc [join [ditem_key $ditem description]]
 
@@ -456,11 +487,30 @@
             set vdesc [variant_desc $porturl $variant_provides]
         }
 
+        # Set description (if any).
         if {$vdesc != ""} {
+            array set variant [ list description $vdesc ]
             lappend PortInfo(variant_desc) $variant_provides $vdesc
         }
+
+        # Set is_default.
+        if { ! [ info exists variant(is_default) ] } {
+            array set variant [ list is_default "-" ]
+        }
+
+        # Set requires (if any).
+        set vrequires [ join [ lsort [ ditem_key $ditem requires ] ] ]
+        if { $vrequires != "" } {
+            array set variant [ list requires $vrequires ]
+        } else {
+            array set variant [ list requires "" ]
+        }
     }
 
+    # Add variant to PortInfo(_variants)
+    array set variants [ list $variant_provides [ array get variant ] ]
+    set PortInfo(_variants) [ array get variants ]
+
     # Finally append the ditem to the dlist.
     lappend all_variants $ditem
 }
@@ -1862,15 +1912,31 @@
     global variations
     switch -regex $action {
         set|append {
-            set PortInfo(default_variants) {}
+            # Retrieve the variants associated with this Portfile.
+            if { ! [ info exists PortInfo(_variants) ] } {
+                set PortInfo(_variants) {}
+            }
+            array set variants $PortInfo(_variants)
+
             foreach v $value {
                 if {[regexp {([-+])([-A-Za-z0-9_]+)} $v whole val variant]} {
+                    # Retrieve the information associated with this variant.
+                    if { ! [ info exists variants($variant) ] } {
+                        set variants($variant) {}
+                    }
+                    array set vinfo $variants($variant)
+
                     if {![info exists variations($variant)]} {
-                    lappend PortInfo(default_variants) $variant $val
-                    set variations($variant) $val
+                        # Set is_default and update variants.
+                        array set vinfo [ list is_default "+" ]
+                        array set variants [ list $variant [ array get vinfo ] ]
+
+                        set variations($variant) $val
                     }
                 }
             }
+            # Update PortInfo(_variants).
+            set PortInfo(_variants) [ array get variants ]
         }
         delete {
             # xxx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20081210/5d79995e/attachment-0001.html>


More information about the macports-changes mailing list