2018-04-10 06:07:10 +02:00
|
|
|
// Copyright 2018 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 java
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
2018-10-19 06:46:09 +02:00
|
|
|
"path/filepath"
|
2020-04-07 20:27:04 +02:00
|
|
|
"reflect"
|
2020-05-14 16:39:10 +02:00
|
|
|
"regexp"
|
2018-04-23 14:41:26 +02:00
|
|
|
"sort"
|
2018-04-10 06:07:10 +02:00
|
|
|
"strings"
|
2018-04-23 14:41:26 +02:00
|
|
|
"sync"
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
"github.com/google/blueprint"
|
2018-04-10 06:07:10 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2020-04-07 20:27:04 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
2018-04-10 06:07:10 +02:00
|
|
|
)
|
|
|
|
|
2019-12-18 07:34:32 +01:00
|
|
|
const (
|
2020-05-08 16:52:37 +02:00
|
|
|
sdkXmlFileSuffix = ".xml"
|
|
|
|
permissionsTemplate = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n` +
|
2019-12-24 10:38:06 +01:00
|
|
|
`<!-- Copyright (C) 2018 The Android Open Source Project\n` +
|
|
|
|
`\n` +
|
2020-02-17 09:28:10 +01:00
|
|
|
` Licensed under the Apache License, Version 2.0 (the \"License\");\n` +
|
2019-12-24 10:38:06 +01:00
|
|
|
` you may not use this file except in compliance with the License.\n` +
|
|
|
|
` You may obtain a copy of the License at\n` +
|
|
|
|
`\n` +
|
|
|
|
` http://www.apache.org/licenses/LICENSE-2.0\n` +
|
|
|
|
`\n` +
|
|
|
|
` Unless required by applicable law or agreed to in writing, software\n` +
|
2020-02-17 09:28:10 +01:00
|
|
|
` distributed under the License is distributed on an \"AS IS\" BASIS,\n` +
|
2019-12-24 10:38:06 +01:00
|
|
|
` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
|
|
|
|
` See the License for the specific language governing permissions and\n` +
|
|
|
|
` limitations under the License.\n` +
|
|
|
|
`-->\n` +
|
|
|
|
`<permissions>\n` +
|
2020-02-17 09:28:10 +01:00
|
|
|
` <library name=\"%s\" file=\"%s\"/>\n` +
|
2019-12-24 10:38:06 +01:00
|
|
|
`</permissions>\n`
|
2018-04-10 06:07:10 +02:00
|
|
|
)
|
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
// A tag to associated a dependency with a specific api scope.
|
|
|
|
type scopeDependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
apiScope *apiScope
|
2020-04-29 21:45:27 +02:00
|
|
|
|
|
|
|
// Function for extracting appropriate path information from the dependency.
|
|
|
|
depInfoExtractor func(paths *scopePaths, dep android.Module) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract tag specific information from the dependency.
|
|
|
|
func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) {
|
|
|
|
err := tag.depInfoExtractor(paths, dep)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error())
|
|
|
|
}
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
2018-04-27 09:29:21 +02:00
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
// Provides information about an api scope, e.g. public, system, test.
|
|
|
|
type apiScope struct {
|
|
|
|
// The name of the api scope, e.g. public, system, test
|
|
|
|
name string
|
2018-04-27 09:29:21 +02:00
|
|
|
|
2020-05-05 15:40:52 +02:00
|
|
|
// The api scope that this scope extends.
|
|
|
|
extends *apiScope
|
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
// The legacy enabled status for a specific scope can be dependent on other
|
|
|
|
// properties that have been specified on the library so it is provided by
|
|
|
|
// a function that can determine the status by examining those properties.
|
|
|
|
legacyEnabledStatus func(module *SdkLibrary) bool
|
|
|
|
|
|
|
|
// The default enabled status for non-legacy behavior, which is triggered by
|
|
|
|
// explicitly enabling at least one api scope.
|
|
|
|
defaultEnabledStatus bool
|
|
|
|
|
|
|
|
// Gets a pointer to the scope specific properties.
|
|
|
|
scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties
|
|
|
|
|
2020-04-07 20:27:04 +02:00
|
|
|
// The name of the field in the dynamically created structure.
|
|
|
|
fieldName string
|
|
|
|
|
2020-05-13 20:19:49 +02:00
|
|
|
// The name of the property in the java_sdk_library_import
|
|
|
|
propertyName string
|
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
// The tag to use to depend on the stubs library module.
|
|
|
|
stubsTag scopeDependencyTag
|
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
// The tag to use to depend on the stubs source module (if separate from the API module).
|
|
|
|
stubsSourceTag scopeDependencyTag
|
|
|
|
|
|
|
|
// The tag to use to depend on the API file generating module (if separate from the stubs source module).
|
|
|
|
apiFileTag scopeDependencyTag
|
|
|
|
|
2020-04-29 21:45:27 +02:00
|
|
|
// The tag to use to depend on the stubs source and API module.
|
|
|
|
stubsSourceAndApiTag scopeDependencyTag
|
2020-01-22 12:57:20 +01:00
|
|
|
|
|
|
|
// The scope specific prefix to add to the api file base of "current.txt" or "removed.txt".
|
|
|
|
apiFilePrefix string
|
|
|
|
|
|
|
|
// The scope specific prefix to add to the sdk library module name to construct a scope specific
|
|
|
|
// module name.
|
|
|
|
moduleSuffix string
|
|
|
|
|
|
|
|
// SDK version that the stubs library is built against. Note that this is always
|
|
|
|
// *current. Older stubs library built with a numbered SDK version is created from
|
|
|
|
// the prebuilt jar.
|
|
|
|
sdkVersion string
|
2020-04-07 19:50:10 +02:00
|
|
|
|
|
|
|
// Extra arguments to pass to droidstubs for this scope.
|
|
|
|
droidstubsArgs []string
|
2020-05-02 12:19:36 +02:00
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
// The args that must be passed to droidstubs to generate the stubs source
|
|
|
|
// for this scope.
|
|
|
|
//
|
|
|
|
// The stubs source must include the definitions of everything that is in this
|
|
|
|
// api scope and all the scopes that this one extends.
|
|
|
|
droidstubsArgsForGeneratingStubsSource []string
|
|
|
|
|
|
|
|
// The args that must be passed to droidstubs to generate the API for this scope.
|
|
|
|
//
|
|
|
|
// The API only includes the additional members that this scope adds over the scope
|
|
|
|
// that it extends.
|
|
|
|
droidstubsArgsForGeneratingApi []string
|
|
|
|
|
|
|
|
// True if the stubs source and api can be created by the same metalava invocation.
|
|
|
|
createStubsSourceAndApiTogether bool
|
|
|
|
|
2020-05-02 12:19:36 +02:00
|
|
|
// Whether the api scope can be treated as unstable, and should skip compat checks.
|
|
|
|
unstable bool
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize a scope, creating and adding appropriate dependency tags
|
|
|
|
func initApiScope(scope *apiScope) *apiScope {
|
2020-04-29 21:45:27 +02:00
|
|
|
name := scope.name
|
2020-05-14 16:39:10 +02:00
|
|
|
scopeByName[name] = scope
|
|
|
|
allScopeNames = append(allScopeNames, name)
|
2020-05-13 20:19:49 +02:00
|
|
|
scope.propertyName = strings.ReplaceAll(name, "-", "_")
|
|
|
|
scope.fieldName = proptools.FieldNameForProperty(scope.propertyName)
|
2020-01-22 12:57:20 +01:00
|
|
|
scope.stubsTag = scopeDependencyTag{
|
2020-04-29 21:45:27 +02:00
|
|
|
name: name + "-stubs",
|
|
|
|
apiScope: scope,
|
|
|
|
depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency,
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
2020-04-29 14:30:54 +02:00
|
|
|
scope.stubsSourceTag = scopeDependencyTag{
|
|
|
|
name: name + "-stubs-source",
|
|
|
|
apiScope: scope,
|
|
|
|
depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep,
|
|
|
|
}
|
|
|
|
scope.apiFileTag = scopeDependencyTag{
|
|
|
|
name: name + "-api",
|
|
|
|
apiScope: scope,
|
|
|
|
depInfoExtractor: (*scopePaths).extractApiInfoFromDep,
|
|
|
|
}
|
2020-04-29 21:45:27 +02:00
|
|
|
scope.stubsSourceAndApiTag = scopeDependencyTag{
|
|
|
|
name: name + "-stubs-source-and-api",
|
|
|
|
apiScope: scope,
|
|
|
|
depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider,
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
2020-04-29 14:30:54 +02:00
|
|
|
|
|
|
|
// To get the args needed to generate the stubs source append all the args from
|
|
|
|
// this scope and all the scopes it extends as each set of args adds additional
|
|
|
|
// members to the stubs.
|
|
|
|
var stubsSourceArgs []string
|
|
|
|
for s := scope; s != nil; s = s.extends {
|
|
|
|
stubsSourceArgs = append(stubsSourceArgs, s.droidstubsArgs...)
|
|
|
|
}
|
|
|
|
scope.droidstubsArgsForGeneratingStubsSource = stubsSourceArgs
|
|
|
|
|
|
|
|
// Currently the args needed to generate the API are the same as the args
|
|
|
|
// needed to add additional members.
|
|
|
|
apiArgs := scope.droidstubsArgs
|
|
|
|
scope.droidstubsArgsForGeneratingApi = apiArgs
|
|
|
|
|
|
|
|
// If the args needed to generate the stubs and API are the same then they
|
|
|
|
// can be generated in a single invocation of metalava, otherwise they will
|
|
|
|
// need separate invocations.
|
|
|
|
scope.createStubsSourceAndApiTogether = reflect.DeepEqual(stubsSourceArgs, apiArgs)
|
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
return scope
|
|
|
|
}
|
|
|
|
|
2020-05-08 15:16:20 +02:00
|
|
|
func (scope *apiScope) stubsLibraryModuleName(baseName string) string {
|
2020-05-08 16:52:37 +02:00
|
|
|
return baseName + ".stubs" + scope.moduleSuffix
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
|
|
|
|
2020-04-29 21:45:27 +02:00
|
|
|
func (scope *apiScope) stubsSourceModuleName(baseName string) string {
|
2020-05-08 16:52:37 +02:00
|
|
|
return baseName + ".stubs.source" + scope.moduleSuffix
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
func (scope *apiScope) apiModuleName(baseName string) string {
|
2020-05-08 16:52:37 +02:00
|
|
|
return baseName + ".api" + scope.moduleSuffix
|
2020-04-29 14:30:54 +02:00
|
|
|
}
|
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
func (scope *apiScope) String() string {
|
|
|
|
return scope.name
|
|
|
|
}
|
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
type apiScopes []*apiScope
|
|
|
|
|
|
|
|
func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string {
|
|
|
|
var list []string
|
|
|
|
for _, scope := range scopes {
|
|
|
|
list = append(list, accessor(scope))
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-05-14 16:39:10 +02:00
|
|
|
scopeByName = make(map[string]*apiScope)
|
|
|
|
allScopeNames []string
|
2020-01-22 12:57:20 +01:00
|
|
|
apiScopePublic = initApiScope(&apiScope{
|
2020-04-28 11:44:03 +02:00
|
|
|
name: "public",
|
|
|
|
|
|
|
|
// Public scope is enabled by default for both legacy and non-legacy modes.
|
|
|
|
legacyEnabledStatus: func(module *SdkLibrary) bool {
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
defaultEnabledStatus: true,
|
|
|
|
|
|
|
|
scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
|
|
|
|
return &module.sdkLibraryProperties.Public
|
|
|
|
},
|
2020-01-22 12:57:20 +01:00
|
|
|
sdkVersion: "current",
|
|
|
|
})
|
|
|
|
apiScopeSystem = initApiScope(&apiScope{
|
2020-04-28 11:44:03 +02:00
|
|
|
name: "system",
|
|
|
|
extends: apiScopePublic,
|
|
|
|
legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
|
|
|
|
scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
|
|
|
|
return &module.sdkLibraryProperties.System
|
|
|
|
},
|
2020-04-28 17:47:41 +02:00
|
|
|
apiFilePrefix: "system-",
|
2020-05-08 16:52:37 +02:00
|
|
|
moduleSuffix: ".system",
|
2020-04-28 17:47:41 +02:00
|
|
|
sdkVersion: "system_current",
|
2020-04-29 23:18:41 +02:00
|
|
|
droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS\\)"},
|
2020-01-22 12:57:20 +01:00
|
|
|
})
|
|
|
|
apiScopeTest = initApiScope(&apiScope{
|
2020-04-28 11:44:03 +02:00
|
|
|
name: "test",
|
|
|
|
extends: apiScopePublic,
|
|
|
|
legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
|
|
|
|
scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
|
|
|
|
return &module.sdkLibraryProperties.Test
|
|
|
|
},
|
2020-04-28 17:47:41 +02:00
|
|
|
apiFilePrefix: "test-",
|
2020-05-08 16:52:37 +02:00
|
|
|
moduleSuffix: ".test",
|
2020-04-28 17:47:41 +02:00
|
|
|
sdkVersion: "test_current",
|
|
|
|
droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"},
|
2020-05-02 12:19:36 +02:00
|
|
|
unstable: true,
|
2020-01-22 12:57:20 +01:00
|
|
|
})
|
2020-04-28 15:13:56 +02:00
|
|
|
apiScopeModuleLib = initApiScope(&apiScope{
|
2020-05-13 20:19:49 +02:00
|
|
|
name: "module-lib",
|
2020-04-28 15:13:56 +02:00
|
|
|
extends: apiScopeSystem,
|
2020-06-02 14:00:08 +02:00
|
|
|
// The module-lib scope is disabled by default in legacy mode.
|
2020-04-28 15:13:56 +02:00
|
|
|
//
|
|
|
|
// Enabling this would break existing usages.
|
|
|
|
legacyEnabledStatus: func(module *SdkLibrary) bool {
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
|
|
|
|
return &module.sdkLibraryProperties.Module_lib
|
|
|
|
},
|
|
|
|
apiFilePrefix: "module-lib-",
|
|
|
|
moduleSuffix: ".module_lib",
|
|
|
|
sdkVersion: "module_current",
|
|
|
|
droidstubsArgs: []string{
|
|
|
|
"--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)",
|
|
|
|
},
|
|
|
|
})
|
2020-06-02 14:00:08 +02:00
|
|
|
apiScopeSystemServer = initApiScope(&apiScope{
|
|
|
|
name: "system-server",
|
|
|
|
extends: apiScopePublic,
|
|
|
|
// The system-server scope is disabled by default in legacy mode.
|
|
|
|
//
|
|
|
|
// Enabling this would break existing usages.
|
|
|
|
legacyEnabledStatus: func(module *SdkLibrary) bool {
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
|
|
|
|
return &module.sdkLibraryProperties.System_server
|
|
|
|
},
|
|
|
|
apiFilePrefix: "system-server-",
|
|
|
|
moduleSuffix: ".system_server",
|
|
|
|
sdkVersion: "system_server_current",
|
|
|
|
droidstubsArgs: []string{
|
|
|
|
"--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.SYSTEM_SERVER\\) ",
|
|
|
|
"--hide-annotation android.annotation.Hide",
|
|
|
|
// com.android.* classes are okay in this interface"
|
|
|
|
"--hide InternalClasses",
|
|
|
|
},
|
|
|
|
})
|
2020-01-22 12:57:20 +01:00
|
|
|
allApiScopes = apiScopes{
|
|
|
|
apiScopePublic,
|
|
|
|
apiScopeSystem,
|
|
|
|
apiScopeTest,
|
2020-04-28 15:13:56 +02:00
|
|
|
apiScopeModuleLib,
|
2020-06-02 14:00:08 +02:00
|
|
|
apiScopeSystemServer,
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
)
|
|
|
|
|
2018-04-23 14:41:26 +02:00
|
|
|
var (
|
|
|
|
javaSdkLibrariesLock sync.Mutex
|
|
|
|
)
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// TODO: these are big features that are currently missing
|
2018-05-28 11:02:19 +02:00
|
|
|
// 1) disallowing linking to the runtime shared lib
|
|
|
|
// 2) HTML generation
|
2018-04-10 06:07:10 +02:00
|
|
|
|
|
|
|
func init() {
|
2019-12-19 12:18:54 +01:00
|
|
|
RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2018-04-23 14:41:26 +02:00
|
|
|
android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
|
|
|
|
javaSdkLibraries := javaSdkLibraries(ctx.Config())
|
|
|
|
sort.Strings(*javaSdkLibraries)
|
|
|
|
ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
|
|
|
|
})
|
2020-02-10 14:37:10 +01:00
|
|
|
|
|
|
|
// Register sdk member types.
|
|
|
|
android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{
|
|
|
|
android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_sdk_libs",
|
|
|
|
SupportsSdk: true,
|
|
|
|
},
|
|
|
|
})
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2019-12-19 12:18:54 +01:00
|
|
|
func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
|
|
|
|
ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
|
|
|
|
}
|
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
// Properties associated with each api scope.
|
|
|
|
type ApiScopeProperties struct {
|
|
|
|
// Indicates whether the api surface is generated.
|
|
|
|
//
|
|
|
|
// If this is set for any scope then all scopes must explicitly specify if they
|
|
|
|
// are enabled. This is to prevent new usages from depending on legacy behavior.
|
|
|
|
//
|
|
|
|
// Otherwise, if this is not set for any scope then the default behavior is
|
|
|
|
// scope specific so please refer to the scope specific property documentation.
|
|
|
|
Enabled *bool
|
2020-05-12 12:50:28 +02:00
|
|
|
|
|
|
|
// The sdk_version to use for building the stubs.
|
|
|
|
//
|
|
|
|
// If not specified then it will use an sdk_version determined as follows:
|
|
|
|
// 1) If the sdk_version specified on the java_sdk_library is none then this
|
|
|
|
// will be none. This is used for java_sdk_library instances that are used
|
|
|
|
// to create stubs that contribute to the core_current sdk version.
|
|
|
|
// 2) Otherwise, it is assumed that this library extends but does not contribute
|
|
|
|
// directly to a specific sdk_version and so this uses the sdk_version appropriate
|
|
|
|
// for the api scope. e.g. public will use sdk_version: current, system will use
|
|
|
|
// sdk_version: system_current, etc.
|
|
|
|
//
|
|
|
|
// This does not affect the sdk_version used for either generating the stubs source
|
|
|
|
// or the API file. They both have to use the same sdk_version as is used for
|
|
|
|
// compiling the implementation library.
|
|
|
|
Sdk_version *string
|
2020-04-28 11:44:03 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
type sdkLibraryProperties struct {
|
2020-05-16 16:52:12 +02:00
|
|
|
// Visibility for impl library module. If not specified then defaults to the
|
|
|
|
// visibility property.
|
|
|
|
Impl_library_visibility []string
|
|
|
|
|
2020-04-30 00:35:13 +02:00
|
|
|
// Visibility for stubs library modules. If not specified then defaults to the
|
|
|
|
// visibility property.
|
|
|
|
Stubs_library_visibility []string
|
|
|
|
|
|
|
|
// Visibility for stubs source modules. If not specified then defaults to the
|
|
|
|
// visibility property.
|
|
|
|
Stubs_source_visibility []string
|
|
|
|
|
2018-06-25 09:04:37 +02:00
|
|
|
// List of Java libraries that will be in the classpath when building stubs
|
|
|
|
Stub_only_libs []string `android:"arch_variant"`
|
|
|
|
|
2019-12-30 18:09:34 +01:00
|
|
|
// list of package names that will be documented and publicized as API.
|
|
|
|
// This allows the API to be restricted to a subset of the source files provided.
|
|
|
|
// If this is unspecified then all the source files will be treated as being part
|
|
|
|
// of the API.
|
2018-04-10 06:07:10 +02:00
|
|
|
Api_packages []string
|
|
|
|
|
2018-05-01 15:25:41 +02:00
|
|
|
// list of package names that must be hidden from the API
|
|
|
|
Hidden_api_packages []string
|
|
|
|
|
2019-12-30 18:23:46 +01:00
|
|
|
// the relative path to the directory containing the api specification files.
|
|
|
|
// Defaults to "api".
|
|
|
|
Api_dir *string
|
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
// Determines whether a runtime implementation library is built; defaults to false.
|
|
|
|
//
|
|
|
|
// If true then it also prevents the module from being used as a shared module, i.e.
|
|
|
|
// it is as is shared_library: false, was set.
|
2019-12-30 18:35:49 +01:00
|
|
|
Api_only *bool
|
|
|
|
|
2019-02-11 16:55:17 +01:00
|
|
|
// local files that are used within user customized droiddoc options.
|
|
|
|
Droiddoc_option_files []string
|
|
|
|
|
|
|
|
// additional droiddoc options
|
|
|
|
// Available variables for substitution:
|
|
|
|
//
|
|
|
|
// $(location <label>): the path to the droiddoc_option_files with name <label>
|
2018-07-31 10:19:11 +02:00
|
|
|
Droiddoc_options []string
|
|
|
|
|
2018-10-19 06:46:09 +02:00
|
|
|
// a list of top-level directories containing files to merge qualifier annotations
|
|
|
|
// (i.e. those intended to be included in the stubs written) from.
|
|
|
|
Merge_annotations_dirs []string
|
|
|
|
|
|
|
|
// a list of top-level directories containing Java stub files to merge show/hide annotations from.
|
|
|
|
Merge_inclusion_annotations_dirs []string
|
|
|
|
|
|
|
|
// If set to true, the path of dist files is apistubs/core. Defaults to false.
|
|
|
|
Core_lib *bool
|
|
|
|
|
2019-05-13 08:02:50 +02:00
|
|
|
// don't create dist rules.
|
|
|
|
No_dist *bool `blueprint:"mutated"`
|
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
// indicates whether system and test apis should be generated.
|
|
|
|
Generate_system_and_test_apis bool `blueprint:"mutated"`
|
|
|
|
|
|
|
|
// The properties specific to the public api scope
|
|
|
|
//
|
|
|
|
// Unless explicitly specified by using public.enabled the public api scope is
|
|
|
|
// enabled by default in both legacy and non-legacy mode.
|
|
|
|
Public ApiScopeProperties
|
|
|
|
|
|
|
|
// The properties specific to the system api scope
|
|
|
|
//
|
|
|
|
// In legacy mode the system api scope is enabled by default when sdk_version
|
|
|
|
// is set to something other than "none".
|
|
|
|
//
|
|
|
|
// In non-legacy mode the system api scope is disabled by default.
|
|
|
|
System ApiScopeProperties
|
|
|
|
|
|
|
|
// The properties specific to the test api scope
|
|
|
|
//
|
|
|
|
// In legacy mode the test api scope is enabled by default when sdk_version
|
|
|
|
// is set to something other than "none".
|
|
|
|
//
|
|
|
|
// In non-legacy mode the test api scope is disabled by default.
|
|
|
|
Test ApiScopeProperties
|
2019-12-30 18:20:10 +01:00
|
|
|
|
2020-06-02 14:00:08 +02:00
|
|
|
// The properties specific to the module-lib api scope
|
2020-04-28 15:13:56 +02:00
|
|
|
//
|
2020-06-02 14:00:08 +02:00
|
|
|
// Unless explicitly specified by using test.enabled the module-lib api scope is
|
2020-04-28 15:13:56 +02:00
|
|
|
// disabled by default.
|
|
|
|
Module_lib ApiScopeProperties
|
|
|
|
|
2020-06-02 14:00:08 +02:00
|
|
|
// The properties specific to the system-server api scope
|
|
|
|
//
|
|
|
|
// Unless explicitly specified by using test.enabled the module-lib api scope is
|
|
|
|
// disabled by default.
|
|
|
|
System_server ApiScopeProperties
|
|
|
|
|
2020-05-27 17:19:53 +02:00
|
|
|
// Determines if the stubs are preferred over the implementation library
|
|
|
|
// for linking, even when the client doesn't specify sdk_version. When this
|
|
|
|
// is set to true, such clients are provided with the widest API surface that
|
|
|
|
// this lib provides. Note however that this option doesn't affect the clients
|
|
|
|
// that are in the same APEX as this library. In that case, the clients are
|
|
|
|
// always linked with the implementation library. Default is false.
|
|
|
|
Default_to_stubs *bool
|
|
|
|
|
2020-05-10 20:32:20 +02:00
|
|
|
// Properties related to api linting.
|
|
|
|
Api_lint struct {
|
|
|
|
// Enable api linting.
|
|
|
|
Enabled *bool
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// TODO: determines whether to create HTML doc or not
|
|
|
|
//Html_doc *bool
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:18:00 +02:00
|
|
|
// Paths to outputs from java_sdk_library and java_sdk_library_import.
|
|
|
|
//
|
|
|
|
// Fields that are android.Paths are always set (during GenerateAndroidBuildActions).
|
|
|
|
// OptionalPaths are always set by java_sdk_library but may not be set by
|
|
|
|
// java_sdk_library_import as not all instances provide that information.
|
2020-01-22 12:57:20 +01:00
|
|
|
type scopePaths struct {
|
2020-05-20 17:18:00 +02:00
|
|
|
// The path (represented as Paths for convenience when returning) to the stubs header jar.
|
|
|
|
//
|
|
|
|
// That is the jar that is created by turbine.
|
|
|
|
stubsHeaderPath android.Paths
|
|
|
|
|
|
|
|
// The path (represented as Paths for convenience when returning) to the stubs implementation jar.
|
|
|
|
//
|
|
|
|
// This is not the implementation jar, it still only contains stubs.
|
|
|
|
stubsImplPath android.Paths
|
|
|
|
|
|
|
|
// The API specification file, e.g. system_current.txt.
|
|
|
|
currentApiFilePath android.OptionalPath
|
|
|
|
|
|
|
|
// The specification of API elements removed since the last release.
|
|
|
|
removedApiFilePath android.OptionalPath
|
|
|
|
|
|
|
|
// The stubs source jar.
|
|
|
|
stubsSrcJar android.OptionalPath
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
|
|
|
|
2020-04-29 21:45:27 +02:00
|
|
|
func (paths *scopePaths) extractStubsLibraryInfoFromDependency(dep android.Module) error {
|
|
|
|
if lib, ok := dep.(Dependency); ok {
|
|
|
|
paths.stubsHeaderPath = lib.HeaderJars()
|
|
|
|
paths.stubsImplPath = lib.ImplementationJars()
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("expected module that implements Dependency, e.g. java_library")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error {
|
|
|
|
if apiStubsProvider, ok := dep.(ApiStubsProvider); ok {
|
|
|
|
action(apiStubsProvider)
|
2020-04-29 21:45:27 +02:00
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:18:00 +02:00
|
|
|
func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider)) error {
|
|
|
|
if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok {
|
|
|
|
action(apiStubsProvider)
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) {
|
2020-05-20 17:18:00 +02:00
|
|
|
paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath())
|
|
|
|
paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath())
|
2020-04-29 14:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (paths *scopePaths) extractApiInfoFromDep(dep android.Module) error {
|
|
|
|
return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
|
|
|
|
paths.extractApiInfoFromApiStubsProvider(provider)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:18:00 +02:00
|
|
|
func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider) {
|
|
|
|
paths.stubsSrcJar = android.OptionalPathForPath(provider.StubsSrcJar())
|
2020-04-29 14:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (paths *scopePaths) extractStubsSourceInfoFromDep(dep android.Module) error {
|
2020-05-20 17:18:00 +02:00
|
|
|
return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) {
|
2020-04-29 14:30:54 +02:00
|
|
|
paths.extractStubsSourceInfoFromApiStubsProviders(provider)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(dep android.Module) error {
|
|
|
|
return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
|
|
|
|
paths.extractApiInfoFromApiStubsProvider(provider)
|
|
|
|
paths.extractStubsSourceInfoFromApiStubsProviders(provider)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type commonToSdkLibraryAndImportProperties struct {
|
2020-05-08 14:44:43 +02:00
|
|
|
// The naming scheme to use for the components that this module creates.
|
|
|
|
//
|
2020-05-08 16:36:30 +02:00
|
|
|
// If not specified then it defaults to "default". The other allowable value is
|
|
|
|
// "framework-modules" which matches the scheme currently used by framework modules
|
|
|
|
// for the equivalent components represented as separate Soong modules.
|
2020-05-08 14:44:43 +02:00
|
|
|
//
|
|
|
|
// This is a temporary mechanism to simplify conversion from separate modules for each
|
|
|
|
// component that follow a different naming pattern to the default one.
|
|
|
|
//
|
|
|
|
// TODO(b/155480189) - Remove once naming inconsistencies have been resolved.
|
2020-04-29 14:30:54 +02:00
|
|
|
Naming_scheme *string
|
2020-05-15 21:37:11 +02:00
|
|
|
|
|
|
|
// Specifies whether this module can be used as an Android shared library; defaults
|
|
|
|
// to true.
|
|
|
|
//
|
|
|
|
// An Android shared library is one that can be referenced in a <uses-library> element
|
|
|
|
// in an AndroidManifest.xml.
|
|
|
|
Shared_library *bool
|
2020-04-29 14:30:54 +02:00
|
|
|
}
|
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
// Common code between sdk library and sdk library import
|
|
|
|
type commonToSdkLibraryAndImport struct {
|
2020-05-08 15:16:20 +02:00
|
|
|
moduleBase *android.ModuleBase
|
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
scopePaths map[*apiScope]*scopePaths
|
2020-05-08 14:44:43 +02:00
|
|
|
|
|
|
|
namingScheme sdkLibraryComponentNamingScheme
|
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
commonSdkLibraryProperties commonToSdkLibraryAndImportProperties
|
2020-05-15 11:20:31 +02:00
|
|
|
|
|
|
|
// Functionality related to this being used as a component of a java_sdk_library.
|
|
|
|
EmbeddableSdkLibraryComponent
|
2020-01-31 14:36:25 +01:00
|
|
|
}
|
|
|
|
|
2020-05-08 15:16:20 +02:00
|
|
|
func (c *commonToSdkLibraryAndImport) initCommon(moduleBase *android.ModuleBase) {
|
|
|
|
c.moduleBase = moduleBase
|
2020-05-08 14:44:43 +02:00
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
moduleBase.AddProperties(&c.commonSdkLibraryProperties)
|
2020-05-15 11:20:31 +02:00
|
|
|
|
|
|
|
// Initialize this as an sdk library component.
|
|
|
|
c.initSdkLibraryComponent(moduleBase)
|
2020-05-08 14:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool {
|
2020-05-15 21:37:11 +02:00
|
|
|
schemeProperty := proptools.StringDefault(c.commonSdkLibraryProperties.Naming_scheme, "default")
|
2020-05-08 14:44:43 +02:00
|
|
|
switch schemeProperty {
|
|
|
|
case "default":
|
|
|
|
c.namingScheme = &defaultNamingScheme{}
|
2020-05-08 16:36:30 +02:00
|
|
|
case "framework-modules":
|
|
|
|
c.namingScheme = &frameworkModulesNamingScheme{}
|
2020-05-08 14:44:43 +02:00
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
// Only track this sdk library if this can be used as a shared library.
|
|
|
|
if c.sharedLibrary() {
|
|
|
|
// Use the name specified in the module definition as the owner.
|
|
|
|
c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = proptools.StringPtr(c.moduleBase.BaseModuleName())
|
|
|
|
}
|
2020-05-15 11:20:31 +02:00
|
|
|
|
2020-05-08 14:44:43 +02:00
|
|
|
return true
|
2020-05-08 15:16:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name of the java_library module that compiles the stubs source.
|
|
|
|
func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string {
|
2020-05-08 14:44:43 +02:00
|
|
|
return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName())
|
2020-05-08 15:16:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name of the droidstubs module that generates the stubs source and may also
|
|
|
|
// generate/check the API.
|
|
|
|
func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string {
|
2020-05-08 14:44:43 +02:00
|
|
|
return c.namingScheme.stubsSourceModuleName(apiScope, c.moduleBase.BaseModuleName())
|
2020-05-08 15:16:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name of the droidstubs module that generates/checks the API. Only used if it
|
|
|
|
// requires different arts to the stubs source generating module.
|
|
|
|
func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string {
|
2020-05-08 14:44:43 +02:00
|
|
|
return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName())
|
2020-05-08 15:16:20 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:39:10 +02:00
|
|
|
// The component names for different outputs of the java_sdk_library.
|
|
|
|
//
|
|
|
|
// They are similar to the names used for the child modules it creates
|
|
|
|
const (
|
|
|
|
stubsSourceComponentName = "stubs.source"
|
|
|
|
|
|
|
|
apiTxtComponentName = "api.txt"
|
|
|
|
|
|
|
|
removedApiTxtComponentName = "removed-api.txt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// A regular expression to match tags that reference a specific stubs component.
|
|
|
|
//
|
|
|
|
// It will only match if given a valid scope and a valid component. It is verfy strict
|
|
|
|
// to ensure it does not accidentally match a similar looking tag that should be processed
|
|
|
|
// by the embedded Library.
|
|
|
|
var tagSplitter = func() *regexp.Regexp {
|
|
|
|
// Given a list of literal string items returns a regular expression that will
|
|
|
|
// match any one of the items.
|
|
|
|
choice := func(items ...string) string {
|
|
|
|
return `\Q` + strings.Join(items, `\E|\Q`) + `\E`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regular expression to match one of the scopes.
|
|
|
|
scopesRegexp := choice(allScopeNames...)
|
|
|
|
|
|
|
|
// Regular expression to match one of the components.
|
|
|
|
componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName)
|
|
|
|
|
|
|
|
// Regular expression to match any combination of one scope and one component.
|
|
|
|
return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// For OutputFileProducer interface
|
|
|
|
//
|
|
|
|
// .<scope>.stubs.source
|
|
|
|
// .<scope>.api.txt
|
|
|
|
// .<scope>.removed-api.txt
|
|
|
|
func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) {
|
|
|
|
if groups := tagSplitter.FindStringSubmatch(tag); groups != nil {
|
|
|
|
scopeName := groups[1]
|
|
|
|
component := groups[2]
|
|
|
|
|
|
|
|
if scope, ok := scopeByName[scopeName]; ok {
|
|
|
|
paths := c.findScopePaths(scope)
|
|
|
|
if paths == nil {
|
|
|
|
return nil, fmt.Errorf("%q does not provide api scope %s", c.moduleBase.BaseModuleName(), scopeName)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch component {
|
|
|
|
case stubsSourceComponentName:
|
|
|
|
if paths.stubsSrcJar.Valid() {
|
|
|
|
return android.Paths{paths.stubsSrcJar.Path()}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
case apiTxtComponentName:
|
|
|
|
if paths.currentApiFilePath.Valid() {
|
|
|
|
return android.Paths{paths.currentApiFilePath.Path()}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
case removedApiTxtComponentName:
|
|
|
|
if paths.removedApiFilePath.Valid() {
|
|
|
|
return android.Paths{paths.removedApiFilePath.Path()}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName)
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("unknown scope %s in %s", scope, tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-20 12:52:25 +02:00
|
|
|
func (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths {
|
2020-01-31 14:36:25 +01:00
|
|
|
if c.scopePaths == nil {
|
|
|
|
c.scopePaths = make(map[*apiScope]*scopePaths)
|
|
|
|
}
|
|
|
|
paths := c.scopePaths[scope]
|
|
|
|
if paths == nil {
|
|
|
|
paths = &scopePaths{}
|
|
|
|
c.scopePaths[scope] = paths
|
|
|
|
}
|
|
|
|
|
|
|
|
return paths
|
|
|
|
}
|
|
|
|
|
2020-05-20 12:52:25 +02:00
|
|
|
func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths {
|
|
|
|
if c.scopePaths == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.scopePaths[scope]
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this does not support the requested api scope then find the closest available
|
|
|
|
// scope it does support. Returns nil if no such scope is available.
|
|
|
|
func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths {
|
|
|
|
for s := scope; s != nil; s = s.extends {
|
|
|
|
if paths := c.findScopePaths(s); paths != nil {
|
|
|
|
return paths
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should never happen outside tests as public should be the base scope for every
|
|
|
|
// scope and is enabled by default.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-20 15:20:02 +02:00
|
|
|
func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
2020-05-20 13:19:10 +02:00
|
|
|
|
|
|
|
// If a specific numeric version has been requested then use prebuilt versions of the sdk.
|
|
|
|
if sdkVersion.version.isNumbered() {
|
|
|
|
return PrebuiltJars(ctx, c.moduleBase.BaseModuleName(), sdkVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
var apiScope *apiScope
|
|
|
|
switch sdkVersion.kind {
|
|
|
|
case sdkSystem:
|
|
|
|
apiScope = apiScopeSystem
|
2020-05-20 12:52:25 +02:00
|
|
|
case sdkModule:
|
|
|
|
apiScope = apiScopeModuleLib
|
2020-05-20 13:19:10 +02:00
|
|
|
case sdkTest:
|
|
|
|
apiScope = apiScopeTest
|
2020-06-02 14:00:08 +02:00
|
|
|
case sdkSystemServer:
|
|
|
|
apiScope = apiScopeSystemServer
|
2020-05-20 13:19:10 +02:00
|
|
|
default:
|
|
|
|
apiScope = apiScopePublic
|
|
|
|
}
|
|
|
|
|
2020-05-20 12:52:25 +02:00
|
|
|
paths := c.findClosestScopePath(apiScope)
|
|
|
|
if paths == nil {
|
|
|
|
var scopes []string
|
|
|
|
for _, s := range allApiScopes {
|
|
|
|
if c.findScopePaths(s) != nil {
|
|
|
|
scopes = append(scopes, s.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx.ModuleErrorf("requires api scope %s from %s but it only has %q available", apiScope.name, c.moduleBase.BaseModuleName(), scopes)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-20 15:20:02 +02:00
|
|
|
return paths.stubsHeaderPath
|
2020-05-20 13:19:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-15 11:20:31 +02:00
|
|
|
func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} {
|
|
|
|
componentProps := &struct {
|
|
|
|
SdkLibraryToImplicitlyTrack *string
|
2020-05-15 21:37:11 +02:00
|
|
|
}{}
|
|
|
|
|
|
|
|
if c.sharedLibrary() {
|
2020-05-15 11:20:31 +02:00
|
|
|
// Mark the stubs library as being components of this java_sdk_library so that
|
|
|
|
// any app that includes code which depends (directly or indirectly) on the stubs
|
|
|
|
// library will have the appropriate <uses-library> invocation inserted into its
|
|
|
|
// manifest if necessary.
|
2020-05-15 21:37:11 +02:00
|
|
|
componentProps.SdkLibraryToImplicitlyTrack = proptools.StringPtr(c.moduleBase.BaseModuleName())
|
2020-05-15 11:20:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return componentProps
|
|
|
|
}
|
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
// Check if this can be used as a shared library.
|
|
|
|
func (c *commonToSdkLibraryAndImport) sharedLibrary() bool {
|
|
|
|
return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true)
|
|
|
|
}
|
|
|
|
|
2020-05-15 11:20:31 +02:00
|
|
|
// Properties related to the use of a module as an component of a java_sdk_library.
|
|
|
|
type SdkLibraryComponentProperties struct {
|
|
|
|
|
|
|
|
// The name of the java_sdk_library/_import to add to a <uses-library> entry
|
|
|
|
// in the AndroidManifest.xml of any Android app that includes code that references
|
|
|
|
// this module. If not set then no java_sdk_library/_import is tracked.
|
|
|
|
SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Structure to be embedded in a module struct that needs to support the
|
|
|
|
// SdkLibraryComponentDependency interface.
|
|
|
|
type EmbeddableSdkLibraryComponent struct {
|
|
|
|
sdkLibraryComponentProperties SdkLibraryComponentProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(moduleBase *android.ModuleBase) {
|
|
|
|
moduleBase.AddProperties(&e.sdkLibraryComponentProperties)
|
|
|
|
}
|
|
|
|
|
|
|
|
// to satisfy SdkLibraryComponentDependency
|
|
|
|
func (e *EmbeddableSdkLibraryComponent) OptionalImplicitSdkLibrary() []string {
|
|
|
|
if e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack != nil {
|
|
|
|
return []string{*e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implemented by modules that are (or possibly could be) a component of a java_sdk_library
|
|
|
|
// (including the java_sdk_library) itself.
|
|
|
|
type SdkLibraryComponentDependency interface {
|
|
|
|
// The optional name of the sdk library that should be implicitly added to the
|
|
|
|
// AndroidManifest of an app that contains code which references the sdk library.
|
|
|
|
//
|
|
|
|
// Returns an array containing 0 or 1 items rather than a *string to make it easier
|
|
|
|
// to append this to the list of exported sdk libraries.
|
|
|
|
OptionalImplicitSdkLibrary() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that all the module types that are components of java_sdk_library/_import
|
|
|
|
// and which can be referenced (directly or indirectly) from an android app implement
|
|
|
|
// the SdkLibraryComponentDependency interface.
|
|
|
|
var _ SdkLibraryComponentDependency = (*Library)(nil)
|
|
|
|
var _ SdkLibraryComponentDependency = (*Import)(nil)
|
|
|
|
var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil)
|
|
|
|
var _ SdkLibraryComponentDependency = (*sdkLibraryImport)(nil)
|
|
|
|
|
|
|
|
// Provides access to sdk_version related header and implentation jars.
|
|
|
|
type SdkLibraryDependency interface {
|
|
|
|
SdkLibraryComponentDependency
|
|
|
|
|
|
|
|
// Get the header jars appropriate for the supplied sdk_version.
|
|
|
|
//
|
|
|
|
// These are turbine generated jars so they only change if the externals of the
|
|
|
|
// class changes but it does not contain and implementation or JavaDoc.
|
|
|
|
SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
|
|
|
|
|
|
|
|
// Get the implementation jars appropriate for the supplied sdk version.
|
|
|
|
//
|
|
|
|
// These are either the implementation jar for the whole sdk library or the implementation
|
|
|
|
// jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise
|
|
|
|
// they are identical to the corresponding header jars.
|
|
|
|
SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
type SdkLibrary struct {
|
2018-10-19 06:46:09 +02:00
|
|
|
Library
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2018-10-19 06:46:09 +02:00
|
|
|
sdkLibraryProperties sdkLibraryProperties
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
// Map from api scope to the scope specific property structure.
|
|
|
|
scopeToProperties map[*apiScope]*ApiScopeProperties
|
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
commonToSdkLibraryAndImport
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
var _ Dependency = (*SdkLibrary)(nil)
|
|
|
|
var _ SdkLibraryDependency = (*SdkLibrary)(nil)
|
2019-02-11 23:03:51 +01:00
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool {
|
|
|
|
return module.sdkLibraryProperties.Generate_system_and_test_apis
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes {
|
|
|
|
// Check to see if any scopes have been explicitly enabled. If any have then all
|
|
|
|
// must be.
|
|
|
|
anyScopesExplicitlyEnabled := false
|
|
|
|
for _, scope := range allApiScopes {
|
|
|
|
scopeProperties := module.scopeToProperties[scope]
|
|
|
|
if scopeProperties.Enabled != nil {
|
|
|
|
anyScopesExplicitlyEnabled = true
|
|
|
|
break
|
|
|
|
}
|
2019-07-15 08:31:16 +02:00
|
|
|
}
|
2020-04-28 11:44:03 +02:00
|
|
|
|
|
|
|
var generatedScopes apiScopes
|
|
|
|
enabledScopes := make(map[*apiScope]struct{})
|
|
|
|
for _, scope := range allApiScopes {
|
|
|
|
scopeProperties := module.scopeToProperties[scope]
|
|
|
|
// If any scopes are explicitly enabled then ignore the legacy enabled status.
|
|
|
|
// This is to ensure that any new usages of this module type do not rely on legacy
|
|
|
|
// behaviour.
|
|
|
|
defaultEnabledStatus := false
|
|
|
|
if anyScopesExplicitlyEnabled {
|
|
|
|
defaultEnabledStatus = scope.defaultEnabledStatus
|
|
|
|
} else {
|
|
|
|
defaultEnabledStatus = scope.legacyEnabledStatus(module)
|
|
|
|
}
|
|
|
|
enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus)
|
|
|
|
if enabled {
|
|
|
|
enabledScopes[scope] = struct{}{}
|
|
|
|
generatedScopes = append(generatedScopes, scope)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check to make sure that any scope that is extended by an enabled scope is also
|
|
|
|
// enabled.
|
|
|
|
for _, scope := range allApiScopes {
|
|
|
|
if _, ok := enabledScopes[scope]; ok {
|
|
|
|
extends := scope.extends
|
|
|
|
if extends != nil {
|
|
|
|
if _, ok := enabledScopes[extends]; !ok {
|
|
|
|
ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return generatedScopes
|
2020-01-22 12:57:20 +01:00
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
|
2020-02-06 14:51:46 +01:00
|
|
|
var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"}
|
|
|
|
|
2020-02-17 09:28:10 +01:00
|
|
|
func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool {
|
|
|
|
if dt, ok := depTag.(dependencyTag); ok {
|
|
|
|
return dt == xmlPermissionsFileTag
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-05-16 16:52:12 +02:00
|
|
|
var implLibraryTag = dependencyTag{name: "impl-library"}
|
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2020-04-28 11:44:03 +02:00
|
|
|
for _, apiScope := range module.getGeneratedApiScopes(ctx) {
|
2020-01-22 12:57:20 +01:00
|
|
|
// Add dependencies to the stubs library
|
2020-05-08 15:16:20 +02:00
|
|
|
ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
|
2020-01-22 12:57:20 +01:00
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
// If the stubs source and API cannot be generated together then add an additional dependency on
|
|
|
|
// the API module.
|
|
|
|
if apiScope.createStubsSourceAndApiTogether {
|
|
|
|
// Add a dependency on the stubs source in order to access both stubs source and api information.
|
2020-05-08 15:16:20 +02:00
|
|
|
ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))
|
2020-04-29 14:30:54 +02:00
|
|
|
} else {
|
|
|
|
// Add separate dependencies on the creators of the stubs source files and the API.
|
2020-05-08 15:16:20 +02:00
|
|
|
ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
|
|
|
|
ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope))
|
2020-04-29 14:30:54 +02:00
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
if module.requiresRuntimeImplementationLibrary() {
|
2020-05-16 16:52:12 +02:00
|
|
|
// Add dependency to the rule for generating the implementation library.
|
|
|
|
ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName())
|
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
if module.sharedLibrary() {
|
|
|
|
// Add dependency to the rule for generating the xml permissions file
|
|
|
|
ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName())
|
|
|
|
}
|
2020-02-06 14:51:46 +01:00
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
// Only add the deps for the library if it is actually going to be built.
|
|
|
|
module.Library.deps(ctx)
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:39:10 +02:00
|
|
|
func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
paths, err := module.commonOutputFiles(tag)
|
|
|
|
if paths == nil && err == nil {
|
|
|
|
return module.Library.OutputFiles(tag)
|
|
|
|
} else {
|
|
|
|
return paths, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2020-05-15 21:37:11 +02:00
|
|
|
// Only build an implementation library if required.
|
|
|
|
if module.requiresRuntimeImplementationLibrary() {
|
2019-12-30 18:35:49 +01:00
|
|
|
module.Library.GenerateAndroidBuildActions(ctx)
|
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
|
2018-07-06 04:20:23 +02:00
|
|
|
// Record the paths to the header jars of the library (stubs and impl).
|
2020-01-22 12:57:20 +01:00
|
|
|
// When this java_sdk_library is depended upon from others via "libs" property,
|
2018-04-10 06:07:10 +02:00
|
|
|
// the recorded paths will be returned depending on the link type of the caller.
|
|
|
|
ctx.VisitDirectDeps(func(to android.Module) {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(to)
|
|
|
|
|
2020-04-29 21:45:27 +02:00
|
|
|
// Extract information from any of the scope specific dependencies.
|
|
|
|
if scopeTag, ok := tag.(scopeDependencyTag); ok {
|
|
|
|
apiScope := scopeTag.apiScope
|
2020-05-20 12:52:25 +02:00
|
|
|
scopePaths := module.getScopePathsCreateIfNeeded(apiScope)
|
2020-04-29 21:45:27 +02:00
|
|
|
|
|
|
|
// Extract information from the dependency. The exact information extracted
|
|
|
|
// is determined by the nature of the dependency which is determined by the tag.
|
|
|
|
scopeTag.extractDepInfo(ctx, to, scopePaths)
|
2018-07-24 04:19:26 +02:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-12-03 05:24:29 +01:00
|
|
|
func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
|
2020-05-15 21:37:11 +02:00
|
|
|
if !module.requiresRuntimeImplementationLibrary() {
|
2019-12-30 18:35:49 +01:00
|
|
|
return nil
|
|
|
|
}
|
2019-12-03 05:24:29 +01:00
|
|
|
entriesList := module.Library.AndroidMkEntries()
|
|
|
|
entries := &entriesList[0]
|
2019-08-29 23:56:03 +02:00
|
|
|
entries.Required = append(entries.Required, module.xmlFileName())
|
2019-12-03 05:24:29 +01:00
|
|
|
return entriesList
|
2018-04-23 14:41:26 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// Module name of the runtime implementation library
|
2020-05-16 16:52:12 +02:00
|
|
|
func (module *SdkLibrary) implLibraryModuleName() string {
|
|
|
|
return module.BaseModuleName() + ".impl"
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Module name of the XML file for the lib
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) xmlFileName() string {
|
2018-04-10 06:07:10 +02:00
|
|
|
return module.BaseModuleName() + sdkXmlFileSuffix
|
|
|
|
}
|
|
|
|
|
2020-03-27 20:43:19 +01:00
|
|
|
// The dist path of the stub artifacts
|
|
|
|
func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
|
|
|
|
if module.ModuleBase.Owner() != "" {
|
|
|
|
return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name)
|
|
|
|
} else if Bool(module.sdkLibraryProperties.Core_lib) {
|
|
|
|
return path.Join("apistubs", "core", apiScope.name)
|
|
|
|
} else {
|
|
|
|
return path.Join("apistubs", "android", apiScope.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-24 21:31:31 +01:00
|
|
|
// Get the sdk version for use when compiling the stubs library.
|
2020-05-12 16:52:55 +02:00
|
|
|
func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string {
|
2020-05-12 12:50:28 +02:00
|
|
|
scopeProperties := module.scopeToProperties[apiScope]
|
|
|
|
if scopeProperties.Sdk_version != nil {
|
|
|
|
return proptools.String(scopeProperties.Sdk_version)
|
|
|
|
}
|
|
|
|
|
2019-12-24 21:31:31 +01:00
|
|
|
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
|
|
|
|
if sdkDep.hasStandardLibs() {
|
|
|
|
// If building against a standard sdk then use the sdk version appropriate for the scope.
|
2020-01-22 12:57:20 +01:00
|
|
|
return apiScope.sdkVersion
|
2019-12-24 21:31:31 +01:00
|
|
|
} else {
|
|
|
|
// Otherwise, use no system module.
|
|
|
|
return "none"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string {
|
|
|
|
return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest"
|
2018-05-12 15:29:12 +02:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string {
|
|
|
|
return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest"
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 16:52:12 +02:00
|
|
|
// Creates the implementation java library
|
|
|
|
func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) {
|
|
|
|
props := struct {
|
|
|
|
Name *string
|
|
|
|
Visibility []string
|
|
|
|
}{
|
|
|
|
Name: proptools.StringPtr(module.implLibraryModuleName()),
|
|
|
|
Visibility: module.sdkLibraryProperties.Impl_library_visibility,
|
|
|
|
}
|
|
|
|
|
|
|
|
properties := []interface{}{
|
|
|
|
&module.properties,
|
|
|
|
&module.protoProperties,
|
|
|
|
&module.deviceProperties,
|
|
|
|
&module.dexpreoptProperties,
|
|
|
|
&props,
|
|
|
|
module.sdkComponentPropertiesForChildLibrary(),
|
|
|
|
}
|
|
|
|
mctx.CreateModule(LibraryFactory, properties...)
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// Creates a static java library that has API stubs
|
2020-04-29 17:47:28 +02:00
|
|
|
func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) {
|
2018-04-10 06:07:10 +02:00
|
|
|
props := struct {
|
2020-05-16 10:57:59 +02:00
|
|
|
Name *string
|
|
|
|
Visibility []string
|
|
|
|
Srcs []string
|
|
|
|
Installable *bool
|
|
|
|
Sdk_version *string
|
|
|
|
System_modules *string
|
|
|
|
Patch_module *string
|
|
|
|
Libs []string
|
|
|
|
Compile_dex *bool
|
|
|
|
Java_version *string
|
|
|
|
Product_variables struct {
|
2018-04-23 14:41:26 +02:00
|
|
|
Pdk struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
Openjdk9 struct {
|
|
|
|
Srcs []string
|
|
|
|
Javacflags []string
|
|
|
|
}
|
2020-03-27 20:43:19 +01:00
|
|
|
Dist struct {
|
|
|
|
Targets []string
|
|
|
|
Dest *string
|
|
|
|
Dir *string
|
|
|
|
Tag *string
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}{}
|
|
|
|
|
2020-05-08 15:16:20 +02:00
|
|
|
props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
|
2020-04-30 00:35:13 +02:00
|
|
|
|
|
|
|
// If stubs_library_visibility is not set then the created module will use the
|
|
|
|
// visibility of this module.
|
|
|
|
visibility := module.sdkLibraryProperties.Stubs_library_visibility
|
|
|
|
props.Visibility = visibility
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// sources are generated from the droiddoc
|
2020-05-08 15:16:20 +02:00
|
|
|
props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)}
|
2019-12-24 21:31:31 +01:00
|
|
|
sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
|
2019-06-11 13:31:14 +02:00
|
|
|
props.Sdk_version = proptools.StringPtr(sdkVersion)
|
2020-05-16 19:54:24 +02:00
|
|
|
props.System_modules = module.deviceProperties.System_modules
|
|
|
|
props.Patch_module = module.properties.Patch_module
|
2019-12-23 20:40:36 +01:00
|
|
|
props.Installable = proptools.BoolPtr(false)
|
2018-10-19 06:46:09 +02:00
|
|
|
props.Libs = module.sdkLibraryProperties.Stub_only_libs
|
2018-04-23 14:41:26 +02:00
|
|
|
props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
|
2020-05-16 19:54:24 +02:00
|
|
|
props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs
|
|
|
|
props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags
|
2020-05-21 10:21:57 +02:00
|
|
|
// We compile the stubs for 1.8 in line with the main android.jar stubs, and potential
|
|
|
|
// interop with older developer tools that don't support 1.9.
|
|
|
|
props.Java_version = proptools.StringPtr("1.8")
|
2020-05-16 19:54:24 +02:00
|
|
|
if module.deviceProperties.Compile_dex != nil {
|
|
|
|
props.Compile_dex = module.deviceProperties.Compile_dex
|
2018-07-31 10:19:11 +02:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-03-27 20:43:19 +01:00
|
|
|
// Dist the class jar artifact for sdk builds.
|
|
|
|
if !Bool(module.sdkLibraryProperties.No_dist) {
|
|
|
|
props.Dist.Targets = []string{"sdk", "win_sdk"}
|
|
|
|
props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName()))
|
|
|
|
props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
|
|
|
|
props.Dist.Tag = proptools.StringPtr(".jar")
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-05-15 11:20:31 +02:00
|
|
|
mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary())
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2020-04-07 19:49:53 +02:00
|
|
|
// Creates a droidstubs module that creates stubs source files from the given full source
|
2020-04-29 21:45:27 +02:00
|
|
|
// files and also updates and checks the API specification files.
|
2020-04-29 14:30:54 +02:00
|
|
|
func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, createStubSources, createApi bool, scopeSpecificDroidstubsArgs []string) {
|
2018-04-10 06:07:10 +02:00
|
|
|
props := struct {
|
2018-10-19 06:46:09 +02:00
|
|
|
Name *string
|
2020-04-30 00:35:13 +02:00
|
|
|
Visibility []string
|
2018-10-19 06:46:09 +02:00
|
|
|
Srcs []string
|
|
|
|
Installable *bool
|
2019-06-11 13:31:14 +02:00
|
|
|
Sdk_version *string
|
2019-12-24 21:31:31 +01:00
|
|
|
System_modules *string
|
2018-10-19 06:46:09 +02:00
|
|
|
Libs []string
|
2019-02-11 16:55:17 +01:00
|
|
|
Arg_files []string
|
2018-10-19 06:46:09 +02:00
|
|
|
Args *string
|
|
|
|
Java_version *string
|
|
|
|
Merge_annotations_dirs []string
|
|
|
|
Merge_inclusion_annotations_dirs []string
|
2020-04-29 14:30:54 +02:00
|
|
|
Generate_stubs *bool
|
2018-10-19 06:46:09 +02:00
|
|
|
Check_api struct {
|
2019-02-28 06:24:05 +01:00
|
|
|
Current ApiToCheck
|
|
|
|
Last_released ApiToCheck
|
|
|
|
Ignore_missing_latest_api *bool
|
2020-05-10 20:32:20 +02:00
|
|
|
|
|
|
|
Api_lint struct {
|
|
|
|
Enabled *bool
|
|
|
|
New_since *string
|
|
|
|
Baseline_file *string
|
|
|
|
}
|
2018-05-12 15:29:12 +02:00
|
|
|
}
|
2018-05-29 04:35:17 +02:00
|
|
|
Aidl struct {
|
|
|
|
Include_dirs []string
|
|
|
|
Local_include_dirs []string
|
|
|
|
}
|
2020-03-27 20:43:19 +01:00
|
|
|
Dist struct {
|
|
|
|
Targets []string
|
|
|
|
Dest *string
|
|
|
|
Dir *string
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}{}
|
|
|
|
|
2020-04-28 15:08:32 +02:00
|
|
|
// The stubs source processing uses the same compile time classpath when extracting the
|
|
|
|
// API from the implementation library as it does when compiling it. i.e. the same
|
|
|
|
// * sdk version
|
|
|
|
// * system_modules
|
|
|
|
// * libs (static_libs/libs)
|
2019-06-07 11:44:37 +02:00
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
props.Name = proptools.StringPtr(name)
|
2020-04-30 00:35:13 +02:00
|
|
|
|
|
|
|
// If stubs_source_visibility is not set then the created module will use the
|
|
|
|
// visibility of this module.
|
|
|
|
visibility := module.sdkLibraryProperties.Stubs_source_visibility
|
|
|
|
props.Visibility = visibility
|
|
|
|
|
2020-05-16 19:54:24 +02:00
|
|
|
props.Srcs = append(props.Srcs, module.properties.Srcs...)
|
|
|
|
props.Sdk_version = module.deviceProperties.Sdk_version
|
|
|
|
props.System_modules = module.deviceProperties.System_modules
|
2018-04-10 06:07:10 +02:00
|
|
|
props.Installable = proptools.BoolPtr(false)
|
2018-06-05 09:46:14 +02:00
|
|
|
// A droiddoc module has only one Libs property and doesn't distinguish between
|
|
|
|
// shared libs and static libs. So we need to add both of these libs to Libs property.
|
2020-05-16 19:54:24 +02:00
|
|
|
props.Libs = module.properties.Libs
|
|
|
|
props.Libs = append(props.Libs, module.properties.Static_libs...)
|
|
|
|
props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs
|
|
|
|
props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs
|
|
|
|
props.Java_version = module.properties.Java_version
|
2018-10-19 06:46:09 +02:00
|
|
|
|
|
|
|
props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
|
|
|
|
props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
|
|
|
|
|
2020-04-07 19:49:53 +02:00
|
|
|
droidstubsArgs := []string{}
|
2019-12-24 11:41:30 +01:00
|
|
|
if len(module.sdkLibraryProperties.Api_packages) != 0 {
|
2020-04-07 19:49:53 +02:00
|
|
|
droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
|
2019-12-24 11:41:30 +01:00
|
|
|
}
|
|
|
|
if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
|
2020-04-07 19:49:53 +02:00
|
|
|
droidstubsArgs = append(droidstubsArgs,
|
2019-12-24 11:41:30 +01:00
|
|
|
android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
|
|
|
|
}
|
2020-04-07 19:49:53 +02:00
|
|
|
droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...)
|
2019-12-24 11:41:30 +01:00
|
|
|
disabledWarnings := []string{
|
|
|
|
"MissingPermission",
|
|
|
|
"BroadcastBehavior",
|
|
|
|
"HiddenSuperclass",
|
|
|
|
"DeprecationMismatch",
|
|
|
|
"UnavailableSymbol",
|
|
|
|
"SdkConstant",
|
|
|
|
"HiddenTypeParameter",
|
|
|
|
"Todo",
|
|
|
|
"Typo",
|
|
|
|
}
|
2020-04-07 19:49:53 +02:00
|
|
|
droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
|
2018-09-17 06:23:09 +02:00
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
if !createStubSources {
|
|
|
|
// Stubs are not required.
|
|
|
|
props.Generate_stubs = proptools.BoolPtr(false)
|
|
|
|
}
|
|
|
|
|
2020-04-07 19:50:10 +02:00
|
|
|
// Add in scope specific arguments.
|
2020-04-29 14:30:54 +02:00
|
|
|
droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...)
|
2019-02-11 16:55:17 +01:00
|
|
|
props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
|
2020-04-07 19:49:53 +02:00
|
|
|
props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " "))
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
if createApi {
|
|
|
|
// List of APIs identified from the provided source files are created. They are later
|
|
|
|
// compared against to the not-yet-released (a.k.a current) list of APIs and to the
|
|
|
|
// last-released (a.k.a numbered) list of API.
|
|
|
|
currentApiFileName := apiScope.apiFilePrefix + "current.txt"
|
|
|
|
removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
|
|
|
|
apiDir := module.getApiDir()
|
|
|
|
currentApiFileName = path.Join(apiDir, currentApiFileName)
|
|
|
|
removedApiFileName = path.Join(apiDir, removedApiFileName)
|
|
|
|
|
|
|
|
// check against the not-yet-release API
|
|
|
|
props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
|
|
|
|
props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
|
|
|
|
|
|
|
|
if !apiScope.unstable {
|
|
|
|
// check against the latest released API
|
|
|
|
latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope))
|
|
|
|
props.Check_api.Last_released.Api_file = latestApiFilegroupName
|
|
|
|
props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
|
|
|
|
module.latestRemovedApiFilegroupName(apiScope))
|
|
|
|
props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
|
|
|
|
|
|
|
|
if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) {
|
|
|
|
// Enable api lint.
|
|
|
|
props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true)
|
|
|
|
props.Check_api.Api_lint.New_since = latestApiFilegroupName
|
|
|
|
|
|
|
|
// If it exists then pass a lint-baseline.txt through to droidstubs.
|
|
|
|
baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt")
|
|
|
|
baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath)
|
|
|
|
paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil)
|
|
|
|
if err != nil {
|
|
|
|
mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err)
|
|
|
|
}
|
|
|
|
if len(paths) == 1 {
|
|
|
|
props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath)
|
|
|
|
} else if len(paths) != 0 {
|
|
|
|
mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths)
|
|
|
|
}
|
2020-05-10 20:32:20 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2020-04-29 14:30:54 +02:00
|
|
|
// Dist the api txt artifact for sdk builds.
|
|
|
|
if !Bool(module.sdkLibraryProperties.No_dist) {
|
|
|
|
props.Dist.Targets = []string{"sdk", "win_sdk"}
|
|
|
|
props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
|
|
|
|
props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
|
|
|
|
}
|
2020-03-27 20:43:19 +01:00
|
|
|
}
|
|
|
|
|
2019-09-25 20:33:01 +02:00
|
|
|
mctx.CreateModule(DroidstubsFactory, &props)
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:23:13 +01:00
|
|
|
func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool {
|
|
|
|
depTag := mctx.OtherModuleDependencyTag(dep)
|
|
|
|
if depTag == xmlPermissionsFileTag {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return module.Library.DepIsInSameApex(mctx, dep)
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// Creates the xml file that publicizes the runtime library
|
2020-04-29 17:47:28 +02:00
|
|
|
func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
|
2020-02-17 09:28:10 +01:00
|
|
|
props := struct {
|
2020-05-16 10:57:59 +02:00
|
|
|
Name *string
|
|
|
|
Lib_name *string
|
|
|
|
Apex_available []string
|
2020-02-17 09:28:10 +01:00
|
|
|
}{
|
2020-03-09 22:23:13 +01:00
|
|
|
Name: proptools.StringPtr(module.xmlFileName()),
|
|
|
|
Lib_name: proptools.StringPtr(module.BaseModuleName()),
|
|
|
|
Apex_available: module.ApexProperties.Apex_available,
|
2020-02-17 09:28:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mctx.CreateModule(sdkLibraryXmlFactory, &props)
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2020-01-21 17:31:05 +01:00
|
|
|
func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths {
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
var ver sdkVersion
|
|
|
|
var kind sdkKind
|
|
|
|
if s.usePrebuilt(ctx) {
|
|
|
|
ver = s.version
|
|
|
|
kind = s.kind
|
2018-10-19 06:46:09 +02:00
|
|
|
} else {
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
// We don't have prebuilt SDK for the specific sdkVersion.
|
|
|
|
// Instead of breaking the build, fallback to use "system_current"
|
|
|
|
ver = sdkVersionCurrent
|
|
|
|
kind = sdkSystem
|
2018-10-19 06:46:09 +02:00
|
|
|
}
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
|
|
|
|
dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
|
2020-01-21 17:31:05 +01:00
|
|
|
jar := filepath.Join(dir, baseName+".jar")
|
2018-10-19 06:46:09 +02:00
|
|
|
jarPath := android.ExistentPathForSource(ctx, jar)
|
2019-02-28 07:01:28 +01:00
|
|
|
if !jarPath.Valid() {
|
2020-01-07 18:34:44 +01:00
|
|
|
if ctx.Config().AllowMissingDependencies() {
|
|
|
|
return android.Paths{android.PathForSource(ctx, jar)}
|
|
|
|
} else {
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar)
|
2020-01-07 18:34:44 +01:00
|
|
|
}
|
2019-02-28 07:01:28 +01:00
|
|
|
return nil
|
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
return android.Paths{jarPath.Path()}
|
|
|
|
}
|
|
|
|
|
2020-05-26 14:21:35 +02:00
|
|
|
// Get the apex name for module, "" if it is for platform.
|
|
|
|
func getApexNameForModule(module android.Module) string {
|
|
|
|
if apex, ok := module.(android.ApexModule); ok {
|
|
|
|
return apex.ApexName()
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if the other module is within the same named APEX as this module.
|
|
|
|
//
|
|
|
|
// If either this or the other module are on the platform then this will return
|
|
|
|
// false.
|
|
|
|
func (module *SdkLibrary) withinSameApexAs(other android.Module) bool {
|
|
|
|
name := module.ApexName()
|
|
|
|
return name != "" && getApexNameForModule(other) == name
|
|
|
|
}
|
|
|
|
|
2020-05-20 13:19:10 +02:00
|
|
|
func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
|
2020-05-27 17:19:53 +02:00
|
|
|
// If the client doesn't set sdk_version, but if this library prefers stubs over
|
|
|
|
// the impl library, let's provide the widest API surface possible. To do so,
|
|
|
|
// force override sdk_version to module_current so that the closest possible API
|
|
|
|
// surface could be found in selectHeaderJarsForSdkVersion
|
|
|
|
if module.defaultsToStubs() && !sdkVersion.specified() {
|
|
|
|
sdkVersion = sdkSpecFrom("module_current")
|
|
|
|
}
|
2020-01-22 12:57:20 +01:00
|
|
|
|
2020-05-26 19:13:57 +02:00
|
|
|
// Only provide access to the implementation library if it is actually built.
|
|
|
|
if module.requiresRuntimeImplementationLibrary() {
|
|
|
|
// Check any special cases for java_sdk_library.
|
|
|
|
//
|
|
|
|
// Only allow access to the implementation library in the following condition:
|
|
|
|
// * No sdk_version specified on the referencing module.
|
2020-05-26 14:21:35 +02:00
|
|
|
// * The referencing module is in the same apex as this.
|
|
|
|
if sdkVersion.kind == sdkPrivate || module.withinSameApexAs(ctx.Module()) {
|
2020-05-26 19:13:57 +02:00
|
|
|
if headerJars {
|
|
|
|
return module.HeaderJars()
|
|
|
|
} else {
|
|
|
|
return module.ImplementationJars()
|
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
2020-05-20 13:19:10 +02:00
|
|
|
|
2020-05-20 15:20:02 +02:00
|
|
|
return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion)
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
// to satisfy SdkLibraryDependency interface
|
|
|
|
func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
|
|
|
return module.sdkJars(ctx, sdkVersion, true /*headerJars*/)
|
|
|
|
}
|
|
|
|
|
2018-07-13 09:16:44 +02:00
|
|
|
// to satisfy SdkLibraryDependency interface
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
2020-01-22 12:57:20 +01:00
|
|
|
return module.sdkJars(ctx, sdkVersion, false /*headerJars*/)
|
2018-07-13 09:16:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-13 08:02:50 +02:00
|
|
|
func (module *SdkLibrary) SetNoDist() {
|
|
|
|
module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
|
2019-02-04 20:22:08 +01:00
|
|
|
var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
|
|
|
|
|
2018-04-23 14:41:26 +02:00
|
|
|
func javaSdkLibraries(config android.Config) *[]string {
|
2019-02-04 20:22:08 +01:00
|
|
|
return config.Once(javaSdkLibrariesKey, func() interface{} {
|
2018-04-23 14:41:26 +02:00
|
|
|
return &[]string{}
|
|
|
|
}).(*[]string)
|
|
|
|
}
|
|
|
|
|
2019-12-30 18:23:46 +01:00
|
|
|
func (module *SdkLibrary) getApiDir() string {
|
|
|
|
return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api")
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// For a java_sdk_library module, create internal modules for stubs, docs,
|
|
|
|
// runtime libs and xml file. If requested, the stubs and docs are created twice
|
|
|
|
// once for public API level and once for system API level
|
2020-04-29 17:47:28 +02:00
|
|
|
func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) {
|
|
|
|
// If the module has been disabled then don't create any child modules.
|
|
|
|
if !module.Enabled() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-16 19:54:24 +02:00
|
|
|
if len(module.properties.Srcs) == 0 {
|
2019-02-08 13:00:45 +01:00
|
|
|
mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
|
2019-12-18 07:34:32 +01:00
|
|
|
return
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2019-12-30 18:20:10 +01:00
|
|
|
// If this builds against standard libraries (i.e. is not part of the core libraries)
|
|
|
|
// then assume it provides both system and test apis. Otherwise, assume it does not and
|
|
|
|
// also assume it does not contribute to the dist build.
|
|
|
|
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
|
|
|
|
hasSystemAndTestApis := sdkDep.hasStandardLibs()
|
2020-04-28 11:44:03 +02:00
|
|
|
module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis
|
2019-12-30 18:20:10 +01:00
|
|
|
module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
|
|
|
|
|
2019-03-18 02:19:51 +01:00
|
|
|
missing_current_api := false
|
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
generatedScopes := module.getGeneratedApiScopes(mctx)
|
2020-01-22 12:57:20 +01:00
|
|
|
|
2019-12-30 18:23:46 +01:00
|
|
|
apiDir := module.getApiDir()
|
2020-04-28 11:44:03 +02:00
|
|
|
for _, scope := range generatedScopes {
|
2019-03-18 02:19:51 +01:00
|
|
|
for _, api := range []string{"current.txt", "removed.txt"} {
|
2020-01-22 12:57:20 +01:00
|
|
|
path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api)
|
2019-03-18 02:19:51 +01:00
|
|
|
p := android.ExistentPathForSource(mctx, path)
|
|
|
|
if !p.Valid() {
|
|
|
|
mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
|
|
|
|
missing_current_api = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if missing_current_api {
|
|
|
|
script := "build/soong/scripts/gen-java-current-api-files.sh"
|
|
|
|
p := android.ExistentPathForSource(mctx, script)
|
|
|
|
|
|
|
|
if !p.Valid() {
|
|
|
|
panic(fmt.Sprintf("script file %s doesn't exist", script))
|
|
|
|
}
|
|
|
|
|
|
|
|
mctx.ModuleErrorf("One or more current api files are missing. "+
|
|
|
|
"You can update them by:\n"+
|
2019-12-30 18:20:10 +01:00
|
|
|
"%s %q %s && m update-api",
|
2020-01-22 12:57:20 +01:00
|
|
|
script, filepath.Join(mctx.ModuleDir(), apiDir),
|
2020-04-28 11:44:03 +02:00
|
|
|
strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
|
2019-03-18 02:19:51 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-28 11:44:03 +02:00
|
|
|
for _, scope := range generatedScopes {
|
2020-04-29 14:30:54 +02:00
|
|
|
stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource
|
2020-05-08 15:16:20 +02:00
|
|
|
stubsSourceModuleName := module.stubsSourceModuleName(scope)
|
2020-04-29 14:30:54 +02:00
|
|
|
|
|
|
|
// If the args needed to generate the stubs and API are the same then they
|
|
|
|
// can be generated in a single invocation of metalava, otherwise they will
|
|
|
|
// need separate invocations.
|
|
|
|
if scope.createStubsSourceAndApiTogether {
|
|
|
|
// Use the stubs source name for legacy reasons.
|
|
|
|
module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs)
|
|
|
|
} else {
|
|
|
|
module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs)
|
|
|
|
|
|
|
|
apiArgs := scope.droidstubsArgsForGeneratingApi
|
2020-05-08 15:16:20 +02:00
|
|
|
apiName := module.apiModuleName(scope)
|
2020-04-29 14:30:54 +02:00
|
|
|
module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs)
|
|
|
|
}
|
|
|
|
|
2020-01-22 12:57:20 +01:00
|
|
|
module.createStubsLibrary(mctx, scope)
|
2019-12-30 18:35:49 +01:00
|
|
|
}
|
2018-04-23 14:41:26 +02:00
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
if module.requiresRuntimeImplementationLibrary() {
|
2020-05-16 16:52:12 +02:00
|
|
|
// Create child module to create an implementation library.
|
|
|
|
//
|
|
|
|
// This temporarily creates a second implementation library that can be explicitly
|
|
|
|
// referenced.
|
|
|
|
//
|
|
|
|
// TODO(b/156618935) - update comment once only one implementation library is created.
|
|
|
|
module.createImplLibrary(mctx)
|
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
// Only create an XML permissions file that declares the library as being usable
|
|
|
|
// as a shared library if required.
|
|
|
|
if module.sharedLibrary() {
|
|
|
|
module.createXmlFile(mctx)
|
|
|
|
}
|
2019-02-08 13:00:45 +01:00
|
|
|
|
2019-12-30 18:35:49 +01:00
|
|
|
// record java_sdk_library modules so that they are exported to make
|
|
|
|
javaSdkLibraries := javaSdkLibraries(mctx.Config())
|
|
|
|
javaSdkLibrariesLock.Lock()
|
|
|
|
defer javaSdkLibrariesLock.Unlock()
|
|
|
|
*javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) InitSdkLibraryProperties() {
|
2018-10-19 06:46:09 +02:00
|
|
|
module.AddProperties(
|
|
|
|
&module.sdkLibraryProperties,
|
2020-05-16 19:54:24 +02:00
|
|
|
&module.properties,
|
|
|
|
&module.dexpreoptProperties,
|
|
|
|
&module.deviceProperties,
|
|
|
|
&module.protoProperties,
|
2018-10-19 06:46:09 +02:00
|
|
|
)
|
|
|
|
|
2020-05-15 11:20:31 +02:00
|
|
|
module.initSdkLibraryComponent(&module.ModuleBase)
|
|
|
|
|
2020-05-16 19:54:24 +02:00
|
|
|
module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
module.deviceProperties.IsSDKLibrary = true
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
|
2020-05-15 21:37:11 +02:00
|
|
|
func (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool {
|
|
|
|
return !proptools.Bool(module.sdkLibraryProperties.Api_only)
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:19:53 +02:00
|
|
|
func (module *SdkLibrary) defaultsToStubs() bool {
|
|
|
|
return proptools.Bool(module.sdkLibraryProperties.Default_to_stubs)
|
|
|
|
}
|
|
|
|
|
2020-05-08 14:44:43 +02:00
|
|
|
// Defines how to name the individual component modules the sdk library creates.
|
|
|
|
type sdkLibraryComponentNamingScheme interface {
|
|
|
|
stubsLibraryModuleName(scope *apiScope, baseName string) string
|
|
|
|
|
|
|
|
stubsSourceModuleName(scope *apiScope, baseName string) string
|
|
|
|
|
|
|
|
apiModuleName(scope *apiScope, baseName string) string
|
|
|
|
}
|
|
|
|
|
|
|
|
type defaultNamingScheme struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string {
|
|
|
|
return scope.stubsLibraryModuleName(baseName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string {
|
|
|
|
return scope.stubsSourceModuleName(baseName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *defaultNamingScheme) apiModuleName(scope *apiScope, baseName string) string {
|
|
|
|
return scope.apiModuleName(baseName)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil)
|
2020-05-08 16:36:30 +02:00
|
|
|
|
|
|
|
type frameworkModulesNamingScheme struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *frameworkModulesNamingScheme) moduleSuffix(scope *apiScope) string {
|
|
|
|
suffix := scope.name
|
|
|
|
if scope == apiScopeModuleLib {
|
|
|
|
suffix = "module_libs_"
|
|
|
|
}
|
|
|
|
return suffix
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *frameworkModulesNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string {
|
|
|
|
return fmt.Sprintf("%s-stubs-%sapi", baseName, s.moduleSuffix(scope))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *frameworkModulesNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string {
|
|
|
|
return fmt.Sprintf("%s-stubs-srcs-%sapi", baseName, s.moduleSuffix(scope))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *frameworkModulesNamingScheme) apiModuleName(scope *apiScope, baseName string) string {
|
|
|
|
return fmt.Sprintf("%s-api-%sapi", baseName, s.moduleSuffix(scope))
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ sdkLibraryComponentNamingScheme = (*frameworkModulesNamingScheme)(nil)
|
2020-05-08 14:44:43 +02:00
|
|
|
|
2020-05-25 13:20:51 +02:00
|
|
|
func moduleStubLinkType(name string) (stub bool, ret linkType) {
|
|
|
|
// This suffix-based approach is fragile and could potentially mis-trigger.
|
|
|
|
// TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly.
|
|
|
|
if strings.HasSuffix(name, ".stubs.public") || strings.HasSuffix(name, "-stubs-publicapi") {
|
|
|
|
return true, javaSdk
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(name, ".stubs.system") || strings.HasSuffix(name, "-stubs-systemapi") {
|
|
|
|
return true, javaSystem
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(name, ".stubs.module_lib") || strings.HasSuffix(name, "-stubs-module_libs_api") {
|
|
|
|
return true, javaModule
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(name, ".stubs.test") {
|
|
|
|
return true, javaSystem
|
|
|
|
}
|
|
|
|
return false, javaPlatform
|
|
|
|
}
|
|
|
|
|
2019-07-11 19:05:35 +02:00
|
|
|
// java_sdk_library is a special Java library that provides optional platform APIs to apps.
|
|
|
|
// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
|
|
|
|
// are linked against to, 2) droiddoc module that internally generates API stubs source files,
|
|
|
|
// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
|
|
|
|
// the runtime lib to the classpath at runtime if requested via <uses-library>.
|
2019-02-08 13:00:45 +01:00
|
|
|
func SdkLibraryFactory() android.Module {
|
|
|
|
module := &SdkLibrary{}
|
2020-05-08 15:16:20 +02:00
|
|
|
|
|
|
|
// Initialize information common between source and prebuilt.
|
|
|
|
module.initCommon(&module.ModuleBase)
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
module.InitSdkLibraryProperties()
|
2019-12-18 07:34:32 +01:00
|
|
|
android.InitApexModule(module)
|
2018-10-19 06:46:09 +02:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2020-04-28 11:44:03 +02:00
|
|
|
|
|
|
|
// Initialize the map from scope to scope specific properties.
|
|
|
|
scopeToProperties := make(map[*apiScope]*ApiScopeProperties)
|
|
|
|
for _, scope := range allApiScopes {
|
|
|
|
scopeToProperties[scope] = scope.scopeSpecificProperties(module)
|
|
|
|
}
|
|
|
|
module.scopeToProperties = scopeToProperties
|
|
|
|
|
2020-04-30 00:35:13 +02:00
|
|
|
// Add the properties containing visibility rules so that they are checked.
|
2020-05-16 16:52:12 +02:00
|
|
|
android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility)
|
2020-04-30 00:35:13 +02:00
|
|
|
android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility)
|
|
|
|
android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility)
|
|
|
|
|
2020-05-08 14:44:43 +02:00
|
|
|
module.SetDefaultableHook(func(ctx android.DefaultableHookContext) {
|
2020-05-15 21:37:11 +02:00
|
|
|
// If no implementation is required then it cannot be used as a shared library
|
|
|
|
// either.
|
|
|
|
if !module.requiresRuntimeImplementationLibrary() {
|
|
|
|
// If shared_library has been explicitly set to true then it is incompatible
|
|
|
|
// with api_only: true.
|
|
|
|
if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) {
|
|
|
|
ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true")
|
|
|
|
}
|
|
|
|
// Set shared_library: false.
|
|
|
|
module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false)
|
|
|
|
}
|
|
|
|
|
2020-05-08 14:44:43 +02:00
|
|
|
if module.initCommonAfterDefaultsApplied(ctx) {
|
|
|
|
module.CreateInternalModules(ctx)
|
|
|
|
}
|
|
|
|
})
|
2018-04-10 06:07:10 +02:00
|
|
|
return module
|
|
|
|
}
|
2019-04-17 20:11:46 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// SDK library prebuilts
|
|
|
|
//
|
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
// Properties associated with each api scope.
|
|
|
|
type sdkLibraryScopeProperties struct {
|
2019-04-17 20:11:46 +02:00
|
|
|
Jars []string `android:"path"`
|
|
|
|
|
|
|
|
Sdk_version *string
|
|
|
|
|
|
|
|
// List of shared java libs that this module has dependencies to
|
|
|
|
Libs []string
|
2020-04-09 01:10:17 +02:00
|
|
|
|
2020-04-29 21:45:27 +02:00
|
|
|
// The stubs source.
|
2020-04-09 01:10:17 +02:00
|
|
|
Stub_srcs []string `android:"path"`
|
2020-04-09 02:08:11 +02:00
|
|
|
|
|
|
|
// The current.txt
|
2020-05-20 17:18:00 +02:00
|
|
|
Current_api *string `android:"path"`
|
2020-04-09 02:08:11 +02:00
|
|
|
|
|
|
|
// The removed.txt
|
2020-05-20 17:18:00 +02:00
|
|
|
Removed_api *string `android:"path"`
|
2019-04-17 20:11:46 +02:00
|
|
|
}
|
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
type sdkLibraryImportProperties struct {
|
2020-01-31 18:54:30 +01:00
|
|
|
// List of shared java libs, common to all scopes, that this module has
|
|
|
|
// dependencies to
|
|
|
|
Libs []string
|
2020-01-31 14:36:25 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 20:11:46 +02:00
|
|
|
type sdkLibraryImport struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModuleBase
|
|
|
|
prebuilt android.Prebuilt
|
2020-02-10 14:37:10 +01:00
|
|
|
android.ApexModuleBase
|
|
|
|
android.SdkBase
|
2019-04-17 20:11:46 +02:00
|
|
|
|
|
|
|
properties sdkLibraryImportProperties
|
|
|
|
|
2020-04-07 20:27:04 +02:00
|
|
|
// Map from api scope to the scope specific property structure.
|
|
|
|
scopeProperties map[*apiScope]*sdkLibraryScopeProperties
|
|
|
|
|
2020-01-31 14:36:25 +01:00
|
|
|
commonToSdkLibraryAndImport
|
2019-04-17 20:11:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
|
|
|
|
|
2020-04-07 20:27:04 +02:00
|
|
|
// The type of a structure that contains a field of type sdkLibraryScopeProperties
|
|
|
|
// for each apiscope in allApiScopes, e.g. something like:
|
|
|
|
// struct {
|
|
|
|
// Public sdkLibraryScopeProperties
|
|
|
|
// System sdkLibraryScopeProperties
|
|
|
|
// ...
|
|
|
|
// }
|
|
|
|
var allScopeStructType = createAllScopePropertiesStructType()
|
|
|
|
|
|
|
|
// Dynamically create a structure type for each apiscope in allApiScopes.
|
|
|
|
func createAllScopePropertiesStructType() reflect.Type {
|
|
|
|
var fields []reflect.StructField
|
|
|
|
for _, apiScope := range allApiScopes {
|
|
|
|
field := reflect.StructField{
|
|
|
|
Name: apiScope.fieldName,
|
|
|
|
Type: reflect.TypeOf(sdkLibraryScopeProperties{}),
|
|
|
|
}
|
|
|
|
fields = append(fields, field)
|
|
|
|
}
|
|
|
|
|
|
|
|
return reflect.StructOf(fields)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an instance of the scope specific structure type and return a map
|
|
|
|
// from apiscope to a pointer to each scope specific field.
|
|
|
|
func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) {
|
|
|
|
allScopePropertiesPtr := reflect.New(allScopeStructType)
|
|
|
|
allScopePropertiesStruct := allScopePropertiesPtr.Elem()
|
|
|
|
scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties)
|
|
|
|
|
|
|
|
for _, apiScope := range allApiScopes {
|
|
|
|
field := allScopePropertiesStruct.FieldByName(apiScope.fieldName)
|
|
|
|
scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties)
|
|
|
|
}
|
|
|
|
|
|
|
|
return allScopePropertiesPtr.Interface(), scopeProperties
|
|
|
|
}
|
|
|
|
|
2019-07-11 19:05:35 +02:00
|
|
|
// java_sdk_library_import imports a prebuilt java_sdk_library.
|
2019-04-17 20:11:46 +02:00
|
|
|
func sdkLibraryImportFactory() android.Module {
|
|
|
|
module := &sdkLibraryImport{}
|
|
|
|
|
2020-04-07 20:27:04 +02:00
|
|
|
allScopeProperties, scopeToProperties := createPropertiesInstance()
|
|
|
|
module.scopeProperties = scopeToProperties
|
|
|
|
module.AddProperties(&module.properties, allScopeProperties)
|
2019-04-17 20:11:46 +02:00
|
|
|
|
2020-05-08 15:16:20 +02:00
|
|
|
// Initialize information common between source and prebuilt.
|
|
|
|
module.initCommon(&module.ModuleBase)
|
|
|
|
|
2020-02-06 16:24:57 +01:00
|
|
|
android.InitPrebuiltModule(module, &[]string{""})
|
2020-02-10 14:37:10 +01:00
|
|
|
android.InitApexModule(module)
|
|
|
|
android.InitSdkAwareModule(module)
|
2019-04-17 20:11:46 +02:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
|
2020-05-08 14:44:43 +02:00
|
|
|
module.SetDefaultableHook(func(mctx android.DefaultableHookContext) {
|
|
|
|
if module.initCommonAfterDefaultsApplied(mctx) {
|
|
|
|
module.createInternalModules(mctx)
|
|
|
|
}
|
|
|
|
})
|
2019-04-17 20:11:46 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
|
|
|
|
return &module.prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *sdkLibraryImport) Name() string {
|
|
|
|
return module.prebuilt.Name(module.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2020-05-08 16:01:19 +02:00
|
|
|
func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) {
|
2019-04-17 20:11:46 +02:00
|
|
|
|
2020-01-21 17:31:05 +01:00
|
|
|
// If the build is configured to use prebuilts then force this to be preferred.
|
|
|
|
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
|
|
|
module.prebuilt.ForcePrefer()
|
|
|
|
}
|
|
|
|
|
2020-04-07 20:27:04 +02:00
|
|
|
for apiScope, scopeProperties := range module.scopeProperties {
|
2020-01-31 14:36:25 +01:00
|
|
|
if len(scopeProperties.Jars) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-04-09 01:07:11 +02:00
|
|
|
module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
|
2020-04-09 01:10:17 +02:00
|
|
|
|
2020-05-20 17:18:00 +02:00
|
|
|
if len(scopeProperties.Stub_srcs) > 0 {
|
|
|
|
module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties)
|
|
|
|
}
|
2020-01-31 14:36:25 +01:00
|
|
|
}
|
2019-04-17 20:11:46 +02:00
|
|
|
|
|
|
|
javaSdkLibraries := javaSdkLibraries(mctx.Config())
|
|
|
|
javaSdkLibrariesLock.Lock()
|
|
|
|
defer javaSdkLibrariesLock.Unlock()
|
|
|
|
*javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
|
|
|
|
}
|
|
|
|
|
2020-05-08 16:01:19 +02:00
|
|
|
func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
|
2020-04-09 01:07:11 +02:00
|
|
|
// Creates a java import for the jar with ".stubs" suffix
|
|
|
|
props := struct {
|
2020-05-16 10:57:59 +02:00
|
|
|
Name *string
|
|
|
|
Sdk_version *string
|
|
|
|
Libs []string
|
|
|
|
Jars []string
|
|
|
|
Prefer *bool
|
2020-04-09 01:07:11 +02:00
|
|
|
}{}
|
2020-05-08 15:16:20 +02:00
|
|
|
props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
|
2020-04-09 01:07:11 +02:00
|
|
|
props.Sdk_version = scopeProperties.Sdk_version
|
|
|
|
// Prepend any of the libs from the legacy public properties to the libs for each of the
|
|
|
|
// scopes to avoid having to duplicate them in each scope.
|
|
|
|
props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
|
|
|
|
props.Jars = scopeProperties.Jars
|
2020-05-16 10:57:59 +02:00
|
|
|
|
2020-05-13 17:08:09 +02:00
|
|
|
// The imports are preferred if the java_sdk_library_import is preferred.
|
|
|
|
props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
|
2020-05-15 11:20:31 +02:00
|
|
|
|
|
|
|
mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary())
|
2020-04-09 01:07:11 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 16:01:19 +02:00
|
|
|
func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
|
2020-04-09 01:10:17 +02:00
|
|
|
props := struct {
|
2020-05-13 17:08:09 +02:00
|
|
|
Name *string
|
|
|
|
Srcs []string
|
|
|
|
Prefer *bool
|
2020-04-09 01:10:17 +02:00
|
|
|
}{}
|
2020-05-08 15:16:20 +02:00
|
|
|
props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope))
|
2020-04-09 01:10:17 +02:00
|
|
|
props.Srcs = scopeProperties.Stub_srcs
|
|
|
|
mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
|
2020-05-13 17:08:09 +02:00
|
|
|
|
|
|
|
// The stubs source is preferred if the java_sdk_library_import is preferred.
|
|
|
|
props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
|
2020-04-09 01:10:17 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 20:11:46 +02:00
|
|
|
func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2020-04-07 20:27:04 +02:00
|
|
|
for apiScope, scopeProperties := range module.scopeProperties {
|
2020-01-31 14:36:25 +01:00
|
|
|
if len(scopeProperties.Jars) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add dependencies to the prebuilt stubs library
|
2020-05-08 15:16:20 +02:00
|
|
|
ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
|
2020-05-20 17:18:00 +02:00
|
|
|
|
|
|
|
if len(scopeProperties.Stub_srcs) > 0 {
|
|
|
|
// Add dependencies to the prebuilt stubs source library
|
|
|
|
ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
|
|
|
|
}
|
2020-01-31 14:36:25 +01:00
|
|
|
}
|
2019-04-17 20:11:46 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:39:10 +02:00
|
|
|
func (module *sdkLibraryImport) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
return module.commonOutputFiles(tag)
|
|
|
|
}
|
|
|
|
|
2019-04-17 20:11:46 +02:00
|
|
|
func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2020-05-20 17:18:00 +02:00
|
|
|
// Record the paths to the prebuilt stubs library and stubs source.
|
2019-04-17 20:11:46 +02:00
|
|
|
ctx.VisitDirectDeps(func(to android.Module) {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(to)
|
|
|
|
|
2020-05-20 17:18:00 +02:00
|
|
|
// Extract information from any of the scope specific dependencies.
|
|
|
|
if scopeTag, ok := tag.(scopeDependencyTag); ok {
|
|
|
|
apiScope := scopeTag.apiScope
|
|
|
|
scopePaths := module.getScopePathsCreateIfNeeded(apiScope)
|
|
|
|
|
|
|
|
// Extract information from the dependency. The exact information extracted
|
|
|
|
// is determined by the nature of the dependency which is determined by the tag.
|
|
|
|
scopeTag.extractDepInfo(ctx, to, scopePaths)
|
2019-04-17 20:11:46 +02:00
|
|
|
}
|
|
|
|
})
|
2020-05-20 17:18:00 +02:00
|
|
|
|
|
|
|
// Populate the scope paths with information from the properties.
|
|
|
|
for apiScope, scopeProperties := range module.scopeProperties {
|
|
|
|
if len(scopeProperties.Jars) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
paths := module.getScopePathsCreateIfNeeded(apiScope)
|
|
|
|
paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api)
|
|
|
|
paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api)
|
|
|
|
}
|
2019-04-17 20:11:46 +02:00
|
|
|
}
|
|
|
|
|
2020-05-20 13:19:10 +02:00
|
|
|
func (module *sdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
2020-05-20 15:20:02 +02:00
|
|
|
return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion)
|
2020-01-31 14:36:25 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 20:11:46 +02:00
|
|
|
// to satisfy SdkLibraryDependency interface
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
2019-04-17 20:11:46 +02:00
|
|
|
// This module is just a wrapper for the prebuilt stubs.
|
2020-01-31 14:36:25 +01:00
|
|
|
return module.sdkJars(ctx, sdkVersion)
|
2019-04-17 20:11:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// to satisfy SdkLibraryDependency interface
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
2019-04-17 20:11:46 +02:00
|
|
|
// This module is just a wrapper for the stubs.
|
2020-01-31 14:36:25 +01:00
|
|
|
return module.sdkJars(ctx, sdkVersion)
|
2019-04-17 20:11:46 +02:00
|
|
|
}
|
2020-02-17 09:28:10 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// java_sdk_library_xml
|
|
|
|
//
|
|
|
|
type sdkLibraryXml struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModuleBase
|
|
|
|
android.ApexModuleBase
|
|
|
|
|
|
|
|
properties sdkLibraryXmlProperties
|
|
|
|
|
|
|
|
outputFilePath android.OutputPath
|
|
|
|
installDirPath android.InstallPath
|
|
|
|
}
|
|
|
|
|
|
|
|
type sdkLibraryXmlProperties struct {
|
|
|
|
// canonical name of the lib
|
|
|
|
Lib_name *string
|
|
|
|
}
|
|
|
|
|
|
|
|
// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
|
|
|
|
// Not to be used directly by users. java_sdk_library internally uses this.
|
|
|
|
func sdkLibraryXmlFactory() android.Module {
|
|
|
|
module := &sdkLibraryXml{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
android.InitApexModule(module)
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
// from android.PrebuiltEtcModule
|
|
|
|
func (module *sdkLibraryXml) SubDir() string {
|
|
|
|
return "permissions"
|
|
|
|
}
|
|
|
|
|
|
|
|
// from android.PrebuiltEtcModule
|
|
|
|
func (module *sdkLibraryXml) OutputFile() android.OutputPath {
|
|
|
|
return module.outputFilePath
|
|
|
|
}
|
|
|
|
|
|
|
|
// from android.ApexModule
|
|
|
|
func (module *sdkLibraryXml) AvailableFor(what string) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
// File path to the runtime implementation library
|
|
|
|
func (module *sdkLibraryXml) implPath() string {
|
|
|
|
implName := proptools.String(module.properties.Lib_name)
|
|
|
|
if apexName := module.ApexName(); apexName != "" {
|
|
|
|
// TODO(b/146468504): ApexName() is only a soong module name, not apex name.
|
|
|
|
// In most cases, this works fine. But when apex_name is set or override_apex is used
|
|
|
|
// this can be wrong.
|
|
|
|
return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName)
|
|
|
|
}
|
|
|
|
partition := "system"
|
|
|
|
if module.SocSpecific() {
|
|
|
|
partition = "vendor"
|
|
|
|
} else if module.DeviceSpecific() {
|
|
|
|
partition = "odm"
|
|
|
|
} else if module.ProductSpecific() {
|
|
|
|
partition = "product"
|
|
|
|
} else if module.SystemExtSpecific() {
|
|
|
|
partition = "system_ext"
|
|
|
|
}
|
|
|
|
return "/" + partition + "/framework/" + implName + ".jar"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
libName := proptools.String(module.properties.Lib_name)
|
|
|
|
xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath())
|
|
|
|
|
|
|
|
module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
rule.Command().
|
|
|
|
Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > ").
|
|
|
|
Output(module.outputFilePath)
|
|
|
|
|
|
|
|
rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML")
|
|
|
|
|
|
|
|
module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
if !module.IsForPlatform() {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
|
|
|
Disabled: true,
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
|
|
|
Class: "ETC",
|
|
|
|
OutputFile: android.OptionalPathForPath(module.outputFilePath),
|
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
|
|
|
func(entries *android.AndroidMkEntries) {
|
|
|
|
entries.SetString("LOCAL_MODULE_TAGS", "optional")
|
|
|
|
entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String())
|
|
|
|
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
}
|
2020-02-10 14:37:10 +01:00
|
|
|
|
|
|
|
type sdkLibrarySdkMemberType struct {
|
|
|
|
android.SdkMemberTypeBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
|
|
|
|
mctx.AddVariationDependencies(nil, dependencyTag, names...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool {
|
|
|
|
_, ok := module.(*SdkLibrary)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
|
|
|
return &sdkLibrarySdkMemberProperties{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type sdkLibrarySdkMemberProperties struct {
|
|
|
|
android.SdkMemberPropertiesBase
|
|
|
|
|
|
|
|
// Scope to per scope properties.
|
|
|
|
Scopes map[*apiScope]scopeProperties
|
|
|
|
|
|
|
|
// Additional libraries that the exported stubs libraries depend upon.
|
|
|
|
Libs []string
|
2020-04-09 01:10:17 +02:00
|
|
|
|
|
|
|
// The Java stubs source files.
|
|
|
|
Stub_srcs []string
|
2020-05-13 17:54:55 +02:00
|
|
|
|
|
|
|
// The naming scheme.
|
|
|
|
Naming_scheme *string
|
2020-05-26 21:57:10 +02:00
|
|
|
|
|
|
|
// True if the java_sdk_library_import is for a shared library, false
|
|
|
|
// otherwise.
|
|
|
|
Shared_library *bool
|
2020-02-10 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type scopeProperties struct {
|
2020-04-09 02:08:11 +02:00
|
|
|
Jars android.Paths
|
|
|
|
StubsSrcJar android.Path
|
|
|
|
CurrentApiFile android.Path
|
|
|
|
RemovedApiFile android.Path
|
|
|
|
SdkVersion string
|
2020-02-10 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
|
|
|
sdk := variant.(*SdkLibrary)
|
|
|
|
|
|
|
|
s.Scopes = make(map[*apiScope]scopeProperties)
|
|
|
|
for _, apiScope := range allApiScopes {
|
2020-05-20 12:52:25 +02:00
|
|
|
paths := sdk.findScopePaths(apiScope)
|
|
|
|
if paths == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-02-10 14:37:10 +01:00
|
|
|
jars := paths.stubsImplPath
|
|
|
|
if len(jars) > 0 {
|
|
|
|
properties := scopeProperties{}
|
|
|
|
properties.Jars = jars
|
2020-05-12 16:52:55 +02:00
|
|
|
properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope)
|
2020-05-20 17:18:00 +02:00
|
|
|
properties.StubsSrcJar = paths.stubsSrcJar.Path()
|
|
|
|
properties.CurrentApiFile = paths.currentApiFilePath.Path()
|
|
|
|
properties.RemovedApiFile = paths.removedApiFilePath.Path()
|
2020-02-10 14:37:10 +01:00
|
|
|
s.Scopes[apiScope] = properties
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Libs = sdk.properties.Libs
|
2020-05-15 21:37:11 +02:00
|
|
|
s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme
|
2020-05-26 21:57:10 +02:00
|
|
|
s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary())
|
2020-02-10 14:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2020-05-13 17:54:55 +02:00
|
|
|
if s.Naming_scheme != nil {
|
|
|
|
propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme))
|
|
|
|
}
|
2020-05-26 21:57:10 +02:00
|
|
|
if s.Shared_library != nil {
|
|
|
|
propertySet.AddProperty("shared_library", *s.Shared_library)
|
|
|
|
}
|
2020-05-13 17:54:55 +02:00
|
|
|
|
2020-02-10 14:37:10 +01:00
|
|
|
for _, apiScope := range allApiScopes {
|
|
|
|
if properties, ok := s.Scopes[apiScope]; ok {
|
2020-05-13 20:19:49 +02:00
|
|
|
scopeSet := propertySet.AddPropertySet(apiScope.propertyName)
|
2020-02-10 14:37:10 +01:00
|
|
|
|
2020-04-09 01:10:17 +02:00
|
|
|
scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name)
|
|
|
|
|
2020-02-10 14:37:10 +01:00
|
|
|
var jars []string
|
|
|
|
for _, p := range properties.Jars {
|
2020-04-09 01:10:17 +02:00
|
|
|
dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar")
|
2020-02-10 14:37:10 +01:00
|
|
|
ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
|
|
|
|
jars = append(jars, dest)
|
|
|
|
}
|
|
|
|
scopeSet.AddProperty("jars", jars)
|
|
|
|
|
2020-04-09 01:10:17 +02:00
|
|
|
// Merge the stubs source jar into the snapshot zip so that when it is unpacked
|
|
|
|
// the source files are also unpacked.
|
|
|
|
snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
|
|
|
|
ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
|
|
|
|
scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
|
|
|
|
|
2020-04-09 02:08:11 +02:00
|
|
|
if properties.CurrentApiFile != nil {
|
|
|
|
currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt")
|
|
|
|
ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath)
|
|
|
|
scopeSet.AddProperty("current_api", currentApiSnapshotPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if properties.RemovedApiFile != nil {
|
|
|
|
removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt")
|
2020-06-02 14:00:02 +02:00
|
|
|
ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath)
|
2020-04-09 02:08:11 +02:00
|
|
|
scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
|
|
|
|
}
|
|
|
|
|
2020-02-10 14:37:10 +01:00
|
|
|
if properties.SdkVersion != "" {
|
|
|
|
scopeSet.AddProperty("sdk_version", properties.SdkVersion)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(s.Libs) > 0 {
|
|
|
|
propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false))
|
|
|
|
}
|
|
|
|
}
|