Merge "Refactor java/droiddoc.go in Soong."

This commit is contained in:
Treehugger Robot 2018-08-06 20:00:02 +00:00 committed by Gerrit Code Review
commit d2e1b6a8e8

View file

@ -169,7 +169,7 @@ type DroiddocProperties struct {
// directory relative to top of the source tree that contains doc templates files. // directory relative to top of the source tree that contains doc templates files.
Custom_template *string Custom_template *string
// directories relative to top of the source tree which contains html/jd files. // directories under current module source which contains html/jd files.
Html_dirs []string Html_dirs []string
// set a value in the Clearsilver hdf namespace. // set a value in the Clearsilver hdf namespace.
@ -266,6 +266,34 @@ type DroiddocProperties struct {
Metalava_merge_annotations_dirs []string Metalava_merge_annotations_dirs []string
} }
//
// Common flags passed down to build rule
//
type droiddocBuilderFlags struct {
args string
bootClasspathArgs string
classpathArgs string
aidlFlags string
doclavaDocsFlags string
doclavaStubsFlags string
postDoclavaCmds string
metalavaAnnotationsFlags string
metalavaDocsFlags string
metalavaStubsFlags string
dokkaFlags string
}
func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
android.InitAndroidArchModule(module, hod, android.MultilibCommon)
android.InitDefaultableModule(module)
}
//
// Javadoc
//
type Javadoc struct { type Javadoc struct {
android.ModuleBase android.ModuleBase
android.DefaultableModuleBase android.DefaultableModuleBase
@ -284,39 +312,6 @@ func (j *Javadoc) Srcs() android.Paths {
return android.Paths{j.stubsSrcJar} return android.Paths{j.stubsSrcJar}
} }
var _ android.SourceFileProducer = (*Javadoc)(nil)
type Droiddoc struct {
Javadoc
properties DroiddocProperties
apiFile android.WritablePath
dexApiFile android.WritablePath
privateApiFile android.WritablePath
privateDexApiFile android.WritablePath
removedApiFile android.WritablePath
removedDexApiFile android.WritablePath
exactApiFile android.WritablePath
apiMappingFile android.WritablePath
checkCurrentApiTimestamp android.WritablePath
updateCurrentApiTimestamp android.WritablePath
checkLastReleasedApiTimestamp android.WritablePath
annotationsZip android.WritablePath
apiFilePath android.Path
}
type ApiFilePath interface {
ApiFilePath() android.Path
}
func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
android.InitAndroidArchModule(module, hod, android.MultilibCommon)
android.InitDefaultableModule(module)
}
func JavadocFactory() android.Module { func JavadocFactory() android.Module {
module := &Javadoc{} module := &Javadoc{}
@ -335,25 +330,7 @@ func JavadocHostFactory() android.Module {
return module return module
} }
func DroiddocFactory() android.Module { var _ android.SourceFileProducer = (*Javadoc)(nil)
module := &Droiddoc{}
module.AddProperties(&module.properties,
&module.Javadoc.properties)
InitDroiddocModule(module, android.HostAndDeviceSupported)
return module
}
func DroiddocHostFactory() android.Module {
module := &Droiddoc{}
module.AddProperties(&module.properties,
&module.Javadoc.properties)
InitDroiddocModule(module, android.HostSupported)
return module
}
func (j *Javadoc) sdkVersion() string { func (j *Javadoc) sdkVersion() string {
return String(j.properties.Sdk_version) return String(j.properties.Sdk_version)
@ -406,8 +383,8 @@ func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool
} }
} }
func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags { func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
var flags javaBuilderFlags var flags droiddocBuilderFlags
// aidl flags. // aidl flags.
aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
@ -443,7 +420,7 @@ func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Op
} }
func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths, func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
flags javaBuilderFlags) android.Paths { flags droiddocBuilderFlags) android.Paths {
outSrcFiles := make(android.Paths, 0, len(srcFiles)) outSrcFiles := make(android.Paths, 0, len(srcFiles))
@ -536,7 +513,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
// do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
// may contain filegroup or genrule. // may contain filegroup or genrule.
srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
flags := j.collectBuilderFlags(ctx, deps) flags := j.collectAidlFlags(ctx, deps)
srcFiles = j.genSources(ctx, srcFiles, flags) srcFiles = j.genSources(ctx, srcFiles, flags)
// srcs may depend on some genrule output. // srcs may depend on some genrule output.
@ -608,6 +585,59 @@ func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}) })
} }
//
// Droiddoc
//
type Droiddoc struct {
Javadoc
properties DroiddocProperties
apiFile android.WritablePath
dexApiFile android.WritablePath
privateApiFile android.WritablePath
privateDexApiFile android.WritablePath
removedApiFile android.WritablePath
removedDexApiFile android.WritablePath
exactApiFile android.WritablePath
apiMappingFile android.WritablePath
checkCurrentApiTimestamp android.WritablePath
updateCurrentApiTimestamp android.WritablePath
checkLastReleasedApiTimestamp android.WritablePath
annotationsZip android.WritablePath
apiFilePath android.Path
}
type ApiFilePath interface {
ApiFilePath() android.Path
}
func DroiddocFactory() android.Module {
module := &Droiddoc{}
module.AddProperties(&module.properties,
&module.Javadoc.properties)
InitDroiddocModule(module, android.HostAndDeviceSupported)
return module
}
func DroiddocHostFactory() android.Module {
module := &Droiddoc{}
module.AddProperties(&module.properties,
&module.Javadoc.properties)
InitDroiddocModule(module, android.HostSupported)
return module
}
func (d *Droiddoc) ApiFilePath() android.Path {
return d.apiFilePath
}
func (d *Droiddoc) checkCurrentApi() bool { func (d *Droiddoc) checkCurrentApi() bool {
if String(d.properties.Check_api.Current.Api_file) != "" && if String(d.properties.Check_api.Current.Api_file) != "" &&
String(d.properties.Check_api.Current.Removed_api_file) != "" { String(d.properties.Check_api.Current.Removed_api_file) != "" {
@ -641,7 +671,7 @@ func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
} }
// extra_arg_files may contains filegroup or genrule. // arg_files may contains filegroup or genrule.
android.ExtractSourcesDeps(ctx, d.properties.Arg_files) android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
// knowntags may contain filegroup or genrule. // knowntags may contain filegroup or genrule.
@ -670,34 +700,25 @@ func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
} }
} }
func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths, deps deps) (droiddocBuilderFlags, error) {
deps := d.Javadoc.collectDeps(ctx) var flags droiddocBuilderFlags
var implicits android.Paths *implicits = append(*implicits, deps.bootClasspath...)
implicits = append(implicits, deps.bootClasspath...) *implicits = append(*implicits, deps.classpath...)
implicits = append(implicits, deps.classpath...)
var bootClasspathArgs string
javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
// Doclava has problem with "-source 1.9", so override javaVersion when Doclava
// is running with EXPERIMENTAL_USE_OPENJDK9=true. And eventually Doclava will be
// replaced by Metalava.
if !Bool(d.properties.Metalava_enabled) {
javaVersion = "1.8"
}
// continue to use -bootclasspath even if Metalava under -source 1.9 is enabled // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
// since it doesn't support system modules yet. // since it doesn't support system modules yet.
if len(deps.bootClasspath.Strings()) > 0 { if len(deps.bootClasspath.Strings()) > 0 {
// For OpenJDK 8 we can use -bootclasspath to define the core libraries code. // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
} }
classpathArgs := deps.classpath.FormJavaClassPath("-classpath") flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
argFiles := ctx.ExpandSources(d.properties.Arg_files, nil) argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
argFilesMap := map[string]android.Path{} argFilesMap := map[string]android.Path{}
for _, f := range argFiles { for _, f := range argFiles {
implicits = append(implicits, f) *implicits = append(*implicits, f)
if _, exists := argFilesMap[f.Rel()]; !exists { if _, exists := argFilesMap[f.Rel()]; !exists {
argFilesMap[f.Rel()] = f argFilesMap[f.Rel()] = f
} else { } else {
@ -706,7 +727,8 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
} }
args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) { var err error
flags.args, err = android.Expand(String(d.properties.Args), func(name string) (string, error) {
if strings.HasPrefix(name, "location ") { if strings.HasPrefix(name, "location ") {
label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
if f, ok := argFilesMap[label]; ok { if f, ok := argFilesMap[label]; ok {
@ -722,25 +744,29 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if err != nil { if err != nil {
ctx.PropertyErrorf("args", "%s", err.Error()) ctx.PropertyErrorf("args", "%s", err.Error())
return return droiddocBuilderFlags{}, err
}
return flags, nil
} }
genDocsForMetalava := false func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
var metalavaArgs string javaVersion string, jsilver, doclava android.Path) string {
if Bool(d.properties.Metalava_enabled) {
if strings.Contains(args, "--generate-documentation") { *implicits = append(*implicits, jsilver)
if !strings.Contains(args, "-nodocs") { *implicits = append(*implicits, doclava)
genDocsForMetalava = true
} var date string
// TODO(nanzhang): Add a Soong property to handle documentation args. if runtime.GOOS == "darwin" {
metalavaArgs = strings.Split(args, "--generate-documentation")[0] date = `date -r`
} else { } else {
metalavaArgs = args date = `date -d`
}
} }
var templateDir, htmlDirArgs, htmlDir2Args string args := " -source " + javaVersion + " -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava { "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
"-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
`-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
if String(d.properties.Custom_template) == "" { if String(d.properties.Custom_template) == "" {
// TODO: This is almost always droiddoc-templates-sdk // TODO: This is almost always droiddoc-templates-sdk
ctx.PropertyErrorf("custom_template", "must specify a template") ctx.PropertyErrorf("custom_template", "must specify a template")
@ -748,8 +774,8 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
if t, ok := m.(*DroiddocTemplate); ok { if t, ok := m.(*DroiddocTemplate); ok {
implicits = append(implicits, t.deps...) *implicits = append(*implicits, t.deps...)
templateDir = t.dir.String() args = args + " -templatedir " + t.dir.String()
} else { } else {
ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m)) ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
} }
@ -757,14 +783,14 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if len(d.properties.Html_dirs) > 0 { if len(d.properties.Html_dirs) > 0 {
htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...) *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
htmlDirArgs = "-htmldir " + htmlDir.String() args = args + " -htmldir " + htmlDir.String()
} }
if len(d.properties.Html_dirs) > 1 { if len(d.properties.Html_dirs) > 1 {
htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...) *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
htmlDir2Args = "-htmldir2 " + htmlDir2.String() args = args + " -htmldir2 " + htmlDir2.String()
} }
if len(d.properties.Html_dirs) > 2 { if len(d.properties.Html_dirs) > 2 {
@ -772,7 +798,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
implicits = append(implicits, knownTags...) *implicits = append(*implicits, knownTags...)
for _, kt := range knownTags { for _, kt := range knownTags {
args = args + " -knowntags " + kt.String() args = args + " -knowntags " + kt.String()
@ -805,125 +831,211 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir) args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
} }
return args
} }
var docArgsForMetalava string func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext, implicitOutputs *android.WritablePaths) (string, string) {
if Bool(d.properties.Metalava_enabled) && genDocsForMetalava { var doclavaFlags, MetalavaFlags string
docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
}
var implicitOutputs android.WritablePaths
if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" { if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt") d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
args = args + " -api " + d.apiFile.String() doclavaFlags += " -api " + d.apiFile.String()
metalavaArgs = metalavaArgs + " --api " + d.apiFile.String() MetalavaFlags = MetalavaFlags + " --api " + d.apiFile.String()
implicitOutputs = append(implicitOutputs, d.apiFile) *implicitOutputs = append(*implicitOutputs, d.apiFile)
d.apiFilePath = d.apiFile d.apiFilePath = d.apiFile
} }
if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" { if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt") d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
args = args + " -removedApi " + d.removedApiFile.String() doclavaFlags += " -removedApi " + d.removedApiFile.String()
metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String() MetalavaFlags = MetalavaFlags + " --removed-api " + d.removedApiFile.String()
implicitOutputs = append(implicitOutputs, d.removedApiFile) *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
} }
if String(d.properties.Private_api_filename) != "" { if String(d.properties.Private_api_filename) != "" {
d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename)) d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
args = args + " -privateApi " + d.privateApiFile.String() doclavaFlags += " -privateApi " + d.privateApiFile.String()
metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String() MetalavaFlags = MetalavaFlags + " --private-api " + d.privateApiFile.String()
implicitOutputs = append(implicitOutputs, d.privateApiFile) *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
} }
if String(d.properties.Dex_api_filename) != "" { if String(d.properties.Dex_api_filename) != "" {
d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename)) d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
args = args + " -dexApi " + d.dexApiFile.String() doclavaFlags += " -dexApi " + d.dexApiFile.String()
implicitOutputs = append(implicitOutputs, d.dexApiFile) *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
} }
if String(d.properties.Private_dex_api_filename) != "" { if String(d.properties.Private_dex_api_filename) != "" {
d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename)) d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
args = args + " -privateDexApi " + d.privateDexApiFile.String() doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String() MetalavaFlags = MetalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
implicitOutputs = append(implicitOutputs, d.privateDexApiFile) *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
} }
if String(d.properties.Removed_dex_api_filename) != "" { if String(d.properties.Removed_dex_api_filename) != "" {
d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename)) d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
args = args + " -removedDexApi " + d.removedDexApiFile.String() doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String() MetalavaFlags = MetalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
implicitOutputs = append(implicitOutputs, d.removedDexApiFile) *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
} }
if String(d.properties.Exact_api_filename) != "" { if String(d.properties.Exact_api_filename) != "" {
d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename)) d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
args = args + " -exactApi " + d.exactApiFile.String() doclavaFlags += " -exactApi " + d.exactApiFile.String()
metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String() MetalavaFlags = MetalavaFlags + " --exact-api " + d.exactApiFile.String()
implicitOutputs = append(implicitOutputs, d.exactApiFile) *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
} }
if String(d.properties.Dex_mapping_filename) != "" { if String(d.properties.Dex_mapping_filename) != "" {
d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename)) d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
args = args + " -apiMapping " + d.apiMappingFile.String() doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
// Omitted: metalava support // Omitted: metalava support
implicitOutputs = append(implicitOutputs, d.apiMappingFile) *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
} }
implicits = append(implicits, d.Javadoc.srcJars...)
implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
for _, o := range d.properties.Out {
implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
}
jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
var date string
if runtime.GOOS == "darwin" {
date = `date -r`
} else {
date = `date -d`
}
doclavaOpts := "-source " + javaVersion + " -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
"-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
"-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
"-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
`-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
if !Bool(d.properties.Metalava_enabled) {
opts := doclavaOpts + args
implicits = append(implicits, jsilver)
implicits = append(implicits, doclava)
if BoolDefault(d.properties.Create_stubs, true) { if BoolDefault(d.properties.Create_stubs, true) {
opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String() doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
} }
if Bool(d.properties.Write_sdk_values) { if Bool(d.properties.Write_sdk_values) {
opts += " -sdkvalues " + android.PathForModuleOut(ctx, "docs", "out").String() doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "docs", "out").String()
}
return doclavaFlags, MetalavaFlags
} }
var postDoclavaCmds string func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
var cmds string
if String(d.properties.Static_doc_index_redirect) != "" { if String(d.properties.Static_doc_index_redirect) != "" {
static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect), static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
"static_doc_index_redirect") "static_doc_index_redirect")
implicits = append(implicits, static_doc_index_redirect) *implicits = append(*implicits, static_doc_index_redirect)
postDoclavaCmds += " && cp " + static_doc_index_redirect.String() + " " + cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
android.PathForModuleOut(ctx, "docs", "out", "index.html").String() android.PathForModuleOut(ctx, "docs", "out", "index.html").String()
} }
if String(d.properties.Static_doc_properties) != "" { if String(d.properties.Static_doc_properties) != "" {
static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties), static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
"static_doc_properties") "static_doc_properties")
implicits = append(implicits, static_doc_properties) *implicits = append(*implicits, static_doc_properties)
postDoclavaCmds += " && cp " + static_doc_properties.String() + " " + cmds = cmds + " && cp " + static_doc_properties.String() + " " +
android.PathForModuleOut(ctx, "docs", "out", "source.properties").String() android.PathForModuleOut(ctx, "docs", "out", "source.properties").String()
} }
return cmds
}
func (d *Droiddoc) collectMetalavaAnnotationsFlags(
ctx android.ModuleContext, implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
var flags string
if String(d.properties.Metalava_previous_api) != "" {
previousApi := ctx.ExpandSource(String(d.properties.Metalava_previous_api),
"metalava_previous_api")
flags += " --previous-api " + previousApi.String()
*implicits = append(*implicits, previousApi)
}
if Bool(d.properties.Metalava_annotations_enabled) {
if String(d.properties.Metalava_previous_api) == "" {
ctx.PropertyErrorf("metalava_previous_api",
"has to be non-empty if annotations was enabled!")
}
flags += " --include-annotations --migrate-nullness"
d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
*implicitOutputs = append(*implicitOutputs, d.annotationsZip)
if len(d.properties.Metalava_merge_annotations_dirs) == 0 {
ctx.PropertyErrorf("metalava_merge_annotations_dirs",
"has to be non-empty if annotations was enabled!")
}
mergeAnnotationsDirs := android.PathsForSource(ctx, d.properties.Metalava_merge_annotations_dirs)
flags += " --extract-annotations " + d.annotationsZip.String()
for _, mergeAnnotationsDir := range mergeAnnotationsDirs {
flags += " --merge-annotations " + mergeAnnotationsDir.String()
}
// TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
}
return flags
}
func (d *Droiddoc) collectMetalavaDocsFlags(ctx android.ModuleContext,
bootClasspathArgs, classpathArgs string) string {
return " --doc-stubs " + android.PathForModuleOut(ctx, "docs", "docStubsDir").String() +
" --write-doc-stubs-source-list $outDir/doc_stubs_src_list " +
" --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
android.PathForModuleOut(ctx, "docs", "docStubsDir").String() + " -quiet -d $outDir "
}
func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
deps := d.Javadoc.collectDeps(ctx)
javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
// Doclava has problem with "-source 1.9", so override javaVersion when Doclava
// is running with EXPERIMENTAL_USE_OPENJDK9=true. And eventually Doclava will be
// replaced by Metalava.
if !Bool(d.properties.Metalava_enabled) {
javaVersion = "1.8"
}
jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
var implicits android.Paths
implicits = append(implicits, d.Javadoc.srcJars...)
var implicitOutputs android.WritablePaths
implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
for _, o := range d.properties.Out {
implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
}
flags, err := d.initBuilderFlags(ctx, &implicits, deps)
if err != nil {
return
}
flags.doclavaStubsFlags, flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
if Bool(d.properties.Metalava_enabled) {
opts := flags.metalavaStubsFlags
flags.metalavaAnnotationsFlags = d.collectMetalavaAnnotationsFlags(ctx, &implicits, &implicitOutputs)
opts += flags.metalavaAnnotationsFlags
if strings.Contains(flags.args, "--generate-documentation") {
// TODO(nanzhang): Add a Soong property to handle documentation args.
flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, javaVersion, jsilver, doclava)
flags.metalavaDocsFlags = d.collectMetalavaDocsFlags(ctx, flags.bootClasspathArgs, flags.classpathArgs)
opts += " " + strings.Split(flags.args, "--generate-documentation")[0] + " " +
flags.metalavaDocsFlags + flags.doclavaDocsFlags +
" " + strings.Split(flags.args, "--generate-documentation")[1]
} else {
opts += " " + flags.args
}
ctx.Build(pctx, android.BuildParams{
Rule: metalava,
Description: "Metalava",
Output: d.Javadoc.stubsSrcJar,
Inputs: d.Javadoc.srcFiles,
Implicits: implicits,
ImplicitOutputs: implicitOutputs,
Args: map[string]string{
"outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
"srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
"javaVersion": javaVersion,
"bootclasspathArgs": flags.bootClasspathArgs,
"classpathArgs": flags.classpathArgs,
"sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
"docZip": d.Javadoc.docZip.String(),
"opts": opts,
},
})
} else {
flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, javaVersion, jsilver, doclava)
flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: javadoc, Rule: javadoc,
Description: "Droiddoc", Description: "Droiddoc",
@ -936,87 +1048,16 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(), "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(), "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
"srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
"opts": opts, "opts": flags.doclavaDocsFlags + flags.doclavaStubsFlags + " " + flags.args,
"bootclasspathArgs": bootClasspathArgs, "bootclasspathArgs": flags.bootClasspathArgs,
"classpathArgs": classpathArgs, "classpathArgs": flags.classpathArgs,
"sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"), "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
"docZip": d.Javadoc.docZip.String(), "docZip": d.Javadoc.docZip.String(),
"postDoclavaCmds": postDoclavaCmds, "postDoclavaCmds": flags.postDoclavaCmds,
}, },
}) })
} else {
opts := metalavaArgs
buildArgs := map[string]string{
"outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
"srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
"javaVersion": javaVersion,
"bootclasspathArgs": bootClasspathArgs,
"classpathArgs": classpathArgs,
"sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
"docZip": d.Javadoc.docZip.String(),
} }
var previousApi android.Path
if String(d.properties.Metalava_previous_api) != "" {
previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
"metalava_previous_api")
opts += " --previous-api " + previousApi.String()
implicits = append(implicits, previousApi)
}
if Bool(d.properties.Metalava_annotations_enabled) {
if String(d.properties.Metalava_previous_api) == "" {
ctx.PropertyErrorf("metalava_previous_api",
"has to be non-empty if annotations was enabled!")
}
opts += " --include-annotations --migrate-nullness"
d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
implicitOutputs = append(implicitOutputs, d.annotationsZip)
if len(d.properties.Metalava_merge_annotations_dirs) == 0 {
ctx.PropertyErrorf("metalava_merge_annotations_dirs",
"has to be non-empty if annotations was enabled!")
}
mergeAnnotationsDirs := android.PathsForSource(ctx, d.properties.Metalava_merge_annotations_dirs)
opts += " --extract-annotations " + d.annotationsZip.String()
for _, mergeAnnotationsDir := range mergeAnnotationsDirs {
opts += " --merge-annotations " + mergeAnnotationsDir.String()
}
// TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
opts += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
}
if genDocsForMetalava {
opts += " --doc-stubs " + android.PathForModuleOut(ctx, "docs", "docStubsDir").String() +
" --write-doc-stubs-source-list $outDir/doc_stubs_src_list " +
" --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
android.PathForModuleOut(ctx, "docs", "docStubsDir").String() + " -quiet -d $outDir "
implicits = append(implicits, jsilver)
implicits = append(implicits, doclava)
}
buildArgs["opts"] = opts
ctx.Build(pctx, android.BuildParams{
Rule: metalava,
Description: "Metalava",
Output: d.Javadoc.stubsSrcJar,
Inputs: d.Javadoc.srcFiles,
Implicits: implicits,
ImplicitOutputs: implicitOutputs,
Args: buildArgs,
})
}
java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() { if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp") d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
@ -1053,7 +1094,6 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}) })
d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp") d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: updateApi, Rule: updateApi,
Description: "update current API", Description: "update current API",
@ -1067,6 +1107,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}, },
}) })
} }
if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() { if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp") d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
@ -1098,10 +1139,9 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
} }
func (d *Droiddoc) ApiFilePath() android.Path { //
return d.apiFilePath // Droiddoc Template
} //
var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
type DroiddocTemplateProperties struct { type DroiddocTemplateProperties struct {