Add nanopb-c support
Test: cd hardware/ril; mma Change-Id: Id1481940d15a2a3f6eb29af54ee30080ff2286cb
This commit is contained in:
@@ -351,6 +351,10 @@ func (c *config) BlueprintToolLocation() string {
|
|||||||
|
|
||||||
var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil)
|
var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil)
|
||||||
|
|
||||||
|
func (c *config) HostToolPath(ctx PathContext, tool string) Path {
|
||||||
|
return PathForOutput(ctx, "host", c.PrebuiltOS(), "bin", tool)
|
||||||
|
}
|
||||||
|
|
||||||
// HostSystemTool looks for non-hermetic tools from the system we're running on.
|
// HostSystemTool looks for non-hermetic tools from the system we're running on.
|
||||||
// Generally shouldn't be used, but useful to find the XCode SDK, etc.
|
// Generally shouldn't be used, but useful to find the XCode SDK, etc.
|
||||||
func (c *config) HostSystemTool(name string) string {
|
func (c *config) HostSystemTool(name string) string {
|
||||||
|
@@ -231,8 +231,6 @@ type builderFlags struct {
|
|||||||
ldFlags string
|
ldFlags string
|
||||||
libFlags string
|
libFlags string
|
||||||
yaccFlags string
|
yaccFlags string
|
||||||
protoFlags string
|
|
||||||
protoOutParams string
|
|
||||||
tidyFlags string
|
tidyFlags string
|
||||||
sAbiFlags string
|
sAbiFlags string
|
||||||
yasmFlags string
|
yasmFlags string
|
||||||
@@ -242,7 +240,6 @@ type builderFlags struct {
|
|||||||
tidy bool
|
tidy bool
|
||||||
coverage bool
|
coverage bool
|
||||||
sAbiDump bool
|
sAbiDump bool
|
||||||
protoRoot bool
|
|
||||||
|
|
||||||
systemIncludeFlags string
|
systemIncludeFlags string
|
||||||
|
|
||||||
@@ -252,6 +249,14 @@ type builderFlags struct {
|
|||||||
stripKeepMiniDebugInfo bool
|
stripKeepMiniDebugInfo bool
|
||||||
stripAddGnuDebuglink bool
|
stripAddGnuDebuglink bool
|
||||||
stripUseLlvmStrip bool
|
stripUseLlvmStrip bool
|
||||||
|
|
||||||
|
protoDeps android.Paths
|
||||||
|
protoFlags string
|
||||||
|
protoOutTypeFlag string
|
||||||
|
protoOutParams string
|
||||||
|
protoC bool
|
||||||
|
protoOptionsFile bool
|
||||||
|
protoRoot bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Objects struct {
|
type Objects struct {
|
||||||
|
11
cc/cc.go
11
cc/cc.go
@@ -130,8 +130,6 @@ type Flags struct {
|
|||||||
CppFlags []string // Flags that apply to C++ source files
|
CppFlags []string // Flags that apply to C++ source files
|
||||||
ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
|
ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
|
||||||
YaccFlags []string // Flags that apply to Yacc source files
|
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
|
aidlFlags []string // Flags that apply to aidl source files
|
||||||
rsFlags []string // Flags that apply to renderscript source files
|
rsFlags []string // Flags that apply to renderscript source files
|
||||||
LdFlags []string // Flags that apply to linker command lines
|
LdFlags []string // Flags that apply to linker command lines
|
||||||
@@ -148,7 +146,6 @@ type Flags struct {
|
|||||||
Tidy bool
|
Tidy bool
|
||||||
Coverage bool
|
Coverage bool
|
||||||
SAbiDump bool
|
SAbiDump bool
|
||||||
ProtoRoot bool
|
|
||||||
|
|
||||||
RequiredInstructionSet string
|
RequiredInstructionSet string
|
||||||
DynamicLinker string
|
DynamicLinker string
|
||||||
@@ -157,6 +154,14 @@ type Flags struct {
|
|||||||
LdFlagsDeps android.Paths // Files depended on by linker flags
|
LdFlagsDeps android.Paths // Files depended on by linker flags
|
||||||
|
|
||||||
GroupStaticLibs bool
|
GroupStaticLibs bool
|
||||||
|
|
||||||
|
protoDeps android.Paths
|
||||||
|
protoFlags []string // Flags that apply to proto source files
|
||||||
|
protoOutTypeFlag string // The output type, --cpp_out for example
|
||||||
|
protoOutParams []string // Flags that modify the output of proto generated files
|
||||||
|
protoC bool // Whether to use C instead of C++
|
||||||
|
protoOptionsFile bool // Whether to look for a .options file next to the .proto
|
||||||
|
ProtoRoot bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ObjectLinkerProperties struct {
|
type ObjectLinkerProperties struct {
|
||||||
|
@@ -182,8 +182,7 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
|||||||
srcFiles[i] = cppFile
|
srcFiles[i] = cppFile
|
||||||
genLex(ctx, srcFile, cppFile)
|
genLex(ctx, srcFile, cppFile)
|
||||||
case ".proto":
|
case ".proto":
|
||||||
ccFile, headerFile := genProto(ctx, srcFile, buildFlags.protoFlags,
|
ccFile, headerFile := genProto(ctx, srcFile, buildFlags)
|
||||||
buildFlags.protoOutParams, buildFlags.protoRoot)
|
|
||||||
srcFiles[i] = ccFile
|
srcFiles[i] = ccFile
|
||||||
deps = append(deps, headerFile)
|
deps = append(deps, headerFile)
|
||||||
case ".aidl":
|
case ".aidl":
|
||||||
|
66
cc/proto.go
66
cc/proto.go
@@ -31,41 +31,56 @@ func init() {
|
|||||||
var (
|
var (
|
||||||
proto = pctx.AndroidStaticRule("protoc",
|
proto = pctx.AndroidStaticRule("protoc",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: "$protocCmd --cpp_out=$protoOutParams:$outDir --dependency_out=$out.d -I $protoBase $protoFlags $in && " +
|
Command: "$protocCmd $protoOut=$protoOutParams:$outDir --dependency_out=$out.d -I $protoBase $protoFlags $in && " +
|
||||||
`$depFixCmd $out.d`,
|
`$depFixCmd $out.d`,
|
||||||
CommandDeps: []string{"$protocCmd", "$depFixCmd"},
|
CommandDeps: []string{"$protocCmd", "$depFixCmd"},
|
||||||
Depfile: "${out}.d",
|
Depfile: "${out}.d",
|
||||||
Deps: blueprint.DepsGCC,
|
Deps: blueprint.DepsGCC,
|
||||||
}, "protoFlags", "protoOutParams", "protoBase", "outDir")
|
}, "protoFlags", "protoOut", "protoOutParams", "protoBase", "outDir")
|
||||||
)
|
)
|
||||||
|
|
||||||
// genProto creates a rule to convert a .proto file to generated .pb.cc and .pb.h files and returns
|
// 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.
|
// the paths to the generated files.
|
||||||
func genProto(ctx android.ModuleContext, protoFile android.Path,
|
func genProto(ctx android.ModuleContext, protoFile android.Path, flags builderFlags) (ccFile, headerFile android.WritablePath) {
|
||||||
protoFlags, protoOutParams string, root bool) (ccFile, headerFile android.WritablePath) {
|
|
||||||
|
srcSuffix := ".cc"
|
||||||
|
if flags.protoC {
|
||||||
|
srcSuffix = ".c"
|
||||||
|
}
|
||||||
|
|
||||||
var protoBase string
|
var protoBase string
|
||||||
if root {
|
if flags.protoRoot {
|
||||||
protoBase = "."
|
protoBase = "."
|
||||||
ccFile = android.GenPathWithExt(ctx, "proto", protoFile, "pb.cc")
|
ccFile = android.GenPathWithExt(ctx, "proto", protoFile, "pb"+srcSuffix)
|
||||||
headerFile = android.GenPathWithExt(ctx, "proto", protoFile, "pb.h")
|
headerFile = android.GenPathWithExt(ctx, "proto", protoFile, "pb.h")
|
||||||
} else {
|
} else {
|
||||||
rel := protoFile.Rel()
|
rel := protoFile.Rel()
|
||||||
protoBase = strings.TrimSuffix(protoFile.String(), rel)
|
protoBase = strings.TrimSuffix(protoFile.String(), rel)
|
||||||
ccFile = android.PathForModuleGen(ctx, "proto", pathtools.ReplaceExtension(rel, "pb.cc"))
|
ccFile = android.PathForModuleGen(ctx, "proto", pathtools.ReplaceExtension(rel, "pb"+srcSuffix))
|
||||||
headerFile = android.PathForModuleGen(ctx, "proto", pathtools.ReplaceExtension(rel, "pb.h"))
|
headerFile = android.PathForModuleGen(ctx, "proto", pathtools.ReplaceExtension(rel, "pb.h"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protoDeps := flags.protoDeps
|
||||||
|
if flags.protoOptionsFile {
|
||||||
|
optionsFile := pathtools.ReplaceExtension(protoFile.String(), "options")
|
||||||
|
optionsPath := android.ExistentPathForSource(ctx, optionsFile)
|
||||||
|
if optionsPath.Valid() {
|
||||||
|
protoDeps = append(android.Paths{optionsPath.Path()}, protoDeps...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: proto,
|
Rule: proto,
|
||||||
Description: "protoc " + protoFile.Rel(),
|
Description: "protoc " + protoFile.Rel(),
|
||||||
Output: ccFile,
|
Output: ccFile,
|
||||||
ImplicitOutput: headerFile,
|
ImplicitOutput: headerFile,
|
||||||
Input: protoFile,
|
Input: protoFile,
|
||||||
|
Implicits: protoDeps,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"outDir": android.ProtoDir(ctx).String(),
|
"outDir": android.ProtoDir(ctx).String(),
|
||||||
"protoFlags": protoFlags,
|
"protoFlags": flags.protoFlags,
|
||||||
"protoOutParams": protoOutParams,
|
"protoOut": flags.protoOutTypeFlag,
|
||||||
|
"protoOutParams": flags.protoOutParams,
|
||||||
"protoBase": protoBase,
|
"protoBase": protoBase,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -91,6 +106,12 @@ func protoDeps(ctx BaseModuleContext, deps Deps, p *android.ProtoProperties, sta
|
|||||||
} else {
|
} else {
|
||||||
lib = "libprotobuf-cpp-lite"
|
lib = "libprotobuf-cpp-lite"
|
||||||
}
|
}
|
||||||
|
case "nanopb-c":
|
||||||
|
lib = "libprotobuf-c-nano"
|
||||||
|
static = true
|
||||||
|
case "nanopb-c-enable_malloc":
|
||||||
|
lib = "libprotobuf-c-nano-enable_malloc"
|
||||||
|
static = true
|
||||||
default:
|
default:
|
||||||
ctx.PropertyErrorf("proto.type", "unknown proto type %q",
|
ctx.PropertyErrorf("proto.type", "unknown proto type %q",
|
||||||
String(p.Proto.Type))
|
String(p.Proto.Type))
|
||||||
@@ -118,8 +139,33 @@ func protoFlags(ctx ModuleContext, flags Flags, p *android.ProtoProperties) Flag
|
|||||||
|
|
||||||
flags.protoFlags = android.ProtoFlags(ctx, p)
|
flags.protoFlags = android.ProtoFlags(ctx, p)
|
||||||
|
|
||||||
if String(p.Proto.Type) == "lite" {
|
var plugin string
|
||||||
|
|
||||||
|
switch String(p.Proto.Type) {
|
||||||
|
case "nanopb-c", "nanopb-c-enable_malloc":
|
||||||
|
flags.protoC = true
|
||||||
|
flags.protoOptionsFile = true
|
||||||
|
flags.protoOutTypeFlag = "--nanopb_out"
|
||||||
|
plugin = "protoc-gen-nanopb"
|
||||||
|
case "full":
|
||||||
|
flags.protoOutTypeFlag = "--cpp_out"
|
||||||
|
case "lite":
|
||||||
|
flags.protoOutTypeFlag = "--cpp_out"
|
||||||
flags.protoOutParams = append(flags.protoOutParams, "lite")
|
flags.protoOutParams = append(flags.protoOutParams, "lite")
|
||||||
|
case "":
|
||||||
|
// TODO(b/119714316): this should be equivalent to "lite" in
|
||||||
|
// order to match protoDeps, but some modules are depending on
|
||||||
|
// this behavior
|
||||||
|
flags.protoOutTypeFlag = "--cpp_out"
|
||||||
|
default:
|
||||||
|
ctx.PropertyErrorf("proto.type", "unknown proto type %q",
|
||||||
|
String(p.Proto.Type))
|
||||||
|
}
|
||||||
|
|
||||||
|
if plugin != "" {
|
||||||
|
path := ctx.Config().HostToolPath(ctx, plugin)
|
||||||
|
flags.protoDeps = append(flags.protoDeps, path)
|
||||||
|
flags.protoFlags = append(flags.protoFlags, "--plugin="+path.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
|
11
cc/util.go
11
cc/util.go
@@ -68,8 +68,6 @@ func flagsToBuilderFlags(in Flags) builderFlags {
|
|||||||
conlyFlags: strings.Join(in.ConlyFlags, " "),
|
conlyFlags: strings.Join(in.ConlyFlags, " "),
|
||||||
cppFlags: strings.Join(in.CppFlags, " "),
|
cppFlags: strings.Join(in.CppFlags, " "),
|
||||||
yaccFlags: strings.Join(in.YaccFlags, " "),
|
yaccFlags: strings.Join(in.YaccFlags, " "),
|
||||||
protoFlags: strings.Join(in.protoFlags, " "),
|
|
||||||
protoOutParams: strings.Join(in.protoOutParams, ","),
|
|
||||||
aidlFlags: strings.Join(in.aidlFlags, " "),
|
aidlFlags: strings.Join(in.aidlFlags, " "),
|
||||||
rsFlags: strings.Join(in.rsFlags, " "),
|
rsFlags: strings.Join(in.rsFlags, " "),
|
||||||
ldFlags: strings.Join(in.LdFlags, " "),
|
ldFlags: strings.Join(in.LdFlags, " "),
|
||||||
@@ -81,11 +79,18 @@ func flagsToBuilderFlags(in Flags) builderFlags {
|
|||||||
coverage: in.Coverage,
|
coverage: in.Coverage,
|
||||||
tidy: in.Tidy,
|
tidy: in.Tidy,
|
||||||
sAbiDump: in.SAbiDump,
|
sAbiDump: in.SAbiDump,
|
||||||
protoRoot: in.ProtoRoot,
|
|
||||||
|
|
||||||
systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
|
systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
|
||||||
|
|
||||||
groupStaticLibs: in.GroupStaticLibs,
|
groupStaticLibs: in.GroupStaticLibs,
|
||||||
|
|
||||||
|
protoDeps: in.protoDeps,
|
||||||
|
protoFlags: strings.Join(in.protoFlags, " "),
|
||||||
|
protoOutTypeFlag: in.protoOutTypeFlag,
|
||||||
|
protoOutParams: strings.Join(in.protoOutParams, ","),
|
||||||
|
protoC: in.protoC,
|
||||||
|
protoOptionsFile: in.protoOptionsFile,
|
||||||
|
protoRoot: in.ProtoRoot,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user