blob: a3e2deda4bd17f0fa8aa0db898420fee2f1e459f [file] [log] [blame]
Colin Cross9bb9bfb2022-03-17 11:12:32 -07001// Copyright 2022 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 java
16
17import (
18 "testing"
19
20 "android/soong/android"
21)
22
23func TestR8(t *testing.T) {
24 result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
25 android_app {
26 name: "app",
27 srcs: ["foo.java"],
28 libs: ["lib"],
29 static_libs: ["static_lib"],
30 platform_apis: true,
31 }
32
33 java_library {
34 name: "lib",
35 srcs: ["foo.java"],
36 }
37
38 java_library {
39 name: "static_lib",
40 srcs: ["foo.java"],
41 }
42 `)
43
44 app := result.ModuleForTests("app", "android_common")
45 lib := result.ModuleForTests("lib", "android_common")
46 staticLib := result.ModuleForTests("static_lib", "android_common")
47
48 appJavac := app.Rule("javac")
49 appR8 := app.Rule("r8")
50 libHeader := lib.Output("turbine-combined/lib.jar").Output
51 staticLibHeader := staticLib.Output("turbine-combined/static_lib.jar").Output
52
53 android.AssertStringDoesContain(t, "expected lib header jar in app javac classpath",
54 appJavac.Args["classpath"], libHeader.String())
55 android.AssertStringDoesContain(t, "expected static_lib header jar in app javac classpath",
56 appJavac.Args["classpath"], staticLibHeader.String())
57
58 android.AssertStringDoesContain(t, "expected lib header jar in app r8 classpath",
59 appR8.Args["r8Flags"], libHeader.String())
60 android.AssertStringDoesNotContain(t, "expected no static_lib header jar in app javac classpath",
61 appR8.Args["r8Flags"], staticLibHeader.String())
Remi NGUYEN VANbdad3142022-08-04 13:19:03 +090062 android.AssertStringDoesContain(t, "expected -ignorewarnings in app r8 flags",
63 appR8.Args["r8Flags"], "-ignorewarnings")
64}
65
66func TestR8Flags(t *testing.T) {
67 result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
68 android_app {
69 name: "app",
70 srcs: ["foo.java"],
71 platform_apis: true,
72 optimize: {
73 shrink: false,
74 optimize: false,
75 obfuscate: false,
76 ignore_warnings: false,
77 },
78 }
79 `)
80
81 app := result.ModuleForTests("app", "android_common")
82 appR8 := app.Rule("r8")
83 android.AssertStringDoesContain(t, "expected -dontshrink in app r8 flags",
84 appR8.Args["r8Flags"], "-dontshrink")
85 android.AssertStringDoesContain(t, "expected -dontoptimize in app r8 flags",
86 appR8.Args["r8Flags"], "-dontoptimize")
87 android.AssertStringDoesContain(t, "expected -dontobfuscate in app r8 flags",
88 appR8.Args["r8Flags"], "-dontobfuscate")
89 android.AssertStringDoesNotContain(t, "expected no -ignorewarnings in app r8 flags",
90 appR8.Args["r8Flags"], "-ignorewarnings")
91
Colin Cross9bb9bfb2022-03-17 11:12:32 -070092}
93
94func TestD8(t *testing.T) {
95 result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
96 java_library {
97 name: "foo",
98 srcs: ["foo.java"],
99 libs: ["lib"],
100 static_libs: ["static_lib"],
101 installable: true,
102 }
103
104 java_library {
105 name: "lib",
106 srcs: ["foo.java"],
107 }
108
109 java_library {
110 name: "static_lib",
111 srcs: ["foo.java"],
112 }
113 `)
114
115 foo := result.ModuleForTests("foo", "android_common")
116 lib := result.ModuleForTests("lib", "android_common")
117 staticLib := result.ModuleForTests("static_lib", "android_common")
118
119 fooJavac := foo.Rule("javac")
120 fooD8 := foo.Rule("d8")
121 libHeader := lib.Output("turbine-combined/lib.jar").Output
122 staticLibHeader := staticLib.Output("turbine-combined/static_lib.jar").Output
123
124 android.AssertStringDoesContain(t, "expected lib header jar in foo javac classpath",
125 fooJavac.Args["classpath"], libHeader.String())
126 android.AssertStringDoesContain(t, "expected static_lib header jar in foo javac classpath",
127 fooJavac.Args["classpath"], staticLibHeader.String())
128
129 android.AssertStringDoesContain(t, "expected lib header jar in foo d8 classpath",
130 fooD8.Args["d8Flags"], libHeader.String())
131 android.AssertStringDoesNotContain(t, "expected no static_lib header jar in foo javac classpath",
132 fooD8.Args["d8Flags"], staticLibHeader.String())
133}