Add -gen suffix to genrule targets with conflicts

Fixes: 224580460
Test: m nothing
Change-Id: I3af3eb0fb7f65216087482eb620484229ac7d674
diff --git a/genrule/genrule.go b/genrule/genrule.go
index a7264cc..b29e2c9 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -1012,6 +1012,17 @@
 				break
 			}
 		}
+		bazelName := m.Name()
+		for _, out := range outs {
+			if out == bazelName {
+				// This is a workaround to circumvent a Bazel warning where a genrule's
+				// out may not have the same name as the target itself. This makes no
+				// difference for reverse dependencies, because they may depend on the
+				// out file by name.
+				bazelName = bazelName + "-gen"
+				break
+			}
+		}
 		attrs := &bazelGenruleAttributes{
 			Srcs:  srcs,
 			Outs:  outs,
@@ -1022,7 +1033,7 @@
 			Rule_class: "genrule",
 		}
 		ctx.CreateBazelTargetModule(props, android.CommonAttributes{
-			Name: m.Name(),
+			Name: bazelName,
 			Tags: tags,
 		}, attrs)
 	}