Support dependencies between variants

Variants of a module may need to depend on other variants, for example
to reuse results between variants.  Support AddInterVariantDependency to
add an explicit dependency from one variant to another, along with a
dependency tag.  Both modules must have just been returned by a call to
CreateVariants.

Change-Id: I8f4878f94ced74dd00cfac8303b15ef70cdebf36
diff --git a/context.go b/context.go
index fdb977a..dde4734 100644
--- a/context.go
+++ b/context.go
@@ -1312,6 +1312,30 @@
 	}}
 }
 
+func (c *Context) addInterVariantDependency(origModule *moduleInfo, tag DependencyTag,
+	from, to Module) {
+
+	var fromInfo, toInfo *moduleInfo
+	for _, m := range origModule.splitModules {
+		if m.logicModule == from {
+			fromInfo = m
+		}
+		if m.logicModule == to {
+			toInfo = m
+			if fromInfo != nil {
+				panic(fmt.Errorf("%q depends on later version of itself", origModule.properties.Name))
+			}
+		}
+	}
+
+	if fromInfo == nil || toInfo == nil {
+		panic(fmt.Errorf("AddInterVariantDependency called for module %q on invalid variant",
+			origModule.properties.Name))
+	}
+
+	fromInfo.directDeps = append(fromInfo.directDeps, depInfo{toInfo, tag})
+}
+
 func (c *Context) parallelVisitAllBottomUp(visit func(group *moduleInfo) bool) {
 	doneCh := make(chan *moduleInfo)
 	count := 0
diff --git a/module_ctx.go b/module_ctx.go
index 055e7f7..b52a75a 100644
--- a/module_ctx.go
+++ b/module_ctx.go
@@ -423,6 +423,7 @@
 	SetDependencyVariation(string)
 	AddVariationDependencies([]Variation, DependencyTag, ...string)
 	AddFarVariationDependencies([]Variation, DependencyTag, ...string)
+	AddInterVariantDependency(tag DependencyTag, from, to Module)
 }
 
 // A Mutator function is called for each Module, and can use
@@ -571,3 +572,7 @@
 		}
 	}
 }
+
+func (mctx *mutatorContext) AddInterVariantDependency(tag DependencyTag, from, to Module) {
+	mctx.context.addInterVariantDependency(mctx.module, tag, from, to)
+}