blob: b6095b2efd19f858f04e9d8ef94e663b7e160e24 [file] [log] [blame]
Romain Jobredeaux1282c422021-10-29 10:52:59 -04001// Copyright 2021 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 bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/java"
20
21 "testing"
22)
23
24func runAndroidAppTestCase(t *testing.T, tc bp2buildTestCase) {
25 t.Helper()
26 runBp2BuildTestCase(t, registerAndroidAppModuleTypes, tc)
27}
28
29func registerAndroidAppModuleTypes(ctx android.RegistrationContext) {
30}
31
32func TestMinimalAndroidApp(t *testing.T) {
33 runAndroidAppTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -040034 description: "Android app - simple example",
35 moduleTypeUnderTest: "android_app",
36 moduleTypeUnderTestFactory: java.AndroidAppFactory,
Romain Jobredeaux1282c422021-10-29 10:52:59 -040037 filesystem: map[string]string{
38 "app.java": "",
39 "res/res.png": "",
40 "AndroidManifest.xml": "",
41 },
42 blueprint: `
43android_app {
44 name: "TestApp",
45 srcs: ["app.java"],
46 sdk_version: "current",
47}
48`,
49 expectedBazelTargets: []string{
50 makeBazelTarget("android_binary", "TestApp", attrNameToString{
51 "srcs": `["app.java"]`,
52 "manifest": `"AndroidManifest.xml"`,
53 "resource_files": `["res/res.png"]`,
Sam Delmerico881d7202022-02-23 15:18:56 +000054 "deps": `["//prebuilts/sdk:public_current_android_sdk_java_import"]`,
Romain Jobredeaux1282c422021-10-29 10:52:59 -040055 }),
56 }})
57}
58
59func TestAndroidAppAllSupportedFields(t *testing.T) {
60 runAndroidAppTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -040061 description: "Android app - all supported fields",
62 moduleTypeUnderTest: "android_app",
63 moduleTypeUnderTestFactory: java.AndroidAppFactory,
Romain Jobredeaux1282c422021-10-29 10:52:59 -040064 filesystem: map[string]string{
65 "app.java": "",
66 "resa/res.png": "",
67 "resb/res.png": "",
68 "manifest/AndroidManifest.xml": "",
69 },
Romain Jobredeaux355851b2022-01-13 17:07:01 +000070 blueprint: simpleModuleDoNotConvertBp2build("android_app", "static_lib_dep") + `
Romain Jobredeaux1282c422021-10-29 10:52:59 -040071android_app {
72 name: "TestApp",
73 srcs: ["app.java"],
74 sdk_version: "current",
75 package_name: "com.google",
76 resource_dirs: ["resa", "resb"],
77 manifest: "manifest/AndroidManifest.xml",
Romain Jobredeaux355851b2022-01-13 17:07:01 +000078 static_libs: ["static_lib_dep"]
Romain Jobredeaux1282c422021-10-29 10:52:59 -040079}
80`,
81 expectedBazelTargets: []string{
82 makeBazelTarget("android_binary", "TestApp", attrNameToString{
83 "srcs": `["app.java"]`,
84 "manifest": `"manifest/AndroidManifest.xml"`,
85 "resource_files": `[
86 "resa/res.png",
87 "resb/res.png",
88 ]`,
89 "custom_package": `"com.google"`,
Sam Delmerico881d7202022-02-23 15:18:56 +000090 "deps": `[
91 "//prebuilts/sdk:public_current_android_sdk_java_import",
92 ":static_lib_dep",
93 ]`,
Romain Jobredeaux1282c422021-10-29 10:52:59 -040094 }),
95 }})
96}
Sam Delmericoe91d0302022-02-23 15:28:33 +000097
98func TestAndroidAppArchVariantSrcs(t *testing.T) {
99 runAndroidAppTestCase(t, bp2buildTestCase{
100 description: "Android app - arch variant srcs",
101 moduleTypeUnderTest: "android_app",
102 moduleTypeUnderTestFactory: java.AndroidAppFactory,
103 filesystem: map[string]string{
104 "arm.java": "",
105 "x86.java": "",
106 "res/res.png": "",
107 "AndroidManifest.xml": "",
108 },
109 blueprint: `
110android_app {
111 name: "TestApp",
112 sdk_version: "current",
113 arch: {
114 arm: {
115 srcs: ["arm.java"],
116 },
117 x86: {
118 srcs: ["x86.java"],
119 }
120 }
121}
122`,
123 expectedBazelTargets: []string{
124 makeBazelTarget("android_binary", "TestApp", attrNameToString{
125 "srcs": `select({
126 "//build/bazel/platforms/arch:arm": ["arm.java"],
127 "//build/bazel/platforms/arch:x86": ["x86.java"],
128 "//conditions:default": [],
129 })`,
130 "manifest": `"AndroidManifest.xml"`,
131 "resource_files": `["res/res.png"]`,
132 "deps": `["//prebuilts/sdk:public_current_android_sdk_java_import"]`,
133 }),
134 }})
135}