blob: fef4508f27ae6f3f37511ab1bfc09682e958ea2b [file] [log] [blame]
Colin Crossb916a382016-07-29 17:28:03 -07001// 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 (
Colin Crossb916a382016-07-29 17:28:03 -070018 "android/soong/android"
19)
20
21//
22// Device libraries shipped with gcc
23//
24
25func init() {
Colin Crosse40b4ea2018-10-02 22:25:58 -070026 android.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
Colin Crossb916a382016-07-29 17:28:03 -070027}
28
Dan Willemsenfeea4df2018-10-07 18:16:48 -070029type 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
Colin Crossb916a382016-07-29 17:28:03 -070034type toolchainLibraryDecorator struct {
35 *libraryDecorator
Dan Willemsenfeea4df2018-10-07 18:16:48 -070036
Yi Kongacee27c2019-03-29 20:05:14 -070037 stripper
38
Dan Willemsenfeea4df2018-10-07 18:16:48 -070039 Properties toolchainLibraryProperties
Colin Crossb916a382016-07-29 17:28:03 -070040}
41
Colin Cross37047f12016-12-13 17:06:13 -080042func (*toolchainLibraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Crossb916a382016-07-29 17:28:03 -070043 // toolchain libraries can't have any dependencies
44 return deps
45}
46
Dan Willemsenfeea4df2018-10-07 18:16:48 -070047func (library *toolchainLibraryDecorator) linkerProps() []interface{} {
48 var props []interface{}
49 props = append(props, library.libraryDecorator.linkerProps()...)
Yi Kongacee27c2019-03-29 20:05:14 -070050 return append(props, &library.Properties, &library.stripper.StripProperties)
Dan Willemsenfeea4df2018-10-07 18:16:48 -070051}
52
Patrice Arrudaea3fcdf2019-04-03 14:37:46 -070053// toolchain_library is used internally by the build tool to link the specified
54// static library in src property to the device libraries that are shipped with
55// gcc.
Colin Crosse40b4ea2018-10-02 22:25:58 -070056func ToolchainLibraryFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -080057 module, library := NewLibrary(android.HostAndDeviceSupported)
58 library.BuildOnlyStatic()
Colin Crossb916a382016-07-29 17:28:03 -070059 toolchainLibrary := &toolchainLibraryDecorator{
60 libraryDecorator: library,
61 }
62 module.compiler = toolchainLibrary
63 module.linker = toolchainLibrary
Colin Crossb916a382016-07-29 17:28:03 -070064 module.stl = nil
65 module.sanitize = nil
66 module.installer = nil
67 return module.Init()
68}
69
70func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070071 deps PathDeps) Objects {
72 return Objects{}
Colin Crossb916a382016-07-29 17:28:03 -070073}
74
75func (library *toolchainLibraryDecorator) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070076 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Crossb916a382016-07-29 17:28:03 -070077
Dan Willemsenfeea4df2018-10-07 18:16:48 -070078 if library.Properties.Src == nil {
79 ctx.PropertyErrorf("src", "No library source specified")
80 return android.PathForSource(ctx, "")
Colin Crossb916a382016-07-29 17:28:03 -070081 }
82
Yi Kongacee27c2019-03-29 20:05:14 -070083 srcPath := android.PathForSource(ctx, *library.Properties.Src)
84
85 if library.stripper.StripProperties.Strip.Keep_symbols_list != nil {
86 fileName := ctx.ModuleName() + staticLibraryExtension
87 outputFile := android.PathForModuleOut(ctx, fileName)
88 buildFlags := flagsToBuilderFlags(flags)
Ryan Prichardf979d732019-05-30 20:53:29 -070089 library.stripper.stripStaticLib(ctx, srcPath, outputFile, buildFlags)
Yi Kongacee27c2019-03-29 20:05:14 -070090 return outputFile
91 }
92
93 return srcPath
Colin Crossb916a382016-07-29 17:28:03 -070094}
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -070095
96func (library *toolchainLibraryDecorator) nativeCoverage() bool {
97 return false
98}