Merge changes from topic "revert-1302576-NGVCIVIIJO"
* changes:
Revert "Detect invalid arch specific properties in snapshot"
Revert "Adds support for 'ignored-on-host'"
Revert "Fix snapshot of a host/device cc_library with stubs"
diff --git a/Android.bp b/Android.bp
index a9eceb2..342ca4c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -391,6 +391,7 @@
srcs: [
"rust/androidmk.go",
"rust/compiler.go",
+ "rust/coverage.go",
"rust/binary.go",
"rust/builder.go",
"rust/library.go",
@@ -403,6 +404,7 @@
testSrcs: [
"rust/binary_test.go",
"rust/compiler_test.go",
+ "rust/coverage_test.go",
"rust/library_test.go",
"rust/rust_test.go",
"rust/test_test.go",
diff --git a/android/module.go b/android/module.go
index f5cfe66..e431ada 100644
--- a/android/module.go
+++ b/android/module.go
@@ -19,6 +19,7 @@
"os"
"path"
"path/filepath"
+ "regexp"
"strings"
"text/scanner"
@@ -135,6 +136,13 @@
// GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
GetTagPath() []blueprint.DependencyTag
+ // GetPathString is supposed to be called in visit function passed in WalkDeps()
+ // and returns a multi-line string showing the modules and dependency tags
+ // among them along the top-down dependency path from a start module to current child module.
+ // skipFirst when set to true, the output doesn't include the start module,
+ // which is already printed when this function is used along with ModuleErrorf().
+ GetPathString(skipFirst bool) string
+
AddMissingDependencies(missingDeps []string)
Target() Target
@@ -1734,6 +1742,41 @@
return b.tagPath
}
+// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
+// a dependency tag.
+var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
+
+// PrettyPrintTag returns string representation of the tag, but prefers
+// custom String() method if available.
+func PrettyPrintTag(tag blueprint.DependencyTag) string {
+ // Use tag's custom String() method if available.
+ if stringer, ok := tag.(fmt.Stringer); ok {
+ return stringer.String()
+ }
+
+ // Otherwise, get a default string representation of the tag's struct.
+ tagString := fmt.Sprintf("%#v", tag)
+
+ // Remove the boilerplate from BaseDependencyTag as it adds no value.
+ tagString = tagCleaner.ReplaceAllString(tagString, "")
+ return tagString
+}
+
+func (b *baseModuleContext) GetPathString(skipFirst bool) string {
+ sb := strings.Builder{}
+ tagPath := b.GetTagPath()
+ walkPath := b.GetWalkPath()
+ if !skipFirst {
+ sb.WriteString(walkPath[0].String())
+ }
+ for i, m := range walkPath[1:] {
+ sb.WriteString("\n")
+ sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
+ sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
+ }
+ return sb.String()
+}
+
func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
visit(module.(Module))
diff --git a/android/util.go b/android/util.go
index e74b64e..8dbf214 100644
--- a/android/util.go
+++ b/android/util.go
@@ -141,6 +141,16 @@
return false
}
+// Returns true if any string in the given list has the given suffix.
+func SuffixInList(list []string, suffix string) bool {
+ for _, s := range list {
+ if strings.HasSuffix(s, suffix) {
+ return true
+ }
+ }
+ return false
+}
+
// IndexListPred returns the index of the element which in the given `list` satisfying the predicate, or -1 if there is no such element.
func IndexListPred(pred func(s string) bool, list []string) int {
for i, l := range list {
diff --git a/androidmk/androidmk/android.go b/androidmk/androidmk/android.go
index f863f8d..5a62324 100644
--- a/androidmk/androidmk/android.go
+++ b/androidmk/androidmk/android.go
@@ -111,6 +111,7 @@
"LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING": "dex_preopt.profile",
"LOCAL_TEST_CONFIG": "test_config",
+ "LOCAL_RRO_THEME": "theme",
})
addStandardProperties(bpparser.ListType,
map[string]string{
@@ -925,6 +926,7 @@
"BUILD_HOST_JAVA_LIBRARY": "java_library_host",
"BUILD_HOST_DALVIK_JAVA_LIBRARY": "java_library_host_dalvik",
"BUILD_PACKAGE": "android_app",
+ "BUILD_RRO_PACKAGE": "runtime_resource_overlay",
"BUILD_CTS_EXECUTABLE": "cc_binary", // will be further massaged by bpfix depending on the output path
"BUILD_CTS_SUPPORT_PACKAGE": "cts_support_package", // will be rewritten to android_test by bpfix
diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go
index 3e1d486..d9bde94 100644
--- a/androidmk/androidmk/androidmk_test.go
+++ b/androidmk/androidmk/androidmk_test.go
@@ -1360,6 +1360,29 @@
}
`,
},
+ {
+ desc: "runtime_resource_overlay",
+ in: `
+include $(CLEAR_VARS)
+LOCAL_PACKAGE_NAME := foo
+LOCAL_PRODUCT_MODULE := true
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+LOCAL_SDK_VERSION := current
+LOCAL_RRO_THEME := FooTheme
+
+include $(BUILD_RRO_PACKAGE)
+`,
+ expected: `
+runtime_resource_overlay {
+ name: "foo",
+ product_specific: true,
+ resource_dirs: ["res"],
+ sdk_version: "current",
+ theme: "FooTheme",
+
+}
+`,
+ },
}
func TestEndToEnd(t *testing.T) {
diff --git a/apex/apex.go b/apex/apex.go
index 03df0fb..fa71ffa 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -18,7 +18,6 @@
"fmt"
"path"
"path/filepath"
- "regexp"
"sort"
"strings"
"sync"
@@ -1603,6 +1602,8 @@
return android.InList(sanitizerName, globalSanitizerNames)
}
+var _ cc.Coverage = (*apexBundle)(nil)
+
func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
}
@@ -1619,6 +1620,8 @@
a.properties.IsCoverageVariant = coverage
}
+func (a *apexBundle) EnableCoverageIfNeeded() {}
+
// TODO(jiyong) move apexFileFor* close to the apexFile type definition
func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
// Decide the APEX-local directory by the multilib of the library
@@ -1807,24 +1810,6 @@
return intVer
}
-// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
-// a dependency tag.
-var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
-
-func PrettyPrintTag(tag blueprint.DependencyTag) string {
- // Use tag's custom String() method if available.
- if stringer, ok := tag.(fmt.Stringer); ok {
- return stringer.String()
- }
-
- // Otherwise, get a default string representation of the tag's struct.
- tagString := fmt.Sprintf("%#v", tag)
-
- // Remove the boilerplate from BaseDependencyTag as it adds no value.
- tagString = tagCleaner.ReplaceAllString(tagString, "")
- return tagString
-}
-
// Ensures that the dependencies are marked as available for this APEX
func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
// Let's be practical. Availability for test, host, and the VNDK apex isn't important
@@ -1859,14 +1844,7 @@
if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
return true
}
- message := ""
- tagPath := ctx.GetTagPath()
- // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
- walkPath := ctx.GetWalkPath()[1:]
- for i, m := range walkPath {
- message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
- }
- ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
+ ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, ctx.GetPathString(true))
// Visit this module's dependencies to check and report any issues with their availability.
return true
})
@@ -2130,7 +2108,7 @@
filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
}
} else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
- ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
+ ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
}
}
}
diff --git a/apex/vndk_test.go b/apex/vndk_test.go
index 523ac26..05cdfcd 100644
--- a/apex/vndk_test.go
+++ b/apex/vndk_test.go
@@ -117,44 +117,7 @@
})
t.Run("VNDK APEX supports coverage variants", func(t *testing.T) {
- ctx, _ := testApex(t, bp+`
- cc_library {
- name: "libprofile-extras",
- vendor_available: true,
- recovery_available: true,
- native_coverage: false,
- system_shared_libs: [],
- stl: "none",
- notice: "custom_notice",
- }
- cc_library {
- name: "libprofile-clang-extras",
- vendor_available: true,
- recovery_available: true,
- native_coverage: false,
- system_shared_libs: [],
- stl: "none",
- notice: "custom_notice",
- }
- cc_library {
- name: "libprofile-extras_ndk",
- vendor_available: true,
- native_coverage: false,
- system_shared_libs: [],
- stl: "none",
- notice: "custom_notice",
- sdk_version: "current",
- }
- cc_library {
- name: "libprofile-clang-extras_ndk",
- vendor_available: true,
- native_coverage: false,
- system_shared_libs: [],
- stl: "none",
- notice: "custom_notice",
- sdk_version: "current",
- }
- `, func(fs map[string][]byte, config android.Config) {
+ ctx, _ := testApex(t, bp, func(fs map[string][]byte, config android.Config) {
config.TestProductVariables.Native_coverage = proptools.BoolPtr(true)
})
diff --git a/cc/cc.go b/cc/cc.go
index 49605cc..02c4879 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -437,7 +437,6 @@
ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
runtimeDepTag = DependencyTag{Name: "runtime lib"}
- coverageDepTag = DependencyTag{Name: "coverage"}
testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
)
@@ -745,6 +744,15 @@
return c.outputFile
}
+func (c *Module) CoverageFiles() android.Paths {
+ if c.linker != nil {
+ if library, ok := c.linker.(libraryInterface); ok {
+ return library.objs().coverageFiles
+ }
+ }
+ panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
+}
+
var _ LinkableInterface = (*Module)(nil)
func (c *Module) UnstrippedOutputFile() android.Path {
@@ -2493,13 +2501,16 @@
// When combining coverage files for shared libraries and executables, coverage files
// in static libraries act as if they were whole static libraries. The same goes for
// source based Abi dump files.
- // This should only be done for cc.Modules
if c, ok := ccDep.(*Module); ok {
staticLib := c.linker.(libraryInterface)
depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
staticLib.objs().coverageFiles...)
depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
staticLib.objs().sAbiDumpFiles...)
+ } else if c, ok := ccDep.(LinkableInterface); ok {
+ // Handle non-CC modules here
+ depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
+ c.CoverageFiles()...)
}
}
diff --git a/cc/coverage.go b/cc/coverage.go
index bde07fd..cc9a1ad 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -65,10 +65,10 @@
if cov.Properties.NeedCoverageVariant {
ctx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
- }, coverageDepTag, getGcovProfileLibraryName(ctx))
+ }, CoverageDepTag, getGcovProfileLibraryName(ctx))
ctx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
- }, coverageDepTag, getClangProfileLibraryName(ctx))
+ }, CoverageDepTag, getClangProfileLibraryName(ctx))
}
return deps
}
@@ -134,14 +134,14 @@
if gcovCoverage {
flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage")
- coverage := ctx.GetDirectDepWithTag(getGcovProfileLibraryName(ctx), coverageDepTag).(*Module)
+ coverage := ctx.GetDirectDepWithTag(getGcovProfileLibraryName(ctx), CoverageDepTag).(*Module)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
} else if clangCoverage {
flags.Local.LdFlags = append(flags.Local.LdFlags, "-fprofile-instr-generate")
- coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), coverageDepTag).(*Module)
+ coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), CoverageDepTag).(*Module)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
}
}
@@ -150,25 +150,30 @@
}
func (cov *coverage) begin(ctx BaseModuleContext) {
+ if ctx.Host() {
+ // TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a
+ // Just turn off for now.
+ } else {
+ cov.Properties = SetCoverageProperties(ctx, cov.Properties, ctx.nativeCoverage(), ctx.useSdk(), ctx.sdkVersion())
+ }
+}
+
+func SetCoverageProperties(ctx android.BaseModuleContext, properties CoverageProperties, moduleTypeHasCoverage bool,
+ useSdk bool, sdkVersion string) CoverageProperties {
// Coverage is disabled globally
if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() {
- return
+ return properties
}
var needCoverageVariant bool
var needCoverageBuild bool
- if ctx.Host() {
- // TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a
- // Just turn off for now.
- } else if !ctx.nativeCoverage() {
- // Native coverage is not supported for this module type.
- } else {
+ if moduleTypeHasCoverage {
// Check if Native_coverage is set to false. This property defaults to true.
- needCoverageVariant = BoolDefault(cov.Properties.Native_coverage, true)
- if sdk_version := ctx.sdkVersion(); ctx.useSdk() && sdk_version != "current" {
+ needCoverageVariant = BoolDefault(properties.Native_coverage, true)
+ if useSdk && sdkVersion != "current" {
// Native coverage is not supported for SDK versions < 23
- if fromApi, err := strconv.Atoi(sdk_version); err == nil && fromApi < 23 {
+ if fromApi, err := strconv.Atoi(sdkVersion); err == nil && fromApi < 23 {
needCoverageVariant = false
}
}
@@ -179,8 +184,10 @@
}
}
- cov.Properties.NeedCoverageBuild = needCoverageBuild
- cov.Properties.NeedCoverageVariant = needCoverageVariant
+ properties.NeedCoverageBuild = needCoverageBuild
+ properties.NeedCoverageVariant = needCoverageVariant
+
+ return properties
}
// Coverage is an interface for non-CC modules to implement to be mutated for coverage
@@ -190,6 +197,7 @@
PreventInstall()
HideFromMake()
MarkAsCoverageVariant(bool)
+ EnableCoverageIfNeeded()
}
func coverageMutator(mctx android.BottomUpMutatorContext) {
@@ -212,14 +220,17 @@
m[1].(*Module).coverage.Properties.IsCoverageVariant = true
}
} else if cov, ok := mctx.Module().(Coverage); ok && cov.IsNativeCoverageNeeded(mctx) {
- // APEX modules fall here
+ // APEX and Rust modules fall here
// Note: variant "" is also created because an APEX can be depended on by another
// module which are split into "" and "cov" variants. e.g. when cc_test refers
// to an APEX via 'data' property.
m := mctx.CreateVariations("", "cov")
- m[0].(Coverage).MarkAsCoverageVariant(true)
+ m[0].(Coverage).MarkAsCoverageVariant(false)
m[0].(Coverage).PreventInstall()
m[0].(Coverage).HideFromMake()
+
+ m[1].(Coverage).MarkAsCoverageVariant(true)
+ m[1].(Coverage).EnableCoverageIfNeeded()
}
}
diff --git a/cc/linkable.go b/cc/linkable.go
index 4a70d48..de36f90 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -12,6 +12,7 @@
CcLibraryInterface() bool
OutputFile() android.OptionalPath
+ CoverageFiles() android.Paths
IncludeDirs() android.Paths
SetDepsInLinkOrder([]android.Path)
@@ -83,4 +84,5 @@
CrtBeginDepTag = DependencyTag{Name: "crtbegin"}
CrtEndDepTag = DependencyTag{Name: "crtend"}
+ CoverageDepTag = DependencyTag{Name: "coverage"}
)
diff --git a/cc/testing.go b/cc/testing.go
index 6119920..be020c5 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -192,6 +192,45 @@
symbol_file: "",
sdk_version: "current",
}
+
+ // Coverage libraries
+ cc_library {
+ name: "libprofile-extras",
+ vendor_available: true,
+ recovery_available: true,
+ native_coverage: false,
+ system_shared_libs: [],
+ stl: "none",
+ notice: "custom_notice",
+ }
+ cc_library {
+ name: "libprofile-clang-extras",
+ vendor_available: true,
+ recovery_available: true,
+ native_coverage: false,
+ system_shared_libs: [],
+ stl: "none",
+ notice: "custom_notice",
+ }
+ cc_library {
+ name: "libprofile-extras_ndk",
+ vendor_available: true,
+ native_coverage: false,
+ system_shared_libs: [],
+ stl: "none",
+ notice: "custom_notice",
+ sdk_version: "current",
+ }
+ cc_library {
+ name: "libprofile-clang-extras_ndk",
+ vendor_available: true,
+ native_coverage: false,
+ system_shared_libs: [],
+ stl: "none",
+ notice: "custom_notice",
+ sdk_version: "current",
+ }
+
cc_library {
name: "libdl",
no_libcrt: true,
diff --git a/java/app.go b/java/app.go
index d25575c..43bdc91 100755
--- a/java/app.go
+++ b/java/app.go
@@ -80,10 +80,14 @@
// list of native libraries that will be provided in or alongside the resulting jar
Jni_libs []string `android:"arch_variant"`
- // if true, allow JNI libraries that link against platform APIs even if this module sets
+ // if true, use JNI libraries that link against platform APIs even if this module sets
// sdk_version.
Jni_uses_platform_apis *bool
+ // if true, use JNI libraries that link against SDK APIs even if this module does not set
+ // sdk_version.
+ Jni_uses_sdk_apis *bool
+
// STL library to use for JNI libraries.
Stl *string `android:"arch_variant"`
@@ -234,7 +238,8 @@
// If the app builds against an Android SDK use the SDK variant of JNI dependencies
// unless jni_uses_platform_apis is set.
if a.sdkVersion().specified() && a.sdkVersion().kind != sdkCorePlatform &&
- !Bool(a.appProperties.Jni_uses_platform_apis) {
+ !Bool(a.appProperties.Jni_uses_platform_apis) ||
+ Bool(a.appProperties.Jni_uses_sdk_apis) {
variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
}
ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
@@ -714,6 +719,8 @@
a.appProperties.IsCoverageVariant = coverage
}
+func (a *AndroidApp) EnableCoverageIfNeeded() {}
+
var _ cc.Coverage = (*AndroidApp)(nil)
// android_app compiles sources and Android resources into an Android application package `.apk` file.
@@ -1391,6 +1398,8 @@
module.processVariants(ctx)
})
+ module.dexpreopter.isTest = true
+
android.InitApexModule(module)
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
diff --git a/java/java_test.go b/java/java_test.go
index e8a1a7c..0033f31 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1229,6 +1229,24 @@
}
}
+func TestJavaSdkLibrary_InvalidScopes(t *testing.T) {
+ testJavaError(t, `module "foo": enabled api scope "system" depends on disabled scope "public"`, `
+ java_sdk_library {
+ name: "foo",
+ srcs: ["a.java", "b.java"],
+ api_packages: ["foo"],
+ // Explicitly disable public to test the check that ensures the set of enabled
+ // scopes is consistent.
+ public: {
+ enabled: false,
+ },
+ system: {
+ enabled: true,
+ },
+ }
+ `)
+}
+
var compilerFlagsTestCases = []struct {
in string
out bool
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 4d480ee..fb51e10 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -70,6 +70,18 @@
// The api scope that this scope extends.
extends *apiScope
+ // The legacy enabled status for a specific scope can be dependent on other
+ // properties that have been specified on the library so it is provided by
+ // a function that can determine the status by examining those properties.
+ legacyEnabledStatus func(module *SdkLibrary) bool
+
+ // The default enabled status for non-legacy behavior, which is triggered by
+ // explicitly enabling at least one api scope.
+ defaultEnabledStatus bool
+
+ // Gets a pointer to the scope specific properties.
+ scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties
+
// The name of the field in the dynamically created structure.
fieldName string
@@ -120,6 +132,10 @@
return baseName + sdkStubsSourceSuffix + scope.moduleSuffix
}
+func (scope *apiScope) String() string {
+ return scope.name
+}
+
type apiScopes []*apiScope
func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string {
@@ -132,30 +148,68 @@
var (
apiScopePublic = initApiScope(&apiScope{
- name: "public",
+ name: "public",
+
+ // Public scope is enabled by default for both legacy and non-legacy modes.
+ legacyEnabledStatus: func(module *SdkLibrary) bool {
+ return true
+ },
+ defaultEnabledStatus: true,
+
+ scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
+ return &module.sdkLibraryProperties.Public
+ },
sdkVersion: "current",
})
apiScopeSystem = initApiScope(&apiScope{
- name: "system",
- extends: apiScopePublic,
+ name: "system",
+ extends: apiScopePublic,
+ legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
+ scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
+ return &module.sdkLibraryProperties.System
+ },
apiFilePrefix: "system-",
moduleSuffix: sdkSystemApiSuffix,
sdkVersion: "system_current",
droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi"},
})
apiScopeTest = initApiScope(&apiScope{
- name: "test",
- extends: apiScopePublic,
+ name: "test",
+ extends: apiScopePublic,
+ legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
+ scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
+ return &module.sdkLibraryProperties.Test
+ },
apiFilePrefix: "test-",
moduleSuffix: sdkTestApiSuffix,
sdkVersion: "test_current",
droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"},
unstable: true,
})
+ apiScopeModuleLib = initApiScope(&apiScope{
+ name: "module_lib",
+ extends: apiScopeSystem,
+ // Module_lib scope is disabled by default in legacy mode.
+ //
+ // Enabling this would break existing usages.
+ legacyEnabledStatus: func(module *SdkLibrary) bool {
+ return false
+ },
+ scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
+ return &module.sdkLibraryProperties.Module_lib
+ },
+ apiFilePrefix: "module-lib-",
+ moduleSuffix: ".module_lib",
+ sdkVersion: "module_current",
+ droidstubsArgs: []string{
+ "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)",
+ },
+ })
allApiScopes = apiScopes{
apiScopePublic,
apiScopeSystem,
apiScopeTest,
+ apiScopeModuleLib,
}
)
@@ -190,6 +244,18 @@
ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
}
+// Properties associated with each api scope.
+type ApiScopeProperties struct {
+ // Indicates whether the api surface is generated.
+ //
+ // If this is set for any scope then all scopes must explicitly specify if they
+ // are enabled. This is to prevent new usages from depending on legacy behavior.
+ //
+ // Otherwise, if this is not set for any scope then the default behavior is
+ // scope specific so please refer to the scope specific property documentation.
+ Enabled *bool
+}
+
type sdkLibraryProperties struct {
// List of Java libraries that will be in the classpath when building stubs
Stub_only_libs []string `android:"arch_variant"`
@@ -232,8 +298,36 @@
// don't create dist rules.
No_dist *bool `blueprint:"mutated"`
- // indicates whether system and test apis should be managed.
- Has_system_and_test_apis bool `blueprint:"mutated"`
+ // indicates whether system and test apis should be generated.
+ Generate_system_and_test_apis bool `blueprint:"mutated"`
+
+ // The properties specific to the public api scope
+ //
+ // Unless explicitly specified by using public.enabled the public api scope is
+ // enabled by default in both legacy and non-legacy mode.
+ Public ApiScopeProperties
+
+ // The properties specific to the system api scope
+ //
+ // In legacy mode the system api scope is enabled by default when sdk_version
+ // is set to something other than "none".
+ //
+ // In non-legacy mode the system api scope is disabled by default.
+ System ApiScopeProperties
+
+ // The properties specific to the test api scope
+ //
+ // In legacy mode the test api scope is enabled by default when sdk_version
+ // is set to something other than "none".
+ //
+ // In non-legacy mode the test api scope is disabled by default.
+ Test ApiScopeProperties
+
+ // The properties specific to the module_lib api scope
+ //
+ // Unless explicitly specified by using test.enabled the module_lib api scope is
+ // disabled by default.
+ Module_lib ApiScopeProperties
// TODO: determines whether to create HTML doc or not
//Html_doc *bool
@@ -270,18 +364,65 @@
sdkLibraryProperties sdkLibraryProperties
+ // Map from api scope to the scope specific property structure.
+ scopeToProperties map[*apiScope]*ApiScopeProperties
+
commonToSdkLibraryAndImport
}
var _ Dependency = (*SdkLibrary)(nil)
var _ SdkLibraryDependency = (*SdkLibrary)(nil)
-func (module *SdkLibrary) getActiveApiScopes() apiScopes {
- if module.sdkLibraryProperties.Has_system_and_test_apis {
- return allApiScopes
- } else {
- return apiScopes{apiScopePublic}
+func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool {
+ return module.sdkLibraryProperties.Generate_system_and_test_apis
+}
+
+func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes {
+ // Check to see if any scopes have been explicitly enabled. If any have then all
+ // must be.
+ anyScopesExplicitlyEnabled := false
+ for _, scope := range allApiScopes {
+ scopeProperties := module.scopeToProperties[scope]
+ if scopeProperties.Enabled != nil {
+ anyScopesExplicitlyEnabled = true
+ break
+ }
}
+
+ var generatedScopes apiScopes
+ enabledScopes := make(map[*apiScope]struct{})
+ for _, scope := range allApiScopes {
+ scopeProperties := module.scopeToProperties[scope]
+ // If any scopes are explicitly enabled then ignore the legacy enabled status.
+ // This is to ensure that any new usages of this module type do not rely on legacy
+ // behaviour.
+ defaultEnabledStatus := false
+ if anyScopesExplicitlyEnabled {
+ defaultEnabledStatus = scope.defaultEnabledStatus
+ } else {
+ defaultEnabledStatus = scope.legacyEnabledStatus(module)
+ }
+ enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus)
+ if enabled {
+ enabledScopes[scope] = struct{}{}
+ generatedScopes = append(generatedScopes, scope)
+ }
+ }
+
+ // Now check to make sure that any scope that is extended by an enabled scope is also
+ // enabled.
+ for _, scope := range allApiScopes {
+ if _, ok := enabledScopes[scope]; ok {
+ extends := scope.extends
+ if extends != nil {
+ if _, ok := enabledScopes[extends]; !ok {
+ ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends)
+ }
+ }
+ }
+ }
+
+ return generatedScopes
}
var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"}
@@ -294,7 +435,7 @@
}
func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
- for _, apiScope := range module.getActiveApiScopes() {
+ for _, apiScope := range module.getGeneratedApiScopes(ctx) {
// Add dependencies to the stubs library
ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope))
@@ -387,7 +528,7 @@
}
// Get the sdk version for use when compiling the stubs library.
-func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) string {
+func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) string {
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
if sdkDep.hasStandardLibs() {
// If building against a standard sdk then use the sdk version appropriate for the scope.
@@ -407,7 +548,7 @@
}
// Creates a static java library that has API stubs
-func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) {
+func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) {
props := struct {
Name *string
Srcs []string
@@ -478,7 +619,7 @@
// Creates a droidstubs module that creates stubs source files from the given full source
// files
-func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope *apiScope) {
+func (module *SdkLibrary) createStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope) {
props := struct {
Name *string
Srcs []string
@@ -597,7 +738,7 @@
}
// Creates the xml file that publicizes the runtime library
-func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
+func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
props := struct {
Name *string
Lib_name *string
@@ -718,7 +859,12 @@
// For a java_sdk_library module, create internal modules for stubs, docs,
// runtime libs and xml file. If requested, the stubs and docs are created twice
// once for public API level and once for system API level
-func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
+func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) {
+ // If the module has been disabled then don't create any child modules.
+ if !module.Enabled() {
+ return
+ }
+
if len(module.Library.Module.properties.Srcs) == 0 {
mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
return
@@ -729,15 +875,15 @@
// also assume it does not contribute to the dist build.
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
hasSystemAndTestApis := sdkDep.hasStandardLibs()
- module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis
+ module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis
module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
missing_current_api := false
- activeScopes := module.getActiveApiScopes()
+ generatedScopes := module.getGeneratedApiScopes(mctx)
apiDir := module.getApiDir()
- for _, scope := range activeScopes {
+ for _, scope := range generatedScopes {
for _, api := range []string{"current.txt", "removed.txt"} {
path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api)
p := android.ExistentPathForSource(mctx, path)
@@ -760,11 +906,11 @@
"You can update them by:\n"+
"%s %q %s && m update-api",
script, filepath.Join(mctx.ModuleDir(), apiDir),
- strings.Join(activeScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
+ strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
return
}
- for _, scope := range activeScopes {
+ for _, scope := range generatedScopes {
module.createStubsLibrary(mctx, scope)
module.createStubsSources(mctx, scope)
}
@@ -804,7 +950,15 @@
module.InitSdkLibraryProperties()
android.InitApexModule(module)
InitJavaModule(module, android.HostAndDeviceSupported)
- android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
+
+ // Initialize the map from scope to scope specific properties.
+ scopeToProperties := make(map[*apiScope]*ApiScopeProperties)
+ for _, scope := range allApiScopes {
+ scopeToProperties[scope] = scope.scopeSpecificProperties(module)
+ }
+ module.scopeToProperties = scopeToProperties
+
+ module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { module.CreateInternalModules(ctx) })
return module
}
diff --git a/rust/androidmk.go b/rust/androidmk.go
index 0fba739..0e2bea3 100644
--- a/rust/androidmk.go
+++ b/rust/androidmk.go
@@ -46,6 +46,12 @@
}
func (mod *Module) AndroidMk() android.AndroidMkData {
+ if mod.Properties.HideFromMake {
+ return android.AndroidMkData{
+ Disabled: true,
+ }
+ }
+
ret := android.AndroidMkData{
OutputFile: mod.outputFile,
Include: "$(BUILD_SYSTEM)/soong_rust_prebuilt.mk",
@@ -84,6 +90,9 @@
ret.DistFile = binary.distFile
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", binary.unstrippedOutputFile.String())
+ if binary.coverageOutputZipFile.Valid() {
+ fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE := "+binary.coverageOutputZipFile.String())
+ }
})
}
@@ -124,6 +133,10 @@
if !library.rlib() {
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", library.unstrippedOutputFile.String())
}
+ if library.coverageOutputZipFile.Valid() {
+ fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE := "+library.coverageOutputZipFile.String())
+ }
+
})
}
diff --git a/rust/binary.go b/rust/binary.go
index fda056e..c25ae09 100644
--- a/rust/binary.go
+++ b/rust/binary.go
@@ -35,9 +35,10 @@
type binaryDecorator struct {
*baseCompiler
- Properties BinaryCompilerProperties
- distFile android.OptionalPath
- unstrippedOutputFile android.Path
+ Properties BinaryCompilerProperties
+ distFile android.OptionalPath
+ coverageOutputZipFile android.OptionalPath
+ unstrippedOutputFile android.Path
}
var _ compiler = (*binaryDecorator)(nil)
@@ -104,6 +105,10 @@
&binary.Properties)
}
+func (binary *binaryDecorator) nativeCoverage() bool {
+ return true
+}
+
func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix()
@@ -114,7 +119,21 @@
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
- TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ outputs := TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ binary.coverageFile = outputs.coverageFile
+
+ var coverageFiles android.Paths
+ if outputs.coverageFile != nil {
+ coverageFiles = append(coverageFiles, binary.coverageFile)
+ }
+ if len(deps.coverageFiles) > 0 {
+ coverageFiles = append(coverageFiles, deps.coverageFiles...)
+ }
+ binary.coverageOutputZipFile = TransformCoverageFilesToZip(ctx, coverageFiles, binary.getStem(ctx))
return outputFile
}
+
+func (binary *binaryDecorator) coverageOutputZipPath() android.OptionalPath {
+ return binary.coverageOutputZipFile
+}
diff --git a/rust/builder.go b/rust/builder.go
index 2d5e602..fbe0e53 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -18,6 +18,7 @@
"strings"
"github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
"android/soong/android"
)
@@ -36,44 +37,57 @@
Depfile: "$out.d",
},
"rustcFlags", "linkFlags", "libFlags", "crtBegin", "crtEnd")
+
+ zip = pctx.AndroidStaticRule("zip",
+ blueprint.RuleParams{
+ Command: "cat $out.rsp | tr ' ' '\\n' | tr -d \\' | sort -u > ${out}.tmp && ${SoongZipCmd} -o ${out} -C $$OUT_DIR -l ${out}.tmp",
+ CommandDeps: []string{"${SoongZipCmd}"},
+ Rspfile: "$out.rsp",
+ RspfileContent: "$in",
+ })
)
-func init() {
+type buildOutput struct {
+ outputFile android.Path
+ coverageFile android.Path
+}
+func init() {
+ pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
}
func TransformSrcToBinary(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, includeDirs []string) {
+ outputFile android.WritablePath, includeDirs []string) buildOutput {
flags.RustFlags = append(flags.RustFlags, "-C lto")
- transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin", includeDirs)
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin", includeDirs)
}
func TransformSrctoRlib(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, includeDirs []string) {
- transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib", includeDirs)
+ outputFile android.WritablePath, includeDirs []string) buildOutput {
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib", includeDirs)
}
func TransformSrctoDylib(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, includeDirs []string) {
- transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib", includeDirs)
+ outputFile android.WritablePath, includeDirs []string) buildOutput {
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib", includeDirs)
}
func TransformSrctoStatic(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, includeDirs []string) {
+ outputFile android.WritablePath, includeDirs []string) buildOutput {
flags.RustFlags = append(flags.RustFlags, "-C lto")
- transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib", includeDirs)
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib", includeDirs)
}
func TransformSrctoShared(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, includeDirs []string) {
+ outputFile android.WritablePath, includeDirs []string) buildOutput {
flags.RustFlags = append(flags.RustFlags, "-C lto")
- transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib", includeDirs)
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib", includeDirs)
}
func TransformSrctoProcMacro(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps,
- flags Flags, outputFile android.WritablePath, includeDirs []string) {
- transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro", includeDirs)
+ flags Flags, outputFile android.WritablePath, includeDirs []string) buildOutput {
+ return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro", includeDirs)
}
func rustLibsToPaths(libs RustLibraries) android.Paths {
@@ -85,11 +99,15 @@
}
func transformSrctoCrate(ctx android.ModuleContext, main android.Path, deps PathDeps, flags Flags,
- outputFile android.WritablePath, crate_type string, includeDirs []string) {
+ outputFile android.WritablePath, crate_type string, includeDirs []string) buildOutput {
var inputs android.Paths
var implicits android.Paths
+ var output buildOutput
var libFlags, rustcFlags, linkFlags []string
+ var implicitOutputs android.WritablePaths
+
+ output.outputFile = outputFile
crate_name := ctx.(ModuleContext).CrateName()
targetTriple := ctx.(ModuleContext).toolchain().RustTriple()
@@ -141,12 +159,26 @@
implicits = append(implicits, deps.CrtBegin.Path(), deps.CrtEnd.Path())
}
+ if flags.Coverage {
+ var gcnoFile android.WritablePath
+
+ if outputFile.Ext() != "" {
+ gcnoFile = android.PathForModuleOut(ctx, pathtools.ReplaceExtension(outputFile.Base(), "gcno"))
+ } else {
+ gcnoFile = android.PathForModuleOut(ctx, outputFile.Base()+".gcno")
+ }
+
+ implicitOutputs = append(implicitOutputs, gcnoFile)
+ output.coverageFile = gcnoFile
+ }
+
ctx.Build(pctx, android.BuildParams{
- Rule: rustc,
- Description: "rustc " + main.Rel(),
- Output: outputFile,
- Inputs: inputs,
- Implicits: implicits,
+ Rule: rustc,
+ Description: "rustc " + main.Rel(),
+ Output: outputFile,
+ ImplicitOutputs: implicitOutputs,
+ Inputs: inputs,
+ Implicits: implicits,
Args: map[string]string{
"rustcFlags": strings.Join(rustcFlags, " "),
"linkFlags": strings.Join(linkFlags, " "),
@@ -156,4 +188,23 @@
},
})
+ return output
+}
+
+func TransformCoverageFilesToZip(ctx android.ModuleContext,
+ covFiles android.Paths, baseName string) android.OptionalPath {
+ if len(covFiles) > 0 {
+
+ outputFile := android.PathForModuleOut(ctx, baseName+".zip")
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: zip,
+ Description: "zip " + outputFile.Base(),
+ Inputs: covFiles,
+ Output: outputFile,
+ })
+
+ return android.OptionalPathForPath(outputFile)
+ }
+ return android.OptionalPath{}
}
diff --git a/rust/compiler.go b/rust/compiler.go
index 7499776..5f098bc 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -110,6 +110,7 @@
linkDirs []string
edition string
src android.Path //rustc takes a single src file
+ coverageFile android.Path //rustc generates a single gcno file
// Install related
dir string
@@ -120,6 +121,10 @@
location installLocation
}
+func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath {
+ panic("baseCompiler does not implement coverageOutputZipPath()")
+}
+
var _ compiler = (*baseCompiler)(nil)
func (compiler *baseCompiler) inData() bool {
@@ -235,6 +240,10 @@
compiler.relativeInstallPath(), compiler.relative)
}
+func (compiler *baseCompiler) nativeCoverage() bool {
+ return false
+}
+
func (compiler *baseCompiler) install(ctx ModuleContext, file android.Path) {
compiler.path = ctx.InstallFile(compiler.installDir(ctx), file.Base(), file)
}
diff --git a/rust/coverage.go b/rust/coverage.go
new file mode 100644
index 0000000..9be57dc
--- /dev/null
+++ b/rust/coverage.go
@@ -0,0 +1,72 @@
+// Copyright 2020 The Android Open Source Project
+//
+// 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 rust
+
+import (
+ "github.com/google/blueprint"
+
+ "android/soong/cc"
+)
+
+var CovLibraryName = "libprofile-extras"
+
+type coverage struct {
+ Properties cc.CoverageProperties
+
+ // Whether binaries containing this module need --coverage added to their ldflags
+ linkCoverage bool
+}
+
+func (cov *coverage) props() []interface{} {
+ return []interface{}{&cov.Properties}
+}
+
+func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
+ if cov.Properties.NeedCoverageVariant {
+ ctx.AddVariationDependencies([]blueprint.Variation{
+ {Mutator: "link", Variation: "static"},
+ }, cc.CoverageDepTag, CovLibraryName)
+ }
+
+ return deps
+}
+
+func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
+
+ if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() {
+ return flags, deps
+ }
+
+ if cov.Properties.CoverageEnabled {
+ flags.Coverage = true
+ coverage := ctx.GetDirectDepWithTag(CovLibraryName, cc.CoverageDepTag).(cc.LinkableInterface)
+ flags.RustFlags = append(flags.RustFlags,
+ "-Z profile", "-g", "-C opt-level=0", "-C link-dead-code", "-Z no-landing-pads")
+ flags.LinkFlags = append(flags.LinkFlags,
+ "--coverage", "-g", coverage.OutputFile().Path().String(), "-Wl,--wrap,getenv")
+ deps.StaticLibs = append(deps.StaticLibs, coverage.OutputFile().Path())
+ }
+
+ return flags, deps
+}
+
+func (cov *coverage) begin(ctx BaseModuleContext) {
+ if ctx.Host() {
+ // Host coverage not yet supported.
+ } else {
+ // Update useSdk and sdkVersion args if Rust modules become SDK aware.
+ cov.Properties = cc.SetCoverageProperties(ctx, cov.Properties, ctx.nativeCoverage(), false, "")
+ }
+}
diff --git a/rust/coverage_test.go b/rust/coverage_test.go
new file mode 100644
index 0000000..27acad3
--- /dev/null
+++ b/rust/coverage_test.go
@@ -0,0 +1,181 @@
+// Copyright 2020 The Android Open Source Project
+//
+// 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 rust
+
+import (
+ "strings"
+ "testing"
+
+ "android/soong/android"
+)
+
+// Test that coverage flags are being correctly generated.
+func TestCoverageFlags(t *testing.T) {
+ ctx := testRustCov(t, `
+ rust_library {
+ name: "libfoo_cov",
+ srcs: ["foo.rs"],
+ crate_name: "foo",
+ }
+ rust_binary {
+ name: "fizz_cov",
+ srcs: ["foo.rs"],
+ }
+ rust_binary {
+ name: "buzzNoCov",
+ srcs: ["foo.rs"],
+ native_coverage: false,
+ }
+ rust_library {
+ name: "libbar_nocov",
+ srcs: ["foo.rs"],
+ crate_name: "bar",
+ native_coverage: false,
+ }`)
+
+ // Make sure native_coverage: false isn't creating a coverage variant.
+ if android.InList("android_arm64_armv8-a_dylib_cov", ctx.ModuleVariantsForTests("libbar_nocov")) {
+ t.Fatalf("coverage variant created for module 'libbar_nocov' with native coverage disabled")
+ }
+
+ // Just test the dylib variants unless the library coverage logic changes to distinguish between the types.
+ libfooCov := ctx.ModuleForTests("libfoo_cov", "android_arm64_armv8-a_dylib_cov").Rule("rustc")
+ libbarNoCov := ctx.ModuleForTests("libbar_nocov", "android_arm64_armv8-a_dylib").Rule("rustc")
+ fizzCov := ctx.ModuleForTests("fizz_cov", "android_arm64_armv8-a_cov").Rule("rustc")
+ buzzNoCov := ctx.ModuleForTests("buzzNoCov", "android_arm64_armv8-a").Rule("rustc")
+
+ rustcCoverageFlags := []string{"-Z profile", " -g ", "-C opt-level=0", "-C link-dead-code", "-Z no-landing-pads"}
+ for _, flag := range rustcCoverageFlags {
+ missingErrorStr := "missing rustc flag '%s' for '%s' module with coverage enabled; rustcFlags: %#v"
+ containsErrorStr := "contains rustc flag '%s' for '%s' module with coverage disabled; rustcFlags: %#v"
+
+ if !strings.Contains(fizzCov.Args["rustcFlags"], flag) {
+ t.Fatalf(missingErrorStr, flag, "fizz_cov", fizzCov.Args["rustcFlags"])
+ }
+ if !strings.Contains(libfooCov.Args["rustcFlags"], flag) {
+ t.Fatalf(missingErrorStr, flag, "libfoo_cov dylib", libfooCov.Args["rustcFlags"])
+ }
+ if strings.Contains(buzzNoCov.Args["rustcFlags"], flag) {
+ t.Fatalf(containsErrorStr, flag, "buzzNoCov", buzzNoCov.Args["rustcFlags"])
+ }
+ if strings.Contains(libbarNoCov.Args["rustcFlags"], flag) {
+ t.Fatalf(containsErrorStr, flag, "libbar_cov", libbarNoCov.Args["rustcFlags"])
+ }
+ }
+
+ linkCoverageFlags := []string{"--coverage", " -g "}
+ for _, flag := range linkCoverageFlags {
+ missingErrorStr := "missing rust linker flag '%s' for '%s' module with coverage enabled; rustcFlags: %#v"
+ containsErrorStr := "contains rust linker flag '%s' for '%s' module with coverage disabled; rustcFlags: %#v"
+
+ if !strings.Contains(fizzCov.Args["linkFlags"], flag) {
+ t.Fatalf(missingErrorStr, flag, "fizz_cov", fizzCov.Args["linkFlags"])
+ }
+ if !strings.Contains(libfooCov.Args["linkFlags"], flag) {
+ t.Fatalf(missingErrorStr, flag, "libfoo_cov dylib", libfooCov.Args["linkFlags"])
+ }
+ if strings.Contains(buzzNoCov.Args["linkFlags"], flag) {
+ t.Fatalf(containsErrorStr, flag, "buzzNoCov", buzzNoCov.Args["linkFlags"])
+ }
+ if strings.Contains(libbarNoCov.Args["linkFlags"], flag) {
+ t.Fatalf(containsErrorStr, flag, "libbar_cov", libbarNoCov.Args["linkFlags"])
+ }
+ }
+
+}
+
+// Test coverage files are included correctly
+func TestCoverageZip(t *testing.T) {
+ ctx := testRustCov(t, `
+ rust_library {
+ name: "libfoo",
+ srcs: ["foo.rs"],
+ rlibs: ["librlib"],
+ crate_name: "foo",
+ }
+ rust_library_rlib {
+ name: "librlib",
+ srcs: ["foo.rs"],
+ crate_name: "rlib",
+ }
+ rust_binary {
+ name: "fizz",
+ rlibs: ["librlib"],
+ static_libs: ["libfoo"],
+ srcs: ["foo.rs"],
+ }
+ cc_binary {
+ name: "buzz",
+ static_libs: ["libfoo"],
+ srcs: ["foo.c"],
+ }
+ cc_library {
+ name: "libbar",
+ static_libs: ["libfoo"],
+ compile_multilib: "64",
+ srcs: ["foo.c"],
+ }`)
+
+ fizzZipInputs := ctx.ModuleForTests("fizz", "android_arm64_armv8-a_cov").Rule("zip").Inputs.Strings()
+ libfooZipInputs := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib_cov").Rule("zip").Inputs.Strings()
+ buzzZipInputs := ctx.ModuleForTests("buzz", "android_arm64_armv8-a_cov").Rule("zip").Inputs.Strings()
+ libbarZipInputs := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared_cov").Rule("zip").Inputs.Strings()
+
+ // Make sure the expected number of input files are included.
+ if len(fizzZipInputs) != 3 {
+ t.Fatalf("expected only 3 coverage inputs for rust 'fizz' binary, got %#v: %#v", len(fizzZipInputs), fizzZipInputs)
+ }
+ if len(libfooZipInputs) != 2 {
+ t.Fatalf("expected only 2 coverage inputs for rust 'libfoo' library, got %#v: %#v", len(libfooZipInputs), libfooZipInputs)
+ }
+ if len(buzzZipInputs) != 2 {
+ t.Fatalf("expected only 2 coverage inputs for cc 'buzz' binary, got %#v: %#v", len(buzzZipInputs), buzzZipInputs)
+ }
+ if len(libbarZipInputs) != 2 {
+ t.Fatalf("expected only 2 coverage inputs for cc 'libbar' library, got %#v: %#v", len(libbarZipInputs), libbarZipInputs)
+ }
+
+ // Make sure the expected inputs are provided to the zip rule.
+ if !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_rlib_cov/librlib.gcno") ||
+ !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_static_cov/libfoo.gcno") ||
+ !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_cov/fizz.gcno") {
+ t.Fatalf("missing expected coverage files for rust 'fizz' binary: %#v", fizzZipInputs)
+ }
+ if !android.SuffixInList(libfooZipInputs, "android_arm64_armv8-a_rlib_cov/librlib.gcno") ||
+ !android.SuffixInList(libfooZipInputs, "android_arm64_armv8-a_dylib_cov/libfoo.dylib.gcno") {
+ t.Fatalf("missing expected coverage files for rust 'fizz' binary: %#v", libfooZipInputs)
+ }
+ if !android.SuffixInList(buzzZipInputs, "android_arm64_armv8-a_cov/obj/foo.gcno") ||
+ !android.SuffixInList(buzzZipInputs, "android_arm64_armv8-a_static_cov/libfoo.gcno") {
+ t.Fatalf("missing expected coverage files for cc 'buzz' binary: %#v", buzzZipInputs)
+ }
+ if !android.SuffixInList(libbarZipInputs, "android_arm64_armv8-a_static_cov/obj/foo.gcno") ||
+ !android.SuffixInList(libbarZipInputs, "android_arm64_armv8-a_static_cov/libfoo.gcno") {
+ t.Fatalf("missing expected coverage files for cc 'libbar' library: %#v", libbarZipInputs)
+ }
+}
+
+func TestCoverageDeps(t *testing.T) {
+ ctx := testRustCov(t, `
+ rust_binary {
+ name: "fizz",
+ srcs: ["foo.rs"],
+ }`)
+
+ fizz := ctx.ModuleForTests("fizz", "android_arm64_armv8-a_cov").Rule("rustc")
+ if !strings.Contains(fizz.Args["linkFlags"], "libprofile-extras.a") {
+ t.Fatalf("missing expected coverage 'libprofile-extras' dependency in linkFlags: %#v", fizz.Args["linkFlags"])
+ }
+}
diff --git a/rust/library.go b/rust/library.go
index 87e816d..8aa033c 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -75,11 +75,12 @@
type libraryDecorator struct {
*baseCompiler
- Properties LibraryCompilerProperties
- MutatedProperties LibraryMutatedProperties
- distFile android.OptionalPath
- unstrippedOutputFile android.Path
- includeDirs android.Paths
+ Properties LibraryCompilerProperties
+ MutatedProperties LibraryMutatedProperties
+ distFile android.OptionalPath
+ coverageOutputZipFile android.OptionalPath
+ unstrippedOutputFile android.Path
+ includeDirs android.Paths
}
type libraryInterface interface {
@@ -107,6 +108,10 @@
BuildOnlyShared()
}
+func (library *libraryDecorator) nativeCoverage() bool {
+ return true
+}
+
func (library *libraryDecorator) exportedDirs() []string {
return library.linkDirs
}
@@ -351,24 +356,37 @@
fileName := library.getStem(ctx) + ctx.toolchain().RlibSuffix()
outputFile = android.PathForModuleOut(ctx, fileName)
- TransformSrctoRlib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ outputs := TransformSrctoRlib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ library.coverageFile = outputs.coverageFile
} else if library.dylib() {
fileName := library.getStem(ctx) + ctx.toolchain().DylibSuffix()
outputFile = android.PathForModuleOut(ctx, fileName)
- TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ outputs := TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ library.coverageFile = outputs.coverageFile
} else if library.static() {
fileName := library.getStem(ctx) + ctx.toolchain().StaticLibSuffix()
outputFile = android.PathForModuleOut(ctx, fileName)
- TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ outputs := TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ library.coverageFile = outputs.coverageFile
} else if library.shared() {
fileName := library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
outputFile = android.PathForModuleOut(ctx, fileName)
- TransformSrctoShared(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ outputs := TransformSrctoShared(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ library.coverageFile = outputs.coverageFile
}
+ var coverageFiles android.Paths
+ if library.coverageFile != nil {
+ coverageFiles = append(coverageFiles, library.coverageFile)
+ }
+ if len(deps.coverageFiles) > 0 {
+ coverageFiles = append(coverageFiles, deps.coverageFiles...)
+ }
+ library.coverageOutputZipFile = TransformCoverageFilesToZip(ctx, coverageFiles, library.getStem(ctx))
+
if library.rlib() || library.dylib() {
library.reexportDirs(deps.linkDirs...)
library.reexportDepFlags(deps.depFlags...)
diff --git a/rust/prebuilt.go b/rust/prebuilt.go
index 45bef9e..1d97650 100644
--- a/rust/prebuilt.go
+++ b/rust/prebuilt.go
@@ -69,3 +69,7 @@
deps = prebuilt.baseCompiler.compilerDeps(ctx, deps)
return deps
}
+
+func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool {
+ return false
+}
diff --git a/rust/rust.go b/rust/rust.go
index 5cc8845..8cf2e6d 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -40,6 +40,7 @@
android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
ctx.BottomUp("rust_unit_tests", TestPerSrcMutator).Parallel()
+ ctx.BottomUp("rust_begin", BeginMutator).Parallel()
})
pctx.Import("android/soong/rust/config")
}
@@ -51,6 +52,7 @@
LinkFlags []string // Flags that apply to linker
RustFlagsDeps android.Paths // Files depended on by compiler flags
Toolchain config.Toolchain
+ Coverage bool
}
type BaseProperties struct {
@@ -60,6 +62,8 @@
AndroidMkSharedLibs []string
AndroidMkStaticLibs []string
SubName string `blueprint:"mutated"`
+ PreventInstall bool
+ HideFromMake bool
}
type Module struct {
@@ -72,6 +76,7 @@
multilib android.Multilib
compiler compiler
+ coverage *coverage
cachedToolchain config.Toolchain
subAndroidMkOnce map[subAndroidMkProvider]bool
outputFile android.OptionalPath
@@ -224,6 +229,8 @@
depFlags []string
//ReexportedDeps android.Paths
+ coverageFiles android.Paths
+
CrtBegin android.OptionalPath
CrtEnd android.OptionalPath
}
@@ -245,6 +252,34 @@
inData() bool
install(ctx ModuleContext, path android.Path)
relativeInstallPath() string
+
+ nativeCoverage() bool
+}
+
+func (mod *Module) isCoverageVariant() bool {
+ return mod.coverage.Properties.IsCoverageVariant
+}
+
+var _ cc.Coverage = (*Module)(nil)
+
+func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
+ return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
+}
+
+func (mod *Module) PreventInstall() {
+ mod.Properties.PreventInstall = true
+}
+
+func (mod *Module) HideFromMake() {
+ mod.Properties.HideFromMake = true
+}
+
+func (mod *Module) MarkAsCoverageVariant(coverage bool) {
+ mod.coverage.Properties.IsCoverageVariant = coverage
+}
+
+func (mod *Module) EnableCoverageIfNeeded() {
+ mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
}
func defaultsFactory() android.Module {
@@ -268,6 +303,7 @@
&ProcMacroCompilerProperties{},
&PrebuiltProperties{},
&TestProperties{},
+ &cc.CoverageProperties{},
)
android.InitDefaultsModule(module)
@@ -395,6 +431,18 @@
return false
}
+func (mod *Module) CoverageFiles() android.Paths {
+ if mod.compiler != nil {
+ if library, ok := mod.compiler.(*libraryDecorator); ok {
+ if library.coverageFile != nil {
+ return android.Paths{library.coverageFile}
+ }
+ return android.Paths{}
+ }
+ }
+ panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
+}
+
var _ cc.LinkableInterface = (*Module)(nil)
func (mod *Module) Init() android.Module {
@@ -403,6 +451,10 @@
if mod.compiler != nil {
mod.AddProperties(mod.compiler.compilerProps()...)
}
+ if mod.coverage != nil {
+ mod.AddProperties(mod.coverage.props()...)
+ }
+
android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
android.InitDefaultableModule(mod)
@@ -432,6 +484,7 @@
}
func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
module := newBaseModule(hod, multilib)
+ module.coverage = &coverage{}
return module
}
@@ -454,6 +507,7 @@
toolchain() config.Toolchain
baseModuleName() string
CrateName() string
+ nativeCoverage() bool
}
type depsContext struct {
@@ -466,6 +520,14 @@
moduleContextImpl
}
+func (ctx *moduleContextImpl) nativeCoverage() bool {
+ return ctx.mod.nativeCoverage()
+}
+
+func (mod *Module) nativeCoverage() bool {
+ return mod.compiler != nil && mod.compiler.nativeCoverage()
+}
+
type moduleContextImpl struct {
mod *Module
ctx BaseModuleContext
@@ -508,9 +570,17 @@
if mod.compiler != nil {
flags = mod.compiler.compilerFlags(ctx, flags)
+ }
+ if mod.coverage != nil {
+ flags, deps = mod.coverage.flags(ctx, flags, deps)
+ }
+
+ if mod.compiler != nil {
outputFile := mod.compiler.compile(ctx, flags, deps)
mod.outputFile = android.OptionalPathForPath(outputFile)
- mod.compiler.install(ctx, mod.outputFile.Path())
+ if !mod.Properties.PreventInstall {
+ mod.compiler.install(ctx, mod.outputFile.Path())
+ }
}
}
@@ -521,6 +591,10 @@
deps = mod.compiler.compilerDeps(ctx, deps)
}
+ if mod.coverage != nil {
+ deps = mod.coverage.deps(ctx, deps)
+ }
+
deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
@@ -553,6 +627,12 @@
testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
)
+func (mod *Module) begin(ctx BaseModuleContext) {
+ if mod.coverage != nil {
+ mod.coverage.begin(ctx)
+ }
+}
+
func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var depPaths PathDeps
@@ -588,6 +668,7 @@
ctx.ModuleErrorf("mod %q not an rlib library", depName)
return
}
+ depPaths.coverageFiles = append(depPaths.coverageFiles, rustDep.CoverageFiles()...)
directRlibDeps = append(directRlibDeps, rustDep)
mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName)
case procMacroDepTag:
@@ -642,6 +723,7 @@
depFlag = "-lstatic=" + libName
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
depPaths.depFlags = append(depPaths.depFlags, depFlag)
+ depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...)
directStaticLibDeps = append(directStaticLibDeps, ccDep)
mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
case cc.SharedDepTag:
@@ -772,6 +854,29 @@
actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
}
+func BeginMutator(ctx android.BottomUpMutatorContext) {
+ if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
+ mod.beginMutator(ctx)
+ }
+}
+
+type baseModuleContext struct {
+ android.BaseModuleContext
+ moduleContextImpl
+}
+
+func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
+ ctx := &baseModuleContext{
+ BaseModuleContext: actx,
+ moduleContextImpl: moduleContextImpl{
+ mod: mod,
+ },
+ }
+ ctx.ctx = ctx
+
+ mod.begin(ctx)
+}
+
func (mod *Module) Name() string {
name := mod.ModuleBase.Name()
if p, ok := mod.compiler.(interface {
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 32eddc1..d658ee2 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -21,6 +21,8 @@
"strings"
"testing"
+ "github.com/google/blueprint/proptools"
+
"android/soong/android"
"android/soong/cc"
)
@@ -57,6 +59,7 @@
fs := map[string][]byte{
"foo.rs": nil,
+ "foo.c": nil,
"src/bar.rs": nil,
"liby.so": nil,
"libz.so": nil,
@@ -68,6 +71,14 @@
}
func testRust(t *testing.T, bp string) *android.TestContext {
+ return testRustContext(t, bp, false)
+}
+
+func testRustCov(t *testing.T, bp string) *android.TestContext {
+ return testRustContext(t, bp, true)
+}
+
+func testRustContext(t *testing.T, bp string, coverage bool) *android.TestContext {
// TODO (b/140435149)
if runtime.GOOS != "linux" {
t.Skip("Only the Linux toolchain is supported for Rust")
@@ -76,6 +87,11 @@
t.Helper()
config := testConfig(bp)
+ if coverage {
+ config.TestProductVariables.Native_coverage = proptools.BoolPtr(true)
+ config.TestProductVariables.CoveragePaths = []string{"*"}
+ }
+
t.Helper()
ctx := CreateTestContext()
ctx.Register(config)
diff --git a/rust/test.go b/rust/test.go
index 04f844c..94568c1 100644
--- a/rust/test.go
+++ b/rust/test.go
@@ -50,6 +50,10 @@
testConfig android.Path
}
+func (test *testDecorator) nativeCoverage() bool {
+ return true
+}
+
func NewRustTest(hod android.HostOrDeviceSupported) (*Module, *testDecorator) {
module := newModule(hod, android.MultilibFirst)
diff --git a/rust/testing.go b/rust/testing.go
index aad4ffe..09008a8 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -98,6 +98,7 @@
// rust mutators
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
ctx.BottomUp("rust_unit_tests", TestPerSrcMutator).Parallel()
+ ctx.BottomUp("rust_begin", BeginMutator).Parallel()
})
return ctx
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 788d016..6173510 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -32,6 +32,8 @@
"api/system-removed.txt": nil,
"api/test-current.txt": nil,
"api/test-removed.txt": nil,
+ "api/module-lib-current.txt": nil,
+ "api/module-lib-removed.txt": nil,
"build/soong/scripts/gen-java-current-api-files.sh": nil,
}
@@ -56,6 +58,9 @@
name: "android_test_stubs_current",
}
java_import {
+ name: "android_module_lib_stubs_current",
+}
+java_import {
name: "core-lambda-stubs",
sdk_version: "none",
}
@@ -1067,3 +1072,194 @@
".intermediates/mysdk/common_os/tmp/sdk_library/test/myjavalib_stub_sources.zip"),
)
}
+
+func TestSnapshotWithJavaSdkLibrary_ApiSurfaces(t *testing.T) {
+ result := testSdkWithJava(t, `
+ sdk {
+ name: "mysdk",
+ java_sdk_libs: ["myjavalib"],
+ }
+
+ java_sdk_library {
+ name: "myjavalib",
+ apex_available: ["//apex_available:anyapex"],
+ srcs: ["Test.java"],
+ sdk_version: "current",
+ public: {
+ enabled: true,
+ },
+ system: {
+ enabled: true,
+ },
+ }
+ `)
+
+ result.CheckSnapshot("mysdk", "",
+ checkAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_sdk_library_import {
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
+ apex_available: ["//apex_available:anyapex"],
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "current",
+ },
+ system: {
+ jars: ["sdk_library/system/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
+ current_api: "sdk_library/system/myjavalib.txt",
+ removed_api: "sdk_library/system/myjavalib-removed.txt",
+ sdk_version: "system_current",
+ },
+}
+
+java_sdk_library_import {
+ name: "myjavalib",
+ prefer: false,
+ apex_available: ["//apex_available:anyapex"],
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "current",
+ },
+ system: {
+ jars: ["sdk_library/system/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
+ current_api: "sdk_library/system/myjavalib.txt",
+ removed_api: "sdk_library/system/myjavalib-removed.txt",
+ sdk_version: "system_current",
+ },
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ java_sdk_libs: ["mysdk_myjavalib@current"],
+}
+`),
+ checkAllCopyRules(`
+.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
+.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib-removed.txt
+.intermediates/myjavalib.stubs.system/android_common/javac/myjavalib.stubs.system.jar -> sdk_library/system/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source.system/android_common/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt
+.intermediates/myjavalib.stubs.source.system/android_common/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib-removed.txt
+`),
+ checkMergeZips(
+ ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
+ ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip",
+ ),
+ )
+}
+
+func TestSnapshotWithJavaSdkLibrary_ModuleLib(t *testing.T) {
+ result := testSdkWithJava(t, `
+ sdk {
+ name: "mysdk",
+ java_sdk_libs: ["myjavalib"],
+ }
+
+ java_sdk_library {
+ name: "myjavalib",
+ apex_available: ["//apex_available:anyapex"],
+ srcs: ["Test.java"],
+ sdk_version: "current",
+ public: {
+ enabled: true,
+ },
+ system: {
+ enabled: true,
+ },
+ module_lib: {
+ enabled: true,
+ },
+ }
+ `)
+
+ result.CheckSnapshot("mysdk", "",
+ checkAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_sdk_library_import {
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
+ apex_available: ["//apex_available:anyapex"],
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "current",
+ },
+ system: {
+ jars: ["sdk_library/system/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
+ current_api: "sdk_library/system/myjavalib.txt",
+ removed_api: "sdk_library/system/myjavalib-removed.txt",
+ sdk_version: "system_current",
+ },
+ module_lib: {
+ jars: ["sdk_library/module_lib/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/module_lib/myjavalib_stub_sources"],
+ current_api: "sdk_library/module_lib/myjavalib.txt",
+ removed_api: "sdk_library/module_lib/myjavalib-removed.txt",
+ sdk_version: "module_current",
+ },
+}
+
+java_sdk_library_import {
+ name: "myjavalib",
+ prefer: false,
+ apex_available: ["//apex_available:anyapex"],
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "current",
+ },
+ system: {
+ jars: ["sdk_library/system/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
+ current_api: "sdk_library/system/myjavalib.txt",
+ removed_api: "sdk_library/system/myjavalib-removed.txt",
+ sdk_version: "system_current",
+ },
+ module_lib: {
+ jars: ["sdk_library/module_lib/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/module_lib/myjavalib_stub_sources"],
+ current_api: "sdk_library/module_lib/myjavalib.txt",
+ removed_api: "sdk_library/module_lib/myjavalib-removed.txt",
+ sdk_version: "module_current",
+ },
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ java_sdk_libs: ["mysdk_myjavalib@current"],
+}
+`),
+ checkAllCopyRules(`
+.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
+.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib-removed.txt
+.intermediates/myjavalib.stubs.system/android_common/javac/myjavalib.stubs.system.jar -> sdk_library/system/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source.system/android_common/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt
+.intermediates/myjavalib.stubs.source.system/android_common/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib-removed.txt
+.intermediates/myjavalib.stubs.module_lib/android_common/javac/myjavalib.stubs.module_lib.jar -> sdk_library/module_lib/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source.module_lib/android_common/myjavalib.stubs.source.module_lib_api.txt -> sdk_library/module_lib/myjavalib.txt
+.intermediates/myjavalib.stubs.source.module_lib/android_common/myjavalib.stubs.source.module_lib_api.txt -> sdk_library/module_lib/myjavalib-removed.txt
+`),
+ checkMergeZips(
+ ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
+ ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip",
+ ".intermediates/mysdk/common_os/tmp/sdk_library/module_lib/myjavalib_stub_sources.zip",
+ ),
+ )
+}
diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go
index 0bcdccb..e1123e0 100644
--- a/ui/build/cleanbuild.go
+++ b/ui/build/cleanbuild.go
@@ -104,6 +104,7 @@
productOut("*.img"),
productOut("*.zip"),
productOut("android-info.txt"),
+ productOut("misc_info.txt"),
productOut("apex"),
productOut("kernel"),
productOut("data"),