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 15package cc 16 17import ( 18 "sort" 19 "strings" 20 "sync" 21 22 "android/soong/android" 23) 24 25type 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 // 30 // `vendor_available: true` must set to together for VNDK 31 // modules. 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 48type vndkdep struct { 49 Properties VndkProperties 50} 51 52func (vndk *vndkdep) props() []interface{} { 53 return []interface{}{&vndk.Properties} 54} 55 56func (vndk *vndkdep) begin(ctx BaseModuleContext) {} 57 58func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps { 59 return deps 60} 61 62func (vndk *vndkdep) isVndk() bool { 63 return Bool(vndk.Properties.Vndk.Enabled) 64} 65 66func (vndk *vndkdep) isVndkSp() bool { 67 return Bool(vndk.Properties.Vndk.Support_system_process) 68} 69 70func (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 80func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module) { 81 if to.linker == nil { 82 return 83 } 84 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { 85 // Check only shared libraries. 86 // Other (static and LL-NDK) libraries are allowed to link. 87 return 88 } 89 if !to.Properties.UseVndk { 90 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", 91 vndk.typeName(), to.Name()) 92 return 93 } 94 if to.vndkdep == nil { 95 return 96 } 97 if (vndk.isVndk() && !to.vndkdep.isVndk()) || (vndk.isVndkSp() && !to.vndkdep.isVndkSp()) { 98 ctx.ModuleErrorf("(%s) should not link to %q(%s)", 99 vndk.typeName(), to.Name(), to.vndkdep.typeName()) 100 return 101 } 102} 103 104var ( 105 vndkCoreLibraries []string 106 vndkSpLibraries []string 107 llndkLibraries []string 108 vndkLibrariesLock sync.Mutex 109) 110 111// gather list of vndk-core, vndk-sp, and ll-ndk libs 112func vndkMutator(mctx android.BottomUpMutatorContext) { 113 if m, ok := mctx.Module().(*Module); ok { 114 if _, ok := m.linker.(*llndkStubDecorator); ok { 115 vndkLibrariesLock.Lock() 116 defer vndkLibrariesLock.Unlock() 117 name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix) 118 if !inList(name, llndkLibraries) { 119 llndkLibraries = append(llndkLibraries, name) 120 sort.Strings(llndkLibraries) 121 } 122 } else if lib, ok := m.linker.(*libraryDecorator); ok && lib.shared() { 123 if m.vndkdep.isVndk() { 124 vndkLibrariesLock.Lock() 125 defer vndkLibrariesLock.Unlock() 126 if m.vndkdep.isVndkSp() { 127 if !inList(m.Name(), vndkSpLibraries) { 128 vndkSpLibraries = append(vndkSpLibraries, m.Name()) 129 sort.Strings(vndkSpLibraries) 130 } 131 } else { 132 if !inList(m.Name(), vndkCoreLibraries) { 133 vndkCoreLibraries = append(vndkCoreLibraries, m.Name()) 134 sort.Strings(vndkCoreLibraries) 135 } 136 } 137 } 138 } 139 } 140} 141