1/* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package apex 18 19import ( 20 "strings" 21 "testing" 22 23 "android/soong/android" 24 "android/soong/java" 25) 26 27func TestModulesSingleton(t *testing.T) { 28 result := android.GroupFixturePreparers( 29 PrepareForTestWithApexMultitreeSingleton, 30 java.PrepareForTestWithJavaDefaultModules, 31 PrepareForTestWithApexBuildComponents, 32 java.FixtureConfigureApexBootJars("myapex:foo"), 33 java.PrepareForTestWithJavaSdkLibraryFiles, 34 ).RunTestWithBp(t, ` 35 prebuilt_apex { 36 name: "myapex", 37 src: "myapex.apex", 38 exported_bootclasspath_fragments: ["mybootclasspath-fragment"], 39 } 40 41 // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred 42 // because AlwaysUsePrebuiltSdks() is true. 43 java_sdk_library_import { 44 name: "foo", 45 prefer: false, 46 shared_library: false, 47 permitted_packages: ["foo"], 48 public: { 49 jars: ["sdk_library/public/foo-stubs.jar"], 50 stub_srcs: ["sdk_library/public/foo_stub_sources"], 51 current_api: "sdk_library/public/foo.txt", 52 removed_api: "sdk_library/public/foo-removed.txt", 53 sdk_version: "current", 54 }, 55 apex_available: ["myapex"], 56 } 57 58 prebuilt_bootclasspath_fragment { 59 name: "mybootclasspath-fragment", 60 apex_available: [ 61 "myapex", 62 ], 63 contents: [ 64 "foo", 65 ], 66 hidden_api: { 67 stub_flags: "prebuilt-stub-flags.csv", 68 annotation_flags: "prebuilt-annotation-flags.csv", 69 metadata: "prebuilt-metadata.csv", 70 index: "prebuilt-index.csv", 71 all_flags: "prebuilt-all-flags.csv", 72 }, 73 } 74 75 platform_bootclasspath { 76 name: "myplatform-bootclasspath", 77 fragments: [ 78 { 79 apex: "myapex", 80 module:"mybootclasspath-fragment", 81 }, 82 ], 83 } 84`, 85 ) 86 87 outputs := result.SingletonForTests("apex_multitree_singleton").AllOutputs() 88 for _, output := range outputs { 89 testingBuildParam := result.SingletonForTests("apex_multitree_singleton").Output(output) 90 switch { 91 case strings.Contains(output, "soong/multitree_apex_metadata.json"): 92 android.AssertStringEquals(t, "Invalid build rule", "android/soong/android.writeFile", testingBuildParam.Rule.String()) 93 android.AssertIntEquals(t, "Invalid input", len(testingBuildParam.Inputs), 0) 94 android.AssertStringDoesContain(t, "Invalid output path", output, "soong/multitree_apex_metadata.json") 95 96 case strings.HasSuffix(output, "multitree_apex_metadata"): 97 android.AssertStringEquals(t, "Invalid build rule", "<builtin>:phony", testingBuildParam.Rule.String()) 98 android.AssertStringEquals(t, "Invalid input", testingBuildParam.Inputs[0].String(), "out/soong/multitree_apex_metadata.json") 99 android.AssertStringEquals(t, "Invalid output path", output, "multitree_apex_metadata") 100 android.AssertIntEquals(t, "Invalid args", len(testingBuildParam.Args), 0) 101 } 102 } 103} 104