diff --git a/Android.bp b/Android.bp index 91e73aab4..f2bc5fb91 100644 --- a/Android.bp +++ b/Android.bp @@ -220,6 +220,7 @@ bootstrap_go_package { "java/app.go", "java/builder.go", "java/dex.go", + "java/droiddoc.go", "java/gen.go", "java/genrule.go", "java/jacoco.go", diff --git a/android/config.go b/android/config.go index 1e5dd521f..1a0b45a5a 100644 --- a/android/config.go +++ b/android/config.go @@ -425,6 +425,14 @@ func (c *config) EmbeddedInMake() bool { return c.inMake } +func (c *config) BuildId() string { + return String(c.ProductVariables.BuildId) +} + +func (c *config) BuildNumberFromFile() string { + return String(c.ProductVariables.BuildNumberFromFile) +} + // DeviceName returns the name of the current device target // TODO: take an AndroidModuleContext to select the device name for multi-device builds func (c *config) DeviceName() string { diff --git a/android/module.go b/android/module.go index 6f247ab18..fe6c0dea7 100644 --- a/android/module.go +++ b/android/module.go @@ -113,6 +113,7 @@ type ModuleContext interface { ExpandOptionalSource(srcFile *string, prop string) OptionalPath ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths Glob(globPattern string, excludes []string) Paths + GlobFiles(globPattern string, excludes []string) Paths InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath @@ -1245,6 +1246,24 @@ func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Pat return pathsForModuleSrcFromFullPath(ctx, ret) } +// glob only "files" under the directory relative to top of the source tree. +func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths { + paths, err := ctx.GlobWithDeps(globPattern, excludes) + if err != nil { + ctx.ModuleErrorf("glob: %s", err.Error()) + } + var ret []Path + for _, p := range paths { + if isDir, err := ctx.Fs().IsDir(p); err != nil { + ctx.ModuleErrorf("error in IsDir(%s): %s", p, err.Error()) + return nil + } else if !isDir { + ret = append(ret, PathForSource(ctx, p)) + } + } + return ret +} + func init() { RegisterSingletonType("buildtarget", BuildTargetSingleton) } diff --git a/android/variable.go b/android/variable.go index 328074a3d..41b32bd63 100644 --- a/android/variable.go +++ b/android/variable.go @@ -110,6 +110,10 @@ type productVariables struct { // Suffix to add to generated Makefiles Make_suffix *string `json:",omitempty"` + BuildId *string `json:",omitempty"` + BuildNumberFromFile *string `json:",omitempty"` + DateFromFile *string `json:",omitempty"` + Platform_sdk_version *int `json:",omitempty"` Platform_sdk_final *bool `json:",omitempty"` Platform_version_active_codenames []string `json:",omitempty"` diff --git a/java/androidmk.go b/java/androidmk.go index 64ef5054d..bb1a13c56 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -196,3 +196,39 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData { } } + +func (jd *Javadoc) AndroidMk() android.AndroidMkData { + return android.AndroidMkData{ + Class: "JAVA_LIBRARIES", + OutputFile: android.OptionalPathForPath(jd.stubsJar), + Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", + Extra: []android.AndroidMkExtraFunc{ + func(w io.Writer, outputFile android.Path) { + if jd.properties.Installable == nil || *jd.properties.Installable == true { + fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String()) + } + if jd.stubsJar != nil { + fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_JAR := ", jd.stubsJar.String()) + } + }, + }, + } +} + +func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData { + return android.AndroidMkData{ + Class: "JAVA_LIBRARIES", + OutputFile: android.OptionalPathForPath(ddoc.stubsJar), + Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", + Extra: []android.AndroidMkExtraFunc{ + func(w io.Writer, outputFile android.Path) { + if ddoc.Javadoc.properties.Installable == nil || *ddoc.Javadoc.properties.Installable == true { + fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String()) + } + if ddoc.Javadoc.stubsJar != nil { + fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_JAR := ", ddoc.Javadoc.stubsJar.String()) + } + }, + }, + } +} diff --git a/java/builder.go b/java/builder.go index 46de4f73c..5aea1cb1c 100644 --- a/java/builder.go +++ b/java/builder.go @@ -428,13 +428,6 @@ func (x *classpath) FormDesugarClasspath(optName string) []string { return flags } -// Append an android.Paths to the end of the classpath list -func (x *classpath) AddPaths(paths android.Paths) { - for _, path := range paths { - *x = append(*x, path) - } -} - // Convert a classpath to an android.Paths func (x *classpath) Paths() android.Paths { return append(android.Paths(nil), (*x)...) diff --git a/java/config/config.go b/java/config/config.go index b5e574e90..c5076eb9a 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -126,6 +126,8 @@ func init() { pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar") pctx.HostJavaToolVariable("DesugarJar", "desugar.jar") + pctx.HostJavaToolVariable("JsilverJar", "jsilver.jar") + pctx.HostJavaToolVariable("DoclavaJar", "doclava.jar") pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper") diff --git a/java/droiddoc.go b/java/droiddoc.go new file mode 100644 index 000000000..efd430ada --- /dev/null +++ b/java/droiddoc.go @@ -0,0 +1,455 @@ +// Copyright 2018 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "android/soong/android" + "android/soong/java/config" + "fmt" + "path/filepath" + "strings" + + "github.com/google/blueprint" +) + +var ( + javadoc = pctx.AndroidStaticRule("javadoc", + blueprint.RuleParams{ + Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + + `${config.ExtractSrcJarsCmd} $srcJarDir $srcJarDir/list $srcJars && ` + + `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` + + `$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` + + `-d $outDir -quiet && ` + + `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` + + `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`, + CommandDeps: []string{ + "${config.ExtractSrcJarsCmd}", + "${config.JavadocCmd}", + "${config.SoongZipCmd}", + "$JsilverJar", + "$DoclavaJar", + }, + Rspfile: "$out.rsp", + RspfileContent: "$in", + Restat: true, + }, + "outDir", "srcJarDir", "stubsDir", "srcJars", "opts", + "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip", "JsilverJar", "DoclavaJar") +) + +func init() { + android.RegisterModuleType("droiddoc", DroiddocFactory) + android.RegisterModuleType("droiddoc_host", DroiddocHostFactory) + android.RegisterModuleType("javadoc", JavadocFactory) + android.RegisterModuleType("javadoc_host", JavadocHostFactory) +} + +type JavadocProperties struct { + // list of source files used to compile the Java module. May be .java, .logtags, .proto, + // or .aidl files. + Srcs []string `android:"arch_variant"` + + // list of directories rooted at the Android.bp file that will + // be added to the search paths for finding source files when passing package names. + Local_sourcepaths []string `android:"arch_variant"` + + // list of source files that should not be used to build the Java module. + // This is most useful in the arch/multilib variants to remove non-common files + // filegroup or genrule can be included within this property. + Exclude_srcs []string `android:"arch_variant"` + + // list of of java libraries that will be in the classpath. + Libs []string `android:"arch_variant"` + + // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true. + Installable *bool `android:"arch_variant"` + + // if not blank, set to the version of the sdk to compile against + Sdk_version *string `android:"arch_variant"` +} + +type DroiddocProperties struct { + // directory relative to top of the source tree that contains doc templates files. + Custom_template_dir *string `android:"arch_variant"` + + // directories relative to top of the source tree which contains html/jd files. + Html_dirs []string `android:"arch_variant"` + + // set a value in the Clearsilver hdf namespace. + Hdf []string `android:"arch_variant"` + + // proofread file contains all of the text content of the javadocs concatenated into one file, + // suitable for spell-checking and other goodness. + Proofread_file *string `android:"arch_variant"` + + // a todo file lists the program elements that are missing documentation. + // At some point, this might be improved to show more warnings. + Todo_file *string `android:"arch_variant"` + + // local files that are used within user customized droiddoc options. + Arg_files []string `android:"arch_variant"` + + // user customized droiddoc args. + // Available variables for substitution: + // + // $(location