Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 18 | "testing" |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 19 | |
| 20 | "android/soong/android" |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 21 | ) |
| 22 | |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 23 | func normalizedPathsToHeaderJars(result *android.TestResult, moduleNames ...string) []string { |
| 24 | paths := []string{} |
| 25 | for _, moduleName := range moduleNames { |
| 26 | module := result.Module(moduleName, "android_common") |
| 27 | info := result.ModuleProvider(module, JavaInfoProvider).(JavaInfo) |
| 28 | paths = append(paths, result.NormalizePathsForTesting(info.HeaderJars)...) |
| 29 | } |
| 30 | return paths |
| 31 | } |
| 32 | |
| 33 | var addSourceSystemModules = android.FixtureAddTextFile("source/Android.bp", ` |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 34 | java_system_modules { |
| 35 | name: "system-modules", |
| 36 | libs: ["system-module1", "system-module2"], |
| 37 | } |
| 38 | java_library { |
| 39 | name: "system-module1", |
| 40 | srcs: ["a.java"], |
| 41 | sdk_version: "none", |
| 42 | system_modules: "none", |
| 43 | } |
| 44 | java_library { |
| 45 | name: "system-module2", |
| 46 | srcs: ["b.java"], |
| 47 | sdk_version: "none", |
| 48 | system_modules: "none", |
| 49 | } |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 50 | `) |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 51 | |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 52 | func TestJavaSystemModules(t *testing.T) { |
| 53 | result := javaFixtureFactory.RunTest(t, addSourceSystemModules) |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 54 | |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 55 | // check the existence of the source module |
| 56 | sourceSystemModules := result.ModuleForTests("system-modules", "android_common") |
| 57 | sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 58 | |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 59 | // The expected paths are the header jars from the source input modules. |
| 60 | expectedSourcePaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2") |
| 61 | result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs)) |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 64 | var addPrebuiltSystemModules = android.FixtureAddTextFile("prebuilts/Android.bp", ` |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 65 | java_system_modules_import { |
| 66 | name: "system-modules", |
| 67 | libs: ["system-module1", "system-module2"], |
| 68 | } |
| 69 | java_import { |
| 70 | name: "system-module1", |
| 71 | jars: ["a.jar"], |
| 72 | } |
| 73 | java_import { |
| 74 | name: "system-module2", |
| 75 | jars: ["b.jar"], |
| 76 | } |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 77 | `) |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 78 | |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 79 | func TestJavaSystemModulesImport(t *testing.T) { |
| 80 | result := javaFixtureFactory.RunTest(t, addPrebuiltSystemModules) |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 81 | |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 82 | // check the existence of the renamed prebuilt module |
| 83 | prebuiltSystemModules := result.ModuleForTests("system-modules", "android_common") |
| 84 | prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 85 | |
Paul Duffin | c52bea9 | 2021-03-11 08:10:19 +0000 | [diff] [blame^] | 86 | // The expected paths are the header jars from the renamed prebuilt input modules. |
| 87 | expectedPrebuiltPaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2") |
| 88 | result.AssertArrayString("renamed prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs)) |
| 89 | } |
| 90 | |
| 91 | func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) { |
| 92 | result := javaFixtureFactory.RunTest(t, |
| 93 | addSourceSystemModules, |
| 94 | addPrebuiltSystemModules, |
| 95 | ) |
| 96 | |
| 97 | // check the existence of the source module |
| 98 | sourceSystemModules := result.ModuleForTests("system-modules", "android_common") |
| 99 | sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs |
| 100 | |
| 101 | // The expected paths are the header jars from the source input modules. |
| 102 | expectedSourcePaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2") |
| 103 | result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs)) |
| 104 | |
| 105 | // check the existence of the renamed prebuilt module |
| 106 | prebuiltSystemModules := result.ModuleForTests("prebuilt_system-modules", "android_common") |
| 107 | prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs |
| 108 | |
| 109 | // The expected paths are the header jars from the renamed prebuilt input modules. |
| 110 | // TODO(b/182402568) - these should be depending on the prebuilts |
| 111 | expectedPrebuiltPaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2") |
| 112 | result.AssertArrayString("prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs)) |
Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame] | 113 | } |