Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | func 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()) |
| 62 | } |
| 63 | |
| 64 | func TestD8(t *testing.T) { |
| 65 | result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, ` |
| 66 | java_library { |
| 67 | name: "foo", |
| 68 | srcs: ["foo.java"], |
| 69 | libs: ["lib"], |
| 70 | static_libs: ["static_lib"], |
| 71 | installable: true, |
| 72 | } |
| 73 | |
| 74 | java_library { |
| 75 | name: "lib", |
| 76 | srcs: ["foo.java"], |
| 77 | } |
| 78 | |
| 79 | java_library { |
| 80 | name: "static_lib", |
| 81 | srcs: ["foo.java"], |
| 82 | } |
| 83 | `) |
| 84 | |
| 85 | foo := result.ModuleForTests("foo", "android_common") |
| 86 | lib := result.ModuleForTests("lib", "android_common") |
| 87 | staticLib := result.ModuleForTests("static_lib", "android_common") |
| 88 | |
| 89 | fooJavac := foo.Rule("javac") |
| 90 | fooD8 := foo.Rule("d8") |
| 91 | libHeader := lib.Output("turbine-combined/lib.jar").Output |
| 92 | staticLibHeader := staticLib.Output("turbine-combined/static_lib.jar").Output |
| 93 | |
| 94 | android.AssertStringDoesContain(t, "expected lib header jar in foo javac classpath", |
| 95 | fooJavac.Args["classpath"], libHeader.String()) |
| 96 | android.AssertStringDoesContain(t, "expected static_lib header jar in foo javac classpath", |
| 97 | fooJavac.Args["classpath"], staticLibHeader.String()) |
| 98 | |
| 99 | android.AssertStringDoesContain(t, "expected lib header jar in foo d8 classpath", |
| 100 | fooD8.Args["d8Flags"], libHeader.String()) |
| 101 | android.AssertStringDoesNotContain(t, "expected no static_lib header jar in foo javac classpath", |
| 102 | fooD8.Args["d8Flags"], staticLibHeader.String()) |
| 103 | } |