Merge "Do not allow duplicate deapexer dependencies."
diff --git a/android/Android.bp b/android/Android.bp
index a20aedc..da36959 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -47,6 +47,7 @@
"image.go",
"license.go",
"license_kind.go",
+ "license_metadata.go",
"license_sdk_member.go",
"licenses.go",
"makefile_goal.go",
diff --git a/android/androidmk.go b/android/androidmk.go
index 0adc2a6..4f6e24c 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -474,6 +474,7 @@
ModuleDir(module blueprint.Module) string
Config() Config
ModuleProvider(module blueprint.Module, provider blueprint.ProviderKey) interface{}
+ ModuleHasProvider(module blueprint.Module, provider blueprint.ProviderKey) bool
}
func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) {
@@ -609,6 +610,11 @@
}
}
+ if ctx.ModuleHasProvider(mod, LicenseMetadataProvider) {
+ licenseMetadata := ctx.ModuleProvider(mod, LicenseMetadataProvider).(*LicenseMetadataInfo)
+ a.SetPath("LOCAL_SOONG_LICENSE_METADATA", licenseMetadata.LicenseMetadataPath)
+ }
+
extraCtx := &androidMkExtraEntriesContext{
ctx: ctx,
mod: mod,
@@ -887,6 +893,10 @@
return nil
}
+func ShouldSkipAndroidMkProcessing(module Module) bool {
+ return shouldSkipAndroidMkProcessing(module.base())
+}
+
func shouldSkipAndroidMkProcessing(module *ModuleBase) bool {
if !module.commonProperties.NamespaceExportedToMake {
// TODO(jeffrygaston) do we want to validate that there are no modules being
diff --git a/android/apex.go b/android/apex.go
index d5fd922..cf1bcfe 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -913,6 +913,7 @@
// ModuleWithMinSdkVersionCheck represents a module that implements min_sdk_version checks
type ModuleWithMinSdkVersionCheck interface {
Module
+ MinSdkVersion(ctx EarlyModuleContext) SdkSpec
CheckMinSdkVersion(ctx ModuleContext)
}
@@ -944,6 +945,14 @@
if am, ok := from.(DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
return false
}
+ if m, ok := to.(ModuleWithMinSdkVersionCheck); ok {
+ // This dependency performs its own min_sdk_version check, just make sure it sets min_sdk_version
+ // to trigger the check.
+ if !m.MinSdkVersion(ctx).Specified() {
+ ctx.OtherModuleErrorf(m, "must set min_sdk_version")
+ }
+ return false
+ }
if err := to.ShouldSupportSdkVersion(ctx, minSdkVersion); err != nil {
toName := ctx.OtherModuleName(to)
if ver, ok := minSdkVersionAllowlist[toName]; !ok || ver.GreaterThan(minSdkVersion) {
diff --git a/android/arch.go b/android/arch.go
index 3bf54b7..3cc5e82 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -566,6 +566,8 @@
return variants
}
+var DarwinUniversalVariantTag = archDepTag{name: "darwin universal binary"}
+
// archMutator splits a module into a variant for each Target requested by the module. Target selection
// for a module is in three levels, OsClass, multilib, and then Target.
// OsClass selection is determined by:
@@ -652,7 +654,7 @@
prefer32 := os == Windows
// Determine the multilib selection for this module.
- multilib, extraMultilib := decodeMultilib(base, os.Class)
+ multilib, extraMultilib := decodeMultilib(base, os)
// Convert the multilib selection into a list of Targets.
targets, err := decodeMultilibTargets(multilib, osTargets, prefer32)
@@ -702,6 +704,16 @@
m.base().commonProperties.SkipInstall = true
}
}
+
+ // Create a dependency for Darwin Universal binaries from the primary to secondary
+ // architecture. The module itself will be responsible for calling lipo to merge the outputs.
+ if os == Darwin {
+ if multilib == "darwin_universal" && len(modules) == 2 {
+ mctx.AddInterVariantDependency(DarwinUniversalVariantTag, modules[1], modules[0])
+ } else if multilib == "darwin_universal_common_first" && len(modules) == 3 {
+ mctx.AddInterVariantDependency(DarwinUniversalVariantTag, modules[2], modules[1])
+ }
+ }
}
// addTargetProperties annotates a variant with the Target is is being compiled for, the list
@@ -717,9 +729,9 @@
// multilib from the factory's call to InitAndroidArchModule if none was set. For modules that
// called InitAndroidMultiTargetsArchModule it always returns "common" for multilib, and returns
// the actual multilib in extraMultilib.
-func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) {
+func decodeMultilib(base *ModuleBase, os OsType) (multilib, extraMultilib string) {
// First check the "android.compile_multilib" or "host.compile_multilib" properties.
- switch class {
+ switch os.Class {
case Device:
multilib = String(base.commonProperties.Target.Android.Compile_multilib)
case Host:
@@ -737,6 +749,26 @@
}
if base.commonProperties.UseTargetVariants {
+ // Darwin has the concept of "universal binaries" which is implemented in Soong by
+ // building both x86_64 and arm64 variants, and having select module types know how to
+ // merge the outputs of their corresponding variants together into a final binary. Most
+ // module types don't need to understand this logic, as we only build a small portion
+ // of the tree for Darwin, and only module types writing macho files need to do the
+ // merging.
+ //
+ // This logic is not enabled for:
+ // "common", as it's not an arch-specific variant
+ // "32", as Darwin never has a 32-bit variant
+ // !UseTargetVariants, as the module has opted into handling the arch-specific logic on
+ // its own.
+ if os == Darwin && multilib != "common" && multilib != "32" {
+ if multilib == "common_first" {
+ multilib = "darwin_universal_common_first"
+ } else {
+ multilib = "darwin_universal"
+ }
+ }
+
return multilib, ""
} else {
// For app modules a single arch variant will be created per OS class which is expected to handle all the
@@ -1793,6 +1825,15 @@
if len(buildTargets) == 0 {
buildTargets = filterMultilibTargets(targets, "lib64")
}
+ case "darwin_universal":
+ buildTargets = filterMultilibTargets(targets, "lib64")
+ // Reverse the targets so that the first architecture can depend on the second
+ // architecture module in order to merge the outputs.
+ reverseSliceInPlace(buildTargets)
+ case "darwin_universal_common_first":
+ archTargets := filterMultilibTargets(targets, "lib64")
+ reverseSliceInPlace(archTargets)
+ buildTargets = append(getCommonTargets(targets), archTargets...)
default:
return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", "prefer32" or "first_prefer32" found %q`,
multilib)
diff --git a/android/bazel.go b/android/bazel.go
index 97f47be..169f6ba 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -461,11 +461,9 @@
"libprotobuf-cpp-full", "libprotobuf-cpp-lite", // Unsupported product&vendor suffix. b/204811222 and b/204810610.
// Depends on libprotobuf-cpp-*
- "libadb_crypto", "libadb_crypto_static", "libadb_pairing_connection",
+ "libadb_pairing_connection",
"libadb_pairing_connection_static",
"libadb_pairing_server", "libadb_pairing_server_static",
- "libadb_protos_static", "libadb_protos",
- "libapp_processes_protos_lite",
}
// Used for quicker lookups
diff --git a/android/config.go b/android/config.go
index 8e01e18..3ce59b2 100644
--- a/android/config.go
+++ b/android/config.go
@@ -892,8 +892,13 @@
return Bool(c.productVariables.Eng)
}
+// DevicePrimaryArchType returns the ArchType for the first configured device architecture, or
+// Common if there are no device architectures.
func (c *config) DevicePrimaryArchType() ArchType {
- return c.Targets[Android][0].Arch.ArchType
+ if androidTargets := c.Targets[Android]; len(androidTargets) > 0 {
+ return androidTargets[0].Arch.ArchType
+ }
+ return Common
}
func (c *config) SanitizeHost() []string {
@@ -1476,6 +1481,10 @@
return c.PlatformSepolicyVersion()
}
+func (c *deviceConfig) BoardPlatVendorPolicy() []string {
+ return c.config.productVariables.BoardPlatVendorPolicy
+}
+
func (c *deviceConfig) BoardReqdMaskPolicy() []string {
return c.config.productVariables.BoardReqdMaskPolicy
}
diff --git a/android/defaults.go b/android/defaults.go
index 9046002..d2b351d 100644
--- a/android/defaults.go
+++ b/android/defaults.go
@@ -89,10 +89,10 @@
var _ Defaultable = (*DefaultableModuleBase)(nil)
func InitDefaultableModule(module DefaultableModule) {
- if module.(Module).base().module == nil {
+ if module.base().module == nil {
panic("InitAndroidModule must be called before InitDefaultableModule")
}
- module.setProperties(module.(Module).GetProperties(), module.(Module).base().variableProperties)
+ module.setProperties(module.GetProperties(), module.base().variableProperties)
module.AddProperties(module.defaults())
diff --git a/android/license_metadata.go b/android/license_metadata.go
new file mode 100644
index 0000000..3bc53d6
--- /dev/null
+++ b/android/license_metadata.go
@@ -0,0 +1,231 @@
+// 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 (
+ "fmt"
+ "sort"
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+)
+
+var (
+ _ = pctx.HostBinToolVariable("licenseMetadataCmd", "build_license_metadata")
+
+ licenseMetadataRule = pctx.AndroidStaticRule("licenseMetadataRule", blueprint.RuleParams{
+ Command: "${licenseMetadataCmd} -o $out @${out}.rsp",
+ CommandDeps: []string{"${licenseMetadataCmd}"},
+ Rspfile: "${out}.rsp",
+ RspfileContent: "${args}",
+ }, "args")
+)
+
+func buildLicenseMetadata(ctx ModuleContext) {
+ base := ctx.Module().base()
+
+ if !base.Enabled() {
+ return
+ }
+
+ if exemptFromRequiredApplicableLicensesProperty(ctx.Module()) {
+ return
+ }
+
+ var allDepMetadataFiles Paths
+ var allDepMetadataArgs []string
+ var allDepOutputFiles Paths
+
+ ctx.VisitDirectDepsBlueprint(func(bpdep blueprint.Module) {
+ dep, _ := bpdep.(Module)
+ if dep == nil {
+ return
+ }
+ if !dep.Enabled() {
+ return
+ }
+
+ if ctx.OtherModuleHasProvider(dep, LicenseMetadataProvider) {
+ info := ctx.OtherModuleProvider(dep, LicenseMetadataProvider).(*LicenseMetadataInfo)
+ allDepMetadataFiles = append(allDepMetadataFiles, info.LicenseMetadataPath)
+
+ depAnnotations := licenseAnnotationsFromTag(ctx.OtherModuleDependencyTag(dep))
+
+ allDepMetadataArgs = append(allDepMetadataArgs, info.LicenseMetadataPath.String()+depAnnotations)
+
+ if depInstallFiles := dep.base().installFiles; len(depInstallFiles) > 0 {
+ allDepOutputFiles = append(allDepOutputFiles, depInstallFiles.Paths()...)
+ } else if depOutputFiles, err := outputFilesForModule(ctx, dep, ""); err == nil {
+ depOutputFiles = PathsIfNonNil(depOutputFiles...)
+ allDepOutputFiles = append(allDepOutputFiles, depOutputFiles...)
+ }
+ }
+ })
+
+ allDepMetadataFiles = SortedUniquePaths(allDepMetadataFiles)
+ sort.Strings(allDepMetadataArgs)
+ allDepOutputFiles = SortedUniquePaths(allDepOutputFiles)
+
+ var orderOnlyDeps Paths
+ var args []string
+
+ if t := ctx.ModuleType(); t != "" {
+ args = append(args,
+ "-mt "+proptools.NinjaAndShellEscape(t))
+ }
+
+ args = append(args,
+ "-r "+proptools.NinjaAndShellEscape(ctx.ModuleDir()),
+ "-mc UNKNOWN")
+
+ if p := base.commonProperties.Effective_package_name; p != nil {
+ args = append(args,
+ "-p "+proptools.NinjaAndShellEscape(*p))
+ }
+
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.commonProperties.Effective_license_kinds), "-k "))
+
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.commonProperties.Effective_license_conditions), "-c "))
+
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.commonProperties.Effective_license_text.Strings()), "-n "))
+
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(allDepMetadataArgs), "-d "))
+ orderOnlyDeps = append(orderOnlyDeps, allDepMetadataFiles...)
+
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(allDepOutputFiles.Strings()), "-s "))
+
+ // Install map
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.licenseInstallMap), "-m "))
+
+ // Built files
+ var outputFiles Paths
+ if outputFileProducer, ok := ctx.Module().(OutputFileProducer); ok {
+ outputFiles, _ = outputFileProducer.OutputFiles("")
+ outputFiles = PathsIfNonNil(outputFiles...)
+ }
+
+ if len(outputFiles) > 0 {
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(outputFiles.Strings()), "-t "))
+ } else {
+ args = append(args, fmt.Sprintf("-t //%s:%s", ctx.ModuleDir(), ctx.ModuleName()))
+ }
+
+ // Installed files
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.installFiles.Strings()), "-i "))
+
+ isContainer := isContainerFromFileExtensions(base.installFiles, outputFiles)
+ if isContainer {
+ args = append(args, "--is_container")
+ }
+
+ licenseMetadataFile := PathForModuleOut(ctx, "meta_lic")
+
+ ctx.Build(pctx, BuildParams{
+ Rule: licenseMetadataRule,
+ Output: licenseMetadataFile,
+ OrderOnly: orderOnlyDeps,
+ Description: "license metadata",
+ Args: map[string]string{
+ "args": strings.Join(args, " "),
+ },
+ })
+
+ ctx.SetProvider(LicenseMetadataProvider, &LicenseMetadataInfo{
+ LicenseMetadataPath: licenseMetadataFile,
+ })
+}
+
+func isContainerFromFileExtensions(installPaths InstallPaths, builtPaths Paths) bool {
+ var paths Paths
+ if len(installPaths) > 0 {
+ paths = installPaths.Paths()
+ } else {
+ paths = builtPaths
+ }
+
+ for _, path := range paths {
+ switch path.Ext() {
+ case ".zip", ".tar", ".tgz", ".tar.gz", ".img", ".srcszip", ".apex":
+ return true
+ }
+ }
+
+ return false
+}
+
+// LicenseMetadataProvider is used to propagate license metadata paths between modules.
+var LicenseMetadataProvider = blueprint.NewProvider(&LicenseMetadataInfo{})
+
+// LicenseMetadataInfo stores the license metadata path for a module.
+type LicenseMetadataInfo struct {
+ LicenseMetadataPath Path
+}
+
+// licenseAnnotationsFromTag returns the LicenseAnnotations for a tag (if any) converted into
+// a string, or an empty string if there are none.
+func licenseAnnotationsFromTag(tag blueprint.DependencyTag) string {
+ if annoTag, ok := tag.(LicenseAnnotationsDependencyTag); ok {
+ annos := annoTag.LicenseAnnotations()
+ if len(annos) > 0 {
+ annoStrings := make([]string, len(annos))
+ for i, s := range annos {
+ annoStrings[i] = string(s)
+ }
+ return ":" + strings.Join(annoStrings, ",")
+ }
+ }
+ return ""
+}
+
+// LicenseAnnotationsDependencyTag is implemented by dependency tags in order to provide a
+// list of license dependency annotations.
+type LicenseAnnotationsDependencyTag interface {
+ LicenseAnnotations() []LicenseAnnotation
+}
+
+// LicenseAnnotation is an enum of annotations that can be applied to dependencies for propagating
+// license information.
+type LicenseAnnotation string
+
+const (
+ // LicenseAnnotationSharedDependency should be returned by LicenseAnnotations implementations
+ // of dependency tags when the usage of the dependency is dynamic, for example a shared library
+ // linkage for native modules or as a classpath library for java modules.
+ LicenseAnnotationSharedDependency LicenseAnnotation = "dynamic"
+
+ // LicenseAnnotationToolchain should be returned by LicenseAnnotations implementations of
+ // dependency tags when the dependency is used as a toolchain.
+ //
+ // Dependency tags that need to always return LicenseAnnotationToolchain
+ // can embed LicenseAnnotationToolchainDependencyTag to implement LicenseAnnotations.
+ LicenseAnnotationToolchain LicenseAnnotation = "toolchain"
+)
+
+// LicenseAnnotationToolchainDependencyTag can be embedded in a dependency tag to implement
+// LicenseAnnotations that always returns LicenseAnnotationToolchain.
+type LicenseAnnotationToolchainDependencyTag struct{}
+
+func (LicenseAnnotationToolchainDependencyTag) LicenseAnnotations() []LicenseAnnotation {
+ return []LicenseAnnotation{LicenseAnnotationToolchain}
+}
diff --git a/android/module.go b/android/module.go
index b500f01..6c7fc65 100644
--- a/android/module.go
+++ b/android/module.go
@@ -419,7 +419,6 @@
PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec
CheckbuildFile(srcPath Path)
- TidyFile(srcPath WritablePath)
InstallInData() bool
InstallInTestcases() bool
@@ -1200,7 +1199,6 @@
installFiles InstallPaths
installFilesDepSet *installPathsDepSet
checkbuildFiles Paths
- tidyFiles WritablePaths
packagingSpecs []PackagingSpec
packagingSpecsDepSet *packagingSpecsDepSet
noticeFiles Paths
@@ -1216,7 +1214,6 @@
// Only set on the final variant of each module
installTarget WritablePath
checkbuildTarget WritablePath
- tidyTarget WritablePath
blueprintDir string
hooks hooks
@@ -1230,6 +1227,10 @@
initRcPaths Paths
vintfFragmentsPaths Paths
+
+ // set of dependency module:location mappings used to populate the license metadata for
+ // apex containers.
+ licenseInstallMap []string
}
// A struct containing all relevant information about a Bazel target converted via bp2build.
@@ -1776,20 +1777,24 @@
return append(Paths{}, m.vintfFragmentsPaths...)
}
+// SetLicenseInstallMap stores the set of dependency module:location mappings for files in an
+// apex container for use when generation the license metadata file.
+func (m *ModuleBase) SetLicenseInstallMap(installMap []string) {
+ m.licenseInstallMap = append(m.licenseInstallMap, installMap...)
+}
+
func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
var allInstalledFiles InstallPaths
var allCheckbuildFiles Paths
- var allTidyFiles WritablePaths
ctx.VisitAllModuleVariants(func(module Module) {
a := module.base()
allInstalledFiles = append(allInstalledFiles, a.installFiles...)
- // A module's -{checkbuild,tidy} phony targets should
+ // A module's -checkbuild phony targets should
// not be created if the module is not exported to make.
// Those could depend on the build target and fail to compile
// for the current build target.
if !ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(a) {
allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
- allTidyFiles = append(allTidyFiles, a.tidyFiles...)
}
})
@@ -1814,13 +1819,6 @@
deps = append(deps, m.checkbuildTarget)
}
- if len(allTidyFiles) > 0 {
- name := namespacePrefix + ctx.ModuleName() + "-tidy"
- ctx.Phony(name, allTidyFiles.Paths()...)
- m.tidyTarget = PathForPhony(ctx, name)
- deps = append(deps, m.tidyTarget)
- }
-
if len(deps) > 0 {
suffix := ""
if ctx.Config().KatiEnabled() {
@@ -2029,7 +2027,6 @@
m.installFiles = append(m.installFiles, ctx.installFiles...)
m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
- m.tidyFiles = append(m.tidyFiles, ctx.tidyFiles...)
m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
m.katiInstalls = append(m.katiInstalls, ctx.katiInstalls...)
m.katiSymlinks = append(m.katiSymlinks, ctx.katiSymlinks...)
@@ -2051,6 +2048,8 @@
m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles)
m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs)
+ buildLicenseMetadata(ctx)
+
m.buildParams = ctx.buildParams
m.ruleParams = ctx.ruleParams
m.variables = ctx.variables
@@ -2227,7 +2226,6 @@
packagingSpecs []PackagingSpec
installFiles InstallPaths
checkbuildFiles Paths
- tidyFiles WritablePaths
module Module
phonies map[string]Paths
@@ -3065,10 +3063,6 @@
m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
}
-func (m *moduleContext) TidyFile(srcPath WritablePath) {
- m.tidyFiles = append(m.tidyFiles, srcPath)
-}
-
func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
return m.bp
}
@@ -3327,9 +3321,10 @@
type buildTargetSingleton struct{}
-func addAncestors(ctx SingletonContext, dirMap map[string]Paths, mmName func(string) string) []string {
+func AddAncestors(ctx SingletonContext, dirMap map[string]Paths, mmName func(string) string) ([]string, []string) {
// Ensure ancestor directories are in dirMap
// Make directories build their direct subdirectories
+ // Returns a slice of all directories and a slice of top-level directories.
dirs := SortedStringKeys(dirMap)
for _, dir := range dirs {
dir := parentDir(dir)
@@ -3342,34 +3337,31 @@
}
}
dirs = SortedStringKeys(dirMap)
+ var topDirs []string
for _, dir := range dirs {
p := parentDir(dir)
if p != "." && p != "/" {
dirMap[p] = append(dirMap[p], PathForPhony(ctx, mmName(dir)))
+ } else if dir != "." && dir != "/" && dir != "" {
+ topDirs = append(topDirs, dir)
}
}
- return SortedStringKeys(dirMap)
+ return SortedStringKeys(dirMap), topDirs
}
func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
var checkbuildDeps Paths
- var tidyDeps Paths
mmTarget := func(dir string) string {
return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
}
- mmTidyTarget := func(dir string) string {
- return "tidy-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
- }
modulesInDir := make(map[string]Paths)
- tidyModulesInDir := make(map[string]Paths)
ctx.VisitAllModules(func(module Module) {
blueprintDir := module.base().blueprintDir
installTarget := module.base().installTarget
checkbuildTarget := module.base().checkbuildTarget
- tidyTarget := module.base().tidyTarget
if checkbuildTarget != nil {
checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
@@ -3379,16 +3371,6 @@
if installTarget != nil {
modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
}
-
- if tidyTarget != nil {
- tidyDeps = append(tidyDeps, tidyTarget)
- // tidyTarget is in modulesInDir so it will be built with "mm".
- modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], tidyTarget)
- // tidyModulesInDir contains tidyTarget but not checkbuildTarget
- // or installTarget, so tidy targets in a directory can be built
- // without other checkbuild or install targets.
- tidyModulesInDir[blueprintDir] = append(tidyModulesInDir[blueprintDir], tidyTarget)
- }
})
suffix := ""
@@ -3399,24 +3381,12 @@
// Create a top-level checkbuild target that depends on all modules
ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
- // Create a top-level tidy target that depends on all modules
- ctx.Phony("tidy"+suffix, tidyDeps...)
-
- dirs := addAncestors(ctx, tidyModulesInDir, mmTidyTarget)
-
- // Kati does not generate tidy-* phony targets yet.
- // Create a tidy-<directory> target that depends on all subdirectories
- // and modules in the directory.
- for _, dir := range dirs {
- ctx.Phony(mmTidyTarget(dir), tidyModulesInDir[dir]...)
- }
-
// Make will generate the MODULES-IN-* targets
if ctx.Config().KatiEnabled() {
return
}
- dirs = addAncestors(ctx, modulesInDir, mmTarget)
+ dirs, _ := AddAncestors(ctx, modulesInDir, mmTarget)
// Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
// depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
diff --git a/android/neverallow.go b/android/neverallow.go
index b36bf04..0348619 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -252,7 +252,7 @@
continue
}
- if !n.appliesToProperties(properties) {
+ if !n.appliesToProperties(ctx, properties) {
continue
}
@@ -272,8 +272,12 @@
}
}
+type ValueMatcherContext interface {
+ Config() Config
+}
+
type ValueMatcher interface {
- Test(string) bool
+ Test(ValueMatcherContext, string) bool
String() string
}
@@ -281,7 +285,7 @@
expected string
}
-func (m *equalMatcher) Test(value string) bool {
+func (m *equalMatcher) Test(ctx ValueMatcherContext, value string) bool {
return m.expected == value
}
@@ -292,7 +296,7 @@
type anyMatcher struct {
}
-func (m *anyMatcher) Test(value string) bool {
+func (m *anyMatcher) Test(ctx ValueMatcherContext, value string) bool {
return true
}
@@ -306,7 +310,7 @@
prefix string
}
-func (m *startsWithMatcher) Test(value string) bool {
+func (m *startsWithMatcher) Test(ctx ValueMatcherContext, value string) bool {
return strings.HasPrefix(value, m.prefix)
}
@@ -318,7 +322,7 @@
re *regexp.Regexp
}
-func (m *regexMatcher) Test(value string) bool {
+func (m *regexMatcher) Test(ctx ValueMatcherContext, value string) bool {
return m.re.MatchString(value)
}
@@ -330,7 +334,7 @@
allowed []string
}
-func (m *notInListMatcher) Test(value string) bool {
+func (m *notInListMatcher) Test(ctx ValueMatcherContext, value string) bool {
return !InList(value, m.allowed)
}
@@ -340,7 +344,7 @@
type isSetMatcher struct{}
-func (m *isSetMatcher) Test(value string) bool {
+func (m *isSetMatcher) Test(ctx ValueMatcherContext, value string) bool {
return value != ""
}
@@ -350,6 +354,19 @@
var isSetMatcherInstance = &isSetMatcher{}
+type sdkVersionMatcher struct {
+ condition func(ctx ValueMatcherContext, spec SdkSpec) bool
+ description string
+}
+
+func (m *sdkVersionMatcher) Test(ctx ValueMatcherContext, value string) bool {
+ return m.condition(ctx, SdkSpecFromWithConfig(ctx.Config(), value))
+}
+
+func (m *sdkVersionMatcher) String() string {
+ return ".sdk-version(" + m.description + ")"
+}
+
type ruleProperty struct {
fields []string // e.x.: Vndk.Enabled
matcher ValueMatcher
@@ -563,9 +580,10 @@
return (len(r.moduleTypes) == 0 || InList(moduleType, r.moduleTypes)) && !InList(moduleType, r.unlessModuleTypes)
}
-func (r *rule) appliesToProperties(properties []interface{}) bool {
- includeProps := hasAllProperties(properties, r.props)
- excludeProps := hasAnyProperty(properties, r.unlessProps)
+func (r *rule) appliesToProperties(ctx ValueMatcherContext,
+ properties []interface{}) bool {
+ includeProps := hasAllProperties(ctx, properties, r.props)
+ excludeProps := hasAnyProperty(ctx, properties, r.unlessProps)
return includeProps && !excludeProps
}
@@ -585,6 +603,16 @@
return ¬InListMatcher{allowed}
}
+func LessThanSdkVersion(sdk string) ValueMatcher {
+ return &sdkVersionMatcher{
+ condition: func(ctx ValueMatcherContext, spec SdkSpec) bool {
+ return spec.ApiLevel.LessThan(
+ SdkSpecFromWithConfig(ctx.Config(), sdk).ApiLevel)
+ },
+ description: "lessThan=" + sdk,
+ }
+}
+
// assorted utils
func cleanPaths(paths []string) []string {
@@ -603,25 +631,28 @@
return names
}
-func hasAnyProperty(properties []interface{}, props []ruleProperty) bool {
+func hasAnyProperty(ctx ValueMatcherContext, properties []interface{},
+ props []ruleProperty) bool {
for _, v := range props {
- if hasProperty(properties, v) {
+ if hasProperty(ctx, properties, v) {
return true
}
}
return false
}
-func hasAllProperties(properties []interface{}, props []ruleProperty) bool {
+func hasAllProperties(ctx ValueMatcherContext, properties []interface{},
+ props []ruleProperty) bool {
for _, v := range props {
- if !hasProperty(properties, v) {
+ if !hasProperty(ctx, properties, v) {
return false
}
}
return true
}
-func hasProperty(properties []interface{}, prop ruleProperty) bool {
+func hasProperty(ctx ValueMatcherContext, properties []interface{},
+ prop ruleProperty) bool {
for _, propertyStruct := range properties {
propertiesValue := reflect.ValueOf(propertyStruct).Elem()
for _, v := range prop.fields {
@@ -635,7 +666,7 @@
}
check := func(value string) bool {
- return prop.matcher.Test(value)
+ return prop.matcher.Test(ctx, value)
}
if matchValue(propertiesValue, check) {
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index edda244..18a8705 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -296,6 +296,48 @@
"Only boot images and seapp contexts may be imported as a makefile goal.",
},
},
+ {
+ name: "min_sdk too low",
+ fs: map[string][]byte{
+ "Android.bp": []byte(`
+ java_library {
+ name: "min_sdk_too_low",
+ min_sdk_version: "30",
+ }`),
+ },
+ rules: []Rule{
+ NeverAllow().WithMatcher("min_sdk_version", LessThanSdkVersion("31")),
+ },
+ expectedErrors: []string{
+ "module \"min_sdk_too_low\": violates neverallow",
+ },
+ },
+ {
+ name: "min_sdk high enough",
+ fs: map[string][]byte{
+ "Android.bp": []byte(`
+ java_library {
+ name: "min_sdk_high_enough",
+ min_sdk_version: "31",
+ }`),
+ },
+ rules: []Rule{
+ NeverAllow().WithMatcher("min_sdk_version", LessThanSdkVersion("31")),
+ },
+ },
+ {
+ name: "current min_sdk high enough",
+ fs: map[string][]byte{
+ "Android.bp": []byte(`
+ java_library {
+ name: "current_min_sdk_high_enough",
+ min_sdk_version: "current",
+ }`),
+ },
+ rules: []Rule{
+ NeverAllow().WithMatcher("min_sdk_version", LessThanSdkVersion("31")),
+ },
+ },
}
var prepareForNeverAllowTest = GroupFixturePreparers(
@@ -379,9 +421,10 @@
}
type mockJavaLibraryProperties struct {
- Libs []string
- Sdk_version *string
- Uncompress_dex *bool
+ Libs []string
+ Min_sdk_version *string
+ Sdk_version *string
+ Uncompress_dex *bool
}
type mockJavaLibraryModule struct {
diff --git a/android/package_ctx.go b/android/package_ctx.go
index c19debb..f354db8 100644
--- a/android/package_ctx.go
+++ b/android/package_ctx.go
@@ -19,6 +19,7 @@
"strings"
"github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
"android/soong/remoteexec"
)
@@ -173,7 +174,7 @@
// package-scoped variable's initialization.
func (p PackageContext) HostBinToolVariable(name, path string) blueprint.Variable {
return p.VariableFunc(name, func(ctx PackageVarContext) string {
- return ctx.Config().HostToolPath(ctx, path).String()
+ return proptools.NinjaAndShellEscape(ctx.Config().HostToolPath(ctx, path).String())
})
}
@@ -183,7 +184,7 @@
// package-scoped variable's initialization.
func (p PackageContext) HostJNIToolVariable(name, path string) blueprint.Variable {
return p.VariableFunc(name, func(ctx PackageVarContext) string {
- return ctx.Config().HostJNIToolPath(ctx, path).String()
+ return proptools.NinjaAndShellEscape(ctx.Config().HostJNIToolPath(ctx, path).String())
})
}
@@ -193,7 +194,7 @@
// part of a package-scoped variable's initialization.
func (p PackageContext) HostJavaToolVariable(name, path string) blueprint.Variable {
return p.VariableFunc(name, func(ctx PackageVarContext) string {
- return ctx.Config().HostJavaToolPath(ctx, path).String()
+ return proptools.NinjaAndShellEscape(ctx.Config().HostJavaToolPath(ctx, path).String())
})
}
diff --git a/android/variable.go b/android/variable.go
index 158d264..a7068108 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -347,6 +347,7 @@
BoardVendorSepolicyDirs []string `json:",omitempty"`
BoardOdmSepolicyDirs []string `json:",omitempty"`
BoardReqdMaskPolicy []string `json:",omitempty"`
+ BoardPlatVendorPolicy []string `json:",omitempty"`
SystemExtPublicSepolicyDirs []string `json:",omitempty"`
SystemExtPrivateSepolicyDirs []string `json:",omitempty"`
BoardSepolicyM4Defs []string `json:",omitempty"`
diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go
index ca40aaa..a2d6992 100644
--- a/androidmk/androidmk/androidmk_test.go
+++ b/androidmk/androidmk/androidmk_test.go
@@ -1537,9 +1537,11 @@
},
{
desc: "LOCAL_LICENSE_KINDS, LOCAL_LICENSE_CONDITIONS, LOCAL_NOTICE_FILE",
- // TODO(b/205615944): When valid "android_license_files" exists, the test requires an Android.mk
- // file (and an Android.bp file is required as well if the license files locates outside the current
- // directory). So plan to use a mock file system to mock the Android.mk and Android.bp files.
+ // When "android_license_files" is valid, the test requires an Android.mk file
+ // outside the current (and an Android.bp file is required as well if the license
+ // files locates directory), thus a mock file system is needed. The integration
+ // test cases for these scenarios have been added in
+ // $(ANDROID_BUILD_TOP)/build/soong/tests/androidmk_test.sh.
in: `
include $(CLEAR_VARS)
LOCAL_MODULE := foo
diff --git a/apex/androidmk.go b/apex/androidmk.go
index 7764b6b..f001fa2 100644
--- a/apex/androidmk.go
+++ b/apex/androidmk.go
@@ -309,19 +309,17 @@
return moduleNames
}
-func (a *apexBundle) writeRequiredModules(w io.Writer, apexBundleName string) {
+func (a *apexBundle) writeRequiredModules(w io.Writer) {
var required []string
var targetRequired []string
var hostRequired []string
required = append(required, a.RequiredModuleNames()...)
targetRequired = append(targetRequired, a.TargetRequiredModuleNames()...)
hostRequired = append(hostRequired, a.HostRequiredModuleNames()...)
- installMapSet := make(map[string]bool) // set of dependency module:location mappings
for _, fi := range a.filesInfo {
required = append(required, fi.requiredModuleNames...)
targetRequired = append(targetRequired, fi.targetRequiredModuleNames...)
hostRequired = append(hostRequired, fi.hostRequiredModuleNames...)
- installMapSet[a.fullModuleName(apexBundleName, &fi)+":"+fi.installDir+"/"+fi.builtFile.Base()] = true
}
if len(required) > 0 {
@@ -333,11 +331,6 @@
if len(hostRequired) > 0 {
fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES +=", strings.Join(hostRequired, " "))
}
- if len(installMapSet) > 0 {
- var installs []string
- installs = append(installs, android.SortedStringKeys(installMapSet)...)
- fmt.Fprintln(w, "LOCAL_LICENSE_INSTALL_MAP +=", strings.Join(installs, " "))
- }
}
func (a *apexBundle) androidMkForType() android.AndroidMkData {
@@ -359,7 +352,7 @@
if len(moduleNames) > 0 {
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
}
- a.writeRequiredModules(w, name)
+ a.writeRequiredModules(w)
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
} else {
@@ -401,7 +394,7 @@
if len(a.requiredDeps) > 0 {
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.requiredDeps, " "))
}
- a.writeRequiredModules(w, name)
+ a.writeRequiredModules(w)
if a.mergedNotices.Merged.Valid() {
fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", a.mergedNotices.Merged.Path().String())
diff --git a/apex/apex.go b/apex/apex.go
index 4ecb104..e5cee72 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -2015,6 +2015,8 @@
}
} else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
// nothing
+ } else if depTag == android.DarwinUniversalVariantTag {
+ // nothing
} else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
}
@@ -2346,6 +2348,8 @@
//
// TODO(jiyong): move these checks to a separate go file.
+var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
+
// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
// of this apexBundle.
func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
@@ -2357,7 +2361,15 @@
android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
}
-func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
+func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpec{
+ Kind: android.SdkNone,
+ ApiLevel: a.minSdkVersion(ctx),
+ Raw: String(a.properties.Min_sdk_version),
+ }
+}
+
+func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
ver := proptools.String(a.properties.Min_sdk_version)
if ver == "" {
return android.NoneApiLevel
@@ -3188,15 +3200,16 @@
BootclasspathJar().
With("apex_available", module_name).
WithMatcher("permitted_packages", android.NotInList(module_packages)).
+ WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Because("jars that are part of the " + module_name +
" module may only allow these packages: " + strings.Join(module_packages, ",") +
- ". Please jarjar or move code around.")
+ " with min_sdk < T. Please jarjar or move code around.")
rules = append(rules, permittedPackagesRule)
}
return rules
}
-// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
+// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART on Q/R/S.
// Adding code to the bootclasspath in new packages will cause issues on module update.
func qModulesPackages() map[string][]string {
return map[string][]string{
@@ -3210,7 +3223,7 @@
}
}
-// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
+// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART on R/S.
// Adding code to the bootclasspath in new packages will cause issues on module update.
func rModulesPackages() map[string][]string {
return map[string][]string{
@@ -3257,7 +3270,7 @@
Updatable bazel.BoolAttribute
Installable bazel.BoolAttribute
Native_shared_libs bazel.LabelListAttribute
- Binaries bazel.StringListAttribute
+ Binaries bazel.LabelListAttribute
Prebuilts bazel.LabelListAttribute
}
@@ -3316,8 +3329,8 @@
prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
- binaries := module.properties.ApexNativeDependencies.Binaries
- binariesStringListAttribute := bazel.MakeStringListAttribute(binaries)
+ binaries := android.BazelLabelForModuleDeps(ctx, module.properties.ApexNativeDependencies.Binaries)
+ binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
var updatableAttribute bazel.BoolAttribute
if module.properties.Updatable != nil {
@@ -3339,7 +3352,7 @@
Updatable: updatableAttribute,
Installable: installableAttribute,
Native_shared_libs: nativeSharedLibsLabelListAttribute,
- Binaries: binariesStringListAttribute,
+ Binaries: binariesLabelListAttribute,
Prebuilts: prebuiltsLabelListAttribute,
}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 387dbc1..c71b6d0 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -7428,6 +7428,7 @@
apex_available: ["myapex"],
sdk_version: "none",
system_modules: "none",
+ min_sdk_version: "30",
}
java_library {
name: "nonbcp_lib2",
@@ -7436,9 +7437,11 @@
permitted_packages: ["a.b"],
sdk_version: "none",
system_modules: "none",
+ min_sdk_version: "30",
}
apex {
name: "myapex",
+ min_sdk_version: "30",
key: "myapex.key",
java_libs: ["bcp_lib1", "nonbcp_lib2"],
updatable: false,
@@ -7451,8 +7454,8 @@
},
},
{
- name: "Bootclasspath apex jar not satisfying allowed module packages.",
- expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar. Please jarjar or move code around.`,
+ name: "Bootclasspath apex jar not satisfying allowed module packages on Q.",
+ expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar with min_sdk < T. Please jarjar or move code around.`,
bp: `
java_library {
name: "bcp_lib1",
@@ -7461,6 +7464,7 @@
permitted_packages: ["foo.bar"],
sdk_version: "none",
system_modules: "none",
+ min_sdk_version: "29",
}
java_library {
name: "bcp_lib2",
@@ -7469,9 +7473,85 @@
permitted_packages: ["foo.bar", "bar.baz"],
sdk_version: "none",
system_modules: "none",
+ min_sdk_version: "29",
}
apex {
name: "myapex",
+ min_sdk_version: "29",
+ key: "myapex.key",
+ java_libs: ["bcp_lib1", "bcp_lib2"],
+ updatable: false,
+ }
+ `,
+ bootJars: []string{"bcp_lib1", "bcp_lib2"},
+ modulesPackages: map[string][]string{
+ "myapex": []string{
+ "foo.bar",
+ },
+ },
+ },
+ {
+ name: "Bootclasspath apex jar not satisfying allowed module packages on R.",
+ expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar with min_sdk < T. Please jarjar or move code around.`,
+ bp: `
+ java_library {
+ name: "bcp_lib1",
+ srcs: ["lib1/src/*.java"],
+ apex_available: ["myapex"],
+ permitted_packages: ["foo.bar"],
+ sdk_version: "none",
+ system_modules: "none",
+ min_sdk_version: "30",
+ }
+ java_library {
+ name: "bcp_lib2",
+ srcs: ["lib2/src/*.java"],
+ apex_available: ["myapex"],
+ permitted_packages: ["foo.bar", "bar.baz"],
+ sdk_version: "none",
+ system_modules: "none",
+ min_sdk_version: "30",
+ }
+ apex {
+ name: "myapex",
+ min_sdk_version: "30",
+ key: "myapex.key",
+ java_libs: ["bcp_lib1", "bcp_lib2"],
+ updatable: false,
+ }
+ `,
+ bootJars: []string{"bcp_lib1", "bcp_lib2"},
+ modulesPackages: map[string][]string{
+ "myapex": []string{
+ "foo.bar",
+ },
+ },
+ },
+ {
+ name: "Bootclasspath apex jar >= T not satisfying Q/R/S allowed module packages.",
+ expectedError: "",
+ bp: `
+ java_library {
+ name: "bcp_lib1",
+ srcs: ["lib1/src/*.java"],
+ apex_available: ["myapex"],
+ permitted_packages: ["foo.bar"],
+ sdk_version: "none",
+ system_modules: "none",
+ min_sdk_version: "current",
+ }
+ java_library {
+ name: "bcp_lib2",
+ srcs: ["lib2/src/*.java"],
+ apex_available: ["myapex"],
+ permitted_packages: ["foo.bar", "bar.baz"],
+ sdk_version: "none",
+ system_modules: "none",
+ min_sdk_version: "current",
+ }
+ apex {
+ name: "myapex",
+ min_sdk_version: "current",
key: "myapex.key",
java_libs: ["bcp_lib1", "bcp_lib2"],
updatable: false,
@@ -8479,6 +8559,184 @@
ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherapex")
}
+func TestSdkLibraryCanHaveHigherMinSdkVersion(t *testing.T) {
+ preparer := android.GroupFixturePreparers(
+ PrepareForTestWithApexBuildComponents,
+ prepareForTestWithMyapex,
+ java.PrepareForTestWithJavaSdkLibraryFiles,
+ java.PrepareForTestWithJavaDefaultModules,
+ android.PrepareForTestWithAndroidBuildComponents,
+ dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"),
+ dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"),
+ )
+
+ // Test java_sdk_library in bootclasspath_fragment may define higher min_sdk_version than the apex
+ t.Run("bootclasspath_fragment jar has higher min_sdk_version than apex", func(t *testing.T) {
+ preparer.RunTestWithBp(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ bootclasspath_fragments: ["mybootclasspathfragment"],
+ min_sdk_version: "30",
+ updatable: false,
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ bootclasspath_fragment {
+ name: "mybootclasspathfragment",
+ contents: ["mybootclasspathlib"],
+ apex_available: ["myapex"],
+ }
+
+ java_sdk_library {
+ name: "mybootclasspathlib",
+ srcs: ["mybootclasspathlib.java"],
+ apex_available: ["myapex"],
+ compile_dex: true,
+ unsafe_ignore_missing_latest_api: true,
+ min_sdk_version: "31",
+ static_libs: ["util"],
+ }
+
+ java_library {
+ name: "util",
+ srcs: ["a.java"],
+ apex_available: ["myapex"],
+ min_sdk_version: "31",
+ static_libs: ["another_util"],
+ }
+
+ java_library {
+ name: "another_util",
+ srcs: ["a.java"],
+ min_sdk_version: "31",
+ apex_available: ["myapex"],
+ }
+ `)
+ })
+
+ // Test java_sdk_library in systemserverclasspath_fragment may define higher min_sdk_version than the apex
+ t.Run("systemserverclasspath_fragment jar has higher min_sdk_version than apex", func(t *testing.T) {
+ preparer.RunTestWithBp(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
+ min_sdk_version: "30",
+ updatable: false,
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ systemserverclasspath_fragment {
+ name: "mysystemserverclasspathfragment",
+ contents: ["mysystemserverclasspathlib"],
+ apex_available: ["myapex"],
+ }
+
+ java_sdk_library {
+ name: "mysystemserverclasspathlib",
+ srcs: ["mysystemserverclasspathlib.java"],
+ apex_available: ["myapex"],
+ compile_dex: true,
+ min_sdk_version: "32",
+ unsafe_ignore_missing_latest_api: true,
+ static_libs: ["util"],
+ }
+
+ java_library {
+ name: "util",
+ srcs: ["a.java"],
+ apex_available: ["myapex"],
+ min_sdk_version: "31",
+ static_libs: ["another_util"],
+ }
+
+ java_library {
+ name: "another_util",
+ srcs: ["a.java"],
+ min_sdk_version: "31",
+ apex_available: ["myapex"],
+ }
+ `)
+ })
+
+ t.Run("bootclasspath_fragment jar must set min_sdk_version", func(t *testing.T) {
+ preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "mybootclasspathlib".*must set min_sdk_version`)).
+ RunTestWithBp(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ bootclasspath_fragments: ["mybootclasspathfragment"],
+ min_sdk_version: "30",
+ updatable: false,
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ bootclasspath_fragment {
+ name: "mybootclasspathfragment",
+ contents: ["mybootclasspathlib"],
+ apex_available: ["myapex"],
+ }
+
+ java_sdk_library {
+ name: "mybootclasspathlib",
+ srcs: ["mybootclasspathlib.java"],
+ apex_available: ["myapex"],
+ compile_dex: true,
+ unsafe_ignore_missing_latest_api: true,
+ }
+ `)
+ })
+
+ t.Run("systemserverclasspath_fragment jar must set min_sdk_version", func(t *testing.T) {
+ preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "mysystemserverclasspathlib".*must set min_sdk_version`)).
+ RunTestWithBp(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
+ min_sdk_version: "30",
+ updatable: false,
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ systemserverclasspath_fragment {
+ name: "mysystemserverclasspathfragment",
+ contents: ["mysystemserverclasspathlib"],
+ apex_available: ["myapex"],
+ }
+
+ java_sdk_library {
+ name: "mysystemserverclasspathlib",
+ srcs: ["mysystemserverclasspathlib.java"],
+ apex_available: ["myapex"],
+ compile_dex: true,
+ unsafe_ignore_missing_latest_api: true,
+ }
+ `)
+ })
+}
+
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
diff --git a/apex/builder.go b/apex/builder.go
index 0880e2b..5910784 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -434,7 +434,10 @@
// Avoid creating duplicate build rules for multi-installed APEXes.
if proptools.BoolDefault(a.properties.Multi_install_skip_symbol_files, false) {
installSymbolFiles = false
+
}
+ // set of dependency module:location mappings
+ installMapSet := make(map[string]bool)
// TODO(jiyong): use the RuleBuilder
var copyCommands []string
@@ -442,7 +445,6 @@
pathWhenActivated := android.PathForModuleInPartitionInstall(ctx, "apex", apexName)
for _, fi := range a.filesInfo {
destPath := imageDir.Join(ctx, fi.path()).String()
- var installedPath android.InstallPath
// Prepare the destination path
destPathDir := filepath.Dir(destPath)
if fi.class == appSet {
@@ -450,6 +452,8 @@
}
copyCommands = append(copyCommands, "mkdir -p "+destPathDir)
+ installMapPath := fi.builtFile
+
// Copy the built file to the directory. But if the symlink optimization is turned
// on, place a symlink to the corresponding file in /system partition instead.
if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() {
@@ -457,6 +461,7 @@
pathOnDevice := filepath.Join("/system", fi.path())
copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath)
} else {
+ var installedPath android.InstallPath
if fi.class == appSet {
copyCommands = append(copyCommands,
fmt.Sprintf("unzip -qDD -d %s %s", destPathDir,
@@ -475,17 +480,19 @@
if installSymbolFiles {
implicitInputs = append(implicitInputs, installedPath)
}
- }
- // Create additional symlinks pointing the file inside the APEX (if any). Note that
- // this is independent from the symlink optimization.
- for _, symlinkPath := range fi.symlinkPaths() {
- symlinkDest := imageDir.Join(ctx, symlinkPath).String()
- copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
- if installSymbolFiles {
- installedSymlink := ctx.InstallSymlink(pathWhenActivated.Join(ctx, filepath.Dir(symlinkPath)), filepath.Base(symlinkPath), installedPath)
- implicitInputs = append(implicitInputs, installedSymlink)
+ // Create additional symlinks pointing the file inside the APEX (if any). Note that
+ // this is independent from the symlink optimization.
+ for _, symlinkPath := range fi.symlinkPaths() {
+ symlinkDest := imageDir.Join(ctx, symlinkPath).String()
+ copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
+ if installSymbolFiles {
+ installedSymlink := ctx.InstallSymlink(pathWhenActivated.Join(ctx, filepath.Dir(symlinkPath)), filepath.Base(symlinkPath), installedPath)
+ implicitInputs = append(implicitInputs, installedSymlink)
+ }
}
+
+ installMapPath = installedPath
}
// Copy the test files (if any)
@@ -502,6 +509,8 @@
copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest)
implicitInputs = append(implicitInputs, d.SrcPath)
}
+
+ installMapSet[installMapPath.String()+":"+fi.installDir+"/"+fi.builtFile.Base()] = true
}
implicitInputs = append(implicitInputs, a.manifestPbOut)
if installSymbolFiles {
@@ -510,6 +519,12 @@
implicitInputs = append(implicitInputs, installedManifest, installedKey)
}
+ if len(installMapSet) > 0 {
+ var installs []string
+ installs = append(installs, android.SortedStringKeys(installMapSet)...)
+ a.SetLicenseInstallMap(installs)
+ }
+
////////////////////////////////////////////////////////////////////////////////////////////
// Step 1.a: Write the list of files in this APEX to a txt file and compare it against
// the allowed list given via the allowed_files property. Build fails when the two lists
diff --git a/apex/prebuilt.go b/apex/prebuilt.go
index 84bdcdd..254c90e 100644
--- a/apex/prebuilt.go
+++ b/apex/prebuilt.go
@@ -965,7 +965,7 @@
a.installDir = android.PathForModuleInstall(ctx, "apex")
if a.installable() {
- ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
+ a.installedFile = ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
}
// in case that apex_set replaces source apex (using prefer: prop)
diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go
index 0bd71c6..41f9886 100644
--- a/bazel/cquery/request_type.go
+++ b/bazel/cquery/request_type.go
@@ -17,6 +17,7 @@
CcStaticLibraryFiles []string
Includes []string
SystemIncludes []string
+ Headers []string
// Archives owned by the current target (not by its dependencies). These will
// be a subset of OutputFiles. (or static libraries, this will be equal to OutputFiles,
// but general cc_library will also have dynamic libraries in output files).
@@ -105,6 +106,7 @@
includes = cc_info.compilation_context.includes.to_list()
system_includes = cc_info.compilation_context.system_includes.to_list()
+headers = [f.path for f in cc_info.compilation_context.headers.to_list()]
ccObjectFiles = []
staticLibraries = []
@@ -145,6 +147,7 @@
ccObjectFiles,
includes,
system_includes,
+ headers,
rootStaticArchives,
rootDynamicLibraries,
[toc_file]
@@ -161,7 +164,7 @@
var ccObjects []string
splitString := strings.Split(rawString, "|")
- if expectedLen := 8; len(splitString) != expectedLen {
+ if expectedLen := 9; len(splitString) != expectedLen {
return CcInfo{}, fmt.Errorf("Expected %d items, got %q", expectedLen, splitString)
}
outputFilesString := splitString[0]
@@ -172,15 +175,17 @@
ccObjects = splitOrEmpty(ccObjectsString, ", ")
includes := splitOrEmpty(splitString[3], ", ")
systemIncludes := splitOrEmpty(splitString[4], ", ")
- rootStaticArchives := splitOrEmpty(splitString[5], ", ")
- rootDynamicLibraries := splitOrEmpty(splitString[6], ", ")
- tocFile := splitString[7] // NOTE: Will be the empty string if there wasn't
+ headers := splitOrEmpty(splitString[5], ", ")
+ rootStaticArchives := splitOrEmpty(splitString[6], ", ")
+ rootDynamicLibraries := splitOrEmpty(splitString[7], ", ")
+ tocFile := splitString[8] // NOTE: Will be the empty string if there wasn't
return CcInfo{
OutputFiles: outputFiles,
CcObjectFiles: ccObjects,
CcStaticLibraryFiles: ccStaticLibraries,
Includes: includes,
SystemIncludes: systemIncludes,
+ Headers: headers,
RootStaticArchives: rootStaticArchives,
RootDynamicLibraries: rootDynamicLibraries,
TocFile: tocFile,
diff --git a/bazel/cquery/request_type_test.go b/bazel/cquery/request_type_test.go
index 34d0832..d3bcb45 100644
--- a/bazel/cquery/request_type_test.go
+++ b/bazel/cquery/request_type_test.go
@@ -71,13 +71,14 @@
}{
{
description: "no result",
- input: "|||||||",
+ input: "||||||||",
expectedOutput: CcInfo{
OutputFiles: []string{},
CcObjectFiles: []string{},
CcStaticLibraryFiles: []string{},
Includes: []string{},
SystemIncludes: []string{},
+ Headers: []string{},
RootStaticArchives: []string{},
RootDynamicLibraries: []string{},
TocFile: "",
@@ -85,13 +86,14 @@
},
{
description: "only output",
- input: "test|||||||",
+ input: "test||||||||",
expectedOutput: CcInfo{
OutputFiles: []string{"test"},
CcObjectFiles: []string{},
CcStaticLibraryFiles: []string{},
Includes: []string{},
SystemIncludes: []string{},
+ Headers: []string{},
RootStaticArchives: []string{},
RootDynamicLibraries: []string{},
TocFile: "",
@@ -99,13 +101,14 @@
},
{
description: "all items set",
- input: "out1, out2|static_lib1, static_lib2|object1, object2|., dir/subdir|system/dir, system/other/dir|rootstaticarchive1|rootdynamiclibrary1|lib.so.toc",
+ input: "out1, out2|static_lib1, static_lib2|object1, object2|., dir/subdir|system/dir, system/other/dir|dir/subdir/hdr.h|rootstaticarchive1|rootdynamiclibrary1|lib.so.toc",
expectedOutput: CcInfo{
OutputFiles: []string{"out1", "out2"},
CcObjectFiles: []string{"object1", "object2"},
CcStaticLibraryFiles: []string{"static_lib1", "static_lib2"},
Includes: []string{".", "dir/subdir"},
SystemIncludes: []string{"system/dir", "system/other/dir"},
+ Headers: []string{"dir/subdir/hdr.h"},
RootStaticArchives: []string{"rootstaticarchive1"},
RootDynamicLibraries: []string{"rootdynamiclibrary1"},
TocFile: "lib.so.toc",
@@ -115,13 +118,13 @@
description: "too few result splits",
input: "|",
expectedOutput: CcInfo{},
- expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", 8, []string{"", ""}),
+ expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", 9, []string{"", ""}),
},
{
description: "too many result splits",
- input: strings.Repeat("|", 8),
+ input: strings.Repeat("|", 50),
expectedOutput: CcInfo{},
- expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", 8, make([]string, 9)),
+ expectedErrorMessage: fmt.Sprintf("Expected %d items, got %q", 9, make([]string, 51)),
},
}
for _, tc := range testCases {
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index 1a23db7..64440df 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -19,6 +19,7 @@
"android/soong/apex"
"android/soong/cc"
"android/soong/java"
+ "android/soong/sh"
"testing"
)
@@ -32,6 +33,8 @@
// CC module types needed as they can be APEX dependencies
cc.RegisterCCBuildComponents(ctx)
+ ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
+ ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
@@ -40,60 +43,63 @@
func TestApexBundleSimple(t *testing.T) {
runApexTestCase(t, bp2buildTestCase{
- description: "apex - simple example",
+ description: "apex - example with all props",
moduleTypeUnderTest: "apex",
moduleTypeUnderTestFactory: apex.BundleFactory,
moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
filesystem: map[string]string{},
blueprint: `
apex_key {
- name: "com.android.apogee.key",
- public_key: "com.android.apogee.avbpubkey",
- private_key: "com.android.apogee.pem",
+ name: "com.android.apogee.key",
+ public_key: "com.android.apogee.avbpubkey",
+ private_key: "com.android.apogee.pem",
bazel_module: { bp2build_available: false },
}
android_app_certificate {
- name: "com.android.apogee.certificate",
- certificate: "com.android.apogee",
- bazel_module: { bp2build_available: false },
-}
-
-cc_library {
- name: "native_shared_lib_1",
+ name: "com.android.apogee.certificate",
+ certificate: "com.android.apogee",
bazel_module: { bp2build_available: false },
}
cc_library {
- name: "native_shared_lib_2",
+ name: "native_shared_lib_1",
+ bazel_module: { bp2build_available: false },
+}
+
+cc_library {
+ name: "native_shared_lib_2",
bazel_module: { bp2build_available: false },
}
// TODO(b/194878861): Add bp2build support for prebuilt_etc
cc_library {
- name: "pretend_prebuilt_1",
- bazel_module: { bp2build_available: false },
+ name: "pretend_prebuilt_1",
+ bazel_module: { bp2build_available: false },
}
// TODO(b/194878861): Add bp2build support for prebuilt_etc
cc_library {
- name: "pretend_prebuilt_2",
- bazel_module: { bp2build_available: false },
+ name: "pretend_prebuilt_2",
+ bazel_module: { bp2build_available: false },
}
filegroup {
name: "com.android.apogee-file_contexts",
- srcs: [
- "com.android.apogee-file_contexts",
- ],
- bazel_module: { bp2build_available: false },
+ srcs: [
+ "com.android.apogee-file_contexts",
+ ],
+ bazel_module: { bp2build_available: false },
}
+cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
+sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
+
apex {
name: "com.android.apogee",
manifest: "apogee_manifest.json",
androidManifest: "ApogeeAndroidManifest.xml",
- file_contexts: "com.android.apogee-file_contexts",
+ file_contexts: "com.android.apogee-file_contexts",
min_sdk_version: "29",
key: "com.android.apogee.key",
certificate: "com.android.apogee.certificate",
@@ -104,8 +110,8 @@
"native_shared_lib_2",
],
binaries: [
- "binary_1",
- "binary_2",
+ "cc_binary_1",
+ "sh_binary_2",
],
prebuilts: [
"pretend_prebuilt_1",
@@ -117,8 +123,8 @@
makeBazelTarget("apex", "com.android.apogee", attrNameToString{
"android_manifest": `"ApogeeAndroidManifest.xml"`,
"binaries": `[
- "binary_1",
- "binary_2",
+ ":cc_binary_1",
+ ":sh_binary_2",
]`,
"certificate": `":com.android.apogee.certificate"`,
"file_contexts": `":com.android.apogee-file_contexts"`,
diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go
index e0331be..64f368e 100644
--- a/bp2build/cc_library_shared_conversion_test.go
+++ b/bp2build/cc_library_shared_conversion_test.go
@@ -450,3 +450,18 @@
},
})
}
+
+func TestCcLibrarySharedUseVersionLib(t *testing.T) {
+ runCcLibrarySharedTestCase(t, bp2buildTestCase{
+ blueprint: soongCcProtoPreamble + `cc_library_shared {
+ name: "foo",
+ use_version_lib: true,
+ include_build_directory: false,
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("cc_library_shared", "foo", attrNameToString{
+ "use_version_lib": "True",
+ }),
+ },
+ })
+}
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index 02229e5..ef82c6b 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -1443,3 +1443,18 @@
},
})
}
+
+func TestCcLibraryStaticUseVersionLib(t *testing.T) {
+ runCcLibraryStaticTestCase(t, bp2buildTestCase{
+ blueprint: soongCcProtoPreamble + `cc_library_static {
+ name: "foo",
+ use_version_lib: true,
+ include_build_directory: false,
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("cc_library_static", "foo", attrNameToString{
+ "use_version_lib": "True",
+ }),
+ },
+ })
+}
diff --git a/bp2build/metrics.go b/bp2build/metrics.go
index 1cc4143..b3d5afb 100644
--- a/bp2build/metrics.go
+++ b/bp2build/metrics.go
@@ -1,9 +1,10 @@
package bp2build
import (
- "android/soong/android"
"fmt"
"strings"
+
+ "android/soong/android"
)
// Simple metrics struct to collect information about a Blueprint to BUILD
@@ -35,7 +36,8 @@
generatedTargetCount += count
}
fmt.Printf(
- "[bp2build] Generated %d total BUILD targets and included %d handcrafted BUILD targets from %d Android.bp modules.\n With %d modules with unconverted deps \n\t%s",
+ "[bp2build] Converted %d Android.bp modules to %d total generated BUILD targets. Included %d handcrafted BUILD targets. There are %d total Android.bp modules.\n%d converted modules have unconverted deps: \n\t%s",
+ metrics.generatedModuleCount,
generatedTargetCount,
metrics.handCraftedModuleCount,
metrics.TotalModuleCount(),
diff --git a/bp2build/performance_test.go b/bp2build/performance_test.go
index 3283952..c4bbae2 100644
--- a/bp2build/performance_test.go
+++ b/bp2build/performance_test.go
@@ -29,6 +29,10 @@
"testing"
)
+const (
+ performance_test_dir = "."
+)
+
func genCustomModule(i int, convert bool) string {
var conversionString string
if convert {
@@ -76,34 +80,83 @@
return strings.Join(bp, "\n\n")
}
+type testConfig struct {
+ config android.Config
+ ctx *android.TestContext
+ codegenCtx *CodegenContext
+}
+
+func (tc testConfig) parse() []error {
+ _, errs := tc.ctx.ParseFileList(performance_test_dir, []string{"Android.bp"})
+ return errs
+}
+
+func (tc testConfig) resolveDependencies() []error {
+ _, errs := tc.ctx.ResolveDependencies(tc.config)
+ return errs
+}
+
+func (tc testConfig) convert() {
+ generateBazelTargetsForDir(tc.codegenCtx, performance_test_dir)
+}
+
+func setup(builddir string, tcSize float64) testConfig {
+ config := android.TestConfig(buildDir, nil, genCustomModuleBp(tcSize), nil)
+ ctx := android.NewTestContext(config)
+
+ registerCustomModuleForBp2buildConversion(ctx)
+ codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
+ return testConfig{
+ config,
+ ctx,
+ codegenCtx,
+ }
+}
+
var pctToConvert = []float64{0.0, 0.01, 0.05, 0.10, 0.25, 0.5, 0.75, 1.0}
+// This is not intended to test performance, but to verify performance infra continues to work
+func TestConvertManyModulesFull(t *testing.T) {
+ for _, tcSize := range pctToConvert {
+
+ t.Run(fmt.Sprintf("pctConverted %f", tcSize), func(t *testing.T) {
+ testConfig := setup(buildDir, tcSize)
+
+ errs := testConfig.parse()
+ if len(errs) > 0 {
+ t.Fatalf("Unexpected errors: %s", errs)
+ }
+
+ errs = testConfig.resolveDependencies()
+ if len(errs) > 0 {
+ t.Fatalf("Unexpected errors: %s", errs)
+ }
+
+ testConfig.convert()
+ })
+ }
+}
+
func BenchmarkManyModulesFull(b *testing.B) {
- dir := "."
for _, tcSize := range pctToConvert {
b.Run(fmt.Sprintf("pctConverted %f", tcSize), func(b *testing.B) {
for n := 0; n < b.N; n++ {
b.StopTimer()
- // setup we don't want to measure
- config := android.TestConfig(buildDir, nil, genCustomModuleBp(tcSize), nil)
- ctx := android.NewTestContext(config)
-
- registerCustomModuleForBp2buildConversion(ctx)
- codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
+ testConfig := setup(buildDir, tcSize)
b.StartTimer()
- _, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
+ errs := testConfig.parse()
if len(errs) > 0 {
b.Fatalf("Unexpected errors: %s", errs)
}
- _, errs = ctx.ResolveDependencies(config)
+ errs = testConfig.resolveDependencies()
if len(errs) > 0 {
b.Fatalf("Unexpected errors: %s", errs)
}
- generateBazelTargetsForDir(codegenCtx, dir)
+ testConfig.convert()
b.StopTimer()
}
})
@@ -111,63 +164,53 @@
}
func BenchmarkManyModulesResolveDependencies(b *testing.B) {
- dir := "."
for _, tcSize := range pctToConvert {
b.Run(fmt.Sprintf("pctConverted %f", tcSize), func(b *testing.B) {
for n := 0; n < b.N; n++ {
b.StopTimer()
// setup we don't want to measure
- config := android.TestConfig(buildDir, nil, genCustomModuleBp(tcSize), nil)
- ctx := android.NewTestContext(config)
+ testConfig := setup(buildDir, tcSize)
- registerCustomModuleForBp2buildConversion(ctx)
- codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
-
- _, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
+ errs := testConfig.parse()
if len(errs) > 0 {
b.Fatalf("Unexpected errors: %s", errs)
}
b.StartTimer()
- _, errs = ctx.ResolveDependencies(config)
+ errs = testConfig.resolveDependencies()
b.StopTimer()
if len(errs) > 0 {
b.Fatalf("Unexpected errors: %s", errs)
}
- generateBazelTargetsForDir(codegenCtx, dir)
+ testConfig.convert()
}
})
}
}
func BenchmarkManyModulesGenerateBazelTargetsForDir(b *testing.B) {
- dir := "."
for _, tcSize := range pctToConvert {
b.Run(fmt.Sprintf("pctConverted %f", tcSize), func(b *testing.B) {
for n := 0; n < b.N; n++ {
b.StopTimer()
// setup we don't want to measure
- config := android.TestConfig(buildDir, nil, genCustomModuleBp(tcSize), nil)
- ctx := android.NewTestContext(config)
+ testConfig := setup(buildDir, tcSize)
- registerCustomModuleForBp2buildConversion(ctx)
- codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
-
- _, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
+ errs := testConfig.parse()
if len(errs) > 0 {
b.Fatalf("Unexpected errors: %s", errs)
}
- _, errs = ctx.ResolveDependencies(config)
+ errs = testConfig.resolveDependencies()
if len(errs) > 0 {
b.Fatalf("Unexpected errors: %s", errs)
}
b.StartTimer()
- generateBazelTargetsForDir(codegenCtx, dir)
+ testConfig.convert()
b.StopTimer()
}
})
diff --git a/bpfix/Android.bp b/bpfix/Android.bp
index 345dbd0..a72d9b4 100644
--- a/bpfix/Android.bp
+++ b/bpfix/Android.bp
@@ -52,5 +52,6 @@
],
deps: [
"blueprint-parser",
+ "blueprint-pathtools",
],
}
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index e1140b8..c0925fe 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -22,6 +22,7 @@
"flag"
"fmt"
"io"
+ "io/ioutil"
"os"
"path/filepath"
"reflect"
@@ -29,6 +30,7 @@
"strings"
"github.com/google/blueprint/parser"
+ "github.com/google/blueprint/pathtools"
)
// Reformat takes a blueprint file as a string and returns a formatted version
@@ -166,7 +168,7 @@
},
{
Name: "rewriteLicenseProperties",
- Fix: runPatchListMod(rewriteLicenseProperties),
+ Fix: runPatchListMod(rewriteLicenseProperty(nil, "")),
},
}
@@ -1452,9 +1454,16 @@
return nil
}
+func rewriteLicenseProperty(fs pathtools.FileSystem, relativePath string) patchListModFunction {
+ return func(mod *parser.Module, buf []byte, patchList *parser.PatchList) error {
+ return rewriteLicenseProperties(mod, patchList, fs, relativePath)
+ }
+}
+
// rewrite the "android_license_kinds" and "android_license_files" properties to a package module
// (and a license module when needed).
-func rewriteLicenseProperties(mod *parser.Module, buf []byte, patchList *parser.PatchList) error {
+func rewriteLicenseProperties(mod *parser.Module, patchList *parser.PatchList, fs pathtools.FileSystem,
+ relativePath string) error {
// if a package module has been added, no more action is needed.
for _, patch := range *patchList {
if strings.Contains(patch.Replacement, "package {") {
@@ -1462,15 +1471,33 @@
}
}
+ // initial the fs
+ if fs == nil {
+ fs = pathtools.NewOsFs(os.Getenv("ANDROID_BUILD_TOP"))
+ }
+
+ // initial the relativePath
+ if len(relativePath) == 0 {
+ relativePath = getModuleRelativePath()
+ }
+ // validate the relativePath
+ ok := hasFile(relativePath+"/Android.mk", fs)
+ // some modules in the existing test cases in the androidmk_test.go do not have a valid path
+ if !ok && len(relativePath) > 0 {
+ return fmt.Errorf("Cannot find an Android.mk file at path %s", relativePath)
+ }
+
licenseKindsPropertyName := "android_license_kinds"
licenseFilesPropertyName := "android_license_files"
- androidBpFileErr := "// Error: No Android.bp file is found at\n" +
+ androidBpFileErr := "// Error: No Android.bp file is found at path\n" +
"// %s\n" +
- "// Please add one there with the needed license module first.\n"
+ "// Please add one there with the needed license module first.\n" +
+ "// Then reset the default_applicable_licenses property below with the license module name.\n"
licenseModuleErr := "// Error: Cannot get the name of the license module in the\n" +
"// %s file.\n" +
- "// If no such license module exists, please add one there first.\n"
+ "// If no such license module exists, please add one there first.\n" +
+ "// Then reset the default_applicable_licenses property below with the license module name.\n"
defaultApplicableLicense := "Android-Apache-2.0"
var licenseModuleName, licensePatch string
@@ -1482,15 +1509,16 @@
// if have LOCAL_NOTICE_FILE outside the current directory, need to find and refer to the license
// module in the LOCAL_NOTICE_FILE location directly and no new license module needs to be created
if hasFileInParentDir {
- bpPath, ok := getPathFromProperty(mod, licenseFilesPropertyName)
+ bpPath, ok := getPathFromProperty(mod, licenseFilesPropertyName, fs, relativePath)
if !ok {
- bpDir, err := getDirFromProperty(mod, licenseFilesPropertyName)
+ bpDir, err := getDirFromProperty(mod, licenseFilesPropertyName, fs, relativePath)
if err != nil {
return err
}
licensePatch += fmt.Sprintf(androidBpFileErr, bpDir)
+ defaultApplicableLicense = ""
} else {
- licenseModuleName, _ = getModuleName(bpPath, "license")
+ licenseModuleName, _ = getModuleName(bpPath, "license", fs)
if len(licenseModuleName) == 0 {
licensePatch += fmt.Sprintf(licenseModuleErr, bpPath)
}
@@ -1498,7 +1526,6 @@
}
} else {
// if have LOCAL_NOTICE_FILE in the current directory, need to create a new license module
- relativePath := getModuleRelativePath()
if len(relativePath) == 0 {
return fmt.Errorf("Cannot obtain the relative path of the Android.mk file")
}
@@ -1617,17 +1644,14 @@
return absPath
}
-// check whether a file exists in a directory
-func hasFile(dir string, fileName string) error {
- _, err := os.Stat(dir + fileName)
- if err != nil {
- return err
- }
- return nil
+// check whether a file exists in a filesystem
+func hasFile(path string, fs pathtools.FileSystem) bool {
+ ok, _, _ := fs.Exists(path)
+ return ok
}
// get the directory where an `Android.bp` file and the property files are expected to locate
-func getDirFromProperty(mod *parser.Module, property string) (string, error) {
+func getDirFromProperty(mod *parser.Module, property string, fs pathtools.FileSystem, relativePath string) (string, error) {
listValue, ok := getLiteralListPropertyValue(mod, property)
if !ok {
// if do not find
@@ -1637,7 +1661,11 @@
// if empty
return "", fmt.Errorf("Cannot find the value of the %s.%s property", mod.Type, property)
}
- path := getModuleAbsolutePath()
+ _, isDir, _ := fs.Exists(relativePath)
+ if !isDir {
+ return "", fmt.Errorf("Cannot find the path %s", relativePath)
+ }
+ path := relativePath
for {
if !strings.HasPrefix(listValue[0], "../") {
break
@@ -1645,25 +1673,29 @@
path = filepath.Dir(path)
listValue[0] = strings.TrimPrefix(listValue[0], "../")
}
+ _, isDir, _ = fs.Exists(path)
+ if !isDir {
+ return "", fmt.Errorf("Cannot find the path %s", path)
+ }
return path, nil
}
// get the path of the `Android.bp` file at the expected location where the property files locate
-func getPathFromProperty(mod *parser.Module, property string) (string, bool) {
- dir, err := getDirFromProperty(mod, property)
+func getPathFromProperty(mod *parser.Module, property string, fs pathtools.FileSystem, relativePath string) (string, bool) {
+ dir, err := getDirFromProperty(mod, property, fs, relativePath)
if err != nil {
return "", false
}
- err = hasFile(dir, "/Android.bp")
- if err != nil {
+ ok := hasFile(dir+"/Android.bp", fs)
+ if !ok {
return "", false
}
return dir + "/Android.bp", true
}
// parse an Android.bp file to get the name of the first module with type of moduleType
-func getModuleName(path string, moduleType string) (string, error) {
- tree, err := parserPath(path)
+func getModuleName(path string, moduleType string, fs pathtools.FileSystem) (string, error) {
+ tree, err := parserPath(path, fs)
if err != nil {
return "", err
}
@@ -1685,8 +1717,13 @@
}
// parse an Android.bp file with the specific path
-func parserPath(path string) (tree *parser.File, err error) {
- fileContent, _ := os.ReadFile(path)
+func parserPath(path string, fs pathtools.FileSystem) (tree *parser.File, err error) {
+ f, err := fs.Open(path)
+ if err != nil {
+ return tree, err
+ }
+ defer f.Close()
+ fileContent, _ := ioutil.ReadAll(f)
tree, err = parse(path, bytes.NewBufferString(string(fileContent)))
if err != nil {
return tree, err
diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go
index e6b6af5..221df45 100644
--- a/bpfix/bpfix/bpfix_test.go
+++ b/bpfix/bpfix/bpfix_test.go
@@ -25,6 +25,7 @@
"reflect"
"github.com/google/blueprint/parser"
+ "github.com/google/blueprint/pathtools"
)
// TODO(jeffrygaston) remove this when position is removed from ParseNode (in b/38325146) and we can directly do reflect.DeepEqual
@@ -1678,10 +1679,20 @@
}
}
-func TestRewriteLicenseProperties(t *testing.T) {
+func TestRewriteLicenseProperty(t *testing.T) {
+ mockFs := pathtools.MockFs(map[string][]byte{
+ "a/b/c/d/Android.mk": []byte("this is not important."),
+ "a/b/LicenseFile1": []byte("LicenseFile1"),
+ "a/b/LicenseFile2": []byte("LicenseFile2"),
+ "a/b/Android.bp": []byte("license {\n\tname: \"reuse_a_b_license\",\n}\n"),
+ })
+ relativePath := "a/b/c/d"
+ relativePathErr := "a/b/c"
tests := []struct {
name string
in string
+ fs pathtools.FileSystem
+ path string
out string
}{
{
@@ -1744,13 +1755,194 @@
}
`,
},
- // TODO(b/205615944): When valid "android_license_files" exists, the test requires an Android.mk
- // file (and an Android.bp file is required as well if the license files locates outside the current
- // directory). So plan to use a mock file system to mock the Android.mk and Android.bp files.
+ {
+ name: "license rewriting with license files in the current directory",
+ in: `
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: ["LicenseFile1", "LicenseFile2",],
+ }
+ `,
+ fs: mockFs,
+ path: relativePath,
+ out: `
+ package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: [
+ "a_b_c_d_license",
+ ],
+ }
+
+ license {
+ name: "a_b_c_d_license",
+ visibility: [":__subpackages__"],
+ license_kinds: [
+ "license_kind",
+ ],
+ license_text: [
+ "LicenseFile1",
+ "LicenseFile2",
+ ],
+ }
+
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: [
+ "LicenseFile1",
+ "LicenseFile2",
+ ],
+ }
+ `,
+ },
+ {
+ name: "license rewriting with license files outside the current directory",
+ in: `
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: ["../../LicenseFile1", "../../LicenseFile2",],
+ }
+ `,
+ fs: mockFs,
+ path: relativePath,
+ out: `
+ package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: [
+ "reuse_a_b_license",
+ ],
+ }
+
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: [
+ "../../LicenseFile1",
+ "../../LicenseFile2",
+ ],
+ }
+ `,
+ },
+ {
+ name: "license rewriting with no Android.bp file in the expected location",
+ in: `
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: ["../../LicenseFile1", "../../LicenseFile2",],
+ }
+ `,
+ fs: pathtools.MockFs(map[string][]byte{
+ "a/b/c/d/Android.mk": []byte("this is not important."),
+ "a/b/LicenseFile1": []byte("LicenseFile1"),
+ "a/b/LicenseFile2": []byte("LicenseFile2"),
+ "a/Android.bp": []byte("license {\n\tname: \"reuse_a_b_license\",\n}\n"),
+ }),
+ path: relativePath,
+ out: `
+ // Error: No Android.bp file is found at path
+ // a/b
+ // Please add one there with the needed license module first.
+ // Then reset the default_applicable_licenses property below with the license module name.
+ package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: [
+ "",
+ ],
+ }
+
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: [
+ "../../LicenseFile1",
+ "../../LicenseFile2",
+ ],
+ }
+ `,
+ },
+ {
+ name: "license rewriting with an Android.bp file without a license module",
+ in: `
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: ["../../LicenseFile1", "../../LicenseFile2",],
+ }
+ `,
+ fs: pathtools.MockFs(map[string][]byte{
+ "a/b/c/d/Android.mk": []byte("this is not important."),
+ "a/b/LicenseFile1": []byte("LicenseFile1"),
+ "a/b/LicenseFile2": []byte("LicenseFile2"),
+ "a/b/Android.bp": []byte("non_license {\n\tname: \"reuse_a_b_license\",\n}\n"),
+ }),
+ path: relativePath,
+ out: `
+ // Error: Cannot get the name of the license module in the
+ // a/b/Android.bp file.
+ // If no such license module exists, please add one there first.
+ // Then reset the default_applicable_licenses property below with the license module name.
+ package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: [
+ "",
+ ],
+ }
+
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: [
+ "../../LicenseFile1",
+ "../../LicenseFile2",
+ ],
+ }
+ `,
+ },
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- runPassOnce(t, test.in, test.out, runPatchListMod(rewriteLicenseProperties))
+ runPassOnce(t, test.in, test.out, runPatchListMod(rewriteLicenseProperty(test.fs, test.path)))
+ })
+ }
+
+ testErrs := []struct {
+ name string
+ in string
+ fs pathtools.FileSystem
+ path string
+ expectedErr string
+ }{
+ {
+ name: "license rewriting with a wrong path",
+ in: `
+ android_test {
+ name: "foo",
+ android_license_kinds: ["license_kind"],
+ android_license_conditions: ["license_notice"],
+ android_license_files: ["../../LicenseFile1", "../../LicenseFile2",],
+ }
+ `,
+ fs: mockFs,
+ path: relativePathErr,
+ expectedErr: `
+ Cannot find an Android.mk file at path a/b/c
+ `,
+ },
+ }
+ for _, test := range testErrs {
+ t.Run(test.name, func(t *testing.T) {
+ checkError(t, test.in, test.expectedErr, runPatchListMod(rewriteLicenseProperty(test.fs, test.path)))
})
}
}
diff --git a/cc/binary.go b/cc/binary.go
index 0650bdf..e839122 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -345,6 +345,12 @@
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-dynamic-linker")
}
+ if ctx.Darwin() && deps.DarwinSecondArchOutput.Valid() {
+ fatOutputFile := outputFile
+ outputFile = android.PathForModuleOut(ctx, "pre-fat", fileName)
+ transformDarwinUniversalBinary(ctx, fatOutputFile, outputFile, deps.DarwinSecondArchOutput.Path())
+ }
+
builderFlags := flagsToBuilderFlags(flags)
stripFlags := flagsToStripFlags(flags)
if binary.stripper.NeedsStrip(ctx) {
@@ -389,7 +395,7 @@
}
}
- var validations android.WritablePaths
+ var validations android.Paths
// Handle host bionic linker symbols.
if ctx.Os() == android.LinuxBionic && !binary.static() {
diff --git a/cc/bp2build.go b/cc/bp2build.go
index f9bbe87..09aa136 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -496,6 +496,7 @@
linkCrt bazel.BoolAttribute
useLibcrt bazel.BoolAttribute
+ useVersionLib bazel.BoolAttribute
linkopts bazel.StringListAttribute
additionalLinkerInputs bazel.LabelListAttribute
stripKeepSymbols bazel.BoolAttribute
@@ -565,6 +566,10 @@
la.linkopts.SetSelectValue(axis, config, linkerFlags)
la.useLibcrt.SetSelectValue(axis, config, props.libCrt())
+ if axis == bazel.NoConfigAxis {
+ la.useVersionLib.SetSelectValue(axis, config, props.Use_version_lib)
+ }
+
// it's very unlikely for nocrt to be arch variant, so bp2build doesn't support it.
if props.crt() != nil {
if axis == bazel.NoConfigAxis {
diff --git a/cc/builder.go b/cc/builder.go
index 72c2fa5..8af2255 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -165,6 +165,12 @@
}
}()
+ darwinLipo = pctx.AndroidStaticRule("darwinLipo",
+ blueprint.RuleParams{
+ Command: "${config.MacLipoPath} -create -output $out $in",
+ CommandDeps: []string{"${config.MacLipoPath}"},
+ })
+
_ = pctx.SourcePathVariable("archiveRepackPath", "build/soong/scripts/archive_repack.sh")
// Rule to repack an archive (.a) file with a subset of object files.
@@ -413,7 +419,7 @@
// Objects is a collection of file paths corresponding to outputs for C++ related build statements.
type Objects struct {
objFiles android.Paths
- tidyFiles android.WritablePaths
+ tidyFiles android.Paths
coverageFiles android.Paths
sAbiDumpFiles android.Paths
kytheFiles android.Paths
@@ -422,7 +428,7 @@
func (a Objects) Copy() Objects {
return Objects{
objFiles: append(android.Paths{}, a.objFiles...),
- tidyFiles: append(android.WritablePaths{}, a.tidyFiles...),
+ tidyFiles: append(android.Paths{}, a.tidyFiles...),
coverageFiles: append(android.Paths{}, a.coverageFiles...),
sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...),
kytheFiles: append(android.Paths{}, a.kytheFiles...),
@@ -451,11 +457,11 @@
// Source files are one-to-one with tidy, coverage, or kythe files, if enabled.
objFiles := make(android.Paths, len(srcFiles))
- var tidyFiles android.WritablePaths
+ var tidyFiles android.Paths
noTidySrcsMap := make(map[android.Path]bool)
var tidyVars string
if flags.tidy {
- tidyFiles = make(android.WritablePaths, 0, len(srcFiles))
+ tidyFiles = make(android.Paths, 0, len(srcFiles))
for _, path := range noTidySrcs {
noTidySrcsMap[path] = true
}
@@ -665,7 +671,6 @@
rule = clangTidyRE
}
- ctx.TidyFile(tidyFile)
ctx.Build(pctx, android.BuildParams{
Rule: rule,
Description: "clang-tidy " + srcFile.Rel(),
@@ -719,7 +724,7 @@
// Generate a rule for compiling multiple .o files to a static library (.a)
func transformObjToStaticLib(ctx android.ModuleContext,
objFiles android.Paths, wholeStaticLibs android.Paths,
- flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths, validations android.WritablePaths) {
+ flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths, validations android.Paths) {
arCmd := "${config.ClangBin}/llvm-ar"
arFlags := ""
@@ -734,7 +739,7 @@
Output: outputFile,
Inputs: objFiles,
Implicits: deps,
- Validations: validations.Paths(),
+ Validations: validations,
Args: map[string]string{
"arFlags": "crsPD" + arFlags,
"arCmd": arCmd,
@@ -764,7 +769,7 @@
func transformObjToDynamicBinary(ctx android.ModuleContext,
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps, crtBegin, crtEnd android.Paths,
groupLate bool, flags builderFlags, outputFile android.WritablePath,
- implicitOutputs android.WritablePaths, validations android.WritablePaths) {
+ implicitOutputs android.WritablePaths, validations android.Paths) {
ldCmd := "${config.ClangBin}/clang++"
@@ -831,7 +836,7 @@
Inputs: objFiles,
Implicits: deps,
OrderOnly: sharedLibs,
- Validations: validations.Paths(),
+ Validations: validations,
Args: args,
})
}
@@ -1060,6 +1065,15 @@
})
}
+func transformDarwinUniversalBinary(ctx android.ModuleContext, outputFile android.WritablePath, inputFiles ...android.Path) {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: darwinLipo,
+ Description: "lipo " + outputFile.Base(),
+ Output: outputFile,
+ Inputs: inputFiles,
+ })
+}
+
// Registers build statement to zip one or more coverage files.
func transformCoverageFilesToZip(ctx android.ModuleContext,
inputs Objects, baseName string) android.OptionalPath {
diff --git a/cc/cc.go b/cc/cc.go
index aeb342f..39fdcb7 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -167,6 +167,10 @@
// Path to the dynamic linker binary
DynamicLinker android.OptionalPath
+
+ // For Darwin builds, the path to the second architecture's output that should
+ // be combined with this architectures's output into a FAT MachO file.
+ DarwinSecondArchOutput android.OptionalPath
}
// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
@@ -682,6 +686,15 @@
return d.Kind == staticLibraryDependency
}
+func (d libraryDependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
+ if d.shared() {
+ return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
+ }
+ return nil
+}
+
+var _ android.LicenseAnnotationsDependencyTag = libraryDependencyTag{}
+
// InstallDepNeeded returns true for shared libraries so that shared library dependencies of
// binaries or other shared libraries are installed as dependencies.
func (d libraryDependencyTag) InstallDepNeeded() bool {
@@ -815,6 +828,10 @@
makeLinkType string
// Kythe (source file indexer) paths for this compilation module
kytheFiles android.Paths
+ // Object .o file output paths for this compilation module
+ objFiles android.Paths
+ // Tidy .tidy file output paths for this compilation module
+ tidyFiles android.Paths
// For apex variants, this is set as apex.min_sdk_version
apexSdkVersion android.ApiLevel
@@ -1835,6 +1852,8 @@
return
}
c.kytheFiles = objs.kytheFiles
+ c.objFiles = objs.objFiles
+ c.tidyFiles = objs.tidyFiles
}
if c.linker != nil {
@@ -2578,6 +2597,11 @@
depName := ctx.OtherModuleName(dep)
depTag := ctx.OtherModuleDependencyTag(dep)
+ if depTag == android.DarwinUniversalVariantTag {
+ depPaths.DarwinSecondArchOutput = dep.(*Module).OutputFile()
+ return
+ }
+
ccDep, ok := dep.(LinkableInterface)
if !ok {
diff --git a/cc/config/darwin_host.go b/cc/config/darwin_host.go
index 318acb4..206bec1 100644
--- a/cc/config/darwin_host.go
+++ b/cc/config/darwin_host.go
@@ -54,6 +54,7 @@
darwinSupportedSdkVersions = []string{
"11",
+ "12",
}
darwinAvailableLibraries = append(
@@ -87,6 +88,10 @@
return getMacTools(ctx).arPath
})
+ pctx.VariableFunc("MacLipoPath", func(ctx android.PackageVarContext) string {
+ return getMacTools(ctx).lipoPath
+ })
+
pctx.VariableFunc("MacStripPath", func(ctx android.PackageVarContext) string {
return getMacTools(ctx).stripPath
})
@@ -118,6 +123,7 @@
sdkRoot string
arPath string
+ lipoPath string
stripPath string
toolPath string
}
@@ -157,6 +163,7 @@
macTools.sdkRoot = xcrun("--show-sdk-path")
macTools.arPath = xcrun("--find", "ar")
+ macTools.lipoPath = xcrun("--find", "lipo")
macTools.stripPath = xcrun("--find", "strip")
macTools.toolPath = filepath.Dir(xcrun("--find", "ld"))
})
diff --git a/cc/library.go b/cc/library.go
index e53aac0..771a6df 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1429,6 +1429,12 @@
builderFlags := flagsToBuilderFlags(flags)
+ if ctx.Darwin() && deps.DarwinSecondArchOutput.Valid() {
+ fatOutputFile := outputFile
+ outputFile = android.PathForModuleOut(ctx, "pre-fat", fileName)
+ transformDarwinUniversalBinary(ctx, fatOutputFile, outputFile, deps.DarwinSecondArchOutput.Path())
+ }
+
// Optimize out relinking against shared libraries whose interface hasn't changed by
// depending on a table of contents file instead of the library itself.
tocFile := outputFile.ReplaceExtension(ctx, flags.Toolchain.ShlibSuffix()[1:]+".toc")
@@ -2474,7 +2480,9 @@
attrs = &bazelCcLibraryStaticAttributes{
staticOrSharedAttributes: commonAttrs,
- Use_libcrt: linkerAttrs.useLibcrt,
+ Use_libcrt: linkerAttrs.useLibcrt,
+ Use_version_lib: linkerAttrs.useVersionLib,
+
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
@@ -2499,14 +2507,16 @@
Cppflags: compilerAttrs.cppFlags,
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
- Linkopts: linkerAttrs.linkopts,
- Link_crt: linkerAttrs.linkCrt,
- Use_libcrt: linkerAttrs.useLibcrt,
- Rtti: compilerAttrs.rtti,
- Stl: compilerAttrs.stl,
- Cpp_std: compilerAttrs.cppStd,
- C_std: compilerAttrs.cStd,
+ Linkopts: linkerAttrs.linkopts,
+ Link_crt: linkerAttrs.linkCrt,
+ Use_libcrt: linkerAttrs.useLibcrt,
+ Use_version_lib: linkerAttrs.useVersionLib,
+
+ Rtti: compilerAttrs.rtti,
+ Stl: compilerAttrs.stl,
+ Cpp_std: compilerAttrs.cppStd,
+ C_std: compilerAttrs.cStd,
Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes,
@@ -2538,11 +2548,13 @@
type bazelCcLibraryStaticAttributes struct {
staticOrSharedAttributes
- Use_libcrt bazel.BoolAttribute
- Rtti bazel.BoolAttribute
- Stl *string
- Cpp_std *string
- C_std *string
+ Use_libcrt bazel.BoolAttribute
+ Use_version_lib bazel.BoolAttribute
+
+ Rtti bazel.BoolAttribute
+ Stl *string
+ Cpp_std *string
+ C_std *string
Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute
@@ -2573,13 +2585,16 @@
type bazelCcLibrarySharedAttributes struct {
staticOrSharedAttributes
- Linkopts bazel.StringListAttribute
- Link_crt bazel.BoolAttribute // Only for linking shared library (and cc_binary)
- Use_libcrt bazel.BoolAttribute
- Rtti bazel.BoolAttribute
- Stl *string
- Cpp_std *string
- C_std *string
+ Linkopts bazel.StringListAttribute
+ Link_crt bazel.BoolAttribute // Only for linking shared library (and cc_binary)
+
+ Use_libcrt bazel.BoolAttribute
+ Use_version_lib bazel.BoolAttribute
+
+ Rtti bazel.BoolAttribute
+ Stl *string
+ Cpp_std *string
+ C_std *string
Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute
diff --git a/cc/library_test.go b/cc/library_test.go
index 7427b59..d220e19 100644
--- a/cc/library_test.go
+++ b/cc/library_test.go
@@ -257,12 +257,14 @@
CcObjectFiles: []string{"foo.o"},
Includes: []string{"include"},
SystemIncludes: []string{"system_include"},
+ Headers: []string{"foo.h"},
RootDynamicLibraries: []string{"foo.so"},
},
"//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{
CcObjectFiles: []string{"foo.o"},
Includes: []string{"include"},
SystemIncludes: []string{"system_include"},
+ Headers: []string{"foo.h"},
RootStaticArchives: []string{"foo.a"},
},
},
@@ -278,18 +280,25 @@
expectedOutputFiles := []string{"outputbase/execroot/__main__/foo.a"}
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
+ flagExporter := ctx.ModuleProvider(staticFoo, FlagExporterInfoProvider).(FlagExporterInfo)
+ android.AssertPathsRelativeToTopEquals(t, "exported include dirs", []string{"outputbase/execroot/__main__/include"}, flagExporter.IncludeDirs)
+ android.AssertPathsRelativeToTopEquals(t, "exported system include dirs", []string{"outputbase/execroot/__main__/system_include"}, flagExporter.SystemIncludeDirs)
+ android.AssertPathsRelativeToTopEquals(t, "exported headers", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.GeneratedHeaders)
+ android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps)
+
sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
outputFiles, err = sharedFoo.(android.OutputFileProducer).OutputFiles("")
if err != nil {
- t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
+ t.Errorf("Unexpected error getting cc_library outputfiles %s", err)
}
expectedOutputFiles = []string{"outputbase/execroot/__main__/foo.so"}
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
- entries := android.AndroidMkEntriesForTest(t, ctx, sharedFoo)[0]
- expectedFlags := []string{"-Ioutputbase/execroot/__main__/include", "-isystem outputbase/execroot/__main__/system_include"}
- gotFlags := entries.EntryMap["LOCAL_EXPORT_CFLAGS"]
- android.AssertDeepEquals(t, "androidmk exported cflags", expectedFlags, gotFlags)
+ flagExporter = ctx.ModuleProvider(sharedFoo, FlagExporterInfoProvider).(FlagExporterInfo)
+ android.AssertPathsRelativeToTopEquals(t, "exported include dirs", []string{"outputbase/execroot/__main__/include"}, flagExporter.IncludeDirs)
+ android.AssertPathsRelativeToTopEquals(t, "exported system include dirs", []string{"outputbase/execroot/__main__/system_include"}, flagExporter.SystemIncludeDirs)
+ android.AssertPathsRelativeToTopEquals(t, "exported headers", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.GeneratedHeaders)
+ android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps)
}
func TestLibraryVersionScript(t *testing.T) {
diff --git a/cc/linkable.go b/cc/linkable.go
index 560c9de..02d7047 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -384,9 +384,13 @@
includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
+ headers := android.PathsForBazelOut(ctx, ccInfo.Headers)
return FlagExporterInfo{
IncludeDirs: android.FirstUniquePaths(includes),
SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
+ GeneratedHeaders: headers,
+ // necessary to ensure generated headers are considered implicit deps of dependent actions
+ Deps: headers,
}
}
diff --git a/cc/test.go b/cc/test.go
index f37fdae..0ca96f7 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -105,11 +105,6 @@
// Add RunCommandTargetPreparer to stop framework before the test and start it after the test.
Disable_framework *bool
- // Add ShippingApiLevelModuleController to auto generated test config. If the device properties
- // for the shipping api level is less than the test_min_api_level, skip this module.
- // Deprecated (b/187258404). Use test_options.min_shipping_api_level instead.
- Test_min_api_level *int64
-
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
// explicitly.
@@ -432,14 +427,6 @@
var options []tradefed.Option
options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_options.Min_shipping_api_level), 10)})
configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options})
- } else if test.Properties.Test_min_api_level != nil {
- // TODO: (b/187258404) Remove test.Properties.Test_min_api_level
- if test.Properties.Test_options.Vsr_min_shipping_api_level != nil {
- ctx.PropertyErrorf("test_min_api_level", "must not be set at the same time as 'vsr_min_shipping_api_level'.")
- }
- var options []tradefed.Option
- options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_min_api_level), 10)})
- configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options})
}
if test.Properties.Test_options.Vsr_min_shipping_api_level != nil {
var options []tradefed.Option
diff --git a/cc/tidy.go b/cc/tidy.go
index 53ff156..78a791f 100644
--- a/cc/tidy.go
+++ b/cc/tidy.go
@@ -15,6 +15,7 @@
package cc
import (
+ "path/filepath"
"regexp"
"strings"
@@ -183,3 +184,154 @@
}
return flags
}
+
+func init() {
+ android.RegisterSingletonType("tidy_phony_targets", TidyPhonySingleton)
+}
+
+// This TidyPhonySingleton generates both tidy-* and obj-* phony targets for C/C++ files.
+func TidyPhonySingleton() android.Singleton {
+ return &tidyPhonySingleton{}
+}
+
+type tidyPhonySingleton struct{}
+
+// Given a final module, add its tidy/obj phony targets to tidy/objModulesInDirGroup.
+func collectTidyObjModuleTargets(ctx android.SingletonContext, module android.Module,
+ tidyModulesInDirGroup, objModulesInDirGroup map[string]map[string]android.Paths) {
+ allObjFileGroups := make(map[string]android.Paths) // variant group name => obj file Paths
+ allTidyFileGroups := make(map[string]android.Paths) // variant group name => tidy file Paths
+ subsetObjFileGroups := make(map[string]android.Paths) // subset group name => obj file Paths
+ subsetTidyFileGroups := make(map[string]android.Paths) // subset group name => tidy file Paths
+
+ // (1) Collect all obj/tidy files into OS-specific groups.
+ ctx.VisitAllModuleVariants(module, func(variant android.Module) {
+ if ctx.Config().KatiEnabled() && android.ShouldSkipAndroidMkProcessing(variant) {
+ return
+ }
+ if m, ok := variant.(*Module); ok {
+ osName := variant.Target().Os.Name
+ addToOSGroup(osName, m.objFiles, allObjFileGroups, subsetObjFileGroups)
+ addToOSGroup(osName, m.tidyFiles, allTidyFileGroups, subsetTidyFileGroups)
+ }
+ })
+
+ // (2) Add an all-OS group, with "" or "subset" name, to include all os-specific phony targets.
+ addAllOSGroup(ctx, module, allObjFileGroups, "", "obj")
+ addAllOSGroup(ctx, module, allTidyFileGroups, "", "tidy")
+ addAllOSGroup(ctx, module, subsetObjFileGroups, "subset", "obj")
+ addAllOSGroup(ctx, module, subsetTidyFileGroups, "subset", "tidy")
+
+ tidyTargetGroups := make(map[string]android.Path)
+ objTargetGroups := make(map[string]android.Path)
+ genObjTidyPhonyTargets(ctx, module, "obj", allObjFileGroups, objTargetGroups)
+ genObjTidyPhonyTargets(ctx, module, "obj", subsetObjFileGroups, objTargetGroups)
+ genObjTidyPhonyTargets(ctx, module, "tidy", allTidyFileGroups, tidyTargetGroups)
+ genObjTidyPhonyTargets(ctx, module, "tidy", subsetTidyFileGroups, tidyTargetGroups)
+
+ moduleDir := ctx.ModuleDir(module)
+ appendToModulesInDirGroup(tidyTargetGroups, moduleDir, tidyModulesInDirGroup)
+ appendToModulesInDirGroup(objTargetGroups, moduleDir, objModulesInDirGroup)
+}
+
+func (m *tidyPhonySingleton) GenerateBuildActions(ctx android.SingletonContext) {
+ // For tidy-* directory phony targets, there are different variant groups.
+ // tidyModulesInDirGroup[G][D] is for group G, directory D, with Paths
+ // of all phony targets to be included into direct dependents of tidy-D_G.
+ tidyModulesInDirGroup := make(map[string]map[string]android.Paths)
+ // Also for obj-* directory phony targets.
+ objModulesInDirGroup := make(map[string]map[string]android.Paths)
+
+ // Collect tidy/obj targets from the 'final' modules.
+ ctx.VisitAllModules(func(module android.Module) {
+ if module == ctx.FinalModule(module) {
+ collectTidyObjModuleTargets(ctx, module, tidyModulesInDirGroup, objModulesInDirGroup)
+ }
+ })
+
+ suffix := ""
+ if ctx.Config().KatiEnabled() {
+ suffix = "-soong"
+ }
+ generateObjTidyPhonyTargets(ctx, suffix, "obj", objModulesInDirGroup)
+ generateObjTidyPhonyTargets(ctx, suffix, "tidy", tidyModulesInDirGroup)
+}
+
+// The name for an obj/tidy module variant group phony target is Name_group-obj/tidy,
+func objTidyModuleGroupName(module android.Module, group string, suffix string) string {
+ if group == "" {
+ return module.Name() + "-" + suffix
+ }
+ return module.Name() + "_" + group + "-" + suffix
+}
+
+// Generate obj-* or tidy-* phony targets.
+func generateObjTidyPhonyTargets(ctx android.SingletonContext, suffix string, prefix string, objTidyModulesInDirGroup map[string]map[string]android.Paths) {
+ // For each variant group, create a <prefix>-<directory>_group target that
+ // depends on all subdirectories and modules in the directory.
+ for group, modulesInDir := range objTidyModulesInDirGroup {
+ groupSuffix := ""
+ if group != "" {
+ groupSuffix = "_" + group
+ }
+ mmTarget := func(dir string) string {
+ return prefix + "-" + strings.Replace(filepath.Clean(dir), "/", "-", -1) + groupSuffix
+ }
+ dirs, topDirs := android.AddAncestors(ctx, modulesInDir, mmTarget)
+ // Create a <prefix>-soong_group target that depends on all <prefix>-dir_group of top level dirs.
+ var topDirPaths android.Paths
+ for _, dir := range topDirs {
+ topDirPaths = append(topDirPaths, android.PathForPhony(ctx, mmTarget(dir)))
+ }
+ ctx.Phony(prefix+suffix+groupSuffix, topDirPaths...)
+ // Create a <prefix>-dir_group target that depends on all targets in modulesInDir[dir]
+ for _, dir := range dirs {
+ if dir != "." && dir != "" {
+ ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
+ }
+ }
+ }
+}
+
+// Append (obj|tidy)TargetGroups[group] into (obj|tidy)ModulesInDirGroups[group][moduleDir].
+func appendToModulesInDirGroup(targetGroups map[string]android.Path, moduleDir string, modulesInDirGroup map[string]map[string]android.Paths) {
+ for group, phonyPath := range targetGroups {
+ if _, found := modulesInDirGroup[group]; !found {
+ modulesInDirGroup[group] = make(map[string]android.Paths)
+ }
+ modulesInDirGroup[group][moduleDir] = append(modulesInDirGroup[group][moduleDir], phonyPath)
+ }
+}
+
+// Add given files to the OS group and subset group.
+func addToOSGroup(osName string, files android.Paths, allGroups, subsetGroups map[string]android.Paths) {
+ if len(files) > 0 {
+ subsetName := osName + "_subset"
+ allGroups[osName] = append(allGroups[osName], files...)
+ // Now include only the first variant in the subsetGroups.
+ // If clang and clang-tidy get faster, we might include more variants.
+ if _, found := subsetGroups[subsetName]; !found {
+ subsetGroups[subsetName] = files
+ }
+ }
+}
+
+// Add an all-OS group, with groupName, to include all os-specific phony targets.
+func addAllOSGroup(ctx android.SingletonContext, module android.Module, phonyTargetGroups map[string]android.Paths, groupName string, objTidyName string) {
+ if len(phonyTargetGroups) > 0 {
+ var targets android.Paths
+ for group, _ := range phonyTargetGroups {
+ targets = append(targets, android.PathForPhony(ctx, objTidyModuleGroupName(module, group, objTidyName)))
+ }
+ phonyTargetGroups[groupName] = targets
+ }
+}
+
+// Create one phony targets for each group and add them to the targetGroups.
+func genObjTidyPhonyTargets(ctx android.SingletonContext, module android.Module, objTidyName string, fileGroups map[string]android.Paths, targetGroups map[string]android.Path) {
+ for group, files := range fileGroups {
+ groupName := objTidyModuleGroupName(module, group, objTidyName)
+ ctx.Phony(groupName, files...)
+ targetGroups[group] = android.PathForPhony(ctx, groupName)
+ }
+}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index c9bf958..e7343a2 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -110,6 +110,7 @@
type hostToolDependencyTag struct {
blueprint.BaseDependencyTag
+ android.LicenseAnnotationToolchainDependencyTag
label string
}
type generatorProperties struct {
diff --git a/java/android_manifest.go b/java/android_manifest.go
index 3a1f5fc..f29d8ad 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -44,13 +44,14 @@
"args", "libs")
// targetSdkVersion for manifest_fixer
-// When TARGET_BUILD_APPS is not empty, this method returns the unreleased(future) API level
+// When TARGET_BUILD_APPS is not empty, this method returns 10000 for modules targeting an unreleased SDK
// This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK
func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext android.SdkContext) string {
- if ctx.Config().UnbundledBuildApps() {
+ targetSdkVersionSpec := sdkContext.TargetSdkVersion(ctx)
+ if ctx.Config().UnbundledBuildApps() && targetSdkVersionSpec.ApiLevel.IsPreview() {
return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt())
}
- targetSdkVersion, err := sdkContext.TargetSdkVersion(ctx).EffectiveVersionString(ctx)
+ targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx)
if err != nil {
ctx.ModuleErrorf("invalid targetSdkVersion: %s", err)
}
@@ -105,6 +106,7 @@
}
var deps android.Paths
targetSdkVersion := targetSdkVersionForManifestFixer(ctx, sdkContext)
+
if UseApiFingerprint(ctx) && ctx.ModuleName() != "framework-res" {
targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", ApiFingerprintPath(ctx).String())
deps = append(deps, ApiFingerprintPath(ctx))
diff --git a/java/app_test.go b/java/app_test.go
index 0aae928..4da7c3d 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -2873,3 +2873,76 @@
t.Errorf("App does not use library proguard config")
}
}
+
+func TestTargetSdkVersionManifestFixer(t *testing.T) {
+ platform_sdk_codename := "Tiramisu"
+ testCases := []struct {
+ name string
+ targetSdkVersionInBp string
+ targetSdkVersionExpected string
+ unbundledBuild bool
+ }{
+ {
+ name: "Non-Unbundled build: Android.bp has targetSdkVersion",
+ targetSdkVersionInBp: "30",
+ targetSdkVersionExpected: "30",
+ unbundledBuild: false,
+ },
+ {
+ name: "Unbundled build: Android.bp has targetSdkVersion",
+ targetSdkVersionInBp: "30",
+ targetSdkVersionExpected: "30",
+ unbundledBuild: true,
+ },
+ {
+ name: "Non-Unbundled build: Android.bp has targetSdkVersion equal to platform_sdk_codename",
+ targetSdkVersionInBp: platform_sdk_codename,
+ targetSdkVersionExpected: platform_sdk_codename,
+ unbundledBuild: false,
+ },
+ {
+ name: "Unbundled build: Android.bp has targetSdkVersion equal to platform_sdk_codename",
+ targetSdkVersionInBp: platform_sdk_codename,
+ targetSdkVersionExpected: "10000",
+ unbundledBuild: true,
+ },
+
+ {
+ name: "Non-Unbundled build: Android.bp has no targetSdkVersion",
+ targetSdkVersionExpected: platform_sdk_codename,
+ unbundledBuild: false,
+ },
+ {
+ name: "Unbundled build: Android.bp has no targetSdkVersion",
+ targetSdkVersionExpected: "10000",
+ unbundledBuild: true,
+ },
+ }
+ for _, testCase := range testCases {
+ bp := fmt.Sprintf(`
+ android_app {
+ name: "foo",
+ sdk_version: "current",
+ target_sdk_version: "%v",
+ }
+ `, testCase.targetSdkVersionInBp)
+ fixture := android.GroupFixturePreparers(
+ prepareForJavaTest,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ // explicitly set platform_sdk_codename to make the test deterministic
+ variables.Platform_sdk_codename = &platform_sdk_codename
+ variables.Platform_version_active_codenames = []string{platform_sdk_codename}
+ // create a non-empty list if unbundledBuild==true
+ if testCase.unbundledBuild {
+ variables.Unbundled_build_apps = []string{"apex_a", "apex_b"}
+ }
+ }),
+ )
+
+ result := fixture.RunTestWithBp(t, bp)
+ foo := result.ModuleForTests("foo", "android_common")
+
+ manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args
+ android.AssertStringEquals(t, testCase.name, testCase.targetSdkVersionExpected, manifestFixerArgs["targetSdkVersion"])
+ }
+}
diff --git a/java/base.go b/java/base.go
index 2f90db2..c0da215 100644
--- a/java/base.go
+++ b/java/base.go
@@ -1643,8 +1643,7 @@
}
// Implements android.ApexModule
-func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
- sdkVersion android.ApiLevel) error {
+func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
sdkSpec := j.MinSdkVersion(ctx)
if !sdkSpec.Specified() {
return fmt.Errorf("min_sdk_version is not specified")
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index df1e121..bfe895c 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -594,8 +594,11 @@
if imageConfig != nil {
info.modules = imageConfig.modules
- info.profilePathOnHost = imageConfig.profilePathOnHost
- info.profileInstallPathInApex = imageConfig.profileInstallPathInApex
+ global := dexpreopt.GetGlobalConfig(ctx)
+ if !global.DisableGenerateProfile {
+ info.profilePathOnHost = imageConfig.profilePathOnHost
+ info.profileInstallPathInApex = imageConfig.profileInstallPathInApex
+ }
}
info.bootImageFilesByArch = bootImageFilesByArch
diff --git a/java/java.go b/java/java.go
index a9f3d1a..e7b1f4f 100644
--- a/java/java.go
+++ b/java/java.go
@@ -270,6 +270,9 @@
type dependencyTag struct {
blueprint.BaseDependencyTag
name string
+
+ // True if the dependency is relinked at runtime.
+ runtimeLinked bool
}
// installDependencyTag is a dependency tag that is annotated to cause the installed files of the
@@ -280,6 +283,15 @@
name string
}
+func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
+ if d.runtimeLinked {
+ return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
+ }
+ return nil
+}
+
+var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
+
type usesLibraryDependencyTag struct {
dependencyTag
@@ -296,10 +308,13 @@
func makeUsesLibraryDependencyTag(sdkVersion int, optional bool, implicit bool) usesLibraryDependencyTag {
return usesLibraryDependencyTag{
- dependencyTag: dependencyTag{name: fmt.Sprintf("uses-library-%d", sdkVersion)},
- sdkVersion: sdkVersion,
- optional: optional,
- implicit: implicit,
+ dependencyTag: dependencyTag{
+ name: fmt.Sprintf("uses-library-%d", sdkVersion),
+ runtimeLinked: true,
+ },
+ sdkVersion: sdkVersion,
+ optional: optional,
+ implicit: implicit,
}
}
@@ -310,22 +325,22 @@
var (
dataNativeBinsTag = dependencyTag{name: "dataNativeBins"}
staticLibTag = dependencyTag{name: "staticlib"}
- libTag = dependencyTag{name: "javalib"}
- java9LibTag = dependencyTag{name: "java9lib"}
+ libTag = dependencyTag{name: "javalib", runtimeLinked: true}
+ java9LibTag = dependencyTag{name: "java9lib", runtimeLinked: true}
pluginTag = dependencyTag{name: "plugin"}
errorpronePluginTag = dependencyTag{name: "errorprone-plugin"}
exportedPluginTag = dependencyTag{name: "exported-plugin"}
- bootClasspathTag = dependencyTag{name: "bootclasspath"}
- systemModulesTag = dependencyTag{name: "system modules"}
+ bootClasspathTag = dependencyTag{name: "bootclasspath", runtimeLinked: true}
+ systemModulesTag = dependencyTag{name: "system modules", runtimeLinked: true}
frameworkResTag = dependencyTag{name: "framework-res"}
- kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
- kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
+ kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib", runtimeLinked: true}
+ kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations", runtimeLinked: true}
kotlinPluginTag = dependencyTag{name: "kotlin-plugin"}
proguardRaiseTag = dependencyTag{name: "proguard-raise"}
certificateTag = dependencyTag{name: "certificate"}
instrumentationForTag = dependencyTag{name: "instrumentation_for"}
extraLintCheckTag = dependencyTag{name: "extra-lint-check"}
- jniLibTag = dependencyTag{name: "jnilib"}
+ jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true}
syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}
jniInstallTag = installDependencyTag{name: "jni install"}
binaryInstallTag = installDependencyTag{name: "binary install"}
@@ -434,6 +449,12 @@
return normalizeJavaVersion(ctx, javaVersion)
} else if ctx.Device() {
return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx))
+ } else if ctx.Config().IsEnvTrue("EXPERIMENTAL_TARGET_JAVA_VERSION_11") {
+ // Temporary experimental flag to be able to try and build with
+ // java version 11 options. The flag, if used, just sets Java
+ // 11 as the default version, leaving any components that
+ // target an older version intact.
+ return JAVA_VERSION_11
} else {
return JAVA_VERSION_9
}
diff --git a/java/sdk.go b/java/sdk.go
index e6bf220..de7070e 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -55,6 +55,12 @@
return JAVA_VERSION_7
} else if sdk.FinalOrFutureInt() <= 29 {
return JAVA_VERSION_8
+ } else if ctx.Config().IsEnvTrue("EXPERIMENTAL_TARGET_JAVA_VERSION_11") {
+ // Temporary experimental flag to be able to try and build with
+ // java version 11 options. The flag, if used, just sets Java
+ // 11 as the default version, leaving any components that
+ // target an older version intact.
+ return JAVA_VERSION_11
} else {
return JAVA_VERSION_9
}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 3065d57..de0d796 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1129,6 +1129,22 @@
return generatedScopes
}
+var _ android.ModuleWithMinSdkVersionCheck = (*SdkLibrary)(nil)
+
+func (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) {
+ android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx).ApiLevel, func(c android.ModuleContext, do android.PayloadDepsCallback) {
+ ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
+ isExternal := !module.depIsInSameApex(ctx, child)
+ if am, ok := child.(android.ApexModule); ok {
+ if !do(ctx, parent, am, isExternal) {
+ return false
+ }
+ }
+ return !isExternal
+ })
+ })
+}
+
type sdkLibraryComponentTag struct {
blueprint.BaseDependencyTag
name string
@@ -1206,14 +1222,23 @@
func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
paths, err := module.commonOutputFiles(tag)
- if paths == nil && err == nil {
- return module.Library.OutputFiles(tag)
- } else {
+ if paths != nil || err != nil {
return paths, err
}
+ if module.requiresRuntimeImplementationLibrary() {
+ return module.Library.OutputFiles(tag)
+ }
+ if tag == "" {
+ return nil, nil
+ }
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ if proptools.String(module.deviceProperties.Min_sdk_version) != "" {
+ module.CheckMinSdkVersion(ctx)
+ }
+
module.generateCommonBuildActions(ctx)
// Only build an implementation library if required.
@@ -2605,12 +2630,12 @@
func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
if module.hideApexVariantFromMake {
- return []android.AndroidMkEntries{android.AndroidMkEntries{
+ return []android.AndroidMkEntries{{
Disabled: true,
}}
}
- return []android.AndroidMkEntries{android.AndroidMkEntries{
+ return []android.AndroidMkEntries{{
Class: "ETC",
OutputFile: android.OptionalPathForPath(module.outputFilePath),
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index 2271573..f3a19e9 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -1140,3 +1140,87 @@
})
}
}
+
+func TestSdkLibrary_CheckMinSdkVersion(t *testing.T) {
+ preparer := android.GroupFixturePreparers(
+ PrepareForTestWithJavaBuildComponents,
+ PrepareForTestWithJavaDefaultModules,
+ PrepareForTestWithJavaSdkLibraryFiles,
+ )
+
+ preparer.RunTestWithBp(t, `
+ java_sdk_library {
+ name: "sdklib",
+ srcs: ["a.java"],
+ static_libs: ["util"],
+ min_sdk_version: "30",
+ unsafe_ignore_missing_latest_api: true,
+ }
+
+ java_library {
+ name: "util",
+ srcs: ["a.java"],
+ min_sdk_version: "30",
+ }
+ `)
+
+ preparer.
+ RunTestWithBp(t, `
+ java_sdk_library {
+ name: "sdklib",
+ srcs: ["a.java"],
+ libs: ["util"],
+ impl_only_libs: ["util"],
+ stub_only_libs: ["util"],
+ stub_only_static_libs: ["util"],
+ min_sdk_version: "30",
+ unsafe_ignore_missing_latest_api: true,
+ }
+
+ java_library {
+ name: "util",
+ srcs: ["a.java"],
+ }
+ `)
+
+ preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "util".*should support min_sdk_version\(30\)`)).
+ RunTestWithBp(t, `
+ java_sdk_library {
+ name: "sdklib",
+ srcs: ["a.java"],
+ static_libs: ["util"],
+ min_sdk_version: "30",
+ unsafe_ignore_missing_latest_api: true,
+ }
+
+ java_library {
+ name: "util",
+ srcs: ["a.java"],
+ min_sdk_version: "31",
+ }
+ `)
+
+ preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "another_util".*should support min_sdk_version\(30\)`)).
+ RunTestWithBp(t, `
+ java_sdk_library {
+ name: "sdklib",
+ srcs: ["a.java"],
+ static_libs: ["util"],
+ min_sdk_version: "30",
+ unsafe_ignore_missing_latest_api: true,
+ }
+
+ java_library {
+ name: "util",
+ srcs: ["a.java"],
+ static_libs: ["another_util"],
+ min_sdk_version: "30",
+ }
+
+ java_library {
+ name: "another_util",
+ srcs: ["a.java"],
+ min_sdk_version: "31",
+ }
+ `)
+}
diff --git a/mk2rbc/expr.go b/mk2rbc/expr.go
index ec0b279..81b31c7 100644
--- a/mk2rbc/expr.go
+++ b/mk2rbc/expr.go
@@ -85,6 +85,31 @@
s.emit(gctx)
}
+// Boolean literal
+type boolLiteralExpr struct {
+ literal bool
+}
+
+func (b *boolLiteralExpr) eval(_ map[string]starlarkExpr) (res starlarkExpr, same bool) {
+ return b, true
+}
+
+func (b *boolLiteralExpr) emit(gctx *generationContext) {
+ if b.literal {
+ gctx.write("True")
+ } else {
+ gctx.write("False")
+ }
+}
+
+func (_ *boolLiteralExpr) typ() starlarkType {
+ return starlarkTypeBool
+}
+
+func (b *boolLiteralExpr) emitListVarCopy(gctx *generationContext) {
+ b.emit(gctx)
+}
+
// interpolateExpr represents Starlark's interpolation operator <string> % list
// we break <string> into a list of chunks, i.e., "first%second%third" % (X, Y)
// will have chunks = ["first", "second", "third"] and args = [X, Y]
@@ -617,6 +642,55 @@
cx.emit(gctx)
}
+type ifExpr struct {
+ condition starlarkExpr
+ ifTrue starlarkExpr
+ ifFalse starlarkExpr
+}
+
+func (i *ifExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) {
+ cond, condSame := i.condition.eval(valueMap)
+ t, tSame := i.ifTrue.eval(valueMap)
+ f, fSame := i.ifFalse.eval(valueMap)
+ same = condSame && tSame && fSame
+ if same {
+ return i, same
+ } else {
+ return &ifExpr{
+ condition: cond,
+ ifTrue: t,
+ ifFalse: f,
+ }, same
+ }
+}
+
+func (i *ifExpr) emit(gctx *generationContext) {
+ gctx.write("(")
+ i.ifTrue.emit(gctx)
+ gctx.write(" if ")
+ i.condition.emit(gctx)
+ gctx.write(" else ")
+ i.ifFalse.emit(gctx)
+ gctx.write(")")
+}
+
+func (i *ifExpr) typ() starlarkType {
+ tType := i.ifTrue.typ()
+ fType := i.ifFalse.typ()
+ if tType != fType && tType != starlarkTypeUnknown && fType != starlarkTypeUnknown {
+ panic("Conflicting types in if expression")
+ }
+ if tType != starlarkTypeUnknown {
+ return tType
+ } else {
+ return fType
+ }
+}
+
+func (i *ifExpr) emitListVarCopy(gctx *generationContext) {
+ i.emit(gctx)
+}
+
type badExpr struct {
errorLocation ErrorLocation
message string
diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go
index cade4d2..d5ff181 100644
--- a/mk2rbc/mk2rbc.go
+++ b/mk2rbc/mk2rbc.go
@@ -112,6 +112,7 @@
"filter-out": {baseName + ".filter_out", starlarkTypeList, hiddenArgNone},
"firstword": {"!firstword", starlarkTypeString, hiddenArgNone},
"get-vendor-board-platforms": {"!get-vendor-board-platforms", starlarkTypeList, hiddenArgNone}, // internal macro, used by is-board-platform, etc.
+ "if": {"!if", starlarkTypeUnknown, hiddenArgNone},
"info": {baseName + ".mkinfo", starlarkTypeVoid, hiddenArgNone},
"is-android-codename": {"!is-android-codename", starlarkTypeBool, hiddenArgNone}, // unused by product config
"is-android-codename-in-list": {"!is-android-codename-in-list", starlarkTypeBool, hiddenArgNone}, // unused by product config
@@ -1331,6 +1332,34 @@
// TODO (asmundak): if we find many, maybe handle them.
return ctx.newBadExpr(node, "SOONG_CONFIG_ variables cannot be referenced, use soong_config_get instead: %s", refDump)
}
+ // Handle substitution references: https://www.gnu.org/software/make/manual/html_node/Substitution-Refs.html
+ if strings.Contains(refDump, ":") {
+ parts := strings.SplitN(refDump, ":", 2)
+ substParts := strings.SplitN(parts[1], "=", 2)
+ if len(substParts) < 2 || strings.Count(substParts[0], "%") > 1 {
+ return ctx.newBadExpr(node, "Invalid substitution reference")
+ }
+ if !strings.Contains(substParts[0], "%") {
+ if strings.Contains(substParts[1], "%") {
+ return ctx.newBadExpr(node, "A substitution reference must have a %% in the \"before\" part of the substitution if it has one in the \"after\" part.")
+ }
+ substParts[0] = "%" + substParts[0]
+ substParts[1] = "%" + substParts[1]
+ }
+ v := ctx.addVariable(parts[0])
+ if v == nil {
+ return ctx.newBadExpr(node, "unknown variable %s", refDump)
+ }
+ return &callExpr{
+ name: "patsubst",
+ returnType: knownFunctions["patsubst"].returnType,
+ args: []starlarkExpr{
+ &stringLiteralExpr{literal: substParts[0]},
+ &stringLiteralExpr{literal: substParts[1]},
+ &variableRefExpr{v, ctx.lastAssignment(v.name()) != nil},
+ },
+ }
+ }
if v := ctx.addVariable(refDump); v != nil {
return &variableRefExpr{v, ctx.lastAssignment(v.name()) != nil}
}
@@ -1368,6 +1397,8 @@
return ctx.newBadExpr(node, "cannot handle invoking %s", expr.name)
}
switch expr.name {
+ case "if":
+ return ctx.parseIfFunc(node, args)
case "word":
return ctx.parseWordFunc(node, args)
case "firstword", "lastword":
@@ -1423,6 +1454,35 @@
}
}
+func (ctx *parseContext) parseIfFunc(node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
+ words := args.Split(",")
+ if len(words) != 2 && len(words) != 3 {
+ return ctx.newBadExpr(node, "if function should have 2 or 3 arguments, found "+strconv.Itoa(len(words)))
+ }
+ condition := ctx.parseMakeString(node, words[0])
+ ifTrue := ctx.parseMakeString(node, words[1])
+ var ifFalse starlarkExpr
+ if len(words) == 3 {
+ ifFalse = ctx.parseMakeString(node, words[2])
+ } else {
+ switch ifTrue.typ() {
+ case starlarkTypeList:
+ ifFalse = &listExpr{items: []starlarkExpr{}}
+ case starlarkTypeInt:
+ ifFalse = &intLiteralExpr{literal: 0}
+ case starlarkTypeBool:
+ ifFalse = &boolLiteralExpr{literal: false}
+ default:
+ ifFalse = &stringLiteralExpr{literal: ""}
+ }
+ }
+ return &ifExpr{
+ condition,
+ ifTrue,
+ ifFalse,
+ }
+}
+
func (ctx *parseContext) parseWordFunc(node mkparser.Node, args *mkparser.MakeString) starlarkExpr {
words := args.Split(",")
if len(words) != 2 {
diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go
index fa33e75..78444c9 100644
--- a/mk2rbc/mk2rbc_test.go
+++ b/mk2rbc/mk2rbc_test.go
@@ -1091,6 +1091,46 @@
pass
`,
},
+ {
+ desc: "if expression",
+ mkname: "product.mk",
+ in: `
+TEST_VAR := foo
+TEST_VAR_LIST := foo
+TEST_VAR_LIST += bar
+TEST_VAR_2 := $(if $(TEST_VAR),bar)
+TEST_VAR_3 := $(if $(TEST_VAR),bar,baz)
+TEST_VAR_3 := $(if $(TEST_VAR),$(TEST_VAR_LIST))
+`,
+ expected: `load("//build/make/core:product_config.rbc", "rblf")
+
+def init(g, handle):
+ cfg = rblf.cfg(handle)
+ g["TEST_VAR"] = "foo"
+ g["TEST_VAR_LIST"] = ["foo"]
+ g["TEST_VAR_LIST"] += ["bar"]
+ g["TEST_VAR_2"] = ("bar" if g["TEST_VAR"] else "")
+ g["TEST_VAR_3"] = ("bar" if g["TEST_VAR"] else "baz")
+ g["TEST_VAR_3"] = (g["TEST_VAR_LIST"] if g["TEST_VAR"] else [])
+`,
+ },
+ {
+ desc: "substitution references",
+ mkname: "product.mk",
+ in: `
+SOURCES := foo.c bar.c
+OBJECTS := $(SOURCES:.c=.o)
+OBJECTS2 := $(SOURCES:%.c=%.o)
+`,
+ expected: `load("//build/make/core:product_config.rbc", "rblf")
+
+def init(g, handle):
+ cfg = rblf.cfg(handle)
+ g["SOURCES"] = "foo.c bar.c"
+ g["OBJECTS"] = rblf.mkpatsubst("%.c", "%.o", g["SOURCES"])
+ g["OBJECTS2"] = rblf.mkpatsubst("%.c", "%.o", g["SOURCES"])
+`,
+ },
}
var known_variables = []struct {
diff --git a/rust/bindgen.go b/rust/bindgen.go
index 32d02e4..5e1b4b7 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -30,7 +30,7 @@
defaultBindgenFlags = []string{""}
// bindgen should specify its own Clang revision so updating Clang isn't potentially blocked on bindgen failures.
- bindgenClangVersion = "clang-r433403"
+ bindgenClangVersion = "clang-r437112"
_ = pctx.VariableFunc("bindgenClangVersion", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("LLVM_BINDGEN_PREBUILTS_VERSION"); override != "" {
diff --git a/rust/config/global.go b/rust/config/global.go
index 23384e5..2821e31 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -41,7 +41,7 @@
}
GlobalRustFlags = []string{
- "--remap-path-prefix $$(pwd)=",
+ "-Z remap-cwd-prefix=.",
"-C codegen-units=1",
"-C debuginfo=2",
"-C opt-level=3",
diff --git a/rust/project_json.go b/rust/project_json.go
index ae48312..fe259d6 100644
--- a/rust/project_json.go
+++ b/rust/project_json.go
@@ -211,6 +211,8 @@
comp = c.binaryDecorator.baseCompiler
case *procMacroDecorator:
comp = c.baseCompiler
+ case *toolchainLibraryDecorator:
+ comp = c.baseCompiler
default:
return nil, nil, false
}
diff --git a/rust/rust.go b/rust/rust.go
index b575c7a..300c0f5 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -969,6 +969,7 @@
name string
library bool
procMacro bool
+ dynamic bool
}
// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
@@ -979,10 +980,19 @@
var _ android.InstallNeededDependencyTag = dependencyTag{}
+func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
+ if d.library && d.dynamic {
+ return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
+ }
+ return nil
+}
+
+var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
+
var (
customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
rlibDepTag = dependencyTag{name: "rlibTag", library: true}
- dylibDepTag = dependencyTag{name: "dylib", library: true}
+ dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true}
procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
sourceDepTag = dependencyTag{name: "source"}
diff --git a/scripts/check_boot_jars/package_allowed_list.txt b/scripts/check_boot_jars/package_allowed_list.txt
index ed63651..a02c195 100644
--- a/scripts/check_boot_jars/package_allowed_list.txt
+++ b/scripts/check_boot_jars/package_allowed_list.txt
@@ -72,6 +72,7 @@
jdk\.internal
jdk\.internal\.math
jdk\.internal\.misc
+jdk\.internal\.ref
jdk\.internal\.reflect
jdk\.internal\.util
jdk\.internal\.vm\.annotation
diff --git a/tests/androidmk_test.sh b/tests/androidmk_test.sh
new file mode 100755
index 0000000..331dc77
--- /dev/null
+++ b/tests/androidmk_test.sh
@@ -0,0 +1,135 @@
+#!/bin/bash -eu
+
+set -o pipefail
+
+# How to run: bash path-to-script/androidmk_test.sh
+# Tests of converting license functionality of the androidmk tool
+REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)"
+$REAL_TOP/build/soong/soong_ui.bash --make-mode androidmk
+
+source "$(dirname "$0")/lib.sh"
+
+# Expect to create a new license module
+function test_rewrite_license_property_inside_current_directory {
+ setup
+
+ # Create an Android.mk file
+ mkdir -p a/b
+ cat > a/b/Android.mk <<'EOF'
+include $(CLEAR_VARS)
+LOCAL_MODULE := foo
+LOCAL_LICENSE_KINDS := license_kind1 license_kind2
+LOCAL_LICENSE_CONDITIONS := license_condition
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/license_notice1 $(LOCAL_PATH)/license_notice2
+include $(BUILD_PACKAGE)
+EOF
+
+ # Create an expected Android.bp file for the module "foo"
+ cat > a/b/Android.bp <<'EOF'
+package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: [
+ "a_b_license",
+ ],
+}
+
+license {
+ name: "a_b_license",
+ visibility: [":__subpackages__"],
+ license_kinds: [
+ "license_kind1",
+ "license_kind2",
+ ],
+ license_text: [
+ "license_notice1",
+ "license_notice2",
+ ],
+}
+
+android_app {
+ name: "foo",
+}
+EOF
+
+ run_androidmk_test "a/b/Android.mk" "a/b/Android.bp"
+}
+
+# Expect to reference to an existing license module
+function test_rewrite_license_property_outside_current_directory {
+ setup
+
+ # Create an Android.mk file
+ mkdir -p a/b/c/d
+ cat > a/b/c/d/Android.mk <<'EOF'
+include $(CLEAR_VARS)
+LOCAL_MODULE := foo
+LOCAL_LICENSE_KINDS := license_kind1 license_kind2
+LOCAL_LICENSE_CONDITIONS := license_condition
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../license_notice1 $(LOCAL_PATH)/../../license_notice2
+include $(BUILD_PACKAGE)
+EOF
+
+ # Create an expected (input) Android.bp file at a/b/
+ cat > a/b/Android.bp <<'EOF'
+package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: [
+ "a_b_license",
+ ],
+}
+
+license {
+ name: "a_b_license",
+ visibility: [":__subpackages__"],
+ license_kinds: [
+ "license_kind1",
+ "license_kind2",
+ ],
+ license_text: [
+ "license_notice1",
+ "license_notice2",
+ ],
+}
+
+android_app {
+ name: "bar",
+}
+EOF
+
+ # Create an expected (output) Android.bp file for the module "foo"
+ cat > a/b/c/d/Android.bp <<'EOF'
+package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: [
+ "a_b_license",
+ ],
+}
+
+android_app {
+ name: "foo",
+}
+EOF
+
+ run_androidmk_test "a/b/c/d/Android.mk" "a/b/c/d/Android.bp"
+}
+
+run_androidmk_test () {
+ export ANDROID_BUILD_TOP="$MOCK_TOP"
+
+ local out=$($REAL_TOP/*/host/*/bin/androidmk "$1")
+ local expected=$(<"$2")
+
+ if [[ "$out" != "$expected" ]]; then
+ ANDROID_BUILD_TOP="$REAL_TOP"
+ cleanup_mock_top
+ fail "The output is not the same as the expected"
+ fi
+
+ ANDROID_BUILD_TOP="$REAL_TOP"
+ cleanup_mock_top
+ echo "Succeeded"
+}
+
+test_rewrite_license_property_inside_current_directory
+
+test_rewrite_license_property_outside_current_directory
diff --git a/tests/run_integration_tests.sh b/tests/run_integration_tests.sh
index b19949a..76a918b 100755
--- a/tests/run_integration_tests.sh
+++ b/tests/run_integration_tests.sh
@@ -3,6 +3,7 @@
set -o pipefail
TOP="$(readlink -f "$(dirname "$0")"/../../..)"
+"$TOP/build/soong/tests/androidmk_test.sh"
"$TOP/build/soong/tests/bootstrap_test.sh"
"$TOP/build/soong/tests/mixed_mode_test.sh"
"$TOP/build/soong/tests/bp2build_bazel_test.sh"
diff --git a/ui/terminal/simple_status.go b/ui/terminal/simple_status.go
index 936b275..3157813 100644
--- a/ui/terminal/simple_status.go
+++ b/ui/terminal/simple_status.go
@@ -22,32 +22,41 @@
)
type simpleStatusOutput struct {
- writer io.Writer
- formatter formatter
- keepANSI bool
+ writer io.Writer
+ formatter formatter
+ keepANSI bool
+ outputLevel status.MsgLevel
}
// NewSimpleStatusOutput returns a StatusOutput that represents the
// current build status similarly to Ninja's built-in terminal
// output.
-func NewSimpleStatusOutput(w io.Writer, formatter formatter, keepANSI bool) status.StatusOutput {
+func NewSimpleStatusOutput(w io.Writer, formatter formatter, keepANSI bool, quietBuild bool) status.StatusOutput {
+ level := status.StatusLvl
+ if quietBuild {
+ level = status.PrintLvl
+ }
return &simpleStatusOutput{
- writer: w,
- formatter: formatter,
- keepANSI: keepANSI,
+ writer: w,
+ formatter: formatter,
+ keepANSI: keepANSI,
+ outputLevel: level,
}
}
func (s *simpleStatusOutput) Message(level status.MsgLevel, message string) {
- if level >= status.StatusLvl {
+ if level >= s.outputLevel {
fmt.Fprintln(s.writer, s.formatter.message(level, message))
}
}
-func (s *simpleStatusOutput) StartAction(action *status.Action, counts status.Counts) {
+func (s *simpleStatusOutput) StartAction(_ *status.Action, _ status.Counts) {
}
func (s *simpleStatusOutput) FinishAction(result status.ActionResult, counts status.Counts) {
+ if s.outputLevel > status.StatusLvl {
+ return
+ }
str := result.Description
if str == "" {
str = result.Command
diff --git a/ui/terminal/status.go b/ui/terminal/status.go
index 2ad174f..ff0af47 100644
--- a/ui/terminal/status.go
+++ b/ui/terminal/status.go
@@ -29,9 +29,9 @@
func NewStatusOutput(w io.Writer, statusFormat string, forceSimpleOutput, quietBuild, forceKeepANSI bool) status.StatusOutput {
formatter := newFormatter(statusFormat, quietBuild)
- if !forceSimpleOutput && isSmartTerminal(w) {
- return NewSmartStatusOutput(w, formatter)
+ if forceSimpleOutput || quietBuild || !isSmartTerminal(w) {
+ return NewSimpleStatusOutput(w, formatter, forceKeepANSI, quietBuild)
} else {
- return NewSimpleStatusOutput(w, formatter, forceKeepANSI)
+ return NewSmartStatusOutput(w, formatter)
}
}