Colin Cross | b916a38 | 2016-07-29 17:28:03 -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 ( |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | // |
| 22 | // Device libraries shipped with gcc |
| 23 | // |
| 24 | |
| 25 | func init() { |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 26 | android.RegisterModuleType("toolchain_library", ToolchainLibraryFactory) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 29 | type toolchainLibraryProperties struct { |
| 30 | // the prebuilt toolchain library, as a path from the top of the source tree |
| 31 | Src *string `android:"arch_variant"` |
Yi Kong | c49c393 | 2019-10-15 02:01:19 -0700 | [diff] [blame] | 32 | |
| 33 | // Repack the archive with only the selected objects. |
| 34 | Repack_objects_to_keep []string `android:"arch_variant"` |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 37 | type toolchainLibraryDecorator struct { |
| 38 | *libraryDecorator |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 39 | stripper Stripper |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 40 | |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 41 | Properties toolchainLibraryProperties |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 44 | func (*toolchainLibraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 45 | // toolchain libraries can't have any dependencies |
| 46 | return deps |
| 47 | } |
| 48 | |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 49 | func (library *toolchainLibraryDecorator) linkerProps() []interface{} { |
| 50 | var props []interface{} |
| 51 | props = append(props, library.libraryDecorator.linkerProps()...) |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 52 | return append(props, &library.Properties, &library.stripper.StripProperties) |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Patrice Arruda | ea3fcdf | 2019-04-03 14:37:46 -0700 | [diff] [blame] | 55 | // toolchain_library is used internally by the build tool to link the specified |
| 56 | // static library in src property to the device libraries that are shipped with |
| 57 | // gcc. |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 58 | func ToolchainLibraryFactory() android.Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 59 | module, library := NewLibrary(android.HostAndDeviceSupported) |
| 60 | library.BuildOnlyStatic() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 61 | toolchainLibrary := &toolchainLibraryDecorator{ |
| 62 | libraryDecorator: library, |
| 63 | } |
| 64 | module.compiler = toolchainLibrary |
| 65 | module.linker = toolchainLibrary |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 66 | module.stl = nil |
| 67 | module.sanitize = nil |
| 68 | module.installer = nil |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 69 | module.Properties.Sdk_version = StringPtr("current") |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 70 | return module.Init() |
| 71 | } |
| 72 | |
| 73 | func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 74 | deps PathDeps) Objects { |
| 75 | return Objects{} |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | func (library *toolchainLibraryDecorator) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 79 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 80 | |
Dan Willemsen | feea4df | 2018-10-07 18:16:48 -0700 | [diff] [blame] | 81 | if library.Properties.Src == nil { |
| 82 | ctx.PropertyErrorf("src", "No library source specified") |
| 83 | return android.PathForSource(ctx, "") |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 86 | srcPath := android.PathForSource(ctx, *library.Properties.Src) |
| 87 | |
| 88 | if library.stripper.StripProperties.Strip.Keep_symbols_list != nil { |
| 89 | fileName := ctx.ModuleName() + staticLibraryExtension |
| 90 | outputFile := android.PathForModuleOut(ctx, fileName) |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 91 | stripFlags := flagsToStripFlags(flags) |
| 92 | library.stripper.StripStaticLib(ctx, srcPath, outputFile, stripFlags) |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 93 | return outputFile |
| 94 | } |
| 95 | |
Yi Kong | c49c393 | 2019-10-15 02:01:19 -0700 | [diff] [blame] | 96 | if library.Properties.Repack_objects_to_keep != nil { |
| 97 | fileName := ctx.ModuleName() + staticLibraryExtension |
| 98 | outputFile := android.PathForModuleOut(ctx, fileName) |
| 99 | TransformArchiveRepack(ctx, srcPath, outputFile, library.Properties.Repack_objects_to_keep) |
| 100 | |
| 101 | return outputFile |
| 102 | } |
| 103 | |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 104 | return srcPath |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 105 | } |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 106 | |
| 107 | func (library *toolchainLibraryDecorator) nativeCoverage() bool { |
| 108 | return false |
| 109 | } |