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{}) { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 69 | module, library := NewLibrary(android.HostAndDeviceSupported) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame^] | 70 | library.BuildOnlyShared() |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 71 | module.compiler = nil |
| 72 | |
| 73 | prebuilt := &prebuiltLibraryLinker{ |
| 74 | libraryDecorator: library, |
| 75 | } |
| 76 | module.linker = prebuilt |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame^] | 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 |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 125 | |
| 126 | return module.Init() |
| 127 | } |