When compiling with the lite protobuf option, pass the option to aprotoc to force the lite runtime.

Test: make
Merged-In: I450f89d144d496a6ddfccc6a6a5a679a05809595
Change-Id: I450f89d144d496a6ddfccc6a6a5a679a05809595
diff --git a/cc/builder.go b/cc/builder.go
index b5f4c5c..e583834 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -231,27 +231,28 @@
 }
 
 type builderFlags struct {
-	globalFlags   string
-	arFlags       string
-	asFlags       string
-	cFlags        string
-	toolingCFlags string // A separate set of Cflags for clang LibTooling tools
-	conlyFlags    string
-	cppFlags      string
-	ldFlags       string
-	libFlags      string
-	yaccFlags     string
-	protoFlags    string
-	tidyFlags     string
-	sAbiFlags     string
-	yasmFlags     string
-	aidlFlags     string
-	rsFlags       string
-	toolchain     config.Toolchain
-	clang         bool
-	tidy          bool
-	coverage      bool
-	sAbiDump      bool
+	globalFlags    string
+	arFlags        string
+	asFlags        string
+	cFlags         string
+	toolingCFlags  string // A separate set of Cflags for clang LibTooling tools
+	conlyFlags     string
+	cppFlags       string
+	ldFlags        string
+	libFlags       string
+	yaccFlags      string
+	protoFlags     string
+	protoOutParams string
+	tidyFlags      string
+	sAbiFlags      string
+	yasmFlags      string
+	aidlFlags      string
+	rsFlags        string
+	toolchain      config.Toolchain
+	clang          bool
+	tidy           bool
+	coverage       bool
+	sAbiDump       bool
 
 	systemIncludeFlags string
 
diff --git a/cc/cc.go b/cc/cc.go
index 715919f..6e28522 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -116,6 +116,7 @@
 	ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
 	YaccFlags       []string // Flags that apply to Yacc source files
 	protoFlags      []string // Flags that apply to proto source files
+	protoOutParams  []string // Flags that modify the output of proto generated files
 	aidlFlags       []string // Flags that apply to aidl source files
 	rsFlags         []string // Flags that apply to renderscript source files
 	LdFlags         []string // Flags that apply to linker command lines
diff --git a/cc/gen.go b/cc/gen.go
index 15b37b5..e9d1e2a 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -153,7 +153,8 @@
 			srcFiles[i] = cppFile
 			genLex(ctx, srcFile, cppFile)
 		case ".proto":
-			ccFile, headerFile := genProto(ctx, srcFile, buildFlags.protoFlags)
+			ccFile, headerFile := genProto(ctx, srcFile, buildFlags.protoFlags,
+				buildFlags.protoOutParams)
 			srcFiles[i] = ccFile
 			deps = append(deps, headerFile)
 		case ".aidl":
diff --git a/cc/proto.go b/cc/proto.go
index e7f1d41..3b5fd3b 100644
--- a/cc/proto.go
+++ b/cc/proto.go
@@ -16,6 +16,7 @@
 
 import (
 	"github.com/google/blueprint"
+	"github.com/google/blueprint/proptools"
 
 	"android/soong/android"
 )
@@ -27,15 +28,15 @@
 var (
 	proto = pctx.AndroidStaticRule("protoc",
 		blueprint.RuleParams{
-			Command:     "$protocCmd --cpp_out=$outDir $protoFlags $in",
+			Command:     "$protocCmd --cpp_out=$protoOutParams:$outDir $protoFlags $in",
 			CommandDeps: []string{"$protocCmd"},
-		}, "protoFlags", "outDir")
+		}, "protoFlags", "protoOutParams", "outDir")
 )
 
 // genProto creates a rule to convert a .proto file to generated .pb.cc and .pb.h files and returns
 // the paths to the generated files.
 func genProto(ctx android.ModuleContext, protoFile android.Path,
-	protoFlags string) (ccFile, headerFile android.WritablePath) {
+	protoFlags string, protoOutParams string) (ccFile, headerFile android.WritablePath) {
 
 	ccFile = android.GenPathWithExt(ctx, "proto", protoFile, "pb.cc")
 	headerFile = android.GenPathWithExt(ctx, "proto", protoFile, "pb.h")
@@ -46,8 +47,9 @@
 		Outputs:     android.WritablePaths{ccFile, headerFile},
 		Input:       protoFile,
 		Args: map[string]string{
-			"outDir":     android.ProtoDir(ctx).String(),
-			"protoFlags": protoFlags,
+			"outDir":         android.ProtoDir(ctx).String(),
+			"protoFlags":     protoFlags,
+			"protoOutParams": protoOutParams,
 		},
 	})
 
@@ -97,5 +99,9 @@
 
 	flags.protoFlags = android.ProtoFlags(ctx, p)
 
+	if proptools.String(p.Proto.Type) == "lite" {
+		flags.protoOutParams = []string{"lite"}
+	}
+
 	return flags
 }
diff --git a/cc/util.go b/cc/util.go
index cc89af6..7041029 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -97,27 +97,28 @@
 
 func flagsToBuilderFlags(in Flags) builderFlags {
 	return builderFlags{
-		globalFlags:   strings.Join(in.GlobalFlags, " "),
-		arFlags:       strings.Join(in.ArFlags, " "),
-		asFlags:       strings.Join(in.AsFlags, " "),
-		cFlags:        strings.Join(in.CFlags, " "),
-		toolingCFlags: strings.Join(in.ToolingCFlags, " "),
-		conlyFlags:    strings.Join(in.ConlyFlags, " "),
-		cppFlags:      strings.Join(in.CppFlags, " "),
-		yaccFlags:     strings.Join(in.YaccFlags, " "),
-		protoFlags:    strings.Join(in.protoFlags, " "),
-		aidlFlags:     strings.Join(in.aidlFlags, " "),
-		rsFlags:       strings.Join(in.rsFlags, " "),
-		ldFlags:       strings.Join(in.LdFlags, " "),
-		libFlags:      strings.Join(in.libFlags, " "),
-		tidyFlags:     strings.Join(in.TidyFlags, " "),
-		sAbiFlags:     strings.Join(in.SAbiFlags, " "),
-		yasmFlags:     strings.Join(in.YasmFlags, " "),
-		toolchain:     in.Toolchain,
-		clang:         in.Clang,
-		coverage:      in.Coverage,
-		tidy:          in.Tidy,
-		sAbiDump:      in.SAbiDump,
+		globalFlags:    strings.Join(in.GlobalFlags, " "),
+		arFlags:        strings.Join(in.ArFlags, " "),
+		asFlags:        strings.Join(in.AsFlags, " "),
+		cFlags:         strings.Join(in.CFlags, " "),
+		toolingCFlags:  strings.Join(in.ToolingCFlags, " "),
+		conlyFlags:     strings.Join(in.ConlyFlags, " "),
+		cppFlags:       strings.Join(in.CppFlags, " "),
+		yaccFlags:      strings.Join(in.YaccFlags, " "),
+		protoFlags:     strings.Join(in.protoFlags, " "),
+		protoOutParams: strings.Join(in.protoOutParams, ":"),
+		aidlFlags:      strings.Join(in.aidlFlags, " "),
+		rsFlags:        strings.Join(in.rsFlags, " "),
+		ldFlags:        strings.Join(in.LdFlags, " "),
+		libFlags:       strings.Join(in.libFlags, " "),
+		tidyFlags:      strings.Join(in.TidyFlags, " "),
+		sAbiFlags:      strings.Join(in.SAbiFlags, " "),
+		yasmFlags:      strings.Join(in.YasmFlags, " "),
+		toolchain:      in.Toolchain,
+		clang:          in.Clang,
+		coverage:       in.Coverage,
+		tidy:           in.Tidy,
+		sAbiDump:       in.SAbiDump,
 
 		systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
 
diff --git a/java/builder.go b/java/builder.go
index 10dfe06..48fba23 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -200,8 +200,9 @@
 	kotlincFlags     string
 	kotlincClasspath classpath
 
-	protoFlags   []string
-	protoOutFlag string
+	protoFlags       []string
+	protoOutTypeFlag string // The flag itself: --java_out
+	protoOutParams   string // Parameters to that flag: --java_out=$protoOutParams:$outDir
 }
 
 func TransformKotlinToClasses(ctx android.ModuleContext, outputFile android.WritablePath,
diff --git a/java/gen.go b/java/gen.go
index 7a0dcac..4893e88 100644
--- a/java/gen.go
+++ b/java/gen.go
@@ -107,7 +107,7 @@
 	if len(protoFiles) > 0 {
 		protoSrcJar := android.PathForModuleGen(ctx, "proto.srcjar")
 		genProto(ctx, protoSrcJar, protoFiles,
-			flags.protoFlags, flags.protoOutFlag, "")
+			flags.protoFlags, flags.protoOutTypeFlag, flags.protoOutParams)
 
 		outSrcFiles = append(outSrcFiles, protoSrcJar)
 	}
diff --git a/java/proto.go b/java/proto.go
index 17f02a3..428413f 100644
--- a/java/proto.go
+++ b/java/proto.go
@@ -31,17 +31,17 @@
 	proto = pctx.AndroidStaticRule("protoc",
 		blueprint.RuleParams{
 			Command: `rm -rf $outDir && mkdir -p $outDir && ` +
-				`$protocCmd $protoOut=$protoOutFlags:$outDir $protoFlags $in && ` +
+				`$protocCmd $protoOut=$protoOutParams:$outDir $protoFlags $in && ` +
 				`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
 			CommandDeps: []string{
 				"$protocCmd",
 				"${config.SoongZipCmd}",
 			},
-		}, "protoFlags", "protoOut", "protoOutFlags", "outDir")
+		}, "protoFlags", "protoOut", "protoOutParams", "outDir")
 )
 
 func genProto(ctx android.ModuleContext, outputSrcJar android.WritablePath,
-	protoFiles android.Paths, protoFlags []string, protoOut, protoOutFlags string) {
+	protoFiles android.Paths, protoFlags []string, protoOut, protoOutParams string) {
 
 	ctx.Build(pctx, android.BuildParams{
 		Rule:        proto,
@@ -49,10 +49,10 @@
 		Output:      outputSrcJar,
 		Inputs:      protoFiles,
 		Args: map[string]string{
-			"outDir":        android.ProtoDir(ctx).String(),
-			"protoOut":      protoOut,
-			"protoOutFlags": protoOutFlags,
-			"protoFlags":    strings.Join(protoFlags, " "),
+			"outDir":         android.ProtoDir(ctx).String(),
+			"protoOut":       protoOut,
+			"protoOutParams": protoOutParams,
+			"protoFlags":     strings.Join(protoFlags, " "),
 		},
 	})
 }
@@ -80,11 +80,14 @@
 func protoFlags(ctx android.ModuleContext, p *android.ProtoProperties, flags javaBuilderFlags) javaBuilderFlags {
 	switch proptools.String(p.Proto.Type) {
 	case "micro":
-		flags.protoOutFlag = "--javamicro_out"
+		flags.protoOutTypeFlag = "--javamicro_out"
 	case "nano":
-		flags.protoOutFlag = "--javanano_out"
-	case "lite", "full", "":
-		flags.protoOutFlag = "--java_out"
+		flags.protoOutTypeFlag = "--javanano_out"
+	case "lite":
+		flags.protoOutTypeFlag = "--java_out"
+		flags.protoOutParams = "lite"
+	case "full", "":
+		flags.protoOutTypeFlag = "--java_out"
 	default:
 		ctx.PropertyErrorf("proto.type", "unknown proto type %q",
 			proptools.String(p.Proto.Type))