1 // Copyright 2016 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 "github.com/google/blueprint" 21 ) 22 23 func init() { 24 android.RegisterModuleType("cc_prebuilt_library_shared", prebuiltSharedLibraryFactory) 25 android.RegisterModuleType("cc_prebuilt_library_static", prebuiltStaticLibraryFactory) 26 android.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) 27 } 28 29 type prebuiltLinkerInterface interface { 30 Name(string) string 31 prebuilt() *android.Prebuilt 32 } 33 34 type prebuiltLinker struct { 35 android.Prebuilt 36 } 37 38 func (p *prebuiltLinker) prebuilt() *android.Prebuilt { 39 return &p.Prebuilt 40 } 41 42 type prebuiltLibraryLinker struct { 43 *libraryDecorator 44 prebuiltLinker 45 } 46 47 var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) 48 49 func (p *prebuiltLibraryLinker) linkerProps() []interface{} { 50 props := p.libraryDecorator.linkerProps() 51 return append(props, &p.Prebuilt.Properties) 52 } 53 54 func (p *prebuiltLibraryLinker) link(ctx ModuleContext, 55 flags Flags, deps PathDeps, objs Objects) android.Path { 56 // TODO(ccross): verify shared library dependencies 57 if len(p.Prebuilt.Properties.Srcs) > 0 { 58 p.libraryDecorator.exportIncludes(ctx, "-I") 59 p.libraryDecorator.reexportFlags(deps.ReexportedFlags) 60 p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps) 61 // TODO(ccross): .toc optimization, stripping, packing 62 return p.Prebuilt.Path(ctx) 63 } 64 65 return nil 66 } 67 68 func prebuiltSharedLibraryFactory() (blueprint.Module, []interface{}) { 69 module, library := NewLibrary(android.HostAndDeviceSupported) 70 library.BuildOnlyShared() 71 module.compiler = nil 72 73 prebuilt := &prebuiltLibraryLinker{ 74 libraryDecorator: library, 75 } 76 module.linker = prebuilt 77 78 return module.Init() 79 } 80 81 func prebuiltStaticLibraryFactory() (blueprint.Module, []interface{}) { 82 module, library := NewLibrary(android.HostAndDeviceSupported) 83 library.BuildOnlyStatic() 84 module.compiler = nil 85 86 prebuilt := &prebuiltLibraryLinker{ 87 libraryDecorator: library, 88 } 89 module.linker = prebuilt 90 91 return module.Init() 92 } 93 94 type prebuiltBinaryLinker struct { 95 *binaryDecorator 96 prebuiltLinker 97 } 98 99 var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil) 100 101 func (p *prebuiltBinaryLinker) linkerProps() []interface{} { 102 props := p.binaryDecorator.linkerProps() 103 return append(props, &p.Prebuilt.Properties) 104 } 105 106 func (p *prebuiltBinaryLinker) link(ctx ModuleContext, 107 flags Flags, deps PathDeps, objs Objects) android.Path { 108 // TODO(ccross): verify shared library dependencies 109 if len(p.Prebuilt.Properties.Srcs) > 0 { 110 // TODO(ccross): .toc optimization, stripping, packing 111 return p.Prebuilt.Path(ctx) 112 } 113 114 return nil 115 } 116 117 func prebuiltBinaryFactory() (blueprint.Module, []interface{}) { 118 module, binary := NewBinary(android.HostAndDeviceSupported) 119 module.compiler = nil 120 121 prebuilt := &prebuiltBinaryLinker{ 122 binaryDecorator: binary, 123 } 124 module.linker = prebuilt 125 126 return module.Init() 127 } 128