Loading android/sdk.go +4 −0 Original line number Diff line number Diff line Loading @@ -946,6 +946,10 @@ type SdkMemberContext interface { // RequiresTrait returns true if this member is expected to provide the specified trait. RequiresTrait(trait SdkMemberTrait) bool // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is // being generated is before Tiramisu, i.e. S. IsTargetBuildBeforeTiramisu() bool } // ExportedComponentsInfo contains information about the components that this module exports to an Loading java/java.go +24 −6 Original line number Diff line number Diff line Loading @@ -118,6 +118,16 @@ var ( copyEverythingToSnapshot, } snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool { // In the S build the build will break if updatable-media does not provide a full implementation // jar. That issue was fixed in Tiramisu by b/229932396. if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" { return true } return false } // Supports adding java boot libraries to module_exports and sdk. // // The build has some implicit dependencies (via the boot jars configuration) on a number of Loading @@ -135,13 +145,21 @@ var ( SupportsSdk: true, }, func(ctx android.SdkMemberContext, j *Library) android.Path { if snapshotRequiresImplementationJar(ctx) { return exportImplementationClassesJar(ctx, j) } // Java boot libs are only provided in the SDK to provide access to their dex implementation // jar for use by dexpreopting and boot jars package check. They do not need to provide an // actual implementation jar but the java_import will need a file that exists so just copy an // empty file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, func(osPrefix, name string) string { func(ctx android.SdkMemberContext, osPrefix, name string) string { if snapshotRequiresImplementationJar(ctx) { return sdkSnapshotFilePathForJar(ctx, osPrefix, name) } // Create a special name for the implementation jar to try and provide some useful information // to a developer that attempts to compile against this. // TODO(b/175714559): Provide a proper error message in Soong not ninja. Loading Loading @@ -175,7 +193,7 @@ var ( // file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, func(osPrefix, name string) string { func(_ android.SdkMemberContext, osPrefix, name string) string { // Create a special name for the implementation jar to try and provide some useful information // to a developer that attempts to compile against this. // TODO(b/175714559): Provide a proper error message in Soong not ninja. Loading Loading @@ -649,7 +667,7 @@ const ( ) // path to the jar file of a java library. Relative to <sdk_root>/<api_dir> func sdkSnapshotFilePathForJar(osPrefix, name string) string { func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string { return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) } Loading @@ -666,7 +684,7 @@ type librarySdkMemberType struct { // Function to compute the snapshot relative path to which the named library's // jar should be copied. snapshotPathGetter func(osPrefix, name string) string snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string // True if only the jar should be copied to the snapshot, false if the jar plus any additional // files like aidl files should also be copied. Loading Loading @@ -724,7 +742,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte exportedJar := p.JarToExport if exportedJar != nil { // Delegate the creation of the snapshot relative path to the member type. snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name()) snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name()) // Copy the exported jar to the snapshot. builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) Loading Loading @@ -1190,7 +1208,7 @@ func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, exportedJar := p.JarToExport if exportedJar != nil { snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name()) snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) Loading sdk/build_release.go +8 −4 Original line number Diff line number Diff line Loading @@ -24,18 +24,22 @@ import ( // buildRelease represents the version of a build system used to create a specific release. // // The name of the release, is the same as the code for the dessert release, e.g. S, T, etc. // The name of the release, is the same as the code for the dessert release, e.g. S, Tiramisu, etc. type buildRelease struct { // The name of the release, e.g. S, T, etc. // The name of the release, e.g. S, Tiramisu, etc. name string // The index of this structure within the buildReleases list. ordinal int } func (br *buildRelease) EarlierThan(other *buildRelease) bool { return br.ordinal < other.ordinal } // String returns the name of the build release. func (s *buildRelease) String() string { return s.name func (br *buildRelease) String() string { return br.name } // buildReleaseSet represents a set of buildRelease objects. Loading sdk/java_sdk_test.go +63 −8 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ package sdk import ( "fmt" "testing" "android/soong/android" Loading Loading @@ -339,8 +340,8 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { android.FixtureAddFile("aidl", nil), android.FixtureAddFile("resource.txt", nil), ).RunTestWithBp(t, ` module_exports { name: "myexports", sdk { name: "mysdk", java_boot_libs: ["myjavalib"], } Loading @@ -360,7 +361,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { } `) CheckSnapshot(t, result, "myexports", "", CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. Loading @@ -377,7 +378,7 @@ java_import { // This is auto-generated. DO NOT EDIT. java_import { name: "myexports_myjavalib@current", name: "mysdk_myjavalib@current", sdk_member_name: "myjavalib", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], Loading @@ -385,19 +386,73 @@ java_import { permitted_packages: ["pkg.myjavalib"], } module_exports_snapshot { name: "myexports@current", sdk_snapshot { name: "mysdk@current", visibility: ["//visibility:public"], java_boot_libs: ["myexports_myjavalib@current"], java_boot_libs: ["mysdk_myjavalib@current"], } `), checkAllCopyRules(` .intermediates/myexports/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar `), ) } func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) { runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, android.FixtureMergeEnv(map[string]string{ "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, }), ).RunTestWithBp(t, ` sdk { name: "mysdk", java_boot_libs: ["updatable-media"], } java_library { name: "updatable-media", srcs: ["Test.java"], system_modules: "none", sdk_version: "none", compile_dex: true, permitted_packages: ["pkg.media"], apex_available: ["com.android.media"], } `) CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(fmt.Sprintf(` // This is auto-generated. DO NOT EDIT. java_import { name: "updatable-media", prefer: false, visibility: ["//visibility:public"], apex_available: ["com.android.media"], jars: ["%s"], permitted_packages: ["pkg.media"], } `, expectedJarPath)), checkAllCopyRules(expectedCopyRule), ) } t.Run("updatable-media in S", func(t *testing.T) { runTest(t, "S", "java/updatable-media.jar", ` .intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar `) }) t.Run("updatable-media in T", func(t *testing.T) { runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", ` .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar `) }) } func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, Loading sdk/update.go +6 −0 Original line number Diff line number Diff line Loading @@ -1931,6 +1931,12 @@ func (m *memberContext) RequiresTrait(trait android.SdkMemberTrait) bool { return m.requiredTraits.Contains(trait) } func (m *memberContext) IsTargetBuildBeforeTiramisu() bool { return m.builder.targetBuildRelease.EarlierThan(buildReleaseT) } var _ android.SdkMemberContext = (*memberContext)(nil) func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) { memberType := member.memberType Loading Loading
android/sdk.go +4 −0 Original line number Diff line number Diff line Loading @@ -946,6 +946,10 @@ type SdkMemberContext interface { // RequiresTrait returns true if this member is expected to provide the specified trait. RequiresTrait(trait SdkMemberTrait) bool // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is // being generated is before Tiramisu, i.e. S. IsTargetBuildBeforeTiramisu() bool } // ExportedComponentsInfo contains information about the components that this module exports to an Loading
java/java.go +24 −6 Original line number Diff line number Diff line Loading @@ -118,6 +118,16 @@ var ( copyEverythingToSnapshot, } snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool { // In the S build the build will break if updatable-media does not provide a full implementation // jar. That issue was fixed in Tiramisu by b/229932396. if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" { return true } return false } // Supports adding java boot libraries to module_exports and sdk. // // The build has some implicit dependencies (via the boot jars configuration) on a number of Loading @@ -135,13 +145,21 @@ var ( SupportsSdk: true, }, func(ctx android.SdkMemberContext, j *Library) android.Path { if snapshotRequiresImplementationJar(ctx) { return exportImplementationClassesJar(ctx, j) } // Java boot libs are only provided in the SDK to provide access to their dex implementation // jar for use by dexpreopting and boot jars package check. They do not need to provide an // actual implementation jar but the java_import will need a file that exists so just copy an // empty file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, func(osPrefix, name string) string { func(ctx android.SdkMemberContext, osPrefix, name string) string { if snapshotRequiresImplementationJar(ctx) { return sdkSnapshotFilePathForJar(ctx, osPrefix, name) } // Create a special name for the implementation jar to try and provide some useful information // to a developer that attempts to compile against this. // TODO(b/175714559): Provide a proper error message in Soong not ninja. Loading Loading @@ -175,7 +193,7 @@ var ( // file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, func(osPrefix, name string) string { func(_ android.SdkMemberContext, osPrefix, name string) string { // Create a special name for the implementation jar to try and provide some useful information // to a developer that attempts to compile against this. // TODO(b/175714559): Provide a proper error message in Soong not ninja. Loading Loading @@ -649,7 +667,7 @@ const ( ) // path to the jar file of a java library. Relative to <sdk_root>/<api_dir> func sdkSnapshotFilePathForJar(osPrefix, name string) string { func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string { return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) } Loading @@ -666,7 +684,7 @@ type librarySdkMemberType struct { // Function to compute the snapshot relative path to which the named library's // jar should be copied. snapshotPathGetter func(osPrefix, name string) string snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string // True if only the jar should be copied to the snapshot, false if the jar plus any additional // files like aidl files should also be copied. Loading Loading @@ -724,7 +742,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte exportedJar := p.JarToExport if exportedJar != nil { // Delegate the creation of the snapshot relative path to the member type. snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name()) snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name()) // Copy the exported jar to the snapshot. builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) Loading Loading @@ -1190,7 +1208,7 @@ func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, exportedJar := p.JarToExport if exportedJar != nil { snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name()) snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) Loading
sdk/build_release.go +8 −4 Original line number Diff line number Diff line Loading @@ -24,18 +24,22 @@ import ( // buildRelease represents the version of a build system used to create a specific release. // // The name of the release, is the same as the code for the dessert release, e.g. S, T, etc. // The name of the release, is the same as the code for the dessert release, e.g. S, Tiramisu, etc. type buildRelease struct { // The name of the release, e.g. S, T, etc. // The name of the release, e.g. S, Tiramisu, etc. name string // The index of this structure within the buildReleases list. ordinal int } func (br *buildRelease) EarlierThan(other *buildRelease) bool { return br.ordinal < other.ordinal } // String returns the name of the build release. func (s *buildRelease) String() string { return s.name func (br *buildRelease) String() string { return br.name } // buildReleaseSet represents a set of buildRelease objects. Loading
sdk/java_sdk_test.go +63 −8 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ package sdk import ( "fmt" "testing" "android/soong/android" Loading Loading @@ -339,8 +340,8 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { android.FixtureAddFile("aidl", nil), android.FixtureAddFile("resource.txt", nil), ).RunTestWithBp(t, ` module_exports { name: "myexports", sdk { name: "mysdk", java_boot_libs: ["myjavalib"], } Loading @@ -360,7 +361,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { } `) CheckSnapshot(t, result, "myexports", "", CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. Loading @@ -377,7 +378,7 @@ java_import { // This is auto-generated. DO NOT EDIT. java_import { name: "myexports_myjavalib@current", name: "mysdk_myjavalib@current", sdk_member_name: "myjavalib", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], Loading @@ -385,19 +386,73 @@ java_import { permitted_packages: ["pkg.myjavalib"], } module_exports_snapshot { name: "myexports@current", sdk_snapshot { name: "mysdk@current", visibility: ["//visibility:public"], java_boot_libs: ["myexports_myjavalib@current"], java_boot_libs: ["mysdk_myjavalib@current"], } `), checkAllCopyRules(` .intermediates/myexports/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar `), ) } func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) { runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, android.FixtureMergeEnv(map[string]string{ "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, }), ).RunTestWithBp(t, ` sdk { name: "mysdk", java_boot_libs: ["updatable-media"], } java_library { name: "updatable-media", srcs: ["Test.java"], system_modules: "none", sdk_version: "none", compile_dex: true, permitted_packages: ["pkg.media"], apex_available: ["com.android.media"], } `) CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(fmt.Sprintf(` // This is auto-generated. DO NOT EDIT. java_import { name: "updatable-media", prefer: false, visibility: ["//visibility:public"], apex_available: ["com.android.media"], jars: ["%s"], permitted_packages: ["pkg.media"], } `, expectedJarPath)), checkAllCopyRules(expectedCopyRule), ) } t.Run("updatable-media in S", func(t *testing.T) { runTest(t, "S", "java/updatable-media.jar", ` .intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar `) }) t.Run("updatable-media in T", func(t *testing.T) { runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", ` .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar `) }) } func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, Loading
sdk/update.go +6 −0 Original line number Diff line number Diff line Loading @@ -1931,6 +1931,12 @@ func (m *memberContext) RequiresTrait(trait android.SdkMemberTrait) bool { return m.requiredTraits.Contains(trait) } func (m *memberContext) IsTargetBuildBeforeTiramisu() bool { return m.builder.targetBuildRelease.EarlierThan(buildReleaseT) } var _ android.SdkMemberContext = (*memberContext)(nil) func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) { memberType := member.memberType Loading