Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | |
| 22 | "github.com/google/blueprint" |
| 23 | ) |
| 24 | |
| 25 | func 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 | |
| 71 | config := android.TestArchConfig(buildDir, nil) |
| 72 | |
Colin Cross | 9a94287 | 2019-05-14 15:44:26 -0700 | [diff] [blame] | 73 | ctx := CreateTestContext(bp, fs, android.Android) |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 74 | |
| 75 | ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(prebuiltSharedLibraryFactory)) |
| 76 | ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(prebuiltStaticLibraryFactory)) |
| 77 | ctx.RegisterModuleType("cc_prebuilt_binary", android.ModuleFactoryAdaptor(prebuiltBinaryFactory)) |
| 78 | |
| 79 | ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) |
| 80 | ctx.PostDepsMutators(android.RegisterPrebuiltsPostDepsMutators) |
| 81 | |
| 82 | ctx.Register() |
| 83 | |
| 84 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 85 | android.FailIfErrored(t, errs) |
| 86 | _, errs = ctx.PrepareBuildActions(config) |
| 87 | android.FailIfErrored(t, errs) |
| 88 | |
| 89 | // Verify that all the modules exist and that their dependencies were connected correctly |
| 90 | liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_core_shared").Module() |
| 91 | libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_core_static").Module() |
| 92 | libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_core_shared").Module() |
| 93 | libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_core_static").Module() |
| 94 | |
| 95 | prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_core_shared").Module() |
| 96 | prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_core_static").Module() |
| 97 | prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_core_shared").Module() |
| 98 | prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_core_static").Module() |
| 99 | |
| 100 | hasDep := func(m android.Module, wantDep android.Module) bool { |
| 101 | t.Helper() |
| 102 | var found bool |
| 103 | ctx.VisitDirectDeps(m, func(dep blueprint.Module) { |
| 104 | if dep == wantDep { |
| 105 | found = true |
| 106 | } |
| 107 | }) |
| 108 | return found |
| 109 | } |
| 110 | |
| 111 | if !hasDep(liba, prebuiltLiba) { |
| 112 | t.Errorf("liba missing dependency on prebuilt_liba") |
| 113 | } |
| 114 | |
| 115 | if !hasDep(libb, prebuiltLibb) { |
| 116 | t.Errorf("libb missing dependency on prebuilt_libb") |
| 117 | } |
| 118 | |
| 119 | if !hasDep(libd, prebuiltLibd) { |
| 120 | t.Errorf("libd missing dependency on prebuilt_libd") |
| 121 | } |
| 122 | |
| 123 | if !hasDep(libe, prebuiltLibe) { |
| 124 | t.Errorf("libe missing dependency on prebuilt_libe") |
| 125 | } |
| 126 | } |