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 15package cc 16 17import ( 18 "android/soong/android" 19) 20 21// 22// Device libraries shipped with gcc 23// 24 25func init() { 26 android.RegisterModuleType("toolchain_library", ToolchainLibraryFactory) 27} 28 29type toolchainLibraryProperties struct { 30 // the prebuilt toolchain library, as a path from the top of the source tree 31 Src *string `android:"arch_variant"` 32 33 // Repack the archive with only the selected objects. 34 Repack_objects_to_keep []string `android:"arch_variant"` 35} 36 37type toolchainLibraryDecorator struct { 38 *libraryDecorator 39 stripper Stripper 40 41 Properties toolchainLibraryProperties 42} 43 44func (*toolchainLibraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { 45 // toolchain libraries can't have any dependencies 46 return deps 47} 48 49func (library *toolchainLibraryDecorator) linkerProps() []interface{} { 50 var props []interface{} 51 props = append(props, library.libraryDecorator.linkerProps()...) 52 return append(props, &library.Properties, &library.stripper.StripProperties) 53} 54 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. 58func ToolchainLibraryFactory() android.Module { 59 module, library := NewLibrary(android.HostAndDeviceSupported) 60 library.BuildOnlyStatic() 61 toolchainLibrary := &toolchainLibraryDecorator{ 62 libraryDecorator: library, 63 } 64 module.compiler = toolchainLibrary 65 module.linker = toolchainLibrary 66 module.stl = nil 67 module.sanitize = nil 68 module.installer = nil 69 module.library = toolchainLibrary 70 module.Properties.Sdk_version = StringPtr("current") 71 return module.Init() 72} 73 74func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags, 75 deps PathDeps) Objects { 76 return Objects{} 77} 78 79func (library *toolchainLibraryDecorator) link(ctx ModuleContext, 80 flags Flags, deps PathDeps, objs Objects) android.Path { 81 82 if library.Properties.Src == nil { 83 ctx.PropertyErrorf("src", "No library source specified") 84 return android.PathForSource(ctx, "") 85 } 86 87 srcPath := android.PathForSource(ctx, *library.Properties.Src) 88 outputFile := android.Path(srcPath) 89 90 if library.Properties.Repack_objects_to_keep != nil { 91 fileName := ctx.ModuleName() + staticLibraryExtension 92 repackedPath := android.PathForModuleOut(ctx, fileName) 93 transformArchiveRepack(ctx, outputFile, repackedPath, library.Properties.Repack_objects_to_keep) 94 outputFile = repackedPath 95 } 96 97 if library.stripper.StripProperties.Strip.Keep_symbols_list != nil { 98 fileName := ctx.ModuleName() + staticLibraryExtension 99 strippedPath := android.PathForModuleOut(ctx, fileName) 100 stripFlags := flagsToStripFlags(flags) 101 library.stripper.StripStaticLib(ctx, outputFile, strippedPath, stripFlags) 102 outputFile = strippedPath 103 } 104 105 depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(outputFile).Build() 106 ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ 107 StaticLibrary: outputFile, 108 109 TransitiveStaticLibrariesForOrdering: depSet, 110 }) 111 112 return outputFile 113} 114 115func (library *toolchainLibraryDecorator) nativeCoverage() bool { 116 return false 117} 118