diff options
author | Colin Cross <ccross@android.com> | 2019-03-28 14:45:07 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2019-04-02 16:38:47 +0000 |
commit | 19878da6a062ef474a1c905f48b1efb986862050 (patch) | |
tree | 389a8ac830a6bc2cee797f0daa70677450b98957 /android | |
parent | 6e1c3faed54db8db15ad46cbcb220f334fdff5f2 (diff) | |
download | build_soong-19878da6a062ef474a1c905f48b1efb986862050.tar.gz build_soong-19878da6a062ef474a1c905f48b1efb986862050.tar.bz2 build_soong-19878da6a062ef474a1c905f48b1efb986862050.zip |
Move proto compilation to RuleBuilder
Using blueprint.Rule for protoc commands was causing code duplication
because there was no good way to run the same protoc for cc, java and
python but then run custom source packaging steps for java and python.
Move most of the code into a common function that returns a
RuleBuilder, and then let java and python add their own commands at
the end of the rule.
Bug: 70706119
Test: All Soong tests
Test: m checkbuild
Change-Id: Ic692136775d273bcc4f4de99620ab4878667c83a
Diffstat (limited to 'android')
-rw-r--r-- | android/proto.go | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/android/proto.go b/android/proto.go index 801837e0..83dc32a9 100644 --- a/android/proto.go +++ b/android/proto.go @@ -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 @@ -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")) @@ -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 ProtoFlags{ + Flags: protoFlags, + CanonicalPathFromRoot: proptools.BoolDefault(p.Proto.Canonical_path_from_root, true), + Dir: PathForModuleGen(ctx, "proto"), + SubDir: PathForModuleGen(ctx, "proto", ctx.ModuleDir()), } - return *p.Proto.Canonical_path_from_root -} - -// 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 { @@ -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()) +} |