From d5dbfb78a0f30f0b3ee43a514e4f59206c203458 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 14 Nov 2017 13:11:23 -0800 Subject: [PATCH 1/7] Fix proto flags in java Compute the common proto flags and pass them to the protoc invocation when generating java files. Test: m checkbuild Change-Id: I0d4c23ad001d01eab03b404545383f009214106d --- java/builder.go | 2 +- java/proto.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/java/builder.go b/java/builder.go index 45e59a426..d2e02fde1 100644 --- a/java/builder.go +++ b/java/builder.go @@ -186,7 +186,7 @@ type javaBuilderFlags struct { kotlincFlags string kotlincClasspath classpath - protoFlags string + protoFlags []string protoOutFlag string } diff --git a/java/proto.go b/java/proto.go index 1077fd69b..eeb5124d9 100644 --- a/java/proto.go +++ b/java/proto.go @@ -15,6 +15,8 @@ package java import ( + "strings" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -39,7 +41,7 @@ var ( ) func genProto(ctx android.ModuleContext, outputSrcJar android.WritablePath, - protoFiles android.Paths, protoFlags string, protoOut, protoOutFlags string) { + protoFiles android.Paths, protoFlags []string, protoOut, protoOutFlags string) { ctx.Build(pctx, android.BuildParams{ Rule: proto, @@ -50,7 +52,7 @@ func genProto(ctx android.ModuleContext, outputSrcJar android.WritablePath, "outDir": android.ProtoDir(ctx).String(), "protoOut": protoOut, "protoOutFlags": protoOutFlags, - "protoFlags": protoFlags, + "protoFlags": strings.Join(protoFlags, " "), }, }) } @@ -93,5 +95,8 @@ func protoFlags(ctx android.ModuleContext, p *android.ProtoProperties, flags jav ctx.PropertyErrorf("proto.type", "unknown proto type %q", proptools.String(p.Proto.Type)) } + + flags.protoFlags = android.ProtoFlags(ctx, p) + return flags } From ebe1a51c81f9ab300e55126a8a7e3028c64efcd7 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 14 Nov 2017 13:12:14 -0800 Subject: [PATCH 2/7] Fix java AIDL properties to match C/C++ The C/C++ aidl properties use: aidl: { local_include_dirs: [], include_dirs: [], } But the Android.bp file was expecting: aidl_include_dirs: [], export_aidl_include_dirs: [], Update java AIDL support to match the C support, which is also what the androidmk conversion tool is creating. Test: m checkbuild Change-Id: I3df763d0b203b1b6556798a21b0553e7d35ad7d5 --- java/java.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/java/java.go b/java/java.go index 432e816e5..8a9b31f75 100644 --- a/java/java.go +++ b/java/java.go @@ -136,12 +136,17 @@ type CompilerDeviceProperties struct { // if not blank, set to the version of the sdk to compile against Sdk_version *string - // directories to pass to aidl tool - Aidl_includes []string + Aidl struct { + // Top level directories to pass to aidl tool + Include_dirs []string - // directories that should be added as include directories - // for any aidl sources of modules that depend on this module - Export_aidl_include_dirs []string + // Directories rooted at the Android.bp file to pass to aidl tool + Local_include_dirs []string + + // directories that should be added as include directories for any aidl sources of modules + // that depend on this module, as well as to aidl for this module. + Export_include_dirs []string + } // If true, export a copy of the module as a -hostdex module for host testing. Hostdex *bool @@ -377,7 +382,11 @@ func (j *Module) hasSrcExt(ext string) bool { func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, aidlIncludeDirs android.Paths) []string { - localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes) + aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs) + aidlIncludes = append(aidlIncludes, + android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...) + aidlIncludes = append(aidlIncludes, + android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...) var flags []string if aidlPreprocess.Valid() { @@ -387,7 +396,7 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt } flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I")) - flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I")) + flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) if src := android.ExistentPathForSource(ctx, "", ctx.ModuleDir(), "src"); src.Valid() { flags = append(flags, "-I"+src.String()) @@ -528,7 +537,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB func (j *Module) compile(ctx android.ModuleContext) { - j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs) + j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs) deps := j.collectDeps(ctx) flags := j.collectBuilderFlags(ctx, deps) From af05017b7533f6f84b04fcce1b85cb1a1d2efe51 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 15 Nov 2017 23:01:59 -0800 Subject: [PATCH 3/7] Add support for .srcjar files from genrules and srcs Allow srcs to contain .srcjar files, which will be extracted just before javac. Also allow genrules and generated sources to directly return .srcjar files. Test: m checkbuild Change-Id: Ie4cf60ecb9d2ec63a4c2275221544203b1383597 --- java/config/config.go | 2 +- java/gen.go | 10 ++++------ java/java.go | 5 +++-- scripts/{extract-src-jars.sh => extract-srcjars.sh} | 0 4 files changed, 8 insertions(+), 9 deletions(-) rename scripts/{extract-src-jars.sh => extract-srcjars.sh} (100%) diff --git a/java/config/config.go b/java/config/config.go index d4994a1c9..3cd284157 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -70,7 +70,7 @@ func init() { pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar") pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime") - pctx.SourcePathVariable("ExtractSrcJarsCmd", "build/soong/scripts/extract-src-jars.sh") + pctx.SourcePathVariable("ExtractSrcJarsCmd", "build/soong/scripts/extract-srcjars.sh") pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh") pctx.HostBinToolVariable("SoongZipCmd", "soong_zip") pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips") diff --git a/java/gen.go b/java/gen.go index 8fa199e14..c73a446ce 100644 --- a/java/gen.go +++ b/java/gen.go @@ -85,7 +85,7 @@ func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Pat } func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths, - flags javaBuilderFlags) (android.Paths, android.Paths) { + flags javaBuilderFlags) android.Paths { var protoFiles android.Paths outSrcFiles := make(android.Paths, 0, len(srcFiles)) @@ -106,17 +106,15 @@ func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths, } } - var outSrcJars android.Paths - if len(protoFiles) > 0 { - protoSrcJar := android.PathForModuleGen(ctx, "proto.src.jar") + protoSrcJar := android.PathForModuleGen(ctx, "proto.srcjar") genProto(ctx, protoSrcJar, protoFiles, flags.protoFlags, flags.protoOutFlag, "") - outSrcJars = append(outSrcJars, protoSrcJar) + outSrcFiles = append(outSrcFiles, protoSrcJar) } - return outSrcFiles, outSrcJars + return outSrcFiles } func LogtagsSingleton() blueprint.Singleton { diff --git a/java/java.go b/java/java.go index 8a9b31f75..b2bd2b0a4 100644 --- a/java/java.go +++ b/java/java.go @@ -550,8 +550,9 @@ func (j *Module) compile(ctx android.ModuleContext) { flags = protoFlags(ctx, &j.protoProperties, flags) } - var srcJars android.Paths - srcFiles, srcJars = j.genSources(ctx, srcFiles, flags) + srcFiles = j.genSources(ctx, srcFiles, flags) + + srcJars := srcFiles.FilterByExt(".srcjar") srcJars = append(srcJars, deps.srcJars...) srcJars = append(srcJars, j.ExtraSrcJars...) diff --git a/scripts/extract-src-jars.sh b/scripts/extract-srcjars.sh similarity index 100% rename from scripts/extract-src-jars.sh rename to scripts/extract-srcjars.sh From d243091381a329fc8d82b2a43a35e5b4ecb82374 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 16 Nov 2017 21:33:38 -0800 Subject: [PATCH 4/7] Remove partial javastream proto support javastream proto is rarely used and tricky to support directly in java because it depends on an extra host tool. It can be supported with a genrule, so just remove the partial built-in support. Test: m checkbuild Change-Id: Iffe75e7040cb889ca17fdd85ef3e8e64fc3aa9e9 --- java/proto.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/java/proto.go b/java/proto.go index eeb5124d9..17f02a3b2 100644 --- a/java/proto.go +++ b/java/proto.go @@ -63,10 +63,6 @@ func protoDeps(ctx android.BottomUpMutatorContext, p *android.ProtoProperties) { ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-micro") case "nano": ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-nano") - case "stream": - // TODO(ccross): add dependency on protoc-gen-java-stream binary - ctx.PropertyErrorf("proto.type", `"stream" not supported yet`) - // No library for stream protobufs case "lite", "": ctx.AddDependency(ctx.Module(), staticLibTag, "libprotobuf-java-lite") case "full": @@ -87,8 +83,6 @@ func protoFlags(ctx android.ModuleContext, p *android.ProtoProperties, flags jav flags.protoOutFlag = "--javamicro_out" case "nano": flags.protoOutFlag = "--javanano_out" - case "stream": - flags.protoOutFlag = "--javastream_out" case "lite", "full", "": flags.protoOutFlag = "--java_out" default: From 1763da8eb982cda821c5930d1012bfc87772d09c Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 15 Nov 2017 22:16:57 -0800 Subject: [PATCH 5/7] Export extract-srcjars.sh to Make Export extract-srcjars.sh to Make so that it can be used to add srcjar support to droiddoc rules. Test: m checkbuild Change-Id: I203ba6dad731ec9167eb8706bbfb345a484f024b --- java/config/makevars.go | 1 + 1 file changed, 1 insertion(+) diff --git a/java/config/makevars.go b/java/config/makevars.go index 96fa92b6f..dabf2e722 100644 --- a/java/config/makevars.go +++ b/java/config/makevars.go @@ -61,4 +61,5 @@ func makeVarsProvider(ctx android.MakeVarsContext) { } ctx.Strict("SOONG_JAVAC_WRAPPER", "${SoongJavacWrapper}") + ctx.Strict("EXTRACT_SRCJARS", "${ExtractSrcJarsCmd}") } From b1bd1aabca24a97cf319dfd5268a89e969f1dd98 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 15 Nov 2017 22:47:16 -0800 Subject: [PATCH 6/7] Use logtags without merged file Assume logtags files will have hardcoded tag numbers and don't build against the merged file. Simplifies the build when logtags files are split across Make and Soong. Test: m checkbuild Change-Id: I1e995ec458690fcadb1b86d64864f277aa9fe3af --- java/gen.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/gen.go b/java/gen.go index c73a446ce..b5973ec77 100644 --- a/java/gen.go +++ b/java/gen.go @@ -42,7 +42,7 @@ var ( logtags = pctx.AndroidStaticRule("logtags", blueprint.RuleParams{ - Command: "$logtagsCmd -o $out $in $allLogtagsFile", + Command: "$logtagsCmd -o $out $in", CommandDeps: []string{"$logtagsCmd"}, }) From 35143d0466461f5d83dfc7aeda53b36a274f8cc8 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 16 Nov 2017 00:11:20 -0800 Subject: [PATCH 7/7] Fix genrules depending on Go tools genrules lost the ability to depend on Go tools after I05e945f38915d49cd3c0ab72a86576949bc7eff2 which converted VisitDirectDeps from blueprint Modules to android Modules. Add VisitDirectDepsBlueprint to visit all modules including blueprint Modules, and use it in genrule. Also add a check for disabled modules that was being handled by VisitDirectDeps. Test: m checkbuild Change-Id: I65724283166c63596d071e598c08fed87ef32896 --- android/module.go | 5 +++++ genrule/genrule.go | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/android/module.go b/android/module.go index 2a8837b32..66859fa56 100644 --- a/android/module.go +++ b/android/module.go @@ -108,6 +108,7 @@ type ModuleContext interface { ModuleSubDir() string + VisitDirectDepsBlueprint(visit func(blueprint.Module)) VisitDirectDeps(visit func(Module)) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) VisitDepsDepthFirst(visit func(Module)) @@ -686,6 +687,10 @@ func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Mo return aModule } +func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) { + a.ModuleContext.VisitDirectDeps(visit) +} + func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) { a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) { if aModule := a.validateAndroidModule(module); aModule != nil { diff --git a/genrule/genrule.go b/genrule/genrule.go index c5b7e1d34..c142c53e0 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -158,7 +158,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { tools := map[string]android.Path{} if len(g.properties.Tools) > 0 { - ctx.VisitDirectDeps(func(module android.Module) { + ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) { switch ctx.OtherModuleDependencyTag(module) { case android.SourceDepTag: // Nothing to do @@ -167,6 +167,14 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { var path android.OptionalPath if t, ok := module.(HostToolProvider); ok { + if !t.(android.Module).Enabled() { + if ctx.AConfig().AllowMissingDependencies() { + ctx.AddMissingDependencies([]string{tool}) + } else { + ctx.ModuleErrorf("depends on disabled module %q", tool) + } + break + } path = t.HostToolPath() } else if t, ok := module.(bootstrap.GoBinaryTool); ok { if s, err := filepath.Rel(android.PathForOutput(ctx).String(), t.InstallPath()); err == nil {