Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1 | // Copyright 2017 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 ( |
Colin Cross | 766efbc | 2017-08-17 14:55:15 -0700 | [diff] [blame] | 18 | "sort" |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 19 | "strings" |
| 20 | "sync" |
| 21 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 22 | "android/soong/android" |
| 23 | ) |
| 24 | |
| 25 | type VndkProperties struct { |
| 26 | Vndk struct { |
| 27 | // declared as a VNDK or VNDK-SP module. The vendor variant |
| 28 | // will be installed in /system instead of /vendor partition. |
| 29 | // |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 30 | // `vendor_vailable` must be explicitly set to either true or |
| 31 | // false together with `vndk: {enabled: true}`. |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 32 | Enabled *bool |
| 33 | |
| 34 | // declared as a VNDK-SP module, which is a subset of VNDK. |
| 35 | // |
| 36 | // `vndk: { enabled: true }` must set together. |
| 37 | // |
| 38 | // All these modules are allowed to link to VNDK-SP or LL-NDK |
| 39 | // modules only. Other dependency will cause link-type errors. |
| 40 | // |
| 41 | // If `support_system_process` is not set or set to false, |
| 42 | // the module is VNDK-core and can link to other VNDK-core, |
| 43 | // VNDK-SP or LL-NDK modules only. |
| 44 | Support_system_process *bool |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 45 | |
| 46 | // Extending another module |
| 47 | Extends *string |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | type vndkdep struct { |
| 52 | Properties VndkProperties |
| 53 | } |
| 54 | |
| 55 | func (vndk *vndkdep) props() []interface{} { |
| 56 | return []interface{}{&vndk.Properties} |
| 57 | } |
| 58 | |
| 59 | func (vndk *vndkdep) begin(ctx BaseModuleContext) {} |
| 60 | |
| 61 | func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 62 | return deps |
| 63 | } |
| 64 | |
| 65 | func (vndk *vndkdep) isVndk() bool { |
| 66 | return Bool(vndk.Properties.Vndk.Enabled) |
| 67 | } |
| 68 | |
| 69 | func (vndk *vndkdep) isVndkSp() bool { |
| 70 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 71 | } |
| 72 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 73 | func (vndk *vndkdep) isVndkExt() bool { |
| 74 | return vndk.Properties.Vndk.Extends != nil |
| 75 | } |
| 76 | |
| 77 | func (vndk *vndkdep) getVndkExtendsModuleName() string { |
| 78 | return String(vndk.Properties.Vndk.Extends) |
| 79 | } |
| 80 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 81 | func (vndk *vndkdep) typeName() string { |
| 82 | if !vndk.isVndk() { |
| 83 | return "native:vendor" |
| 84 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 85 | if !vndk.isVndkExt() { |
| 86 | if !vndk.isVndkSp() { |
| 87 | return "native:vendor:vndk" |
| 88 | } |
| 89 | return "native:vendor:vndksp" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 90 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 91 | if !vndk.isVndkSp() { |
| 92 | return "native:vendor:vndkext" |
| 93 | } |
| 94 | return "native:vendor:vndkspext" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 95 | } |
| 96 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 97 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag dependencyTag) { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 98 | if to.linker == nil { |
| 99 | return |
| 100 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 101 | if !vndk.isVndk() { |
| 102 | // Non-VNDK modules (those installed to /vendor) can't depend on modules marked with |
| 103 | // vendor_available: false. |
| 104 | violation := false |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 105 | if lib, ok := to.linker.(*llndkStubDecorator); ok && !Bool(lib.Properties.Vendor_available) { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 106 | violation = true |
| 107 | } else { |
| 108 | if _, ok := to.linker.(libraryInterface); ok && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) { |
| 109 | // Vendor_available == nil && !Bool(Vendor_available) should be okay since |
| 110 | // it means a vendor-only library which is a valid dependency for non-VNDK |
| 111 | // modules. |
| 112 | violation = true |
| 113 | } |
| 114 | } |
| 115 | if violation { |
| 116 | ctx.ModuleErrorf("Vendor module that is not VNDK should not link to %q which is marked as `vendor_available: false`", to.Name()) |
| 117 | } |
| 118 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 119 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 120 | // Check only shared libraries. |
| 121 | // Other (static and LL-NDK) libraries are allowed to link. |
| 122 | return |
| 123 | } |
| 124 | if !to.Properties.UseVndk { |
| 125 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 126 | vndk.typeName(), to.Name()) |
| 127 | return |
| 128 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 129 | if tag == vndkExtDepTag { |
| 130 | // Ensure `extends: "name"` property refers a vndk module that has vendor_available |
| 131 | // and has identical vndk properties. |
| 132 | if to.vndkdep == nil || !to.vndkdep.isVndk() { |
| 133 | ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name()) |
| 134 | return |
| 135 | } |
| 136 | if vndk.isVndkSp() != to.vndkdep.isVndkSp() { |
| 137 | ctx.ModuleErrorf( |
| 138 | "`extends` refers a module %q with mismatched support_system_process", |
| 139 | to.Name()) |
| 140 | return |
| 141 | } |
| 142 | if !Bool(to.VendorProperties.Vendor_available) { |
| 143 | ctx.ModuleErrorf( |
| 144 | "`extends` refers module %q which does not have `vendor_available: true`", |
| 145 | to.Name()) |
| 146 | return |
| 147 | } |
| 148 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 149 | if to.vndkdep == nil { |
| 150 | return |
| 151 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 152 | |
| 153 | // VNDK-core and VNDK-SP must not depend on VNDK extensions. |
| 154 | if (vndk.isVndk() || vndk.isVndkSp()) && !vndk.isVndkExt() && to.vndkdep.isVndkExt() { |
| 155 | ctx.ModuleErrorf("(%s) should not link to %q (%s)", |
| 156 | vndk.typeName(), to.Name(), to.vndkdep.typeName()) |
| 157 | return |
| 158 | } |
| 159 | |
| 160 | // VNDK-core must be only depend on VNDK-SP or LL-NDK. VNDK-SP must only depend on |
| 161 | // LL-NDK, regardless the extension status. VNDK-Ext may depend on vendor libraries, but |
| 162 | // VNDK-SP-Ext must remain self-contained. |
| 163 | if (vndk.isVndk() && !to.vndkdep.isVndk() && !vndk.isVndkExt()) || |
| 164 | (vndk.isVndkSp() && !to.vndkdep.isVndkSp()) { |
| 165 | ctx.ModuleErrorf("(%s) should not link to %q (%s)", |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 166 | vndk.typeName(), to.Name(), to.vndkdep.typeName()) |
| 167 | return |
| 168 | } |
| 169 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 170 | |
| 171 | var ( |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 172 | vndkCoreLibraries []string |
| 173 | vndkSpLibraries []string |
| 174 | llndkLibraries []string |
| 175 | vndkPrivateLibraries []string |
| 176 | vndkLibrariesLock sync.Mutex |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 177 | ) |
| 178 | |
| 179 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 180 | func vndkMutator(mctx android.BottomUpMutatorContext) { |
Jiyong Park | 4b03222 | 2018-02-16 22:14:07 +0900 | [diff] [blame] | 181 | if m, ok := mctx.Module().(*Module); ok && m.Enabled() { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 182 | if lib, ok := m.linker.(*llndkStubDecorator); ok { |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 183 | vndkLibrariesLock.Lock() |
| 184 | defer vndkLibrariesLock.Unlock() |
| 185 | name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix) |
| 186 | if !inList(name, llndkLibraries) { |
| 187 | llndkLibraries = append(llndkLibraries, name) |
Colin Cross | 766efbc | 2017-08-17 14:55:15 -0700 | [diff] [blame] | 188 | sort.Strings(llndkLibraries) |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 189 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 190 | if !Bool(lib.Properties.Vendor_available) { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 191 | if !inList(name, vndkPrivateLibraries) { |
| 192 | vndkPrivateLibraries = append(vndkPrivateLibraries, name) |
| 193 | sort.Strings(vndkPrivateLibraries) |
| 194 | } |
| 195 | } |
| 196 | } else { |
| 197 | lib, is_lib := m.linker.(*libraryDecorator) |
| 198 | prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker) |
| 199 | if (is_lib && lib.shared()) || (is_prebuilt_lib && prebuilt_lib.shared()) { |
| 200 | name := strings.TrimPrefix(m.Name(), "prebuilt_") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 201 | if m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 202 | vndkLibrariesLock.Lock() |
| 203 | defer vndkLibrariesLock.Unlock() |
| 204 | if m.vndkdep.isVndkSp() { |
| 205 | if !inList(name, vndkSpLibraries) { |
| 206 | vndkSpLibraries = append(vndkSpLibraries, name) |
| 207 | sort.Strings(vndkSpLibraries) |
| 208 | } |
| 209 | } else { |
| 210 | if !inList(name, vndkCoreLibraries) { |
| 211 | vndkCoreLibraries = append(vndkCoreLibraries, name) |
| 212 | sort.Strings(vndkCoreLibraries) |
| 213 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 214 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 215 | if !Bool(m.VendorProperties.Vendor_available) { |
| 216 | if !inList(name, vndkPrivateLibraries) { |
| 217 | vndkPrivateLibraries = append(vndkPrivateLibraries, name) |
| 218 | sort.Strings(vndkPrivateLibraries) |
| 219 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | } |