Loading Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -193,6 +193,7 @@ bootstrap_go_package { "cc/gen_test.go", "cc/genrule_test.go", "cc/library_test.go", "cc/proto_test.go", "cc/test_data_test.go", "cc/util_test.go", ], Loading android/proto.go +46 −19 Original line number Diff line number Diff line Loading @@ -14,6 +14,12 @@ package android import ( "strings" "github.com/google/blueprint/proptools" ) // TODO(ccross): protos are often used to communicate between multiple modules. If the only // way to convert a proto to source is to reference it as a source file, and external modules cannot // reference source files in other modules, then every module that owns a proto file will need to Loading @@ -22,9 +28,17 @@ package android // and then external modules could depend on the proto module but use their own settings to // generate the source. func ProtoFlags(ctx ModuleContext, p *ProtoProperties) []string { protoFlags := []string{} type ProtoFlags struct { Flags []string CanonicalPathFromRoot bool Dir ModuleGenPath SubDir ModuleGenPath OutTypeFlag string OutParams []string } func GetProtoFlags(ctx ModuleContext, p *ProtoProperties) ProtoFlags { var protoFlags []string if len(p.Proto.Local_include_dirs) > 0 { localProtoIncludeDirs := PathsForModuleSrc(ctx, p.Proto.Local_include_dirs) protoFlags = append(protoFlags, JoinWithPrefix(localProtoIncludeDirs.Strings(), "-I")) Loading @@ -34,24 +48,12 @@ func ProtoFlags(ctx ModuleContext, p *ProtoProperties) []string { protoFlags = append(protoFlags, JoinWithPrefix(rootProtoIncludeDirs.Strings(), "-I")) } return protoFlags } func ProtoCanonicalPathFromRoot(ctx ModuleContext, p *ProtoProperties) bool { if p.Proto.Canonical_path_from_root == nil { return true } return *p.Proto.Canonical_path_from_root return ProtoFlags{ Flags: protoFlags, CanonicalPathFromRoot: proptools.BoolDefault(p.Proto.Canonical_path_from_root, true), Dir: PathForModuleGen(ctx, "proto"), SubDir: PathForModuleGen(ctx, "proto", ctx.ModuleDir()), } // ProtoDir returns the module's "gen/proto" directory func ProtoDir(ctx ModuleContext) ModuleGenPath { return PathForModuleGen(ctx, "proto") } // ProtoSubDir returns the module's "gen/proto/path/to/module" directory func ProtoSubDir(ctx ModuleContext) ModuleGenPath { return PathForModuleGen(ctx, "proto", ctx.ModuleDir()) } type ProtoProperties struct { Loading @@ -76,3 +78,28 @@ type ProtoProperties struct { Canonical_path_from_root *bool } `android:"arch_variant"` } func ProtoRule(ctx ModuleContext, rule *RuleBuilder, protoFile Path, flags ProtoFlags, deps Paths, outDir WritablePath, depFile WritablePath, outputs WritablePaths) { var protoBase string if flags.CanonicalPathFromRoot { protoBase = "." } else { rel := protoFile.Rel() protoBase = strings.TrimSuffix(protoFile.String(), rel) } rule.Command(). Tool(ctx.Config().HostToolPath(ctx, "aprotoc")). FlagWithArg(flags.OutTypeFlag+"=", strings.Join(flags.OutParams, ",")+":"+outDir.String()). FlagWithDepFile("--dependency_out=", depFile). FlagWithArg("-I ", protoBase). Flags(flags.Flags). Input(protoFile). Implicits(deps). ImplicitOutputs(outputs) rule.Command(). Tool(ctx.Config().HostToolPath(ctx, "dep_fixer")).Flag(depFile.String()) } cc/builder.go +1 −4 Original line number Diff line number Diff line Loading @@ -261,12 +261,9 @@ type builderFlags struct { stripUseGnuStrip bool protoDeps android.Paths protoFlags string protoOutTypeFlag string protoOutParams string proto android.ProtoFlags protoC bool protoOptionsFile bool protoRoot bool } type Objects struct { Loading cc/cc.go +3 −6 Original line number Diff line number Diff line Loading @@ -162,13 +162,10 @@ type Flags struct { GroupStaticLibs bool proto android.ProtoFlags 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 { Loading cc/library.go +3 −3 Original line number Diff line number Diff line Loading @@ -848,10 +848,10 @@ func (library *libraryDecorator) link(ctx ModuleContext, if Bool(library.Properties.Proto.Export_proto_headers) { if library.baseCompiler.hasSrcExt(".proto") { includes := []string{} if flags.ProtoRoot { includes = append(includes, "-I"+android.ProtoSubDir(ctx).String()) if flags.proto.CanonicalPathFromRoot { includes = append(includes, "-I"+flags.proto.SubDir.String()) } includes = append(includes, "-I"+android.ProtoDir(ctx).String()) includes = append(includes, "-I"+flags.proto.Dir.String()) library.reexportFlags(includes) library.reuseExportedFlags = append(library.reuseExportedFlags, includes...) library.reexportDeps(library.baseCompiler.pathDeps) // TODO: restrict to proto deps Loading Loading
Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -193,6 +193,7 @@ bootstrap_go_package { "cc/gen_test.go", "cc/genrule_test.go", "cc/library_test.go", "cc/proto_test.go", "cc/test_data_test.go", "cc/util_test.go", ], Loading
android/proto.go +46 −19 Original line number Diff line number Diff line Loading @@ -14,6 +14,12 @@ package android import ( "strings" "github.com/google/blueprint/proptools" ) // TODO(ccross): protos are often used to communicate between multiple modules. If the only // way to convert a proto to source is to reference it as a source file, and external modules cannot // reference source files in other modules, then every module that owns a proto file will need to Loading @@ -22,9 +28,17 @@ package android // and then external modules could depend on the proto module but use their own settings to // generate the source. func ProtoFlags(ctx ModuleContext, p *ProtoProperties) []string { protoFlags := []string{} type ProtoFlags struct { Flags []string CanonicalPathFromRoot bool Dir ModuleGenPath SubDir ModuleGenPath OutTypeFlag string OutParams []string } func GetProtoFlags(ctx ModuleContext, p *ProtoProperties) ProtoFlags { var protoFlags []string if len(p.Proto.Local_include_dirs) > 0 { localProtoIncludeDirs := PathsForModuleSrc(ctx, p.Proto.Local_include_dirs) protoFlags = append(protoFlags, JoinWithPrefix(localProtoIncludeDirs.Strings(), "-I")) Loading @@ -34,24 +48,12 @@ func ProtoFlags(ctx ModuleContext, p *ProtoProperties) []string { protoFlags = append(protoFlags, JoinWithPrefix(rootProtoIncludeDirs.Strings(), "-I")) } return protoFlags } func ProtoCanonicalPathFromRoot(ctx ModuleContext, p *ProtoProperties) bool { if p.Proto.Canonical_path_from_root == nil { return true } return *p.Proto.Canonical_path_from_root return ProtoFlags{ Flags: protoFlags, CanonicalPathFromRoot: proptools.BoolDefault(p.Proto.Canonical_path_from_root, true), Dir: PathForModuleGen(ctx, "proto"), SubDir: PathForModuleGen(ctx, "proto", ctx.ModuleDir()), } // ProtoDir returns the module's "gen/proto" directory func ProtoDir(ctx ModuleContext) ModuleGenPath { return PathForModuleGen(ctx, "proto") } // ProtoSubDir returns the module's "gen/proto/path/to/module" directory func ProtoSubDir(ctx ModuleContext) ModuleGenPath { return PathForModuleGen(ctx, "proto", ctx.ModuleDir()) } type ProtoProperties struct { Loading @@ -76,3 +78,28 @@ type ProtoProperties struct { Canonical_path_from_root *bool } `android:"arch_variant"` } func ProtoRule(ctx ModuleContext, rule *RuleBuilder, protoFile Path, flags ProtoFlags, deps Paths, outDir WritablePath, depFile WritablePath, outputs WritablePaths) { var protoBase string if flags.CanonicalPathFromRoot { protoBase = "." } else { rel := protoFile.Rel() protoBase = strings.TrimSuffix(protoFile.String(), rel) } rule.Command(). Tool(ctx.Config().HostToolPath(ctx, "aprotoc")). FlagWithArg(flags.OutTypeFlag+"=", strings.Join(flags.OutParams, ",")+":"+outDir.String()). FlagWithDepFile("--dependency_out=", depFile). FlagWithArg("-I ", protoBase). Flags(flags.Flags). Input(protoFile). Implicits(deps). ImplicitOutputs(outputs) rule.Command(). Tool(ctx.Config().HostToolPath(ctx, "dep_fixer")).Flag(depFile.String()) }
cc/builder.go +1 −4 Original line number Diff line number Diff line Loading @@ -261,12 +261,9 @@ type builderFlags struct { stripUseGnuStrip bool protoDeps android.Paths protoFlags string protoOutTypeFlag string protoOutParams string proto android.ProtoFlags protoC bool protoOptionsFile bool protoRoot bool } type Objects struct { Loading
cc/cc.go +3 −6 Original line number Diff line number Diff line Loading @@ -162,13 +162,10 @@ type Flags struct { GroupStaticLibs bool proto android.ProtoFlags 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 { Loading
cc/library.go +3 −3 Original line number Diff line number Diff line Loading @@ -848,10 +848,10 @@ func (library *libraryDecorator) link(ctx ModuleContext, if Bool(library.Properties.Proto.Export_proto_headers) { if library.baseCompiler.hasSrcExt(".proto") { includes := []string{} if flags.ProtoRoot { includes = append(includes, "-I"+android.ProtoSubDir(ctx).String()) if flags.proto.CanonicalPathFromRoot { includes = append(includes, "-I"+flags.proto.SubDir.String()) } includes = append(includes, "-I"+android.ProtoDir(ctx).String()) includes = append(includes, "-I"+flags.proto.Dir.String()) library.reexportFlags(includes) library.reuseExportedFlags = append(library.reuseExportedFlags, includes...) library.reexportDeps(library.baseCompiler.pathDeps) // TODO: restrict to proto deps Loading