blob: 3d809fc3c1292d92426ae9216a325beb92fd3576 [file] [log] [blame]
Colin Cross33b2fb72019-05-14 14:07:01 -07001// Copyright 2019 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 "github.com/google/blueprint"
23)
24
25func TestPrebuilt(t *testing.T) {
26 bp := `
27 cc_library {
28 name: "liba",
29 }
30
31 cc_prebuilt_library_shared {
32 name: "liba",
33 srcs: ["liba.so"],
34 }
35
36 cc_library {
37 name: "libb",
38 }
39
40 cc_prebuilt_library_static {
41 name: "libb",
42 srcs: ["libb.a"],
43 }
44
45 cc_library_shared {
46 name: "libd",
47 }
48
49 cc_prebuilt_library_shared {
50 name: "libd",
51 srcs: ["libd.so"],
52 }
53
54 cc_library_static {
55 name: "libe",
56 }
57
58 cc_prebuilt_library_static {
59 name: "libe",
60 srcs: ["libe.a"],
61 }
62 `
63
64 fs := map[string][]byte{
65 "liba.so": nil,
66 "libb.a": nil,
67 "libd.so": nil,
68 "libe.a": nil,
69 }
70
Colin Cross98be1bb2019-12-13 20:41:13 -080071 config := TestConfig(buildDir, android.Android, nil, bp, fs)
Colin Cross33b2fb72019-05-14 14:07:01 -070072
Colin Cross98be1bb2019-12-13 20:41:13 -080073 ctx := CreateTestContext()
Colin Cross33b2fb72019-05-14 14:07:01 -070074
Colin Cross98be1bb2019-12-13 20:41:13 -080075 ctx.Register(config)
Colin Cross33b2fb72019-05-14 14:07:01 -070076
77 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
78 android.FailIfErrored(t, errs)
79 _, errs = ctx.PrepareBuildActions(config)
80 android.FailIfErrored(t, errs)
81
82 // Verify that all the modules exist and that their dependencies were connected correctly
Colin Cross7113d202019-11-20 16:39:12 -080083 liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_shared").Module()
84 libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_static").Module()
85 libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_shared").Module()
86 libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_static").Module()
Colin Cross33b2fb72019-05-14 14:07:01 -070087
Colin Cross7113d202019-11-20 16:39:12 -080088 prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_shared").Module()
89 prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_static").Module()
90 prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_shared").Module()
91 prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_static").Module()
Colin Cross33b2fb72019-05-14 14:07:01 -070092
93 hasDep := func(m android.Module, wantDep android.Module) bool {
94 t.Helper()
95 var found bool
96 ctx.VisitDirectDeps(m, func(dep blueprint.Module) {
97 if dep == wantDep {
98 found = true
99 }
100 })
101 return found
102 }
103
104 if !hasDep(liba, prebuiltLiba) {
105 t.Errorf("liba missing dependency on prebuilt_liba")
106 }
107
108 if !hasDep(libb, prebuiltLibb) {
109 t.Errorf("libb missing dependency on prebuilt_libb")
110 }
111
112 if !hasDep(libd, prebuiltLibd) {
113 t.Errorf("libd missing dependency on prebuilt_libd")
114 }
115
116 if !hasDep(libe, prebuiltLibe) {
117 t.Errorf("libe missing dependency on prebuilt_libe")
118 }
119}