1// Copyright 2024 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package codegen 16 17import ( 18 "testing" 19 20 "android/soong/android" 21 "android/soong/java" 22) 23 24func TestAconfigDeclarationsGroup(t *testing.T) { 25 result := android.GroupFixturePreparers( 26 PrepareForTestWithAconfigBuildComponents, 27 java.PrepareForTestWithJavaDefaultModules, 28 ).RunTestWithBp(t, ` 29 aconfig_declarations { 30 name: "foo-aconfig", 31 package: "com.example.package", 32 container: "com.android.foo", 33 srcs: ["foo.aconfig"], 34 } 35 36 java_aconfig_library { 37 name: "foo-java", 38 aconfig_declarations: "foo-aconfig", 39 } 40 41 aconfig_declarations { 42 name: "bar-aconfig", 43 package: "com.example.package", 44 container: "com.android.foo", 45 srcs: ["foo.aconfig"], 46 } 47 48 java_aconfig_library { 49 name: "bar-java", 50 aconfig_declarations: "bar-aconfig", 51 } 52 53 aconfig_declarations_group { 54 name: "my_group", 55 java_aconfig_libraries: [ 56 "foo-java", 57 "bar-java", 58 ], 59 } 60 61 java_library { 62 name: "baz", 63 srcs: [ 64 ":my_group{.srcjars}", 65 ], 66 } 67 `) 68 69 // Check if aconfig_declarations_group module depends on the aconfig_library modules 70 java.CheckModuleDependencies(t, result.TestContext, "my_group", "android_common", []string{ 71 `bar-java`, 72 `foo-java`, 73 }) 74 75 // Check if srcjar files are correctly passed to the reverse dependency of 76 // aconfig_declarations_group module 77 bazModule := result.ModuleForTests("baz", "android_common") 78 bazJavacSrcjars := bazModule.Rule("javac").Args["srcJars"] 79 errorMessage := "baz javac argument expected to contain srcjar provided by aconfig_declrations_group" 80 android.AssertStringDoesContain(t, errorMessage, bazJavacSrcjars, "foo-java.srcjar") 81 android.AssertStringDoesContain(t, errorMessage, bazJavacSrcjars, "bar-java.srcjar") 82} 83