github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/cc/vndk_prebuilt.go (about) 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 "strings" 19 20 "android/soong/android" 21 ) 22 23 var ( 24 vndkSuffix = ".vndk." 25 ) 26 27 // Creates vndk prebuilts that include the VNDK version. 28 // 29 // Example: 30 // 31 // vndk_prebuilt_shared { 32 // name: "libfoo", 33 // version: "27.1.0", 34 // vendor_available: true, 35 // vndk: { 36 // enabled: true, 37 // }, 38 // export_include_dirs: ["include/external/libfoo/vndk_include"], 39 // arch: { 40 // arm64: { 41 // srcs: ["arm/lib64/libfoo.so"], 42 // }, 43 // arm: { 44 // srcs: ["arm/lib/libfoo.so"], 45 // }, 46 // }, 47 // } 48 // 49 type vndkPrebuiltProperties struct { 50 // VNDK snapshot version. 51 Version *string 52 53 // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64_ab') 54 Target_arch *string 55 56 // Prebuilt files for each arch. 57 Srcs []string `android:"arch_variant"` 58 } 59 60 type vndkPrebuiltLibraryDecorator struct { 61 *libraryDecorator 62 properties vndkPrebuiltProperties 63 } 64 65 func (p *vndkPrebuiltLibraryDecorator) Name(name string) string { 66 return name + p.NameSuffix() 67 } 68 69 func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string { 70 if p.arch() != "" { 71 return vndkSuffix + p.version() + "." + p.arch() 72 } 73 return vndkSuffix + p.version() 74 } 75 76 func (p *vndkPrebuiltLibraryDecorator) version() string { 77 return String(p.properties.Version) 78 } 79 80 func (p *vndkPrebuiltLibraryDecorator) arch() string { 81 return String(p.properties.Target_arch) 82 } 83 84 func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { 85 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) 86 return p.libraryDecorator.linkerFlags(ctx, flags) 87 } 88 89 func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) android.Path { 90 if len(p.properties.Srcs) == 0 { 91 ctx.PropertyErrorf("srcs", "missing prebuilt source file") 92 return nil 93 } 94 95 if len(p.properties.Srcs) > 1 { 96 ctx.PropertyErrorf("srcs", "multiple prebuilt source files") 97 return nil 98 } 99 100 return android.PathForModuleSrc(ctx, p.properties.Srcs[0]) 101 } 102 103 func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, 104 flags Flags, deps PathDeps, objs Objects) android.Path { 105 if len(p.properties.Srcs) > 0 && p.shared() { 106 // current VNDK prebuilts are only shared libs. 107 return p.singleSourcePath(ctx) 108 } 109 return nil 110 } 111 112 func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) { 113 arches := ctx.DeviceConfig().Arches() 114 if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { 115 return 116 } 117 if p.shared() { 118 if ctx.isVndkSp() { 119 p.baseInstaller.subDir = "vndk-sp-" + p.version() 120 } else if ctx.isVndk() { 121 p.baseInstaller.subDir = "vndk-" + p.version() 122 } 123 p.baseInstaller.install(ctx, file) 124 } 125 } 126 127 func vndkPrebuiltSharedLibrary() *Module { 128 module, library := NewLibrary(android.DeviceSupported) 129 library.BuildOnlyShared() 130 module.stl = nil 131 module.sanitize = nil 132 library.StripProperties.Strip.None = BoolPtr(true) 133 134 prebuilt := &vndkPrebuiltLibraryDecorator{ 135 libraryDecorator: library, 136 } 137 138 module.compiler = nil 139 module.linker = prebuilt 140 module.installer = prebuilt 141 142 module.AddProperties( 143 &prebuilt.properties, 144 ) 145 146 return module 147 } 148 149 func vndkPrebuiltSharedFactory() android.Module { 150 module := vndkPrebuiltSharedLibrary() 151 return module.Init() 152 } 153 154 func init() { 155 android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory) 156 }