2020-01-16 12:47:25 +01:00
|
|
|
// Copyright 2020 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"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2020-03-24 02:19:52 +01:00
|
|
|
|
2020-01-16 12:47:25 +01:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.RegisterSdkMemberType(ccBinarySdkMemberType)
|
|
|
|
}
|
|
|
|
|
|
|
|
var ccBinarySdkMemberType = &binarySdkMemberType{
|
|
|
|
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "native_binaries",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
type binarySdkMemberType struct {
|
|
|
|
android.SdkMemberTypeBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *binarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
|
|
|
|
targets := mctx.MultiTargets()
|
|
|
|
for _, lib := range names {
|
|
|
|
for _, target := range targets {
|
|
|
|
name, version := StubsLibNameAndVersion(lib)
|
|
|
|
if version == "" {
|
|
|
|
version = LatestStubsVersionFor(mctx.Config(), name)
|
|
|
|
}
|
|
|
|
mctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
|
|
|
|
{Mutator: "version", Variation: version},
|
|
|
|
}...), dependencyTag, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *binarySdkMemberType) IsInstance(module android.Module) bool {
|
|
|
|
// Check the module to see if it can be used with this module type.
|
|
|
|
if m, ok := module.(*Module); ok {
|
|
|
|
for _, allowableMemberType := range m.sdkMemberTypes {
|
|
|
|
if allowableMemberType == mt {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (mt *binarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "cc_prebuilt_binary")
|
2020-02-27 17:00:53 +01:00
|
|
|
}
|
2020-01-16 12:47:25 +01:00
|
|
|
|
2020-02-27 17:00:53 +01:00
|
|
|
func (mt *binarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
|
|
|
return &nativeBinaryInfoProperties{}
|
2020-01-16 12:47:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
nativeBinaryDir = "bin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// path to the native binary. Relative to <sdk_root>/<api_dir>
|
|
|
|
func nativeBinaryPathFor(lib nativeBinaryInfoProperties) string {
|
2020-03-02 11:16:35 +01:00
|
|
|
return filepath.Join(lib.OsPrefix(), lib.archType,
|
2020-01-16 12:47:25 +01:00
|
|
|
nativeBinaryDir, lib.outputFile.Base())
|
|
|
|
}
|
|
|
|
|
|
|
|
// nativeBinaryInfoProperties represents properties of a native binary
|
|
|
|
//
|
|
|
|
// The exported (capitalized) fields will be examined and may be changed during common value extraction.
|
|
|
|
// The unexported fields will be left untouched.
|
|
|
|
type nativeBinaryInfoProperties struct {
|
2020-02-27 17:00:53 +01:00
|
|
|
android.SdkMemberPropertiesBase
|
2020-01-16 12:47:25 +01:00
|
|
|
|
|
|
|
// archType is not exported as if set (to a non default value) it is always arch specific.
|
|
|
|
// This is "" for common properties.
|
|
|
|
archType string
|
|
|
|
|
|
|
|
// outputFile is not exported as it is always arch specific.
|
|
|
|
outputFile android.Path
|
2020-03-06 13:30:43 +01:00
|
|
|
|
|
|
|
// The set of shared libraries
|
|
|
|
//
|
|
|
|
// This field is exported as its contents may not be arch specific.
|
|
|
|
SharedLibs []string
|
|
|
|
|
|
|
|
// The set of system shared libraries
|
|
|
|
//
|
|
|
|
// This field is exported as its contents may not be arch specific.
|
|
|
|
SystemSharedLibs []string
|
2020-01-16 12:47:25 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *nativeBinaryInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
2020-02-27 17:00:53 +01:00
|
|
|
ccModule := variant.(*Module)
|
|
|
|
|
|
|
|
p.archType = ccModule.Target().Arch.ArchType.String()
|
2020-05-05 15:11:57 +02:00
|
|
|
p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
|
2020-03-06 13:30:43 +01:00
|
|
|
|
|
|
|
if ccModule.linker != nil {
|
|
|
|
specifiedDeps := specifiedDeps{}
|
|
|
|
specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
|
|
|
|
|
|
|
|
p.SharedLibs = specifiedDeps.sharedLibs
|
|
|
|
p.SystemSharedLibs = specifiedDeps.systemSharedLibs
|
|
|
|
}
|
2020-02-27 17:00:53 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *nativeBinaryInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2020-02-27 17:00:53 +01:00
|
|
|
if p.Compile_multilib != "" {
|
|
|
|
propertySet.AddProperty("compile_multilib", p.Compile_multilib)
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
builder := ctx.SnapshotBuilder()
|
2020-02-27 17:00:53 +01:00
|
|
|
if p.outputFile != nil {
|
|
|
|
propertySet.AddProperty("srcs", []string{nativeBinaryPathFor(*p)})
|
|
|
|
|
|
|
|
builder.CopyToSnapshot(p.outputFile, nativeBinaryPathFor(*p))
|
|
|
|
}
|
2020-03-06 13:30:43 +01:00
|
|
|
|
|
|
|
if len(p.SharedLibs) > 0 {
|
|
|
|
propertySet.AddPropertyWithTag("shared_libs", p.SharedLibs, builder.SdkMemberReferencePropertyTag(false))
|
|
|
|
}
|
|
|
|
|
2020-03-24 02:19:52 +01:00
|
|
|
// SystemSharedLibs needs to be propagated if it's a list, even if it's empty,
|
|
|
|
// so check for non-nil instead of nonzero length.
|
|
|
|
if p.SystemSharedLibs != nil {
|
2020-03-06 13:30:43 +01:00
|
|
|
propertySet.AddPropertyWithTag("system_shared_libs", p.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false))
|
|
|
|
}
|
2020-01-16 12:47:25 +01:00
|
|
|
}
|