Jiyong Park | 4c48f72 | 2017-01-20 08:57:02 +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 | "github.com/google/blueprint" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/cc/config" |
| 22 | ) |
| 23 | |
| 24 | type vndkExtLibraryProperties struct { |
| 25 | // Name of the VNDK library module that this VNDK-ext library is extending. |
| 26 | // This library will have the same file name and soname as the original VNDK |
| 27 | // library, but will be installed in /system/lib/vndk-ext rather |
| 28 | // than /system/lib/vndk. |
| 29 | Extends string |
| 30 | } |
| 31 | |
| 32 | type vndkExtLibraryDecorator struct { |
| 33 | *libraryDecorator |
| 34 | |
| 35 | properties vndkExtLibraryProperties |
| 36 | } |
| 37 | |
| 38 | func init() { |
| 39 | android.RegisterModuleType("vndk_ext_library", vndkExtLibraryFactory) |
| 40 | } |
| 41 | |
| 42 | func (deco *vndkExtLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 43 | extends := deco.properties.Extends |
| 44 | if extends != "" { |
| 45 | if config.IsVndkLibrary(extends) { |
| 46 | // TODO(jiyong): ensure that the module referenced by 'extends' exists. Don't know how... |
| 47 | // Adding a dependency was not successful because it leads to circular dependency |
| 48 | // in between this and the 'extends' module. |
| 49 | // Ideally, this should be something like follows: |
| 50 | // otherCtx = findModuleByName(deco.properties.Extends) |
| 51 | // if otherCtx != nil && otherCtx.isVndk() { |
| 52 | // deco.libaryDecorator.libName = otherCtx.getBaseName() |
| 53 | // } |
| 54 | deco.libraryDecorator.libName = extends |
| 55 | } else { |
| 56 | ctx.PropertyErrorf("extends", "%s should be a VNDK or VNDK-indirect library", extends) |
| 57 | } |
| 58 | } else { |
| 59 | ctx.PropertyErrorf("extends", "missing. A VNDK-ext library must extend existing VNDK library") |
| 60 | } |
| 61 | return deco.libraryDecorator.linkerFlags(ctx, flags) |
| 62 | } |
| 63 | |
| 64 | func (deco *vndkExtLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
| 65 | deco.libraryDecorator.baseInstaller.subDir = "vndk-ext" |
| 66 | deco.libraryDecorator.baseInstaller.install(ctx, file) |
| 67 | } |
| 68 | |
| 69 | func vndkExtLibraryFactory() (blueprint.Module, []interface{}) { |
| 70 | module, library := NewLibrary(android.DeviceSupported) |
| 71 | library.BuildOnlyShared() |
| 72 | |
| 73 | _, props := module.Init() |
| 74 | |
| 75 | deco := &vndkExtLibraryDecorator{ |
| 76 | libraryDecorator: library, |
| 77 | } |
| 78 | |
| 79 | module.installer = deco |
| 80 | module.linker = deco |
| 81 | |
| 82 | props = append(props, &deco.properties) |
| 83 | |
| 84 | return module, props |
| 85 | } |