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