2017-03-19 21:44:32 +01:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
llndkLibrarySuffix = ".llndk"
|
2017-10-19 08:59:33 +02:00
|
|
|
llndkHeadersSuffix = ".llndk"
|
2017-03-19 21:44:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Creates a stub shared library based on the provided version file.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// llndk_library {
|
2017-04-08 00:21:13 +02:00
|
|
|
// name: "libfoo",
|
2017-03-19 21:44:32 +01:00
|
|
|
// symbol_file: "libfoo.map.txt",
|
|
|
|
// export_include_dirs: ["include_vndk"],
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
type llndkLibraryProperties struct {
|
|
|
|
// Relative path to the symbol map.
|
|
|
|
// An example file can be seen here: TODO(danalbert): Make an example.
|
2017-11-07 19:57:05 +01:00
|
|
|
Symbol_file *string
|
2017-03-19 21:44:32 +01:00
|
|
|
|
|
|
|
// Whether to export any headers as -isystem instead of -I. Mainly for use by
|
|
|
|
// bionic/libc.
|
2017-11-07 19:57:05 +01:00
|
|
|
Export_headers_as_system *bool
|
2017-03-19 21:44:32 +01:00
|
|
|
|
|
|
|
// Which headers to process with versioner. This really only handles
|
|
|
|
// bionic/libc/include right now.
|
|
|
|
Export_preprocessed_headers []string
|
|
|
|
|
|
|
|
// Whether the system library uses symbol versions.
|
2017-11-07 19:57:05 +01:00
|
|
|
Unversioned *bool
|
2017-08-16 07:05:54 +02:00
|
|
|
|
|
|
|
// whether this module can be directly depended upon by libs that are installed to /vendor.
|
|
|
|
// When set to false, this module can only be depended on by VNDK libraries, not vendor
|
|
|
|
// libraries. This effectively hides this module from vendors. Default value is true.
|
2017-11-07 19:57:05 +01:00
|
|
|
Vendor_available *bool
|
2017-10-19 08:59:33 +02:00
|
|
|
|
|
|
|
// list of llndk headers to re-export include directories from.
|
|
|
|
Export_llndk_headers []string `android:"arch_variant"`
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type llndkStubDecorator struct {
|
|
|
|
*libraryDecorator
|
|
|
|
|
|
|
|
Properties llndkLibraryProperties
|
|
|
|
|
|
|
|
exportHeadersTimestamp android.OptionalPath
|
|
|
|
versionScriptPath android.ModuleGenPath
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:33:08 +01:00
|
|
|
func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
|
|
|
|
flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
|
2017-07-19 20:39:53 +02:00
|
|
|
return addStubLibraryCompilerFlags(flags)
|
|
|
|
}
|
|
|
|
|
2017-03-19 21:44:32 +01:00
|
|
|
func (stub *llndkStubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
2019-08-26 09:52:35 +02:00
|
|
|
vndk_ver := ctx.Module().(*Module).Properties.VndkVersion
|
2018-03-23 09:43:47 +01:00
|
|
|
if vndk_ver == "current" {
|
|
|
|
platform_vndk_ver := ctx.DeviceConfig().PlatformVndkVersion()
|
|
|
|
if !inList(platform_vndk_ver, ctx.Config().PlatformVersionCombinedCodenames()) {
|
|
|
|
vndk_ver = platform_vndk_ver
|
|
|
|
}
|
|
|
|
} else if vndk_ver == "" {
|
|
|
|
// For non-enforcing devices, use "current"
|
|
|
|
vndk_ver = "current"
|
|
|
|
}
|
|
|
|
objs, versionScript := compileStubLibrary(ctx, flags, String(stub.Properties.Symbol_file), vndk_ver, "--vndk")
|
2017-03-19 21:44:32 +01:00
|
|
|
stub.versionScriptPath = versionScript
|
|
|
|
return objs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (stub *llndkStubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2017-10-19 08:59:33 +02:00
|
|
|
headers := addSuffix(stub.Properties.Export_llndk_headers, llndkHeadersSuffix)
|
|
|
|
deps.HeaderLibs = append(deps.HeaderLibs, headers...)
|
|
|
|
deps.ReexportHeaderLibHeaders = append(deps.ReexportHeaderLibHeaders, headers...)
|
|
|
|
return deps
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
2017-04-08 00:21:13 +02:00
|
|
|
func (stub *llndkStubDecorator) Name(name string) string {
|
|
|
|
return name + llndkLibrarySuffix
|
|
|
|
}
|
|
|
|
|
2017-03-19 21:44:32 +01:00
|
|
|
func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
stub.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(),
|
|
|
|
llndkLibrarySuffix)
|
|
|
|
return stub.libraryDecorator.linkerFlags(ctx, flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (stub *llndkStubDecorator) processHeaders(ctx ModuleContext, srcHeaderDir string, outDir android.ModuleGenPath) android.Path {
|
|
|
|
srcDir := android.PathForModuleSrc(ctx, srcHeaderDir)
|
2018-02-27 06:50:08 +01:00
|
|
|
srcFiles := ctx.GlobFiles(filepath.Join(srcDir.String(), "**/*.h"), nil)
|
2017-03-19 21:44:32 +01:00
|
|
|
|
|
|
|
var installPaths []android.WritablePath
|
|
|
|
for _, header := range srcFiles {
|
|
|
|
headerDir := filepath.Dir(header.String())
|
|
|
|
relHeaderDir, err := filepath.Rel(srcDir.String(), headerDir)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("filepath.Rel(%q, %q) failed: %s",
|
|
|
|
srcDir.String(), headerDir, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
installPaths = append(installPaths, outDir.Join(ctx, relHeaderDir, header.Base()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return processHeadersWithVersioner(ctx, srcDir, outDir, srcFiles, installPaths)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
|
|
|
|
objs Objects) android.Path {
|
|
|
|
|
2017-11-07 19:57:05 +01:00
|
|
|
if !Bool(stub.Properties.Unversioned) {
|
2017-03-19 21:44:32 +01:00
|
|
|
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
|
2019-06-11 03:02:25 +02:00
|
|
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(stub.Properties.Export_preprocessed_headers) > 0 {
|
|
|
|
genHeaderOutDir := android.PathForModuleGen(ctx, "include")
|
|
|
|
|
|
|
|
var timestampFiles android.Paths
|
|
|
|
for _, dir := range stub.Properties.Export_preprocessed_headers {
|
|
|
|
timestampFiles = append(timestampFiles, stub.processHeaders(ctx, dir, genHeaderOutDir))
|
|
|
|
}
|
|
|
|
|
2017-11-07 19:57:05 +01:00
|
|
|
if Bool(stub.Properties.Export_headers_as_system) {
|
2019-10-22 13:19:51 +02:00
|
|
|
stub.reexportSystemDirs(genHeaderOutDir)
|
2019-06-03 12:10:47 +02:00
|
|
|
} else {
|
2019-10-22 13:19:51 +02:00
|
|
|
stub.reexportDirs(genHeaderOutDir)
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
2019-06-03 12:10:47 +02:00
|
|
|
stub.reexportDeps(timestampFiles...)
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
2017-11-07 19:57:05 +01:00
|
|
|
if Bool(stub.Properties.Export_headers_as_system) {
|
2019-06-03 12:10:47 +02:00
|
|
|
stub.exportIncludesAsSystem(ctx)
|
2017-03-19 21:44:32 +01:00
|
|
|
stub.libraryDecorator.flagExporter.Properties.Export_include_dirs = []string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stub.libraryDecorator.link(ctx, flags, deps, objs)
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:31 +01:00
|
|
|
func (stub *llndkStubDecorator) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-11-14 12:53:00 +01:00
|
|
|
func NewLLndkStubLibrary() *Module {
|
2017-03-19 21:44:32 +01:00
|
|
|
module, library := NewLibrary(android.DeviceSupported)
|
|
|
|
library.BuildOnlyShared()
|
|
|
|
module.stl = nil
|
|
|
|
module.sanitize = nil
|
2017-11-07 19:57:05 +01:00
|
|
|
library.StripProperties.Strip.None = BoolPtr(true)
|
2017-03-19 21:44:32 +01:00
|
|
|
|
|
|
|
stub := &llndkStubDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
2017-11-07 19:57:05 +01:00
|
|
|
stub.Properties.Vendor_available = BoolPtr(true)
|
2017-03-19 21:44:32 +01:00
|
|
|
module.compiler = stub
|
|
|
|
module.linker = stub
|
|
|
|
module.installer = nil
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
module.AddProperties(
|
2019-04-17 06:12:10 +02:00
|
|
|
&module.Properties,
|
2017-06-24 00:06:31 +02:00
|
|
|
&stub.Properties,
|
|
|
|
&library.MutatedProperties,
|
|
|
|
&library.flagExporter.Properties)
|
|
|
|
|
|
|
|
return module
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 23:37:46 +02:00
|
|
|
// llndk_library creates a stub llndk shared library based on the provided
|
|
|
|
// version file. Example:
|
|
|
|
//
|
|
|
|
// llndk_library {
|
|
|
|
// name: "libfoo",
|
|
|
|
// symbol_file: "libfoo.map.txt",
|
|
|
|
// export_include_dirs: ["include_vndk"],
|
|
|
|
// }
|
2018-12-19 09:12:36 +01:00
|
|
|
func LlndkLibraryFactory() android.Module {
|
2017-11-14 12:53:00 +01:00
|
|
|
module := NewLLndkStubLibrary()
|
2017-06-24 00:06:31 +02:00
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
|
|
|
|
return module
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
2017-10-19 08:59:33 +02:00
|
|
|
type llndkHeadersDecorator struct {
|
|
|
|
*libraryDecorator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (headers *llndkHeadersDecorator) Name(name string) string {
|
|
|
|
return name + llndkHeadersSuffix
|
|
|
|
}
|
|
|
|
|
2019-04-03 23:37:46 +02:00
|
|
|
// llndk_headers contains a set of c/c++ llndk headers files which are imported
|
|
|
|
// by other soongs cc modules.
|
2017-10-19 08:59:33 +02:00
|
|
|
func llndkHeadersFactory() android.Module {
|
|
|
|
module, library := NewLibrary(android.DeviceSupported)
|
|
|
|
library.HeaderOnly()
|
|
|
|
|
|
|
|
decorator := &llndkHeadersDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
|
|
|
|
module.compiler = nil
|
|
|
|
module.linker = decorator
|
|
|
|
module.installer = nil
|
|
|
|
|
2019-04-17 06:12:10 +02:00
|
|
|
module.AddProperties(
|
|
|
|
&module.Properties,
|
|
|
|
&library.MutatedProperties,
|
|
|
|
&library.flagExporter.Properties)
|
2017-10-19 08:59:33 +02:00
|
|
|
|
2019-07-29 14:27:18 +02:00
|
|
|
module.Init()
|
2017-10-19 08:59:33 +02:00
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2017-03-19 21:44:32 +01:00
|
|
|
func init() {
|
2018-12-19 09:12:36 +01:00
|
|
|
android.RegisterModuleType("llndk_library", LlndkLibraryFactory)
|
2017-10-19 08:59:33 +02:00
|
|
|
android.RegisterModuleType("llndk_headers", llndkHeadersFactory)
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|