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 ( |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame^] | 18 | "strings" |
| 19 | "sync" |
| 20 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | type VndkProperties struct { |
| 25 | Vndk struct { |
| 26 | // declared as a VNDK or VNDK-SP module. The vendor variant |
| 27 | // will be installed in /system instead of /vendor partition. |
| 28 | // |
| 29 | // `vendor_available: true` must set to together for VNDK |
| 30 | // modules. |
| 31 | Enabled *bool |
| 32 | |
| 33 | // declared as a VNDK-SP module, which is a subset of VNDK. |
| 34 | // |
| 35 | // `vndk: { enabled: true }` must set together. |
| 36 | // |
| 37 | // All these modules are allowed to link to VNDK-SP or LL-NDK |
| 38 | // modules only. Other dependency will cause link-type errors. |
| 39 | // |
| 40 | // If `support_system_process` is not set or set to false, |
| 41 | // the module is VNDK-core and can link to other VNDK-core, |
| 42 | // VNDK-SP or LL-NDK modules only. |
| 43 | Support_system_process *bool |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | type vndkdep struct { |
| 48 | Properties VndkProperties |
| 49 | } |
| 50 | |
| 51 | func (vndk *vndkdep) props() []interface{} { |
| 52 | return []interface{}{&vndk.Properties} |
| 53 | } |
| 54 | |
| 55 | func (vndk *vndkdep) begin(ctx BaseModuleContext) {} |
| 56 | |
| 57 | func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 58 | return deps |
| 59 | } |
| 60 | |
| 61 | func (vndk *vndkdep) isVndk() bool { |
| 62 | return Bool(vndk.Properties.Vndk.Enabled) |
| 63 | } |
| 64 | |
| 65 | func (vndk *vndkdep) isVndkSp() bool { |
| 66 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 67 | } |
| 68 | |
| 69 | func (vndk *vndkdep) typeName() string { |
| 70 | if !vndk.isVndk() { |
| 71 | return "native:vendor" |
| 72 | } |
| 73 | if !vndk.isVndkSp() { |
| 74 | return "native:vendor:vndk" |
| 75 | } |
| 76 | return "native:vendor:vndksp" |
| 77 | } |
| 78 | |
| 79 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module) { |
| 80 | if to.linker == nil { |
| 81 | return |
| 82 | } |
| 83 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 84 | // Check only shared libraries. |
| 85 | // Other (static and LL-NDK) libraries are allowed to link. |
| 86 | return |
| 87 | } |
| 88 | if !to.Properties.UseVndk { |
| 89 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 90 | vndk.typeName(), to.Name()) |
| 91 | return |
| 92 | } |
| 93 | if to.vndkdep == nil { |
| 94 | return |
| 95 | } |
| 96 | if (vndk.isVndk() && !to.vndkdep.isVndk()) || (vndk.isVndkSp() && !to.vndkdep.isVndkSp()) { |
| 97 | ctx.ModuleErrorf("(%s) should not link to %q(%s)", |
| 98 | vndk.typeName(), to.Name(), to.vndkdep.typeName()) |
| 99 | return |
| 100 | } |
| 101 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame^] | 102 | |
| 103 | var ( |
| 104 | vndkCoreLibraries []string |
| 105 | vndkSpLibraries []string |
| 106 | llndkLibraries []string |
| 107 | vndkLibrariesLock sync.Mutex |
| 108 | ) |
| 109 | |
| 110 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 111 | func vndkMutator(mctx android.BottomUpMutatorContext) { |
| 112 | if m, ok := mctx.Module().(*Module); ok { |
| 113 | if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 114 | vndkLibrariesLock.Lock() |
| 115 | defer vndkLibrariesLock.Unlock() |
| 116 | name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix) |
| 117 | if !inList(name, llndkLibraries) { |
| 118 | llndkLibraries = append(llndkLibraries, name) |
| 119 | } |
| 120 | } else if lib, ok := m.linker.(*libraryDecorator); ok && lib.shared() { |
| 121 | if m.vndkdep.isVndk() { |
| 122 | vndkLibrariesLock.Lock() |
| 123 | defer vndkLibrariesLock.Unlock() |
| 124 | if m.vndkdep.isVndkSp() { |
| 125 | if !inList(m.Name(), vndkSpLibraries) { |
| 126 | vndkSpLibraries = append(vndkSpLibraries, m.Name()) |
| 127 | } |
| 128 | } else { |
| 129 | if !inList(m.Name(), vndkCoreLibraries) { |
| 130 | vndkCoreLibraries = append(vndkCoreLibraries, m.Name()) |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |