Use dependency tags for genrules

So that we don't get confused when using :<module> in srcs to depend on
a module that could also be a HostBinTool.

Test: m -j
Change-Id: Ia3b1c26826e70f84c6dc5ff78c95dd11d76901b6
diff --git a/cc/cc.go b/cc/cc.go
index fe9c4a4..f0ba1c6 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -956,6 +956,7 @@
 		if cc == nil {
 			switch tag {
 			case android.DefaultsDepTag, android.SourceDepTag:
+				// Nothing to do
 			case genSourceDepTag:
 				if genRule, ok := m.(genrule.SourceFileGenerator); ok {
 					depPaths.GeneratedSources = append(depPaths.GeneratedSources,
diff --git a/genrule/genrule.go b/genrule/genrule.go
index c5de1fd..921a64e 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -48,6 +48,12 @@
 	HostToolPath() android.OptionalPath
 }
 
+type hostToolDependencyTag struct {
+	blueprint.BaseDependencyTag
+}
+
+var hostToolDepTag hostToolDependencyTag
+
 type generatorProperties struct {
 	// The command to run on one or more input files. Cmd supports substitution of a few variables
 	// (the actual substitution is implemented in GenerateAndroidBuildActions below)
@@ -123,7 +129,7 @@
 		if len(g.properties.Tools) > 0 {
 			ctx.AddFarVariationDependencies([]blueprint.Variation{
 				{"arch", ctx.AConfig().BuildOsVariant},
-			}, nil, g.properties.Tools...)
+			}, hostToolDepTag, g.properties.Tools...)
 		}
 	}
 }
@@ -147,23 +153,37 @@
 
 	if len(g.properties.Tools) > 0 {
 		ctx.VisitDirectDeps(func(module blueprint.Module) {
-			if t, ok := module.(HostToolProvider); ok {
-				p := t.HostToolPath()
-				if p.Valid() {
-					g.deps = append(g.deps, p.Path())
-					tool := ctx.OtherModuleName(module)
-					if _, exists := tools[tool]; !exists {
-						tools[tool] = p.Path()
+			switch ctx.OtherModuleDependencyTag(module) {
+			case android.SourceDepTag:
+				// Nothing to do
+			case hostToolDepTag:
+				tool := ctx.OtherModuleName(module)
+
+				if t, ok := module.(HostToolProvider); ok {
+					p := t.HostToolPath()
+					if p.Valid() {
+						g.deps = append(g.deps, p.Path())
+						if _, exists := tools[tool]; !exists {
+							tools[tool] = p.Path()
+						} else {
+							ctx.ModuleErrorf("multiple tools for %q, %q and %q", tool, tools[tool], p.Path().String())
+						}
 					} else {
-						ctx.ModuleErrorf("multiple tools for %q, %q and %q", tool, tools[tool], p.Path().String())
+						ctx.ModuleErrorf("host tool %q missing output file", tool)
 					}
 				} else {
-					ctx.ModuleErrorf("host tool %q missing output file", ctx.OtherModuleName(module))
+					ctx.ModuleErrorf("%q is not a host tool provider", tool)
 				}
+			default:
+				ctx.ModuleErrorf("unknown dependency on %q", ctx.OtherModuleName(module))
 			}
 		})
 	}
 
+	if ctx.Failed() {
+		return
+	}
+
 	for _, tool := range g.properties.Tool_files {
 		toolPath := android.PathForModuleSrc(ctx, tool)
 		g.deps = append(g.deps, toolPath)
diff --git a/java/java.go b/java/java.go
index 2298acc..b4ce35e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -249,6 +249,7 @@
 		if dep == nil {
 			switch tag {
 			case android.DefaultsDepTag, android.SourceDepTag:
+				// Nothing to do
 			default:
 				ctx.ModuleErrorf("depends on non-java module %q", otherName)
 			}