blob: c69d21ffdf8726057697a524c42dc0b75122b04c [file] [log] [blame]
Jihoon Kang2a43e562024-02-12 19:05:12 +00001// 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 (
Yu Liu315a53c2024-04-24 16:41:57 +000018 "testing"
19
Jihoon Kang2a43e562024-02-12 19:05:12 +000020 "android/soong/android"
21 "android/soong/java"
Jihoon Kang2a43e562024-02-12 19:05:12 +000022)
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",
Yu Liu315a53c2024-04-24 16:41:57 +000032 container: "com.android.foo",
Jihoon Kang2a43e562024-02-12 19:05:12 +000033 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",
Yu Liu315a53c2024-04-24 16:41:57 +000044 container: "com.android.foo",
Jihoon Kang2a43e562024-02-12 19:05:12 +000045 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", "", []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}