// 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" "runtime" "strings" "github.com/google/blueprint" ) var ( javadoc = pctx.AndroidStaticRule("javadoc", blueprint.RuleParams{ Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + `${config.SoongJavacWrapper} ${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` + `$opts $bootclasspathArgs $classpathArgs $sourcepathArgs ` + `-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 $postDoclavaCmds && ` + `rm -rf "$srcJarDir"`, CommandDeps: []string{ "${config.ZipSyncCmd}", "${config.JavadocCmd}", "${config.SoongZipCmd}", }, CommandOrderOnly: []string{"${config.SoongJavacWrapper}"}, Rspfile: "$out.rsp", RspfileContent: "$in", Restat: true, }, "outDir", "srcJarDir", "stubsDir", "srcJars", "opts", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "docZip", "postDoclavaCmds") apiCheck = pctx.AndroidStaticRule("apiCheck", blueprint.RuleParams{ Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` + `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` + `&& touch $out ) || (echo -e "$msg" ; exit 38)`, CommandDeps: []string{ "${config.ApiCheckCmd}", }, }, "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg") updateApi = pctx.AndroidStaticRule("updateApi", blueprint.RuleParams{ Command: `( ( cp -f $srcApiFile $destApiFile && cp -f $srcRemovedApiFile $destRemovedApiFile ) ` + `&& touch $out ) || (echo failed to update public API ; exit 38)`, }, "srcApiFile", "destApiFile", "srcRemovedApiFile", "destRemovedApiFile") metalava = pctx.AndroidStaticRule("metalava", blueprint.RuleParams{ Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` + `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` + `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` + `$opts && ` + `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir && ` + `rm -rf "$srcJarDir"`, CommandDeps: []string{ "${config.ZipSyncCmd}", "${config.JavaCmd}", "${config.MetalavaJar}", "${config.SoongZipCmd}", }, Rspfile: "$out.rsp", RspfileContent: "$in", Restat: true, }, "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "opts") metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck", blueprint.RuleParams{ Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` + `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` + `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` + `$opts && touch $out && rm -rf "$srcJarDir") || ` + `( echo -e "$msg" ; exit 38 )`, CommandDeps: []string{ "${config.ZipSyncCmd}", "${config.JavaCmd}", "${config.MetalavaJar}", }, Rspfile: "$out.rsp", RspfileContent: "$in", }, "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "opts", "msg") nullabilityWarningsCheck = pctx.AndroidStaticRule("nullabilityWarningsCheck", blueprint.RuleParams{ Command: `( diff $expected $actual && touch $out ) || ( echo -e "$msg" ; exit 38 )`, }, "expected", "actual", "msg") dokka = pctx.AndroidStaticRule("dokka", blueprint.RuleParams{ Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` + `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + `${config.JavaCmd} -jar ${config.DokkaJar} $srcJarDir ` + `$classpathArgs -format dac -dacRoot /reference/kotlin -output $outDir $opts && ` + `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` + `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir && ` + `rm -rf "$srcJarDir"`, CommandDeps: []string{ "${config.ZipSyncCmd}", "${config.DokkaJar}", "${config.MetalavaJar}", "${config.SoongZipCmd}", }, Restat: true, }, "outDir", "srcJarDir", "stubsDir", "srcJars", "classpathArgs", "opts", "docZip") ) func init() { android.RegisterModuleType("doc_defaults", DocDefaultsFactory) android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory) android.RegisterModuleType("droiddoc", DroiddocFactory) android.RegisterModuleType("droiddoc_host", DroiddocHostFactory) android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory) android.RegisterModuleType("javadoc", JavadocFactory) android.RegisterModuleType("javadoc_host", JavadocHostFactory) android.RegisterModuleType("droidstubs", DroidstubsFactory) android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory) } var ( srcsLibTag = dependencyTag{name: "sources from javalib"} ) type JavadocProperties struct { // list of source files used to compile the Java module. May be .java, .logtags, .proto, // or .aidl files. Srcs []string `android:"path,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 // 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:"path,arch_variant"` // list of java libraries that will be in the classpath. Libs []string `android:"arch_variant"` // don't build against the default libraries (bootclasspath, ext, and framework for device // targets) No_standard_libs *bool // don't build against the framework libraries (ext, and framework for device targets) No_framework_libs *bool // the java library (in classpath) for documentation that provides java srcs and srcjars. Srcs_lib *string // the base dirs under srcs_lib will be scanned for java srcs. Srcs_lib_whitelist_dirs []string // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. Srcs_lib_whitelist_pkgs []string // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true. Installable *bool // 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 } // If not blank, set the java version passed to javadoc as -source Java_version *string // local files that are used within user customized droiddoc options. Arg_files []string `android:"path"` // user customized droiddoc args. // Available variables for substitution: // // $(location