Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 1 | // Copyright 2017 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 ( |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 18 | "strconv" |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 19 | "strings" |
| 20 | "testing" |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 21 | |
| 22 | "android/soong/android" |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func TestKotlin(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 26 | ctx, _ := testJava(t, ` |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 27 | java_library { |
| 28 | name: "foo", |
| 29 | srcs: ["a.java", "b.kt"], |
| 30 | } |
| 31 | |
| 32 | java_library { |
| 33 | name: "bar", |
| 34 | srcs: ["b.kt"], |
| 35 | libs: ["foo"], |
| 36 | static_libs: ["baz"], |
| 37 | } |
| 38 | |
| 39 | java_library { |
| 40 | name: "baz", |
| 41 | srcs: ["c.java"], |
| 42 | } |
| 43 | `) |
| 44 | |
| 45 | fooKotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc") |
| 46 | fooJavac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 47 | fooJar := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar") |
Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 48 | fooHeaderJar := ctx.ModuleForTests("foo", "android_common").Output("turbine-combined/foo.jar") |
| 49 | |
| 50 | fooKotlincClasses := fooKotlinc.Output |
| 51 | fooKotlincHeaderClasses := fooKotlinc.ImplicitOutput |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 52 | |
| 53 | if len(fooKotlinc.Inputs) != 2 || fooKotlinc.Inputs[0].String() != "a.java" || |
| 54 | fooKotlinc.Inputs[1].String() != "b.kt" { |
| 55 | t.Errorf(`foo kotlinc inputs %v != ["a.java", "b.kt"]`, fooKotlinc.Inputs) |
| 56 | } |
| 57 | |
| 58 | if len(fooJavac.Inputs) != 1 || fooJavac.Inputs[0].String() != "a.java" { |
| 59 | t.Errorf(`foo inputs %v != ["a.java"]`, fooJavac.Inputs) |
| 60 | } |
| 61 | |
Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 62 | if !strings.Contains(fooJavac.Args["classpath"], fooKotlincHeaderClasses.String()) { |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 63 | t.Errorf("foo classpath %v does not contain %q", |
Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 64 | fooJavac.Args["classpath"], fooKotlincHeaderClasses.String()) |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 67 | if !inList(fooKotlincClasses.String(), fooJar.Inputs.Strings()) { |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 68 | t.Errorf("foo jar inputs %v does not contain %q", |
Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 69 | fooJar.Inputs.Strings(), fooKotlincClasses.String()) |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 72 | if !inList(fooKotlincHeaderClasses.String(), fooHeaderJar.Inputs.Strings()) { |
| 73 | t.Errorf("foo header jar inputs %v does not contain %q", |
| 74 | fooHeaderJar.Inputs.Strings(), fooKotlincHeaderClasses.String()) |
| 75 | } |
| 76 | |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 77 | bazHeaderJar := ctx.ModuleForTests("baz", "android_common").Output("turbine-combined/baz.jar") |
| 78 | barKotlinc := ctx.ModuleForTests("bar", "android_common").Rule("kotlinc") |
| 79 | |
| 80 | if len(barKotlinc.Inputs) != 1 || barKotlinc.Inputs[0].String() != "b.kt" { |
| 81 | t.Errorf(`bar kotlinc inputs %v != ["b.kt"]`, barKotlinc.Inputs) |
| 82 | } |
| 83 | |
| 84 | if !inList(fooHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) { |
| 85 | t.Errorf(`expected %q in bar implicits %v`, |
| 86 | fooHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) |
| 87 | } |
| 88 | |
| 89 | if !inList(bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) { |
| 90 | t.Errorf(`expected %q in bar implicits %v`, |
| 91 | bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) |
| 92 | } |
| 93 | } |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 94 | |
| 95 | func TestKapt(t *testing.T) { |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 96 | bp := ` |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 97 | java_library { |
| 98 | name: "foo", |
| 99 | srcs: ["a.java", "b.kt"], |
Colin Cross | 5a11686 | 2020-04-22 11:44:34 -0700 | [diff] [blame] | 100 | plugins: ["bar", "baz"], |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 101 | errorprone: { |
| 102 | extra_check_modules: ["my_check"], |
| 103 | }, |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 106 | java_plugin { |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 107 | name: "bar", |
Colin Cross | 3a3e94c | 2019-01-23 15:39:50 -0800 | [diff] [blame] | 108 | processor_class: "com.bar", |
| 109 | srcs: ["b.java"], |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 110 | } |
Colin Cross | 5a11686 | 2020-04-22 11:44:34 -0700 | [diff] [blame] | 111 | |
| 112 | java_plugin { |
| 113 | name: "baz", |
| 114 | processor_class: "com.baz", |
| 115 | srcs: ["b.java"], |
| 116 | } |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 117 | |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 118 | java_plugin { |
| 119 | name: "my_check", |
| 120 | srcs: ["b.java"], |
| 121 | } |
| 122 | ` |
| 123 | t.Run("", func(t *testing.T) { |
| 124 | ctx, _ := testJava(t, bp) |
Colin Cross | 3a3e94c | 2019-01-23 15:39:50 -0800 | [diff] [blame] | 125 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 126 | buildOS := ctx.Config().BuildOS.String() |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 127 | |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 128 | foo := ctx.ModuleForTests("foo", "android_common") |
| 129 | kaptStubs := foo.Rule("kapt") |
| 130 | turbineApt := foo.Description("turbine apt") |
| 131 | kotlinc := foo.Rule("kotlinc") |
| 132 | javac := foo.Rule("javac") |
Colin Cross | 3a3e94c | 2019-01-23 15:39:50 -0800 | [diff] [blame] | 133 | |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 134 | bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String() |
| 135 | baz := ctx.ModuleForTests("baz", buildOS+"_common").Rule("javac").Output.String() |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 136 | |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 137 | // Test that the kotlin and java sources are passed to kapt and kotlinc |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 138 | if len(kaptStubs.Inputs) != 2 || kaptStubs.Inputs[0].String() != "a.java" || kaptStubs.Inputs[1].String() != "b.kt" { |
| 139 | t.Errorf(`foo kapt inputs %v != ["a.java", "b.kt"]`, kaptStubs.Inputs) |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 140 | } |
| 141 | if len(kotlinc.Inputs) != 2 || kotlinc.Inputs[0].String() != "a.java" || kotlinc.Inputs[1].String() != "b.kt" { |
| 142 | t.Errorf(`foo kotlinc inputs %v != ["a.java", "b.kt"]`, kotlinc.Inputs) |
| 143 | } |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 144 | |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 145 | // Test that only the java sources are passed to turbine-apt and javac |
| 146 | if len(turbineApt.Inputs) != 1 || turbineApt.Inputs[0].String() != "a.java" { |
| 147 | t.Errorf(`foo turbine apt inputs %v != ["a.java"]`, turbineApt.Inputs) |
| 148 | } |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 149 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { |
| 150 | t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) |
| 151 | } |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 152 | |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 153 | // Test that the kapt stubs jar is a dependency of turbine-apt |
| 154 | if !inList(kaptStubs.Output.String(), turbineApt.Implicits.Strings()) { |
| 155 | t.Errorf("expected %q in turbine-apt implicits %v", kaptStubs.Output.String(), kotlinc.Implicits.Strings()) |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 156 | } |
Colin Cross | 3a3e94c | 2019-01-23 15:39:50 -0800 | [diff] [blame] | 157 | |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 158 | // Test that the turbine-apt srcjar is a dependency of kotlinc and javac rules |
Isaac Chiou | a23d994 | 2022-04-06 06:14:38 +0000 | [diff] [blame^] | 159 | if !inList(turbineApt.Output.String(), kotlinc.Implicits.Strings()) { |
| 160 | t.Errorf("expected %q in kotlinc implicits %v", turbineApt.Output.String(), kotlinc.Implicits.Strings()) |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 161 | } |
Isaac Chiou | a23d994 | 2022-04-06 06:14:38 +0000 | [diff] [blame^] | 162 | if !inList(turbineApt.Output.String(), javac.Implicits.Strings()) { |
| 163 | t.Errorf("expected %q in javac implicits %v", turbineApt.Output.String(), javac.Implicits.Strings()) |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | // Test that the turbine-apt srcjar is extracted by the kotlinc and javac rules |
Isaac Chiou | a23d994 | 2022-04-06 06:14:38 +0000 | [diff] [blame^] | 167 | if kotlinc.Args["srcJars"] != turbineApt.Output.String() { |
| 168 | t.Errorf("expected %q in kotlinc srcjars %v", turbineApt.Output.String(), kotlinc.Args["srcJars"]) |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 169 | } |
Isaac Chiou | a23d994 | 2022-04-06 06:14:38 +0000 | [diff] [blame^] | 170 | if javac.Args["srcJars"] != turbineApt.Output.String() { |
| 171 | t.Errorf("expected %q in javac srcjars %v", turbineApt.Output.String(), kotlinc.Args["srcJars"]) |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 172 | } |
Colin Cross | 3a3e94c | 2019-01-23 15:39:50 -0800 | [diff] [blame] | 173 | |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 174 | // Test that the processors are passed to kapt |
| 175 | expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar + |
| 176 | " -P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + baz |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 177 | if kaptStubs.Args["kaptProcessorPath"] != expectedProcessorPath { |
| 178 | t.Errorf("expected kaptProcessorPath %q, got %q", expectedProcessorPath, kaptStubs.Args["kaptProcessorPath"]) |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 179 | } |
| 180 | expectedProcessor := "-P plugin:org.jetbrains.kotlin.kapt3:processors=com.bar -P plugin:org.jetbrains.kotlin.kapt3:processors=com.baz" |
Colin Cross | f61766e | 2022-03-16 18:06:48 -0700 | [diff] [blame] | 181 | if kaptStubs.Args["kaptProcessor"] != expectedProcessor { |
| 182 | t.Errorf("expected kaptProcessor %q, got %q", expectedProcessor, kaptStubs.Args["kaptProcessor"]) |
| 183 | } |
| 184 | |
| 185 | // Test that the processors are passed to turbine-apt |
| 186 | expectedProcessorPath = "--processorpath " + bar + " " + baz |
| 187 | if !strings.Contains(turbineApt.Args["turbineFlags"], expectedProcessorPath) { |
| 188 | t.Errorf("expected turbine-apt processorpath %q, got %q", expectedProcessorPath, turbineApt.Args["turbineFlags"]) |
| 189 | } |
| 190 | expectedProcessor = "--processors com.bar com.baz" |
| 191 | if !strings.Contains(turbineApt.Args["turbineFlags"], expectedProcessor) { |
| 192 | t.Errorf("expected turbine-apt processor %q, got %q", expectedProcessor, turbineApt.Args["turbineFlags"]) |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // Test that the processors are not passed to javac |
| 196 | if javac.Args["processorpath"] != "" { |
| 197 | t.Errorf("expected processorPath '', got %q", javac.Args["processorpath"]) |
| 198 | } |
| 199 | if javac.Args["processor"] != "-proc:none" { |
| 200 | t.Errorf("expected processor '-proc:none', got %q", javac.Args["processor"]) |
| 201 | } |
| 202 | }) |
| 203 | |
| 204 | t.Run("errorprone", func(t *testing.T) { |
| 205 | env := map[string]string{ |
| 206 | "RUN_ERROR_PRONE": "true", |
| 207 | } |
Paul Duffin | b148a49 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 208 | |
| 209 | result := android.GroupFixturePreparers( |
| 210 | PrepareForTestWithJavaDefaultModules, |
| 211 | android.FixtureMergeEnv(env), |
| 212 | ).RunTestWithBp(t, bp) |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 213 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 214 | buildOS := result.Config.BuildOS.String() |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 215 | |
Paul Duffin | b148a49 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 216 | kapt := result.ModuleForTests("foo", "android_common").Rule("kapt") |
Paul Duffin | b148a49 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 217 | javac := result.ModuleForTests("foo", "android_common").Description("javac") |
| 218 | errorprone := result.ModuleForTests("foo", "android_common").Description("errorprone") |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 219 | |
Paul Duffin | b148a49 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 220 | bar := result.ModuleForTests("bar", buildOS+"_common").Description("javac").Output.String() |
| 221 | baz := result.ModuleForTests("baz", buildOS+"_common").Description("javac").Output.String() |
| 222 | myCheck := result.ModuleForTests("my_check", buildOS+"_common").Description("javac").Output.String() |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 223 | |
| 224 | // Test that the errorprone plugins are not passed to kapt |
| 225 | expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar + |
| 226 | " -P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + baz |
| 227 | if kapt.Args["kaptProcessorPath"] != expectedProcessorPath { |
| 228 | t.Errorf("expected kaptProcessorPath %q, got %q", expectedProcessorPath, kapt.Args["kaptProcessorPath"]) |
| 229 | } |
| 230 | expectedProcessor := "-P plugin:org.jetbrains.kotlin.kapt3:processors=com.bar -P plugin:org.jetbrains.kotlin.kapt3:processors=com.baz" |
| 231 | if kapt.Args["kaptProcessor"] != expectedProcessor { |
| 232 | t.Errorf("expected kaptProcessor %q, got %q", expectedProcessor, kapt.Args["kaptProcessor"]) |
| 233 | } |
| 234 | |
| 235 | // Test that the errorprone plugins are not passed to javac |
| 236 | if javac.Args["processorpath"] != "" { |
| 237 | t.Errorf("expected processorPath '', got %q", javac.Args["processorpath"]) |
| 238 | } |
| 239 | if javac.Args["processor"] != "-proc:none" { |
| 240 | t.Errorf("expected processor '-proc:none', got %q", javac.Args["processor"]) |
| 241 | } |
| 242 | |
| 243 | // Test that the errorprone plugins are passed to errorprone |
| 244 | expectedProcessorPath = "-processorpath " + myCheck |
| 245 | if errorprone.Args["processorpath"] != expectedProcessorPath { |
| 246 | t.Errorf("expected processorpath %q, got %q", expectedProcessorPath, errorprone.Args["processorpath"]) |
| 247 | } |
| 248 | if errorprone.Args["processor"] != "-proc:none" { |
| 249 | t.Errorf("expected processor '-proc:none', got %q", errorprone.Args["processor"]) |
| 250 | } |
| 251 | }) |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | func TestKaptEncodeFlags(t *testing.T) { |
| 255 | // Compares the kaptEncodeFlags against the results of the example implementation at |
| 256 | // https://kotlinlang.org/docs/reference/kapt.html#apjavac-options-encoding |
| 257 | tests := []struct { |
| 258 | in [][2]string |
| 259 | out string |
| 260 | }{ |
| 261 | { |
| 262 | // empty input |
| 263 | in: [][2]string{}, |
| 264 | out: "rO0ABXcEAAAAAA==", |
| 265 | }, |
| 266 | { |
| 267 | // common input |
| 268 | in: [][2]string{ |
| 269 | {"-source", "1.8"}, |
| 270 | {"-target", "1.8"}, |
| 271 | }, |
| 272 | out: "rO0ABXcgAAAAAgAHLXNvdXJjZQADMS44AActdGFyZ2V0AAMxLjg=", |
| 273 | }, |
| 274 | { |
| 275 | // input that serializes to a 255 byte block |
| 276 | in: [][2]string{ |
| 277 | {"-source", "1.8"}, |
| 278 | {"-target", "1.8"}, |
| 279 | {"a", strings.Repeat("b", 218)}, |
| 280 | }, |
| 281 | out: "rO0ABXf/AAAAAwAHLXNvdXJjZQADMS44AActdGFyZ2V0AAMxLjgAAWEA2mJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJi", |
| 282 | }, |
| 283 | { |
| 284 | // input that serializes to a 256 byte block |
| 285 | in: [][2]string{ |
| 286 | {"-source", "1.8"}, |
| 287 | {"-target", "1.8"}, |
| 288 | {"a", strings.Repeat("b", 219)}, |
| 289 | }, |
| 290 | out: "rO0ABXoAAAEAAAAAAwAHLXNvdXJjZQADMS44AActdGFyZ2V0AAMxLjgAAWEA22JiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYg==", |
| 291 | }, |
| 292 | { |
| 293 | // input that serializes to a 257 byte block |
| 294 | in: [][2]string{ |
| 295 | {"-source", "1.8"}, |
| 296 | {"-target", "1.8"}, |
| 297 | {"a", strings.Repeat("b", 220)}, |
| 298 | }, |
| 299 | out: "rO0ABXoAAAEBAAAAAwAHLXNvdXJjZQADMS44AActdGFyZ2V0AAMxLjgAAWEA3GJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmI=", |
| 300 | }, |
| 301 | } |
| 302 | |
| 303 | for i, test := range tests { |
| 304 | t.Run(strconv.Itoa(i), func(t *testing.T) { |
| 305 | got := kaptEncodeFlags(test.in) |
| 306 | if got != test.out { |
| 307 | t.Errorf("\nwant %q\n got %q", test.out, got) |
| 308 | } |
| 309 | }) |
| 310 | } |
| 311 | } |
Colin Cross | a1ff7c6 | 2021-09-17 14:11:52 -0700 | [diff] [blame] | 312 | |
| 313 | func TestKotlinCompose(t *testing.T) { |
| 314 | result := android.GroupFixturePreparers( |
| 315 | PrepareForTestWithJavaDefaultModules, |
| 316 | ).RunTestWithBp(t, ` |
| 317 | java_library { |
| 318 | name: "androidx.compose.runtime_runtime", |
| 319 | } |
| 320 | |
| 321 | java_library_host { |
| 322 | name: "androidx.compose.compiler_compiler-hosted", |
| 323 | } |
| 324 | |
| 325 | java_library { |
| 326 | name: "withcompose", |
| 327 | srcs: ["a.kt"], |
| 328 | static_libs: ["androidx.compose.runtime_runtime"], |
| 329 | } |
| 330 | |
| 331 | java_library { |
| 332 | name: "nocompose", |
| 333 | srcs: ["a.kt"], |
| 334 | } |
| 335 | `) |
| 336 | |
| 337 | buildOS := result.Config.BuildOS.String() |
| 338 | |
| 339 | composeCompiler := result.ModuleForTests("androidx.compose.compiler_compiler-hosted", buildOS+"_common").Rule("combineJar").Output |
| 340 | withCompose := result.ModuleForTests("withcompose", "android_common") |
| 341 | noCompose := result.ModuleForTests("nocompose", "android_common") |
| 342 | |
| 343 | android.AssertStringListContains(t, "missing compose compiler dependency", |
| 344 | withCompose.Rule("kotlinc").Implicits.Strings(), composeCompiler.String()) |
| 345 | |
| 346 | android.AssertStringDoesContain(t, "missing compose compiler plugin", |
| 347 | withCompose.VariablesForTestsRelativeToTop()["kotlincFlags"], "-Xplugin="+composeCompiler.String()) |
| 348 | |
| 349 | android.AssertStringListDoesNotContain(t, "unexpected compose compiler dependency", |
| 350 | noCompose.Rule("kotlinc").Implicits.Strings(), composeCompiler.String()) |
| 351 | |
| 352 | android.AssertStringDoesNotContain(t, "unexpected compose compiler plugin", |
| 353 | noCompose.VariablesForTestsRelativeToTop()["kotlincFlags"], "-Xplugin="+composeCompiler.String()) |
| 354 | } |