[24100] trunk/base/src/port1.0/portutil.tcl

source_changes at macosforge.org source_changes at macosforge.org
Mon Apr 16 04:07:46 PDT 2007


Revision: 24100
          http://trac.macosforge.org/projects/macports/changeset/24100
Author:   pguyot at kallisys.net
Date:     2007-04-16 04:07:45 -0700 (Mon, 16 Apr 2007)

Log Message:
-----------
New logic to remove previously defined variant code, something that happens with universal variant and that could happen with group code.

Doing :
variant foo {
	puts "def 1"
}

variant foo {
	puts "def 2"
}

will now cleanly override the previous definition. The behavior is unchanged, because the intra-portfile dependency solver already only considered the second instance, however such behavior was undefined and undocumented.

Defining a variant twice also now yields to a single instance in the portinfo.

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

Modified: trunk/base/src/port1.0/portutil.tcl
===================================================================
--- trunk/base/src/port1.0/portutil.tcl	2007-04-16 10:06:19 UTC (rev 24099)
+++ trunk/base/src/port1.0/portutil.tcl	2007-04-16 11:07:45 UTC (rev 24100)
@@ -370,10 +370,20 @@
     # make a user procedure named variant-blah-blah
     # we will call this procedure during variant-run
     makeuserproc "variant-[ditem_key $ditem name]" \{$code\}
-    lappend all_variants $ditem
     
     # Export provided variant to PortInfo
-    lappend PortInfo(variants) [ditem_key $ditem provides]
+    # (don't list it twice if the variant was already defined, which can happen
+    # with universal or group code).
+    set variant_provides [ditem_key $ditem provides]
+	if {![info exists PortInfo(variants)] || [lsearch -exact $PortInfo(variants) $variant_provides] < 0} {
+	    lappend PortInfo(variants) $variant_provides
+	} else {
+		# This variant was already defined. Remove it from the dlist.
+		variant_remove_ditem $variant_provides
+	}
+
+	# Finally append the ditem to the dlist.
+    lappend all_variants $ditem
 }
 
 # variant_isset name
@@ -423,8 +433,27 @@
 			}
 		}
 	}
+	
+	# And from the dlist.
+	variant_remove_ditem $name
 }
 
+# variant_remove_ditem name
+# Remove variant name's ditem from the all_variants dlist
+proc variant_remove_ditem {name} {
+	global all_variants
+	set item_index 0
+	foreach variant_item $all_variants {
+		set item_provides [ditem_key $variant_item provides]
+		if {$item_provides == $name} {
+			set all_variants [lreplace $all_variants $item_index $item_index]
+			break
+		}
+		
+		incr item_index
+	}
+}
+
 # platform <os> [<release>] [<arch>] 
 # Portfile level procedure to provide support for declaring platform-specifics
 # Basically, just wrap 'variant', so that Portfiles' platform declarations can

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070416/c3aaf23c/attachment.html


More information about the macports-changes mailing list