4e7d1c43e2
Specifying an apex in the apexes propety will cause all the *classpath_fragments that are contents of the APEX to be automatically added as members of the sdk and appear in the snapshot. The purpose of this change is to dedup the APEX and sdk definitions and try and avoid some of the issues that we have been finding while attempting to build against the prebuilts. Two tests, one each for bootclasspath_fragment and systemserverclasspath_fragment, have been refactored to compare the output when adding the *fragment to the sdk directly of via the APEX. That ensures switching to use the APEX will not change the sdk snapshot unless it was previously missing a *fragment. There was also a slight difference in where the hidden API flags were copied from. That should have no impact on the output as the flags are identical. The sdk snapshot generation needed some tweaks to avoid generating a prebuilt for the APEX. Bug: 232401814 Test: m nothing Change-Id: I7aaf16a3a0ab4bebf97765d1484215cc008dc4b8
212 lines
5.8 KiB
Go
212 lines
5.8 KiB
Go
// Copyright (C) 2021 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 sdk
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"android/soong/android"
|
|
"android/soong/dexpreopt"
|
|
"android/soong/java"
|
|
)
|
|
|
|
func testSnapshotWithSystemServerClasspathFragment(t *testing.T, sdk string, targetBuildRelease string, expectedSdkSnapshot string) {
|
|
result := android.GroupFixturePreparers(
|
|
prepareForSdkTestWithJava,
|
|
java.PrepareForTestWithJavaDefaultModules,
|
|
java.PrepareForTestWithJavaSdkLibraryFiles,
|
|
java.FixtureWithLastReleaseApis("mysdklibrary"),
|
|
dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"),
|
|
android.FixtureModifyEnv(func(env map[string]string) {
|
|
if targetBuildRelease != "latest" {
|
|
env["SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE"] = targetBuildRelease
|
|
}
|
|
}),
|
|
prepareForSdkTestWithApex,
|
|
|
|
android.FixtureWithRootAndroidBp(sdk+`
|
|
apex {
|
|
name: "myapex",
|
|
key: "myapex.key",
|
|
min_sdk_version: "2",
|
|
systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
|
|
}
|
|
|
|
systemserverclasspath_fragment {
|
|
name: "mysystemserverclasspathfragment",
|
|
apex_available: ["myapex"],
|
|
contents: [
|
|
"mylib",
|
|
"mysdklibrary",
|
|
],
|
|
}
|
|
|
|
java_library {
|
|
name: "mylib",
|
|
apex_available: ["myapex"],
|
|
srcs: ["Test.java"],
|
|
system_modules: "none",
|
|
sdk_version: "none",
|
|
min_sdk_version: "2",
|
|
compile_dex: true,
|
|
permitted_packages: ["mylib"],
|
|
}
|
|
|
|
java_sdk_library {
|
|
name: "mysdklibrary",
|
|
apex_available: ["myapex"],
|
|
srcs: ["Test.java"],
|
|
shared_library: false,
|
|
public: {enabled: true},
|
|
min_sdk_version: "2",
|
|
}
|
|
`),
|
|
).RunTest(t)
|
|
|
|
CheckSnapshot(t, result, "mysdk", "",
|
|
checkAndroidBpContents(expectedSdkSnapshot),
|
|
)
|
|
}
|
|
|
|
func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
|
|
|
|
commonSdk := `
|
|
sdk {
|
|
name: "mysdk",
|
|
systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
|
|
java_sdk_libs: [
|
|
// This is not strictly needed as it should be automatically added to the sdk_snapshot as
|
|
// a java_sdk_libs module because it is used in the mysystemserverclasspathfragment's
|
|
// contents property. However, it is specified here to ensure that duplicates are
|
|
// correctly deduped.
|
|
"mysdklibrary",
|
|
],
|
|
}
|
|
`
|
|
|
|
expectedLatestSnapshot := `
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
java_sdk_library_import {
|
|
name: "mysdklibrary",
|
|
prefer: false,
|
|
visibility: ["//visibility:public"],
|
|
apex_available: ["myapex"],
|
|
shared_library: false,
|
|
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_import {
|
|
name: "mylib",
|
|
prefer: false,
|
|
visibility: ["//visibility:public"],
|
|
apex_available: ["myapex"],
|
|
jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
|
|
permitted_packages: ["mylib"],
|
|
}
|
|
|
|
prebuilt_systemserverclasspath_fragment {
|
|
name: "mysystemserverclasspathfragment",
|
|
prefer: false,
|
|
visibility: ["//visibility:public"],
|
|
apex_available: ["myapex"],
|
|
contents: [
|
|
"mylib",
|
|
"mysdklibrary",
|
|
],
|
|
}
|
|
`
|
|
|
|
t.Run("target-s", func(t *testing.T) {
|
|
testSnapshotWithSystemServerClasspathFragment(t, commonSdk, "S", `
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
java_sdk_library_import {
|
|
name: "mysdklibrary",
|
|
prefer: false,
|
|
visibility: ["//visibility:public"],
|
|
apex_available: ["myapex"],
|
|
shared_library: false,
|
|
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",
|
|
},
|
|
}
|
|
`)
|
|
})
|
|
|
|
t.Run("target-t", func(t *testing.T) {
|
|
testSnapshotWithSystemServerClasspathFragment(t, commonSdk, "Tiramisu", `
|
|
// This is auto-generated. DO NOT EDIT.
|
|
|
|
java_sdk_library_import {
|
|
name: "mysdklibrary",
|
|
prefer: false,
|
|
visibility: ["//visibility:public"],
|
|
apex_available: ["myapex"],
|
|
shared_library: false,
|
|
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_import {
|
|
name: "mylib",
|
|
prefer: false,
|
|
visibility: ["//visibility:public"],
|
|
apex_available: ["myapex"],
|
|
jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
|
|
permitted_packages: ["mylib"],
|
|
}
|
|
|
|
prebuilt_systemserverclasspath_fragment {
|
|
name: "mysystemserverclasspathfragment",
|
|
prefer: false,
|
|
visibility: ["//visibility:public"],
|
|
apex_available: ["myapex"],
|
|
contents: [
|
|
"mylib",
|
|
"mysdklibrary",
|
|
],
|
|
}
|
|
`)
|
|
})
|
|
|
|
t.Run("added-directly", func(t *testing.T) {
|
|
testSnapshotWithSystemServerClasspathFragment(t, commonSdk, `latest`, expectedLatestSnapshot)
|
|
})
|
|
|
|
t.Run("added-via-apex", func(t *testing.T) {
|
|
testSnapshotWithSystemServerClasspathFragment(t, `
|
|
sdk {
|
|
name: "mysdk",
|
|
apexes: ["myapex"],
|
|
}
|
|
`, `latest`, expectedLatestSnapshot)
|
|
})
|
|
}
|