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 34type toolchainLibraryDecorator struct { 35 *libraryDecorator 36 37 stripper 38 39 Properties toolchainLibraryProperties 40} 41 42func (*toolchainLibraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { 43 // toolchain libraries can't have any dependencies 44 return deps 45} 46 47func (library *toolchainLibraryDecorator) linkerProps() []interface{} { 48 var props []interface{} 49 props = append(props, library.libraryDecorator.linkerProps()...) 50 return append(props, &library.Properties, &library.stripper.StripProperties) 51} 52 53func ToolchainLibraryFactory() android.Module { 54 module, library := NewLibrary(android.HostAndDeviceSupported) 55 library.BuildOnlyStatic() 56 toolchainLibrary := &toolchainLibraryDecorator{ 57 libraryDecorator: library, 58 } 59 module.compiler = toolchainLibrary 60 module.linker = toolchainLibrary 61 module.stl = nil 62 module.sanitize = nil 63 module.installer = nil 64 return module.Init() 65} 66 67func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags, 68 deps PathDeps) Objects { 69 return Objects{} 70} 71 72func (library *toolchainLibraryDecorator) link(ctx ModuleContext, 73 flags Flags, deps PathDeps, objs Objects) android.Path { 74 75 if library.Properties.Src == nil { 76 ctx.PropertyErrorf("src", "No library source specified") 77 return android.PathForSource(ctx, "") 78 } 79 80 srcPath := android.PathForSource(ctx, *library.Properties.Src) 81 82 if library.stripper.StripProperties.Strip.Keep_symbols_list != nil { 83 fileName := ctx.ModuleName() + staticLibraryExtension 84 outputFile := android.PathForModuleOut(ctx, fileName) 85 buildFlags := flagsToBuilderFlags(flags) 86 library.stripper.strip(ctx, srcPath, outputFile, buildFlags) 87 return outputFile 88 } 89 90 return srcPath 91} 92 93func (library *toolchainLibraryDecorator) nativeCoverage() bool { 94 return false 95} 96