Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 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() { |
Colin Cross | dfee1bc | 2017-03-17 14:03:18 -0700 | [diff] [blame] | 24 | android.RegisterModuleType("cc_prebuilt_library_shared", prebuiltSharedLibraryFactory) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 25 | android.RegisterModuleType("cc_prebuilt_library_static", prebuiltStaticLibraryFactory) |
| 26 | android.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | type prebuiltLinkerInterface interface { |
| 30 | Name(string) string |
| 31 | prebuilt() *android.Prebuilt |
| 32 | } |
| 33 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 34 | type prebuiltLinker struct { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 35 | android.Prebuilt |
| 36 | } |
| 37 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 38 | func (p *prebuiltLinker) prebuilt() *android.Prebuilt { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 39 | return &p.Prebuilt |
| 40 | } |
| 41 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 42 | type prebuiltLibraryLinker struct { |
| 43 | *libraryDecorator |
| 44 | prebuiltLinker |
| 45 | } |
| 46 | |
| 47 | var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) |
| 48 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 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, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 55 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 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{}) { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame^] | 69 | module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported) |
| 70 | return module.Init() |
| 71 | } |
| 72 | |
| 73 | func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
| 74 | module, library := NewLibrary(hod) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 75 | library.BuildOnlyShared() |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 76 | module.compiler = nil |
| 77 | |
| 78 | prebuilt := &prebuiltLibraryLinker{ |
| 79 | libraryDecorator: library, |
| 80 | } |
| 81 | module.linker = prebuilt |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 82 | |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame^] | 83 | return module, library |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | func prebuiltStaticLibraryFactory() (blueprint.Module, []interface{}) { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame^] | 87 | module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported) |
| 88 | return module.Init() |
| 89 | } |
| 90 | |
| 91 | func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
| 92 | module, library := NewLibrary(hod) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 93 | library.BuildOnlyStatic() |
| 94 | module.compiler = nil |
| 95 | |
| 96 | prebuilt := &prebuiltLibraryLinker{ |
| 97 | libraryDecorator: library, |
| 98 | } |
| 99 | module.linker = prebuilt |
| 100 | |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame^] | 101 | return module, library |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | type prebuiltBinaryLinker struct { |
| 105 | *binaryDecorator |
| 106 | prebuiltLinker |
| 107 | } |
| 108 | |
| 109 | var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil) |
| 110 | |
| 111 | func (p *prebuiltBinaryLinker) linkerProps() []interface{} { |
| 112 | props := p.binaryDecorator.linkerProps() |
| 113 | return append(props, &p.Prebuilt.Properties) |
| 114 | } |
| 115 | |
| 116 | func (p *prebuiltBinaryLinker) link(ctx ModuleContext, |
| 117 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 118 | // TODO(ccross): verify shared library dependencies |
| 119 | if len(p.Prebuilt.Properties.Srcs) > 0 { |
| 120 | // TODO(ccross): .toc optimization, stripping, packing |
| 121 | return p.Prebuilt.Path(ctx) |
| 122 | } |
| 123 | |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | func prebuiltBinaryFactory() (blueprint.Module, []interface{}) { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame^] | 128 | module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported) |
| 129 | return module.Init() |
| 130 | } |
| 131 | |
| 132 | func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { |
| 133 | module, binary := NewBinary(hod) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 134 | module.compiler = nil |
| 135 | |
| 136 | prebuilt := &prebuiltBinaryLinker{ |
| 137 | binaryDecorator: binary, |
| 138 | } |
| 139 | module.linker = prebuilt |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 140 | |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame^] | 141 | return module, binary |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 142 | } |