Introduce module type 'sdk'
This change introduces a new module type named 'sdk'. It is a logical
group of prebuilt modules that together provide a context (e.g. APIs)
in which Mainline modules (such as APEXes) are built.
A prebuilt module (e.g. java_import) can join an sdk by adding it to the
sdk module as shown below:
sdk {
name: "mysdk#20",
java_libs: ["myjavalib_mysdk_20"],
}
java_import {
name: "myjavalib_mysdk_20",
srcs: ["myjavalib-v20.jar"],
sdk_member_name: "myjavalib",
}
sdk {
name: "mysdk#21",
java_libs: ["myjavalib_mysdk_21"],
}
java_import {
name: "myjavalib_mysdk_21",
srcs: ["myjavalib-v21.jar"],
sdk_member_name: "myjavalib",
}
java_library {
name: "myjavalib",
srcs: ["**/*/*.java"],
}
An APEX can specify the SDK(s) that it wants to build with via the new
'uses_sdks' property.
apex {
name: "myapex",
java_libs: ["libX", "libY"],
uses_sdks: ["mysdk#20"],
}
With this, libX, libY, and their transitive dependencies are all built
with the version 20 of myjavalib (the first java_import module) instead
of the other one (which is for version 21) and java_library having the
same name (which is for ToT).
Bug: 138182343
Test: m (sdk_test.go added)
Change-Id: I7e14c524a7d6a0d9f575fb20822080f39818c01e
2019-07-17 13:08:41 +02:00
|
|
|
// Copyright (C) 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// 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 android
|
|
|
|
|
|
|
|
import (
|
2021-07-14 13:08:37 +02:00
|
|
|
"fmt"
|
2019-12-13 12:22:16 +01:00
|
|
|
"sort"
|
Introduce module type 'sdk'
This change introduces a new module type named 'sdk'. It is a logical
group of prebuilt modules that together provide a context (e.g. APIs)
in which Mainline modules (such as APEXes) are built.
A prebuilt module (e.g. java_import) can join an sdk by adding it to the
sdk module as shown below:
sdk {
name: "mysdk#20",
java_libs: ["myjavalib_mysdk_20"],
}
java_import {
name: "myjavalib_mysdk_20",
srcs: ["myjavalib-v20.jar"],
sdk_member_name: "myjavalib",
}
sdk {
name: "mysdk#21",
java_libs: ["myjavalib_mysdk_21"],
}
java_import {
name: "myjavalib_mysdk_21",
srcs: ["myjavalib-v21.jar"],
sdk_member_name: "myjavalib",
}
java_library {
name: "myjavalib",
srcs: ["**/*/*.java"],
}
An APEX can specify the SDK(s) that it wants to build with via the new
'uses_sdks' property.
apex {
name: "myapex",
java_libs: ["libX", "libY"],
uses_sdks: ["mysdk#20"],
}
With this, libX, libY, and their transitive dependencies are all built
with the version 20 of myjavalib (the first java_import module) instead
of the other one (which is for version 21) and java_library having the
same name (which is for ToT).
Bug: 138182343
Test: m (sdk_test.go added)
Change-Id: I7e14c524a7d6a0d9f575fb20822080f39818c01e
2019-07-17 13:08:41 +02:00
|
|
|
"strings"
|
|
|
|
|
2019-11-28 15:31:38 +01:00
|
|
|
"github.com/google/blueprint"
|
Introduce module type 'sdk'
This change introduces a new module type named 'sdk'. It is a logical
group of prebuilt modules that together provide a context (e.g. APIs)
in which Mainline modules (such as APEXes) are built.
A prebuilt module (e.g. java_import) can join an sdk by adding it to the
sdk module as shown below:
sdk {
name: "mysdk#20",
java_libs: ["myjavalib_mysdk_20"],
}
java_import {
name: "myjavalib_mysdk_20",
srcs: ["myjavalib-v20.jar"],
sdk_member_name: "myjavalib",
}
sdk {
name: "mysdk#21",
java_libs: ["myjavalib_mysdk_21"],
}
java_import {
name: "myjavalib_mysdk_21",
srcs: ["myjavalib-v21.jar"],
sdk_member_name: "myjavalib",
}
java_library {
name: "myjavalib",
srcs: ["**/*/*.java"],
}
An APEX can specify the SDK(s) that it wants to build with via the new
'uses_sdks' property.
apex {
name: "myapex",
java_libs: ["libX", "libY"],
uses_sdks: ["mysdk#20"],
}
With this, libX, libY, and their transitive dependencies are all built
with the version 20 of myjavalib (the first java_import module) instead
of the other one (which is for version 21) and java_library having the
same name (which is for ToT).
Bug: 138182343
Test: m (sdk_test.go added)
Change-Id: I7e14c524a7d6a0d9f575fb20822080f39818c01e
2019-07-17 13:08:41 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
2022-07-27 01:53:00 +02:00
|
|
|
// minApiLevelForSdkSnapshot provides access to the min_sdk_version for MinApiLevelForSdkSnapshot
|
|
|
|
type minApiLevelForSdkSnapshot interface {
|
2023-03-03 22:20:36 +01:00
|
|
|
MinSdkVersion(ctx EarlyModuleContext) ApiLevel
|
2022-07-27 01:53:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MinApiLevelForSdkSnapshot returns the ApiLevel of the min_sdk_version of the supplied module.
|
|
|
|
//
|
|
|
|
// If the module does not provide a min_sdk_version then it defaults to 1.
|
|
|
|
func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel {
|
|
|
|
minApiLevel := NoneApiLevel
|
|
|
|
if m, ok := module.(minApiLevelForSdkSnapshot); ok {
|
2023-03-03 22:20:36 +01:00
|
|
|
minApiLevel = m.MinSdkVersion(ctx)
|
2022-07-27 01:53:00 +02:00
|
|
|
}
|
|
|
|
if minApiLevel == NoneApiLevel {
|
|
|
|
// The default min API level is 1.
|
|
|
|
minApiLevel = uncheckedFinalApiLevel(1)
|
|
|
|
}
|
|
|
|
return minApiLevel
|
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SnapshotBuilder provides support for generating the build rules which will build the snapshot.
|
2019-11-12 20:39:25 +01:00
|
|
|
type SnapshotBuilder interface {
|
2021-09-09 16:38:32 +02:00
|
|
|
// CopyToSnapshot generates a rule that will copy the src to the dest (which is a snapshot
|
|
|
|
// relative path) and add the dest to the zip.
|
2019-11-12 20:39:25 +01:00
|
|
|
CopyToSnapshot(src Path, dest string)
|
|
|
|
|
2022-11-21 11:57:30 +01:00
|
|
|
// EmptyFile returns the path to an empty file.
|
|
|
|
//
|
|
|
|
// This can be used by sdk member types that need to create an empty file in the snapshot, simply
|
|
|
|
// pass the value returned from this to the CopyToSnapshot() method.
|
|
|
|
EmptyFile() Path
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// UnzipToSnapshot generates a rule that will unzip the supplied zip into the snapshot relative
|
|
|
|
// directory destDir.
|
2019-11-12 20:39:36 +01:00
|
|
|
UnzipToSnapshot(zipPath Path, destDir string)
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// AddPrebuiltModule adds a new prebuilt module to the snapshot.
|
|
|
|
//
|
|
|
|
// It is intended to be called from SdkMemberType.AddPrebuiltModule which can add module type
|
|
|
|
// specific properties that are not variant specific. The following properties will be
|
|
|
|
// automatically populated before returning.
|
2019-11-27 18:43:54 +01:00
|
|
|
//
|
|
|
|
// * name
|
|
|
|
// * sdk_member_name
|
|
|
|
// * prefer
|
|
|
|
//
|
2021-09-09 16:38:32 +02:00
|
|
|
// Properties that are variant specific will be handled by SdkMemberProperties structure.
|
|
|
|
//
|
|
|
|
// Each module created by this method can be output to the generated Android.bp file in two
|
|
|
|
// different forms, depending on the setting of the SOONG_SDK_SNAPSHOT_VERSION build property.
|
|
|
|
// The two forms are:
|
|
|
|
// 1. A versioned Soong module that is referenced from a corresponding similarly versioned
|
|
|
|
// snapshot module.
|
|
|
|
// 2. An unversioned Soong module that.
|
|
|
|
//
|
|
|
|
// See sdk/update.go for more information.
|
2019-12-05 19:19:29 +01:00
|
|
|
AddPrebuiltModule(member SdkMember, moduleType string) BpModule
|
2020-01-13 22:03:22 +01:00
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkMemberReferencePropertyTag returns a property tag to use when adding a property to a
|
|
|
|
// BpModule that contains references to other sdk members.
|
|
|
|
//
|
|
|
|
// Using this will ensure that the reference is correctly output for both versioned and
|
|
|
|
// unversioned prebuilts in the snapshot.
|
2020-01-13 22:03:22 +01:00
|
|
|
//
|
2021-09-09 16:38:32 +02:00
|
|
|
// "required: true" means that the property must only contain references to other members of the
|
|
|
|
// sdk. Passing a reference to a module that is not a member of the sdk will result in a build
|
|
|
|
// error.
|
2020-03-06 13:30:43 +01:00
|
|
|
//
|
2021-09-09 16:38:32 +02:00
|
|
|
// "required: false" means that the property can contain references to modules that are either
|
|
|
|
// members or not members of the sdk. If a reference is to a module that is a non member then the
|
|
|
|
// reference is left unchanged, i.e. it is not transformed as references to members are.
|
2020-03-06 13:30:43 +01:00
|
|
|
//
|
2021-09-09 16:38:32 +02:00
|
|
|
// The handling of the member names is dependent on whether it is an internal or exported member.
|
|
|
|
// An exported member is one whose name is specified in one of the member type specific
|
|
|
|
// properties. An internal member is one that is added due to being a part of an exported (or
|
|
|
|
// other internal) member and is not itself an exported member.
|
2020-03-06 13:30:43 +01:00
|
|
|
//
|
|
|
|
// Member names are handled as follows:
|
2021-09-09 16:38:32 +02:00
|
|
|
// * When creating the unversioned form of the module the name is left unchecked unless the member
|
|
|
|
// is internal in which case it is transformed into an sdk specific name, i.e. by prefixing with
|
|
|
|
// the sdk name.
|
2020-03-06 13:30:43 +01:00
|
|
|
//
|
2021-09-09 16:38:32 +02:00
|
|
|
// * When creating the versioned form of the module the name is transformed into a versioned sdk
|
|
|
|
// specific name, i.e. by prefixing with the sdk name and suffixing with the version.
|
2020-03-06 13:30:43 +01:00
|
|
|
//
|
2020-01-13 22:03:22 +01:00
|
|
|
// e.g.
|
2020-03-06 13:30:43 +01:00
|
|
|
// bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag(true))
|
|
|
|
SdkMemberReferencePropertyTag(required bool) BpPropertyTag
|
2019-11-27 18:43:54 +01:00
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// BpPropertyTag is a marker interface that can be associated with properties in a BpPropertySet to
|
|
|
|
// provide additional information which can be used to customize their behavior.
|
2020-01-15 15:23:52 +01:00
|
|
|
type BpPropertyTag interface{}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// BpPropertySet is a set of properties for use in a .bp file.
|
2019-11-27 18:43:54 +01:00
|
|
|
type BpPropertySet interface {
|
2021-09-09 16:38:32 +02:00
|
|
|
// AddProperty adds a property.
|
|
|
|
//
|
|
|
|
// The value can be one of the following types:
|
2019-11-27 18:43:54 +01:00
|
|
|
// * string
|
|
|
|
// * array of the above
|
|
|
|
// * bool
|
2020-09-10 01:40:37 +02:00
|
|
|
// For these types it is an error if multiple properties with the same name
|
|
|
|
// are added.
|
|
|
|
//
|
|
|
|
// * pointer to a struct
|
2019-11-27 18:43:54 +01:00
|
|
|
// * BpPropertySet
|
|
|
|
//
|
2020-09-10 01:40:37 +02:00
|
|
|
// A pointer to a Blueprint-style property struct is first converted into a
|
|
|
|
// BpPropertySet by traversing the fields and adding their values as
|
|
|
|
// properties in a BpPropertySet. A field with a struct value is itself
|
|
|
|
// converted into a BpPropertySet before adding.
|
|
|
|
//
|
|
|
|
// Adding a BpPropertySet is done as follows:
|
|
|
|
// * If no property with the name exists then the BpPropertySet is added
|
|
|
|
// directly to this property. Care must be taken to ensure that it does not
|
|
|
|
// introduce a cycle.
|
|
|
|
// * If a property exists with the name and the current value is a
|
|
|
|
// BpPropertySet then every property of the new BpPropertySet is added to
|
|
|
|
// the existing BpPropertySet.
|
|
|
|
// * Otherwise, if a property exists with the name then it is an error.
|
2019-11-27 18:43:54 +01:00
|
|
|
AddProperty(name string, value interface{})
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// AddPropertyWithTag adds a property with an associated property tag.
|
2020-01-15 15:23:52 +01:00
|
|
|
AddPropertyWithTag(name string, value interface{}, tag BpPropertyTag)
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// AddPropertySet adds a property set with the specified name and returns it so that additional
|
|
|
|
// properties can be added to it.
|
2019-11-27 18:43:54 +01:00
|
|
|
AddPropertySet(name string) BpPropertySet
|
2021-05-07 02:10:01 +02:00
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// AddCommentForProperty adds a comment for the named property (or property set).
|
2021-05-07 02:10:01 +02:00
|
|
|
AddCommentForProperty(name, text string)
|
2019-11-27 18:43:54 +01:00
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// BpModule represents a module definition in a .bp file.
|
2019-11-27 18:43:54 +01:00
|
|
|
type BpModule interface {
|
|
|
|
BpPropertySet
|
2021-05-07 02:10:01 +02:00
|
|
|
|
|
|
|
// ModuleType returns the module type of the module
|
|
|
|
ModuleType() string
|
|
|
|
|
|
|
|
// Name returns the name of the module or "" if no name has been specified.
|
|
|
|
Name() string
|
2019-11-12 20:39:25 +01:00
|
|
|
}
|
2019-11-28 15:31:38 +01:00
|
|
|
|
2021-05-18 13:54:27 +02:00
|
|
|
// BpPrintable is a marker interface that must be implemented by any struct that is added as a
|
|
|
|
// property value.
|
|
|
|
type BpPrintable interface {
|
|
|
|
bpPrintable()
|
|
|
|
}
|
|
|
|
|
|
|
|
// BpPrintableBase must be embedded within any struct that is added as a
|
|
|
|
// property value.
|
|
|
|
type BpPrintableBase struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b BpPrintableBase) bpPrintable() {
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ BpPrintable = BpPrintableBase{}
|
|
|
|
|
2021-09-22 12:51:09 +02:00
|
|
|
// sdkRegisterable defines the interface that must be implemented by objects that can be registered
|
|
|
|
// in an sdkRegistry.
|
|
|
|
type sdkRegisterable interface {
|
|
|
|
// SdkPropertyName returns the name of the corresponding property on an sdk module.
|
|
|
|
SdkPropertyName() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// sdkRegistry provides support for registering and retrieving objects that define properties for
|
|
|
|
// use by sdk and module_exports module types.
|
|
|
|
type sdkRegistry struct {
|
|
|
|
// The list of registered objects sorted by property name.
|
|
|
|
list []sdkRegisterable
|
|
|
|
}
|
|
|
|
|
|
|
|
// copyAndAppend creates a new sdkRegistry that includes all the traits registered in
|
|
|
|
// this registry plus the supplied trait.
|
|
|
|
func (r *sdkRegistry) copyAndAppend(registerable sdkRegisterable) *sdkRegistry {
|
|
|
|
oldList := r.list
|
|
|
|
|
2021-09-22 14:25:23 +02:00
|
|
|
// Make sure that list does not already contain the property. Uses a simple linear search instead
|
|
|
|
// of a binary search even though the list is sorted. That is because the number of items in the
|
|
|
|
// list is small and so not worth the overhead of a binary search.
|
|
|
|
found := false
|
|
|
|
newPropertyName := registerable.SdkPropertyName()
|
|
|
|
for _, r := range oldList {
|
|
|
|
if r.SdkPropertyName() == newPropertyName {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if found {
|
|
|
|
names := []string{}
|
|
|
|
for _, r := range oldList {
|
|
|
|
names = append(names, r.SdkPropertyName())
|
|
|
|
}
|
|
|
|
panic(fmt.Errorf("duplicate properties found, %q already exists in %q", newPropertyName, names))
|
|
|
|
}
|
|
|
|
|
2021-09-22 12:51:09 +02:00
|
|
|
// Copy the slice just in case this is being read while being modified, e.g. when testing.
|
|
|
|
list := make([]sdkRegisterable, 0, len(oldList)+1)
|
|
|
|
list = append(list, oldList...)
|
|
|
|
list = append(list, registerable)
|
|
|
|
|
|
|
|
// Sort the registered objects by their property name to ensure that registry order has no effect
|
|
|
|
// on behavior.
|
|
|
|
sort.Slice(list, func(i1, i2 int) bool {
|
|
|
|
t1 := list[i1]
|
|
|
|
t2 := list[i2]
|
|
|
|
|
|
|
|
return t1.SdkPropertyName() < t2.SdkPropertyName()
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create a new registry so the pointer uniquely identifies the set of registered types.
|
|
|
|
return &sdkRegistry{
|
|
|
|
list: list,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// registeredObjects returns the list of registered instances.
|
|
|
|
func (r *sdkRegistry) registeredObjects() []sdkRegisterable {
|
|
|
|
return r.list
|
|
|
|
}
|
|
|
|
|
|
|
|
// uniqueOnceKey returns a key that uniquely identifies this instance and can be used with
|
|
|
|
// OncePer.Once
|
|
|
|
func (r *sdkRegistry) uniqueOnceKey() OnceKey {
|
|
|
|
// Use the pointer to the registry as the unique key. The pointer is used because it is guaranteed
|
|
|
|
// to uniquely identify the contained list. The list itself cannot be used as slices are not
|
|
|
|
// comparable. Using the pointer does mean that two separate registries with identical lists would
|
|
|
|
// have different keys and so cause whatever information is cached to be created multiple times.
|
|
|
|
// However, that is not an issue in practice as it should not occur outside tests. Constructing a
|
|
|
|
// string representation of the list to use instead would avoid that but is an unnecessary
|
|
|
|
// complication that provides no significant benefit.
|
|
|
|
return NewCustomOnceKey(r)
|
|
|
|
}
|
|
|
|
|
2021-07-14 13:08:37 +02:00
|
|
|
// SdkMemberTrait represents a trait that members of an sdk module can contribute to the sdk
|
|
|
|
// snapshot.
|
|
|
|
//
|
|
|
|
// A trait is simply a characteristic of sdk member that is not required by default which may be
|
|
|
|
// required for some members but not others. Traits can cause additional information to be output
|
|
|
|
// to the sdk snapshot or replace the default information exported for a member with something else.
|
|
|
|
// e.g.
|
2022-08-16 19:27:33 +02:00
|
|
|
// - By default cc libraries only export the default image variants to the SDK. However, for some
|
|
|
|
// members it may be necessary to export specific image variants, e.g. vendor, or recovery.
|
|
|
|
// - By default cc libraries export all the configured architecture variants except for the native
|
|
|
|
// bridge architecture variants. However, for some members it may be necessary to export the
|
|
|
|
// native bridge architecture variants as well.
|
|
|
|
// - By default cc libraries export the platform variant (i.e. sdk:). However, for some members it
|
|
|
|
// may be necessary to export the sdk variant (i.e. sdk:sdk).
|
2021-07-14 13:08:37 +02:00
|
|
|
//
|
|
|
|
// A sdk can request a module to provide no traits, one trait or a collection of traits. The exact
|
|
|
|
// behavior of a trait is determined by how SdkMemberType implementations handle the traits. A trait
|
|
|
|
// could be specific to one SdkMemberType or many. Some trait combinations could be incompatible.
|
|
|
|
//
|
|
|
|
// The sdk module type will create a special traits structure that contains a property for each
|
|
|
|
// trait registered with RegisterSdkMemberTrait(). The property names are those returned from
|
|
|
|
// SdkPropertyName(). Each property contains a list of modules that are required to have that trait.
|
|
|
|
// e.g. something like this:
|
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// sdk {
|
|
|
|
// name: "sdk",
|
|
|
|
// ...
|
|
|
|
// traits: {
|
|
|
|
// recovery_image: ["module1", "module4", "module5"],
|
|
|
|
// native_bridge: ["module1", "module2"],
|
|
|
|
// native_sdk: ["module1", "module3"],
|
|
|
|
// ...
|
|
|
|
// },
|
|
|
|
// ...
|
|
|
|
// }
|
2021-07-14 13:08:37 +02:00
|
|
|
type SdkMemberTrait interface {
|
|
|
|
// SdkPropertyName returns the name of the traits property on an sdk module.
|
|
|
|
SdkPropertyName() string
|
|
|
|
}
|
|
|
|
|
2021-09-22 12:51:09 +02:00
|
|
|
var _ sdkRegisterable = (SdkMemberTrait)(nil)
|
|
|
|
|
2021-07-14 13:08:37 +02:00
|
|
|
// SdkMemberTraitBase is the base struct that must be embedded within any type that implements
|
|
|
|
// SdkMemberTrait.
|
|
|
|
type SdkMemberTraitBase struct {
|
|
|
|
// PropertyName is the name of the property
|
|
|
|
PropertyName string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *SdkMemberTraitBase) SdkPropertyName() string {
|
|
|
|
return b.PropertyName
|
|
|
|
}
|
|
|
|
|
|
|
|
// SdkMemberTraitSet is a set of SdkMemberTrait instances.
|
|
|
|
type SdkMemberTraitSet interface {
|
|
|
|
// Empty returns true if this set is empty.
|
|
|
|
Empty() bool
|
|
|
|
|
|
|
|
// Contains returns true if this set contains the specified trait.
|
|
|
|
Contains(trait SdkMemberTrait) bool
|
|
|
|
|
|
|
|
// Subtract returns a new set containing all elements of this set except for those in the
|
|
|
|
// other set.
|
|
|
|
Subtract(other SdkMemberTraitSet) SdkMemberTraitSet
|
|
|
|
|
|
|
|
// String returns a string representation of the set and its contents.
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSdkMemberTraitSet(traits []SdkMemberTrait) SdkMemberTraitSet {
|
|
|
|
if len(traits) == 0 {
|
|
|
|
return EmptySdkMemberTraitSet()
|
|
|
|
}
|
|
|
|
|
|
|
|
m := sdkMemberTraitSet{}
|
|
|
|
for _, trait := range traits {
|
|
|
|
m[trait] = true
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func EmptySdkMemberTraitSet() SdkMemberTraitSet {
|
|
|
|
return (sdkMemberTraitSet)(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
type sdkMemberTraitSet map[SdkMemberTrait]bool
|
|
|
|
|
|
|
|
var _ SdkMemberTraitSet = (sdkMemberTraitSet{})
|
|
|
|
|
|
|
|
func (s sdkMemberTraitSet) Empty() bool {
|
|
|
|
return len(s) == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s sdkMemberTraitSet) Contains(trait SdkMemberTrait) bool {
|
|
|
|
return s[trait]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s sdkMemberTraitSet) Subtract(other SdkMemberTraitSet) SdkMemberTraitSet {
|
|
|
|
if other.Empty() {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
var remainder []SdkMemberTrait
|
|
|
|
for trait, _ := range s {
|
|
|
|
if !other.Contains(trait) {
|
|
|
|
remainder = append(remainder, trait)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewSdkMemberTraitSet(remainder)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s sdkMemberTraitSet) String() string {
|
|
|
|
list := []string{}
|
|
|
|
for trait, _ := range s {
|
|
|
|
list = append(list, trait.SdkPropertyName())
|
|
|
|
}
|
|
|
|
sort.Strings(list)
|
|
|
|
return fmt.Sprintf("[%s]", strings.Join(list, ","))
|
|
|
|
}
|
|
|
|
|
2021-09-22 12:51:09 +02:00
|
|
|
var registeredSdkMemberTraits = &sdkRegistry{}
|
2021-09-22 12:49:47 +02:00
|
|
|
|
|
|
|
// RegisteredSdkMemberTraits returns a OnceKey and a sorted list of registered traits.
|
|
|
|
//
|
|
|
|
// The key uniquely identifies the array of traits and can be used with OncePer.Once() to cache
|
|
|
|
// information derived from the array of traits.
|
|
|
|
func RegisteredSdkMemberTraits() (OnceKey, []SdkMemberTrait) {
|
2021-09-22 12:51:09 +02:00
|
|
|
registerables := registeredSdkMemberTraits.registeredObjects()
|
|
|
|
traits := make([]SdkMemberTrait, len(registerables))
|
|
|
|
for i, registerable := range registerables {
|
|
|
|
traits[i] = registerable.(SdkMemberTrait)
|
|
|
|
}
|
|
|
|
return registeredSdkMemberTraits.uniqueOnceKey(), traits
|
2021-09-22 12:49:47 +02:00
|
|
|
}
|
2021-07-14 13:08:37 +02:00
|
|
|
|
|
|
|
// RegisterSdkMemberTrait registers an SdkMemberTrait object to allow them to be used in the
|
|
|
|
// module_exports, module_exports_snapshot, sdk and sdk_snapshot module types.
|
|
|
|
func RegisterSdkMemberTrait(trait SdkMemberTrait) {
|
2021-09-22 12:49:47 +02:00
|
|
|
registeredSdkMemberTraits = registeredSdkMemberTraits.copyAndAppend(trait)
|
2021-07-14 13:08:37 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkMember is an individual member of the SDK.
|
|
|
|
//
|
|
|
|
// It includes all of the variants that the SDK depends upon.
|
2019-11-28 15:31:38 +01:00
|
|
|
type SdkMember interface {
|
2021-09-09 16:38:32 +02:00
|
|
|
// Name returns the name of the member.
|
2019-11-28 15:31:38 +01:00
|
|
|
Name() string
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// Variants returns all the variants of this module depended upon by the SDK.
|
2022-11-23 19:09:54 +01:00
|
|
|
Variants() []Module
|
2019-11-28 15:31:38 +01:00
|
|
|
}
|
|
|
|
|
2021-09-02 15:29:21 +02:00
|
|
|
// SdkMemberDependencyTag is the interface that a tag must implement in order to allow the
|
2021-05-06 13:02:27 +02:00
|
|
|
// dependent module to be automatically added to the sdk.
|
2021-09-02 15:29:21 +02:00
|
|
|
type SdkMemberDependencyTag interface {
|
2019-11-19 20:44:10 +01:00
|
|
|
blueprint.DependencyTag
|
|
|
|
|
2021-04-23 22:20:20 +02:00
|
|
|
// SdkMemberType returns the SdkMemberType that will be used to automatically add the child module
|
|
|
|
// to the sdk.
|
2021-05-26 11:16:01 +02:00
|
|
|
//
|
|
|
|
// Returning nil will prevent the module being added to the sdk.
|
2021-04-28 00:17:56 +02:00
|
|
|
SdkMemberType(child Module) SdkMemberType
|
2021-04-23 22:20:20 +02:00
|
|
|
|
|
|
|
// ExportMember determines whether a module added to the sdk through this tag will be exported
|
|
|
|
// from the sdk or not.
|
|
|
|
//
|
|
|
|
// An exported member is added to the sdk using its own name, e.g. if "foo" was exported from sdk
|
|
|
|
// "bar" then its prebuilt would be simply called "foo". A member can be added to the sdk via
|
|
|
|
// multiple tags and if any of those tags returns true from this method then the membe will be
|
|
|
|
// exported. Every module added directly to the sdk via one of the member type specific
|
|
|
|
// properties, e.g. java_libs, will automatically be exported.
|
|
|
|
//
|
|
|
|
// If a member is not exported then it is treated as an internal implementation detail of the
|
|
|
|
// sdk and so will be added with an sdk specific name. e.g. if "foo" was an internal member of sdk
|
|
|
|
// "bar" then its prebuilt would be called "bar_foo". Additionally its visibility will be set to
|
|
|
|
// "//visibility:private" so it will not be accessible from outside its Android.bp file.
|
|
|
|
ExportMember() bool
|
2019-11-19 20:44:10 +01:00
|
|
|
}
|
|
|
|
|
2021-09-02 15:29:21 +02:00
|
|
|
var _ SdkMemberDependencyTag = (*sdkMemberDependencyTag)(nil)
|
|
|
|
var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil)
|
2020-07-09 18:32:57 +02:00
|
|
|
|
2021-09-02 15:29:21 +02:00
|
|
|
type sdkMemberDependencyTag struct {
|
2019-11-19 20:44:10 +01:00
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
memberType SdkMemberType
|
2021-04-23 22:20:20 +02:00
|
|
|
export bool
|
2019-11-19 20:44:10 +01:00
|
|
|
}
|
|
|
|
|
2021-09-02 15:29:21 +02:00
|
|
|
func (t *sdkMemberDependencyTag) SdkMemberType(_ Module) SdkMemberType {
|
2019-11-19 20:44:10 +01:00
|
|
|
return t.memberType
|
|
|
|
}
|
|
|
|
|
2021-09-02 15:29:21 +02:00
|
|
|
func (t *sdkMemberDependencyTag) ExportMember() bool {
|
2021-04-23 22:20:20 +02:00
|
|
|
return t.export
|
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// ReplaceSourceWithPrebuilt prevents dependencies from the sdk/module_exports onto their members
|
|
|
|
// from being replaced with a preferred prebuilt.
|
2021-09-02 15:29:21 +02:00
|
|
|
func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool {
|
2020-07-09 18:32:57 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-09-02 15:29:21 +02:00
|
|
|
// DependencyTagForSdkMemberType creates an SdkMemberDependencyTag that will cause any
|
2021-04-23 22:20:20 +02:00
|
|
|
// dependencies added by the tag to be added to the sdk as the specified SdkMemberType and exported
|
|
|
|
// (or not) as specified by the export parameter.
|
2021-09-02 15:29:21 +02:00
|
|
|
func DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMemberDependencyTag {
|
|
|
|
return &sdkMemberDependencyTag{memberType: memberType, export: export}
|
2019-11-19 20:44:10 +01:00
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkMemberType is the interface that must be implemented for every type that can be a member of an
|
2019-11-28 15:31:38 +01:00
|
|
|
// sdk.
|
|
|
|
//
|
|
|
|
// The basic implementation should look something like this, where ModuleType is
|
|
|
|
// the name of the module type being supported.
|
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// type moduleTypeSdkMemberType struct {
|
|
|
|
// android.SdkMemberTypeBase
|
|
|
|
// }
|
2019-11-28 15:31:38 +01:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// func init() {
|
|
|
|
// android.RegisterSdkMemberType(&moduleTypeSdkMemberType{
|
|
|
|
// SdkMemberTypeBase: android.SdkMemberTypeBase{
|
|
|
|
// PropertyName: "module_types",
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
// }
|
2019-11-28 15:31:38 +01:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// ...methods...
|
2019-11-28 15:31:38 +01:00
|
|
|
type SdkMemberType interface {
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkPropertyName returns the name of the member type property on an sdk module.
|
2019-12-13 12:22:16 +01:00
|
|
|
SdkPropertyName() string
|
|
|
|
|
2021-05-11 01:31:38 +02:00
|
|
|
// RequiresBpProperty returns true if this member type requires its property to be usable within
|
|
|
|
// an Android.bp file.
|
|
|
|
RequiresBpProperty() bool
|
|
|
|
|
2022-07-01 17:56:06 +02:00
|
|
|
// SupportedBuildReleases returns the string representation of a set of target build releases that
|
|
|
|
// support this member type.
|
|
|
|
SupportedBuildReleases() string
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot,
|
|
|
|
// false otherwise.
|
2019-12-16 18:43:48 +01:00
|
|
|
UsableWithSdkAndSdkSnapshot() bool
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// IsHostOsDependent returns true if prebuilt host artifacts may be specific to the host OS. Only
|
|
|
|
// applicable to modules where HostSupported() is true. If this is true, snapshots will list each
|
|
|
|
// host OS variant explicitly and disable all other host OS'es.
|
2020-07-11 05:52:24 +02:00
|
|
|
IsHostOsDependent() bool
|
|
|
|
|
2022-05-13 02:40:00 +02:00
|
|
|
// SupportedLinkages returns the names of the linkage variants supported by this module.
|
|
|
|
SupportedLinkages() []string
|
|
|
|
|
2022-05-13 15:12:19 +02:00
|
|
|
// ArePrebuiltsRequired returns true if prebuilts are required in the sdk snapshot, false
|
|
|
|
// otherwise.
|
|
|
|
ArePrebuiltsRequired() bool
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// AddDependencies adds dependencies from the SDK module to all the module variants the member
|
|
|
|
// type contributes to the SDK. `names` is the list of module names given in the member type
|
|
|
|
// property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants
|
|
|
|
// required is determined by the SDK and its properties. The dependencies must be added with the
|
|
|
|
// supplied tag.
|
2019-11-28 15:31:38 +01:00
|
|
|
//
|
|
|
|
// The BottomUpMutatorContext provided is for the SDK module.
|
2021-07-14 11:29:36 +02:00
|
|
|
AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string)
|
2019-11-28 15:31:38 +01:00
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// IsInstance returns true if the supplied module is an instance of this member type.
|
2019-11-28 15:31:38 +01:00
|
|
|
//
|
2021-09-09 16:38:32 +02:00
|
|
|
// This is used to check the type of each variant before added to the SdkMember. Returning false
|
|
|
|
// will cause an error to be logged explaining that the module is not allowed in whichever sdk
|
|
|
|
// property it was added.
|
2019-11-28 15:31:38 +01:00
|
|
|
IsInstance(module Module) bool
|
|
|
|
|
2021-05-11 00:58:40 +02:00
|
|
|
// UsesSourceModuleTypeInSnapshot returns true when the AddPrebuiltModule() method returns a
|
|
|
|
// source module type.
|
|
|
|
UsesSourceModuleTypeInSnapshot() bool
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// AddPrebuiltModule is called to add a prebuilt module that the sdk will populate.
|
2020-02-27 17:00:53 +01:00
|
|
|
//
|
2020-05-06 13:41:39 +02:00
|
|
|
// The sdk module code generates the snapshot as follows:
|
2020-02-27 17:00:53 +01:00
|
|
|
//
|
|
|
|
// * A properties struct of type SdkMemberProperties is created for each variant and
|
2022-11-23 19:09:54 +01:00
|
|
|
// populated with information from the variant by calling PopulateFromVariant(Module)
|
2020-02-27 17:00:53 +01:00
|
|
|
// on the struct.
|
|
|
|
//
|
|
|
|
// * An additional properties struct is created into which the common properties will be
|
|
|
|
// added.
|
|
|
|
//
|
|
|
|
// * The variant property structs are analysed to find exported (capitalized) fields which
|
|
|
|
// have common values. Those fields are cleared and the common value added to the common
|
2020-05-06 11:23:19 +02:00
|
|
|
// properties.
|
|
|
|
//
|
2022-09-22 16:30:58 +02:00
|
|
|
// A field annotated with a tag of `sdk:"ignore"` will be treated as if it
|
|
|
|
// was not capitalized, i.e. ignored and not optimized for common values.
|
2020-02-27 17:00:53 +01:00
|
|
|
//
|
2022-09-22 17:21:54 +02:00
|
|
|
// A field annotated with a tag of `sdk:"keep"` will not be cleared even if the value is common
|
|
|
|
// across multiple structs. Common values will still be copied into the common property struct.
|
|
|
|
// So, if the same value is placed in all structs populated from variants that value would be
|
|
|
|
// copied into all common property structs and so be available in every instance.
|
|
|
|
//
|
2020-05-06 11:23:19 +02:00
|
|
|
// A field annotated with a tag of `android:"arch_variant"` will be allowed to have
|
|
|
|
// values that differ by arch, fields not tagged as such must have common values across
|
|
|
|
// all variants.
|
|
|
|
//
|
2020-04-30 19:08:29 +02:00
|
|
|
// * Additional field tags can be specified on a field that will ignore certain values
|
|
|
|
// for the purpose of common value optimization. A value that is ignored must have the
|
|
|
|
// default value for the property type. This is to ensure that significant value are not
|
|
|
|
// ignored by accident. The purpose of this is to allow the snapshot generation to reflect
|
|
|
|
// the behavior of the runtime. e.g. if a property is ignored on the host then a property
|
|
|
|
// that is common for android can be treated as if it was common for android and host as
|
|
|
|
// the setting for host is ignored anyway.
|
|
|
|
// * `sdk:"ignored-on-host" - this indicates the property is ignored on the host variant.
|
|
|
|
//
|
2020-02-27 17:00:53 +01:00
|
|
|
// * The sdk module type populates the BpModule structure, creating the arch specific
|
|
|
|
// structure and calls AddToPropertySet(...) on the properties struct to add the member
|
|
|
|
// specific properties in the correct place in the structure.
|
|
|
|
//
|
2020-03-19 17:11:18 +01:00
|
|
|
AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule
|
2020-02-27 17:00:53 +01:00
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// CreateVariantPropertiesStruct creates a structure into which variant specific properties can be
|
|
|
|
// added.
|
2020-02-27 17:00:53 +01:00
|
|
|
CreateVariantPropertiesStruct() SdkMemberProperties
|
2021-07-14 13:08:37 +02:00
|
|
|
|
|
|
|
// SupportedTraits returns the set of traits supported by this member type.
|
|
|
|
SupportedTraits() SdkMemberTraitSet
|
2022-05-13 02:40:00 +02:00
|
|
|
|
|
|
|
// Overrides returns whether type overrides other SdkMemberType
|
|
|
|
Overrides(SdkMemberType) bool
|
2019-11-28 15:31:38 +01:00
|
|
|
}
|
2019-12-13 12:22:16 +01:00
|
|
|
|
2021-09-22 12:51:09 +02:00
|
|
|
var _ sdkRegisterable = (SdkMemberType)(nil)
|
|
|
|
|
2021-07-14 11:29:36 +02:00
|
|
|
// SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies()
|
|
|
|
// implementations.
|
|
|
|
type SdkDependencyContext interface {
|
|
|
|
BottomUpMutatorContext
|
2021-07-14 13:08:37 +02:00
|
|
|
|
|
|
|
// RequiredTraits returns the set of SdkMemberTrait instances that the sdk requires the named
|
|
|
|
// member to provide.
|
|
|
|
RequiredTraits(name string) SdkMemberTraitSet
|
|
|
|
|
|
|
|
// RequiresTrait returns true if the sdk requires the member with the supplied name to provide the
|
|
|
|
// supplied trait.
|
|
|
|
RequiresTrait(name string, trait SdkMemberTrait) bool
|
2021-07-14 11:29:36 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkMemberTypeBase is the base type for SdkMemberType implementations and must be embedded in any
|
|
|
|
// struct that implements SdkMemberType.
|
2019-12-13 12:22:16 +01:00
|
|
|
type SdkMemberTypeBase struct {
|
2021-05-11 01:31:38 +02:00
|
|
|
PropertyName string
|
|
|
|
|
2022-05-13 02:40:00 +02:00
|
|
|
// Property names that this SdkMemberTypeBase can override, this is useful when a module type is a
|
|
|
|
// superset of another module type.
|
|
|
|
OverridesPropertyNames map[string]bool
|
|
|
|
|
|
|
|
// The names of linkage variants supported by this module.
|
|
|
|
SupportedLinkageNames []string
|
|
|
|
|
2021-05-11 01:31:38 +02:00
|
|
|
// When set to true BpPropertyNotRequired indicates that the member type does not require the
|
|
|
|
// property to be specifiable in an Android.bp file.
|
|
|
|
BpPropertyNotRequired bool
|
|
|
|
|
2022-07-01 17:56:06 +02:00
|
|
|
// The name of the first targeted build release.
|
|
|
|
//
|
|
|
|
// If not specified then it is assumed to be available on all targeted build releases.
|
|
|
|
SupportedBuildReleaseSpecification string
|
|
|
|
|
2022-05-13 15:12:19 +02:00
|
|
|
// Set to true if this must be usable with the sdk/sdk_snapshot module types. Otherwise, it will
|
|
|
|
// only be usable with module_exports/module_exports_snapshots module types.
|
|
|
|
SupportsSdk bool
|
|
|
|
|
|
|
|
// Set to true if prebuilt host artifacts of this member may be specific to the host OS. Only
|
|
|
|
// applicable to modules where HostSupported() is true.
|
2021-05-06 13:02:27 +02:00
|
|
|
HostOsDependent bool
|
2021-05-11 00:58:40 +02:00
|
|
|
|
|
|
|
// When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source
|
|
|
|
// module type in its SdkMemberType.AddPrebuiltModule() method. That prevents the sdk snapshot
|
|
|
|
// code from automatically adding a prefer: true flag.
|
|
|
|
UseSourceModuleTypeInSnapshot bool
|
2021-07-14 13:08:37 +02:00
|
|
|
|
2022-05-13 15:12:19 +02:00
|
|
|
// Set to proptools.BoolPtr(false) if this member does not generate prebuilts but is only provided
|
|
|
|
// to allow the sdk to gather members from this member's dependencies. If not specified then
|
|
|
|
// defaults to true.
|
|
|
|
PrebuiltsRequired *bool
|
|
|
|
|
2021-07-14 13:08:37 +02:00
|
|
|
// The list of supported traits.
|
|
|
|
Traits []SdkMemberTrait
|
2019-12-13 12:22:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *SdkMemberTypeBase) SdkPropertyName() string {
|
|
|
|
return b.PropertyName
|
|
|
|
}
|
|
|
|
|
2021-05-11 01:31:38 +02:00
|
|
|
func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
|
|
|
|
return !b.BpPropertyNotRequired
|
|
|
|
}
|
|
|
|
|
2022-07-01 17:56:06 +02:00
|
|
|
func (b *SdkMemberTypeBase) SupportedBuildReleases() string {
|
|
|
|
return b.SupportedBuildReleaseSpecification
|
|
|
|
}
|
|
|
|
|
2019-12-16 18:43:48 +01:00
|
|
|
func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
|
|
|
|
return b.SupportsSdk
|
|
|
|
}
|
|
|
|
|
2020-07-11 05:52:24 +02:00
|
|
|
func (b *SdkMemberTypeBase) IsHostOsDependent() bool {
|
|
|
|
return b.HostOsDependent
|
|
|
|
}
|
|
|
|
|
2022-05-13 15:12:19 +02:00
|
|
|
func (b *SdkMemberTypeBase) ArePrebuiltsRequired() bool {
|
|
|
|
return proptools.BoolDefault(b.PrebuiltsRequired, true)
|
|
|
|
}
|
|
|
|
|
2021-05-11 00:58:40 +02:00
|
|
|
func (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool {
|
|
|
|
return b.UseSourceModuleTypeInSnapshot
|
|
|
|
}
|
|
|
|
|
2021-07-14 13:08:37 +02:00
|
|
|
func (b *SdkMemberTypeBase) SupportedTraits() SdkMemberTraitSet {
|
|
|
|
return NewSdkMemberTraitSet(b.Traits)
|
|
|
|
}
|
|
|
|
|
2022-05-13 02:40:00 +02:00
|
|
|
func (b *SdkMemberTypeBase) Overrides(other SdkMemberType) bool {
|
|
|
|
return b.OverridesPropertyNames[other.SdkPropertyName()]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *SdkMemberTypeBase) SupportedLinkages() []string {
|
|
|
|
return b.SupportedLinkageNames
|
|
|
|
}
|
|
|
|
|
2021-09-22 12:49:47 +02:00
|
|
|
// registeredModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports
|
|
|
|
// modules.
|
2021-09-22 12:51:09 +02:00
|
|
|
var registeredModuleExportsMemberTypes = &sdkRegistry{}
|
2021-09-22 12:49:47 +02:00
|
|
|
|
2021-09-22 12:51:09 +02:00
|
|
|
// registeredSdkMemberTypes is the set of registered registeredSdkMemberTypes for sdk modules.
|
|
|
|
var registeredSdkMemberTypes = &sdkRegistry{}
|
2021-09-22 12:49:47 +02:00
|
|
|
|
|
|
|
// RegisteredSdkMemberTypes returns a OnceKey and a sorted list of registered types.
|
|
|
|
//
|
|
|
|
// If moduleExports is true then the slice of types includes all registered types that can be used
|
|
|
|
// with the module_exports and module_exports_snapshot module types. Otherwise, the slice of types
|
|
|
|
// only includes those registered types that can be used with the sdk and sdk_snapshot module
|
|
|
|
// types.
|
|
|
|
//
|
|
|
|
// The key uniquely identifies the array of types and can be used with OncePer.Once() to cache
|
|
|
|
// information derived from the array of types.
|
|
|
|
func RegisteredSdkMemberTypes(moduleExports bool) (OnceKey, []SdkMemberType) {
|
2021-09-22 12:51:09 +02:00
|
|
|
var registry *sdkRegistry
|
2021-09-22 12:49:47 +02:00
|
|
|
if moduleExports {
|
|
|
|
registry = registeredModuleExportsMemberTypes
|
|
|
|
} else {
|
|
|
|
registry = registeredSdkMemberTypes
|
|
|
|
}
|
2021-07-14 13:05:16 +02:00
|
|
|
|
2021-09-22 12:51:09 +02:00
|
|
|
registerables := registry.registeredObjects()
|
|
|
|
types := make([]SdkMemberType, len(registerables))
|
|
|
|
for i, registerable := range registerables {
|
|
|
|
types[i] = registerable.(SdkMemberType)
|
|
|
|
}
|
|
|
|
return registry.uniqueOnceKey(), types
|
2021-09-22 12:49:47 +02:00
|
|
|
}
|
2019-12-16 18:43:48 +01:00
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// RegisterSdkMemberType registers an SdkMemberType object to allow them to be used in the
|
|
|
|
// module_exports, module_exports_snapshot and (depending on the value returned from
|
|
|
|
// SdkMemberType.UsableWithSdkAndSdkSnapshot) the sdk and sdk_snapshot module types.
|
2019-12-16 18:43:48 +01:00
|
|
|
func RegisterSdkMemberType(memberType SdkMemberType) {
|
|
|
|
// All member types are usable with module_exports.
|
2021-09-22 12:49:47 +02:00
|
|
|
registeredModuleExportsMemberTypes = registeredModuleExportsMemberTypes.copyAndAppend(memberType)
|
2019-12-16 18:43:48 +01:00
|
|
|
|
|
|
|
// Only those that explicitly indicate it are usable with sdk.
|
|
|
|
if memberType.UsableWithSdkAndSdkSnapshot() {
|
2021-09-22 12:49:47 +02:00
|
|
|
registeredSdkMemberTypes = registeredSdkMemberTypes.copyAndAppend(memberType)
|
2019-12-16 18:43:48 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-27 17:00:53 +01:00
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkMemberPropertiesBase is the base structure for all implementations of SdkMemberProperties and
|
|
|
|
// must be embedded in any struct that implements SdkMemberProperties.
|
2020-02-27 17:00:53 +01:00
|
|
|
//
|
2020-07-10 01:14:03 +02:00
|
|
|
// Contains common properties that apply across many different member types.
|
2020-02-27 17:00:53 +01:00
|
|
|
type SdkMemberPropertiesBase struct {
|
2020-03-02 11:16:35 +01:00
|
|
|
// The number of unique os types supported by the member variants.
|
2020-03-17 22:04:24 +01:00
|
|
|
//
|
|
|
|
// If a member has a variant with more than one os type then it will need to differentiate
|
|
|
|
// the locations of any of their prebuilt files in the snapshot by os type to prevent them
|
|
|
|
// from colliding. See OsPrefix().
|
|
|
|
//
|
2022-09-22 16:30:58 +02:00
|
|
|
// Ignore this property during optimization. This is needed because this property is the same for
|
|
|
|
// all variants of a member and so would be optimized away if it was not ignored.
|
|
|
|
Os_count int `sdk:"ignore"`
|
2020-03-02 11:16:35 +01:00
|
|
|
|
|
|
|
// The os type for which these properties refer.
|
2020-03-17 22:04:24 +01:00
|
|
|
//
|
|
|
|
// Provided to allow a member to differentiate between os types in the locations of their
|
|
|
|
// prebuilt files when it supports more than one os type.
|
|
|
|
//
|
2022-09-22 16:30:58 +02:00
|
|
|
// Ignore this property during optimization. This is needed because this property is the same for
|
|
|
|
// all variants of a member and so would be optimized away if it was not ignored.
|
|
|
|
Os OsType `sdk:"ignore"`
|
2020-03-17 22:04:24 +01:00
|
|
|
|
|
|
|
// The setting to use for the compile_multilib property.
|
2020-07-10 01:14:03 +02:00
|
|
|
Compile_multilib string `android:"arch_variant"`
|
2020-03-02 11:16:35 +01:00
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// OsPrefix returns the os prefix to use for any file paths in the sdk.
|
2020-03-02 11:16:35 +01:00
|
|
|
//
|
|
|
|
// Is an empty string if the member only provides variants for a single os type, otherwise
|
|
|
|
// is the OsType.Name.
|
|
|
|
func (b *SdkMemberPropertiesBase) OsPrefix() string {
|
|
|
|
if b.Os_count == 1 {
|
|
|
|
return ""
|
|
|
|
} else {
|
|
|
|
return b.Os.Name
|
|
|
|
}
|
2020-02-27 17:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *SdkMemberPropertiesBase) Base() *SdkMemberPropertiesBase {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkMemberProperties is the interface to be implemented on top of a structure that contains
|
|
|
|
// variant specific information.
|
2020-02-27 17:00:53 +01:00
|
|
|
//
|
2021-09-09 16:38:32 +02:00
|
|
|
// Struct fields that are capitalized are examined for common values to extract. Fields that are not
|
|
|
|
// capitalized are assumed to be arch specific.
|
2020-02-27 17:00:53 +01:00
|
|
|
type SdkMemberProperties interface {
|
2021-09-09 16:38:32 +02:00
|
|
|
// Base returns the base structure.
|
2020-02-27 17:00:53 +01:00
|
|
|
Base() *SdkMemberPropertiesBase
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// PopulateFromVariant populates this structure with information from a module variant.
|
|
|
|
//
|
|
|
|
// It will typically be called once for each variant of a member module that the SDK depends upon.
|
2020-03-19 17:11:18 +01:00
|
|
|
PopulateFromVariant(ctx SdkMemberContext, variant Module)
|
2020-02-27 17:00:53 +01:00
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// AddToPropertySet adds the information from this structure to the property set.
|
|
|
|
//
|
|
|
|
// This will be called for each instance of this structure on which the PopulateFromVariant method
|
|
|
|
// was called and also on a number of different instances of this structure into which properties
|
|
|
|
// common to one or more variants have been copied. Therefore, implementations of this must handle
|
|
|
|
// the case when this structure is only partially populated.
|
2020-03-19 17:11:18 +01:00
|
|
|
AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet)
|
|
|
|
}
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkMemberContext provides access to information common to a specific member.
|
2020-03-19 17:11:18 +01:00
|
|
|
type SdkMemberContext interface {
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SdkModuleContext returns the module context of the sdk common os variant which is creating the
|
|
|
|
// snapshot.
|
|
|
|
//
|
|
|
|
// This is common to all members of the sdk and is not specific to the member being processed.
|
|
|
|
// If information about the member being processed needs to be obtained from this ModuleContext it
|
|
|
|
// must be obtained using one of the OtherModule... methods not the Module... methods.
|
2020-03-19 17:11:18 +01:00
|
|
|
SdkModuleContext() ModuleContext
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// SnapshotBuilder the builder of the snapshot.
|
2020-03-19 17:11:18 +01:00
|
|
|
SnapshotBuilder() SnapshotBuilder
|
2020-03-17 22:04:24 +01:00
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// MemberType returns the type of the member currently being processed.
|
2020-03-17 22:04:24 +01:00
|
|
|
MemberType() SdkMemberType
|
|
|
|
|
2021-09-09 16:38:32 +02:00
|
|
|
// Name returns the name of the member currently being processed.
|
2020-03-17 22:04:24 +01:00
|
|
|
//
|
|
|
|
// Provided for use by sdk members to create a member specific location within the snapshot
|
|
|
|
// into which to copy the prebuilt files.
|
|
|
|
Name() string
|
2021-07-14 13:08:37 +02:00
|
|
|
|
|
|
|
// RequiresTrait returns true if this member is expected to provide the specified trait.
|
|
|
|
RequiresTrait(trait SdkMemberTrait) bool
|
2022-07-15 15:12:35 +02:00
|
|
|
|
|
|
|
// IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is
|
|
|
|
// being generated is before Tiramisu, i.e. S.
|
|
|
|
IsTargetBuildBeforeTiramisu() bool
|
2023-04-28 21:32:27 +02:00
|
|
|
|
|
|
|
// ModuleErrorf reports an error at the line number of the module type in the module definition.
|
|
|
|
ModuleErrorf(fmt string, args ...interface{})
|
2020-02-27 17:00:53 +01:00
|
|
|
}
|
Remove duplicate component from sdk snapshot
Previously, an sdk snapshot could contain the following:
* A java_sdk_library_import module, e.g. "foo" which creates component
modules "foo.stubs", etc.
* A corresponding versioned module, e.g. "sdk_foo@current" which
created component modules "sdk_foo@current.stubs", etc.
* An internal (to the sdk snapshot) java_import for one of "foo"'s
components, e.g. "sdk_foo.stubs"
* A corresponding versioned module, e.g. "sdk_foo.stubs@current".
That causes a few problems:
1. The "foo.stubs" is duplicated.
2. The names of the components created by the versioned
java_sdk_library_import are invalid, as they append the component's
suffix to the version and not the name before the version.
The latter causes problems when building against prebuilts and fixing
that causes the generated snapshot to be invalid because it contains
duplicate definitions of the "sdk_foo.stubs@current" module. One
explicitly in the Android.bp file and one created by the
"sdk_foo@current" module.
Removing the duplicates from the snapshot causes errors as the name
generated by the snapshot for the component module, i.e.
"sdk_foo.stubs@current" does not match the name generated by the
"sdk_foo@current", i.e. "sdk_foo@current.stubs".
This change fixes them together.
Bug: 179354495
Test: m nothing
Merged-In: I515f235fe21755b5275af12366e96c24c94c0273
Change-Id: I515f235fe21755b5275af12366e96c24c94c0273
(cherry picked from commit a1aa7387f74a49c8c974ba2198def0e081488624)
2021-04-29 22:50:40 +02:00
|
|
|
|
|
|
|
// ExportedComponentsInfo contains information about the components that this module exports to an
|
|
|
|
// sdk snapshot.
|
|
|
|
//
|
|
|
|
// A component of a module is a child module that the module creates and which forms an integral
|
|
|
|
// part of the functionality that the creating module provides. A component module is essentially
|
|
|
|
// owned by its creator and is tightly coupled to the creator and other components.
|
|
|
|
//
|
|
|
|
// e.g. the child modules created by prebuilt_apis are not components because they are not tightly
|
|
|
|
// coupled to the prebuilt_apis module. Once they are created the prebuilt_apis ignores them. The
|
|
|
|
// child impl and stub library created by java_sdk_library (and corresponding import) are components
|
|
|
|
// because the creating module depends upon them in order to provide some of its own functionality.
|
|
|
|
//
|
|
|
|
// A component is exported if it is part of an sdk snapshot. e.g. The xml and impl child modules are
|
|
|
|
// components but they are not exported as they are not part of an sdk snapshot.
|
|
|
|
//
|
|
|
|
// This information is used by the sdk snapshot generation code to ensure that it does not create
|
|
|
|
// an sdk snapshot that contains a declaration of the component module and the module that creates
|
|
|
|
// it as that would result in duplicate modules when attempting to use the snapshot. e.g. a snapshot
|
|
|
|
// that included the java_sdk_library_import "foo" and also a java_import "foo.stubs" would fail
|
|
|
|
// as there would be two modules called "foo.stubs".
|
|
|
|
type ExportedComponentsInfo struct {
|
|
|
|
// The names of the exported components.
|
|
|
|
Components []string
|
|
|
|
}
|
|
|
|
|
2023-12-13 01:39:03 +01:00
|
|
|
var ExportedComponentsInfoProvider = blueprint.NewProvider[ExportedComponentsInfo]()
|
2022-05-16 15:10:47 +02:00
|
|
|
|
|
|
|
// AdditionalSdkInfo contains additional properties to add to the generated SDK info file.
|
|
|
|
type AdditionalSdkInfo struct {
|
|
|
|
Properties map[string]interface{}
|
|
|
|
}
|
|
|
|
|
2023-12-13 01:39:03 +01:00
|
|
|
var AdditionalSdkInfoProvider = blueprint.NewProvider[AdditionalSdkInfo]()
|