Add subdir to GenPath

We were emulating this for proto files, standardize it and make the
other generators use it as well.

Test: Compare out/soong/build.ninja before/after change
Test: mmma -j system/tools/hidl
Change-Id: I1888c7b981749060a398387bbb9b481270bf6d75
diff --git a/cc/builder.go b/cc/builder.go
index faa39d1..f795bba 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -234,7 +234,7 @@
 	}
 
 	for i, srcFile := range srcFiles {
-		objFile := android.ObjPathWithExt(ctx, srcFile, subdir, "o")
+		objFile := android.ObjPathWithExt(ctx, subdir, srcFile, "o")
 
 		objFiles[i] = objFile
 
@@ -285,7 +285,7 @@
 		})
 
 		if tidy {
-			tidyFile := android.ObjPathWithExt(ctx, srcFile, subdir, "tidy")
+			tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy")
 			tidyFiles = append(tidyFiles, tidyFile)
 
 			ctx.ModuleBuild(pctx, android.ModuleBuildParams{
diff --git a/cc/gen.go b/cc/gen.go
index 1451895..9d3a67c 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -48,7 +48,7 @@
 )
 
 func genYacc(ctx android.ModuleContext, yaccFile android.Path, outFile android.ModuleGenPath, yaccFlags string) (headerFile android.ModuleGenPath) {
-	headerFile = android.GenPathWithExt(ctx, yaccFile, "h")
+	headerFile = android.GenPathWithExt(ctx, "yacc", yaccFile, "h")
 
 	ctx.ModuleBuild(pctx, android.ModuleBuildParams{
 		Rule:    yacc,
@@ -80,19 +80,19 @@
 	for i, srcFile := range srcFiles {
 		switch srcFile.Ext() {
 		case ".y":
-			cFile := android.GenPathWithExt(ctx, srcFile, "c")
+			cFile := android.GenPathWithExt(ctx, "yacc", srcFile, "c")
 			srcFiles[i] = cFile
 			deps = append(deps, genYacc(ctx, srcFile, cFile, buildFlags.yaccFlags))
 		case ".yy":
-			cppFile := android.GenPathWithExt(ctx, srcFile, "cpp")
+			cppFile := android.GenPathWithExt(ctx, "yacc", srcFile, "cpp")
 			srcFiles[i] = cppFile
 			deps = append(deps, genYacc(ctx, srcFile, cppFile, buildFlags.yaccFlags))
 		case ".l":
-			cFile := android.GenPathWithExt(ctx, srcFile, "c")
+			cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c")
 			srcFiles[i] = cFile
 			genLex(ctx, srcFile, cFile)
 		case ".ll":
-			cppFile := android.GenPathWithExt(ctx, srcFile, "cpp")
+			cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp")
 			srcFiles[i] = cppFile
 			genLex(ctx, srcFile, cppFile)
 		case ".proto":
diff --git a/cc/proto.go b/cc/proto.go
index 3d3ca59..51f5448 100644
--- a/cc/proto.go
+++ b/cc/proto.go
@@ -15,8 +15,6 @@
 package cc
 
 import (
-	"strings"
-
 	"github.com/google/blueprint"
 
 	"android/soong/android"
@@ -46,17 +44,14 @@
 func genProto(ctx android.ModuleContext, protoFile android.Path,
 	protoFlags string) (android.ModuleGenPath, android.ModuleGenPath) {
 
-	outDir := android.PathForModuleGen(ctx, "proto")
-	baseName := strings.TrimSuffix(protoFile.Base(), protoFile.Ext())
-
-	outFile := android.PathForModuleGen(ctx, "proto", ctx.ModuleDir(), baseName+".pb.cc")
-	headerFile := android.PathForModuleGen(ctx, "proto", ctx.ModuleDir(), baseName+".pb.h")
+	outFile := android.GenPathWithExt(ctx, "proto", protoFile, "pb.cc")
+	headerFile := android.GenPathWithExt(ctx, "proto", protoFile, "pb.h")
 	ctx.ModuleBuild(pctx, android.ModuleBuildParams{
 		Rule:    proto,
 		Outputs: android.WritablePaths{outFile, headerFile},
 		Input:   protoFile,
 		Args: map[string]string{
-			"outDir":     outDir.String(),
+			"outDir":     protoDir(ctx).String(),
 			"protoFlags": protoFlags,
 		},
 	})