From 1e440683e53602ec188913fc81e9d33c1af0f0a3 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 23 May 2018 18:42:04 +0900 Subject: [PATCH] droiddoc accepts aidl files as inputs droiddoc now accepts aidl files as inputs. This in turn allows us to feed aidl files to java_sdk_library modules. This is required as some java_sdk_library internally uses AIDL files and thus we need to specify *.aidl files in the srcs property. Since the srcs property is internally given to the droiddoc module as well as the runtime library, droiddoc should be able to handle aidl files. Bug: 77575606 Test: java_test.go Change-Id: If7a8559a2a1d8ac1056b061d24e3a5ee5253453f --- java/droiddoc.go | 64 +++++++++++++++++++++++++++++++++++++++++++++++ java/java_test.go | 10 ++++++++ 2 files changed, 74 insertions(+) diff --git a/java/droiddoc.go b/java/droiddoc.go index b34c39367..cda50f04a 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -110,6 +110,14 @@ type JavadocProperties struct { // if not blank, set to the version of the sdk to compile against Sdk_version *string `android:"arch_variant"` + + Aidl struct { + // Top level directories to pass to aidl tool + Include_dirs []string + + // Directories rooted at the Android.bp file to pass to aidl tool + Local_include_dirs []string + } } type ApiToCheck struct { @@ -310,6 +318,60 @@ func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool } } +func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags { + var flags javaBuilderFlags + + // aidl flags. + aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) + if len(aidlFlags) > 0 { + // optimization. + ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) + flags.aidlFlags = "$aidlFlags" + } + + return flags +} + +func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, + aidlIncludeDirs android.Paths) []string { + + aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs) + aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...) + + var flags []string + if aidlPreprocess.Valid() { + flags = append(flags, "-p"+aidlPreprocess.String()) + } else { + flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.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()) + } + + return flags +} + +func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths, + flags javaBuilderFlags) android.Paths { + + outSrcFiles := make(android.Paths, 0, len(srcFiles)) + + for _, srcFile := range srcFiles { + switch srcFile.Ext() { + case ".aidl": + javaFile := genAidl(ctx, srcFile, flags.aidlFlags) + outSrcFiles = append(outSrcFiles, javaFile) + default: + outSrcFiles = append(outSrcFiles, srcFile) + } + } + + return outSrcFiles +} + func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { var deps deps @@ -388,6 +450,8 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs // may contain filegroup or genrule. srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) + flags := j.collectBuilderFlags(ctx, deps) + srcFiles = j.genSources(ctx, srcFiles, flags) // srcs may depend on some genrule output. j.srcJars = srcFiles.FilterByExt(".srcjar") diff --git a/java/java_test.go b/java/java_test.go index fe1c3d720..baf4b723b 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -200,6 +200,7 @@ func testContext(config android.Config, bp string, "bar-doc/a.java": nil, "bar-doc/b.java": nil, + "bar-doc/IFoo.aidl": nil, "bar-doc/known_oj_tags.txt": nil, "external/doclava/templates-sdk": nil, @@ -921,6 +922,7 @@ func TestDroiddoc(t *testing.T) { name: "bar-doc", srcs: [ "bar-doc/*.java", + "bar-doc/IFoo.aidl", ], exclude_srcs: [ "bar-doc/b.java" @@ -943,6 +945,14 @@ func TestDroiddoc(t *testing.T) { if stubsJar != barDoc.Output.String() { t.Errorf("expected stubs Jar [%q], got %q", stubsJar, barDoc.Output.String()) } + inputs := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc").Inputs + var javaSrcs []string + for _, i := range inputs { + javaSrcs = append(javaSrcs, i.Base()) + } + if len(javaSrcs) != 2 || javaSrcs[0] != "a.java" || javaSrcs[1] != "IFoo.java" { + t.Errorf("inputs of bar-doc must be []string{\"a.java\", \"IFoo.java\", but was %#v.", javaSrcs) + } } func TestJarGenrules(t *testing.T) {