Handle multiple blueprint files in one dir

If there are multiple blueprint files in one directory, say an
Android.bp, and a build=['other.bp'] entry that pulls in another
blueprint file from the same directory, we'd look for a matching
Android.mk twice. This would cause duplicate glob rules.

Instead, keep track of blueprint directories rather than files.

Change-Id: I4f224e51337ffd5e5e48257ac3458c2d8b2061fa
diff --git a/common/androidmk.go b/common/androidmk.go
index d308936..5dd422d 100644
--- a/common/androidmk.go
+++ b/common/androidmk.go
@@ -51,33 +51,32 @@
 type androidMkSingleton struct{}
 
 func (c *androidMkSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
-	fileModules := make(map[string][]blueprint.Module)
-	hasBPFile := make(map[string]bool)
-	bpFiles := []string{}
+	dirModules := make(map[string][]blueprint.Module)
+	hasBPDir := make(map[string]bool)
+	bpDirs := []string{}
 
 	ctx.SetNinjaBuildDir(pctx, filepath.Join(ctx.Config().(Config).BuildDir(), ".."))
 
 	ctx.VisitAllModules(func(module blueprint.Module) {
 		if _, ok := module.(AndroidModule); ok {
-			bpFile := ctx.BlueprintFile(module)
+			bpDir := filepath.Dir(ctx.BlueprintFile(module))
 
-			if !hasBPFile[bpFile] {
-				hasBPFile[bpFile] = true
-				bpFiles = append(bpFiles, bpFile)
+			if !hasBPDir[bpDir] {
+				hasBPDir[bpDir] = true
+				bpDirs = append(bpDirs, bpDir)
 			}
 
-			fileModules[bpFile] = append(fileModules[bpFile], module)
+			dirModules[bpDir] = append(dirModules[bpDir], module)
 		}
 	})
 
 	// Gather list of eligible Android modules for translation
 	androidMkModules := make(map[blueprint.Module]bool)
-	var validBpFiles []string
 	srcDir := ctx.Config().(Config).SrcDir()
 	intermediatesDir := filepath.Join(ctx.Config().(Config).IntermediatesDir(), "androidmk")
-	sort.Strings(bpFiles)
-	for _, origBp := range bpFiles {
-		mkFile := filepath.Join(srcDir, filepath.Dir(origBp), "Android.mk")
+	sort.Strings(bpDirs)
+	for _, bpDir := range bpDirs {
+		mkFile := filepath.Join(srcDir, bpDir, "Android.mk")
 
 		files, err := Glob(ctx, intermediatesDir, mkFile, nil)
 		if err != nil {
@@ -93,9 +92,7 @@
 			continue
 		}
 
-		validBpFiles = append(validBpFiles, origBp)
-
-		for _, mod := range fileModules[origBp] {
+		for _, mod := range dirModules[bpDir] {
 			androidMkModules[mod] = true
 		}
 	}