blob: 7b9867c1b83c306c281e605b6d9578a399bbf96a [file] [log] [blame]
Colin Crossc511bc52020-04-07 16:50:32 +00001// 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
15package cc
16
17import (
18 "testing"
19
20 "android/soong/android"
21)
22
23func TestSdkMutator(t *testing.T) {
Colin Cross323dc602020-09-18 14:25:31 -070024 t.Parallel()
Colin Crossc511bc52020-04-07 16:50:32 +000025 bp := `
26 cc_library {
27 name: "libsdk",
28 shared_libs: ["libsdkdep"],
29 sdk_version: "current",
30 stl: "c++_shared",
31 }
32
33 cc_library {
34 name: "libsdkdep",
35 sdk_version: "current",
36 stl: "c++_shared",
37 }
38
39 cc_library {
40 name: "libplatform",
41 shared_libs: ["libsdk"],
42 stl: "libc++",
43 }
44
45 cc_binary {
46 name: "platformbinary",
47 shared_libs: ["libplatform"],
48 stl: "libc++",
49 }
50
51 cc_binary {
52 name: "sdkbinary",
53 shared_libs: ["libsdk"],
54 sdk_version: "current",
55 stl: "libc++",
56 }
57 `
58
59 assertDep := func(t *testing.T, from, to android.TestingModule) {
60 t.Helper()
61 found := false
62
63 var toFile android.Path
64 m := to.Module().(*Module)
65 if toc := m.Toc(); toc.Valid() {
66 toFile = toc.Path()
67 } else {
68 toFile = m.outputFile.Path()
69 }
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}