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 |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | type vndkdep struct { |
| 49 | Properties VndkProperties |
| 50 | } |
| 51 | |
| 52 | func (vndk *vndkdep) props() []interface{} { |
| 53 | return []interface{}{&vndk.Properties} |
| 54 | } |
| 55 | |
| 56 | func (vndk *vndkdep) begin(ctx BaseModuleContext) {} |
| 57 | |
| 58 | func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 59 | return deps |
| 60 | } |
| 61 | |
| 62 | func (vndk *vndkdep) isVndk() bool { |
| 63 | return Bool(vndk.Properties.Vndk.Enabled) |
| 64 | } |
| 65 | |
| 66 | func (vndk *vndkdep) isVndkSp() bool { |
| 67 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 68 | } |
| 69 | |
| 70 | func (vndk *vndkdep) typeName() string { |
| 71 | if !vndk.isVndk() { |
| 72 | return "native:vendor" |
| 73 | } |
| 74 | if !vndk.isVndkSp() { |
| 75 | return "native:vendor:vndk" |
| 76 | } |
| 77 | return "native:vendor:vndksp" |
| 78 | } |
| 79 | |
| 80 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module) { |
| 81 | if to.linker == nil { |
| 82 | return |
| 83 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 84 | if !vndk.isVndk() { |
| 85 | // Non-VNDK modules (those installed to /vendor) can't depend on modules marked with |
| 86 | // vendor_available: false. |
| 87 | violation := false |
| 88 | if lib, ok := to.linker.(*llndkStubDecorator); ok && !lib.Properties.Vendor_available { |
| 89 | violation = true |
| 90 | } else { |
| 91 | if _, ok := to.linker.(libraryInterface); ok && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) { |
| 92 | // Vendor_available == nil && !Bool(Vendor_available) should be okay since |
| 93 | // it means a vendor-only library which is a valid dependency for non-VNDK |
| 94 | // modules. |
| 95 | violation = true |
| 96 | } |
| 97 | } |
| 98 | if violation { |
| 99 | ctx.ModuleErrorf("Vendor module that is not VNDK should not link to %q which is marked as `vendor_available: false`", to.Name()) |
| 100 | } |
| 101 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 102 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 103 | // Check only shared libraries. |
| 104 | // Other (static and LL-NDK) libraries are allowed to link. |
| 105 | return |
| 106 | } |
| 107 | if !to.Properties.UseVndk { |
| 108 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 109 | vndk.typeName(), to.Name()) |
| 110 | return |
| 111 | } |
| 112 | if to.vndkdep == nil { |
| 113 | return |
| 114 | } |
| 115 | if (vndk.isVndk() && !to.vndkdep.isVndk()) || (vndk.isVndkSp() && !to.vndkdep.isVndkSp()) { |
| 116 | ctx.ModuleErrorf("(%s) should not link to %q(%s)", |
| 117 | vndk.typeName(), to.Name(), to.vndkdep.typeName()) |
| 118 | return |
| 119 | } |
| 120 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 121 | |
| 122 | var ( |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 123 | vndkCoreLibraries []string |
| 124 | vndkSpLibraries []string |
| 125 | llndkLibraries []string |
| 126 | vndkPrivateLibraries []string |
| 127 | vndkLibrariesLock sync.Mutex |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 128 | ) |
| 129 | |
| 130 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 131 | func vndkMutator(mctx android.BottomUpMutatorContext) { |
| 132 | if m, ok := mctx.Module().(*Module); ok { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 133 | if lib, ok := m.linker.(*llndkStubDecorator); ok { |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 134 | vndkLibrariesLock.Lock() |
| 135 | defer vndkLibrariesLock.Unlock() |
| 136 | name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix) |
| 137 | if !inList(name, llndkLibraries) { |
| 138 | llndkLibraries = append(llndkLibraries, name) |
Colin Cross | 766efbc | 2017-08-17 14:55:15 -0700 | [diff] [blame] | 139 | sort.Strings(llndkLibraries) |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 140 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 141 | if !lib.Properties.Vendor_available { |
| 142 | if !inList(name, vndkPrivateLibraries) { |
| 143 | vndkPrivateLibraries = append(vndkPrivateLibraries, name) |
| 144 | sort.Strings(vndkPrivateLibraries) |
| 145 | } |
| 146 | } |
| 147 | } else { |
| 148 | lib, is_lib := m.linker.(*libraryDecorator) |
| 149 | prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker) |
| 150 | if (is_lib && lib.shared()) || (is_prebuilt_lib && prebuilt_lib.shared()) { |
| 151 | name := strings.TrimPrefix(m.Name(), "prebuilt_") |
| 152 | if m.vndkdep.isVndk() { |
| 153 | vndkLibrariesLock.Lock() |
| 154 | defer vndkLibrariesLock.Unlock() |
| 155 | if m.vndkdep.isVndkSp() { |
| 156 | if !inList(name, vndkSpLibraries) { |
| 157 | vndkSpLibraries = append(vndkSpLibraries, name) |
| 158 | sort.Strings(vndkSpLibraries) |
| 159 | } |
| 160 | } else { |
| 161 | if !inList(name, vndkCoreLibraries) { |
| 162 | vndkCoreLibraries = append(vndkCoreLibraries, name) |
| 163 | sort.Strings(vndkCoreLibraries) |
| 164 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 165 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 166 | if !Bool(m.VendorProperties.Vendor_available) { |
| 167 | if !inList(name, vndkPrivateLibraries) { |
| 168 | vndkPrivateLibraries = append(vndkPrivateLibraries, name) |
| 169 | sort.Strings(vndkPrivateLibraries) |
| 170 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | } |
| 174 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 175 | |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 176 | } |
| 177 | } |