Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1 | // Copyright 2020 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 cc |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | func TestSdkMutator(t *testing.T) { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 24 | bp := ` |
| 25 | cc_library { |
| 26 | name: "libsdk", |
| 27 | shared_libs: ["libsdkdep"], |
| 28 | sdk_version: "current", |
| 29 | stl: "c++_shared", |
| 30 | } |
| 31 | |
| 32 | cc_library { |
| 33 | name: "libsdkdep", |
| 34 | sdk_version: "current", |
| 35 | stl: "c++_shared", |
| 36 | } |
| 37 | |
| 38 | cc_library { |
| 39 | name: "libplatform", |
| 40 | shared_libs: ["libsdk"], |
| 41 | stl: "libc++", |
| 42 | } |
| 43 | |
| 44 | cc_binary { |
| 45 | name: "platformbinary", |
| 46 | shared_libs: ["libplatform"], |
| 47 | stl: "libc++", |
| 48 | } |
| 49 | |
| 50 | cc_binary { |
| 51 | name: "sdkbinary", |
| 52 | shared_libs: ["libsdk"], |
| 53 | sdk_version: "current", |
| 54 | stl: "libc++", |
| 55 | } |
| 56 | ` |
| 57 | |
| 58 | assertDep := func(t *testing.T, from, to android.TestingModule) { |
| 59 | t.Helper() |
| 60 | found := false |
| 61 | |
| 62 | var toFile android.Path |
| 63 | m := to.Module().(*Module) |
| 64 | if toc := m.Toc(); toc.Valid() { |
| 65 | toFile = toc.Path() |
| 66 | } else { |
| 67 | toFile = m.outputFile.Path() |
| 68 | } |
Paul Duffin | e8366da | 2021-03-24 10:40:38 +0000 | [diff] [blame] | 69 | toFile = toFile.RelativeToTop() |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 70 | |
| 71 | rule := from.Description("link") |
| 72 | for _, dep := range rule.Implicits { |
| 73 | if dep.String() == toFile.String() { |
| 74 | found = true |
| 75 | } |
| 76 | } |
| 77 | if !found { |
| 78 | t.Errorf("expected %q in %q", toFile.String(), rule.Implicits.Strings()) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | ctx := testCc(t, bp) |
| 83 | |
| 84 | libsdkNDK := ctx.ModuleForTests("libsdk", "android_arm64_armv8-a_sdk_shared") |
| 85 | libsdkPlatform := ctx.ModuleForTests("libsdk", "android_arm64_armv8-a_shared") |
| 86 | libsdkdepNDK := ctx.ModuleForTests("libsdkdep", "android_arm64_armv8-a_sdk_shared") |
| 87 | libsdkdepPlatform := ctx.ModuleForTests("libsdkdep", "android_arm64_armv8-a_shared") |
| 88 | libplatform := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared") |
| 89 | platformbinary := ctx.ModuleForTests("platformbinary", "android_arm64_armv8-a") |
| 90 | sdkbinary := ctx.ModuleForTests("sdkbinary", "android_arm64_armv8-a_sdk") |
| 91 | |
| 92 | libcxxNDK := ctx.ModuleForTests("ndk_libc++_shared", "android_arm64_armv8-a_sdk_shared") |
| 93 | libcxxPlatform := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared") |
| 94 | |
| 95 | assertDep(t, libsdkNDK, libsdkdepNDK) |
| 96 | assertDep(t, libsdkPlatform, libsdkdepPlatform) |
| 97 | assertDep(t, libplatform, libsdkPlatform) |
| 98 | assertDep(t, platformbinary, libplatform) |
| 99 | assertDep(t, sdkbinary, libsdkNDK) |
| 100 | |
| 101 | assertDep(t, libsdkNDK, libcxxNDK) |
| 102 | assertDep(t, libsdkPlatform, libcxxPlatform) |
| 103 | } |
Jooyung Han | 54f7805 | 2023-02-20 18:17:47 +0900 | [diff] [blame] | 104 | |
| 105 | func TestMakeModuleNameForSdkVariant(t *testing.T) { |
| 106 | bp := ` |
| 107 | cc_library { |
| 108 | name: "libfoo", |
| 109 | srcs: ["main_test.cpp"], |
| 110 | sdk_version: "current", |
| 111 | stl: "none", |
| 112 | } |
| 113 | ` |
| 114 | platformVariant := "android_arm64_armv8-a_shared" |
| 115 | sdkVariant := "android_arm64_armv8-a_sdk_shared" |
| 116 | testCases := []struct { |
| 117 | name string |
| 118 | unbundledApps []string |
| 119 | variant string |
| 120 | skipInstall bool // soong skips install |
| 121 | hideFromMake bool // no make entry |
| 122 | makeUninstallable bool // make skips install |
| 123 | makeModuleName string |
| 124 | }{ |
| 125 | { |
| 126 | name: "platform variant in normal builds", |
| 127 | unbundledApps: nil, |
| 128 | variant: platformVariant, |
| 129 | // installable in soong |
| 130 | skipInstall: false, |
| 131 | // visiable in Make as "libfoo" |
| 132 | hideFromMake: false, |
| 133 | makeModuleName: "libfoo", |
| 134 | // installable in Make |
| 135 | makeUninstallable: false, |
| 136 | }, |
| 137 | { |
| 138 | name: "sdk variant in normal builds", |
| 139 | unbundledApps: nil, |
| 140 | variant: sdkVariant, |
| 141 | // soong doesn't install |
| 142 | skipInstall: true, |
| 143 | // visible in Make as "libfoo.sdk" |
| 144 | hideFromMake: false, |
| 145 | makeModuleName: "libfoo.sdk", |
| 146 | // but not installed |
| 147 | makeUninstallable: true, |
| 148 | }, |
| 149 | { |
| 150 | name: "platform variant in unbunded builds", |
| 151 | unbundledApps: []string{"bar"}, |
| 152 | variant: platformVariant, |
| 153 | // installable in soong |
| 154 | skipInstall: false, |
| 155 | // hidden from make |
| 156 | hideFromMake: true, |
| 157 | }, |
| 158 | { |
| 159 | name: "sdk variant in unbunded builds", |
| 160 | unbundledApps: []string{"bar"}, |
| 161 | variant: sdkVariant, |
| 162 | // soong doesn't install |
| 163 | skipInstall: true, |
| 164 | // visible in Make as "libfoo" |
| 165 | hideFromMake: false, |
| 166 | makeModuleName: "libfoo", |
| 167 | // but not installed |
| 168 | makeUninstallable: true, |
| 169 | }, |
| 170 | } |
| 171 | for _, tc := range testCases { |
| 172 | t.Run(tc.name, func(t *testing.T) { |
| 173 | fixture := android.GroupFixturePreparers(prepareForCcTest, |
| 174 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 175 | variables.Unbundled_build_apps = tc.unbundledApps |
| 176 | }), |
| 177 | ) |
| 178 | ctx := fixture.RunTestWithBp(t, bp).TestContext |
| 179 | module := ctx.ModuleForTests("libfoo", tc.variant).Module().(*Module) |
| 180 | android.AssertBoolEquals(t, "IsSkipInstall", tc.skipInstall, module.IsSkipInstall()) |
| 181 | android.AssertBoolEquals(t, "HideFromMake", tc.hideFromMake, module.HiddenFromMake()) |
| 182 | if !tc.hideFromMake { |
| 183 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
| 184 | android.AssertStringEquals(t, "LOCAL_MODULE", |
| 185 | tc.makeModuleName, entries.EntryMap["LOCAL_MODULE"][0]) |
| 186 | actualUninstallable := false |
| 187 | if actual, ok := entries.EntryMap["LOCAL_UNINSTALLABLE_MODULE"]; ok { |
| 188 | actualUninstallable = "true" == actual[0] |
| 189 | } |
| 190 | android.AssertBoolEquals(t, "LOCAL_UNINSTALLABLE_MODULE", |
| 191 | tc.makeUninstallable, actualUninstallable) |
| 192 | } |
| 193 | }) |
| 194 | } |
| 195 | } |