From c6ddccfa88a6f922f247f6ba90d6457a72461ad8 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 13 Sep 2019 20:56:14 +0900 Subject: [PATCH] Add filter_packages property to droiddoc The property is used to filter input source files by their package names. Bug: 140764681 Test: m Change-Id: If31adb81055ea7953ccd589344bdd298eaacedda --- java/droiddoc.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/java/droiddoc.go b/java/droiddoc.go index 5deac5ea9..1d5331e64 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -57,6 +57,10 @@ type JavadocProperties struct { // filegroup or genrule can be included within this property. Exclude_srcs []string `android:"path,arch_variant"` + // list of package names that should actually be used. If this property is left unspecified, + // all the sources from the srcs property is used. + Filter_packages []string + // list of java libraries that will be in the classpath. Libs []string `android:"arch_variant"` @@ -524,6 +528,34 @@ 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 := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) + + filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path { + if filterPackages == nil { + return srcs + } + filtered := []android.Path{} + for _, src := range srcs { + if src.Ext() != ".java" { + // Don't filter-out non-Java (=generated sources) by package names. This is not ideal, + // but otherwise metalava emits stub sources having references to the generated AIDL classes + // in filtered-out pacages (e.g. com.android.internal.*). + // TODO(b/141149570) We need to fix this by introducing default private constructors or + // fixing metalava to not emit constructors having references to unknown classes. + filtered = append(filtered, src) + continue + } + packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".") + for _, pkg := range filterPackages { + if strings.HasPrefix(packageName, pkg) { + filtered = append(filtered, src) + break + } + } + } + return filtered + } + srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages) + flags := j.collectAidlFlags(ctx, deps) srcFiles = j.genSources(ctx, srcFiles, flags)