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 ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | type VndkProperties struct { |
| 22 | Vndk struct { |
| 23 | // declared as a VNDK or VNDK-SP module. The vendor variant |
| 24 | // will be installed in /system instead of /vendor partition. |
| 25 | // |
| 26 | // `vendor_available: true` must set to together for VNDK |
| 27 | // modules. |
| 28 | Enabled *bool |
| 29 | |
| 30 | // declared as a VNDK-SP module, which is a subset of VNDK. |
| 31 | // |
| 32 | // `vndk: { enabled: true }` must set together. |
| 33 | // |
| 34 | // All these modules are allowed to link to VNDK-SP or LL-NDK |
| 35 | // modules only. Other dependency will cause link-type errors. |
| 36 | // |
| 37 | // If `support_system_process` is not set or set to false, |
| 38 | // the module is VNDK-core and can link to other VNDK-core, |
| 39 | // VNDK-SP or LL-NDK modules only. |
| 40 | Support_system_process *bool |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | type vndkdep struct { |
| 45 | Properties VndkProperties |
| 46 | } |
| 47 | |
| 48 | func (vndk *vndkdep) props() []interface{} { |
| 49 | return []interface{}{&vndk.Properties} |
| 50 | } |
| 51 | |
| 52 | func (vndk *vndkdep) begin(ctx BaseModuleContext) {} |
| 53 | |
| 54 | func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 55 | return deps |
| 56 | } |
| 57 | |
| 58 | func (vndk *vndkdep) isVndk() bool { |
| 59 | return Bool(vndk.Properties.Vndk.Enabled) |
| 60 | } |
| 61 | |
| 62 | func (vndk *vndkdep) isVndkSp() bool { |
| 63 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 64 | } |
| 65 | |
| 66 | func (vndk *vndkdep) typeName() string { |
| 67 | if !vndk.isVndk() { |
| 68 | return "native:vendor" |
| 69 | } |
| 70 | if !vndk.isVndkSp() { |
| 71 | return "native:vendor:vndk" |
| 72 | } |
| 73 | return "native:vendor:vndksp" |
| 74 | } |
| 75 | |
| 76 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module) { |
| 77 | if to.linker == nil { |
| 78 | return |
| 79 | } |
| 80 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 81 | // Check only shared libraries. |
| 82 | // Other (static and LL-NDK) libraries are allowed to link. |
| 83 | return |
| 84 | } |
| 85 | if !to.Properties.UseVndk { |
| 86 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 87 | vndk.typeName(), to.Name()) |
| 88 | return |
| 89 | } |
| 90 | if to.vndkdep == nil { |
| 91 | return |
| 92 | } |
| 93 | if (vndk.isVndk() && !to.vndkdep.isVndk()) || (vndk.isVndkSp() && !to.vndkdep.isVndkSp()) { |
| 94 | ctx.ModuleErrorf("(%s) should not link to %q(%s)", |
| 95 | vndk.typeName(), to.Name(), to.vndkdep.typeName()) |
| 96 | return |
| 97 | } |
| 98 | } |