blob: bda73eabf575ce72ff504a9862a0d23b858a7e3b [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"`
Yi Kongc49c3932019-10-15 02:01:19 -070032
33 // Repack the archive with only the selected objects.
34 Repack_objects_to_keep []string `android:"arch_variant"`
Dan Willemsenfeea4df2018-10-07 18:16:48 -070035}
36
Colin Crossb916a382016-07-29 17:28:03 -070037type toolchainLibraryDecorator struct {
38 *libraryDecorator
ThiƩbaud Weksteend4587452020-08-19 14:53:01 +020039 stripper Stripper
Yi Kongacee27c2019-03-29 20:05:14 -070040
Dan Willemsenfeea4df2018-10-07 18:16:48 -070041 Properties toolchainLibraryProperties
Colin Crossb916a382016-07-29 17:28:03 -070042}
43
Colin Cross37047f12016-12-13 17:06:13 -080044func (*toolchainLibraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Crossb916a382016-07-29 17:28:03 -070045 // toolchain libraries can't have any dependencies
46 return deps
47}
48
Dan Willemsenfeea4df2018-10-07 18:16:48 -070049func (library *toolchainLibraryDecorator) linkerProps() []interface{} {
50 var props []interface{}
51 props = append(props, library.libraryDecorator.linkerProps()...)
Yi Kongacee27c2019-03-29 20:05:14 -070052 return append(props, &library.Properties, &library.stripper.StripProperties)
Dan Willemsenfeea4df2018-10-07 18:16:48 -070053}
54
Patrice Arrudaea3fcdf2019-04-03 14:37:46 -070055// 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 Crosse40b4ea2018-10-02 22:25:58 -070058func ToolchainLibraryFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -080059 module, library := NewLibrary(android.HostAndDeviceSupported)
60 library.BuildOnlyStatic()
Colin Crossb916a382016-07-29 17:28:03 -070061 toolchainLibrary := &toolchainLibraryDecorator{
62 libraryDecorator: library,
63 }
64 module.compiler = toolchainLibrary
65 module.linker = toolchainLibrary
Colin Crossb916a382016-07-29 17:28:03 -070066 module.stl = nil
67 module.sanitize = nil
68 module.installer = nil
Colin Cross31076b32020-10-23 17:22:06 -070069 module.library = toolchainLibrary
Colin Crossc511bc52020-04-07 16:50:32 +000070 module.Properties.Sdk_version = StringPtr("current")
Colin Crossb916a382016-07-29 17:28:03 -070071 return module.Init()
72}
73
74func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070075 deps PathDeps) Objects {
76 return Objects{}
Colin Crossb916a382016-07-29 17:28:03 -070077}
78
79func (library *toolchainLibraryDecorator) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070080 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Crossb916a382016-07-29 17:28:03 -070081
Dan Willemsenfeea4df2018-10-07 18:16:48 -070082 if library.Properties.Src == nil {
83 ctx.PropertyErrorf("src", "No library source specified")
84 return android.PathForSource(ctx, "")
Colin Crossb916a382016-07-29 17:28:03 -070085 }
86
Yi Kongacee27c2019-03-29 20:05:14 -070087 srcPath := android.PathForSource(ctx, *library.Properties.Src)
Colin Cross0de8a1e2020-09-18 14:15:30 -070088 outputFile := android.Path(srcPath)
Yi Kongacee27c2019-03-29 20:05:14 -070089
Yi Kongc49c3932019-10-15 02:01:19 -070090 if library.Properties.Repack_objects_to_keep != nil {
91 fileName := ctx.ModuleName() + staticLibraryExtension
Colin Cross0de8a1e2020-09-18 14:15:30 -070092 repackedPath := android.PathForModuleOut(ctx, fileName)
Chris Parsonsbf4f55f2020-11-23 17:02:44 -050093 transformArchiveRepack(ctx, outputFile, repackedPath, library.Properties.Repack_objects_to_keep)
Colin Cross0de8a1e2020-09-18 14:15:30 -070094 outputFile = repackedPath
Yi Kongc49c3932019-10-15 02:01:19 -070095 }
96
Colin Cross0de8a1e2020-09-18 14:15:30 -070097 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
Colin Crossb916a382016-07-29 17:28:03 -0700113}
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700114
115func (library *toolchainLibraryDecorator) nativeCoverage() bool {
116 return false
117}