Merge changes I2729001d,Ife5d2193
* changes:
packaging: install/package deps if not marked IsHideFromMake
Generate linker config with packaged items.
diff --git a/android/Android.bp b/android/Android.bp
index 6124654..5d0f2b9 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -42,6 +42,7 @@
"image.go",
"license.go",
"license_kind.go",
+ "license_sdk_member.go",
"licenses.go",
"makefile_goal.go",
"makevars.go",
diff --git a/android/androidmk.go b/android/androidmk.go
index 590eceb..557e7ba 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -501,7 +501,7 @@
a.SetString("LOCAL_MODULE", name+a.SubName)
a.AddStrings("LOCAL_LICENSE_KINDS", amod.commonProperties.Effective_license_kinds...)
a.AddStrings("LOCAL_LICENSE_CONDITIONS", amod.commonProperties.Effective_license_conditions...)
- a.AddStrings("LOCAL_NOTICE_FILE", amod.commonProperties.Effective_license_text...)
+ a.AddStrings("LOCAL_NOTICE_FILE", amod.commonProperties.Effective_license_text.Strings()...)
// TODO(b/151177513): Does this code need to set LOCAL_MODULE_IS_CONTAINER ?
if amod.commonProperties.Effective_package_name != nil {
a.SetString("LOCAL_LICENSE_PACKAGE_NAME", *amod.commonProperties.Effective_package_name)
diff --git a/android/bazel.go b/android/bazel.go
index 6c476a7..0af4aa0 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -207,7 +207,6 @@
"libc_jemalloc_wrapper", // http://b/187012490, cc_library_static, depends on //external/jemalloc_new:libjemalloc5 (http://b/186828626)
"libc_ndk", // http://b/187013218, cc_library_static, depends on //bionic/libm:libm (http://b/183064661)
"libc", // http://b/183064430, cc_library, depends on //external/jemalloc_new:libjemalloc5 (http://b/186828626)
- "libc_tzcode", // http://b/186822591, cc_library_static, localtime.c:84:46: error: expected expression
"libc_bionic_ndk", // http://b/186822256, cc_library_static, signal.cpp:186:52: error: ISO C++ requires field designators to be specified in declaration order
"libc_malloc_hooks", // http://b/187016307, cc_library, ld.lld: error: undefined symbol: __malloc_hook
"libm", // http://b/183064661, cc_library, math.h:25:16: error: unexpected token in argument list
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 4598995..8cddbb2 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -347,7 +347,10 @@
bazelCmd := exec.Command(paths.bazelPath, cmdFlags...)
bazelCmd.Dir = absolutePath(paths.syntheticWorkspaceDir())
- bazelCmd.Env = append(os.Environ(), "HOME="+paths.homeDir, pwdPrefix(),
+ bazelCmd.Env = append(os.Environ(),
+ "HOME="+paths.homeDir,
+ pwdPrefix(),
+ "BUILD_DIR="+absolutePath(paths.buildDir),
// Disables local host detection of gcc; toolchain information is defined
// explicitly in BUILD files.
"BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1")
@@ -583,8 +586,9 @@
var err error
soongInjectionPath := absolutePath(context.paths.injectedFilesDir())
- if _, err := os.Stat(soongInjectionPath); os.IsNotExist(err) {
- err = os.Mkdir(soongInjectionPath, 0777)
+ mixedBuildsPath := filepath.Join(soongInjectionPath, "mixed_builds")
+ if _, err := os.Stat(mixedBuildsPath); os.IsNotExist(err) {
+ err = os.MkdirAll(mixedBuildsPath, 0777)
}
if err != nil {
return err
@@ -596,14 +600,14 @@
}
err = ioutil.WriteFile(
- filepath.Join(soongInjectionPath, "main.bzl"),
+ filepath.Join(mixedBuildsPath, "main.bzl"),
context.mainBzlFileContents(), 0666)
if err != nil {
return err
}
err = ioutil.WriteFile(
- filepath.Join(soongInjectionPath, "BUILD.bazel"),
+ filepath.Join(mixedBuildsPath, "BUILD.bazel"),
context.mainBuildFileContents(), 0666)
if err != nil {
return err
@@ -615,7 +619,7 @@
if err != nil {
return err
}
- buildrootLabel := "@soong_injection//:buildroot"
+ buildrootLabel := "@soong_injection//mixed_builds:buildroot"
cqueryOutput, cqueryErr, err = context.issueBazelCommand(
context.paths,
bazel.CqueryBuildRootRunName,
@@ -676,7 +680,7 @@
_, _, err = context.issueBazelCommand(
context.paths,
bazel.BazelBuildPhonyRootRunName,
- bazelCommand{"build", "@soong_injection//:phonyroot"})
+ bazelCommand{"build", "@soong_injection//mixed_builds:phonyroot"})
if err != nil {
return err
diff --git a/android/bazel_handler_test.go b/android/bazel_handler_test.go
index cb25fee..f1fabec 100644
--- a/android/bazel_handler_test.go
+++ b/android/bazel_handler_test.go
@@ -11,7 +11,7 @@
label := "//foo:bar"
arch := Arm64
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
- bazelCommand{command: "cquery", expression: "kind(rule, deps(@soong_injection//:buildroot))"}: `//foo:bar|arm64>>out/foo/bar.txt`,
+ bazelCommand{command: "cquery", expression: "kind(rule, deps(@soong_injection//mixed_builds:buildroot))"}: `//foo:bar|arm64>>out/foo/bar.txt`,
})
g, ok := bazelContext.GetOutputFiles(label, arch)
if ok {
@@ -35,13 +35,13 @@
if err != nil {
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
}
- if _, err := os.Stat(filepath.Join(baseDir, "soong_injection", "main.bzl")); os.IsNotExist(err) {
+ if _, err := os.Stat(filepath.Join(baseDir, "soong_injection", "mixed_builds", "main.bzl")); os.IsNotExist(err) {
t.Errorf("Expected main.bzl to exist, but it does not")
} else if err != nil {
t.Errorf("Unexpected error stating main.bzl %s", err)
}
- if _, err := os.Stat(filepath.Join(baseDir, "soong_injection", "BUILD.bazel")); os.IsNotExist(err) {
+ if _, err := os.Stat(filepath.Join(baseDir, "soong_injection", "mixed_builds", "BUILD.bazel")); os.IsNotExist(err) {
t.Errorf("Expected BUILD.bazel to exist, but it does not")
} else if err != nil {
t.Errorf("Unexpected error stating BUILD.bazel %s", err)
@@ -56,7 +56,7 @@
func TestInvokeBazelPopulatesBuildStatements(t *testing.T) {
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
- bazelCommand{command: "aquery", expression: "deps(@soong_injection//:buildroot)"}: `
+ bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}: `
{
"artifacts": [{
"id": 1,
@@ -105,7 +105,7 @@
outputBase: "outputbase",
workspaceDir: "workspace_dir",
}
- aqueryCommand := bazelCommand{command: "aquery", expression: "deps(@soong_injection//:buildroot)"}
+ aqueryCommand := bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}
if _, exists := bazelCommandResults[aqueryCommand]; !exists {
bazelCommandResults[aqueryCommand] = "{}\n"
}
diff --git a/android/config.go b/android/config.go
index 3db7980..79917ad 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1564,6 +1564,15 @@
return false
}
+// ApexOfJar returns the apex component of the first pair with the given jar name on the list, or
+// an empty string if not found.
+func (l *ConfiguredJarList) ApexOfJar(jar string) string {
+ if idx := IndexList(jar, l.jars); idx != -1 {
+ return l.Apex(IndexList(jar, l.jars))
+ }
+ return ""
+}
+
// IndexOfJar returns the first pair with the given jar name on the list, or -1
// if not found.
func (l *ConfiguredJarList) IndexOfJar(jar string) int {
diff --git a/android/license.go b/android/license.go
index cb375a2..8bfd3ba 100644
--- a/android/license.go
+++ b/android/license.go
@@ -61,7 +61,17 @@
}
func (m *licenseModule) GenerateAndroidBuildActions(ctx ModuleContext) {
- // Nothing to do.
+ // license modules have no licenses, but license_kinds must refer to license_kind modules
+ mergeStringProps(&m.base().commonProperties.Effective_licenses, ctx.ModuleName())
+ mergePathProps(&m.base().commonProperties.Effective_license_text, PathsForModuleSrc(ctx, m.properties.License_text)...)
+ for _, module := range ctx.GetDirectDepsWithTag(licenseKindTag) {
+ if lk, ok := module.(*licenseKindModule); ok {
+ mergeStringProps(&m.base().commonProperties.Effective_license_conditions, lk.properties.Conditions...)
+ mergeStringProps(&m.base().commonProperties.Effective_license_kinds, ctx.OtherModuleName(module))
+ } else {
+ ctx.ModuleErrorf("license_kinds property %q is not a license_kind module", ctx.OtherModuleName(module))
+ }
+ }
}
func LicenseFactory() Module {
diff --git a/android/license_sdk_member.go b/android/license_sdk_member.go
new file mode 100644
index 0000000..cd36ed6
--- /dev/null
+++ b/android/license_sdk_member.go
@@ -0,0 +1,118 @@
+// Copyright 2021 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 android
+
+import (
+ "path/filepath"
+
+ "github.com/google/blueprint"
+)
+
+// Contains support for adding license modules to an sdk.
+
+func init() {
+ RegisterSdkMemberType(LicenseModuleSdkMemberType)
+}
+
+// licenseSdkMemberType determines how a license module is added to the sdk.
+type licenseSdkMemberType struct {
+ SdkMemberTypeBase
+}
+
+func (l *licenseSdkMemberType) AddDependencies(mctx BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
+ // Add dependencies onto the license module from the sdk module.
+ mctx.AddDependency(mctx.Module(), dependencyTag, names...)
+}
+
+func (l *licenseSdkMemberType) IsInstance(module Module) bool {
+ // Verify that the module being added is compatible with this module type.
+ _, ok := module.(*licenseModule)
+ return ok
+}
+
+func (l *licenseSdkMemberType) AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule {
+ // Add the basics of a prebuilt module.
+ return ctx.SnapshotBuilder().AddPrebuiltModule(member, "license")
+}
+
+func (l *licenseSdkMemberType) CreateVariantPropertiesStruct() SdkMemberProperties {
+ // Create the structure into which the properties of the license module that need to be output to
+ // the snapshot will be placed. The structure may be populated with information from a variant or
+ // may be used as the destination for properties that are common to a set of variants.
+ return &licenseSdkMemberProperties{}
+}
+
+// LicenseModuleSdkMemberType is the instance of licenseSdkMemberType
+var LicenseModuleSdkMemberType = &licenseSdkMemberType{
+ SdkMemberTypeBase{
+ PropertyName: "licenses",
+
+ // This should never be added directly to an sdk/module_exports, all license modules should be
+ // added indirectly as transitive dependencies of other sdk members.
+ BpPropertyNotRequired: true,
+
+ SupportsSdk: true,
+
+ // The snapshot of the license module is just another license module (not a prebuilt). They are
+ // internal modules only so will have an sdk specific name that will not clash with the
+ // originating source module.
+ UseSourceModuleTypeInSnapshot: true,
+ },
+}
+
+var _ SdkMemberType = (*licenseSdkMemberType)(nil)
+
+// licenseSdkMemberProperties is the set of properties that need to be added to the license module
+// in the snapshot.
+type licenseSdkMemberProperties struct {
+ SdkMemberPropertiesBase
+
+ // The kinds of licenses provided by the module.
+ License_kinds []string
+
+ // The source paths to the files containing license text.
+ License_text Paths
+}
+
+func (p *licenseSdkMemberProperties) PopulateFromVariant(_ SdkMemberContext, variant Module) {
+ // Populate the properties from the variant.
+ l := variant.(*licenseModule)
+ p.License_kinds = l.properties.License_kinds
+ p.License_text = l.base().commonProperties.Effective_license_text
+}
+
+func (p *licenseSdkMemberProperties) AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet) {
+ // Just pass any specified license_kinds straight through.
+ if len(p.License_kinds) > 0 {
+ propertySet.AddProperty("license_kinds", p.License_kinds)
+ }
+
+ // Copy any license test files to the snapshot into a module specific location.
+ if len(p.License_text) > 0 {
+ dests := []string{}
+ for _, path := range p.License_text {
+ // The destination path only uses the path of the license file in the source not the license
+ // module name. That ensures that if the same license file is used by multiple license modules
+ // that it only gets copied once as the snapshot builder will dedup copies where the source
+ // and destination match.
+ dest := filepath.Join("licenses", path.String())
+ dests = append(dests, dest)
+ ctx.SnapshotBuilder().CopyToSnapshot(path, dest)
+ }
+ propertySet.AddProperty("license_text", dests)
+ }
+}
+
+var _ SdkMemberProperties = (*licenseSdkMemberProperties)(nil)
diff --git a/android/license_test.go b/android/license_test.go
index 2b09a4f..26b33c3 100644
--- a/android/license_test.go
+++ b/android/license_test.go
@@ -8,7 +8,7 @@
var prepareForLicenseTest = GroupFixturePreparers(
// General preparers in alphabetical order.
PrepareForTestWithDefaults,
- prepareForTestWithLicenses,
+ PrepareForTestWithLicenses,
PrepareForTestWithOverrides,
PrepareForTestWithPackageModule,
PrepareForTestWithPrebuilts,
diff --git a/android/licenses.go b/android/licenses.go
index 2838f5d..464ba49 100644
--- a/android/licenses.go
+++ b/android/licenses.go
@@ -32,8 +32,23 @@
blueprint.BaseDependencyTag
}
+func (l licensesDependencyTag) SdkMemberType(Module) SdkMemberType {
+ // Add the supplied module to the sdk as a license module.
+ return LicenseModuleSdkMemberType
+}
+
+func (l licensesDependencyTag) ExportMember() bool {
+ // The license module will only every be referenced from within the sdk. This will ensure that it
+ // gets a unique name and so avoid clashing with the original license module.
+ return false
+}
+
var (
licensesTag = licensesDependencyTag{}
+
+ // License modules, i.e. modules depended upon via a licensesTag, must be automatically added to
+ // any sdk/module_exports to which their referencing module is a member.
+ _ SdkMemberTypeDependencyTag = licensesTag
)
// Describes the property provided by a module to reference applicable licenses.
@@ -140,7 +155,6 @@
}
licenses := getLicenses(ctx, m)
-
ctx.AddVariationDependencies(nil, licensesTag, licenses...)
}
@@ -187,34 +201,21 @@
return
}
- // license modules have no licenses, but license_kinds must refer to license_kind modules
- if l, ok := m.(*licenseModule); ok {
- mergeProps(&m.base().commonProperties.Effective_licenses, ctx.ModuleName())
- mergeProps(&m.base().commonProperties.Effective_license_text, PathsForModuleSrc(ctx, l.properties.License_text).Strings()...)
- for _, module := range ctx.GetDirectDepsWithTag(licenseKindTag) {
- if lk, ok := module.(*licenseKindModule); ok {
- mergeProps(&m.base().commonProperties.Effective_license_conditions, lk.properties.Conditions...)
- mergeProps(&m.base().commonProperties.Effective_license_kinds, ctx.OtherModuleName(module))
- } else {
- ctx.ModuleErrorf("license_kinds property %q is not a license_kind module", ctx.OtherModuleName(module))
- }
- }
- return
- }
-
if exemptFromRequiredApplicableLicensesProperty(m) {
return
}
+ var licenses []string
for _, module := range ctx.GetDirectDepsWithTag(licensesTag) {
if l, ok := module.(*licenseModule); ok {
+ licenses = append(licenses, ctx.OtherModuleName(module))
if m.base().commonProperties.Effective_package_name == nil && l.properties.Package_name != nil {
m.base().commonProperties.Effective_package_name = l.properties.Package_name
}
- mergeProps(&m.base().commonProperties.Effective_licenses, module.base().commonProperties.Effective_licenses...)
- mergeProps(&m.base().commonProperties.Effective_license_text, module.base().commonProperties.Effective_license_text...)
- mergeProps(&m.base().commonProperties.Effective_license_kinds, module.base().commonProperties.Effective_license_kinds...)
- mergeProps(&m.base().commonProperties.Effective_license_conditions, module.base().commonProperties.Effective_license_conditions...)
+ mergeStringProps(&m.base().commonProperties.Effective_licenses, module.base().commonProperties.Effective_licenses...)
+ mergePathProps(&m.base().commonProperties.Effective_license_text, module.base().commonProperties.Effective_license_text...)
+ mergeStringProps(&m.base().commonProperties.Effective_license_kinds, module.base().commonProperties.Effective_license_kinds...)
+ mergeStringProps(&m.base().commonProperties.Effective_license_conditions, module.base().commonProperties.Effective_license_conditions...)
} else {
propertyName := "licenses"
primaryProperty := m.base().primaryLicensesProperty
@@ -224,19 +225,24 @@
ctx.ModuleErrorf("%s property %q is not a license module", propertyName, ctx.OtherModuleName(module))
}
}
+
+ // Make the license information available for other modules.
+ licenseInfo := LicenseInfo{
+ Licenses: licenses,
+ }
+ ctx.SetProvider(LicenseInfoProvider, licenseInfo)
}
// Update a property string array with a distinct union of its values and a list of new values.
-func mergeProps(prop *[]string, values ...string) {
- s := make(map[string]bool)
- for _, v := range *prop {
- s[v] = true
- }
- for _, v := range values {
- s[v] = true
- }
- *prop = []string{}
- *prop = append(*prop, SortedStringKeys(s)...)
+func mergeStringProps(prop *[]string, values ...string) {
+ *prop = append(*prop, values...)
+ *prop = SortedUniqueStrings(*prop)
+}
+
+// Update a property Path array with a distinct union of its values and a list of new values.
+func mergePathProps(prop *Paths, values ...Path) {
+ *prop = append(*prop, values...)
+ *prop = SortedUniquePaths(*prop)
}
// Get the licenses property falling back to the package default.
@@ -293,3 +299,12 @@
}
return true
}
+
+// LicenseInfo contains information about licenses for a specific module.
+type LicenseInfo struct {
+ // The list of license modules this depends upon, either explicitly or through default package
+ // configuration.
+ Licenses []string
+}
+
+var LicenseInfoProvider = blueprint.NewProvider(LicenseInfo{})
diff --git a/android/licenses_test.go b/android/licenses_test.go
index 913dc88..8503310 100644
--- a/android/licenses_test.go
+++ b/android/licenses_test.go
@@ -6,18 +6,6 @@
"github.com/google/blueprint"
)
-var prepareForTestWithLicenses = GroupFixturePreparers(
- FixtureRegisterWithContext(RegisterLicenseKindBuildComponents),
- FixtureRegisterWithContext(RegisterLicenseBuildComponents),
- FixtureRegisterWithContext(registerLicenseMutators),
-)
-
-func registerLicenseMutators(ctx RegistrationContext) {
- ctx.PreArchMutators(RegisterLicensesPackageMapper)
- ctx.PreArchMutators(RegisterLicensesPropertyGatherer)
- ctx.PostDepsMutators(RegisterLicensesDependencyChecker)
-}
-
var licensesTests = []struct {
name string
fs MockFS
@@ -670,7 +658,7 @@
if base == nil {
return
}
- actualNotices[m.Name()] = base.commonProperties.Effective_license_text
+ actualNotices[m.Name()] = base.commonProperties.Effective_license_text.Strings()
})
for moduleName, expectedNotices := range effectiveNotices {
diff --git a/android/module.go b/android/module.go
index f355a8b..c9a1662 100644
--- a/android/module.go
+++ b/android/module.go
@@ -688,7 +688,7 @@
// Override of module name when reporting licenses
Effective_package_name *string `blueprint:"mutated"`
// Notice files
- Effective_license_text []string `blueprint:"mutated"`
+ Effective_license_text Paths `blueprint:"mutated"`
// License names
Effective_license_kinds []string `blueprint:"mutated"`
// License conditions
diff --git a/android/sdk.go b/android/sdk.go
index 0adfd89..36c576d 100644
--- a/android/sdk.go
+++ b/android/sdk.go
@@ -284,11 +284,20 @@
// Add a property set with the specified name and return so that additional
// properties can be added.
AddPropertySet(name string) BpPropertySet
+
+ // Add comment for property (or property set).
+ AddCommentForProperty(name, text string)
}
// A .bp module definition.
type BpModule interface {
BpPropertySet
+
+ // ModuleType returns the module type of the module
+ ModuleType() string
+
+ // Name returns the name of the module or "" if no name has been specified.
+ Name() string
}
// An individual member of the SDK, includes all of the variants that the SDK
@@ -380,6 +389,10 @@
// The name of the member type property on an sdk module.
SdkPropertyName() string
+ // RequiresBpProperty returns true if this member type requires its property to be usable within
+ // an Android.bp file.
+ RequiresBpProperty() bool
+
// True if the member type supports the sdk/sdk_snapshot, false otherwise.
UsableWithSdkAndSdkSnapshot() bool
@@ -405,6 +418,10 @@
// the module is not allowed in whichever sdk property it was added.
IsInstance(module Module) bool
+ // UsesSourceModuleTypeInSnapshot returns true when the AddPrebuiltModule() method returns a
+ // source module type.
+ UsesSourceModuleTypeInSnapshot() bool
+
// Add a prebuilt module that the sdk will populate.
//
// The sdk module code generates the snapshot as follows:
@@ -448,15 +465,29 @@
// Base type for SdkMemberType implementations.
type SdkMemberTypeBase struct {
- PropertyName string
+ PropertyName string
+
+ // When set to true BpPropertyNotRequired indicates that the member type does not require the
+ // property to be specifiable in an Android.bp file.
+ BpPropertyNotRequired bool
+
SupportsSdk bool
HostOsDependent bool
+
+ // When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source
+ // module type in its SdkMemberType.AddPrebuiltModule() method. That prevents the sdk snapshot
+ // code from automatically adding a prefer: true flag.
+ UseSourceModuleTypeInSnapshot bool
}
func (b *SdkMemberTypeBase) SdkPropertyName() string {
return b.PropertyName
}
+func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
+ return !b.BpPropertyNotRequired
+}
+
func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
return b.SupportsSdk
}
@@ -465,6 +496,10 @@
return b.HostOsDependent
}
+func (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool {
+ return b.UseSourceModuleTypeInSnapshot
+}
+
// Encapsulates the information about registered SdkMemberTypes.
type SdkMemberTypesRegistry struct {
// The list of types sorted by property name.
diff --git a/android/testing.go b/android/testing.go
index ce27fca..191cb8d 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -74,6 +74,42 @@
ctx.PostDepsMutators(RegisterOverridePostDepsMutators)
})
+var PrepareForTestWithLicenses = GroupFixturePreparers(
+ FixtureRegisterWithContext(RegisterLicenseKindBuildComponents),
+ FixtureRegisterWithContext(RegisterLicenseBuildComponents),
+ FixtureRegisterWithContext(registerLicenseMutators),
+)
+
+func registerLicenseMutators(ctx RegistrationContext) {
+ ctx.PreArchMutators(RegisterLicensesPackageMapper)
+ ctx.PreArchMutators(RegisterLicensesPropertyGatherer)
+ ctx.PostDepsMutators(RegisterLicensesDependencyChecker)
+}
+
+var PrepareForTestWithLicenseDefaultModules = GroupFixturePreparers(
+ FixtureAddTextFile("build/soong/licenses/Android.bp", `
+ license {
+ name: "Android-Apache-2.0",
+ package_name: "Android",
+ license_kinds: ["SPDX-license-identifier-Apache-2.0"],
+ copyright_notice: "Copyright (C) The Android Open Source Project",
+ license_text: ["LICENSE"],
+ }
+
+ license_kind {
+ name: "SPDX-license-identifier-Apache-2.0",
+ conditions: ["notice"],
+ url: "https://spdx.org/licenses/Apache-2.0.html",
+ }
+
+ license_kind {
+ name: "legacy_unencumbered",
+ conditions: ["unencumbered"],
+ }
+ `),
+ FixtureAddFile("build/soong/licenses/LICENSE", nil),
+)
+
// Test fixture preparer that will register most java build components.
//
// Singletons and mutators should only be added here if they are needed for a majority of java
diff --git a/androidmk/androidmk/android.go b/androidmk/androidmk/android.go
index f0f51bf..5316d7b 100644
--- a/androidmk/androidmk/android.go
+++ b/androidmk/androidmk/android.go
@@ -216,6 +216,8 @@
"LOCAL_JETIFIER_ENABLED": "jetifier",
"LOCAL_IS_UNIT_TEST": "unit_test",
+
+ "LOCAL_ENFORCE_USES_LIBRARIES": "enforce_uses_libs",
})
}
diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go
index f32ff2a..439f45d 100644
--- a/androidmk/androidmk/androidmk_test.go
+++ b/androidmk/androidmk/androidmk_test.go
@@ -1446,6 +1446,23 @@
}
`,
},
+ {
+ desc: "LOCAL_ENFORCE_USES_LIBRARIES",
+ in: `
+include $(CLEAR_VARS)
+LOCAL_MODULE := foo
+LOCAL_ENFORCE_USES_LIBRARIES := false
+LOCAL_ENFORCE_USES_LIBRARIES := true
+include $(BUILD_PACKAGE)
+`,
+ expected: `
+android_app {
+ name: "foo",
+ enforce_uses_libs: false,
+ enforce_uses_libs: true,
+}
+`,
+ },
}
func TestEndToEnd(t *testing.T) {
diff --git a/apex/apex.go b/apex/apex.go
index 949d80e..24af85d 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -50,10 +50,15 @@
ctx.RegisterModuleType("override_apex", overrideApexFactory)
ctx.RegisterModuleType("apex_set", apexSetFactory)
+ ctx.PreArchMutators(registerPreArchMutators)
ctx.PreDepsMutators(RegisterPreDepsMutators)
ctx.PostDepsMutators(RegisterPostDepsMutators)
}
+func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
+ ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
+}
+
func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
@@ -1251,7 +1256,7 @@
}
// Implements cc.Coverage
-func (a *apexBundle) PreventInstall() {
+func (a *apexBundle) SetPreventInstall() {
a.properties.PreventInstall = true
}
@@ -2097,6 +2102,11 @@
}
}
+ // Add classpaths.proto config.
+ classpathProtoOutput := bootclasspathFragmentInfo.ClasspathFragmentProtoOutput
+ classpathProto := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), bootclasspathFragmentInfo.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
+ filesToAdd = append(filesToAdd, classpathProto)
+
return filesToAdd
}
diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go
index e2b320c..7bb3ff6 100644
--- a/apex/bootclasspath_fragment_test.go
+++ b/apex/bootclasspath_fragment_test.go
@@ -279,6 +279,7 @@
).RunTest(t)
ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
+ "etc/classpaths/mybootclasspathfragment.pb",
"javalib/arm/boot.art",
"javalib/arm/boot.oat",
"javalib/arm/boot.vdex",
@@ -481,6 +482,7 @@
ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
// This does not include art, oat or vdex files as they are only included for the art boot
// image.
+ "etc/classpaths/mybootclasspathfragment.pb",
"javalib/bar.jar",
"javalib/foo.jar",
})
diff --git a/apex/deapexer.go b/apex/deapexer.go
index 9bc5720..c7cdbfa 100644
--- a/apex/deapexer.go
+++ b/apex/deapexer.go
@@ -40,17 +40,29 @@
// This is intentionally not registered by name as it is not intended to be used from within an
// `Android.bp` file.
-// Properties that are specific to `deapexer` but which need to be provided on the `prebuilt_apex`
-// module.`
-type DeapexerProperties struct {
- // List of java libraries that are embedded inside this prebuilt APEX bundle and for which this
- // APEX bundle will create an APEX variant and provide dex implementation jars for use by
- // dexpreopt and boot jars package check.
- Exported_java_libs []string
+// DeapexerExportedFile defines the properties needed to expose a file from the deapexer module.
+type DeapexerExportedFile struct {
+ // The tag parameter which must be passed to android.OutputFileProducer OutputFiles(tag) method
+ // to retrieve the path to the unpacked file.
+ Tag string
- // List of bootclasspath fragments inside this prebuiltd APEX bundle and for which this APEX
- // bundle will create an APEX variant.
- Exported_bootclasspath_fragments []string
+ // The path within the APEX that needs to be exported.
+ Path string `android:"path"`
+}
+
+// DeapexerProperties specifies the properties supported by the deapexer module.
+//
+// As these are never intended to be supplied in a .bp file they use a different naming convention
+// to make it clear that they are different.
+type DeapexerProperties struct {
+ // List of common modules that may need access to files exported by this module.
+ //
+ // A common module in this sense is one that is not arch specific but uses a common variant for
+ // all architectures, e.g. java.
+ CommonModules []string
+
+ // List of files exported from the .apex file by this module
+ ExportedFiles []DeapexerExportedFile
}
type SelectedApexProperties struct {
@@ -81,7 +93,7 @@
func (p *Deapexer) DepsMutator(ctx android.BottomUpMutatorContext) {
// Add dependencies from the java modules to which this exports files from the `.apex` file onto
// this module so that they can access the `DeapexerInfo` object that this provides.
- for _, lib := range p.properties.Exported_java_libs {
+ for _, lib := range p.properties.CommonModules {
dep := prebuiltApexExportedModuleName(ctx, lib)
ctx.AddReverseDependency(ctx.Module(), android.DeapexerTag, dep)
}
@@ -96,10 +108,12 @@
exports := make(map[string]android.Path)
// Create mappings from name+tag to all the required exported paths.
- for _, l := range p.properties.Exported_java_libs {
- // Populate the exports that this makes available. The path here must match the path of the
- // file in the APEX created by apexFileForJavaModule(...).
- exports[l+"{.dexjar}"] = deapexerOutput.Join(ctx, "javalib", l+".jar")
+ for _, e := range p.properties.ExportedFiles {
+ tag := e.Tag
+ path := e.Path
+
+ // Populate the exports that this makes available.
+ exports[tag] = deapexerOutput.Join(ctx, path)
}
// If the prebuilt_apex exports any files then create a build rule that unpacks the apex using
diff --git a/apex/prebuilt.go b/apex/prebuilt.go
index 8996352..9d632a9 100644
--- a/apex/prebuilt.go
+++ b/apex/prebuilt.go
@@ -16,6 +16,7 @@
import (
"fmt"
+ "path/filepath"
"strconv"
"strings"
@@ -46,11 +47,10 @@
}
type prebuiltCommon struct {
- prebuilt android.Prebuilt
- properties prebuiltCommonProperties
+ prebuilt android.Prebuilt
- deapexerProperties DeapexerProperties
- selectedApexProperties SelectedApexProperties
+ // Properties common to both prebuilt_apex and apex_set.
+ prebuiltCommonProperties prebuiltCommonProperties
}
type sanitizedPrebuilt interface {
@@ -58,7 +58,18 @@
}
type prebuiltCommonProperties struct {
+ SelectedApexProperties
+
ForceDisable bool `blueprint:"mutated"`
+
+ // List of java libraries that are embedded inside this prebuilt APEX bundle and for which this
+ // APEX bundle will create an APEX variant and provide dex implementation jars for use by
+ // dexpreopt and boot jars package check.
+ Exported_java_libs []string
+
+ // List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX
+ // bundle will create an APEX variant.
+ Exported_bootclasspath_fragments []string
}
func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
@@ -66,7 +77,7 @@
}
func (p *prebuiltCommon) isForceDisabled() bool {
- return p.properties.ForceDisable
+ return p.prebuiltCommonProperties.ForceDisable
}
func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool {
@@ -88,25 +99,47 @@
forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress"))
if forceDisable && p.prebuilt.SourceExists() {
- p.properties.ForceDisable = true
+ p.prebuiltCommonProperties.ForceDisable = true
return true
}
return false
}
-func (p *prebuiltCommon) deapexerDeps(ctx android.BottomUpMutatorContext) {
+// prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and
+// apex_set in order to create the modules needed to provide access to the prebuilt .apex file.
+type prebuiltApexModuleCreator interface {
+ createPrebuiltApexModules(ctx android.TopDownMutatorContext)
+}
+
+// prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the
+// prebuiltApexModuleCreator's createPrebuiltApexModules method.
+//
+// It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it
+// will need to access dependencies added by that (exported modules) but must run before the
+// DepsMutator so that the deapexer module it creates can add dependencies onto itself from the
+// exported modules.
+func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) {
+ module := ctx.Module()
+ if creator, ok := module.(prebuiltApexModuleCreator); ok {
+ creator.createPrebuiltApexModules(ctx)
+ }
+}
+
+// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
+func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
+ module := ctx.Module()
// Add dependencies onto the java modules that represent the java libraries that are provided by
// and exported from this prebuilt apex.
- for _, exported := range p.deapexerProperties.Exported_java_libs {
- dep := prebuiltApexExportedModuleName(ctx, exported)
- ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), exportedJavaLibTag, dep)
+ for _, exported := range p.prebuiltCommonProperties.Exported_java_libs {
+ dep := android.PrebuiltNameFromSource(exported)
+ ctx.AddDependency(module, exportedJavaLibTag, dep)
}
// Add dependencies onto the bootclasspath fragment modules that are exported from this prebuilt
// apex.
- for _, exported := range p.deapexerProperties.Exported_bootclasspath_fragments {
- dep := prebuiltApexExportedModuleName(ctx, exported)
- ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), exportedBootclasspathFragmentTag, dep)
+ for _, exported := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
+ dep := android.PrebuiltNameFromSource(exported)
+ ctx.AddDependency(module, exportedBootclasspathFragmentTag, dep)
}
}
@@ -240,8 +273,7 @@
android.ModuleBase
prebuiltCommon
- properties PrebuiltProperties
- selectedApexProperties SelectedApexProperties
+ properties PrebuiltProperties
inputApex android.Path
installDir android.InstallPath
@@ -354,58 +386,16 @@
}
// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
-//
-// If this needs to make files from within a `.apex` file available for use by other Soong modules,
-// e.g. make dex implementation jars available for java_import modules isted in exported_java_libs,
-// it does so as follows:
-//
-// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and
-// makes them available for use by other modules, at both Soong and ninja levels.
-//
-// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what
-// an `apex` module does. That ensures that code which looks for specific apex variant, e.g.
-// dexpreopt, will work the same way from source and prebuilt.
-//
-// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto
-// itself so that they can retrieve the file paths to those files.
-//
-// It also creates a child module `selector` that is responsible for selecting the appropriate
-// input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons:
-// 1. To dedup the selection logic so it only runs in one module.
-// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an
-// `apex_set`.
-//
-// prebuilt_apex
-// / | \
-// / | \
-// V | V
-// selector <--- deapexer <--- exported java lib
-//
func PrebuiltFactory() android.Module {
module := &Prebuilt{}
- module.AddProperties(&module.properties, &module.deapexerProperties, &module.selectedApexProperties)
- android.InitSingleSourcePrebuiltModule(module, &module.selectedApexProperties, "Selected_apex")
+ module.AddProperties(&module.properties, &module.prebuiltCommonProperties)
+ android.InitSingleSourcePrebuiltModule(module, &module.prebuiltCommonProperties, "Selected_apex")
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
- android.AddLoadHook(module, func(ctx android.LoadHookContext) {
- baseModuleName := module.BaseModuleName()
-
- apexSelectorModuleName := apexSelectorModuleName(baseModuleName)
- createApexSelectorModule(ctx, apexSelectorModuleName, &module.properties.ApexFileProperties)
-
- apexFileSource := ":" + apexSelectorModuleName
- if len(module.deapexerProperties.Exported_java_libs) != 0 {
- createDeapexerModule(ctx, deapexerModuleName(baseModuleName), apexFileSource, &module.deapexerProperties)
- }
-
- // Add a source reference to retrieve the selected apex from the selector module.
- module.selectedApexProperties.Selected_apex = proptools.StringPtr(apexFileSource)
- })
-
return module
}
-func createApexSelectorModule(ctx android.LoadHookContext, name string, apexFileProperties *ApexFileProperties) {
+func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, apexFileProperties *ApexFileProperties) {
props := struct {
Name *string
}{
@@ -418,7 +408,54 @@
)
}
-func createDeapexerModule(ctx android.LoadHookContext, deapexerName string, apexFileSource string, deapexerProperties *DeapexerProperties) {
+// createDeapexerModuleIfNeeded will create a deapexer module if it is needed.
+//
+// A deapexer module is only needed when the prebuilt apex specifies one or more modules in either
+// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that
+// the listed modules need access to files from within the prebuilt .apex file.
+func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string, properties *prebuiltCommonProperties) {
+ // Only create the deapexer module if it is needed.
+ if len(properties.Exported_java_libs)+len(properties.Exported_bootclasspath_fragments) == 0 {
+ return
+ }
+
+ // Compute the deapexer properties from the transitive dependencies of this module.
+ javaModules := []string{}
+ exportedFiles := map[string]string{}
+ ctx.WalkDeps(func(child, parent android.Module) bool {
+ tag := ctx.OtherModuleDependencyTag(child)
+
+ name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
+ if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
+ javaModules = append(javaModules, name)
+
+ // Add the dex implementation jar to the set of exported files. The path here must match the
+ // path of the file in the APEX created by apexFileForJavaModule(...).
+ exportedFiles[name+"{.dexjar}"] = filepath.Join("javalib", name+".jar")
+
+ } else if tag == exportedBootclasspathFragmentTag {
+ // Only visit the children of the bootclasspath_fragment for now.
+ return true
+ }
+
+ return false
+ })
+
+ // Create properties for deapexer module.
+ deapexerProperties := &DeapexerProperties{
+ // Remove any duplicates from the java modules lists as a module may be included via a direct
+ // dependency as well as transitive ones.
+ CommonModules: android.SortedUniqueStrings(javaModules),
+ }
+
+ // Populate the exported files property in a fixed order.
+ for _, tag := range android.SortedStringKeys(exportedFiles) {
+ deapexerProperties.ExportedFiles = append(deapexerProperties.ExportedFiles, DeapexerExportedFile{
+ Tag: tag,
+ Path: exportedFiles[tag],
+ })
+ }
+
props := struct {
Name *string
Selected_apex *string
@@ -479,8 +516,52 @@
exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
)
-func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
- p.deapexerDeps(ctx)
+var _ prebuiltApexModuleCreator = (*Prebuilt)(nil)
+
+// createPrebuiltApexModules creates modules necessary to export files from the prebuilt apex to the
+// build.
+//
+// If this needs to make files from within a `.apex` file available for use by other Soong modules,
+// e.g. make dex implementation jars available for java_import modules listed in exported_java_libs,
+// it does so as follows:
+//
+// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and
+// makes them available for use by other modules, at both Soong and ninja levels.
+//
+// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what
+// an `apex` module does. That ensures that code which looks for specific apex variant, e.g.
+// dexpreopt, will work the same way from source and prebuilt.
+//
+// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto
+// itself so that they can retrieve the file paths to those files.
+//
+// It also creates a child module `selector` that is responsible for selecting the appropriate
+// input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons:
+// 1. To dedup the selection logic so it only runs in one module.
+// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an
+// `apex_set`.
+//
+// prebuilt_apex
+// / | \
+// / | \
+// V V V
+// selector <--- deapexer <--- exported java lib
+//
+func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
+ baseModuleName := p.BaseModuleName()
+
+ apexSelectorModuleName := apexSelectorModuleName(baseModuleName)
+ createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties)
+
+ apexFileSource := ":" + apexSelectorModuleName
+ createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, &p.prebuiltCommonProperties)
+
+ // Add a source reference to retrieve the selected apex from the selector module.
+ p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
+}
+
+func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
+ p.prebuiltApexContentsDeps(ctx)
}
var _ ApexInfoMutator = (*Prebuilt)(nil)
@@ -491,7 +572,7 @@
func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// TODO(jungjw): Check the key validity.
- p.inputApex = android.OptionalPathForModuleSrc(ctx, p.selectedApexProperties.Selected_apex).Path()
+ p.inputApex = android.OptionalPathForModuleSrc(ctx, p.prebuiltCommonProperties.Selected_apex).Path()
p.installDir = android.PathForModuleInstall(ctx, "apex")
p.installFilename = p.InstallFilename()
if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
@@ -693,30 +774,15 @@
// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
func apexSetFactory() android.Module {
module := &ApexSet{}
- module.AddProperties(&module.properties, &module.selectedApexProperties, &module.deapexerProperties)
+ module.AddProperties(&module.properties, &module.prebuiltCommonProperties)
- android.InitSingleSourcePrebuiltModule(module, &module.selectedApexProperties, "Selected_apex")
+ android.InitSingleSourcePrebuiltModule(module, &module.prebuiltCommonProperties, "Selected_apex")
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
- android.AddLoadHook(module, func(ctx android.LoadHookContext) {
- baseModuleName := module.BaseModuleName()
-
- apexExtractorModuleName := apexExtractorModuleName(baseModuleName)
- createApexExtractorModule(ctx, apexExtractorModuleName, &module.properties.ApexExtractorProperties)
-
- apexFileSource := ":" + apexExtractorModuleName
- if len(module.deapexerProperties.Exported_java_libs) != 0 {
- createDeapexerModule(ctx, deapexerModuleName(baseModuleName), apexFileSource, &module.deapexerProperties)
- }
-
- // After passing the arch specific src properties to the creating the apex selector module
- module.selectedApexProperties.Selected_apex = proptools.StringPtr(apexFileSource)
- })
-
return module
}
-func createApexExtractorModule(ctx android.LoadHookContext, name string, apexExtractorProperties *ApexExtractorProperties) {
+func createApexExtractorModule(ctx android.TopDownMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) {
props := struct {
Name *string
}{
@@ -733,8 +799,30 @@
return baseModuleName + ".apex.extractor"
}
-func (a *ApexSet) DepsMutator(ctx android.BottomUpMutatorContext) {
- a.deapexerDeps(ctx)
+var _ prebuiltApexModuleCreator = (*ApexSet)(nil)
+
+// createPrebuiltApexModules creates modules necessary to export files from the apex set to other
+// modules.
+//
+// This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a
+// prebuilt_apex except that instead of creating a selector module which selects one .apex file
+// from those provided this creates an extractor module which extracts the appropriate .apex file
+// from the zip file containing them.
+func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
+ baseModuleName := a.BaseModuleName()
+
+ apexExtractorModuleName := apexExtractorModuleName(baseModuleName)
+ createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties)
+
+ apexFileSource := ":" + apexExtractorModuleName
+ createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, &a.prebuiltCommonProperties)
+
+ // After passing the arch specific src properties to the creating the apex selector module
+ a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
+}
+
+func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
+ a.prebuiltApexContentsDeps(ctx)
}
var _ ApexInfoMutator = (*ApexSet)(nil)
@@ -749,7 +837,7 @@
ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
}
- inputApex := android.OptionalPathForModuleSrc(ctx, a.selectedApexProperties.Selected_apex).Path()
+ inputApex := android.OptionalPathForModuleSrc(ctx, a.prebuiltCommonProperties.Selected_apex).Path()
a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 0551a18..c3f13e6 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -257,24 +257,74 @@
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
- "foo/bar/a.cpp": "",
+ "foo/bar/both.cpp": "",
+ "foo/bar/sharedonly.cpp": "",
+ "foo/bar/staticonly.cpp": "",
"foo/bar/Android.bp": `
cc_library {
name: "a",
- shared: { whole_static_libs: ["b"] },
- static: { srcs: ["a.cpp"] },
+ srcs: ["both.cpp"],
+ cflags: ["bothflag"],
+ shared_libs: ["shared_dep_for_both"],
+ static_libs: ["static_dep_for_both"],
+ whole_static_libs: ["whole_static_lib_for_both"],
+ static: {
+ srcs: ["staticonly.cpp"],
+ cflags: ["staticflag"],
+ shared_libs: ["shared_dep_for_static"],
+ static_libs: ["static_dep_for_static"],
+ whole_static_libs: ["whole_static_lib_for_static"],
+ },
+ shared: {
+ srcs: ["sharedonly.cpp"],
+ cflags: ["sharedflag"],
+ shared_libs: ["shared_dep_for_shared"],
+ static_libs: ["static_dep_for_shared"],
+ whole_static_libs: ["whole_static_lib_for_shared"],
+ },
bazel_module: { bp2build_available: true },
}
-cc_library_static { name: "b" }
+cc_library_static { name: "static_dep_for_shared" }
+
+cc_library_static { name: "static_dep_for_static" }
+
+cc_library_static { name: "static_dep_for_both" }
+
+cc_library_static { name: "whole_static_lib_for_shared" }
+
+cc_library_static { name: "whole_static_lib_for_static" }
+
+cc_library_static { name: "whole_static_lib_for_both" }
+
+cc_library { name: "shared_dep_for_shared" }
+
+cc_library { name: "shared_dep_for_static" }
+
+cc_library { name: "shared_dep_for_both" }
`,
},
bp: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
- copts = ["-Ifoo/bar"],
- srcs = ["a.cpp"],
- static_deps_for_shared = [":b"],
+ copts = [
+ "bothflag",
+ "-Ifoo/bar",
+ ],
+ deps = [":static_dep_for_both"],
+ dynamic_deps = [":shared_dep_for_both"],
+ dynamic_deps_for_shared = [":shared_dep_for_shared"],
+ dynamic_deps_for_static = [":shared_dep_for_static"],
+ shared_copts = ["sharedflag"],
+ shared_srcs = ["sharedonly.cpp"],
+ srcs = ["both.cpp"],
+ static_copts = ["staticflag"],
+ static_deps_for_shared = [":static_dep_for_shared"],
+ static_deps_for_static = [":static_dep_for_static"],
+ static_srcs = ["staticonly.cpp"],
+ whole_archive_deps = [":whole_static_lib_for_both"],
+ whole_archive_deps_for_shared = [":whole_static_lib_for_shared"],
+ whole_archive_deps_for_static = [":whole_static_lib_for_static"],
)`},
},
{
@@ -302,6 +352,162 @@
version_script = "v.map",
)`},
},
+ {
+ description: "cc_library configured version script",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
+ dir: "foo/bar",
+ filesystem: map[string]string{
+ "foo/bar/Android.bp": `
+ cc_library {
+ name: "a",
+ srcs: ["a.cpp"],
+ arch: {
+ arm: {
+ version_script: "arm.map",
+ },
+ arm64: {
+ version_script: "arm64.map",
+ },
+ },
+
+ bazel_module: { bp2build_available: true },
+ }
+ `,
+ },
+ bp: soongCcLibraryPreamble,
+ expectedBazelTargets: []string{`cc_library(
+ name = "a",
+ copts = ["-Ifoo/bar"],
+ srcs = ["a.cpp"],
+ version_script = select({
+ "//build/bazel/platforms/arch:arm": "arm.map",
+ "//build/bazel/platforms/arch:arm64": "arm64.map",
+ "//conditions:default": None,
+ }),
+)`},
+ },
+ {
+ description: "cc_library shared_libs",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
+ dir: "foo/bar",
+ filesystem: map[string]string{
+ "foo/bar/Android.bp": `
+cc_library {
+ name: "mylib",
+ bazel_module: { bp2build_available: true },
+}
+
+cc_library {
+ name: "a",
+ shared_libs: ["mylib",],
+ bazel_module: { bp2build_available: true },
+}
+`,
+ },
+ bp: soongCcLibraryPreamble,
+ expectedBazelTargets: []string{`cc_library(
+ name = "a",
+ copts = ["-Ifoo/bar"],
+ dynamic_deps = [":mylib"],
+)`, `cc_library(
+ name = "mylib",
+ copts = ["-Ifoo/bar"],
+)`},
+ },
+ {
+ description: "cc_library pack_relocations test",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
+ dir: "foo/bar",
+ filesystem: map[string]string{
+ "foo/bar/Android.bp": `
+cc_library {
+ name: "a",
+ srcs: ["a.cpp"],
+ pack_relocations: false,
+ bazel_module: { bp2build_available: true },
+}
+
+cc_library {
+ name: "b",
+ srcs: ["b.cpp"],
+ arch: {
+ x86_64: {
+ pack_relocations: false,
+ },
+ },
+ bazel_module: { bp2build_available: true },
+}
+
+cc_library {
+ name: "c",
+ srcs: ["c.cpp"],
+ target: {
+ darwin: {
+ pack_relocations: false,
+ },
+ },
+ bazel_module: { bp2build_available: true },
+}`,
+ },
+ bp: soongCcLibraryPreamble,
+ expectedBazelTargets: []string{`cc_library(
+ name = "a",
+ copts = ["-Ifoo/bar"],
+ linkopts = ["-Wl,--pack-dyn-relocs=none"],
+ srcs = ["a.cpp"],
+)`, `cc_library(
+ name = "b",
+ copts = ["-Ifoo/bar"],
+ linkopts = select({
+ "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"],
+ "//conditions:default": [],
+ }),
+ srcs = ["b.cpp"],
+)`, `cc_library(
+ name = "c",
+ copts = ["-Ifoo/bar"],
+ linkopts = select({
+ "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"],
+ "//conditions:default": [],
+ }),
+ srcs = ["c.cpp"],
+)`},
+ },
+ {
+ description: "cc_library spaces in copts",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
+ dir: "foo/bar",
+ filesystem: map[string]string{
+ "foo/bar/Android.bp": `
+cc_library {
+ name: "a",
+ cflags: ["-include header.h",],
+ bazel_module: { bp2build_available: true },
+}
+`,
+ },
+ bp: soongCcLibraryPreamble,
+ expectedBazelTargets: []string{`cc_library(
+ name = "a",
+ copts = [
+ "-include",
+ "header.h",
+ "-Ifoo/bar",
+ ],
+)`},
+ },
}
dir := "."
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index bff9b07..d082db1 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -189,8 +189,6 @@
":header_lib_2",
":static_lib_1",
":static_lib_2",
- ":whole_static_lib_1",
- ":whole_static_lib_2",
],
includes = [
"export_include_dir_1",
@@ -201,6 +199,10 @@
"foo_static1.cc",
"foo_static2.cc",
],
+ whole_archive_deps = [
+ ":whole_static_lib_1",
+ ":whole_static_lib_2",
+ ],
)`, `cc_library_static(
name = "static_lib_1",
copts = ["-I."],
@@ -423,13 +425,14 @@
name = "foo_static",
copts = ["-I."],
deps = select({
- "//build/bazel/platforms/arch:arm64": [
- ":static_dep",
- ":static_dep2",
- ],
+ "//build/bazel/platforms/arch:arm64": [":static_dep"],
"//conditions:default": [],
}),
linkstatic = True,
+ whole_archive_deps = select({
+ "//build/bazel/platforms/arch:arm64": [":static_dep2"],
+ "//conditions:default": [],
+ }),
)`, `cc_library_static(
name = "static_dep",
copts = ["-I."],
@@ -458,13 +461,14 @@
name = "foo_static",
copts = ["-I."],
deps = select({
- "//build/bazel/platforms/os:android": [
- ":static_dep",
- ":static_dep2",
- ],
+ "//build/bazel/platforms/os:android": [":static_dep"],
"//conditions:default": [],
}),
linkstatic = True,
+ whole_archive_deps = select({
+ "//build/bazel/platforms/os:android": [":static_dep2"],
+ "//conditions:default": [],
+ }),
)`, `cc_library_static(
name = "static_dep",
copts = ["-I."],
@@ -497,10 +501,7 @@
expectedBazelTargets: []string{`cc_library_static(
name = "foo_static",
copts = ["-I."],
- deps = [
- ":static_dep",
- ":static_dep2",
- ] + select({
+ deps = [":static_dep"] + select({
"//build/bazel/platforms/arch:arm64": [":static_dep4"],
"//conditions:default": [],
}) + select({
@@ -508,6 +509,7 @@
"//conditions:default": [],
}),
linkstatic = True,
+ whole_archive_deps = [":static_dep2"],
)`, `cc_library_static(
name = "static_dep",
copts = ["-I."],
@@ -732,8 +734,7 @@
cc_library_static { name: "static_dep" }
cc_library_static {
name: "foo_static",
- static_libs: ["static_dep"],
- whole_static_libs: ["static_dep"],
+ static_libs: ["static_dep", "static_dep"],
}`,
expectedBazelTargets: []string{`cc_library_static(
name = "foo_static",
diff --git a/bp2build/configurability.go b/bp2build/configurability.go
index 95a2747..2b8f6cc 100644
--- a/bp2build/configurability.go
+++ b/bp2build/configurability.go
@@ -31,8 +31,19 @@
}
func getLabelValue(label bazel.LabelAttribute) (reflect.Value, selects, selects) {
- value := reflect.ValueOf(label.Value)
- return value, nil, nil
+ var value reflect.Value
+ var archSelects selects
+
+ if label.HasConfigurableValues() {
+ archSelects = map[string]reflect.Value{}
+ for arch, selectKey := range bazel.PlatformArchMap {
+ archSelects[selectKey] = reflect.ValueOf(label.GetValueForArch(arch))
+ }
+ } else {
+ value = reflect.ValueOf(label.Value)
+ }
+
+ return value, archSelects, nil
}
func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects, selects) {
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 1433f6f..4c01de5 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -17,6 +17,7 @@
"android/soong/android"
"android/soong/bazel"
"path/filepath"
+ "strings"
)
// bp2build functions and helpers for converting cc_* modules to Bazel.
@@ -85,7 +86,11 @@
}
type sharedAttributes struct {
- staticDeps bazel.LabelListAttribute
+ copts bazel.StringListAttribute
+ srcs bazel.LabelListAttribute
+ staticDeps bazel.LabelListAttribute
+ dynamicDeps bazel.LabelListAttribute
+ wholeArchiveDeps bazel.LabelListAttribute
}
// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
@@ -95,17 +100,35 @@
return sharedAttributes{}
}
- var staticDeps bazel.LabelListAttribute
+ copts := bazel.StringListAttribute{Value: lib.SharedProperties.Shared.Cflags}
- staticDeps.Value = android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)
+ srcs := bazel.LabelListAttribute{
+ Value: android.BazelLabelForModuleSrc(ctx, lib.SharedProperties.Shared.Srcs)}
+
+ staticDeps := bazel.LabelListAttribute{
+ Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Static_libs)}
+
+ dynamicDeps := bazel.LabelListAttribute{
+ Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Shared_libs)}
+
+ wholeArchiveDeps := bazel.LabelListAttribute{
+ Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)}
return sharedAttributes{
- staticDeps: staticDeps,
+ copts: copts,
+ srcs: srcs,
+ staticDeps: staticDeps,
+ dynamicDeps: dynamicDeps,
+ wholeArchiveDeps: wholeArchiveDeps,
}
}
type staticAttributes struct {
- srcs bazel.LabelListAttribute
+ copts bazel.StringListAttribute
+ srcs bazel.LabelListAttribute
+ staticDeps bazel.LabelListAttribute
+ dynamicDeps bazel.LabelListAttribute
+ wholeArchiveDeps bazel.LabelListAttribute
}
// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
@@ -115,11 +138,26 @@
return staticAttributes{}
}
- var srcs bazel.LabelListAttribute
- srcs.Value = android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)
+ copts := bazel.StringListAttribute{Value: lib.StaticProperties.Static.Cflags}
+
+ srcs := bazel.LabelListAttribute{
+ Value: android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)}
+
+ staticDeps := bazel.LabelListAttribute{
+ Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Static_libs)}
+
+ dynamicDeps := bazel.LabelListAttribute{
+ Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Shared_libs)}
+
+ wholeArchiveDeps := bazel.LabelListAttribute{
+ Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Whole_static_libs)}
return staticAttributes{
- srcs: srcs,
+ copts: copts,
+ srcs: srcs,
+ staticDeps: staticDeps,
+ dynamicDeps: dynamicDeps,
+ wholeArchiveDeps: wholeArchiveDeps,
}
}
@@ -151,7 +189,13 @@
// Parse the list of copts.
parseCopts := func(baseCompilerProps *BaseCompilerProperties) []string {
- copts := append([]string{}, baseCompilerProps.Cflags...)
+ var copts []string
+ for _, flag := range baseCompilerProps.Cflags {
+ // Soong's cflags can contain spaces, like `-include header.h`. For
+ // Bazel's copts, split them up to be compatible with the
+ // no_copts_tokenization feature.
+ copts = append(copts, strings.Split(flag, " ")...)
+ }
for _, dir := range parseLocalIncludeDirs(baseCompilerProps) {
copts = append(copts, includeFlag(dir))
}
@@ -246,15 +290,28 @@
// Convenience struct to hold all attributes parsed from linker properties.
type linkerAttributes struct {
- deps bazel.LabelListAttribute
- linkopts bazel.StringListAttribute
- versionScript bazel.LabelAttribute
+ deps bazel.LabelListAttribute
+ dynamicDeps bazel.LabelListAttribute
+ wholeArchiveDeps bazel.LabelListAttribute
+ linkopts bazel.StringListAttribute
+ versionScript bazel.LabelAttribute
+}
+
+// FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here
+func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string {
+ flags := linkerProperties.Ldflags
+ if !BoolDefault(linkerProperties.Pack_relocations, true) {
+ flags = append(flags, "-Wl,--pack-dyn-relocs=none")
+ }
+ return flags
}
// bp2BuildParseLinkerProps parses the linker properties of a module, including
// configurable attribute values.
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
var deps bazel.LabelListAttribute
+ var dynamicDeps bazel.LabelListAttribute
+ var wholeArchiveDeps bazel.LabelListAttribute
var linkopts bazel.StringListAttribute
var versionScript bazel.LabelAttribute
@@ -263,14 +320,19 @@
libs := baseLinkerProps.Header_libs
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
libs = append(libs, baseLinkerProps.Static_libs...)
- libs = append(libs, baseLinkerProps.Whole_static_libs...)
+ wholeArchiveLibs := baseLinkerProps.Whole_static_libs
libs = android.SortedUniqueStrings(libs)
deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))
- linkopts.Value = baseLinkerProps.Ldflags
+ linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps)
+ wholeArchiveDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
if baseLinkerProps.Version_script != nil {
versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)
}
+
+ sharedLibs := baseLinkerProps.Shared_libs
+ dynamicDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, sharedLibs))
+
break
}
}
@@ -280,14 +342,19 @@
libs := baseLinkerProps.Header_libs
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
libs = append(libs, baseLinkerProps.Static_libs...)
- libs = append(libs, baseLinkerProps.Whole_static_libs...)
+ wholeArchiveLibs := baseLinkerProps.Whole_static_libs
libs = android.SortedUniqueStrings(libs)
deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs))
- linkopts.SetValueForArch(arch.Name, baseLinkerProps.Ldflags)
+ linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps))
+ wholeArchiveDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
+
if baseLinkerProps.Version_script != nil {
versionScript.SetValueForArch(arch.Name,
android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
}
+
+ sharedLibs := baseLinkerProps.Shared_libs
+ dynamicDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
}
}
@@ -296,17 +363,24 @@
libs := baseLinkerProps.Header_libs
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
libs = append(libs, baseLinkerProps.Static_libs...)
- libs = append(libs, baseLinkerProps.Whole_static_libs...)
+ wholeArchiveLibs := baseLinkerProps.Whole_static_libs
libs = android.SortedUniqueStrings(libs)
+ wholeArchiveDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs))
- linkopts.SetValueForOS(os.Name, baseLinkerProps.Ldflags)
+
+ linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps))
+
+ sharedLibs := baseLinkerProps.Shared_libs
+ dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
}
}
return linkerAttributes{
- deps: deps,
- linkopts: linkopts,
- versionScript: versionScript,
+ deps: deps,
+ dynamicDeps: dynamicDeps,
+ wholeArchiveDeps: wholeArchiveDeps,
+ linkopts: linkopts,
+ versionScript: versionScript,
}
}
diff --git a/cc/cc.go b/cc/cc.go
index 16a49d3..2520705 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -841,6 +841,10 @@
c.Properties.HideFromMake = true
}
+func (c *Module) HiddenFromMake() bool {
+ return c.Properties.HideFromMake
+}
+
func (c *Module) Toc() android.OptionalPath {
if c.linker != nil {
if library, ok := c.linker.(libraryInterface); ok {
@@ -1088,12 +1092,6 @@
return false
}
-// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
-// "product" and "vendor" variant modules return true for this function.
-// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
-// "soc_specific: true" and more vendor installed modules are included here.
-// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "product_available: true" or
-// "product_specific: true" modules are included here.
func (c *Module) UseVndk() bool {
return c.Properties.VndkVersion != ""
}
@@ -1141,6 +1139,18 @@
return c.VendorProperties.IsVendorPublicLibrary
}
+func (c *Module) HasLlndkStubs() bool {
+ lib := moduleLibraryInterface(c)
+ return lib != nil && lib.hasLLNDKStubs()
+}
+
+func (c *Module) StubsVersion() string {
+ if lib, ok := c.linker.(versionedInterface); ok {
+ return lib.stubsVersion()
+ }
+ panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", c.BaseModuleName()))
+}
+
// isImplementationForLLNDKPublic returns true for any variant of a cc_library that has LLNDK stubs
// and does not set llndk.vendor_available: false.
func (c *Module) isImplementationForLLNDKPublic() bool {
@@ -1185,7 +1195,7 @@
return false
}
-func (c *Module) isVndkSp() bool {
+func (c *Module) IsVndkSp() bool {
if vndkdep := c.vndkdep; vndkdep != nil {
return vndkdep.isVndkSp()
}
@@ -1204,7 +1214,7 @@
}
func (c *Module) MustUseVendorVariant() bool {
- return c.isVndkSp() || c.Properties.MustUseVendorVariant
+ return c.IsVndkSp() || c.Properties.MustUseVendorVariant
}
func (c *Module) getVndkExtendsModuleName() string {
@@ -1343,11 +1353,11 @@
}
func (ctx *moduleContextImpl) binary() bool {
- return ctx.mod.binary()
+ return ctx.mod.Binary()
}
func (ctx *moduleContextImpl) object() bool {
- return ctx.mod.object()
+ return ctx.mod.Object()
}
func (ctx *moduleContextImpl) canUseSdk() bool {
@@ -1445,7 +1455,7 @@
}
func (ctx *moduleContextImpl) isVndkSp() bool {
- return ctx.mod.isVndkSp()
+ return ctx.mod.IsVndkSp()
}
func (ctx *moduleContextImpl) IsVndkExt() bool {
@@ -1786,7 +1796,7 @@
// glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
// RECOVERY_SNAPSHOT_VERSION is current.
if i, ok := c.linker.(snapshotLibraryInterface); ok {
- if shouldCollectHeadersForSnapshot(ctx, c, apexInfo) {
+ if ShouldCollectHeadersForSnapshot(ctx, c, apexInfo) {
i.collectHeadersForSnapshot(ctx)
}
}
@@ -1799,7 +1809,7 @@
// modules can be hidden from make as some are needed for resolving make side
// dependencies.
c.HideFromMake()
- } else if !c.installable(apexInfo) {
+ } else if !installable(c, apexInfo) {
c.SkipInstall()
}
@@ -2451,7 +2461,7 @@
return true
}
- if to.isVndkSp() || to.IsLlndk() {
+ if to.IsVndkSp() || to.IsLlndk() {
return false
}
@@ -3064,7 +3074,7 @@
return false
}
-func (c *Module) binary() bool {
+func (c *Module) Binary() bool {
if b, ok := c.linker.(interface {
binary() bool
}); ok {
@@ -3073,7 +3083,7 @@
return false
}
-func (c *Module) object() bool {
+func (c *Module) Object() bool {
if o, ok := c.linker.(interface {
object() bool
}); ok {
@@ -3155,18 +3165,25 @@
}
}
-// Return true if the module is ever installable.
func (c *Module) EverInstallable() bool {
return c.installer != nil &&
// Check to see whether the module is actually ever installable.
c.installer.everInstallable()
}
-func (c *Module) installable(apexInfo android.ApexInfo) bool {
+func (c *Module) PreventInstall() bool {
+ return c.Properties.PreventInstall
+}
+
+func (c *Module) Installable() *bool {
+ return c.Properties.Installable
+}
+
+func installable(c LinkableInterface, apexInfo android.ApexInfo) bool {
ret := c.EverInstallable() &&
// Check to see whether the module has been configured to not be installed.
- proptools.BoolDefault(c.Properties.Installable, true) &&
- !c.Properties.PreventInstall && c.outputFile.Valid()
+ proptools.BoolDefault(c.Installable(), true) &&
+ !c.PreventInstall() && c.OutputFile().Valid()
// The platform variant doesn't need further condition. Apex variants however might not
// be installable because it will likely to be included in the APEX and won't appear
diff --git a/cc/cc_test.go b/cc/cc_test.go
index e9daf33..d82619a 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -381,8 +381,8 @@
if !mod.IsVndk() {
t.Errorf("%q IsVndk() must equal to true", name)
}
- if mod.isVndkSp() != isVndkSp {
- t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
+ if mod.IsVndkSp() != isVndkSp {
+ t.Errorf("%q IsVndkSp() must equal to %t", name, isVndkSp)
}
// Check VNDK extension properties.
diff --git a/cc/coverage.go b/cc/coverage.go
index 5b5ccf2..b2788ec 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -203,7 +203,7 @@
type Coverage interface {
android.Module
IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool
- PreventInstall()
+ SetPreventInstall()
HideFromMake()
MarkAsCoverageVariant(bool)
EnableCoverageIfNeeded()
@@ -236,7 +236,7 @@
// to an APEX via 'data' property.
m := mctx.CreateVariations("", "cov")
m[0].(Coverage).MarkAsCoverageVariant(false)
- m[0].(Coverage).PreventInstall()
+ m[0].(Coverage).SetPreventInstall()
m[0].(Coverage).HideFromMake()
m[1].(Coverage).MarkAsCoverageVariant(true)
diff --git a/cc/library.go b/cc/library.go
index 7b631fa..c5ff9b1 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -220,15 +220,29 @@
// For bp2build conversion.
type bazelCcLibraryAttributes struct {
- Srcs bazel.LabelListAttribute
- Hdrs bazel.LabelListAttribute
- Copts bazel.StringListAttribute
- Linkopts bazel.StringListAttribute
- Deps bazel.LabelListAttribute
- User_link_flags bazel.StringListAttribute
- Includes bazel.StringListAttribute
- Static_deps_for_shared bazel.LabelListAttribute
- Version_script bazel.LabelAttribute
+ // Attributes pertaining to both static and shared variants.
+ Srcs bazel.LabelListAttribute
+ Hdrs bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
+ Dynamic_deps bazel.LabelListAttribute
+ Whole_archive_deps bazel.LabelListAttribute
+ Copts bazel.StringListAttribute
+ Includes bazel.StringListAttribute
+ Linkopts bazel.StringListAttribute
+ // Attributes pertaining to shared variant.
+ Shared_copts bazel.StringListAttribute
+ Shared_srcs bazel.LabelListAttribute
+ Static_deps_for_shared bazel.LabelListAttribute
+ Dynamic_deps_for_shared bazel.LabelListAttribute
+ Whole_archive_deps_for_shared bazel.LabelListAttribute
+ User_link_flags bazel.StringListAttribute
+ Version_script bazel.LabelAttribute
+ // Attributes pertaining to static variant.
+ Static_copts bazel.StringListAttribute
+ Static_srcs bazel.LabelListAttribute
+ Static_deps_for_static bazel.LabelListAttribute
+ Dynamic_deps_for_static bazel.LabelListAttribute
+ Whole_archive_deps_for_static bazel.LabelListAttribute
}
type bazelCcLibrary struct {
@@ -275,16 +289,26 @@
var srcs bazel.LabelListAttribute
srcs.Append(compilerAttrs.srcs)
- srcs.Append(staticAttrs.srcs)
attrs := &bazelCcLibraryAttributes{
- Srcs: srcs,
- Copts: compilerAttrs.copts,
- Linkopts: linkerAttrs.linkopts,
- Deps: linkerAttrs.deps,
- Version_script: linkerAttrs.versionScript,
- Static_deps_for_shared: sharedAttrs.staticDeps,
- Includes: exportedIncludes,
+ Srcs: srcs,
+ Deps: linkerAttrs.deps,
+ Dynamic_deps: linkerAttrs.dynamicDeps,
+ Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
+ Copts: compilerAttrs.copts,
+ Includes: exportedIncludes,
+ Linkopts: linkerAttrs.linkopts,
+ Shared_copts: sharedAttrs.copts,
+ Shared_srcs: sharedAttrs.srcs,
+ Static_deps_for_shared: sharedAttrs.staticDeps,
+ Whole_archive_deps_for_shared: sharedAttrs.wholeArchiveDeps,
+ Dynamic_deps_for_shared: sharedAttrs.dynamicDeps,
+ Version_script: linkerAttrs.versionScript,
+ Static_copts: staticAttrs.copts,
+ Static_srcs: staticAttrs.srcs,
+ Static_deps_for_static: staticAttrs.staticDeps,
+ Whole_archive_deps_for_static: staticAttrs.wholeArchiveDeps,
+ Dynamic_deps_for_static: staticAttrs.dynamicDeps,
}
props := bazel.BazelTargetModuleProperties{
@@ -2192,13 +2216,14 @@
}
type bazelCcLibraryStaticAttributes struct {
- Copts bazel.StringListAttribute
- Srcs bazel.LabelListAttribute
- Deps bazel.LabelListAttribute
- Linkopts bazel.StringListAttribute
- Linkstatic bool
- Includes bazel.StringListAttribute
- Hdrs bazel.LabelListAttribute
+ Copts bazel.StringListAttribute
+ Srcs bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
+ Whole_archive_deps bazel.LabelListAttribute
+ Linkopts bazel.StringListAttribute
+ Linkstatic bool
+ Includes bazel.StringListAttribute
+ Hdrs bazel.LabelListAttribute
}
type bazelCcLibraryStatic struct {
@@ -2219,9 +2244,11 @@
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module)
attrs := &bazelCcLibraryStaticAttributes{
- Copts: compilerAttrs.copts,
- Srcs: compilerAttrs.srcs,
- Deps: linkerAttrs.deps,
+ Copts: compilerAttrs.copts,
+ Srcs: compilerAttrs.srcs,
+ Deps: linkerAttrs.deps,
+ Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
+
Linkopts: linkerAttrs.linkopts,
Linkstatic: true,
Includes: exportedIncludes,
diff --git a/cc/linkable.go b/cc/linkable.go
index 40a9d8b..b583b69 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -48,6 +48,20 @@
// SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
SanitizerSupported(t SanitizerType) bool
+ // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
+ // either because it requires it or because a dependent module which requires it to be linked in this module.
+ MinimalRuntimeDep() bool
+
+ // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
+ // either because it requires it or because a dependent module which requires it to be linked in this module.
+ UbsanRuntimeDep() bool
+
+ // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
+ UbsanRuntimeNeeded() bool
+
+ // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
+ MinimalRuntimeNeeded() bool
+
// SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
SanitizableDepTagChecker() SantizableDependencyTagChecker
}
@@ -60,14 +74,42 @@
// implementation should handle tags from both.
type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
+// Snapshottable defines those functions necessary for handling module snapshots.
+type Snapshottable interface {
+ // SnapshotHeaders returns a list of header paths provided by this module.
+ SnapshotHeaders() android.Paths
+
+ // ExcludeFromVendorSnapshot returns true if this module should be otherwise excluded from the vendor snapshot.
+ ExcludeFromVendorSnapshot() bool
+
+ // ExcludeFromRecoverySnapshot returns true if this module should be otherwise excluded from the recovery snapshot.
+ ExcludeFromRecoverySnapshot() bool
+
+ // SnapshotLibrary returns true if this module is a snapshot library.
+ IsSnapshotLibrary() bool
+
+ // SnapshotRuntimeLibs returns a list of libraries needed by this module at runtime but which aren't build dependencies.
+ SnapshotRuntimeLibs() []string
+
+ // SnapshotSharedLibs returns the list of shared library dependencies for this module.
+ SnapshotSharedLibs() []string
+
+ // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
+ IsSnapshotPrebuilt() bool
+}
+
// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
type LinkableInterface interface {
android.Module
+ Snapshottable
Module() android.Module
CcLibrary() bool
CcLibraryInterface() bool
+ // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
+ BaseModuleName() string
+
OutputFile() android.OptionalPath
CoverageFiles() android.Paths
@@ -79,9 +121,6 @@
BuildSharedVariant() bool
SetStatic()
SetShared()
- Static() bool
- Shared() bool
- Header() bool
IsPrebuilt() bool
Toc() android.OptionalPath
@@ -106,13 +145,29 @@
// IsLlndkPublic returns true only for LLNDK (public) libs.
IsLlndkPublic() bool
+ // HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
+ HasLlndkStubs() bool
+
// NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
NeedsLlndkVariants() bool
// NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
NeedsVendorPublicLibraryVariants() bool
+ //StubsVersion returns the stubs version for this module.
+ StubsVersion() string
+
+ // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
+ // "product" and "vendor" variant modules return true for this function.
+ // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
+ // "soc_specific: true" and more vendor installed modules are included here.
+ // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
+ // "product_specific: true" modules are included here.
UseVndk() bool
+
+ // IsVndkSp returns true if this is a VNDK-SP module.
+ IsVndkSp() bool
+
MustUseVendorVariant() bool
IsVndk() bool
IsVndkExt() bool
@@ -140,6 +195,51 @@
// KernelHeadersDecorator returns true if this is a kernel headers decorator module.
// This is specific to cc and should always return false for all other packages.
KernelHeadersDecorator() bool
+
+ // HiddenFromMake returns true if this module is hidden from Make.
+ HiddenFromMake() bool
+
+ // RelativeInstallPath returns the relative install path for this module.
+ RelativeInstallPath() string
+
+ // Binary returns true if this is a binary module.
+ Binary() bool
+
+ // Object returns true if this is an object module.
+ Object() bool
+
+ // Rlib returns true if this is an rlib module.
+ Rlib() bool
+
+ // Dylib returns true if this is an dylib module.
+ Dylib() bool
+
+ // Static returns true if this is a static library module.
+ Static() bool
+
+ // Shared returns true if this is a shared library module.
+ Shared() bool
+
+ // Header returns true if this is a library headers module.
+ Header() bool
+
+ // EverInstallable returns true if the module is ever installable
+ EverInstallable() bool
+
+ // PreventInstall returns true if this module is prevented from installation.
+ PreventInstall() bool
+
+ // InstallInData returns true if this module is installed in data.
+ InstallInData() bool
+
+ // Installable returns a bool pointer to the module installable property.
+ Installable() *bool
+
+ // Symlinks returns a list of symlinks that should be created for this module.
+ Symlinks() []string
+
+ // VndkVersion returns the VNDK version string for this module.
+ VndkVersion() string
}
var (
diff --git a/cc/linker.go b/cc/linker.go
index 73fc4f0..a9930ad 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -421,9 +421,13 @@
if !BoolDefault(linker.Properties.Pack_relocations, true) {
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=none")
} else if ctx.Device() {
- // The SHT_RELR relocations is only supported by API level >= 28.
- // Do not turn this on if older version NDK is used.
- if !ctx.useSdk() || CheckSdkVersionAtLeast(ctx, 28) {
+ // SHT_RELR relocations are only supported at API level >= 30.
+ // ANDROID_RELR relocations were supported at API level >= 28.
+ // Relocation packer was supported at API level >= 23.
+ // Do the best we can...
+ if !ctx.useSdk() || CheckSdkVersionAtLeast(ctx, 30) {
+ flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=android+relr")
+ } else if CheckSdkVersionAtLeast(ctx, 28) {
flags.Global.LdFlags = append(flags.Global.LdFlags,
"-Wl,--pack-dyn-relocs=android+relr",
"-Wl,--use-android-relr-tags")
diff --git a/cc/sabi.go b/cc/sabi.go
index c0eb57c..384dcc1 100644
--- a/cc/sabi.go
+++ b/cc/sabi.go
@@ -84,7 +84,7 @@
return "LLNDK"
}
if m.UseVndk() && m.IsVndk() && !m.IsVndkPrivate() {
- if m.isVndkSp() {
+ if m.IsVndkSp() {
if m.IsVndkExt() {
return "VNDK-SP-ext"
} else {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 397121e..605a8d0 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -1075,7 +1075,7 @@
sanitizers = append(sanitizers, "shadow-call-stack")
}
- if Bool(c.sanitize.Properties.Sanitize.Memtag_heap) && c.binary() {
+ if Bool(c.sanitize.Properties.Sanitize.Memtag_heap) && c.Binary() {
noteDep := "note_memtag_heap_async"
if Bool(c.sanitize.Properties.Sanitize.Diag.Memtag_heap) {
noteDep = "note_memtag_heap_sync"
@@ -1208,6 +1208,14 @@
AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string)
}
+func (c *Module) MinimalRuntimeDep() bool {
+ return c.sanitize.Properties.MinimalRuntimeDep
+}
+
+func (c *Module) UbsanRuntimeDep() bool {
+ return c.sanitize.Properties.UbsanRuntimeDep
+}
+
func (c *Module) SanitizePropDefined() bool {
return c.sanitize != nil
}
@@ -1441,6 +1449,14 @@
return false
}
+func (m *Module) UbsanRuntimeNeeded() bool {
+ return enableUbsanRuntime(m.sanitize)
+}
+
+func (m *Module) MinimalRuntimeNeeded() bool {
+ return enableMinimalRuntime(m.sanitize)
+}
+
func enableUbsanRuntime(sanitize *sanitize) bool {
return Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) ||
Bool(sanitize.Properties.Sanitize.Diag.Undefined) ||
diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go
index 885a0ce..0b1147e 100644
--- a/cc/snapshot_prebuilt.go
+++ b/cc/snapshot_prebuilt.go
@@ -35,12 +35,12 @@
// Function that returns true if the module is included in this image.
// Using a function return instead of a value to prevent early
// evalution of a function that may be not be defined.
- inImage(m *Module) func() bool
+ inImage(m LinkableInterface) func() bool
// Returns true if the module is private and must not be included in the
// snapshot. For example VNDK-private modules must return true for the
// vendor snapshots. But false for the recovery snapshots.
- private(m *Module) bool
+ private(m LinkableInterface) bool
// Returns true if a dir under source tree is an SoC-owned proprietary
// directory, such as device/, vendor/, etc.
@@ -56,7 +56,7 @@
// Whether a given module has been explicitly excluded from the
// snapshot, e.g., using the exclude_from_vendor_snapshot or
// exclude_from_recovery_snapshot properties.
- excludeFromSnapshot(m *Module) bool
+ excludeFromSnapshot(m LinkableInterface) bool
// Returns true if the build is using a snapshot for this image.
isUsingSnapshot(cfg android.DeviceConfig) bool
@@ -125,11 +125,11 @@
return ctx.DeviceConfig().VndkVersion() == "current"
}
-func (vendorSnapshotImage) inImage(m *Module) func() bool {
+func (vendorSnapshotImage) inImage(m LinkableInterface) func() bool {
return m.InVendor
}
-func (vendorSnapshotImage) private(m *Module) bool {
+func (vendorSnapshotImage) private(m LinkableInterface) bool {
return m.IsVndkPrivate()
}
@@ -159,7 +159,7 @@
return true
}
-func (vendorSnapshotImage) excludeFromSnapshot(m *Module) bool {
+func (vendorSnapshotImage) excludeFromSnapshot(m LinkableInterface) bool {
return m.ExcludeFromVendorSnapshot()
}
@@ -206,12 +206,12 @@
return ctx.DeviceConfig().RecoverySnapshotVersion() == "current"
}
-func (recoverySnapshotImage) inImage(m *Module) func() bool {
+func (recoverySnapshotImage) inImage(m LinkableInterface) func() bool {
return m.InRecovery
}
// recovery snapshot does not have private libraries.
-func (recoverySnapshotImage) private(m *Module) bool {
+func (recoverySnapshotImage) private(m LinkableInterface) bool {
return false
}
@@ -224,7 +224,7 @@
return false
}
-func (recoverySnapshotImage) excludeFromSnapshot(m *Module) bool {
+func (recoverySnapshotImage) excludeFromSnapshot(m LinkableInterface) bool {
return m.ExcludeFromRecoverySnapshot()
}
diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go
index c32fa36..8eb6164 100644
--- a/cc/snapshot_utils.go
+++ b/cc/snapshot_utils.go
@@ -23,6 +23,36 @@
headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
)
+func (m *Module) IsSnapshotLibrary() bool {
+ if _, ok := m.linker.(snapshotLibraryInterface); ok {
+ return true
+ }
+ return false
+}
+
+func (m *Module) SnapshotHeaders() android.Paths {
+ if m.IsSnapshotLibrary() {
+ return m.linker.(snapshotLibraryInterface).snapshotHeaders()
+ }
+ return android.Paths{}
+}
+
+func (m *Module) Dylib() bool {
+ return false
+}
+
+func (m *Module) Rlib() bool {
+ return false
+}
+
+func (m *Module) SnapshotRuntimeLibs() []string {
+ return m.Properties.SnapshotRuntimeLibs
+}
+
+func (m *Module) SnapshotSharedLibs() []string {
+ return m.Properties.SnapshotSharedLibs
+}
+
// snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
type snapshotLibraryInterface interface {
libraryInterface
@@ -68,14 +98,14 @@
return snapshot, found
}
-// shouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot.
+// ShouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot.
// If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions.
-func shouldCollectHeadersForSnapshot(ctx android.ModuleContext, m *Module, apexInfo android.ApexInfo) bool {
+func ShouldCollectHeadersForSnapshot(ctx android.ModuleContext, m LinkableInterface, apexInfo android.ApexInfo) bool {
if ctx.DeviceConfig().VndkVersion() != "current" &&
ctx.DeviceConfig().RecoverySnapshotVersion() != "current" {
return false
}
- if _, _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok {
+ if _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok {
return ctx.Config().VndkSnapshotBuildArtifacts()
}
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index 9ad51ad..4e59a95 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -115,7 +115,7 @@
// still be a vendor proprietary module. This happens for cc modules
// that are excluded from the vendor snapshot, and it means that the
// vendor has assumed control of the framework-provided module.
- if c, ok := ctx.Module().(*Module); ok {
+ if c, ok := ctx.Module().(LinkableInterface); ok {
if c.ExcludeFromVendorSnapshot() {
return true
}
@@ -137,7 +137,7 @@
// that are excluded from the recovery snapshot, and it means that the
// vendor has assumed control of the framework-provided module.
- if c, ok := ctx.Module().(*Module); ok {
+ if c, ok := ctx.Module().(LinkableInterface); ok {
if c.ExcludeFromRecoverySnapshot() {
return true
}
@@ -147,8 +147,8 @@
}
// Determines if the module is a candidate for snapshot.
-func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool {
- if !m.Enabled() || m.Properties.HideFromMake {
+func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool {
+ if !m.Enabled() || m.HiddenFromMake() {
return false
}
// When android/prebuilt.go selects between source and prebuilt, it sets
@@ -177,51 +177,51 @@
return false
}
// skip kernel_headers which always depend on vendor
- if _, ok := m.linker.(*kernelHeadersDecorator); ok {
+ if m.KernelHeadersDecorator() {
return false
}
- // skip LLNDK libraries which are backward compatible
+
if m.IsLlndk() {
return false
}
// Libraries
- if l, ok := m.linker.(snapshotLibraryInterface); ok {
- if m.sanitize != nil {
+ if sanitizable, ok := m.(PlatformSanitizeable); ok && sanitizable.IsSnapshotLibrary() {
+ if sanitizable.SanitizePropDefined() {
// scs and hwasan export both sanitized and unsanitized variants for static and header
// Always use unsanitized variants of them.
for _, t := range []SanitizerType{scs, Hwasan} {
- if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
+ if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(t) {
return false
}
}
// cfi also exports both variants. But for static, we capture both.
// This is because cfi static libraries can't be linked from non-cfi modules,
// and vice versa. This isn't the case for scs and hwasan sanitizers.
- if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) {
+ if !sanitizable.Static() && !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(cfi) {
return false
}
}
- if l.static() {
- return m.outputFile.Valid() && !image.private(m)
+ if sanitizable.Static() {
+ return sanitizable.OutputFile().Valid() && !image.private(m)
}
- if l.shared() {
- if !m.outputFile.Valid() {
+ if sanitizable.Shared() {
+ if !sanitizable.OutputFile().Valid() {
return false
}
if image.includeVndk() {
- if !m.IsVndk() {
+ if !sanitizable.IsVndk() {
return true
}
- return m.IsVndkExt()
+ return sanitizable.IsVndkExt()
}
}
return true
}
// Binaries and Objects
- if m.binary() || m.object() {
- return m.outputFile.Valid()
+ if m.Binary() || m.Object() {
+ return m.OutputFile().Valid()
}
return false
@@ -323,7 +323,7 @@
// installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file.
// For executables, init_rc and vintf_fragments files are also copied.
- installSnapshot := func(m *Module, fake bool) android.Paths {
+ installSnapshot := func(m LinkableInterface, fake bool) android.Paths {
targetArch := "arch-" + m.Target().Arch.ArchType.String()
if m.Target().Arch.ArchVariant != "" {
targetArch += "-" + m.Target().Arch.ArchVariant
@@ -337,7 +337,7 @@
prop.ModuleName = ctx.ModuleName(m)
if c.supportsVndkExt && m.IsVndkExt() {
// vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
- if m.isVndkSp() {
+ if m.IsVndkSp() {
prop.RelativeInstallPath = "vndk-sp"
} else {
prop.RelativeInstallPath = "vndk"
@@ -345,7 +345,7 @@
} else {
prop.RelativeInstallPath = m.RelativeInstallPath()
}
- prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs
+ prop.RuntimeLibs = m.SnapshotRuntimeLibs()
prop.Required = m.RequiredModuleNames()
for _, path := range m.InitRc() {
prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base()))
@@ -365,8 +365,8 @@
var propOut string
- if l, ok := m.linker.(snapshotLibraryInterface); ok {
- exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
+ if m.IsSnapshotLibrary() {
+ exporterInfo := ctx.ModuleProvider(m.Module(), FlagExporterInfoProvider).(FlagExporterInfo)
// library flags
prop.ExportedFlags = exporterInfo.Flags
@@ -376,19 +376,22 @@
for _, dir := range exporterInfo.SystemIncludeDirs {
prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String()))
}
+
// shared libs dependencies aren't meaningful on static or header libs
- if l.shared() {
- prop.SharedLibs = m.Properties.SnapshotSharedLibs
+ if m.Shared() {
+ prop.SharedLibs = m.SnapshotSharedLibs()
}
- if l.static() && m.sanitize != nil {
- prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize)
- prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize)
+ if sanitizable, ok := m.(PlatformSanitizeable); ok {
+ if sanitizable.Static() && sanitizable.SanitizePropDefined() {
+ prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded()
+ prop.SanitizeUbsanDep = sanitizable.UbsanRuntimeDep() || sanitizable.UbsanRuntimeNeeded()
+ }
}
var libType string
- if l.static() {
+ if m.Static() {
libType = "static"
- } else if l.shared() {
+ } else if m.Shared() {
libType = "shared"
} else {
libType = "header"
@@ -398,16 +401,18 @@
// install .a or .so
if libType != "header" {
- libPath := m.outputFile.Path()
+ libPath := m.OutputFile().Path()
stem = libPath.Base()
- if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) {
- // both cfi and non-cfi variant for static libraries can exist.
- // attach .cfi to distinguish between cfi and non-cfi.
- // e.g. libbase.a -> libbase.cfi.a
- ext := filepath.Ext(stem)
- stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
- prop.Sanitize = "cfi"
- prop.ModuleName += ".cfi"
+ if sanitizable, ok := m.(PlatformSanitizeable); ok {
+ if sanitizable.Static() && sanitizable.SanitizePropDefined() && sanitizable.IsSanitizerEnabled(cfi) {
+ // both cfi and non-cfi variant for static libraries can exist.
+ // attach .cfi to distinguish between cfi and non-cfi.
+ // e.g. libbase.a -> libbase.cfi.a
+ ext := filepath.Ext(stem)
+ stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
+ prop.Sanitize = "cfi"
+ prop.ModuleName += ".cfi"
+ }
}
snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake))
@@ -416,20 +421,20 @@
}
propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
- } else if m.binary() {
+ } else if m.Binary() {
// binary flags
prop.Symlinks = m.Symlinks()
- prop.SharedLibs = m.Properties.SnapshotSharedLibs
+ prop.SharedLibs = m.SnapshotSharedLibs()
// install bin
- binPath := m.outputFile.Path()
+ binPath := m.OutputFile().Path()
snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake))
propOut = snapshotBinOut + ".json"
- } else if m.object() {
+ } else if m.Object() {
// object files aren't installed to the device, so their names can conflict.
// Use module name as stem.
- objPath := m.outputFile.Path()
+ objPath := m.OutputFile().Path()
snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake))
@@ -450,7 +455,7 @@
}
ctx.VisitAllModules(func(module android.Module) {
- m, ok := module.(*Module)
+ m, ok := module.(LinkableInterface)
if !ok {
return
}
@@ -484,8 +489,8 @@
// installSnapshot installs prebuilts and json flag files
snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...)
// just gather headers and notice files here, because they are to be deduplicated
- if l, ok := m.linker.(snapshotLibraryInterface); ok {
- headers = append(headers, l.snapshotHeaders()...)
+ if m.IsSnapshotLibrary() {
+ headers = append(headers, m.SnapshotHeaders()...)
}
if len(m.NoticeFiles()) > 0 {
diff --git a/cc/vndk.go b/cc/vndk.go
index 8b3788b..0254edc 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -372,7 +372,7 @@
if mctx.ModuleName() == "libz" {
return false
}
- return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.isVndkSp()
+ return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.IsVndkSp()
}
useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
@@ -574,38 +574,37 @@
vndkSnapshotZipFile android.OptionalPath
}
-func isVndkSnapshotAware(config android.DeviceConfig, m *Module,
- apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
+func isVndkSnapshotAware(config android.DeviceConfig, m LinkableInterface,
+ apexInfo android.ApexInfo) (vndkType string, isVndkSnapshotLib bool) {
if m.Target().NativeBridge == android.NativeBridgeEnabled {
- return nil, "", false
+ return "", false
}
// !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
// !installable: Snapshot only cares about "installable" modules.
// !m.IsLlndk: llndk stubs are required for building against snapshots.
// IsSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
// !outputFile.Valid: Snapshot requires valid output file.
- if !m.InVendor() || (!m.installable(apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.outputFile.Valid() {
- return nil, "", false
+ if !m.InVendor() || (!installable(m, apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.OutputFile().Valid() {
+ return "", false
}
- l, ok := m.linker.(snapshotLibraryInterface)
- if !ok || !l.shared() {
- return nil, "", false
+ if !m.IsSnapshotLibrary() || !m.Shared() {
+ return "", false
}
if m.VndkVersion() == config.PlatformVndkVersion() {
if m.IsVndk() && !m.IsVndkExt() {
- if m.isVndkSp() {
- return l, "vndk-sp", true
+ if m.IsVndkSp() {
+ return "vndk-sp", true
} else {
- return l, "vndk-core", true
+ return "vndk-core", true
}
- } else if l.hasLLNDKStubs() && l.stubsVersion() == "" {
+ } else if m.HasLlndkStubs() && m.StubsVersion() == "" {
// Use default version for the snapshot.
- return l, "llndk-stub", true
+ return "llndk-stub", true
}
}
- return nil, "", false
+ return "", false
}
func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
@@ -722,7 +721,7 @@
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
- l, vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
+ vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
if !ok {
return
}
@@ -761,7 +760,7 @@
}
if ctx.Config().VndkSnapshotBuildArtifacts() {
- headers = append(headers, l.snapshotHeaders()...)
+ headers = append(headers, m.SnapshotHeaders()...)
}
})
diff --git a/cmd/soong_build/writedocs.go b/cmd/soong_build/writedocs.go
index a69de6a..b7c260c 100644
--- a/cmd/soong_build/writedocs.go
+++ b/cmd/soong_build/writedocs.go
@@ -114,7 +114,10 @@
err = ioutil.WriteFile(filename, buf.Bytes(), 0666)
}
- // Now, produce per-package module lists with detailed information.
+ // Now, produce per-package module lists with detailed information, and a list
+ // of keywords.
+ keywordsTmpl := template.Must(template.New("file").Parse(keywordsTemplate))
+ keywordsBuf := &bytes.Buffer{}
for _, pkg := range packages {
// We need a module name getter/setter function because I couldn't
// find a way to keep it in a variable defined within the template.
@@ -141,7 +144,17 @@
if err != nil {
return err
}
+ err = keywordsTmpl.Execute(keywordsBuf, data)
+ if err != nil {
+ return err
+ }
}
+
+ // Write out list of keywords. This includes all module and property names, which is useful for
+ // building syntax highlighters.
+ keywordsFilename := filepath.Join(filepath.Dir(filename), "keywords.txt")
+ err = ioutil.WriteFile(keywordsFilename, keywordsBuf.Bytes(), 0666)
+
return err
}
@@ -413,4 +426,9 @@
</script>
{{end}}
`
+
+ keywordsTemplate = `
+{{range $moduleType := .Modules}}{{$moduleType.Name}}:{{range $property := $moduleType.Properties}}{{$property.Name}},{{end}}
+{{end}}
+`
)
diff --git a/java/app.go b/java/app.go
index 5695022..fc1ace0 100755
--- a/java/app.go
+++ b/java/app.go
@@ -893,7 +893,7 @@
return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
}
-func (a *AndroidApp) PreventInstall() {
+func (a *AndroidApp) SetPreventInstall() {
a.appProperties.PreventInstall = true
}
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index 6270b5b..bed629d 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -109,6 +109,8 @@
android.ModuleBase
android.ApexModuleBase
android.SdkBase
+ ClasspathFragmentBase
+
properties bootclasspathFragmentProperties
}
@@ -117,6 +119,7 @@
m.AddProperties(&m.properties)
android.InitApexModule(m)
android.InitSdkAwareModule(m)
+ initClasspathFragment(m, BOOTCLASSPATH)
android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
android.AddLoadHook(m, func(ctx android.LoadHookContext) {
@@ -242,6 +245,22 @@
// BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the
// apex contents.
type BootclasspathFragmentApexContentInfo struct {
+ // ClasspathFragmentProtoOutput is an output path for the generated classpaths.proto config of this module.
+ //
+ // The file should be copied to a relevant place on device, see ClasspathFragmentProtoInstallDir
+ // for more details.
+ ClasspathFragmentProtoOutput android.OutputPath
+
+ // ClasspathFragmentProtoInstallDir contains information about on device location for the generated classpaths.proto file.
+ //
+ // The path encodes expected sub-location within partitions, i.e. etc/classpaths/<proto-file>,
+ // for ClasspathFragmentProtoOutput. To get sub-location, instead of the full output / make path
+ // use android.InstallPath#Rel().
+ //
+ // This is only relevant for APEX modules as they perform their own installation; while regular
+ // system files are installed via ClasspathFragmentBase#androidMkEntries().
+ ClasspathFragmentProtoInstallDir android.InstallPath
+
// The image config, internal to this module (and the dex_bootjars singleton).
//
// Will be nil if the BootclasspathFragmentApexContentInfo has not been provided for a specific module. That can occur
@@ -339,30 +358,47 @@
b.bootclasspathImageNameContentsConsistencyCheck(ctx)
}
+ // Generate classpaths.proto config
+ b.generateClasspathProtoBuildActions(ctx)
+
// Perform hidden API processing.
b.generateHiddenAPIBuildActions(ctx)
- // Nothing to do if skipping the dexpreopt of boot image jars.
- if SkipDexpreoptBootJars(ctx) {
- return
- }
-
- // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
- // GenerateSingletonBuildActions method as it cannot create it for itself.
- dexpreopt.GetGlobalSoongConfig(ctx)
-
- imageConfig := b.getImageConfig(ctx)
- if imageConfig == nil {
- return
- }
-
// Construct the boot image info from the config.
- info := BootclasspathFragmentApexContentInfo{imageConfig: imageConfig}
+ info := BootclasspathFragmentApexContentInfo{
+ ClasspathFragmentProtoInstallDir: b.classpathFragmentBase().installDirPath,
+ ClasspathFragmentProtoOutput: b.classpathFragmentBase().outputFilepath,
+ imageConfig: nil,
+ }
+
+ if !SkipDexpreoptBootJars(ctx) {
+ // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
+ // GenerateSingletonBuildActions method as it cannot create it for itself.
+ dexpreopt.GetGlobalSoongConfig(ctx)
+ info.imageConfig = b.getImageConfig(ctx)
+ }
// Make it available for other modules.
ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
}
+// generateClasspathProtoBuildActions generates all required build actions for classpath.proto config
+func (b *BootclasspathFragmentModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) {
+ var classpathJars []classpathJar
+ if "art" == proptools.String(b.properties.Image_name) {
+ // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
+ classpathJars = configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), BOOTCLASSPATH, DEX2OATBOOTCLASSPATH)
+ } else {
+ classpathJars = configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), b.classpathType)
+ }
+ b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars)
+}
+
+func (b *BootclasspathFragmentModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
+ // TODO(satayev): populate with actual content
+ return android.EmptyConfiguredJarList()
+}
+
func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
// Get a map of the image configs that are supported.
imageConfigs := genBootImageConfigs(ctx)
diff --git a/java/classpath_fragment.go b/java/classpath_fragment.go
index 2e05823..7422fa2 100644
--- a/java/classpath_fragment.go
+++ b/java/classpath_fragment.go
@@ -143,6 +143,8 @@
android.WriteFileRule(ctx, output, content.String())
}
+// Returns AndroidMkEntries objects to install generated classpath.proto.
+// Do not use this to install into APEXes as the injection of the generated files happen separately for APEXes.
func (c *ClasspathFragmentBase) androidMkEntries() []android.AndroidMkEntries {
return []android.AndroidMkEntries{{
Class: "ETC",
diff --git a/java/java.go b/java/java.go
index d74bf68..9a5fbfc 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1222,6 +1222,13 @@
return LintDepSets{}
}
+func (j *Import) getStrictUpdatabilityLinting() bool {
+ return false
+}
+
+func (j *Import) setStrictUpdatabilityLinting(bool) {
+}
+
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
@@ -1545,6 +1552,13 @@
return true
}
+func (j *DexImport) getStrictUpdatabilityLinting() bool {
+ return false
+}
+
+func (j *DexImport) setStrictUpdatabilityLinting(bool) {
+}
+
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if len(j.properties.Jars) != 1 {
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
diff --git a/java/lint.go b/java/lint.go
index 5e39274..9f769df 100644
--- a/java/lint.go
+++ b/java/lint.go
@@ -103,6 +103,10 @@
type lintDepSetsIntf interface {
LintDepSets() LintDepSets
+
+ // Methods used to propagate strict_updatability_linting values.
+ getStrictUpdatabilityLinting() bool
+ setStrictUpdatabilityLinting(bool)
}
type LintDepSets struct {
@@ -153,6 +157,14 @@
return l.outputs.depSets
}
+func (l *linter) getStrictUpdatabilityLinting() bool {
+ return BoolDefault(l.properties.Lint.Strict_updatability_linting, false)
+}
+
+func (l *linter) setStrictUpdatabilityLinting(strictLinting bool) {
+ l.properties.Lint.Strict_updatability_linting = &strictLinting
+}
+
var _ lintDepSetsIntf = (*linter)(nil)
var _ lintOutputsIntf = (*linter)(nil)
@@ -260,7 +272,7 @@
cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks)
cmd.FlagForEachArg("--fatal_check ", l.properties.Lint.Fatal_checks)
- if BoolDefault(l.properties.Lint.Strict_updatability_linting, false) {
+ if l.getStrictUpdatabilityLinting() {
// Verify the module does not baseline issues that endanger safe updatability.
if baselinePath := l.getBaselineFilepath(ctx); baselinePath.Valid() {
cmd.FlagWithInput("--baseline ", baselinePath.Path())
@@ -586,6 +598,14 @@
func init() {
android.RegisterSingletonType("lint",
func() android.Singleton { return &lintSingleton{} })
+
+ registerLintBuildComponents(android.InitRegistrationContext)
+}
+
+func registerLintBuildComponents(ctx android.RegistrationContext) {
+ ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.TopDown("enforce_strict_updatability_linting", enforceStrictUpdatabilityLintingMutator).Parallel()
+ })
}
func lintZip(ctx android.BuilderContext, paths android.Paths, outputPath android.WritablePath) {
@@ -604,3 +624,15 @@
rule.Build(outputPath.Base(), outputPath.Base())
}
+
+// Enforce the strict updatability linting to all applicable transitive dependencies.
+func enforceStrictUpdatabilityLintingMutator(ctx android.TopDownMutatorContext) {
+ m := ctx.Module()
+ if d, ok := m.(lintDepSetsIntf); ok && d.getStrictUpdatabilityLinting() {
+ ctx.VisitDirectDepsWithTag(staticLibTag, func(d android.Module) {
+ if a, ok := d.(lintDepSetsIntf); ok {
+ a.setStrictUpdatabilityLinting(true)
+ }
+ })
+ }
+}
diff --git a/java/lint_test.go b/java/lint_test.go
index a253df9..6d64de7 100644
--- a/java/lint_test.go
+++ b/java/lint_test.go
@@ -181,12 +181,22 @@
srcs: [
"a.java",
],
+ static_libs: ["bar"],
min_sdk_version: "29",
sdk_version: "current",
lint: {
strict_updatability_linting: true,
},
}
+
+ java_library {
+ name: "bar",
+ srcs: [
+ "a.java",
+ ],
+ min_sdk_version: "29",
+ sdk_version: "current",
+ }
`
fs := android.MockFS{
"lint-baseline.xml": nil,
@@ -201,4 +211,11 @@
"--baseline lint-baseline.xml --disallowed_issues NewApi") {
t.Error("did not restrict baselining NewApi")
}
+
+ bar := result.ModuleForTests("bar", "android_common")
+ sboxProto = android.RuleBuilderSboxProtoForTests(t, bar.Output("lint.sbox.textproto"))
+ if !strings.Contains(*sboxProto.Commands[0].Command,
+ "--baseline lint-baseline.xml --disallowed_issues NewApi") {
+ t.Error("did not restrict baselining NewApi")
+ }
}
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index 1caffe4..c787e47 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -203,6 +203,7 @@
func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) {
// ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
classpathJars := configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), BOOTCLASSPATH, DEX2OATBOOTCLASSPATH)
+
// TODO(satayev): remove updatable boot jars once each apex has its own fragment
global := dexpreopt.GetGlobalConfig(ctx)
classpathJars = append(classpathJars, configuredJarListToClasspathJars(ctx, global.UpdatableBootJars, BOOTCLASSPATH)...)
diff --git a/java/sdk_library.go b/java/sdk_library.go
index aff4539..800e93b 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -2195,6 +2195,20 @@
}
}
+func (module *SdkLibraryImport) getStrictUpdatabilityLinting() bool {
+ if module.implLibraryModule == nil {
+ return false
+ } else {
+ return module.implLibraryModule.getStrictUpdatabilityLinting()
+ }
+}
+
+func (module *SdkLibraryImport) setStrictUpdatabilityLinting(strictLinting bool) {
+ if module.implLibraryModule != nil {
+ module.implLibraryModule.setStrictUpdatabilityLinting(strictLinting)
+ }
+}
+
// to satisfy apex.javaDependency interface
func (module *SdkLibraryImport) Stem() string {
return module.BaseModuleName()
diff --git a/java/testing.go b/java/testing.go
index 37e63f5..387d595 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -245,6 +245,7 @@
RegisterStubsBuildComponents(ctx)
RegisterSystemModulesBuildComponents(ctx)
registerSystemserverClasspathBuildComponents(ctx)
+ registerLintBuildComponents(ctx)
}
// gatherRequiredDepsForTest gathers the module definitions used by
diff --git a/rust/Android.bp b/rust/Android.bp
index f45404f..b611672 100644
--- a/rust/Android.bp
+++ b/rust/Android.bp
@@ -31,8 +31,9 @@
"protobuf.go",
"rust.go",
"sanitize.go",
- "strip.go",
"source_provider.go",
+ "snapshot_utils.go",
+ "strip.go",
"test.go",
"testing.go",
],
diff --git a/rust/compiler.go b/rust/compiler.go
index a3f02c0..1598ebf 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -341,6 +341,11 @@
return compiler.Properties.Crate_name
}
+func (compiler *baseCompiler) everInstallable() bool {
+ // Most modules are installable, so return true by default.
+ return true
+}
+
func (compiler *baseCompiler) installDir(ctx ModuleContext) android.InstallPath {
dir := compiler.dir
if ctx.toolchain().Is64Bit() && compiler.dir64 != "" {
diff --git a/rust/proc_macro.go b/rust/proc_macro.go
index 4eead32..c217959 100644
--- a/rust/proc_macro.go
+++ b/rust/proc_macro.go
@@ -82,3 +82,8 @@
func (procMacro *procMacroDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
return rlibAutoDep
}
+
+func (procMacro *procMacroDecorator) everInstallable() bool {
+ // Proc_macros are never installed
+ return false
+}
diff --git a/rust/rust.go b/rust/rust.go
index bb97142..f068b3d 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -97,6 +97,7 @@
PreventInstall bool
HideFromMake bool
+ Installable *bool
}
type Module struct {
@@ -143,6 +144,10 @@
mod.Properties.HideFromMake = true
}
+func (c *Module) HiddenFromMake() bool {
+ return c.Properties.HideFromMake
+}
+
func (mod *Module) SanitizePropDefined() bool {
// Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not
// nil since we need compiler to actually sanitize.
@@ -210,6 +215,38 @@
return false
}
+func (mod *Module) Dylib() bool {
+ if mod.compiler != nil {
+ if library, ok := mod.compiler.(libraryInterface); ok {
+ return library.dylib()
+ }
+ }
+ return false
+}
+
+func (mod *Module) Rlib() bool {
+ if mod.compiler != nil {
+ if library, ok := mod.compiler.(libraryInterface); ok {
+ return library.rlib()
+ }
+ }
+ return false
+}
+
+func (mod *Module) Binary() bool {
+ if mod.compiler != nil {
+ if _, ok := mod.compiler.(*binaryDecorator); ok {
+ return true
+ }
+ }
+ return false
+}
+
+func (mod *Module) Object() bool {
+ // Rust has no modules which produce only object files.
+ return false
+}
+
func (mod *Module) Toc() android.OptionalPath {
if mod.compiler != nil {
if _, ok := mod.compiler.(libraryInterface); ok {
@@ -223,12 +260,13 @@
return false
}
-// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
-// "product" and "vendor" variant modules return true for this function.
-// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
-// "soc_specific: true" and more vendor installed modules are included here.
-// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
-// "product_specific: true" modules are included here.
+func (mod *Module) RelativeInstallPath() string {
+ if mod.compiler != nil {
+ return mod.compiler.relativeInstallPath()
+ }
+ return ""
+}
+
func (mod *Module) UseVndk() bool {
return mod.Properties.VndkVersion != ""
}
@@ -250,6 +288,10 @@
return false
}
+func (mod *Module) IsVndkSp() bool {
+ return false
+}
+
func (c *Module) IsVndkPrivate() bool {
return false
}
@@ -274,6 +316,14 @@
return false
}
+func (mod *Module) HasLlndkStubs() bool {
+ return false
+}
+
+func (mod *Module) StubsVersion() string {
+ panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName()))
+}
+
func (mod *Module) SdkVersion() string {
return ""
}
@@ -362,6 +412,7 @@
inData() bool
install(ctx ModuleContext)
relativeInstallPath() string
+ everInstallable() bool
nativeCoverage() bool
@@ -423,8 +474,12 @@
return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
}
-func (mod *Module) PreventInstall() {
- mod.Properties.PreventInstall = true
+func (mod *Module) VndkVersion() string {
+ return mod.Properties.VndkVersion
+}
+
+func (mod *Module) PreventInstall() bool {
+ return mod.Properties.PreventInstall
}
func (mod *Module) HideFromMake() {
@@ -676,6 +731,16 @@
return mod.compiler != nil && mod.compiler.nativeCoverage()
}
+func (mod *Module) EverInstallable() bool {
+ return mod.compiler != nil &&
+ // Check to see whether the module is actually ever installable.
+ mod.compiler.everInstallable()
+}
+
+func (mod *Module) Installable() *bool {
+ return mod.Properties.Installable
+}
+
func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
if mod.cachedToolchain == nil {
mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
diff --git a/rust/sanitize.go b/rust/sanitize.go
index 0a53f98..3d14d51 100644
--- a/rust/sanitize.go
+++ b/rust/sanitize.go
@@ -189,6 +189,22 @@
}
}
+func (m *Module) UbsanRuntimeNeeded() bool {
+ return false
+}
+
+func (m *Module) MinimalRuntimeNeeded() bool {
+ return false
+}
+
+func (m *Module) UbsanRuntimeDep() bool {
+ return false
+}
+
+func (m *Module) MinimalRuntimeDep() bool {
+ return false
+}
+
// Check if the sanitizer is explicitly disabled (as opposed to nil by
// virtue of not being set).
func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t cc.SanitizerType) bool {
diff --git a/rust/snapshot_utils.go b/rust/snapshot_utils.go
new file mode 100644
index 0000000..e0ed1f7
--- /dev/null
+++ b/rust/snapshot_utils.go
@@ -0,0 +1,54 @@
+// Copyright 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "android/soong/android"
+)
+
+func (mod *Module) ExcludeFromVendorSnapshot() bool {
+ // TODO Rust does not yet support snapshotting
+ return true
+}
+
+func (mod *Module) ExcludeFromRecoverySnapshot() bool {
+ // TODO Rust does not yet support snapshotting
+ return true
+}
+
+func (mod *Module) IsSnapshotLibrary() bool {
+ // TODO Rust does not yet support snapshotting
+ return false
+}
+
+func (mod *Module) SnapshotRuntimeLibs() []string {
+ // TODO Rust does not yet support a runtime libs notion similar to CC
+ return []string{}
+}
+
+func (mod *Module) SnapshotSharedLibs() []string {
+ // TODO Rust does not yet support snapshotting
+ return []string{}
+}
+
+func (mod *Module) Symlinks() []string {
+ // TODO update this to return the list of symlinks when Rust supports defining symlinks
+ return nil
+}
+
+func (m *Module) SnapshotHeaders() android.Paths {
+ // TODO Rust does not yet support snapshotting
+ return android.Paths{}
+}
diff --git a/scripts/Android.bp b/scripts/Android.bp
index b0a8669..1c02bd0 100644
--- a/scripts/Android.bp
+++ b/scripts/Android.bp
@@ -265,22 +265,3 @@
"linker_config_proto",
],
}
-
-python_binary_host {
- name: "conv_classpaths_proto",
- srcs: [
- "conv_classpaths_proto.py",
- ],
- version: {
- py2: {
- enabled: false,
- },
- py3: {
- enabled: true,
- embedded_launcher: true,
- },
- },
- libs: [
- "classpaths_proto_python",
- ],
-}
diff --git a/scripts/conv_classpaths_proto.py b/scripts/conv_classpaths_proto.py
deleted file mode 100644
index f49fbbb..0000000
--- a/scripts/conv_classpaths_proto.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# Copyright (C) 2021 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import argparse
-
-import classpaths_pb2
-
-import google.protobuf.json_format as json_format
-import google.protobuf.text_format as text_format
-
-
-def encode(args):
- pb = classpaths_pb2.ExportedClasspathsJars()
- if args.format == 'json':
- json_format.Parse(args.input.read(), pb)
- else:
- text_format.Parse(args.input.read(), pb)
- args.output.write(pb.SerializeToString())
- args.input.close()
- args.output.close()
-
-
-def decode(args):
- pb = classpaths_pb2.ExportedClasspathsJars()
- pb.ParseFromString(args.input.read())
- if args.format == 'json':
- args.output.write(json_format.MessageToJson(pb))
- else:
- args.output.write(text_format.MessageToString(pb).encode('utf_8'))
- args.input.close()
- args.output.close()
-
-
-def main():
- parser = argparse.ArgumentParser('Convert classpaths.proto messages between binary and '
- 'human-readable formats.')
- parser.add_argument('-f', '--format', default='textproto',
- help='human-readable format, either json or text(proto), '
- 'defaults to textproto')
- parser.add_argument('-i', '--input',
- nargs='?', type=argparse.FileType('rb'), default=sys.stdin.buffer)
- parser.add_argument('-o', '--output',
- nargs='?', type=argparse.FileType('wb'),
- default=sys.stdout.buffer)
-
- subparsers = parser.add_subparsers()
-
- parser_encode = subparsers.add_parser('encode',
- help='convert classpaths protobuf message from '
- 'JSON to binary format',
- parents=[parser], add_help=False)
-
- parser_encode.set_defaults(func=encode)
-
- parser_decode = subparsers.add_parser('decode',
- help='print classpaths config in JSON format',
- parents=[parser], add_help=False)
- parser_decode.set_defaults(func=decode)
-
- args = parser.parse_args()
- args.func(args)
-
-
-if __name__ == '__main__':
- main()
diff --git a/sdk/Android.bp b/sdk/Android.bp
index 09a7286..368c03a 100644
--- a/sdk/Android.bp
+++ b/sdk/Android.bp
@@ -26,6 +26,7 @@
"compat_config_sdk_test.go",
"exports_test.go",
"java_sdk_test.go",
+ "license_sdk_test.go",
"sdk_test.go",
"testing.go",
],
diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go
index 0f2fd54..e91546e 100644
--- a/sdk/bootclasspath_fragment_sdk_test.go
+++ b/sdk/bootclasspath_fragment_sdk_test.go
@@ -95,9 +95,6 @@
prebuilt_apex {
name: "com.android.art",
src: "art.apex",
- exported_java_libs: [
- "mybootlib",
- ],
exported_bootclasspath_fragments: [
"mybootclasspathfragment",
],
diff --git a/sdk/bp.go b/sdk/bp.go
index 11ec8c6..e2dace8 100644
--- a/sdk/bp.go
+++ b/sdk/bp.go
@@ -25,6 +25,7 @@
type bpPropertySet struct {
properties map[string]interface{}
tags map[string]android.BpPropertyTag
+ comments map[string]string
order []string
}
@@ -133,10 +134,22 @@
return s.properties[name]
}
+func (s *bpPropertySet) getOptionalValue(name string) (interface{}, bool) {
+ value, ok := s.properties[name]
+ return value, ok
+}
+
func (s *bpPropertySet) getTag(name string) interface{} {
return s.tags[name]
}
+func (s *bpPropertySet) AddCommentForProperty(name, text string) {
+ if s.comments == nil {
+ s.comments = map[string]string{}
+ }
+ s.comments[name] = strings.TrimSpace(text)
+}
+
func (s *bpPropertySet) transformContents(transformer bpPropertyTransformer) {
var newOrder []string
for _, name := range s.order {
@@ -188,6 +201,12 @@
}
}
+func (s *bpPropertySet) removeProperty(name string) {
+ delete(s.properties, name)
+ delete(s.tags, name)
+ _, s.order = android.RemoveFromList(name, s.order)
+}
+
func (s *bpPropertySet) insertAfter(position string, name string, value interface{}) {
if s.properties[name] != nil {
panic("Property %q already exists in property set")
@@ -216,6 +235,19 @@
moduleType string
}
+func (m *bpModule) ModuleType() string {
+ return m.moduleType
+}
+
+func (m *bpModule) Name() string {
+ name, hasName := m.getOptionalValue("name")
+ if hasName {
+ return name.(string)
+ } else {
+ return ""
+ }
+}
+
var _ android.BpModule = (*bpModule)(nil)
type bpPropertyTransformer interface {
@@ -346,16 +378,26 @@
// is unique within this file.
func (f *bpFile) AddModule(module android.BpModule) {
m := module.(*bpModule)
- if name, ok := m.getValue("name").(string); ok {
- if f.modules[name] != nil {
- panic(fmt.Sprintf("Module %q already exists in bp file", name))
- }
-
- f.modules[name] = m
- f.order = append(f.order, m)
- } else {
- panic("Module does not have a name property, or it is not a string")
+ moduleType := module.ModuleType()
+ name := m.Name()
+ hasName := true
+ if name == "" {
+ // Use a prefixed module type as the name instead just in case this is something like a package
+ // of namespace module which does not require a name.
+ name = "#" + moduleType
+ hasName = false
}
+
+ if f.modules[name] != nil {
+ if hasName {
+ panic(fmt.Sprintf("Module %q already exists in bp file", name))
+ } else {
+ panic(fmt.Sprintf("Unnamed module type %q already exists in bp file", moduleType))
+ }
+ }
+
+ f.modules[name] = m
+ f.order = append(f.order, m)
}
func (f *bpFile) newModule(moduleType string) *bpModule {
diff --git a/sdk/license_sdk_test.go b/sdk/license_sdk_test.go
new file mode 100644
index 0000000..1ef6fe6
--- /dev/null
+++ b/sdk/license_sdk_test.go
@@ -0,0 +1,138 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package sdk
+
+import (
+ "testing"
+
+ "android/soong/android"
+)
+
+func TestSnapshotWithPackageDefaultLicense(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForSdkTestWithJava,
+ android.PrepareForTestWithLicenses,
+ android.PrepareForTestWithLicenseDefaultModules,
+ android.MockFS{
+ "NOTICE1": nil,
+ "NOTICE2": nil,
+ }.AddToFixture(),
+ ).RunTestWithBp(t, `
+ package {
+ default_applicable_licenses: ["mylicense"],
+ }
+
+ license {
+ name: "mylicense",
+ license_kinds: [
+ "SPDX-license-identifier-Apache-2.0",
+ "legacy_unencumbered",
+ ],
+ license_text: [
+ "NOTICE1",
+ "NOTICE2",
+ ],
+ }
+
+ sdk {
+ name: "mysdk",
+ java_header_libs: ["myjavalib"],
+ }
+
+ java_library {
+ name: "myjavalib",
+ srcs: ["Test.java"],
+ system_modules: "none",
+ sdk_version: "none",
+ }
+ `)
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+package {
+ // A default list here prevents the license LSC from adding its own list which would
+ // be unnecessary as every module in the sdk already has its own licenses property.
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+java_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ licenses: ["mysdk_mylicense"],
+ jars: ["java/myjavalib.jar"],
+}
+
+license {
+ name: "mysdk_mylicense",
+ visibility: ["//visibility:private"],
+ license_kinds: [
+ "SPDX-license-identifier-Apache-2.0",
+ "legacy_unencumbered",
+ ],
+ license_text: [
+ "licenses/NOTICE1",
+ "licenses/NOTICE2",
+ ],
+}
+ `),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+package {
+ // A default list here prevents the license LSC from adding its own list which would
+ // be unnecessary as every module in the sdk already has its own licenses property.
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+java_import {
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ licenses: ["mysdk_mylicense@current"],
+ jars: ["java/myjavalib.jar"],
+}
+
+license {
+ name: "mysdk_mylicense@current",
+ sdk_member_name: "mylicense",
+ visibility: ["//visibility:private"],
+ license_kinds: [
+ "SPDX-license-identifier-Apache-2.0",
+ "legacy_unencumbered",
+ ],
+ license_text: [
+ "licenses/NOTICE1",
+ "licenses/NOTICE2",
+ ],
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ visibility: ["//visibility:public"],
+ java_header_libs: ["mysdk_myjavalib@current"],
+}
+ `),
+ checkAllCopyRules(`
+.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/myjavalib.jar
+NOTICE1 -> licenses/NOTICE1
+NOTICE2 -> licenses/NOTICE2
+`),
+ )
+}
diff --git a/sdk/sdk.go b/sdk/sdk.go
index 624c0fa..b1c8aeb 100644
--- a/sdk/sdk.go
+++ b/sdk/sdk.go
@@ -169,23 +169,27 @@
var fields []reflect.StructField
// Iterate over the member types creating StructField and sdkMemberListProperty objects.
- for f, memberType := range sdkMemberTypes {
+ nextFieldIndex := 0
+ for _, memberType := range sdkMemberTypes {
+
p := memberType.SdkPropertyName()
- // Create a dynamic exported field for the member type's property.
- fields = append(fields, reflect.StructField{
- Name: proptools.FieldNameForProperty(p),
- Type: reflect.TypeOf([]string{}),
- Tag: `android:"arch_variant"`,
- })
+ var getter func(properties interface{}) []string
+ var setter func(properties interface{}, list []string)
+ if memberType.RequiresBpProperty() {
+ // Create a dynamic exported field for the member type's property.
+ fields = append(fields, reflect.StructField{
+ Name: proptools.FieldNameForProperty(p),
+ Type: reflect.TypeOf([]string{}),
+ Tag: `android:"arch_variant"`,
+ })
- // Copy the field index for use in the getter func as using the loop variable directly will
- // cause all funcs to use the last value.
- fieldIndex := f
+ // Copy the field index for use in the getter func as using the loop variable directly will
+ // cause all funcs to use the last value.
+ fieldIndex := nextFieldIndex
+ nextFieldIndex += 1
- // Create an sdkMemberListProperty for the member type.
- memberListProperty := &sdkMemberListProperty{
- getter: func(properties interface{}) []string {
+ getter = func(properties interface{}) []string {
// The properties is expected to be of the following form (where
// <Module_types> is the name of an SdkMemberType.SdkPropertyName().
// properties *struct {<Module_types> []string, ....}
@@ -195,9 +199,9 @@
//
list := reflect.ValueOf(properties).Elem().Field(fieldIndex).Interface().([]string)
return list
- },
+ }
- setter: func(properties interface{}, list []string) {
+ setter = func(properties interface{}, list []string) {
// The properties is expected to be of the following form (where
// <Module_types> is the name of an SdkMemberType.SdkPropertyName().
// properties *struct {<Module_types> []string, ....}
@@ -206,8 +210,13 @@
// *properties.<Module_types> = list
//
reflect.ValueOf(properties).Elem().Field(fieldIndex).Set(reflect.ValueOf(list))
- },
+ }
+ }
+ // Create an sdkMemberListProperty for the member type.
+ memberListProperty := &sdkMemberListProperty{
+ getter: getter,
+ setter: setter,
memberType: memberType,
// Dependencies added directly from member properties are always exported.
@@ -402,6 +411,9 @@
// Add dependencies from enabled and non CommonOS variants to the sdk member variants.
if s.Enabled() && !s.IsCommonOSVariant() {
for _, memberListProperty := range s.memberListProperties() {
+ if memberListProperty.getter == nil {
+ continue
+ }
names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
if len(names) > 0 {
tag := memberListProperty.dependencyTag
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index e9129e0..12545d6 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -525,4 +525,43 @@
`),
)
})
+
+ t.Run("SOONG_SDK_SNAPSHOT_PREFER=true", func(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ preparer,
+ android.FixtureMergeEnv(map[string]string{
+ "SOONG_SDK_SNAPSHOT_PREFER": "true",
+ }),
+ ).RunTest(t)
+
+ checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "mysdk_myjavalib@current",
+ sdk_member_name: "myjavalib",
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java/myjavalib.jar"],
+}
+
+java_import {
+ name: "myjavalib",
+ prefer: true,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java/myjavalib.jar"],
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ visibility: ["//visibility:public"],
+ java_header_libs: ["mysdk_myjavalib@current"],
+}
+ `),
+ )
+ })
}
diff --git a/sdk/update.go b/sdk/update.go
index 457cbd9..85dfc4a 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -29,6 +29,14 @@
"android/soong/android"
)
+// Environment variables that affect the generated snapshot
+// ========================================================
+//
+// SOONG_SDK_SNAPSHOT_PREFER
+// By default every unversioned module in the generated snapshot has prefer: false. Building it
+// with SOONG_SDK_SNAPSHOT_PREFER=true will force them to use prefer: true.
+//
+
var pctx = android.NewPackageContext("android/soong/sdk")
var (
@@ -220,6 +228,7 @@
allMembersByName := make(map[string]struct{})
exportedMembersByName := make(map[string]struct{})
+ hasLicenses := false
var memberVariantDeps []sdkMemberVariantDep
for _, sdkVariant := range sdkVariants {
memberVariantDeps = append(memberVariantDeps, sdkVariant.memberVariantDeps...)
@@ -233,6 +242,10 @@
if memberVariantDep.export {
exportedMembersByName[name] = struct{}{}
}
+
+ if memberVariantDep.memberType == android.LicenseModuleSdkMemberType {
+ hasLicenses = true
+ }
}
}
@@ -258,8 +271,27 @@
}
s.builderForTests = builder
- // Create the prebuilt modules for each of the member modules.
+ // If the sdk snapshot includes any license modules then add a package module which has a
+ // default_applicable_licenses property. That will prevent the LSC license process from updating
+ // the generated Android.bp file to add a package module that includes all licenses used by all
+ // the modules in that package. That would be unnecessary as every module in the sdk should have
+ // their own licenses property specified.
+ if hasLicenses {
+ pkg := bpFile.newModule("package")
+ property := "default_applicable_licenses"
+ pkg.AddCommentForProperty(property, `
+A default list here prevents the license LSC from adding its own list which would
+be unnecessary as every module in the sdk already has its own licenses property.
+`)
+ pkg.AddProperty(property, []string{"Android-Apache-2.0"})
+ bpFile.AddModule(pkg)
+ }
+
+ // Group the variants for each member module together and then group the members of each member
+ // type together.
members := s.groupMemberVariantsByMemberThenType(ctx, memberVariantDeps)
+
+ // Create the prebuilt modules for each of the member modules.
for _, member := range members {
memberType := member.memberType
@@ -274,7 +306,9 @@
// Create a transformer that will transform an unversioned module by replacing any references
// to internal members with a unique module name and setting prefer: false.
- unversionedTransformer := unversionedTransformation{builder: builder}
+ unversionedTransformer := unversionedTransformation{
+ builder: builder,
+ }
for _, unversioned := range builder.prebuiltOrder {
// Prune any empty property sets.
@@ -503,15 +537,19 @@
}
combined := sdkVariantToCombinedProperties[memberVariantDep.sdkVariant]
- memberTypeProperty := s.memberListProperty(memberVariantDep.memberType)
+ memberListProperty := s.memberListProperty(memberVariantDep.memberType)
memberName := ctx.OtherModuleName(memberVariantDep.variant)
+ if memberListProperty.getter == nil {
+ continue
+ }
+
// Append the member to the appropriate list, if it is not already present in the list.
- memberList := memberTypeProperty.getter(combined.dynamicProperties)
+ memberList := memberListProperty.getter(combined.dynamicProperties)
if !android.InList(memberName, memberList) {
memberList = append(memberList, memberName)
}
- memberTypeProperty.setter(combined.dynamicProperties, memberList)
+ memberListProperty.setter(combined.dynamicProperties, memberList)
}
return list
@@ -563,6 +601,9 @@
dynamicMemberTypeListProperties := combined.dynamicProperties
for _, memberListProperty := range s.memberListProperties() {
+ if memberListProperty.getter == nil {
+ continue
+ }
names := memberListProperty.getter(dynamicMemberTypeListProperties)
if len(names) > 0 {
propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false))
@@ -596,9 +637,11 @@
func (t unversionedToVersionedTransformation) transformModule(module *bpModule) *bpModule {
// Use a versioned name for the module but remember the original name for the
// snapshot.
- name := module.getValue("name").(string)
+ name := module.Name()
module.setProperty("name", t.builder.versionedSdkMemberName(name, true))
module.insertAfter("name", "sdk_member_name", name)
+ // Remove the prefer property if present as versioned modules never need marking with prefer.
+ module.removeProperty("prefer")
return module
}
@@ -618,12 +661,8 @@
func (t unversionedTransformation) transformModule(module *bpModule) *bpModule {
// If the module is an internal member then use a unique name for it.
- name := module.getValue("name").(string)
+ name := module.Name()
module.setProperty("name", t.builder.unversionedSdkMemberName(name, true))
-
- // Set prefer: false - this is not strictly required as that is the default.
- module.insertAfter("name", "prefer", false)
-
return module
}
@@ -674,12 +713,26 @@
func outputPropertySet(contents *generatedContents, set *bpPropertySet) {
contents.Indent()
+ addComment := func(name string) {
+ if text, ok := set.comments[name]; ok {
+ for _, line := range strings.Split(text, "\n") {
+ contents.Printfln("// %s", line)
+ }
+ }
+ }
+
// Output the properties first, followed by the nested sets. This ensures a
// consistent output irrespective of whether property sets are created before
// or after the properties. This simplifies the creation of the module.
for _, name := range set.order {
value := set.getValue(name)
+ // Do not write property sets in the properties phase.
+ if _, ok := value.(*bpPropertySet); ok {
+ continue
+ }
+
+ addComment(name)
switch v := value.(type) {
case []string:
length := len(v)
@@ -700,9 +753,6 @@
case bool:
contents.Printfln("%s: %t,", name, v)
- case *bpPropertySet:
- // Do not write property sets in the properties phase.
-
default:
contents.Printfln("%s: %q,", name, value)
}
@@ -714,6 +764,7 @@
// Only write property sets in the sets phase.
switch v := value.(type) {
case *bpPropertySet:
+ addComment(name)
contents.Printfln("%s: {", name)
outputPropertySet(contents, v)
contents.Printfln("},")
@@ -732,7 +783,9 @@
func (s *sdk) GetUnversionedAndroidBpContentsForTests() string {
contents := &generatedContents{}
generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool {
- return !strings.Contains(module.properties["name"].(string), "@")
+ name := module.Name()
+ // Include modules that are either unversioned or have no name.
+ return !strings.Contains(name, "@")
})
return contents.content.String()
}
@@ -740,7 +793,9 @@
func (s *sdk) GetVersionedAndroidBpContentsForTests() string {
contents := &generatedContents{}
generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool {
- return strings.Contains(module.properties["name"].(string), "@")
+ name := module.Name()
+ // Include modules that are either versioned or have no name.
+ return name == "" || strings.Contains(name, "@")
})
return contents.content.String()
}
@@ -859,6 +914,13 @@
m.AddProperty("apex_available", apexAvailable)
}
+ // The licenses are the same for all variants.
+ mctx := s.ctx
+ licenseInfo := mctx.OtherModuleProvider(variant, android.LicenseInfoProvider).(android.LicenseInfo)
+ if len(licenseInfo.Licenses) > 0 {
+ m.AddPropertyWithTag("licenses", licenseInfo.Licenses, s.OptionalSdkMemberReferencePropertyTag())
+ }
+
deviceSupported := false
hostSupported := false
@@ -886,6 +948,12 @@
}
func addHostDeviceSupportedProperties(deviceSupported bool, hostSupported bool, bpModule *bpModule) {
+ // If neither device or host is supported then this module does not support either so will not
+ // recognize the properties.
+ if !deviceSupported && !hostSupported {
+ return
+ }
+
if !deviceSupported {
bpModule.AddProperty("device_supported", false)
}
@@ -1362,6 +1430,21 @@
memberType := member.memberType
+ // Do not add the prefer property if the member snapshot module is a source module type.
+ if !memberType.UsesSourceModuleTypeInSnapshot() {
+ // Set the prefer based on the environment variable. This is a temporary work around to allow a
+ // snapshot to be created that sets prefer: true.
+ // TODO(b/174997203): Remove once the ability to select the modules to prefer can be done
+ // dynamically at build time not at snapshot generation time.
+ prefer := ctx.sdkMemberContext.Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER")
+
+ // Set prefer. Setting this to false is not strictly required as that is the default but it does
+ // provide a convenient hook to post-process the generated Android.bp file, e.g. in tests to
+ // check the behavior when a prebuilt is preferred. It also makes it explicit what the default
+ // behavior is for the module.
+ bpModule.insertAfter("name", "prefer", prefer)
+ }
+
// Group the variants by os type.
variantsByOsType := make(map[android.OsType][]android.Module)
variants := member.Variants()
diff --git a/third_party/zip/android_test.go b/third_party/zip/android_test.go
index 9932c1b..46588d4 100644
--- a/third_party/zip/android_test.go
+++ b/third_party/zip/android_test.go
@@ -140,3 +140,83 @@
t.Errorf("Expected UnompressedSize64 %d, got %d", w, g)
}
}
+
+// Test for b/187485108: zip64 output can't be read by p7zip 16.02.
+func TestZip64P7ZipRecords(t *testing.T) {
+ if testing.Short() {
+ t.Skip("slow test; skipping")
+ }
+
+ const size = uint32max + 1
+ zipBytes := &bytes.Buffer{}
+ zip := NewWriter(zipBytes)
+ f, err := zip.CreateHeaderAndroid(&FileHeader{
+ Name: "large",
+ Method: Store,
+ UncompressedSize64: size,
+ CompressedSize64: size,
+ })
+ if err != nil {
+ t.Fatalf("Create: %v", err)
+ }
+ _, err = f.Write(make([]byte, size))
+ if err != nil {
+ t.Fatalf("Write: %v", err)
+ }
+ err = zip.Close()
+ if err != nil {
+ t.Fatalf("Close: %v", err)
+ }
+
+ buf := zipBytes.Bytes()
+ p := findSignatureInBlock(buf)
+ if p < 0 {
+ t.Fatalf("Missing signature")
+ }
+
+ b := readBuf(buf[p+4:]) // skip signature
+ d := &directoryEnd{
+ diskNbr: uint32(b.uint16()),
+ dirDiskNbr: uint32(b.uint16()),
+ dirRecordsThisDisk: uint64(b.uint16()),
+ directoryRecords: uint64(b.uint16()),
+ directorySize: uint64(b.uint32()),
+ directoryOffset: uint64(b.uint32()),
+ commentLen: b.uint16(),
+ }
+
+ // p7zip 16.02 wants regular end record directoryRecords to be accurate.
+ if g, w := d.directoryRecords, uint64(1); g != w {
+ t.Errorf("wanted directoryRecords %d, got %d", w, g)
+ }
+
+ if g, w := d.directorySize, uint64(uint32max); g != w {
+ t.Errorf("wanted directorySize %d, got %d", w, g)
+ }
+
+ if g, w := d.directoryOffset, uint64(uint32max); g != w {
+ t.Errorf("wanted directoryOffset %d, got %d", w, g)
+ }
+
+ r := bytes.NewReader(buf)
+
+ p64, err := findDirectory64End(r, int64(p))
+ if err != nil {
+ t.Fatalf("findDirectory64End: %v", err)
+ }
+ if p < 0 {
+ t.Fatalf("findDirectory64End: not found")
+ }
+ err = readDirectory64End(r, p64, d)
+ if err != nil {
+ t.Fatalf("readDirectory64End: %v", err)
+ }
+
+ if g, w := d.directoryRecords, uint64(1); g != w {
+ t.Errorf("wanted directoryRecords %d, got %d", w, g)
+ }
+
+ if g, w := d.directoryOffset, uint64(uint32max); g <= w {
+ t.Errorf("wanted directoryOffset > %d, got %d", w, g)
+ }
+}
diff --git a/third_party/zip/writer.go b/third_party/zip/writer.go
index 8dd986e..f526838 100644
--- a/third_party/zip/writer.go
+++ b/third_party/zip/writer.go
@@ -155,7 +155,14 @@
// store max values in the regular end record to signal that
// that the zip64 values should be used instead
- records = uint16max
+ // BEGIN ANDROID CHANGE: only store uintmax for the number of entries in the regular
+ // end record if it doesn't fit. p7zip 16.02 rejects zip files where the number of
+ // entries in the regular end record is larger than the number of entries counted
+ // in the central directory.
+ if records > uint16max {
+ records = uint16max
+ }
+ // END ANDROID CHANGE
size = uint32max
offset = uint32max
}
diff --git a/zip/zip.go b/zip/zip.go
index 84e974b..6e412c9 100644
--- a/zip/zip.go
+++ b/zip/zip.go
@@ -656,9 +656,11 @@
UncompressedSize64: uint64(fileSize),
}
+ mode := os.FileMode(0600)
if executable {
- header.SetMode(0700)
+ mode = 0700
}
+ header.SetMode(mode)
err = createParentDirs(dest, src)
if err != nil {
diff --git a/zip/zip_test.go b/zip/zip_test.go
index a37ae41..441dea3 100644
--- a/zip/zip_test.go
+++ b/zip/zip_test.go
@@ -62,7 +62,7 @@
Method: method,
CRC32: crc32.ChecksumIEEE(contents),
UncompressedSize64: uint64(len(contents)),
- ExternalAttrs: 0,
+ ExternalAttrs: (syscall.S_IFREG | 0600) << 16,
}
}