Merge "Add stub_libs properties to bootclasspath_fragment snapshot"

This commit is contained in:
Paul Duffin
2021-04-29 09:34:38 +00:00
committed by Gerrit Code Review
3 changed files with 165 additions and 8 deletions

View File

@@ -433,6 +433,10 @@ type bootclasspathFragmentSdkMemberProperties struct {
// Contents of the bootclasspath fragment // Contents of the bootclasspath fragment
Contents []string Contents []string
// Stub_libs properties.
Stub_libs []string
Core_platform_stub_libs []string
// Flag files by *hiddenAPIFlagFileCategory // Flag files by *hiddenAPIFlagFileCategory
Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths
} }
@@ -447,6 +451,10 @@ func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx andro
mctx := ctx.SdkModuleContext() mctx := ctx.SdkModuleContext()
flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo) flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
b.Flag_files_by_category = flagFileInfo.categoryToPaths b.Flag_files_by_category = flagFileInfo.categoryToPaths
// Copy stub_libs properties.
b.Stub_libs = module.properties.Api.Stub_libs
b.Core_platform_stub_libs = module.properties.Core_platform_api.Stub_libs
} }
func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
@@ -454,11 +462,22 @@ func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.
propertySet.AddProperty("image_name", *b.Image_name) propertySet.AddProperty("image_name", *b.Image_name)
} }
builder := ctx.SnapshotBuilder()
requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
if len(b.Contents) > 0 { if len(b.Contents) > 0 {
propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true)) propertySet.AddPropertyWithTag("contents", b.Contents, requiredMemberDependency)
}
if len(b.Stub_libs) > 0 {
apiPropertySet := propertySet.AddPropertySet("api")
apiPropertySet.AddPropertyWithTag("stub_libs", b.Stub_libs, requiredMemberDependency)
}
if len(b.Core_platform_stub_libs) > 0 {
corePlatformApiPropertySet := propertySet.AddPropertySet("core_platform_api")
corePlatformApiPropertySet.AddPropertyWithTag("stub_libs", b.Core_platform_stub_libs, requiredMemberDependency)
} }
builder := ctx.SnapshotBuilder()
if b.Flag_files_by_category != nil { if b.Flag_files_by_category != nil {
hiddenAPISet := propertySet.AddPropertySet("hidden_api") hiddenAPISet := propertySet.AddPropertySet("hidden_api")
for _, category := range hiddenAPIFlagFileCategories { for _, category := range hiddenAPIFlagFileCategories {

View File

@@ -125,10 +125,20 @@ func TestBootclasspathFragment_Coverage(t *testing.T) {
contents: [ contents: [
"mybootlib", "mybootlib",
], ],
api: {
stub_libs: [
"mysdklibrary",
],
},
coverage: { coverage: {
contents: [ contents: [
"coveragelib", "coveragelib",
], ],
api: {
stub_libs: [
"mycoveragestubs",
],
},
}, },
} }
@@ -147,6 +157,21 @@ func TestBootclasspathFragment_Coverage(t *testing.T) {
sdk_version: "none", sdk_version: "none",
compile_dex: true, compile_dex: true,
} }
java_sdk_library {
name: "mysdklibrary",
srcs: ["Test.java"],
compile_dex: true,
public: {enabled: true},
system: {enabled: true},
}
java_sdk_library {
name: "mycoveragestubs",
srcs: ["Test.java"],
compile_dex: true,
public: {enabled: true},
}
`) `)
checkContents := func(t *testing.T, result *android.TestResult, expected ...string) { checkContents := func(t *testing.T, result *android.TestResult, expected ...string) {
@@ -154,19 +179,22 @@ func TestBootclasspathFragment_Coverage(t *testing.T) {
android.AssertArrayString(t, "contents property", expected, module.properties.Contents) android.AssertArrayString(t, "contents property", expected, module.properties.Contents)
} }
preparer := android.GroupFixturePreparers(
prepareForTestWithBootclasspathFragment,
PrepareForTestWithJavaSdkLibraryFiles,
FixtureWithLastReleaseApis("mysdklibrary", "mycoveragestubs"),
prepareWithBp,
)
t.Run("without coverage", func(t *testing.T) { t.Run("without coverage", func(t *testing.T) {
result := android.GroupFixturePreparers( result := preparer.RunTest(t)
prepareForTestWithBootclasspathFragment,
prepareWithBp,
).RunTest(t)
checkContents(t, result, "mybootlib") checkContents(t, result, "mybootlib")
}) })
t.Run("with coverage", func(t *testing.T) { t.Run("with coverage", func(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
prepareForTestWithBootclasspathFragment,
prepareForTestWithFrameworkCoverage, prepareForTestWithFrameworkCoverage,
prepareWithBp, preparer,
).RunTest(t) ).RunTest(t)
checkContents(t, result, "mybootlib", "coveragelib") checkContents(t, result, "mybootlib", "coveragelib")
}) })

View File

@@ -165,15 +165,25 @@ sdk_snapshot {
func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
prepareForSdkTestWithJava, prepareForSdkTestWithJava,
java.PrepareForTestWithJavaDefaultModules,
java.PrepareForTestWithJavaSdkLibraryFiles,
java.FixtureWithLastReleaseApis("mysdklibrary", "mycoreplatform"),
android.FixtureWithRootAndroidBp(` android.FixtureWithRootAndroidBp(`
sdk { sdk {
name: "mysdk", name: "mysdk",
bootclasspath_fragments: ["mybootclasspathfragment"], bootclasspath_fragments: ["mybootclasspathfragment"],
java_sdk_libs: ["mysdklibrary", "mycoreplatform"],
} }
bootclasspath_fragment { bootclasspath_fragment {
name: "mybootclasspathfragment", name: "mybootclasspathfragment",
contents: ["mybootlib"], contents: ["mybootlib"],
api: {
stub_libs: ["mysdklibrary"],
},
core_platform_api: {
stub_libs: ["mycoreplatform"],
},
} }
java_library { java_library {
@@ -183,6 +193,20 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
sdk_version: "none", sdk_version: "none",
compile_dex: true, compile_dex: true,
} }
java_sdk_library {
name: "mysdklibrary",
srcs: ["Test.java"],
compile_dex: true,
public: {enabled: true},
}
java_sdk_library {
name: "mycoreplatform",
srcs: ["Test.java"],
compile_dex: true,
public: {enabled: true},
}
`), `),
).RunTest(t) ).RunTest(t)
@@ -196,6 +220,12 @@ prebuilt_bootclasspath_fragment {
visibility: ["//visibility:public"], visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"], apex_available: ["//apex_available:platform"],
contents: ["mybootlib"], contents: ["mybootlib"],
api: {
stub_libs: ["mysdklibrary"],
},
core_platform_api: {
stub_libs: ["mycoreplatform"],
},
} }
java_import { java_import {
@@ -205,6 +235,38 @@ java_import {
apex_available: ["//apex_available:platform"], apex_available: ["//apex_available:platform"],
jars: ["java/mybootlib.jar"], jars: ["java/mybootlib.jar"],
} }
java_sdk_library_import {
name: "mysdklibrary",
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
compile_dex: true,
public: {
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
current_api: "sdk_library/public/mysdklibrary.txt",
removed_api: "sdk_library/public/mysdklibrary-removed.txt",
sdk_version: "current",
},
}
java_sdk_library_import {
name: "mycoreplatform",
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
compile_dex: true,
public: {
jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
current_api: "sdk_library/public/mycoreplatform.txt",
removed_api: "sdk_library/public/mycoreplatform-removed.txt",
sdk_version: "current",
},
}
`), `),
checkVersionedAndroidBpContents(` checkVersionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT. // This is auto-generated. DO NOT EDIT.
@@ -215,6 +277,12 @@ prebuilt_bootclasspath_fragment {
visibility: ["//visibility:public"], visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"], apex_available: ["//apex_available:platform"],
contents: ["mysdk_mybootlib@current"], contents: ["mysdk_mybootlib@current"],
api: {
stub_libs: ["mysdk_mysdklibrary@current"],
},
core_platform_api: {
stub_libs: ["mysdk_mycoreplatform@current"],
},
} }
java_import { java_import {
@@ -225,15 +293,57 @@ java_import {
jars: ["java/mybootlib.jar"], jars: ["java/mybootlib.jar"],
} }
java_sdk_library_import {
name: "mysdk_mysdklibrary@current",
sdk_member_name: "mysdklibrary",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
compile_dex: true,
public: {
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
current_api: "sdk_library/public/mysdklibrary.txt",
removed_api: "sdk_library/public/mysdklibrary-removed.txt",
sdk_version: "current",
},
}
java_sdk_library_import {
name: "mysdk_mycoreplatform@current",
sdk_member_name: "mycoreplatform",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
shared_library: true,
compile_dex: true,
public: {
jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
current_api: "sdk_library/public/mycoreplatform.txt",
removed_api: "sdk_library/public/mycoreplatform-removed.txt",
sdk_version: "current",
},
}
sdk_snapshot { sdk_snapshot {
name: "mysdk@current", name: "mysdk@current",
visibility: ["//visibility:public"], visibility: ["//visibility:public"],
bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"],
java_boot_libs: ["mysdk_mybootlib@current"], java_boot_libs: ["mysdk_mybootlib@current"],
java_sdk_libs: [
"mysdk_mysdklibrary@current",
"mysdk_mycoreplatform@current",
],
} }
`), `),
checkAllCopyRules(` checkAllCopyRules(`
.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
.intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar
.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt
.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt
`)) `))
} }