Merge "Remove libgcc toolchain libs for Android"
diff --git a/android/Android.bp b/android/Android.bp
index 773aa6a..a32e8f2 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -67,6 +67,7 @@
"rule_builder.go",
"sandbox.go",
"sdk.go",
+ "sdk_version.go",
"singleton.go",
"singleton_module.go",
"soong_config_modules.go",
diff --git a/android/apex.go b/android/apex.go
index 01ac9b3..7f9f0f5 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -809,8 +809,10 @@
"androidx.arch.core_core-common-nodeps": 29,
"androidx.collection_collection-nodeps": 29,
"androidx.collection_collection-ktx-nodeps": 30,
+ "androidx.concurrent_concurrent-futures-nodeps": 30,
"androidx.lifecycle_lifecycle-common-java8-nodeps": 30,
"androidx.lifecycle_lifecycle-common-nodeps": 29,
+ "androidx.room_room-common-nodeps": 30,
"androidx-constraintlayout_constraintlayout-solver-nodeps": 29,
"apache-commons-compress": 29,
"bouncycastle_ike_digests": 30,
@@ -820,6 +822,7 @@
"flatbuffer_headers": 30,
"framework-permission": 30,
"gemmlowp_headers": 30,
+ "guava-listenablefuture-prebuilt-jar": 30,
"ike-internals": 30,
"kotlinx-coroutines-android": 28,
"kotlinx-coroutines-android-nodeps": 30,
diff --git a/android/api_levels.go b/android/api_levels.go
index 2f6a9d2..9bc7e83 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -31,9 +31,9 @@
// ApiLevelFromUser or ApiLevelOrPanic.
//
// The different *types* of API levels are handled separately. Currently only
-// Java has these, and they're managed with the sdkKind enum of the sdkSpec. A
-// future cleanup should be to migrate sdkSpec to using ApiLevel instead of its
-// sdkVersion int, and to move sdkSpec into this package.
+// Java has these, and they're managed with the SdkKind enum of the SdkSpec. A
+// future cleanup should be to migrate SdkSpec to using ApiLevel instead of its
+// SdkVersion int, and to move SdkSpec into this package.
type ApiLevel struct {
// The string representation of the API level.
value string
diff --git a/android/arch.go b/android/arch.go
index 20b4ab0..3eff5d5 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -1709,3 +1709,90 @@
}
return archToProp
}
+
+// GetTargetProperties returns a map of OS target (e.g. android, windows) to the
+// values of the properties of the 'dst' struct that are specific to that OS
+// target.
+//
+// For example, passing a struct { Foo bool, Bar string } will return an
+// interface{} that can be type asserted back into the same struct, containing
+// the os-specific property value specified by the module if defined.
+//
+// While this looks similar to GetArchProperties, the internal representation of
+// the properties have a slightly different layout to warrant a standalone
+// lookup function.
+func (m *ModuleBase) GetTargetProperties(dst interface{}) map[OsType]interface{} {
+ // Return value of the arch types to the prop values for that arch.
+ osToProp := map[OsType]interface{}{}
+
+ // Nothing to do for non-OS/arch-specific modules.
+ if !m.ArchSpecific() {
+ return osToProp
+ }
+
+ // archProperties has the type of [][]interface{}. Looks complicated, so
+ // let's explain this step by step.
+ //
+ // Loop over the outer index, which determines the property struct that
+ // contains a matching set of properties in dst that we're interested in.
+ // For example, BaseCompilerProperties or BaseLinkerProperties.
+ for i := range m.archProperties {
+ if m.archProperties[i] == nil {
+ continue
+ }
+
+ // Iterate over the supported OS types
+ for _, os := range OsTypeList {
+ // e.g android, linux_bionic
+ field := os.Field
+
+ // If it's not nil, loop over the inner index, which determines the arch variant
+ // of the prop type. In an Android.bp file, this is like looping over:
+ //
+ // target: { android: { key: value, ... }, linux_bionic: { key: value, ... } }
+ for _, archProperties := range m.archProperties[i] {
+ archPropValues := reflect.ValueOf(archProperties).Elem()
+
+ // This is the archPropRoot struct. Traverse into the Targetnested struct.
+ src := archPropValues.FieldByName("Target").Elem()
+
+ // Step into non-nil pointers to structs in the src value.
+ if src.Kind() == reflect.Ptr {
+ if src.IsNil() {
+ continue
+ }
+ src = src.Elem()
+ }
+
+ // Find the requested field (e.g. android, linux_bionic) in the src struct.
+ src = src.FieldByName(field)
+
+ // Validation steps. We want valid non-nil pointers to structs.
+ if !src.IsValid() || src.IsNil() {
+ continue
+ }
+
+ if src.Kind() != reflect.Ptr || src.Elem().Kind() != reflect.Struct {
+ continue
+ }
+
+ // Clone the destination prop, since we want a unique prop struct per arch.
+ dstClone := reflect.New(reflect.ValueOf(dst).Elem().Type()).Interface()
+
+ // Copy the located property struct into the cloned destination property struct.
+ err := proptools.ExtendMatchingProperties([]interface{}{dstClone}, src.Interface(), nil, proptools.OrderReplace)
+ if err != nil {
+ // This is fine, it just means the src struct doesn't match.
+ continue
+ }
+
+ // Found the prop for the os, you have.
+ osToProp[os] = dstClone
+
+ // Go to the next prop.
+ break
+ }
+ }
+ }
+ return osToProp
+}
diff --git a/android/bazel.go b/android/bazel.go
index 51ff3cb..b2170be 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -108,6 +108,11 @@
type BazelConversionConfigEntry int
const (
+ // A sentinel value to be used as a key in Bp2BuildConfig for modules with
+ // no package path. This is also the module dir for top level Android.bp
+ // modules.
+ BP2BUILD_TOPLEVEL = "."
+
// iota + 1 ensures that the int value is not 0 when used in the Bp2buildAllowlist map,
// which can also mean that the key doesn't exist in a lookup.
@@ -169,9 +174,6 @@
"liblinker_debuggerd_stub", // ruperts@, cc_library_static, depends on //system/libbase
"libbionic_tests_headers_posix", // ruperts@, cc_library_static
"libc_dns", // ruperts@, cc_library_static
- "generated_android_ids", // cparsons@, genrule
- "note_memtag_heap_async", // cparsons@, cc_library_static
- "note_memtag_heap_sync", // cparsons@, cc_library_static
}
// Used for quicker lookups
@@ -224,10 +226,15 @@
func bp2buildDefaultTrueRecursively(packagePath string, config Bp2BuildConfig) bool {
ret := false
+ // Return exact matches in the config.
+ if config[packagePath] == Bp2BuildDefaultTrueRecursively {
+ return true
+ }
if config[packagePath] == Bp2BuildDefaultFalse {
return false
}
+ // If not, check for the config recursively.
packagePrefix := ""
// e.g. for x/y/z, iterate over x, x/y, then x/y/z, taking the final value from the allowlist.
for _, part := range strings.Split(packagePath, "/") {
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index abc793f..5b9d3bf 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -34,13 +34,6 @@
"android/soong/shared"
)
-type CqueryRequestType int
-
-const (
- getAllFiles CqueryRequestType = iota
- getAllFilesAndCcObjectFiles
-)
-
// Map key to describe bazel cquery requests.
type cqueryKey struct {
label string
@@ -270,13 +263,23 @@
cmdFlags = append(cmdFlags, labels...)
cmdFlags = append(cmdFlags, "--package_path=%workspace%/"+context.intermediatesDir())
cmdFlags = append(cmdFlags, "--profile="+shared.BazelMetricsFilename(context, runName))
- // Set default platforms to canonicalized values for mixed builds requests. If these are set
- // in the bazelrc, they will have values that are non-canonicalized, and thus be invalid.
- // The actual platform values here may be overridden by configuration transitions from the buildroot.
+
+ // Set default platforms to canonicalized values for mixed builds requests.
+ // If these are set in the bazelrc, they will have values that are
+ // non-canonicalized to @sourceroot labels, and thus be invalid when
+ // referenced from the buildroot.
+ //
+ // The actual platform values here may be overridden by configuration
+ // transitions from the buildroot.
cmdFlags = append(cmdFlags,
- fmt.Sprintf("--platforms=%s", canonicalizeLabel("//build/bazel/platforms:generic_x86_64")))
+ fmt.Sprintf("--platforms=%s", canonicalizeLabel("//build/bazel/platforms:android_x86_64")))
cmdFlags = append(cmdFlags,
fmt.Sprintf("--extra_toolchains=%s", canonicalizeLabel("//prebuilts/clang/host/linux-x86:all")))
+ // This should be parameterized on the host OS, but let's restrict to linux
+ // to keep things simple for now.
+ cmdFlags = append(cmdFlags,
+ fmt.Sprintf("--host_platform=%s", canonicalizeLabel("//build/bazel/platforms:linux_x86_64")))
+
// Explicitly disable downloading rules (such as canonical C++ and Java rules) from the network.
cmdFlags = append(cmdFlags, "--experimental_repository_disable_download")
cmdFlags = append(cmdFlags, extraFlags...)
@@ -328,7 +331,7 @@
def _config_node_transition_impl(settings, attr):
return {
- "//command_line_option:platforms": "@sourceroot//build/bazel/platforms:generic_%s" % attr.arch,
+ "//command_line_option:platforms": "@sourceroot//build/bazel/platforms:android_%s" % attr.arch,
}
_config_node_transition = transition(
@@ -471,7 +474,7 @@
return id_string + ">>" + %s(target)
`
- for _, requestType := range cquery.RequestTypes {
+ for requestType, _ := range requestTypeToCqueryIdEntries {
labelMapName := requestType.Name() + "_Labels"
functionName := requestType.Name() + "_Fn"
labelRegistrationMapSection += fmt.Sprintf(mapDeclarationFormatString,
@@ -504,10 +507,10 @@
platform_name = build_options(target)["//command_line_option:platforms"][0].name
if platform_name == "host":
return "HOST"
- elif not platform_name.startswith("generic_"):
- fail("expected platform name of the form 'generic_<arch>', but was " + str(platforms))
+ elif not platform_name.startswith("android_"):
+ fail("expected platform name of the form 'android_<arch>', but was " + str(platforms))
return "UNKNOWN"
- return platform_name[len("generic_"):]
+ return platform_name[len("android_"):]
def format(target):
id_string = str(target.label) + "|" + get_arch(target)
@@ -678,7 +681,7 @@
// Register bazel-owned build statements (obtained from the aquery invocation).
for index, buildStatement := range ctx.Config().BazelContext.BuildStatementsToRegister() {
if len(buildStatement.Command) < 1 {
- panic(fmt.Sprintf("unhandled build statement: %s", buildStatement))
+ panic(fmt.Sprintf("unhandled build statement: %v", buildStatement))
}
rule := NewRuleBuilder(pctx, ctx)
cmd := rule.Command()
@@ -692,6 +695,10 @@
cmd.Implicit(PathForBazelOut(ctx, inputPath))
}
+ if depfile := buildStatement.Depfile; depfile != nil {
+ cmd.ImplicitDepFile(PathForBazelOut(ctx, *depfile))
+ }
+
// This is required to silence warnings pertaining to unexpected timestamps. Particularly,
// some Bazel builtins (such as files in the bazel_tools directory) have far-future
// timestamps. Without restat, Ninja would emit warnings that the input files of a
diff --git a/android/sdk_version.go b/android/sdk_version.go
new file mode 100644
index 0000000..5fdaa91
--- /dev/null
+++ b/android/sdk_version.go
@@ -0,0 +1,278 @@
+// 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"
+ "strconv"
+ "strings"
+)
+
+type SdkContext interface {
+ // SdkVersion returns SdkSpec that corresponds to the sdk_version property of the current module
+ SdkVersion() SdkSpec
+ // SystemModules returns the system_modules property of the current module, or an empty string if it is not set.
+ SystemModules() string
+ // MinSdkVersion returns SdkSpec that corresponds to the min_sdk_version property of the current module,
+ // or from sdk_version if it is not set.
+ MinSdkVersion() SdkSpec
+ // TargetSdkVersion returns the SdkSpec that corresponds to the target_sdk_version property of the current module,
+ // or from sdk_version if it is not set.
+ TargetSdkVersion() SdkSpec
+}
+
+// SdkKind represents a particular category of an SDK spec like public, system, test, etc.
+type SdkKind int
+
+const (
+ SdkInvalid SdkKind = iota
+ SdkNone
+ SdkCore
+ SdkCorePlatform
+ SdkPublic
+ SdkSystem
+ SdkTest
+ SdkModule
+ SdkSystemServer
+ SdkPrivate
+)
+
+// String returns the string representation of this SdkKind
+func (k SdkKind) String() string {
+ switch k {
+ case SdkPrivate:
+ return "private"
+ case SdkNone:
+ return "none"
+ case SdkPublic:
+ return "public"
+ case SdkSystem:
+ return "system"
+ case SdkTest:
+ return "test"
+ case SdkCore:
+ return "core"
+ case SdkCorePlatform:
+ return "core_platform"
+ case SdkModule:
+ return "module-lib"
+ case SdkSystemServer:
+ return "system-server"
+ default:
+ return "invalid"
+ }
+}
+
+// SdkSpec represents the kind and the version of an SDK for a module to build against
+type SdkSpec struct {
+ Kind SdkKind
+ ApiLevel ApiLevel
+ Raw string
+}
+
+func (s SdkSpec) String() string {
+ return fmt.Sprintf("%s_%s", s.Kind, s.ApiLevel)
+}
+
+// Valid checks if this SdkSpec is well-formed. Note however that true doesn't mean that the
+// specified SDK actually exists.
+func (s SdkSpec) Valid() bool {
+ return s.Kind != SdkInvalid
+}
+
+// Specified checks if this SdkSpec is well-formed and is not "".
+func (s SdkSpec) Specified() bool {
+ return s.Valid() && s.Kind != SdkPrivate
+}
+
+// whether the API surface is managed and versioned, i.e. has .txt file that
+// get frozen on SDK freeze and changes get reviewed by API council.
+func (s SdkSpec) Stable() bool {
+ if !s.Specified() {
+ return false
+ }
+ switch s.Kind {
+ case SdkNone:
+ // there is nothing to manage and version in this case; de facto stable API.
+ return true
+ case SdkCore, SdkPublic, SdkSystem, SdkModule, SdkSystemServer:
+ return true
+ case SdkCorePlatform, SdkTest, SdkPrivate:
+ return false
+ default:
+ panic(fmt.Errorf("unknown SdkKind=%v", s.Kind))
+ }
+ return false
+}
+
+// PrebuiltSdkAvailableForUnbundledBuilt tells whether this SdkSpec can have a prebuilt SDK
+// that can be used for unbundled builds.
+func (s SdkSpec) PrebuiltSdkAvailableForUnbundledBuild() bool {
+ // "", "none", and "core_platform" are not available for unbundled build
+ // as we don't/can't have prebuilt stub for the versions
+ return s.Kind != SdkPrivate && s.Kind != SdkNone && s.Kind != SdkCorePlatform
+}
+
+func (s SdkSpec) ForVendorPartition(ctx EarlyModuleContext) SdkSpec {
+ // If BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES has a numeric value,
+ // use it instead of "current" for the vendor partition.
+ currentSdkVersion := ctx.DeviceConfig().CurrentApiLevelForVendorModules()
+ if currentSdkVersion == "current" {
+ return s
+ }
+
+ if s.Kind == SdkPublic || s.Kind == SdkSystem {
+ if s.ApiLevel.IsCurrent() {
+ if i, err := strconv.Atoi(currentSdkVersion); err == nil {
+ apiLevel := uncheckedFinalApiLevel(i)
+ return SdkSpec{s.Kind, apiLevel, s.Raw}
+ }
+ panic(fmt.Errorf("BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES must be either \"current\" or a number, but was %q", currentSdkVersion))
+ }
+ }
+ return s
+}
+
+// UsePrebuilt determines whether prebuilt SDK should be used for this SdkSpec with the given context.
+func (s SdkSpec) UsePrebuilt(ctx EarlyModuleContext) bool {
+ if s.ApiLevel.IsCurrent() {
+ // "current" can be built from source and be from prebuilt SDK
+ return ctx.Config().AlwaysUsePrebuiltSdks()
+ } else if !s.ApiLevel.IsPreview() {
+ // validation check
+ if s.Kind != SdkPublic && s.Kind != SdkSystem && s.Kind != SdkTest && s.Kind != SdkModule {
+ panic(fmt.Errorf("prebuilt SDK is not not available for SdkKind=%q", s.Kind))
+ return false
+ }
+ // numbered SDKs are always from prebuilt
+ return true
+ }
+ // "", "none", "core_platform" fall here
+ return false
+}
+
+// EffectiveVersion converts an SdkSpec into the concrete ApiLevel that the module should use. For
+// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns
+// FutureApiLevel(10000).
+func (s SdkSpec) EffectiveVersion(ctx EarlyModuleContext) (ApiLevel, error) {
+ if !s.Valid() {
+ return s.ApiLevel, fmt.Errorf("invalid sdk version %q", s.Raw)
+ }
+
+ if ctx.DeviceSpecific() || ctx.SocSpecific() {
+ s = s.ForVendorPartition(ctx)
+ }
+ if !s.ApiLevel.IsPreview() {
+ return s.ApiLevel, nil
+ }
+ ret := ctx.Config().DefaultAppTargetSdk(ctx)
+ if ret.IsPreview() {
+ return FutureApiLevel, nil
+ }
+ return ret, nil
+}
+
+// EffectiveVersionString converts an SdkSpec into the concrete version string that the module
+// should use. For modules targeting an unreleased SDK (meaning it does not yet have a number)
+// it returns the codename (P, Q, R, etc.)
+func (s SdkSpec) EffectiveVersionString(ctx EarlyModuleContext) (string, error) {
+ if !s.Valid() {
+ return s.ApiLevel.String(), fmt.Errorf("invalid sdk version %q", s.Raw)
+ }
+
+ if ctx.DeviceSpecific() || ctx.SocSpecific() {
+ s = s.ForVendorPartition(ctx)
+ }
+ if !s.ApiLevel.IsPreview() {
+ return s.ApiLevel.String(), nil
+ }
+ return ctx.Config().DefaultAppTargetSdk(ctx).String(), nil
+}
+
+func SdkSpecFrom(str string) SdkSpec {
+ switch str {
+ // special cases first
+ case "":
+ return SdkSpec{SdkPrivate, NoneApiLevel, str}
+ case "none":
+ return SdkSpec{SdkNone, NoneApiLevel, str}
+ case "core_platform":
+ return SdkSpec{SdkCorePlatform, NoneApiLevel, str}
+ default:
+ // the syntax is [kind_]version
+ sep := strings.LastIndex(str, "_")
+
+ var kindString string
+ if sep == 0 {
+ return SdkSpec{SdkInvalid, NoneApiLevel, str}
+ } else if sep == -1 {
+ kindString = ""
+ } else {
+ kindString = str[0:sep]
+ }
+ versionString := str[sep+1 : len(str)]
+
+ var kind SdkKind
+ switch kindString {
+ case "":
+ kind = SdkPublic
+ case "core":
+ kind = SdkCore
+ case "system":
+ kind = SdkSystem
+ case "test":
+ kind = SdkTest
+ case "module":
+ kind = SdkModule
+ case "system_server":
+ kind = SdkSystemServer
+ default:
+ return SdkSpec{SdkInvalid, NoneApiLevel, str}
+ }
+
+ var apiLevel ApiLevel
+ if versionString == "current" {
+ apiLevel = FutureApiLevel
+ } else if i, err := strconv.Atoi(versionString); err == nil {
+ apiLevel = uncheckedFinalApiLevel(i)
+ } else {
+ return SdkSpec{SdkInvalid, apiLevel, str}
+ }
+
+ return SdkSpec{kind, apiLevel, str}
+ }
+}
+
+func (s SdkSpec) ValidateSystemSdk(ctx EarlyModuleContext) bool {
+ // Ensures that the specified system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor/product Java module)
+ // Assuming that BOARD_SYSTEMSDK_VERSIONS := 28 29,
+ // sdk_version of the modules in vendor/product that use system sdk must be either system_28, system_29 or system_current
+ if s.Kind != SdkSystem || s.ApiLevel.IsPreview() {
+ return true
+ }
+ allowedVersions := ctx.DeviceConfig().PlatformSystemSdkVersions()
+ if ctx.DeviceSpecific() || ctx.SocSpecific() || (ctx.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
+ systemSdkVersions := ctx.DeviceConfig().SystemSdkVersions()
+ if len(systemSdkVersions) > 0 {
+ allowedVersions = systemSdkVersions
+ }
+ }
+ if len(allowedVersions) > 0 && !InList(s.ApiLevel.String(), allowedVersions) {
+ ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
+ s.Raw, allowedVersions)
+ return false
+ }
+ return true
+}
diff --git a/apex/apex.go b/apex/apex.go
index c9e3f99..bad382a 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1049,6 +1049,16 @@
if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
apexBundleName := mctx.ModuleName()
mctx.CreateVariations(apexBundleName)
+ if strings.HasPrefix(apexBundleName, "com.android.art") {
+ // Create an alias from the platform variant. This is done to make
+ // test_for dependencies work for modules that are split by the APEX
+ // mutator, since test_for dependencies always go to the platform variant.
+ // This doesn't happen for normal APEXes that are disjunct, so only do
+ // this for the overlapping ART APEXes.
+ // TODO(b/183882457): Remove this if the test_for functionality is
+ // refactored to depend on the proper APEX variants instead of platform.
+ mctx.CreateAliasVariation("", apexBundleName)
+ }
} else if o, ok := mctx.Module().(*OverrideApex); ok {
apexBundleName := o.GetOverriddenModuleName()
if apexBundleName == "" {
@@ -1056,6 +1066,10 @@
return
}
mctx.CreateVariations(apexBundleName)
+ if strings.HasPrefix(apexBundleName, "com.android.art") {
+ // TODO(b/183882457): See note for CreateAliasVariation above.
+ mctx.CreateAliasVariation("", apexBundleName)
+ }
}
}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 98b40fd..87d551b 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -216,7 +216,7 @@
variables.Platform_sdk_codename = proptools.StringPtr("Q")
variables.Platform_sdk_final = proptools.BoolPtr(false)
variables.Platform_version_active_codenames = []string{"Q"}
- variables.Platform_vndk_version = proptools.StringPtr("VER")
+ variables.Platform_vndk_version = proptools.StringPtr("29")
}),
)
@@ -1366,13 +1366,13 @@
ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
- mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"]
- ensureContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so")
+ mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.29_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"]
+ ensureContains(t, mylibLdFlags, "libbar/android_vendor.29_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so")
for _, ver := range tc.shouldNotLink {
- ensureNotContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so")
+ ensureNotContains(t, mylibLdFlags, "libbar/android_vendor.29_arm64_armv8-a_shared_"+ver+"/libbar.so")
}
- mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"]
+ mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.29_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"]
ver := tc.shouldLink
if tc.shouldLink == "current" {
ver = strconv.Itoa(android.FutureApiLevelInt)
@@ -2411,8 +2411,8 @@
inputsString := strings.Join(inputsList, " ")
// ensure that the apex includes vendor variants of the direct and indirect deps
- ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib.so")
- ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib2.so")
+ ensureContains(t, inputsString, "android_vendor.29_arm64_armv8-a_shared_apex10000/mylib.so")
+ ensureContains(t, inputsString, "android_vendor.29_arm64_armv8-a_shared_apex10000/mylib2.so")
// ensure that the apex does not include core variants
ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so")
@@ -2558,7 +2558,7 @@
}
`)
- vendorVariant := "android_vendor.VER_arm64_armv8-a"
+ vendorVariant := "android_vendor.29_arm64_armv8-a"
ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld")
libs := names(ldRule.Args["libFlags"])
@@ -2607,7 +2607,7 @@
)
cflags := strings.Fields(
- ctx.ModuleForTests("foo", "android_product.VER_arm64_armv8-a_apex10000").Rule("cc").Args["cFlags"])
+ ctx.ModuleForTests("foo", "android_product.29_arm64_armv8-a_apex10000").Rule("cc").Args["cFlags"])
ensureListContains(t, cflags, "-D__ANDROID_VNDK__")
ensureListContains(t, cflags, "-D__ANDROID_APEX__")
ensureListContains(t, cflags, "-D__ANDROID_PRODUCT__")
@@ -3305,11 +3305,11 @@
"lib64/libvndk.so",
"lib64/libvndksp.so",
"lib64/libc++.so",
- "etc/llndk.libraries.VER.txt",
- "etc/vndkcore.libraries.VER.txt",
- "etc/vndksp.libraries.VER.txt",
- "etc/vndkprivate.libraries.VER.txt",
- "etc/vndkproduct.libraries.VER.txt",
+ "etc/llndk.libraries.29.txt",
+ "etc/vndkcore.libraries.29.txt",
+ "etc/vndksp.libraries.29.txt",
+ "etc/vndkprivate.libraries.29.txt",
+ "etc/vndkproduct.libraries.29.txt",
})
}
@@ -3495,7 +3495,7 @@
}
}
- assertApexName("com.android.vndk.vVER", "com.android.vndk.current")
+ assertApexName("com.android.vndk.v29", "com.android.vndk.current")
assertApexName("com.android.vndk.v28", "com.android.vndk.v28")
}
@@ -6947,6 +6947,56 @@
ensureLinkedLibIs("myprivlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so")
}
+func TestTestForForLibInOtherApex(t *testing.T) {
+ // This case is only allowed for known overlapping APEXes, i.e. the ART APEXes.
+ _ = testApex(t, `
+ apex {
+ name: "com.android.art",
+ key: "myapex.key",
+ native_shared_libs: ["mylib"],
+ updatable: false,
+ }
+
+ apex {
+ name: "com.android.art.debug",
+ key: "myapex.key",
+ native_shared_libs: ["mylib", "mytestlib"],
+ updatable: false,
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ cc_library {
+ name: "mylib",
+ srcs: ["mylib.cpp"],
+ system_shared_libs: [],
+ stl: "none",
+ stubs: {
+ versions: ["1"],
+ },
+ apex_available: ["com.android.art", "com.android.art.debug"],
+ }
+
+ cc_library {
+ name: "mytestlib",
+ srcs: ["mylib.cpp"],
+ system_shared_libs: [],
+ shared_libs: ["mylib"],
+ stl: "none",
+ apex_available: ["com.android.art.debug"],
+ test_for: ["com.android.art"],
+ }
+ `,
+ android.MockFS{
+ "system/sepolicy/apex/com.android.art-file_contexts": nil,
+ "system/sepolicy/apex/com.android.art.debug-file_contexts": nil,
+ }.AddToFixture())
+}
+
// TODO(jungjw): Move this to proptools
func intPtr(i int) *int {
return &i
diff --git a/apex/builder.go b/apex/builder.go
index da800d4..2df380b 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -950,6 +950,10 @@
if v := m.MinSdkVersion(); v != "" {
toMinSdkVersion = v
}
+ } else if m, ok := to.(interface{ MinSdkVersionString() string }); ok {
+ if v := m.MinSdkVersionString(); v != "" {
+ toMinSdkVersion = v
+ }
}
depInfos[to.Name()] = android.ApexModuleDepInfo{
diff --git a/apex/vndk_test.go b/apex/vndk_test.go
index 015283d..d580e5a 100644
--- a/apex/vndk_test.go
+++ b/apex/vndk_test.go
@@ -59,11 +59,11 @@
"lib/libc++.so",
"lib64/libvndksp.so",
"lib64/libc++.so",
- "etc/llndk.libraries.VER.txt",
- "etc/vndkcore.libraries.VER.txt",
- "etc/vndksp.libraries.VER.txt",
- "etc/vndkprivate.libraries.VER.txt",
- "etc/vndkproduct.libraries.VER.txt",
+ "etc/llndk.libraries.29.txt",
+ "etc/vndkcore.libraries.29.txt",
+ "etc/vndksp.libraries.29.txt",
+ "etc/vndkprivate.libraries.29.txt",
+ "etc/vndkproduct.libraries.29.txt",
})
}
@@ -111,7 +111,7 @@
// VNDK APEX doesn't create apex variant
files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
- ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
+ ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.29_arm_armv7-a-neon_shared/libfoo.so")
})
t.Run("VNDK APEX gathers only vendor variants even if product variants are available", func(t *testing.T) {
@@ -123,7 +123,7 @@
)
files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
- ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
+ ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.29_arm_armv7-a-neon_shared/libfoo.so")
})
t.Run("VNDK APEX supports coverage variants", func(t *testing.T) {
@@ -135,9 +135,9 @@
)
files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
- ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
+ ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.29_arm_armv7-a-neon_shared/libfoo.so")
files = getFiles(t, ctx, "com.android.vndk.current", "android_common_cov_image")
- ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared_cov/libfoo.so")
+ ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.29_arm_armv7-a-neon_shared_cov/libfoo.so")
})
}
diff --git a/bazel/aquery.go b/bazel/aquery.go
index c82b464..555f1dc 100644
--- a/bazel/aquery.go
+++ b/bazel/aquery.go
@@ -74,6 +74,7 @@
// with a Bazel action from Bazel's action graph.
type BuildStatement struct {
Command string
+ Depfile *string
OutputPaths []string
InputPaths []string
Env []KeyValuePair
@@ -133,12 +134,22 @@
continue
}
outputPaths := []string{}
+ var depfile *string
for _, outputId := range actionEntry.OutputIds {
outputPath, exists := artifactIdToPath[outputId]
if !exists {
return nil, fmt.Errorf("undefined outputId %d", outputId)
}
- outputPaths = append(outputPaths, outputPath)
+ ext := filepath.Ext(outputPath)
+ if ext == ".d" {
+ if depfile != nil {
+ return nil, fmt.Errorf("found multiple potential depfiles %q, %q", *depfile, outputPath)
+ } else {
+ depfile = &outputPath
+ }
+ } else {
+ outputPaths = append(outputPaths, outputPath)
+ }
}
inputPaths := []string{}
for _, inputDepSetId := range actionEntry.InputDepSetIds {
@@ -161,12 +172,13 @@
}
buildStatement := BuildStatement{
Command: strings.Join(proptools.ShellEscapeList(actionEntry.Arguments), " "),
+ Depfile: depfile,
OutputPaths: outputPaths,
InputPaths: inputPaths,
Env: actionEntry.EnvironmentVariables,
Mnemonic: actionEntry.Mnemonic}
if len(actionEntry.Arguments) < 1 {
- return nil, fmt.Errorf("received action with no command: [%s]", buildStatement)
+ return nil, fmt.Errorf("received action with no command: [%v]", buildStatement)
continue
}
buildStatements = append(buildStatements, buildStatement)
diff --git a/bazel/aquery_test.go b/bazel/aquery_test.go
index a48e083..fa8810f 100644
--- a/bazel/aquery_test.go
+++ b/bazel/aquery_test.go
@@ -393,6 +393,109 @@
assertError(t, err, "undefined path fragment id 3")
}
+func TestDepfiles(t *testing.T) {
+ const inputString = `
+{
+ "artifacts": [{
+ "id": 1,
+ "pathFragmentId": 1
+ }, {
+ "id": 2,
+ "pathFragmentId": 2
+ }, {
+ "id": 3,
+ "pathFragmentId": 3
+ }],
+ "actions": [{
+ "targetId": 1,
+ "actionKey": "x",
+ "mnemonic": "x",
+ "arguments": ["touch", "foo"],
+ "inputDepSetIds": [1],
+ "outputIds": [2, 3],
+ "primaryOutputId": 2
+ }],
+ "depSetOfFiles": [{
+ "id": 1,
+ "directArtifactIds": [1, 2, 3]
+ }],
+ "pathFragments": [{
+ "id": 1,
+ "label": "one"
+ }, {
+ "id": 2,
+ "label": "two"
+ }, {
+ "id": 3,
+ "label": "two.d"
+ }]
+}`
+
+ actual, err := AqueryBuildStatements([]byte(inputString))
+ if err != nil {
+ t.Errorf("Unexpected error %q", err)
+ }
+ if expected := 1; len(actual) != expected {
+ t.Fatalf("Expected %d build statements, got %d", expected, len(actual))
+ }
+
+ bs := actual[0]
+ expectedDepfile := "two.d"
+ if bs.Depfile == nil {
+ t.Errorf("Expected depfile %q, but there was none found", expectedDepfile)
+ } else if *bs.Depfile != expectedDepfile {
+ t.Errorf("Expected depfile %q, but got %q", expectedDepfile, *bs.Depfile)
+ }
+}
+
+func TestMultipleDepfiles(t *testing.T) {
+ const inputString = `
+{
+ "artifacts": [{
+ "id": 1,
+ "pathFragmentId": 1
+ }, {
+ "id": 2,
+ "pathFragmentId": 2
+ }, {
+ "id": 3,
+ "pathFragmentId": 3
+ }, {
+ "id": 4,
+ "pathFragmentId": 4
+ }],
+ "actions": [{
+ "targetId": 1,
+ "actionKey": "x",
+ "mnemonic": "x",
+ "arguments": ["touch", "foo"],
+ "inputDepSetIds": [1],
+ "outputIds": [2,3,4],
+ "primaryOutputId": 2
+ }],
+ "depSetOfFiles": [{
+ "id": 1,
+ "directArtifactIds": [1, 2, 3, 4]
+ }],
+ "pathFragments": [{
+ "id": 1,
+ "label": "one"
+ }, {
+ "id": 2,
+ "label": "two"
+ }, {
+ "id": 3,
+ "label": "two.d"
+ }, {
+ "id": 4,
+ "label": "other.d"
+ }]
+}`
+
+ _, err := AqueryBuildStatements([]byte(inputString))
+ assertError(t, err, `found multiple potential depfiles "two.d", "other.d"`)
+}
+
func TestTransitiveInputDepsets(t *testing.T) {
// The input aquery for this test comes from a proof-of-concept starlark rule which registers
// a single action with many inputs given via a deep depset.
@@ -627,7 +730,7 @@
// Build statement equivalence is determined using buildStatementEquals.
func assertBuildStatements(t *testing.T, expected []BuildStatement, actual []BuildStatement) {
if len(expected) != len(actual) {
- t.Errorf("expected %d build statements, but got %d,\n expected: %s,\n actual: %s",
+ t.Errorf("expected %d build statements, but got %d,\n expected: %v,\n actual: %v",
len(expected), len(actual), expected, actual)
return
}
@@ -638,7 +741,7 @@
continue ACTUAL_LOOP
}
}
- t.Errorf("unexpected build statement %s.\n expected: %s",
+ t.Errorf("unexpected build statement %v.\n expected: %v",
actualStatement, expected)
return
}
diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go
index 864db3d..affb5ce 100644
--- a/bazel/cquery/request_type.go
+++ b/bazel/cquery/request_type.go
@@ -6,7 +6,6 @@
var (
GetOutputFiles RequestType = &getOutputFilesRequestType{}
- GetCcObjectFiles RequestType = &getCcObjectFilesRequestType{}
GetOutputFilesAndCcObjectFiles RequestType = &getOutputFilesAndCcObjectFilesType{}
)
@@ -15,9 +14,6 @@
CcObjectFiles []string
}
-var RequestTypes []RequestType = []RequestType{
- GetOutputFiles, GetCcObjectFiles, GetOutputFilesAndCcObjectFiles}
-
type RequestType interface {
// Name returns a string name for this request type. Such request type names must be unique,
// and must only consist of alphanumeric characters.
@@ -55,28 +51,6 @@
return strings.Split(rawString, ", ")
}
-type getCcObjectFilesRequestType struct{}
-
-func (g getCcObjectFilesRequestType) Name() string {
- return "getCcObjectFiles"
-}
-
-func (g getCcObjectFilesRequestType) StarlarkFunctionBody() string {
- return `
-result = []
-linker_inputs = providers(target)["CcInfo"].linking_context.linker_inputs.to_list()
-
-for linker_input in linker_inputs:
- for library in linker_input.libraries:
- for object in library.objects:
- result += [object.path]
-return ', '.join(result)`
-}
-
-func (g getCcObjectFilesRequestType) ParseResult(rawString string) interface{} {
- return strings.Split(rawString, ", ")
-}
-
type getOutputFilesAndCcObjectFilesType struct{}
func (g getOutputFilesAndCcObjectFilesType) Name() string {
@@ -104,7 +78,17 @@
splitString := strings.Split(rawString, "|")
outputFilesString := splitString[0]
ccObjectsString := splitString[1]
- outputFiles = strings.Split(outputFilesString, ", ")
- ccObjects = strings.Split(ccObjectsString, ", ")
+ outputFiles = splitOrEmpty(outputFilesString, ", ")
+ ccObjects = splitOrEmpty(ccObjectsString, ", ")
return GetOutputFilesAndCcObjectFiles_Result{outputFiles, ccObjects}
}
+
+// splitOrEmpty is a modification of strings.Split() that returns an empty list
+// if the given string is empty.
+func splitOrEmpty(s string, sep string) []string {
+ if len(s) < 1 {
+ return []string{}
+ } else {
+ return strings.Split(s, sep)
+ }
+}
diff --git a/bazel/properties.go b/bazel/properties.go
index 1763f2d..2440ca1 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -80,20 +80,52 @@
}
const (
- ARCH_X86 = "x86"
- ARCH_X86_64 = "x86_64"
+ // ArchType names in arch.go
ARCH_ARM = "arm"
ARCH_ARM64 = "arm64"
+ ARCH_X86 = "x86"
+ ARCH_X86_64 = "x86_64"
+
+ // OsType names in arch.go
+ OS_ANDROID = "android"
+ OS_DARWIN = "darwin"
+ OS_FUCHSIA = "fuchsia"
+ OS_LINUX = "linux_glibc"
+ OS_LINUX_BIONIC = "linux_bionic"
+ OS_WINDOWS = "windows"
)
var (
- // This is the list of architectures with a Bazel config_setting and
- // constraint value equivalent. is actually android.ArchTypeList, but the
- // android package depends on the bazel package, so a cyclic dependency
- // prevents using that here.
- selectableArchs = []string{ARCH_X86, ARCH_X86_64, ARCH_ARM, ARCH_ARM64}
+ // These are the list of OSes and architectures with a Bazel config_setting
+ // and constraint value equivalent. These exist in arch.go, but the android
+ // package depends on the bazel package, so a cyclic dependency prevents
+ // using those variables here.
+
+ // A map of architectures to the Bazel label of the constraint_value
+ // for the @platforms//cpu:cpu constraint_setting
+ PlatformArchMap = map[string]string{
+ ARCH_ARM: "//build/bazel/platforms/arch:arm",
+ ARCH_ARM64: "//build/bazel/platforms/arch:arm64",
+ ARCH_X86: "//build/bazel/platforms/arch:x86",
+ ARCH_X86_64: "//build/bazel/platforms/arch:x86_64",
+ }
+
+ // A map of target operating systems to the Bazel label of the
+ // constraint_value for the @platforms//os:os constraint_setting
+ PlatformOsMap = map[string]string{
+ OS_ANDROID: "//build/bazel/platforms/os:android",
+ OS_DARWIN: "//build/bazel/platforms/os:darwin",
+ OS_FUCHSIA: "//build/bazel/platforms/os:fuchsia",
+ OS_LINUX: "//build/bazel/platforms/os:linux",
+ OS_LINUX_BIONIC: "//build/bazel/platforms/os:linux_bionic",
+ OS_WINDOWS: "//build/bazel/platforms/os:windows",
+ }
)
+type Attribute interface {
+ HasConfigurableValues() bool
+}
+
// Arch-specific label_list typed Bazel attribute values. This should correspond
// to the types of architectures supported for compilation in arch.go.
type labelListArchValues struct {
@@ -101,8 +133,16 @@
X86_64 LabelList
Arm LabelList
Arm64 LabelList
- // TODO(b/181299724): this is currently missing the "common" arch, which
- // doesn't have an equivalent platform() definition yet.
+ Common LabelList
+}
+
+type labelListOsValues struct {
+ Android LabelList
+ Darwin LabelList
+ Fuchsia LabelList
+ Linux LabelList
+ LinuxBionic LabelList
+ Windows LabelList
}
// LabelListAttribute is used to represent a list of Bazel labels as an
@@ -115,6 +155,11 @@
// are generated in a select statement and appended to the non-arch specific
// label list Value.
ArchValues labelListArchValues
+
+ // The os-specific attribute label list values. Optional. If used, these
+ // are generated in a select statement and appended to the non-os specific
+ // label list Value.
+ OsValues labelListOsValues
}
// MakeLabelListAttribute initializes a LabelListAttribute with the non-arch specific value.
@@ -124,45 +169,75 @@
// HasArchSpecificValues returns true if the attribute contains
// architecture-specific label_list values.
-func (attrs *LabelListAttribute) HasArchSpecificValues() bool {
- for _, arch := range selectableArchs {
- if len(attrs.GetValueForArch(arch).Includes) > 0 || len(attrs.GetValueForArch(arch).Excludes) > 0 {
+func (attrs LabelListAttribute) HasConfigurableValues() bool {
+ for arch := range PlatformArchMap {
+ if len(attrs.GetValueForArch(arch).Includes) > 0 {
+ return true
+ }
+ }
+
+ for os := range PlatformOsMap {
+ if len(attrs.GetValueForOS(os).Includes) > 0 {
return true
}
}
return false
}
+func (attrs *LabelListAttribute) archValuePtrs() map[string]*LabelList {
+ return map[string]*LabelList{
+ ARCH_X86: &attrs.ArchValues.X86,
+ ARCH_X86_64: &attrs.ArchValues.X86_64,
+ ARCH_ARM: &attrs.ArchValues.Arm,
+ ARCH_ARM64: &attrs.ArchValues.Arm64,
+ }
+}
+
// GetValueForArch returns the label_list attribute value for an architecture.
func (attrs *LabelListAttribute) GetValueForArch(arch string) LabelList {
- switch arch {
- case ARCH_X86:
- return attrs.ArchValues.X86
- case ARCH_X86_64:
- return attrs.ArchValues.X86_64
- case ARCH_ARM:
- return attrs.ArchValues.Arm
- case ARCH_ARM64:
- return attrs.ArchValues.Arm64
- default:
+ var v *LabelList
+ if v = attrs.archValuePtrs()[arch]; v == nil {
panic(fmt.Errorf("Unknown arch: %s", arch))
}
+ return *v
}
// SetValueForArch sets the label_list attribute value for an architecture.
func (attrs *LabelListAttribute) SetValueForArch(arch string, value LabelList) {
- switch arch {
- case "x86":
- attrs.ArchValues.X86 = value
- case "x86_64":
- attrs.ArchValues.X86_64 = value
- case "arm":
- attrs.ArchValues.Arm = value
- case "arm64":
- attrs.ArchValues.Arm64 = value
- default:
+ var v *LabelList
+ if v = attrs.archValuePtrs()[arch]; v == nil {
panic(fmt.Errorf("Unknown arch: %s", arch))
}
+ *v = value
+}
+
+func (attrs *LabelListAttribute) osValuePtrs() map[string]*LabelList {
+ return map[string]*LabelList{
+ OS_ANDROID: &attrs.OsValues.Android,
+ OS_DARWIN: &attrs.OsValues.Darwin,
+ OS_FUCHSIA: &attrs.OsValues.Fuchsia,
+ OS_LINUX: &attrs.OsValues.Linux,
+ OS_LINUX_BIONIC: &attrs.OsValues.LinuxBionic,
+ OS_WINDOWS: &attrs.OsValues.Windows,
+ }
+}
+
+// GetValueForOS returns the label_list attribute value for an OS target.
+func (attrs *LabelListAttribute) GetValueForOS(os string) LabelList {
+ var v *LabelList
+ if v = attrs.osValuePtrs()[os]; v == nil {
+ panic(fmt.Errorf("Unknown os: %s", os))
+ }
+ return *v
+}
+
+// SetValueForArch sets the label_list attribute value for an OS target.
+func (attrs *LabelListAttribute) SetValueForOS(os string, value LabelList) {
+ var v *LabelList
+ if v = attrs.osValuePtrs()[os]; v == nil {
+ panic(fmt.Errorf("Unknown os: %s", os))
+ }
+ *v = value
}
// StringListAttribute corresponds to the string_list Bazel attribute type with
@@ -171,8 +246,15 @@
// The base value of the string list attribute.
Value []string
- // Optional additive set of list values to the base value.
+ // The arch-specific attribute string list values. Optional. If used, these
+ // are generated in a select statement and appended to the non-arch specific
+ // label list Value.
ArchValues stringListArchValues
+
+ // The os-specific attribute string list values. Optional. If used, these
+ // are generated in a select statement and appended to the non-os specific
+ // label list Value.
+ OsValues stringListOsValues
}
// Arch-specific string_list typed Bazel attribute values. This should correspond
@@ -182,51 +264,89 @@
X86_64 []string
Arm []string
Arm64 []string
- // TODO(b/181299724): this is currently missing the "common" arch, which
- // doesn't have an equivalent platform() definition yet.
+ Common []string
}
-// HasArchSpecificValues returns true if the attribute contains
+type stringListOsValues struct {
+ Android []string
+ Darwin []string
+ Fuchsia []string
+ Linux []string
+ LinuxBionic []string
+ Windows []string
+}
+
+// HasConfigurableValues returns true if the attribute contains
// architecture-specific string_list values.
-func (attrs *StringListAttribute) HasArchSpecificValues() bool {
- for _, arch := range selectableArchs {
+func (attrs StringListAttribute) HasConfigurableValues() bool {
+ for arch := range PlatformArchMap {
if len(attrs.GetValueForArch(arch)) > 0 {
return true
}
}
+
+ for os := range PlatformOsMap {
+ if len(attrs.GetValueForOS(os)) > 0 {
+ return true
+ }
+ }
return false
}
+func (attrs *StringListAttribute) archValuePtrs() map[string]*[]string {
+ return map[string]*[]string{
+ ARCH_X86: &attrs.ArchValues.X86,
+ ARCH_X86_64: &attrs.ArchValues.X86_64,
+ ARCH_ARM: &attrs.ArchValues.Arm,
+ ARCH_ARM64: &attrs.ArchValues.Arm64,
+ }
+}
+
// GetValueForArch returns the string_list attribute value for an architecture.
func (attrs *StringListAttribute) GetValueForArch(arch string) []string {
- switch arch {
- case ARCH_X86:
- return attrs.ArchValues.X86
- case ARCH_X86_64:
- return attrs.ArchValues.X86_64
- case ARCH_ARM:
- return attrs.ArchValues.Arm
- case ARCH_ARM64:
- return attrs.ArchValues.Arm64
- default:
+ var v *[]string
+ if v = attrs.archValuePtrs()[arch]; v == nil {
panic(fmt.Errorf("Unknown arch: %s", arch))
}
+ return *v
}
// SetValueForArch sets the string_list attribute value for an architecture.
func (attrs *StringListAttribute) SetValueForArch(arch string, value []string) {
- switch arch {
- case ARCH_X86:
- attrs.ArchValues.X86 = value
- case ARCH_X86_64:
- attrs.ArchValues.X86_64 = value
- case ARCH_ARM:
- attrs.ArchValues.Arm = value
- case ARCH_ARM64:
- attrs.ArchValues.Arm64 = value
- default:
+ var v *[]string
+ if v = attrs.archValuePtrs()[arch]; v == nil {
panic(fmt.Errorf("Unknown arch: %s", arch))
}
+ *v = value
+}
+
+func (attrs *StringListAttribute) osValuePtrs() map[string]*[]string {
+ return map[string]*[]string{
+ OS_ANDROID: &attrs.OsValues.Android,
+ OS_DARWIN: &attrs.OsValues.Darwin,
+ OS_FUCHSIA: &attrs.OsValues.Fuchsia,
+ OS_LINUX: &attrs.OsValues.Linux,
+ OS_LINUX_BIONIC: &attrs.OsValues.LinuxBionic,
+ OS_WINDOWS: &attrs.OsValues.Windows,
+ }
+}
+
+// GetValueForOS returns the string_list attribute value for an OS target.
+func (attrs *StringListAttribute) GetValueForOS(os string) []string {
+ var v *[]string
+ if v = attrs.osValuePtrs()[os]; v == nil {
+ panic(fmt.Errorf("Unknown os: %s", os))
+ }
+ return *v
+}
+
+// SetValueForArch sets the string_list attribute value for an OS target.
+func (attrs *StringListAttribute) SetValueForOS(os string, value []string) {
+ var v *[]string
+ if v = attrs.osValuePtrs()[os]; v == nil {
+ panic(fmt.Errorf("Unknown os: %s", os))
+ }
+ *v = value
}
// TryVariableSubstitution, replace string substitution formatting within each string in slice with
diff --git a/bootstrap_test.sh b/bootstrap_test.sh
index 6c5338a..9d87697 100755
--- a/bootstrap_test.sh
+++ b/bootstrap_test.sh
@@ -402,6 +402,14 @@
fi
}
+function test_dump_json_module_graph() {
+ setup
+ SOONG_DUMP_JSON_MODULE_GRAPH="$MOCK_TOP/modules.json" run_soong
+ if [[ ! -r "$MOCK_TOP/modules.json" ]]; then
+ fail "JSON file was not created"
+ fi
+}
+
test_bazel_smoke
test_smoke
test_null_build
@@ -413,3 +421,4 @@
test_delete_android_bp
test_add_file_to_soong_build
test_soong_build_rerun_iff_environment_changes
+test_dump_json_module_graph
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index e93b3dc..dd14c7d 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -415,64 +415,10 @@
case reflect.Struct:
// Special cases where the bp2build sends additional information to the codegenerator
// by wrapping the attributes in a custom struct type.
- if labels, ok := propertyValue.Interface().(bazel.LabelListAttribute); ok {
- // TODO(b/165114590): convert glob syntax
- ret, err := prettyPrint(reflect.ValueOf(labels.Value.Includes), indent)
- if err != nil {
- return ret, err
- }
-
- if !labels.HasArchSpecificValues() {
- // Select statement not needed.
- return ret, nil
- }
-
- ret += " + " + "select({\n"
- for _, arch := range android.ArchTypeList() {
- value := labels.GetValueForArch(arch.Name)
- if len(value.Includes) > 0 {
- ret += makeIndent(indent + 1)
- list, _ := prettyPrint(reflect.ValueOf(value.Includes), indent+1)
- ret += fmt.Sprintf("\"%s\": %s,\n", platformArchMap[arch], list)
- }
- }
-
- ret += makeIndent(indent + 1)
- ret += fmt.Sprintf("\"%s\": [],\n", "//conditions:default")
-
- ret += makeIndent(indent)
- ret += "})"
- return ret, err
+ if attr, ok := propertyValue.Interface().(bazel.Attribute); ok {
+ return prettyPrintAttribute(attr, indent)
} else if label, ok := propertyValue.Interface().(bazel.Label); ok {
return fmt.Sprintf("%q", label.Label), nil
- } else if stringList, ok := propertyValue.Interface().(bazel.StringListAttribute); ok {
- // A Bazel string_list attribute that may contain a select statement.
- ret, err := prettyPrint(reflect.ValueOf(stringList.Value), indent)
- if err != nil {
- return ret, err
- }
-
- if !stringList.HasArchSpecificValues() {
- // Select statement not needed.
- return ret, nil
- }
-
- ret += " + " + "select({\n"
- for _, arch := range android.ArchTypeList() {
- value := stringList.GetValueForArch(arch.Name)
- if len(value) > 0 {
- ret += makeIndent(indent + 1)
- list, _ := prettyPrint(reflect.ValueOf(value), indent+1)
- ret += fmt.Sprintf("\"%s\": %s,\n", platformArchMap[arch], list)
- }
- }
-
- ret += makeIndent(indent + 1)
- ret += fmt.Sprintf("\"%s\": [],\n", "//conditions:default")
-
- ret += makeIndent(indent)
- ret += "})"
- return ret, err
}
ret = "{\n"
diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go
index f12862c..dbea37a 100644
--- a/bp2build/cc_library_headers_conversion_test.go
+++ b/bp2build/cc_library_headers_conversion_test.go
@@ -99,13 +99,11 @@
cc_library_headers {
name: "lib-1",
export_include_dirs: ["lib-1"],
- bazel_module: { bp2build_available: true },
}
cc_library_headers {
name: "lib-2",
export_include_dirs: ["lib-2"],
- bazel_module: { bp2build_available: true },
}
cc_library_headers {
@@ -114,7 +112,6 @@
header_libs: ["lib-1", "lib-2"],
// TODO: Also support export_header_lib_headers
- bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{`cc_library_headers(
name = "foo_headers",
@@ -152,6 +149,106 @@
],
)`},
},
+ {
+ description: "cc_library_headers test with os-specific header_libs props",
+ moduleTypeUnderTest: "cc_library_headers",
+ moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
+ depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
+ filesystem: map[string]string{},
+ bp: soongCcLibraryPreamble + `
+cc_library_headers { name: "android-lib" }
+cc_library_headers { name: "base-lib" }
+cc_library_headers { name: "darwin-lib" }
+cc_library_headers { name: "fuchsia-lib" }
+cc_library_headers { name: "linux-lib" }
+cc_library_headers { name: "linux_bionic-lib" }
+cc_library_headers { name: "windows-lib" }
+cc_library_headers {
+ name: "foo_headers",
+ header_libs: ["base-lib"],
+ target: {
+ android: { header_libs: ["android-lib"] },
+ darwin: { header_libs: ["darwin-lib"] },
+ fuchsia: { header_libs: ["fuchsia-lib"] },
+ linux_bionic: { header_libs: ["linux_bionic-lib"] },
+ linux_glibc: { header_libs: ["linux-lib"] },
+ windows: { header_libs: ["windows-lib"] },
+ },
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{`cc_library_headers(
+ name = "android-lib",
+)`, `cc_library_headers(
+ name = "base-lib",
+)`, `cc_library_headers(
+ name = "darwin-lib",
+)`, `cc_library_headers(
+ name = "foo_headers",
+ deps = [
+ ":base-lib",
+ ] + select({
+ "//build/bazel/platforms/os:android": [
+ ":android-lib",
+ ],
+ "//build/bazel/platforms/os:darwin": [
+ ":darwin-lib",
+ ],
+ "//build/bazel/platforms/os:fuchsia": [
+ ":fuchsia-lib",
+ ],
+ "//build/bazel/platforms/os:linux": [
+ ":linux-lib",
+ ],
+ "//build/bazel/platforms/os:linux_bionic": [
+ ":linux_bionic-lib",
+ ],
+ "//build/bazel/platforms/os:windows": [
+ ":windows-lib",
+ ],
+ "//conditions:default": [],
+ }),
+)`, `cc_library_headers(
+ name = "fuchsia-lib",
+)`, `cc_library_headers(
+ name = "linux-lib",
+)`, `cc_library_headers(
+ name = "linux_bionic-lib",
+)`, `cc_library_headers(
+ name = "windows-lib",
+)`},
+ },
+ {
+ description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props",
+ moduleTypeUnderTest: "cc_library_headers",
+ moduleTypeUnderTestFactory: cc.LibraryHeaderFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build,
+ depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
+ filesystem: map[string]string{},
+ bp: soongCcLibraryPreamble + `
+cc_library_headers { name: "android-lib" }
+cc_library_headers { name: "exported-lib" }
+cc_library_headers {
+ name: "foo_headers",
+ target: {
+ android: { header_libs: ["android-lib"], export_header_lib_headers: ["exported-lib"] },
+ },
+}`,
+ expectedBazelTargets: []string{`cc_library_headers(
+ name = "android-lib",
+)`, `cc_library_headers(
+ name = "exported-lib",
+)`, `cc_library_headers(
+ name = "foo_headers",
+ deps = [] + select({
+ "//build/bazel/platforms/os:android": [
+ ":android-lib",
+ ":exported-lib",
+ ],
+ "//conditions:default": [],
+ }),
+)`},
+ },
}
dir := "."
@@ -169,6 +266,9 @@
config := android.TestConfig(buildDir, nil, testCase.bp, filesystem)
ctx := android.NewTestContext(config)
+ // TODO(jingwen): make this default for all bp2build tests
+ ctx.RegisterBp2BuildConfig(bp2buildConfig)
+
cc.RegisterCCBuildComponents(ctx)
ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go
index 9461739..4f3babe 100644
--- a/bp2build/cc_object_conversion_test.go
+++ b/bp2build/cc_object_conversion_test.go
@@ -324,7 +324,7 @@
copts = [
"-fno-addrsig",
] + select({
- "@bazel_tools//platforms:x86_32": [
+ "//build/bazel/platforms/arch:x86": [
"-fPIC",
],
"//conditions:default": [],
@@ -335,7 +335,7 @@
srcs = [
"a.cpp",
] + select({
- "@bazel_tools//platforms:arm": [
+ "//build/bazel/platforms/arch:arm": [
"arch/arm/file.S",
],
"//conditions:default": [],
@@ -378,16 +378,16 @@
copts = [
"-fno-addrsig",
] + select({
- "@bazel_tools//platforms:arm": [
+ "//build/bazel/platforms/arch:arm": [
"-Wall",
],
- "@bazel_tools//platforms:aarch64": [
+ "//build/bazel/platforms/arch:arm64": [
"-Wall",
],
- "@bazel_tools//platforms:x86_32": [
+ "//build/bazel/platforms/arch:x86": [
"-fPIC",
],
- "@bazel_tools//platforms:x86_64": [
+ "//build/bazel/platforms/arch:x86_64": [
"-fPIC",
],
"//conditions:default": [],
@@ -398,16 +398,16 @@
srcs = [
"base.cpp",
] + select({
- "@bazel_tools//platforms:arm": [
+ "//build/bazel/platforms/arch:arm": [
"arm.cpp",
],
- "@bazel_tools//platforms:aarch64": [
+ "//build/bazel/platforms/arch:arm64": [
"arm64.cpp",
],
- "@bazel_tools//platforms:x86_32": [
+ "//build/bazel/platforms/arch:x86": [
"x86.cpp",
],
- "@bazel_tools//platforms:x86_64": [
+ "//build/bazel/platforms/arch:x86_64": [
"x86_64.cpp",
],
"//conditions:default": [],
@@ -415,6 +415,54 @@
)`,
},
},
+ {
+ description: "cc_object setting cflags for multiple OSes",
+ moduleTypeUnderTest: "cc_object",
+ moduleTypeUnderTestFactory: cc.ObjectFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
+ blueprint: `cc_object {
+ name: "foo",
+ srcs: ["base.cpp"],
+ target: {
+ android: {
+ cflags: ["-fPIC"],
+ },
+ windows: {
+ cflags: ["-fPIC"],
+ },
+ darwin: {
+ cflags: ["-Wall"],
+ },
+ },
+ bazel_module: { bp2build_available: true },
+}
+`,
+ expectedBazelTargets: []string{
+ `cc_object(
+ name = "foo",
+ copts = [
+ "-fno-addrsig",
+ ] + select({
+ "//build/bazel/platforms/os:android": [
+ "-fPIC",
+ ],
+ "//build/bazel/platforms/os:darwin": [
+ "-Wall",
+ ],
+ "//build/bazel/platforms/os:windows": [
+ "-fPIC",
+ ],
+ "//conditions:default": [],
+ }),
+ local_include_dirs = [
+ ".",
+ ],
+ srcs = [
+ "base.cpp",
+ ],
+)`,
+ },
+ },
}
dir := "."
diff --git a/bp2build/configurability.go b/bp2build/configurability.go
index 47cf3c6..b2b3379 100644
--- a/bp2build/configurability.go
+++ b/bp2build/configurability.go
@@ -1,15 +1,136 @@
package bp2build
-import "android/soong/android"
+import (
+ "android/soong/android"
+ "android/soong/bazel"
+ "fmt"
+ "reflect"
+)
// Configurability support for bp2build.
-var (
- // A map of architectures to the Bazel label of the constraint_value.
- platformArchMap = map[android.ArchType]string{
- android.Arm: "@bazel_tools//platforms:arm",
- android.Arm64: "@bazel_tools//platforms:aarch64",
- android.X86: "@bazel_tools//platforms:x86_32",
- android.X86_64: "@bazel_tools//platforms:x86_64",
+type selects map[string]reflect.Value
+
+func getStringListValues(list bazel.StringListAttribute) (reflect.Value, selects, selects) {
+ value := reflect.ValueOf(list.Value)
+ if !list.HasConfigurableValues() {
+ return value, nil, nil
}
-)
+
+ archSelects := map[string]reflect.Value{}
+ for arch, selectKey := range bazel.PlatformArchMap {
+ archSelects[selectKey] = reflect.ValueOf(list.GetValueForArch(arch))
+ }
+
+ osSelects := map[string]reflect.Value{}
+ for os, selectKey := range bazel.PlatformOsMap {
+ osSelects[selectKey] = reflect.ValueOf(list.GetValueForOS(os))
+ }
+
+ return value, archSelects, osSelects
+}
+
+func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, selects, selects) {
+ value := reflect.ValueOf(list.Value.Includes)
+ if !list.HasConfigurableValues() {
+ return value, nil, nil
+ }
+
+ archSelects := map[string]reflect.Value{}
+ for arch, selectKey := range bazel.PlatformArchMap {
+ archSelects[selectKey] = reflect.ValueOf(list.GetValueForArch(arch).Includes)
+ }
+
+ osSelects := map[string]reflect.Value{}
+ for os, selectKey := range bazel.PlatformOsMap {
+ osSelects[selectKey] = reflect.ValueOf(list.GetValueForOS(os).Includes)
+ }
+
+ return value, archSelects, osSelects
+}
+
+// prettyPrintAttribute converts an Attribute to its Bazel syntax. May contain
+// select statements.
+func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) {
+ var value reflect.Value
+ var archSelects, osSelects selects
+
+ switch list := v.(type) {
+ case bazel.StringListAttribute:
+ value, archSelects, osSelects = getStringListValues(list)
+ case bazel.LabelListAttribute:
+ value, archSelects, osSelects = getLabelListValues(list)
+ default:
+ return "", fmt.Errorf("Not a supported Bazel attribute type: %s", v)
+ }
+
+ ret, err := prettyPrint(value, indent)
+ if err != nil {
+ return ret, err
+ }
+
+ // Create the selects for arch specific values.
+ selectMap, err := prettyPrintSelectMap(archSelects, "[]", indent)
+ if err != nil {
+ return "", err
+ }
+ ret += selectMap
+
+ // Create the selects for target os specific values.
+ selectMap, err = prettyPrintSelectMap(osSelects, "[]", indent)
+ if err != nil {
+ return "", err
+ }
+ ret += selectMap
+
+ return ret, err
+}
+
+// prettyPrintSelectMap converts a map of select keys to reflected Values as a generic way
+// to construct a select map for any kind of attribute type.
+func prettyPrintSelectMap(selectMap map[string]reflect.Value, defaultValue string, indent int) (string, error) {
+ if selectMap == nil {
+ return "", nil
+ }
+
+ var selects string
+ for _, selectKey := range android.SortedStringKeys(selectMap) {
+ value := selectMap[selectKey]
+ if isZero(value) {
+ // Ignore zero values to not generate empty lists.
+ continue
+ }
+ s, err := prettyPrintSelectEntry(value, selectKey, indent)
+ if err != nil {
+ return "", err
+ }
+ selects += s + ",\n"
+ }
+
+ if len(selects) == 0 {
+ // No conditions (or all values are empty lists), so no need for a map.
+ return "", nil
+ }
+
+ // Create the map.
+ ret := " + select({\n"
+ ret += selects
+ // default condition comes last.
+ ret += fmt.Sprintf("%s\"%s\": %s,\n", makeIndent(indent+1), "//conditions:default", defaultValue)
+ ret += makeIndent(indent)
+ ret += "})"
+
+ return ret, nil
+}
+
+// prettyPrintSelectEntry converts a reflect.Value into an entry in a select map
+// with a provided key.
+func prettyPrintSelectEntry(value reflect.Value, key string, indent int) (string, error) {
+ s := makeIndent(indent + 1)
+ v, err := prettyPrint(value, indent+1)
+ if err != nil {
+ return "", err
+ }
+ s += fmt.Sprintf("\"%s\": %s", key, v)
+ return s, nil
+}
diff --git a/bp2build/testing.go b/bp2build/testing.go
index ede8044..ef3a78f 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -5,6 +5,13 @@
"android/soong/bazel"
)
+var (
+ // A default configuration for tests to not have to specify bp2build_available on top level targets.
+ bp2buildConfig = android.Bp2BuildConfig{
+ android.BP2BUILD_TOPLEVEL: android.Bp2BuildDefaultTrueRecursively,
+ }
+)
+
type nestedProps struct {
Nested_prop string
}
diff --git a/cc/Android.bp b/cc/Android.bp
index 79e92cb..cc4d9bc 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -20,6 +20,7 @@
"androidmk.go",
"api_level.go",
"builder.go",
+ "bp2build.go",
"cc.go",
"ccdeps.go",
"check.go",
diff --git a/cc/bp2build.go b/cc/bp2build.go
new file mode 100644
index 0000000..497d227
--- /dev/null
+++ b/cc/bp2build.go
@@ -0,0 +1,131 @@
+// 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 cc
+
+import (
+ "android/soong/android"
+ "android/soong/bazel"
+)
+
+// bp2build functions and helpers for converting cc_* modules to Bazel.
+
+func init() {
+ android.DepsBp2BuildMutators(RegisterDepsBp2Build)
+}
+
+func RegisterDepsBp2Build(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("cc_bp2build_deps", depsBp2BuildMutator)
+}
+
+// A naive deps mutator to add deps on all modules across all combinations of
+// target props for cc modules. This is needed to make module -> bazel label
+// resolution work in the bp2build mutator later. This is probably
+// the wrong way to do it, but it works.
+//
+// TODO(jingwen): can we create a custom os mutator in depsBp2BuildMutator to do this?
+func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
+ module, ok := ctx.Module().(*Module)
+ if !ok {
+ // Not a cc module
+ return
+ }
+
+ if !module.ConvertWithBp2build(ctx) {
+ return
+ }
+
+ var allDeps []string
+
+ for _, p := range module.GetTargetProperties(&BaseLinkerProperties{}) {
+ // arch specific linker props
+ if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
+ allDeps = append(allDeps, baseLinkerProps.Header_libs...)
+ allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
+ }
+ }
+
+ ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)
+}
+
+// bp2buildParseCflags creates a label list attribute containing the cflags of a module, including
+func bp2BuildParseCflags(ctx android.TopDownMutatorContext, module *Module) bazel.StringListAttribute {
+ var ret bazel.StringListAttribute
+ for _, props := range module.compiler.compilerProps() {
+ if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
+ ret.Value = baseCompilerProps.Cflags
+ break
+ }
+ }
+
+ for arch, props := range module.GetArchProperties(&BaseCompilerProperties{}) {
+ if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
+ ret.SetValueForArch(arch.Name, baseCompilerProps.Cflags)
+ }
+ }
+
+ for os, props := range module.GetTargetProperties(&BaseCompilerProperties{}) {
+ if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
+ ret.SetValueForOS(os.Name, baseCompilerProps.Cflags)
+ }
+ }
+
+ return ret
+}
+
+// bp2BuildParseHeaderLibs creates a label list attribute containing the header library deps of a module, including
+// configurable attribute values.
+func bp2BuildParseHeaderLibs(ctx android.TopDownMutatorContext, module *Module) bazel.LabelListAttribute {
+ var ret bazel.LabelListAttribute
+ for _, linkerProps := range module.linker.linkerProps() {
+ if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
+ libs := baseLinkerProps.Header_libs
+ libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
+ ret = bazel.MakeLabelListAttribute(
+ android.BazelLabelForModuleDeps(ctx, android.SortedUniqueStrings(libs)))
+ break
+ }
+ }
+
+ for os, p := range module.GetTargetProperties(&BaseLinkerProperties{}) {
+ if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
+ libs := baseLinkerProps.Header_libs
+ libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
+ libs = android.SortedUniqueStrings(libs)
+ ret.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs))
+ }
+ }
+
+ return ret
+}
+
+// bp2BuildParseExportedIncludes creates a label list attribute contains the
+// exported included directories of a module.
+func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) (bazel.LabelListAttribute, bazel.LabelListAttribute) {
+ libraryDecorator := module.linker.(*libraryDecorator)
+
+ includeDirs := libraryDecorator.flagExporter.Properties.Export_system_include_dirs
+ includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...)
+
+ includeDirsLabels := android.BazelLabelForModuleSrc(ctx, includeDirs)
+
+ var includeDirGlobs []string
+ for _, includeDir := range includeDirs {
+ includeDirGlobs = append(includeDirGlobs, includeDir+"/**/*.h")
+ includeDirGlobs = append(includeDirGlobs, includeDir+"/**/*.inc")
+ includeDirGlobs = append(includeDirGlobs, includeDir+"/**/*.hpp")
+ }
+
+ headersLabels := android.BazelLabelForModuleSrc(ctx, includeDirGlobs)
+ return bazel.MakeLabelListAttribute(includeDirsLabels), bazel.MakeLabelListAttribute(headersLabels)
+}
diff --git a/cc/builder.go b/cc/builder.go
index 4771b89..8c9743f 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -182,11 +182,11 @@
blueprint.RuleParams{
Depfile: "${out}.d",
Deps: blueprint.DepsGCC,
- Command: "CROSS_COMPILE=$crossCompile $tocPath $format -i ${in} -o ${out} -d ${out}.d",
+ Command: "CLANG_BIN=$clangBin $tocPath $format -i ${in} -o ${out} -d ${out}.d",
CommandDeps: []string{"$tocPath"},
Restat: true,
},
- "crossCompile", "format")
+ "clangBin", "format")
// Rule for invoking clang-tidy (a clang-based linter).
clangTidy, clangTidyRE = pctx.RemoteStaticRules("clangTidy",
@@ -918,16 +918,12 @@
outputFile android.WritablePath, flags builderFlags) {
var format string
- var crossCompile string
if ctx.Darwin() {
format = "--macho"
- crossCompile = "${config.MacToolPath}"
} else if ctx.Windows() {
format = "--pe"
- crossCompile = gccCmd(flags.toolchain, "")
} else {
format = "--elf"
- crossCompile = gccCmd(flags.toolchain, "")
}
ctx.Build(pctx, android.BuildParams{
@@ -936,8 +932,8 @@
Output: outputFile,
Input: inputFile,
Args: map[string]string{
- "crossCompile": crossCompile,
- "format": format,
+ "clangBin": "${config.ClangBin}",
+ "format": format,
},
})
}
diff --git a/cc/cc.go b/cc/cc.go
index f074597..1ce83a9 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1646,12 +1646,12 @@
c.hideApexVariantFromMake = true
}
+ c.makeLinkType = GetMakeLinkType(actx, c)
+
if c.maybeGenerateBazelActions(actx) {
return
}
- c.makeLinkType = GetMakeLinkType(actx, c)
-
ctx := &moduleContext{
ModuleContext: actx,
moduleContextImpl: moduleContextImpl{
@@ -1892,8 +1892,8 @@
}
for _, lib := range deps.ReexportStaticLibHeaders {
- if !inList(lib, deps.StaticLibs) {
- ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
+ if !inList(lib, deps.StaticLibs) && !inList(lib, deps.WholeStaticLibs) {
+ ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs or whole_static_libs: '%s'", lib)
}
}
@@ -3284,6 +3284,10 @@
type Defaults struct {
android.ModuleBase
android.DefaultsModuleBase
+ // Included to support setting bazel_module.label for multiple Soong modules to the same Bazel
+ // target. This is primarily useful for modules that were architecture specific and instead are
+ // handled in Bazel as a select().
+ android.BazelModuleBase
android.ApexModuleBase
}
@@ -3330,6 +3334,8 @@
&RustBindgenClangProperties{},
)
+ // Bazel module must be initialized _before_ Defaults to be included in cc_defaults module.
+ android.InitBazelModule(module)
android.InitDefaultsModule(module)
return module
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 9fc1f35..465283d 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -35,7 +35,7 @@
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.DeviceVndkVersion = StringPtr("current")
variables.ProductVndkVersion = StringPtr("current")
- variables.Platform_vndk_version = StringPtr("VER")
+ variables.Platform_vndk_version = StringPtr("29")
}),
)
@@ -75,7 +75,7 @@
func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
t.Helper()
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
return testCcWithConfig(t, config)
}
@@ -89,7 +89,7 @@
t.Helper()
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
return testCcWithConfig(t, config)
}
@@ -116,7 +116,7 @@
t.Helper()
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
testCcErrorWithConfig(t, pattern, config)
return
}
@@ -131,15 +131,15 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.ProductVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
testCcErrorWithConfig(t, pattern, config)
return
}
const (
coreVariant = "android_arm64_armv8-a_shared"
- vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
- productVariant = "android_product.VER_arm64_armv8-a_shared"
+ vendorVariant = "android_vendor.29_arm64_armv8-a_shared"
+ productVariant = "android_product.29_arm64_armv8-a_shared"
recoveryVariant = "android_recovery_arm64_armv8-a_shared"
)
@@ -456,7 +456,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.ProductVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := testCcWithConfig(t, config)
@@ -486,8 +486,8 @@
vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
- variant := "android_vendor.VER_arm64_armv8-a_shared"
- variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
+ variant := "android_vendor.29_arm64_armv8-a_shared"
+ variant2nd := "android_vendor.29_arm_armv7-a-neon_shared"
snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
@@ -577,12 +577,12 @@
}`
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := testCcWithConfig(t, config)
module := ctx.ModuleForTests("llndk.libraries.txt", "")
entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0]
- assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
+ assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.29.txt"})
}
func TestVndkUsingCoreVariant(t *testing.T) {
@@ -627,7 +627,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
@@ -654,7 +654,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
ctx := testCcWithConfig(t, config)
@@ -705,7 +705,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
ctx := testCcWithConfig(t, config)
@@ -1331,7 +1331,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.ProductVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := testCcWithConfig(t, config)
@@ -1776,7 +1776,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.ProductVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
testCcWithConfig(t, config)
}
@@ -2140,7 +2140,7 @@
}
func TestEnforceProductVndkVersionErrors(t *testing.T) {
- testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
+ testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
cc_library {
name: "libprod",
product_specific: true,
@@ -2155,7 +2155,7 @@
nocrt: true,
}
`)
- testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
+ testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
cc_library {
name: "libprod",
product_specific: true,
@@ -2169,7 +2169,7 @@
nocrt: true,
}
`)
- testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
+ testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
cc_library {
name: "libprod",
product_specific: true,
@@ -2204,7 +2204,7 @@
nocrt: true,
}
`)
- testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
+ testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
cc_library {
name: "libprod",
product_specific: true,
@@ -2330,7 +2330,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
// native:vndk
ctx := testCcWithConfig(t, config)
@@ -2664,27 +2664,27 @@
`)
actual := ctx.ModuleVariantsForTests("libllndk")
for i := 0; i < len(actual); i++ {
- if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
+ if !strings.HasPrefix(actual[i], "android_vendor.29_") {
actual = append(actual[:i], actual[i+1:]...)
i--
}
}
expected := []string{
- "android_vendor.VER_arm64_armv8-a_shared_1",
- "android_vendor.VER_arm64_armv8-a_shared_2",
- "android_vendor.VER_arm64_armv8-a_shared_current",
- "android_vendor.VER_arm64_armv8-a_shared",
- "android_vendor.VER_arm_armv7-a-neon_shared_1",
- "android_vendor.VER_arm_armv7-a-neon_shared_2",
- "android_vendor.VER_arm_armv7-a-neon_shared_current",
- "android_vendor.VER_arm_armv7-a-neon_shared",
+ "android_vendor.29_arm64_armv8-a_shared_1",
+ "android_vendor.29_arm64_armv8-a_shared_2",
+ "android_vendor.29_arm64_armv8-a_shared_current",
+ "android_vendor.29_arm64_armv8-a_shared",
+ "android_vendor.29_arm_armv7-a-neon_shared_1",
+ "android_vendor.29_arm_armv7-a-neon_shared_2",
+ "android_vendor.29_arm_armv7-a-neon_shared_current",
+ "android_vendor.29_arm_armv7-a-neon_shared",
}
checkEquals(t, "variants for llndk stubs", expected, actual)
- params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
+ params := ctx.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared").Description("generate stub")
checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
- params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
+ params = ctx.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared_1").Description("generate stub")
checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
}
@@ -2714,7 +2714,7 @@
`)
// _static variant is used since _shared reuses *.o from the static variant
- cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
+ cc := ctx.ModuleForTests("libvendor", "android_vendor.29_arm_armv7-a-neon_static").Rule("cc")
cflags := cc.Args["cFlags"]
if !strings.Contains(cflags, "-Imy_include") {
t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
@@ -2835,7 +2835,7 @@
// runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
// and vendor variants.
- variant = "android_vendor.VER_arm64_armv8-a_shared"
+ variant = "android_vendor.29_arm64_armv8-a_shared"
module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
@@ -2845,7 +2845,7 @@
// runtime_libs for product variants have '.product' suffixes if the modules have both core
// and product variants.
- variant = "android_product.VER_arm64_armv8-a_shared"
+ variant = "android_product.29_arm64_armv8-a_shared"
module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
checkRuntimeLibs(t, []string{"liball_available.product"}, module)
@@ -2861,7 +2861,7 @@
module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
checkRuntimeLibs(t, []string{"liball_available"}, module)
- variant = "android_vendor.VER_arm64_armv8-a_shared"
+ variant = "android_vendor.29_arm64_armv8-a_shared"
module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
checkRuntimeLibs(t, nil, module)
}
@@ -3044,7 +3044,7 @@
`)
coreVariant := "android_arm64_armv8-a_shared"
- vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
+ vendorVariant := "android_vendor.29_arm64_armv8-a_shared"
// test if header search paths are correctly added
// _static variant is used since _shared reuses *.o from the static variant
@@ -3124,7 +3124,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
ctx := testCcWithConfig(t, config)
@@ -3368,6 +3368,9 @@
shared: {
srcs: ["baz.c"],
},
+ bazel_module: {
+ bp2build_available: true,
+ },
}
cc_library_static {
diff --git a/cc/library.go b/cc/library.go
index 091acfe..11b6737 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -425,11 +425,14 @@
if !ok {
return ok
}
- if len(outputPaths) != 1 {
+ if len(outputPaths) > 1 {
// TODO(cparsons): This is actually expected behavior for static libraries with no srcs.
// We should support this.
- ctx.ModuleErrorf("expected exactly one output file for '%s', but got %s", label, objPaths)
+ ctx.ModuleErrorf("expected at most one output file for '%s', but got %s", label, objPaths)
return false
+ } else if len(outputPaths) == 0 {
+ handler.module.outputFile = android.OptionalPath{}
+ return true
}
outputFilePath := android.PathForBazelOut(ctx, outputPaths[0])
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
@@ -453,7 +456,15 @@
Direct(outputFilePath).
Build(),
})
- handler.module.outputFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, objPaths[0]))
+ if i, ok := handler.module.linker.(snapshotLibraryInterface); ok {
+ // Dependencies on this library will expect collectedSnapshotHeaders to
+ // be set, otherwise validation will fail. For now, set this to an empty
+ // list.
+ // TODO(cparsons): More closely mirror the collectHeadersForSnapshot
+ // implementation.
+ i.(*libraryDecorator).collectedSnapshotHeaders = android.Paths{}
+ }
+
return ok
}
@@ -2046,38 +2057,6 @@
return outputFile
}
-func Bp2BuildParseHeaderLibs(ctx android.TopDownMutatorContext, module *Module) bazel.LabelListAttribute {
- var headerLibs []string
- for _, linkerProps := range module.linker.linkerProps() {
- if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
- headerLibs = baseLinkerProps.Header_libs
- // FIXME: re-export include dirs from baseLinkerProps.Export_header_lib_headers?
- break
- }
- }
- headerLibsLabels := bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, headerLibs))
- return headerLibsLabels
-}
-
-func Bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) (bazel.LabelListAttribute, bazel.LabelListAttribute) {
- libraryDecorator := module.linker.(*libraryDecorator)
-
- includeDirs := libraryDecorator.flagExporter.Properties.Export_system_include_dirs
- includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...)
-
- includeDirsLabels := android.BazelLabelForModuleSrc(ctx, includeDirs)
-
- var includeDirGlobs []string
- for _, includeDir := range includeDirs {
- includeDirGlobs = append(includeDirGlobs, includeDir+"/**/*.h")
- includeDirGlobs = append(includeDirGlobs, includeDir+"/**/*.inc")
- includeDirGlobs = append(includeDirGlobs, includeDir+"/**/*.hpp")
- }
-
- headersLabels := android.BazelLabelForModuleSrc(ctx, includeDirGlobs)
- return bazel.MakeLabelListAttribute(includeDirsLabels), bazel.MakeLabelListAttribute(headersLabels)
-}
-
type bazelCcLibraryStaticAttributes struct {
Copts []string
Srcs bazel.LabelListAttribute
@@ -2149,10 +2128,10 @@
allIncludes = append(allIncludes, localIncludeDirs...)
includesLabels := android.BazelLabelForModuleSrc(ctx, allIncludes)
- exportedIncludesLabels, exportedIncludesHeadersLabels := Bp2BuildParseExportedIncludes(ctx, module)
+ exportedIncludesLabels, exportedIncludesHeadersLabels := bp2BuildParseExportedIncludes(ctx, module)
includesLabels.Append(exportedIncludesLabels.Value)
- headerLibsLabels := Bp2BuildParseHeaderLibs(ctx, module)
+ headerLibsLabels := bp2BuildParseHeaderLibs(ctx, module)
depsLabels.Append(headerLibsLabels.Value)
attrs := &bazelCcLibraryStaticAttributes{
diff --git a/cc/library_headers.go b/cc/library_headers.go
index 8286848..82af16a 100644
--- a/cc/library_headers.go
+++ b/cc/library_headers.go
@@ -62,6 +62,7 @@
}
type bazelCcLibraryHeadersAttributes struct {
+ Copts bazel.StringListAttribute
Hdrs bazel.LabelListAttribute
Includes bazel.LabelListAttribute
Deps bazel.LabelListAttribute
@@ -94,11 +95,12 @@
return
}
- exportedIncludesLabels, exportedIncludesHeadersLabels := Bp2BuildParseExportedIncludes(ctx, module)
+ exportedIncludesLabels, exportedIncludesHeadersLabels := bp2BuildParseExportedIncludes(ctx, module)
- headerLibsLabels := Bp2BuildParseHeaderLibs(ctx, module)
+ headerLibsLabels := bp2BuildParseHeaderLibs(ctx, module)
attrs := &bazelCcLibraryHeadersAttributes{
+ Copts: bp2BuildParseCflags(ctx, module),
Includes: exportedIncludesLabels,
Hdrs: exportedIncludesHeadersLabels,
Deps: headerLibsLabels,
diff --git a/cc/object.go b/cc/object.go
index ea8d7d3..4f8797d 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -156,13 +156,11 @@
}
// Set arch-specific configurable attributes
- var copts bazel.StringListAttribute
var srcs bazel.LabelListAttribute
var localIncludeDirs []string
var asFlags []string
for _, props := range m.compiler.compilerProps() {
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
- copts.Value = baseCompilerProps.Cflags
srcs = bazel.MakeLabelListAttribute(
android.BazelLabelForModuleSrcExcludes(
ctx,
@@ -205,14 +203,13 @@
for arch, p := range m.GetArchProperties(&BaseCompilerProperties{}) {
if cProps, ok := p.(*BaseCompilerProperties); ok {
srcs.SetValueForArch(arch.Name, android.BazelLabelForModuleSrcExcludes(ctx, cProps.Srcs, cProps.Exclude_srcs))
- copts.SetValueForArch(arch.Name, cProps.Cflags)
}
}
attrs := &bazelObjectAttributes{
Srcs: srcs,
Deps: deps,
- Copts: copts,
+ Copts: bp2BuildParseCflags(ctx, m),
Asflags: asFlags,
Local_include_dirs: localIncludeDirs,
}
diff --git a/cc/vendor_snapshot_test.go b/cc/vendor_snapshot_test.go
index 8d13ceb..20cd031 100644
--- a/cc/vendor_snapshot_test.go
+++ b/cc/vendor_snapshot_test.go
@@ -88,7 +88,7 @@
`
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := testCcWithConfig(t, config)
// Check Vendor snapshot output.
@@ -108,7 +108,7 @@
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
// For shared libraries, only non-VNDK vendor_available modules are captured
- sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
+ sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
@@ -121,8 +121,8 @@
// For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
// Also cfi variants are captured, except for prebuilts like toolchain_library
- staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant)
- staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant)
+ staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
+ staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant)
staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
@@ -142,7 +142,7 @@
// For binary executables, all vendor:true and vendor_available modules are captured.
if archType == "arm64" {
- binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
+ binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
@@ -156,7 +156,7 @@
jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
// For object modules, all vendor:true and vendor_available modules are captured.
- objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
+ objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
@@ -214,7 +214,7 @@
`
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
config.TestProductVariables.DirectedVendorSnapshot = true
config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
@@ -237,7 +237,7 @@
archVariant := arch[1]
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
- sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
+ sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
// Included modules
@@ -308,7 +308,7 @@
vndkBp := `
vndk_prebuilt_shared {
name: "libvndk",
- version: "BOARD",
+ version: "28",
target_arch: "arm64",
vendor_available: true,
product_available: true,
@@ -326,7 +326,7 @@
// old snapshot module which has to be ignored
vndk_prebuilt_shared {
name: "libvndk",
- version: "OLD",
+ version: "26",
target_arch: "arm64",
vendor_available: true,
product_available: true,
@@ -381,7 +381,7 @@
vendor_snapshot {
name: "vendor_snapshot",
compile_multilib: "first",
- version: "BOARD",
+ version: "28",
vndk_libs: [
"libvndk",
],
@@ -401,7 +401,7 @@
vendor_snapshot_static {
name: "libvndk",
- version: "BOARD",
+ version: "28",
target_arch: "arm64",
vendor: true,
arch: {
@@ -414,7 +414,7 @@
vendor_snapshot_shared {
name: "libvendor",
- version: "BOARD",
+ version: "28",
target_arch: "arm64",
compile_multilib: "64",
vendor: true,
@@ -433,7 +433,7 @@
vendor_snapshot_static {
name: "libvendor",
- version: "BOARD",
+ version: "28",
target_arch: "arm64",
vendor: true,
arch: {
@@ -447,7 +447,7 @@
vendor_snapshot_shared {
name: "libvendor_available",
androidmk_suffix: ".vendor",
- version: "BOARD",
+ version: "28",
target_arch: "arm64",
vendor: true,
arch: {
@@ -461,7 +461,7 @@
vendor_snapshot_static {
name: "libvendor_available",
androidmk_suffix: ".vendor",
- version: "BOARD",
+ version: "28",
target_arch: "arm64",
vendor: true,
arch: {
@@ -474,7 +474,7 @@
vendor_snapshot_binary {
name: "bin",
- version: "BOARD",
+ version: "28",
target_arch: "arm64",
vendor: true,
arch: {
@@ -487,7 +487,7 @@
// old snapshot module which has to be ignored
vendor_snapshot_binary {
name: "bin",
- version: "OLD",
+ version: "26",
target_arch: "arm64",
vendor: true,
arch: {
@@ -517,8 +517,8 @@
}
config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
- config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := CreateTestContext(config)
ctx.Register()
@@ -527,11 +527,11 @@
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
- sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared"
- staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
- binaryVariant := "android_vendor.BOARD_arm64_armv8-a"
+ sharedVariant := "android_vendor.28_arm64_armv8-a_shared"
+ staticVariant := "android_vendor.28_arm64_armv8-a_static"
+ binaryVariant := "android_vendor.28_arm64_armv8-a"
- // libclient uses libvndk.vndk.BOARD.arm64, libvendor.vendor_static.BOARD.arm64, libvendor_without_snapshot
+ // libclient uses libvndk.vndk.28.arm64, libvendor.vendor_static.28.arm64, libvendor_without_snapshot
libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
for _, includeFlags := range []string{
"-Ivndk/include/libvndk", // libvndk
@@ -545,8 +545,8 @@
libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
for _, input := range [][]string{
- []string{sharedVariant, "libvndk.vndk.BOARD.arm64"},
- []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"},
+ []string{sharedVariant, "libvndk.vndk.28.arm64"},
+ []string{staticVariant, "libvendor.vendor_static.28.arm64"},
[]string{staticVariant, "libvendor_without_snapshot"},
} {
outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
@@ -565,7 +565,7 @@
t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
}
- // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64
+ // bin_without_snapshot uses libvndk.vendor_static.28.arm64
binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
@@ -573,28 +573,28 @@
}
binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
- libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"})
+ libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.28.arm64"})
if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
}
- // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64
- ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so")
+ // libvendor.so is installed by libvendor.vendor_shared.28.arm64
+ ctx.ModuleForTests("libvendor.vendor_shared.28.arm64", sharedVariant).Output("libvendor.so")
- // libvendor_available.so is installed by libvendor_available.vendor_shared.BOARD.arm64
- ctx.ModuleForTests("libvendor_available.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor_available.so")
+ // libvendor_available.so is installed by libvendor_available.vendor_shared.28.arm64
+ ctx.ModuleForTests("libvendor_available.vendor_shared.28.arm64", sharedVariant).Output("libvendor_available.so")
// libvendor_without_snapshot.so is installed by libvendor_without_snapshot
ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
- // bin is installed by bin.vendor_binary.BOARD.arm64
- ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin")
+ // bin is installed by bin.vendor_binary.28.arm64
+ ctx.ModuleForTests("bin.vendor_binary.28.arm64", binaryVariant).Output("bin")
// bin_without_snapshot is installed by bin_without_snapshot
ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
- // libvendor, libvendor_available and bin don't have vendor.BOARD variant
+ // libvendor, libvendor_available and bin don't have vendor.28 variant
libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
if inList(sharedVariant, libvendorVariants) {
t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
@@ -617,7 +617,7 @@
name: "libsnapshot",
vendor: true,
target_arch: "arm64",
- version: "BOARD",
+ version: "28",
arch: {
arm64: {
src: "libsnapshot.a",
@@ -629,18 +629,18 @@
}
`
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
- config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := testCcWithConfig(t, config)
// Check non-cfi and cfi variant.
- staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
- staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi"
+ staticVariant := "android_vendor.28_arm64_armv8-a_static"
+ staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
- staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module)
+ staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
- staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module)
+ staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
}
@@ -709,7 +709,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := CreateTestContext(config)
ctx.Register()
@@ -744,7 +744,7 @@
archVariant := arch[1]
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
- sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
+ sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
// Included modules
@@ -801,7 +801,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := CreateTestContext(config)
ctx.Register()
@@ -875,7 +875,7 @@
`
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := testCcWithConfig(t, config)
// Check Recovery snapshot output.
@@ -993,7 +993,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
ctx := CreateTestContext(config)
ctx.Register()
@@ -1094,7 +1094,7 @@
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
- config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
+ config.TestProductVariables.Platform_vndk_version = StringPtr("29")
config.TestProductVariables.DirectedRecoverySnapshot = true
config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 3abf978..1863ece 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -135,10 +135,25 @@
}
}
+func writeJsonModuleGraph(configuration android.Config, ctx *android.Context, path string, extraNinjaDeps []string) {
+ f, err := os.Create(path)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%s", err)
+ os.Exit(1)
+ }
+
+ defer f.Close()
+ ctx.Context.PrintJSONGraph(f)
+ writeFakeNinjaFile(extraNinjaDeps, configuration.BuildDir())
+}
+
func doChosenActivity(configuration android.Config, extraNinjaDeps []string) {
bazelConversionRequested := configuration.IsEnvTrue("GENERATE_BAZEL_FILES")
mixedModeBuild := configuration.BazelContext.BazelEnabled()
generateQueryView := bazelQueryViewDir != ""
+ jsonModuleFile := configuration.Getenv("SOONG_DUMP_JSON_MODULE_GRAPH")
+
+ prepareBuildActions := !generateQueryView && jsonModuleFile == ""
if bazelConversionRequested {
// Run the alternate pipeline of bp2build mutators and singleton to convert
@@ -147,7 +162,7 @@
return
}
- ctx := newContext(configuration, !generateQueryView)
+ ctx := newContext(configuration, prepareBuildActions)
if mixedModeBuild {
runMixedModeBuild(configuration, ctx, extraNinjaDeps)
} else {
@@ -159,6 +174,12 @@
runQueryView(configuration, ctx)
return
}
+
+ if jsonModuleFile != "" {
+ writeJsonModuleGraph(configuration, ctx, jsonModuleFile, extraNinjaDeps)
+ return
+ }
+
writeMetrics(configuration)
}
@@ -230,6 +251,29 @@
}
}
+// Workarounds to support running bp2build in a clean AOSP checkout with no
+// prior builds, and exiting early as soon as the BUILD files get generated,
+// therefore not creating build.ninja files that soong_ui and callers of
+// soong_build expects.
+//
+// These files are: build.ninja and build.ninja.d. Since Kati hasn't been
+// ran as well, and `nothing` is defined in a .mk file, there isn't a ninja
+// target called `nothing`, so we manually create it here.
+func writeFakeNinjaFile(extraNinjaDeps []string, buildDir string) {
+ extraNinjaDepsString := strings.Join(extraNinjaDeps, " \\\n ")
+
+ ninjaFileName := "build.ninja"
+ ninjaFile := shared.JoinPath(topDir, buildDir, ninjaFileName)
+ ninjaFileD := shared.JoinPath(topDir, buildDir, ninjaFileName)
+ // A workaround to create the 'nothing' ninja target so `m nothing` works,
+ // since bp2build runs without Kati, and the 'nothing' target is declared in
+ // a Makefile.
+ ioutil.WriteFile(ninjaFile, []byte("build nothing: phony\n phony_output = true\n"), 0666)
+ ioutil.WriteFile(ninjaFileD,
+ []byte(fmt.Sprintf("%s: \\\n %s\n", ninjaFileName, extraNinjaDepsString)),
+ 0666)
+}
+
// Run Soong in the bp2build mode. This creates a standalone context that registers
// an alternate pipeline of mutators and singletons specifically for generating
// Bazel BUILD files instead of Ninja files.
@@ -271,30 +315,5 @@
metrics.Print()
extraNinjaDeps = append(extraNinjaDeps, codegenContext.AdditionalNinjaDeps()...)
- extraNinjaDepsString := strings.Join(extraNinjaDeps, " \\\n ")
-
- // Workarounds to support running bp2build in a clean AOSP checkout with no
- // prior builds, and exiting early as soon as the BUILD files get generated,
- // therefore not creating build.ninja files that soong_ui and callers of
- // soong_build expects.
- //
- // These files are: build.ninja and build.ninja.d. Since Kati hasn't been
- // ran as well, and `nothing` is defined in a .mk file, there isn't a ninja
- // target called `nothing`, so we manually create it here.
- //
- // Even though outFile (build.ninja) and depFile (build.ninja.d) are values
- // passed into bootstrap.Main, they are package-private fields in bootstrap.
- // Short of modifying Blueprint to add an exported getter, inlining them
- // here is the next-best practical option.
- ninjaFileName := "build.ninja"
- ninjaFile := android.PathForOutput(codegenContext, ninjaFileName)
- ninjaFileD := android.PathForOutput(codegenContext, ninjaFileName+".d")
- // A workaround to create the 'nothing' ninja target so `m nothing` works,
- // since bp2build runs without Kati, and the 'nothing' target is declared in
- // a Makefile.
- android.WriteFileToOutputDir(ninjaFile, []byte("build nothing: phony\n phony_output = true\n"), 0666)
- android.WriteFileToOutputDir(
- ninjaFileD,
- []byte(fmt.Sprintf("%s: \\\n %s\n", ninjaFileName, extraNinjaDepsString)),
- 0666)
+ writeFakeNinjaFile(extraNinjaDeps, codegenContext.Config().BuildDir())
}
diff --git a/filesystem/logical_partition.go b/filesystem/logical_partition.go
index dbbc1d8..739e609 100644
--- a/filesystem/logical_partition.go
+++ b/filesystem/logical_partition.go
@@ -40,7 +40,8 @@
// Set the name of the output. Defaults to <module_name>.img.
Stem *string
- // Total size of the logical partition
+ // Total size of the logical partition. If set to "auto", total size is automatically
+ // calcaulted as minimum.
Size *string
// List of partitions for default group. Default group has no size limit and automatically
@@ -117,9 +118,8 @@
size := proptools.String(l.properties.Size)
if size == "" {
ctx.PropertyErrorf("size", "must be set")
- }
- if _, err := strconv.Atoi(size); err != nil {
- ctx.PropertyErrorf("size", "must be a number")
+ } else if _, err := strconv.Atoi(size); err != nil && size != "auto" {
+ ctx.PropertyErrorf("size", `must be a number or "auto"`)
}
cmd.FlagWithArg("--device-size=", size)
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 5d438ea..d07b002 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -229,11 +229,16 @@
filePaths, ok := bazelCtx.GetOutputFiles(label, ctx.Arch().ArchType)
if ok {
var bazelOutputFiles android.Paths
+ exportIncludeDirs := map[string]bool{}
for _, bazelOutputFile := range filePaths {
bazelOutputFiles = append(bazelOutputFiles, android.PathForBazelOut(ctx, bazelOutputFile))
+ exportIncludeDirs[filepath.Dir(bazelOutputFile)] = true
}
c.outputFiles = bazelOutputFiles
c.outputDeps = bazelOutputFiles
+ for includePath, _ := range exportIncludeDirs {
+ c.exportedIncludeDirs = append(c.exportedIncludeDirs, android.PathForBazelOut(ctx, includePath))
+ }
}
return ok
}
diff --git a/java/aar.go b/java/aar.go
index 67b9ef0..a122a94 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -163,7 +163,7 @@
a.aaptProperties.RROEnforcedForDependent
}
-func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext,
+func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkContext,
manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths,
resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {
@@ -218,7 +218,7 @@
linkDeps = append(linkDeps, assetDeps...)
// SDK version flags
- minSdkVersion, err := sdkContext.minSdkVersion().effectiveVersionString(ctx)
+ minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersionString(ctx)
if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
@@ -266,7 +266,7 @@
CommandDeps: []string{"${config.Zip2ZipCmd}"},
})
-func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext,
+func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkContext,
classLoaderContexts dexpreopt.ClassLoaderContextMap, extraLinkFlags ...string) {
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags :=
@@ -397,7 +397,7 @@
}
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
-func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) (
+func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) (
transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) {
var sharedLibs android.Paths
@@ -498,7 +498,7 @@
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
a.Module.deps(ctx)
- sdkDep := decodeSdkDep(ctx, sdkContext(a))
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(a))
if sdkDep.hasFrameworkLibs() {
a.aapt.deps(ctx, sdkDep)
}
@@ -507,7 +507,7 @@
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.aapt.isLibrary = true
a.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
- a.aapt.buildActions(ctx, sdkContext(a), a.classLoaderContexts)
+ a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts)
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
@@ -625,23 +625,23 @@
}
}
-func (a *AARImport) sdkVersion() sdkSpec {
- return sdkSpecFrom(String(a.properties.Sdk_version))
+func (a *AARImport) SdkVersion() android.SdkSpec {
+ return android.SdkSpecFrom(String(a.properties.Sdk_version))
}
-func (a *AARImport) systemModules() string {
+func (a *AARImport) SystemModules() string {
return ""
}
-func (a *AARImport) minSdkVersion() sdkSpec {
+func (a *AARImport) MinSdkVersion() android.SdkSpec {
if a.properties.Min_sdk_version != nil {
- return sdkSpecFrom(*a.properties.Min_sdk_version)
+ return android.SdkSpecFrom(*a.properties.Min_sdk_version)
}
- return a.sdkVersion()
+ return a.SdkVersion()
}
-func (a *AARImport) targetSdkVersion() sdkSpec {
- return a.sdkVersion()
+func (a *AARImport) TargetSdkVersion() android.SdkSpec {
+ return a.SdkVersion()
}
func (a *AARImport) javaVersion() string {
@@ -700,7 +700,7 @@
func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) {
if !ctx.Config().AlwaysUsePrebuiltSdks() {
- sdkDep := decodeSdkDep(ctx, sdkContext(a))
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(a))
if sdkDep.useModule && sdkDep.frameworkResModule != "" {
ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
}
@@ -780,7 +780,7 @@
linkDeps = append(linkDeps, a.manifest)
transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags :=
- aaptLibs(ctx, sdkContext(a), nil)
+ aaptLibs(ctx, android.SdkContext(a), nil)
_ = staticLibManifests
_ = staticRRODirs
diff --git a/java/android_manifest.go b/java/android_manifest.go
index b30f3d2..8510f30 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -43,7 +43,7 @@
"args", "libs")
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
-func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
+func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext android.SdkContext,
classLoaderContexts dexpreopt.ClassLoaderContextMap, isLibrary, useEmbeddedNativeLibs, usesNonSdkApis,
useEmbeddedDex, hasNoCode bool, loggingParent string) android.Path {
@@ -51,11 +51,11 @@
if isLibrary {
args = append(args, "--library")
} else {
- minSdkVersion, err := sdkContext.minSdkVersion().effectiveVersion(ctx)
+ minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersion(ctx)
if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
- if minSdkVersion >= 23 {
+ if minSdkVersion.FinalOrFutureInt() >= 23 {
args = append(args, fmt.Sprintf("--extract-native-libs=%v", !useEmbeddedNativeLibs))
} else if useEmbeddedNativeLibs {
ctx.ModuleErrorf("module attempted to store uncompressed native libraries, but minSdkVersion=%d doesn't support it",
@@ -87,7 +87,7 @@
args = append(args, "--logging-parent", loggingParent)
}
var deps android.Paths
- targetSdkVersion, err := sdkContext.targetSdkVersion().effectiveVersionString(ctx)
+ targetSdkVersion, err := sdkContext.TargetSdkVersion().EffectiveVersionString(ctx)
if err != nil {
ctx.ModuleErrorf("invalid targetSdkVersion: %s", err)
}
@@ -96,7 +96,7 @@
deps = append(deps, ApiFingerprintPath(ctx))
}
- minSdkVersion, err := sdkContext.minSdkVersion().effectiveVersionString(ctx)
+ minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersionString(ctx)
if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
diff --git a/java/androidmk.go b/java/androidmk.go
index 3d3eae5..75661a7 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -106,7 +106,7 @@
if len(library.dexpreopter.builtInstalled) > 0 {
entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled)
}
- entries.SetString("LOCAL_SDK_VERSION", library.sdkVersion().raw)
+ entries.SetString("LOCAL_SDK_VERSION", library.SdkVersion().Raw)
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
@@ -255,7 +255,7 @@
entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
- entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion().raw)
+ entries.SetString("LOCAL_SDK_VERSION", prebuilt.SdkVersion().Raw)
},
},
}}
diff --git a/java/app.go b/java/app.go
index b849b98..04406e7 100755
--- a/java/app.go
+++ b/java/app.go
@@ -213,16 +213,16 @@
func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
a.Module.deps(ctx)
- if String(a.appProperties.Stl) == "c++_shared" && !a.sdkVersion().specified() {
+ if String(a.appProperties.Stl) == "c++_shared" && !a.SdkVersion().Specified() {
ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared")
}
- sdkDep := decodeSdkDep(ctx, sdkContext(a))
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(a))
if sdkDep.hasFrameworkLibs() {
a.aapt.deps(ctx, sdkDep)
}
- usesSDK := a.sdkVersion().specified() && a.sdkVersion().kind != sdkCorePlatform
+ usesSDK := a.SdkVersion().Specified() && a.SdkVersion().Kind != android.SdkCorePlatform
if usesSDK && Bool(a.appProperties.Jni_uses_sdk_apis) {
ctx.PropertyErrorf("jni_uses_sdk_apis",
@@ -279,16 +279,16 @@
func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
if a.Updatable() {
- if !a.sdkVersion().stable() {
- ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.sdkVersion())
+ if !a.SdkVersion().Stable() {
+ ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion())
}
if String(a.deviceProperties.Min_sdk_version) == "" {
ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
}
- if minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx); err == nil {
+ if minSdkVersion, err := a.MinSdkVersion().EffectiveVersion(ctx); err == nil {
a.checkJniLibsSdkVersion(ctx, minSdkVersion)
- android.CheckMinSdkVersion(a, ctx, minSdkVersion.ApiLevel(ctx))
+ android.CheckMinSdkVersion(a, ctx, minSdkVersion)
} else {
ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
}
@@ -304,7 +304,7 @@
// because, sdk_version is overridden by min_sdk_version (if set as smaller)
// and sdkLinkType is checked with dependencies so we can be sure that the whole dependency tree
// will meet the requirements.
-func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion sdkVersion) {
+func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion android.ApiLevel) {
// It's enough to check direct JNI deps' sdk_version because all transitive deps from JNI deps are checked in cc.checkLinkType()
ctx.VisitDirectDeps(func(m android.Module) {
if !IsJniDepTag(ctx.OtherModuleDependencyTag(m)) {
@@ -312,10 +312,10 @@
}
dep, _ := m.(*cc.Module)
// The domain of cc.sdk_version is "current" and <number>
- // We can rely on sdkSpec to convert it to <number> so that "current" is handled
- // properly regardless of sdk finalization.
- jniSdkVersion, err := sdkSpecFrom(dep.SdkVersion()).effectiveVersion(ctx)
- if err != nil || minSdkVersion < jniSdkVersion {
+ // We can rely on android.SdkSpec to convert it to <number> so that "current" is
+ // handled properly regardless of sdk finalization.
+ jniSdkVersion, err := android.SdkSpecFrom(dep.SdkVersion()).EffectiveVersion(ctx)
+ if err != nil || minSdkVersion.LessThan(jniSdkVersion) {
ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)",
dep.SdkVersion(), minSdkVersion, ctx.ModuleName())
return
@@ -327,13 +327,13 @@
// Returns true if the native libraries should be stored in the APK uncompressed and the
// extractNativeLibs application flag should be set to false in the manifest.
func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
- minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx)
+ minSdkVersion, err := a.MinSdkVersion().EffectiveVersion(ctx)
if err != nil {
- ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
+ ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.MinSdkVersion(), err)
}
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
- return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
+ return (minSdkVersion.FinalOrFutureInt() >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
!apexInfo.IsForPlatform()
}
@@ -380,7 +380,11 @@
}
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
- a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis)
+ usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis)
+ if ctx.Module().(android.SdkContext).SdkVersion().Kind == android.SdkModule {
+ usePlatformAPI = true
+ }
+ a.aapt.usesNonSdkApis = usePlatformAPI
// Ask manifest_fixer to add or update the application element indicating this app has no code.
a.aapt.hasNoCode = !a.hasCode(ctx)
@@ -419,7 +423,7 @@
a.aapt.splitNames = a.appProperties.Package_splits
a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent)
- a.aapt.buildActions(ctx, sdkContext(a), a.classLoaderContexts, aaptLinkFlags...)
+ a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, aaptLinkFlags...)
// apps manifests are handled by aapt, don't let Module see them
a.properties.Manifest = nil
@@ -720,8 +724,8 @@
}
type appDepsInterface interface {
- sdkVersion() sdkSpec
- minSdkVersion() sdkSpec
+ SdkVersion() android.SdkSpec
+ MinSdkVersion() android.SdkSpec
RequiresStableAPIs(ctx android.BaseModuleContext) bool
}
@@ -734,8 +738,8 @@
seenModulePaths := make(map[string]bool)
if checkNativeSdkVersion {
- checkNativeSdkVersion = app.sdkVersion().specified() &&
- app.sdkVersion().kind != sdkCorePlatform && !app.RequiresStableAPIs(ctx)
+ checkNativeSdkVersion = app.SdkVersion().Specified() &&
+ app.SdkVersion().Kind != android.SdkCorePlatform && !app.RequiresStableAPIs(ctx)
}
ctx.WalkDeps(func(module android.Module, parent android.Module) bool {
@@ -829,6 +833,10 @@
if v := m.MinSdkVersion(); v != "" {
toMinSdkVersion = v
}
+ } else if m, ok := to.(interface{ MinSdkVersionString() string }); ok {
+ if v := m.MinSdkVersionString(); v != "" {
+ toMinSdkVersion = v
+ }
}
depsInfo[depName] = android.ApexModuleDepInfo{
To: depName,
@@ -840,7 +848,7 @@
return true
})
- a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(), depsInfo)
+ a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersionString(), depsInfo)
}
func (a *AndroidApp) Updatable() bool {
diff --git a/java/app_import.go b/java/app_import.go
index d4da64d..32cec23 100644
--- a/java/app_import.go
+++ b/java/app_import.go
@@ -394,12 +394,12 @@
return false
}
-func (a *AndroidAppImport) sdkVersion() sdkSpec {
- return sdkSpecFrom("")
+func (a *AndroidAppImport) SdkVersion() android.SdkSpec {
+ return android.SdkSpecFrom("")
}
-func (a *AndroidAppImport) minSdkVersion() sdkSpec {
- return sdkSpecFrom("")
+func (a *AndroidAppImport) MinSdkVersion() android.SdkSpec {
+ return android.SdkSpecFrom("")
}
var _ android.ApexModule = (*AndroidAppImport)(nil)
diff --git a/java/base.go b/java/base.go
index bd394af..9bc0738 100644
--- a/java/base.go
+++ b/java/base.go
@@ -373,11 +373,11 @@
}
func (j *Module) CheckStableSdkVersion() error {
- sdkVersion := j.sdkVersion()
- if sdkVersion.stable() {
+ sdkVersion := j.SdkVersion()
+ if sdkVersion.Stable() {
return nil
}
- if sdkVersion.kind == sdkCorePlatform {
+ if sdkVersion.Kind == android.SdkCorePlatform {
if useLegacyCorePlatformApiByName(j.BaseModuleName()) {
return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion)
} else {
@@ -392,8 +392,8 @@
// checkSdkVersions enforces restrictions around SDK dependencies.
func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
if j.RequiresStableAPIs(ctx) {
- if sc, ok := ctx.Module().(sdkContext); ok {
- if !sc.sdkVersion().specified() {
+ if sc, ok := ctx.Module().(android.SdkContext); ok {
+ if !sc.SdkVersion().Specified() {
ctx.PropertyErrorf("sdk_version",
"sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
}
@@ -416,9 +416,9 @@
}
func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
- if sc, ok := ctx.Module().(sdkContext); ok {
+ if sc, ok := ctx.Module().(android.SdkContext); ok {
usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
- sdkVersionSpecified := sc.sdkVersion().specified()
+ sdkVersionSpecified := sc.SdkVersion().Specified()
if usePlatformAPI && sdkVersionSpecified {
ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
} else if !usePlatformAPI && !sdkVersionSpecified {
@@ -512,30 +512,30 @@
return false
}
-func (j *Module) sdkVersion() sdkSpec {
- return sdkSpecFrom(String(j.deviceProperties.Sdk_version))
+func (j *Module) SdkVersion() android.SdkSpec {
+ return android.SdkSpecFrom(String(j.deviceProperties.Sdk_version))
}
-func (j *Module) systemModules() string {
+func (j *Module) SystemModules() string {
return proptools.String(j.deviceProperties.System_modules)
}
-func (j *Module) minSdkVersion() sdkSpec {
+func (j *Module) MinSdkVersion() android.SdkSpec {
if j.deviceProperties.Min_sdk_version != nil {
- return sdkSpecFrom(*j.deviceProperties.Min_sdk_version)
+ return android.SdkSpecFrom(*j.deviceProperties.Min_sdk_version)
}
- return j.sdkVersion()
+ return j.SdkVersion()
}
-func (j *Module) targetSdkVersion() sdkSpec {
+func (j *Module) TargetSdkVersion() android.SdkSpec {
if j.deviceProperties.Target_sdk_version != nil {
- return sdkSpecFrom(*j.deviceProperties.Target_sdk_version)
+ return android.SdkSpecFrom(*j.deviceProperties.Target_sdk_version)
}
- return j.sdkVersion()
+ return j.SdkVersion()
}
-func (j *Module) MinSdkVersion() string {
- return j.minSdkVersion().version.String()
+func (j *Module) MinSdkVersionString() string {
+ return j.MinSdkVersion().ApiLevel.String()
}
func (j *Module) AvailableFor(what string) bool {
@@ -552,7 +552,7 @@
if ctx.Device() {
j.linter.deps(ctx)
- sdkDeps(ctx, sdkContext(j), j.dexer)
+ sdkDeps(ctx, android.SdkContext(j), j.dexer)
if j.deviceProperties.SyspropPublicStub != "" {
// This is a sysprop implementation library that has a corresponding sysprop public
@@ -702,7 +702,7 @@
var flags javaBuilderFlags
// javaVersion flag.
- flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
+ flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), android.SdkContext(j))
if ctx.Config().RunErrorProne() {
if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil {
@@ -731,7 +731,7 @@
flags.processors = android.FirstUniqueStrings(flags.processors)
if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
- decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
+ decodeSdkDep(ctx, android.SdkContext(j)).hasStandardLibs() {
// Give host-side tools a version of OpenJDK's standard libraries
// close to what they're targeting. As of Dec 2017, AOSP is only
// bundling OpenJDK 8 and 9, so nothing < 8 is available.
@@ -1209,7 +1209,7 @@
}
// Dex compilation
var dexOutputFile android.OutputPath
- dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
+ dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(), outputFile, jarName)
if ctx.Failed() {
return
}
@@ -1254,8 +1254,8 @@
}
if ctx.Device() {
- lintSDKVersionString := func(sdkSpec sdkSpec) string {
- if v := sdkSpec.version; v.isNumbered() {
+ lintSDKVersionString := func(sdkSpec android.SdkSpec) string {
+ if v := sdkSpec.ApiLevel; !v.IsPreview() {
return v.String()
} else {
return ctx.Config().DefaultAppTargetSdk(ctx).String()
@@ -1267,9 +1267,9 @@
j.linter.srcJars = srcJars
j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
j.linter.classes = j.implementationJarFile
- j.linter.minSdkVersion = lintSDKVersionString(j.minSdkVersion())
- j.linter.targetSdkVersion = lintSDKVersionString(j.targetSdkVersion())
- j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
+ j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion())
+ j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion())
+ j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion())
j.linter.javaLanguageLevel = flags.javaVersion.String()
j.linter.kotlinLanguageLevel = "1.3"
if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
@@ -1471,18 +1471,18 @@
// Implements android.ApexModule
func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
- sdkSpec := j.minSdkVersion()
- if !sdkSpec.specified() {
+ sdkSpec := j.MinSdkVersion()
+ if !sdkSpec.Specified() {
return fmt.Errorf("min_sdk_version is not specified")
}
- if sdkSpec.kind == sdkCore {
+ if sdkSpec.Kind == android.SdkCore {
return nil
}
- ver, err := sdkSpec.effectiveVersion(ctx)
+ ver, err := sdkSpec.EffectiveVersion(ctx)
if err != nil {
return err
}
- if ver.ApiLevel(ctx).GreaterThan(sdkVersion) {
+ if ver.GreaterThan(sdkVersion) {
return fmt.Errorf("newer SDK(%v)", ver)
}
return nil
@@ -1576,24 +1576,24 @@
return linkType, true
}
- ver := m.sdkVersion()
- switch ver.kind {
- case sdkCore:
+ ver := m.SdkVersion()
+ switch ver.Kind {
+ case android.SdkCore:
return javaCore, false
- case sdkSystem:
+ case android.SdkSystem:
return javaSystem, false
- case sdkPublic:
+ case android.SdkPublic:
return javaSdk, false
- case sdkModule:
+ case android.SdkModule:
return javaModule, false
- case sdkSystemServer:
+ case android.SdkSystemServer:
return javaSystemServer, false
- case sdkPrivate, sdkNone, sdkCorePlatform, sdkTest:
+ case android.SdkPrivate, android.SdkNone, android.SdkCorePlatform, android.SdkTest:
return javaPlatform, false
}
- if !ver.valid() {
- panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw))
+ if !ver.Valid() {
+ panic(fmt.Errorf("sdk_version is invalid. got %q", ver.Raw))
}
return javaSdk, false
}
@@ -1625,7 +1625,7 @@
var deps deps
if ctx.Device() {
- sdkDep := decodeSdkDep(ctx, sdkContext(j))
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
if sdkDep.invalidVersion {
ctx.AddMissingDependencies(sdkDep.bootclasspath)
ctx.AddMissingDependencies(sdkDep.java9Classpath)
@@ -1656,7 +1656,7 @@
if dep, ok := module.(SdkLibraryDependency); ok {
switch tag {
case libTag:
- deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
+ deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...)
case staticLibTag:
ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
}
diff --git a/java/config/kotlin.go b/java/config/kotlin.go
index fd8e3db..6cb61f3 100644
--- a/java/config/kotlin.go
+++ b/java/config/kotlin.go
@@ -35,11 +35,16 @@
pctx.SourcePathVariable("KotlinAnnotationJar", "external/kotlinc/lib/annotations-13.0.jar")
pctx.SourcePathVariable("KotlinStdlibJar", KotlinStdlibJar)
- // These flags silence "Illegal reflective access" warnings when running kotlinc in OpenJDK9
- pctx.StaticVariable("KotlincSuppressJDK9Warnings", strings.Join([]string{
+ // These flags silence "Illegal reflective access" warnings when running kapt in OpenJDK9+
+ pctx.StaticVariable("KaptSuppressJDK9Warnings", strings.Join([]string{
"-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"-J--add-opens=java.base/sun.net.www.protocol.jar=ALL-UNNAMED",
}, " "))
+
+ // These flags silence "Illegal reflective access" warnings when running kotlinc in OpenJDK9+
+ pctx.StaticVariable("KotlincSuppressJDK9Warnings", strings.Join([]string{
+ "-J--add-opens=java.base/java.util=ALL-UNNAMED", // https://youtrack.jetbrains.com/issue/KT-43704
+ }, " "))
}
diff --git a/java/dex.go b/java/dex.go
index b042f13..7898e9d 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -15,6 +15,7 @@
package java
import (
+ "strconv"
"strings"
"github.com/google/blueprint"
@@ -157,7 +158,7 @@
}, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir",
"r8Flags", "zipFlags"}, []string{"implicits"})
-func (d *dexer) dexCommonFlags(ctx android.ModuleContext, minSdkVersion sdkSpec) []string {
+func (d *dexer) dexCommonFlags(ctx android.ModuleContext, minSdkVersion android.SdkSpec) []string {
flags := d.dexProperties.Dxflags
// Translate all the DX flags to D8 ones until all the build files have been migrated
// to D8 flags. See: b/69377755
@@ -174,12 +175,12 @@
"--verbose")
}
- effectiveVersion, err := minSdkVersion.effectiveVersion(ctx)
+ effectiveVersion, err := minSdkVersion.EffectiveVersion(ctx)
if err != nil {
ctx.PropertyErrorf("min_sdk_version", "%s", err)
}
- flags = append(flags, "--min-api "+effectiveVersion.asNumberString())
+ flags = append(flags, "--min-api "+strconv.Itoa(effectiveVersion.FinalOrFutureInt()))
return flags
}
@@ -266,7 +267,7 @@
return r8Flags, r8Deps
}
-func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion sdkSpec,
+func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion android.SdkSpec,
classesJar android.Path, jarName string) android.OutputPath {
// Compile classes.jar into classes.dex and then javalib.jar
diff --git a/java/droiddoc.go b/java/droiddoc.go
index f7595b1..e527d59 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -98,10 +98,6 @@
// names of the output files used in args that will be generated
Out []string
-
- // If set, metalava is sandboxed to only read files explicitly specified on the command
- // line. Defaults to false.
- Sandbox *bool
}
type ApiToCheck struct {
@@ -265,25 +261,25 @@
var _ android.OutputFileProducer = (*Javadoc)(nil)
-func (j *Javadoc) sdkVersion() sdkSpec {
- return sdkSpecFrom(String(j.properties.Sdk_version))
+func (j *Javadoc) SdkVersion() android.SdkSpec {
+ return android.SdkSpecFrom(String(j.properties.Sdk_version))
}
-func (j *Javadoc) systemModules() string {
+func (j *Javadoc) SystemModules() string {
return proptools.String(j.properties.System_modules)
}
-func (j *Javadoc) minSdkVersion() sdkSpec {
- return j.sdkVersion()
+func (j *Javadoc) MinSdkVersion() android.SdkSpec {
+ return j.SdkVersion()
}
-func (j *Javadoc) targetSdkVersion() sdkSpec {
- return j.sdkVersion()
+func (j *Javadoc) TargetSdkVersion() android.SdkSpec {
+ return j.SdkVersion()
}
func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
if ctx.Device() {
- sdkDep := decodeSdkDep(ctx, sdkContext(j))
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
if sdkDep.useModule {
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
@@ -361,7 +357,7 @@
func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
var deps deps
- sdkDep := decodeSdkDep(ctx, sdkContext(j))
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
if sdkDep.invalidVersion {
ctx.AddMissingDependencies(sdkDep.bootclasspath)
ctx.AddMissingDependencies(sdkDep.java9Classpath)
@@ -390,7 +386,7 @@
}
case libTag:
if dep, ok := module.(SdkLibraryDependency); ok {
- deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
+ deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...)
} else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
deps.classpath = append(deps.classpath, dep.HeaderJars...)
@@ -555,7 +551,7 @@
srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
- javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
+ javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), android.SdkContext(j))
cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
deps.systemModules, deps.classpath, j.sourcepaths)
diff --git a/java/droidstubs.go b/java/droidstubs.go
index d7a0668..a9e2749 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -383,7 +383,7 @@
func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths,
- implicitsRsp, homeDir android.WritablePath, sandbox bool) *android.RuleBuilderCommand {
+ homeDir android.WritablePath) *android.RuleBuilderCommand {
rule.Command().Text("rm -rf").Flag(homeDir.String())
rule.Command().Text("mkdir -p").Flag(homeDir.String())
@@ -392,39 +392,16 @@
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_METALAVA") {
rule.Remoteable(android.RemoteRuleSupports{RBE: true})
- if sandbox {
- execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
- labels := map[string]string{"type": "tool", "name": "metalava"}
- // TODO: metalava pool rejects these jobs
- pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "java16")
- rule.Rewrapper(&remoteexec.REParams{
- Labels: labels,
- ExecStrategy: execStrategy,
- ToolchainInputs: []string{config.JavaCmd(ctx).String()},
- Platform: map[string]string{remoteexec.PoolKey: pool},
- })
- } else {
- execStrategy := remoteexec.LocalExecStrategy
- labels := map[string]string{"type": "compile", "lang": "java", "compiler": "metalava", "shallow": "true"}
- pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "metalava")
-
- inputs := []string{
- ctx.Config().HostJavaToolPath(ctx, "metalava").String(),
- homeDir.String(),
- }
- if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" {
- inputs = append(inputs, strings.Split(v, ",")...)
- }
- cmd.Text((&remoteexec.REParams{
- Labels: labels,
- ExecStrategy: execStrategy,
- Inputs: inputs,
- RSPFiles: []string{implicitsRsp.String()},
- ToolchainInputs: []string{config.JavaCmd(ctx).String()},
- Platform: map[string]string{remoteexec.PoolKey: pool},
- EnvironmentVariables: []string{"ANDROID_PREFS_ROOT"},
- }).NoVarTemplate(ctx.Config().RBEWrapper()))
- }
+ execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
+ labels := map[string]string{"type": "tool", "name": "metalava"}
+ // TODO: metalava pool rejects these jobs
+ pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "java16")
+ rule.Rewrapper(&remoteexec.REParams{
+ Labels: labels,
+ ExecStrategy: execStrategy,
+ ToolchainInputs: []string{config.JavaCmd(ctx).String()},
+ Platform: map[string]string{remoteexec.PoolKey: pool},
+ })
}
cmd.BuiltTool("metalava").ImplicitTool(ctx.Config().HostJavaToolPath(ctx, "metalava.jar")).
@@ -435,18 +412,6 @@
FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "metalava.rsp"), srcs).
FlagWithInput("@", srcJarList)
- if !sandbox {
- if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" {
- cmd.Implicit(android.PathForSource(ctx, javaHome))
- }
-
- cmd.FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt"))
-
- if implicitsRsp != nil {
- cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String())
- }
- }
-
if len(bootclasspath) > 0 {
cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
}
@@ -474,7 +439,7 @@
func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
deps := d.Javadoc.collectDeps(ctx)
- javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
+ javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), android.SdkContext(d))
// Create rule for metalava
@@ -482,12 +447,9 @@
rule := android.NewRuleBuilder(pctx, ctx)
- sandbox := proptools.BoolDefault(d.Javadoc.properties.Sandbox, true)
- if sandbox {
- rule.Sbox(android.PathForModuleOut(ctx, "metalava"),
- android.PathForModuleOut(ctx, "metalava.sbox.textproto")).
- SandboxInputs()
- }
+ rule.Sbox(android.PathForModuleOut(ctx, "metalava"),
+ android.PathForModuleOut(ctx, "metalava.sbox.textproto")).
+ SandboxInputs()
if BoolDefault(d.properties.High_mem, false) {
// This metalava run uses lots of memory, restrict the number of metalava jobs that can run in parallel.
@@ -505,11 +467,9 @@
srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
- implicitsRsp := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp")
homeDir := android.PathForModuleOut(ctx, "metalava", "home")
cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
- deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, implicitsRsp, homeDir,
- sandbox)
+ deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, homeDir)
cmd.Implicits(d.Javadoc.implicits)
d.stubsFlags(ctx, cmd, stubsDir)
@@ -628,22 +588,6 @@
cmd.FlagWithArg("--error-message:compatibility:released ", msg)
}
- if !sandbox {
- // When sandboxing is enabled RuleBuilder tracks all the inputs needed for remote execution.
- // Without it we have to do it manually.
- impRule := android.NewRuleBuilder(pctx, ctx)
- impCmd := impRule.Command()
- // An action that copies the ninja generated rsp file to a new location. This allows us to
- // add a large number of inputs to a file without exceeding bash command length limits (which
- // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the
- // rsp file to be ${output}.rsp.
- impCmd.Text("cp").
- FlagWithRspFileInputList("", android.PathForModuleOut(ctx, "metalava-implicits.rsp"), cmd.GetImplicits()).
- Output(implicitsRsp)
- impRule.Build("implicitsGen", "implicits generation")
- cmd.Implicit(implicitsRsp)
- }
-
if generateStubs {
rule.Command().
BuiltTool("soong_zip").
@@ -675,9 +619,7 @@
}
// TODO(b/183630617): rewrapper doesn't support restat rules
- if !sandbox {
- rule.Restat()
- }
+ // rule.Restat()
zipSyncCleanupCmd(rule, srcJarDir)
diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go
index f8125fb..db664c1 100644
--- a/java/droidstubs_test.go
+++ b/java/droidstubs_test.go
@@ -34,7 +34,6 @@
srcs: ["bar-doc/a.java"],
api_levels_annotations_dirs: ["droiddoc-templates-sdk"],
api_levels_annotations_enabled: true,
- sandbox: false,
}
droidstubs {
@@ -44,7 +43,6 @@
api_levels_annotations_dirs: ["droiddoc-templates-sdk"],
api_levels_annotations_enabled: true,
api_levels_jar_filename: "android.other.jar",
- sandbox: false,
}
`,
map[string][]byte{
@@ -68,13 +66,15 @@
}
for _, c := range testcases {
m := ctx.ModuleForTests(c.moduleName, "android_common")
- metalava := m.Rule("metalava")
- rp := metalava.RuleParams
+ manifest := m.Output("metalava.sbox.textproto")
+ sboxProto := android.RuleBuilderSboxProtoForTests(t, manifest)
expected := "--android-jar-pattern ./%/public/" + c.expectedJarFilename
- if actual := rp.Command; !strings.Contains(actual, expected) {
+ if actual := String(sboxProto.Commands[0].Command); !strings.Contains(actual, expected) {
t.Errorf("For %q, expected metalava argument %q, but was not found %q", c.moduleName, expected, actual)
}
+ metalava := m.Rule("metalava")
+ rp := metalava.RuleParams
if actual := rp.Pool != nil && strings.Contains(rp.Pool.String(), "highmem"); actual != c.high_mem {
t.Errorf("Expected %q high_mem to be %v, was %v", c.moduleName, c.high_mem, actual)
}
@@ -92,7 +92,6 @@
droidstubs {
name: "bar-stubs",
srcs: ["bar-doc/a.java"],
- sandbox: true,
args: "--reference $(location :foo)",
arg_files: [":foo"],
diff --git a/java/java.go b/java/java.go
index 26e5091..fa7c96e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -304,7 +304,7 @@
unstrippedFile android.Path
}
-func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext sdkContext, d dexer) {
+func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, d dexer) {
sdkDep := decodeSdkDep(ctx, sdkContext)
if sdkDep.useModule {
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
@@ -352,11 +352,11 @@
}
}
-func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
+func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext android.SdkContext) javaVersion {
if javaVersion != "" {
return normalizeJavaVersion(ctx, javaVersion)
} else if ctx.Device() {
- return sdkContext.sdkVersion().defaultJavaLanguageVersion(ctx)
+ return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion())
} else {
return JAVA_VERSION_9
}
@@ -776,7 +776,7 @@
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if j.testProperties.Test_options.Unit_test == nil && ctx.Host() {
// TODO(b/): Clean temporary heuristic to avoid unexpected onboarding.
- defaultUnitTest := !inList("tradefed", j.properties.Static_libs) && !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites)
+ defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites)
j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest)
}
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
@@ -1132,31 +1132,31 @@
hideApexVariantFromMake bool
}
-func (j *Import) sdkVersion() sdkSpec {
- return sdkSpecFrom(String(j.properties.Sdk_version))
+func (j *Import) SdkVersion() android.SdkSpec {
+ return android.SdkSpecFrom(String(j.properties.Sdk_version))
}
func (j *Import) makeSdkVersion() string {
- return j.sdkVersion().raw
+ return j.SdkVersion().Raw
}
-func (j *Import) systemModules() string {
+func (j *Import) SystemModules() string {
return "none"
}
-func (j *Import) minSdkVersion() sdkSpec {
+func (j *Import) MinSdkVersion() android.SdkSpec {
if j.properties.Min_sdk_version != nil {
- return sdkSpecFrom(*j.properties.Min_sdk_version)
+ return android.SdkSpecFrom(*j.properties.Min_sdk_version)
}
- return j.sdkVersion()
+ return j.SdkVersion()
}
-func (j *Import) targetSdkVersion() sdkSpec {
- return j.sdkVersion()
+func (j *Import) TargetSdkVersion() android.SdkSpec {
+ return j.SdkVersion()
}
-func (j *Import) MinSdkVersion() string {
- return j.minSdkVersion().version.String()
+func (j *Import) MinSdkVersionString() string {
+ return j.MinSdkVersion().ApiLevel.String()
}
func (j *Import) Prebuilt() *android.Prebuilt {
@@ -1187,7 +1187,7 @@
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
- sdkDeps(ctx, sdkContext(j), j.dexer)
+ sdkDeps(ctx, android.SdkContext(j), j.dexer)
}
}
@@ -1230,7 +1230,7 @@
} else if dep, ok := module.(SdkLibraryDependency); ok {
switch tag {
case libTag:
- flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
+ flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...)
}
}
@@ -1272,7 +1272,7 @@
ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt_apex %q", deapexerModule.Name())
}
} else if Bool(j.dexProperties.Compile_dex) {
- sdkDep := decodeSdkDep(ctx, sdkContext(j))
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
if sdkDep.invalidVersion {
ctx.AddMissingDependencies(sdkDep.bootclasspath)
ctx.AddMissingDependencies(sdkDep.java9Classpath)
@@ -1291,7 +1291,7 @@
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
var dexOutputFile android.OutputPath
- dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
+ dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(), outputFile, jarName)
if ctx.Failed() {
return
}
@@ -1359,18 +1359,18 @@
// Implements android.ApexModule
func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
- sdkSpec := j.minSdkVersion()
- if !sdkSpec.specified() {
+ sdkSpec := j.MinSdkVersion()
+ if !sdkSpec.Specified() {
return fmt.Errorf("min_sdk_version is not specified")
}
- if sdkSpec.kind == sdkCore {
+ if sdkSpec.Kind == android.SdkCore {
return nil
}
- ver, err := sdkSpec.effectiveVersion(ctx)
+ ver, err := sdkSpec.EffectiveVersion(ctx)
if err != nil {
return err
}
- if ver.ApiLevel(ctx).GreaterThan(sdkVersion) {
+ if ver.GreaterThan(sdkVersion) {
return fmt.Errorf("newer SDK(%v)", ver)
}
return nil
diff --git a/java/kotlin.go b/java/kotlin.go
index 2960f81..3a6fc0f 100644
--- a/java/kotlin.go
+++ b/java/kotlin.go
@@ -34,8 +34,9 @@
`${config.GenKotlinBuildFileCmd} --classpath "$classpath" --name "$name"` +
` --out_dir "$classesDir" --srcs "$out.rsp" --srcs "$srcJarDir/list"` +
` $commonSrcFilesArg --out "$kotlinBuildFile" && ` +
- `${config.KotlincCmd} ${config.JavacHeapFlags} $kotlincFlags ` +
- `-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile -kotlin-home $emptyDir && ` +
+ `${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} ` +
+ `$kotlincFlags -jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile ` +
+ `-kotlin-home $emptyDir && ` +
`${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` +
`rm -rf "$srcJarDir"`,
CommandDeps: []string{
@@ -123,8 +124,8 @@
`${config.GenKotlinBuildFileCmd} --classpath "$classpath" --name "$name"` +
` --srcs "$out.rsp" --srcs "$srcJarDir/list"` +
` $commonSrcFilesArg --out "$kotlinBuildFile" && ` +
- `${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} $kotlincFlags ` +
- `-Xplugin=${config.KotlinKaptJar} ` +
+ `${config.KotlincCmd} ${config.KaptSuppressJDK9Warnings} ${config.KotlincSuppressJDK9Warnings} ` +
+ `${config.JavacHeapFlags} $kotlincFlags -Xplugin=${config.KotlinKaptJar} ` +
`-P plugin:org.jetbrains.kotlin.kapt3:sources=$kaptDir/sources ` +
`-P plugin:org.jetbrains.kotlin.kapt3:classes=$kaptDir/classes ` +
`-P plugin:org.jetbrains.kotlin.kapt3:stubs=$kaptDir/stubs ` +
diff --git a/java/rro.go b/java/rro.go
index aafa88e..4ae0014 100644
--- a/java/rro.go
+++ b/java/rro.go
@@ -91,7 +91,7 @@
}
func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) {
- sdkDep := decodeSdkDep(ctx, sdkContext(r))
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(r))
if sdkDep.hasFrameworkLibs() {
r.aapt.deps(ctx, sdkDep)
}
@@ -141,23 +141,23 @@
ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
}
-func (r *RuntimeResourceOverlay) sdkVersion() sdkSpec {
- return sdkSpecFrom(String(r.properties.Sdk_version))
+func (r *RuntimeResourceOverlay) SdkVersion() android.SdkSpec {
+ return android.SdkSpecFrom(String(r.properties.Sdk_version))
}
-func (r *RuntimeResourceOverlay) systemModules() string {
+func (r *RuntimeResourceOverlay) SystemModules() string {
return ""
}
-func (r *RuntimeResourceOverlay) minSdkVersion() sdkSpec {
+func (r *RuntimeResourceOverlay) MinSdkVersion() android.SdkSpec {
if r.properties.Min_sdk_version != nil {
- return sdkSpecFrom(*r.properties.Min_sdk_version)
+ return android.SdkSpecFrom(*r.properties.Min_sdk_version)
}
- return r.sdkVersion()
+ return r.SdkVersion()
}
-func (r *RuntimeResourceOverlay) targetSdkVersion() sdkSpec {
- return r.sdkVersion()
+func (r *RuntimeResourceOverlay) TargetSdkVersion() android.SdkSpec {
+ return r.SdkVersion()
}
func (r *RuntimeResourceOverlay) Certificate() Certificate {
diff --git a/java/sdk.go b/java/sdk.go
index 74d5a81..f324b76 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -19,7 +19,6 @@
"path/filepath"
"sort"
"strconv"
- "strings"
"android/soong/android"
"android/soong/java/config"
@@ -38,19 +37,6 @@
var nonUpdatableFrameworkAidlPathKey = android.NewOnceKey("nonUpdatableFrameworkAidlPathKey")
var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey")
-type sdkContext interface {
- // sdkVersion returns sdkSpec that corresponds to the sdk_version property of the current module
- sdkVersion() sdkSpec
- // systemModules returns the system_modules property of the current module, or an empty string if it is not set.
- systemModules() string
- // minSdkVersion returns sdkSpec that corresponds to the min_sdk_version property of the current module,
- // or from sdk_version if it is not set.
- minSdkVersion() sdkSpec
- // targetSdkVersion returns the sdkSpec that corresponds to the target_sdk_version property of the current module,
- // or from sdk_version if it is not set.
- targetSdkVersion() sdkSpec
-}
-
func UseApiFingerprint(ctx android.BaseModuleContext) bool {
if ctx.Config().UnbundledBuild() &&
!ctx.Config().AlwaysUsePrebuiltSdks() &&
@@ -60,318 +46,41 @@
return false
}
-// sdkKind represents a particular category of an SDK spec like public, system, test, etc.
-type sdkKind int
-
-const (
- sdkInvalid sdkKind = iota
- sdkNone
- sdkCore
- sdkCorePlatform
- sdkPublic
- sdkSystem
- sdkTest
- sdkModule
- sdkSystemServer
- sdkPrivate
-)
-
-// String returns the string representation of this sdkKind
-func (k sdkKind) String() string {
- switch k {
- case sdkPrivate:
- return "private"
- case sdkNone:
- return "none"
- case sdkPublic:
- return "public"
- case sdkSystem:
- return "system"
- case sdkTest:
- return "test"
- case sdkCore:
- return "core"
- case sdkCorePlatform:
- return "core_platform"
- case sdkModule:
- return "module-lib"
- case sdkSystemServer:
- return "system-server"
- default:
- return "invalid"
- }
-}
-
-// sdkVersion represents a specific version number of an SDK spec of a particular kind
-type sdkVersion int
-
-const (
- // special version number for a not-yet-frozen SDK
- sdkVersionCurrent sdkVersion = sdkVersion(android.FutureApiLevelInt)
- // special version number to be used for SDK specs where version number doesn't
- // make sense, e.g. "none", "", etc.
- sdkVersionNone sdkVersion = sdkVersion(0)
-)
-
-// isCurrent checks if the sdkVersion refers to the not-yet-published version of an sdkKind
-func (v sdkVersion) isCurrent() bool {
- return v == sdkVersionCurrent
-}
-
-// isNumbered checks if the sdkVersion refers to the published (a.k.a numbered) version of an sdkKind
-func (v sdkVersion) isNumbered() bool {
- return !v.isCurrent() && v != sdkVersionNone
-}
-
-// String returns the string representation of this sdkVersion.
-func (v sdkVersion) String() string {
- if v.isCurrent() {
- return "current"
- } else if v.isNumbered() {
- return strconv.Itoa(int(v))
- }
- return "(no version)"
-}
-
-func (v sdkVersion) ApiLevel(ctx android.EarlyModuleContext) android.ApiLevel {
- return android.ApiLevelOrPanic(ctx, v.String())
-}
-
-// asNumberString directly converts the numeric value of this sdk version as a string.
-// When isNumbered() is true, this method is the same as String(). However, for sdkVersionCurrent
-// and sdkVersionNone, this returns 10000 and 0 while String() returns "current" and "(no version"),
-// respectively.
-func (v sdkVersion) asNumberString() string {
- return strconv.Itoa(int(v))
-}
-
-// sdkSpec represents the kind and the version of an SDK for a module to build against
-type sdkSpec struct {
- kind sdkKind
- version sdkVersion
- raw string
-}
-
-func (s sdkSpec) String() string {
- return fmt.Sprintf("%s_%s", s.kind, s.version)
-}
-
-// valid checks if this sdkSpec is well-formed. Note however that true doesn't mean that the
-// specified SDK actually exists.
-func (s sdkSpec) valid() bool {
- return s.kind != sdkInvalid
-}
-
-// specified checks if this sdkSpec is well-formed and is not "".
-func (s sdkSpec) specified() bool {
- return s.valid() && s.kind != sdkPrivate
-}
-
-// whether the API surface is managed and versioned, i.e. has .txt file that
-// get frozen on SDK freeze and changes get reviewed by API council.
-func (s sdkSpec) stable() bool {
- if !s.specified() {
- return false
- }
- switch s.kind {
- case sdkNone:
- // there is nothing to manage and version in this case; de facto stable API.
- return true
- case sdkCore, sdkPublic, sdkSystem, sdkModule, sdkSystemServer:
- return true
- case sdkCorePlatform, sdkTest, sdkPrivate:
- return false
- default:
- panic(fmt.Errorf("unknown sdkKind=%v", s.kind))
- }
- return false
-}
-
-// prebuiltSdkAvailableForUnbundledBuilt tells whether this sdkSpec can have a prebuilt SDK
-// that can be used for unbundled builds.
-func (s sdkSpec) prebuiltSdkAvailableForUnbundledBuild() bool {
- // "", "none", and "core_platform" are not available for unbundled build
- // as we don't/can't have prebuilt stub for the versions
- return s.kind != sdkPrivate && s.kind != sdkNone && s.kind != sdkCorePlatform
-}
-
-func (s sdkSpec) forVendorPartition(ctx android.EarlyModuleContext) sdkSpec {
- // If BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES has a numeric value,
- // use it instead of "current" for the vendor partition.
- currentSdkVersion := ctx.DeviceConfig().CurrentApiLevelForVendorModules()
- if currentSdkVersion == "current" {
- return s
- }
-
- if s.kind == sdkPublic || s.kind == sdkSystem {
- if s.version.isCurrent() {
- if i, err := strconv.Atoi(currentSdkVersion); err == nil {
- version := sdkVersion(i)
- return sdkSpec{s.kind, version, s.raw}
- }
- panic(fmt.Errorf("BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES must be either \"current\" or a number, but was %q", currentSdkVersion))
- }
- }
- return s
-}
-
-// usePrebuilt determines whether prebuilt SDK should be used for this sdkSpec with the given context.
-func (s sdkSpec) usePrebuilt(ctx android.EarlyModuleContext) bool {
- if s.version.isCurrent() {
- // "current" can be built from source and be from prebuilt SDK
- return ctx.Config().AlwaysUsePrebuiltSdks()
- } else if s.version.isNumbered() {
- // validation check
- if s.kind != sdkPublic && s.kind != sdkSystem && s.kind != sdkTest && s.kind != sdkModule {
- panic(fmt.Errorf("prebuilt SDK is not not available for sdkKind=%q", s.kind))
- return false
- }
- // numbered SDKs are always from prebuilt
- return true
- }
- // "", "none", "core_platform" fall here
- return false
-}
-
-// effectiveVersion converts an sdkSpec into the concrete sdkVersion that the module
-// should use. For modules targeting an unreleased SDK (meaning it does not yet have a number)
-// it returns android.FutureApiLevel(10000).
-func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, error) {
- if !s.valid() {
- return s.version, fmt.Errorf("invalid sdk version %q", s.raw)
- }
-
- if ctx.DeviceSpecific() || ctx.SocSpecific() {
- s = s.forVendorPartition(ctx)
- }
- if s.version.isNumbered() {
- return s.version, nil
- }
- return sdkVersion(ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt()), nil
-}
-
-// effectiveVersionString converts an sdkSpec into the concrete version string that the module
-// should use. For modules targeting an unreleased SDK (meaning it does not yet have a number)
-// it returns the codename (P, Q, R, etc.)
-func (s sdkSpec) effectiveVersionString(ctx android.EarlyModuleContext) (string, error) {
- ver, err := s.effectiveVersion(ctx)
- if err == nil && int(ver) == ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt() {
- return ctx.Config().DefaultAppTargetSdk(ctx).String(), nil
- }
- return ver.String(), err
-}
-
-func (s sdkSpec) defaultJavaLanguageVersion(ctx android.EarlyModuleContext) javaVersion {
- sdk, err := s.effectiveVersion(ctx)
+func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpec) javaVersion {
+ sdk, err := s.EffectiveVersion(ctx)
if err != nil {
ctx.PropertyErrorf("sdk_version", "%s", err)
}
- if sdk <= 23 {
+ if sdk.FinalOrFutureInt() <= 23 {
return JAVA_VERSION_7
- } else if sdk <= 29 {
+ } else if sdk.FinalOrFutureInt() <= 29 {
return JAVA_VERSION_8
} else {
return JAVA_VERSION_9
}
}
-func sdkSpecFrom(str string) sdkSpec {
- switch str {
- // special cases first
- case "":
- return sdkSpec{sdkPrivate, sdkVersionNone, str}
- case "none":
- return sdkSpec{sdkNone, sdkVersionNone, str}
- case "core_platform":
- return sdkSpec{sdkCorePlatform, sdkVersionNone, str}
- default:
- // the syntax is [kind_]version
- sep := strings.LastIndex(str, "_")
-
- var kindString string
- if sep == 0 {
- return sdkSpec{sdkInvalid, sdkVersionNone, str}
- } else if sep == -1 {
- kindString = ""
- } else {
- kindString = str[0:sep]
- }
- versionString := str[sep+1 : len(str)]
-
- var kind sdkKind
- switch kindString {
- case "":
- kind = sdkPublic
- case "core":
- kind = sdkCore
- case "system":
- kind = sdkSystem
- case "test":
- kind = sdkTest
- case "module":
- kind = sdkModule
- case "system_server":
- kind = sdkSystemServer
- default:
- return sdkSpec{sdkInvalid, sdkVersionNone, str}
- }
-
- var version sdkVersion
- if versionString == "current" {
- version = sdkVersionCurrent
- } else if i, err := strconv.Atoi(versionString); err == nil {
- version = sdkVersion(i)
- } else {
- return sdkSpec{sdkInvalid, sdkVersionNone, str}
- }
-
- return sdkSpec{kind, version, str}
- }
-}
-
-func (s sdkSpec) validateSystemSdk(ctx android.EarlyModuleContext) bool {
- // Ensures that the specified system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor/product Java module)
- // Assuming that BOARD_SYSTEMSDK_VERSIONS := 28 29,
- // sdk_version of the modules in vendor/product that use system sdk must be either system_28, system_29 or system_current
- if s.kind != sdkSystem || !s.version.isNumbered() {
- return true
- }
- allowedVersions := ctx.DeviceConfig().PlatformSystemSdkVersions()
- if ctx.DeviceSpecific() || ctx.SocSpecific() || (ctx.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
- systemSdkVersions := ctx.DeviceConfig().SystemSdkVersions()
- if len(systemSdkVersions) > 0 {
- allowedVersions = systemSdkVersions
- }
- }
- if len(allowedVersions) > 0 && !android.InList(s.version.String(), allowedVersions) {
- ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
- s.raw, allowedVersions)
- return false
- }
- return true
-}
-
-func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep {
- sdkVersion := sdkContext.sdkVersion()
- if !sdkVersion.valid() {
- ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.raw)
+func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep {
+ sdkVersion := sdkContext.SdkVersion()
+ if !sdkVersion.Valid() {
+ ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.Raw)
return sdkDep{}
}
if ctx.DeviceSpecific() || ctx.SocSpecific() {
- sdkVersion = sdkVersion.forVendorPartition(ctx)
+ sdkVersion = sdkVersion.ForVendorPartition(ctx)
}
- if !sdkVersion.validateSystemSdk(ctx) {
+ if !sdkVersion.ValidateSystemSdk(ctx) {
return sdkDep{}
}
- if sdkVersion.usePrebuilt(ctx) {
- dir := filepath.Join("prebuilts", "sdk", sdkVersion.version.String(), sdkVersion.kind.String())
+ if sdkVersion.UsePrebuilt(ctx) {
+ dir := filepath.Join("prebuilts", "sdk", sdkVersion.ApiLevel.String(), sdkVersion.Kind.String())
jar := filepath.Join(dir, "android.jar")
// There's no aidl for other SDKs yet.
// TODO(77525052): Add aidl files for other SDKs too.
- publicDir := filepath.Join("prebuilts", "sdk", sdkVersion.version.String(), "public")
+ publicDir := filepath.Join("prebuilts", "sdk", sdkVersion.ApiLevel.String(), "public")
aidl := filepath.Join(publicDir, "framework.aidl")
jarPath := android.ExistentPathForSource(ctx, jar)
aidlPath := android.ExistentPathForSource(ctx, aidl)
@@ -380,23 +89,23 @@
if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
return sdkDep{
invalidVersion: true,
- bootclasspath: []string{fmt.Sprintf("sdk_%s_%s_android", sdkVersion.kind, sdkVersion.version.String())},
+ bootclasspath: []string{fmt.Sprintf("sdk_%s_%s_android", sdkVersion.Kind, sdkVersion.ApiLevel.String())},
}
}
if !jarPath.Valid() {
- ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.raw, jar)
+ ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.Raw, jar)
return sdkDep{}
}
if !aidlPath.Valid() {
- ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.raw, aidl)
+ ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.Raw, aidl)
return sdkDep{}
}
var systemModules string
- if sdkVersion.defaultJavaLanguageVersion(ctx).usesJavaModules() {
- systemModules = "sdk_public_" + sdkVersion.version.String() + "_system_modules"
+ if defaultJavaLanguageVersion(ctx, sdkVersion).usesJavaModules() {
+ systemModules = "sdk_public_" + sdkVersion.ApiLevel.String() + "_system_modules"
}
return sdkDep{
@@ -418,8 +127,8 @@
}
}
- switch sdkVersion.kind {
- case sdkPrivate:
+ switch sdkVersion.Kind {
+ case android.SdkPrivate:
return sdkDep{
useModule: true,
systemModules: corePlatformSystemModules(ctx),
@@ -427,8 +136,8 @@
classpath: config.FrameworkLibraries,
frameworkResModule: "framework-res",
}
- case sdkNone:
- systemModules := sdkContext.systemModules()
+ case android.SdkNone:
+ systemModules := sdkContext.SystemModules()
if systemModules == "" {
ctx.PropertyErrorf("sdk_version",
`system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`)
@@ -444,34 +153,34 @@
systemModules: systemModules,
bootclasspath: []string{systemModules},
}
- case sdkCorePlatform:
+ case android.SdkCorePlatform:
return sdkDep{
useModule: true,
systemModules: corePlatformSystemModules(ctx),
bootclasspath: corePlatformBootclasspathLibraries(ctx),
noFrameworksLibs: true,
}
- case sdkPublic:
+ case android.SdkPublic:
return toModule([]string{"android_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx))
- case sdkSystem:
+ case android.SdkSystem:
return toModule([]string{"android_system_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx))
- case sdkTest:
+ case android.SdkTest:
return toModule([]string{"android_test_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx))
- case sdkCore:
+ case android.SdkCore:
return sdkDep{
useModule: true,
bootclasspath: []string{"core.current.stubs", config.DefaultLambdaStubsLibrary},
systemModules: "core-current-stubs-system-modules",
noFrameworksLibs: true,
}
- case sdkModule:
+ case android.SdkModule:
// TODO(146757305): provide .apk and .aidl that have more APIs for modules
return toModule([]string{"android_module_lib_stubs_current"}, "framework-res", nonUpdatableFrameworkAidlPath(ctx))
- case sdkSystemServer:
+ case android.SdkSystemServer:
// TODO(146757305): provide .apk and .aidl that have more APIs for modules
return toModule([]string{"android_system_server_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx))
default:
- panic(fmt.Errorf("invalid sdk %q", sdkVersion.raw))
+ panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw))
}
}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index e1ca77d..37b8d9f 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -814,22 +814,22 @@
return nil
}
-func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
+func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths {
// If a specific numeric version has been requested then use prebuilt versions of the sdk.
- if sdkVersion.version.isNumbered() {
+ if !sdkVersion.ApiLevel.IsPreview() {
return PrebuiltJars(ctx, c.moduleBase.BaseModuleName(), sdkVersion)
}
var apiScope *apiScope
- switch sdkVersion.kind {
- case sdkSystem:
+ switch sdkVersion.Kind {
+ case android.SdkSystem:
apiScope = apiScopeSystem
- case sdkModule:
+ case android.SdkModule:
apiScope = apiScopeModuleLib
- case sdkTest:
+ case android.SdkTest:
apiScope = apiScopeTest
- case sdkSystemServer:
+ case android.SdkSystemServer:
apiScope = apiScopeSystemServer
default:
apiScope = apiScopePublic
@@ -932,14 +932,14 @@
//
// These are turbine generated jars so they only change if the externals of the
// class changes but it does not contain and implementation or JavaDoc.
- SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
+ SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths
// Get the implementation jars appropriate for the supplied sdk version.
//
// These are either the implementation jar for the whole sdk library or the implementation
// jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise
// they are identical to the corresponding header jars.
- SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
+ SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths
}
type SdkLibrary struct {
@@ -1147,7 +1147,7 @@
return proptools.String(scopeProperties.Sdk_version)
}
- sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
+ sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library))
if sdkDep.hasStandardLibs() {
// If building against a standard sdk then use the sdk version appropriate for the scope.
return apiScope.sdkVersion
@@ -1465,17 +1465,17 @@
mctx.CreateModule(sdkLibraryXmlFactory, &props)
}
-func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths {
- var ver sdkVersion
- var kind sdkKind
- if s.usePrebuilt(ctx) {
- ver = s.version
- kind = s.kind
+func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s android.SdkSpec) android.Paths {
+ var ver android.ApiLevel
+ var kind android.SdkKind
+ if s.UsePrebuilt(ctx) {
+ ver = s.ApiLevel
+ kind = s.Kind
} else {
// We don't have prebuilt SDK for the specific sdkVersion.
// Instead of breaking the build, fallback to use "system_current"
- ver = sdkVersionCurrent
- kind = sdkSystem
+ ver = android.FutureApiLevel
+ kind = android.SdkSystem
}
dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
@@ -1485,7 +1485,7 @@
if ctx.Config().AllowMissingDependencies() {
return android.Paths{android.PathForSource(ctx, jar)}
} else {
- ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar)
+ ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.Raw, jar)
}
return nil
}
@@ -1502,13 +1502,13 @@
return len(otherApexInfo.InApexes) > 0 && reflect.DeepEqual(apexInfo.InApexes, otherApexInfo.InApexes)
}
-func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
+func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec, headerJars bool) android.Paths {
// If the client doesn't set sdk_version, but if this library prefers stubs over
// the impl library, let's provide the widest API surface possible. To do so,
// force override sdk_version to module_current so that the closest possible API
// surface could be found in selectHeaderJarsForSdkVersion
- if module.defaultsToStubs() && !sdkVersion.specified() {
- sdkVersion = sdkSpecFrom("module_current")
+ if module.defaultsToStubs() && !sdkVersion.Specified() {
+ sdkVersion = android.SdkSpecFrom("module_current")
}
// Only provide access to the implementation library if it is actually built.
@@ -1518,7 +1518,7 @@
// Only allow access to the implementation library in the following condition:
// * No sdk_version specified on the referencing module.
// * The referencing module is in the same apex as this.
- if sdkVersion.kind == sdkPrivate || withinSameApexesAs(ctx, module) {
+ if sdkVersion.Kind == android.SdkPrivate || withinSameApexesAs(ctx, module) {
if headerJars {
return module.HeaderJars()
} else {
@@ -1531,12 +1531,12 @@
}
// to satisfy SdkLibraryDependency interface
-func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
+func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths {
return module.sdkJars(ctx, sdkVersion, true /*headerJars*/)
}
// to satisfy SdkLibraryDependency interface
-func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
+func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths {
return module.sdkJars(ctx, sdkVersion, false /*headerJars*/)
}
@@ -1568,7 +1568,7 @@
// If this builds against standard libraries (i.e. is not part of the core libraries)
// then assume it provides both system and test apis.
- sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
+ sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library))
hasSystemAndTestApis := sdkDep.hasStandardLibs()
module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis
@@ -2069,7 +2069,7 @@
}
}
-func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
+func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec, headerJars bool) android.Paths {
// For consistency with SdkLibrary make the implementation jar available to libraries that
// are within the same APEX.
@@ -2086,13 +2086,13 @@
}
// to satisfy SdkLibraryDependency interface
-func (module *SdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
+func (module *SdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths {
// This module is just a wrapper for the prebuilt stubs.
return module.sdkJars(ctx, sdkVersion, true)
}
// to satisfy SdkLibraryDependency interface
-func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
+func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths {
// This module is just a wrapper for the stubs.
return module.sdkJars(ctx, sdkVersion, false)
}
diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go
index 408d433..1c8e43e 100644
--- a/rust/config/allowed_list.go
+++ b/rust/config/allowed_list.go
@@ -19,6 +19,7 @@
"packages/modules/Virtualization",
"prebuilts/rust",
"system/bt",
+ "system/core/libstats/pull_rust",
"system/extras/profcollectd",
"system/extras/simpleperf",
"system/hardware/interfaces/keystore2",
diff --git a/rust/image_test.go b/rust/image_test.go
index e40599c..7677cce 100644
--- a/rust/image_test.go
+++ b/rust/image_test.go
@@ -38,7 +38,7 @@
}
`)
- vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_vendor.VER_arm64_armv8-a").Module().(*cc.Module)
+ vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_vendor.29_arm64_armv8-a").Module().(*cc.Module)
if !android.InList("libfoo_vendor", vendorBinary.Properties.AndroidMkStaticLibs) {
t.Errorf("vendorBinary should have a dependency on libfoo_vendor")
@@ -56,7 +56,7 @@
}
`)
- vendor := ctx.ModuleForTests("libfoo", "android_vendor.VER_arm64_armv8-a_static").Rule("rustc")
+ vendor := ctx.ModuleForTests("libfoo", "android_vendor.29_arm64_armv8-a_static").Rule("rustc")
if !strings.Contains(vendor.Args["rustcFlags"], "--cfg 'android_vndk'") {
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"])
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 418bd93..890fb26 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -75,7 +75,7 @@
func(variables android.FixtureProductVariables) {
variables.DeviceVndkVersion = StringPtr("current")
variables.ProductVndkVersion = StringPtr("current")
- variables.Platform_vndk_version = StringPtr("VER")
+ variables.Platform_vndk_version = StringPtr("29")
},
),
).RunTestWithBp(t, bp)
diff --git a/rust/sanitize.go b/rust/sanitize.go
index 2f44b20..2498aa1 100644
--- a/rust/sanitize.go
+++ b/rust/sanitize.go
@@ -40,12 +40,12 @@
"-C passes='sancov'",
"--cfg fuzzing",
- "-C llvm-args=-sanitizer-coverage-level=4",
+ "-C llvm-args=-sanitizer-coverage-level=3",
"-C llvm-args=-sanitizer-coverage-trace-compares",
"-C llvm-args=-sanitizer-coverage-inline-8bit-counters",
+ "-C llvm-args=-sanitizer-coverage-stack-depth",
"-C llvm-args=-sanitizer-coverage-trace-geps",
"-C llvm-args=-sanitizer-coverage-prune-blocks=0",
- "-C llvm-args=-sanitizer-coverage-pc-table",
"-Z sanitizer=address",
// Sancov breaks with lto
diff --git a/scripts/toc.sh b/scripts/toc.sh
index 8b1d25f..c6b7866 100755
--- a/scripts/toc.sh
+++ b/scripts/toc.sh
@@ -17,7 +17,7 @@
# Script to handle generating a .toc file from a .so file
# Inputs:
# Environment:
-# CROSS_COMPILE: prefix added to readelf tool
+# CLANG_BIN: path to the clang bin directory
# Arguments:
# -i ${file}: input file (required)
# -o ${file}: output file (required)
@@ -35,34 +35,34 @@
}
do_elf() {
- ("${CROSS_COMPILE}readelf" -d "${infile}" | grep SONAME || echo "No SONAME for ${infile}") > "${outfile}.tmp"
- "${CROSS_COMPILE}readelf" --dyn-syms "${infile}" | awk '{$2=""; $3=""; print}' >> "${outfile}.tmp"
+ ("${CLANG_BIN}/llvm-readelf" -d "${infile}" | grep SONAME || echo "No SONAME for ${infile}") > "${outfile}.tmp"
+ "${CLANG_BIN}/llvm-readelf" --dyn-syms "${infile}" | awk '{$2=""; $3=""; print}' >> "${outfile}.tmp"
cat <<EOF > "${depsfile}"
${outfile}: \\
- ${CROSS_COMPILE}readelf \\
+ ${CLANG_BIN}/llvm-readelf \\
EOF
}
do_macho() {
- "${CROSS_COMPILE}/otool" -l "${infile}" | grep LC_ID_DYLIB -A 5 > "${outfile}.tmp"
- "${CROSS_COMPILE}/nm" -gP "${infile}" | cut -f1-2 -d" " | (grep -v 'U$' >> "${outfile}.tmp" || true)
+ "${CLANG_BIN}/llvm-objdump" -p "${infile}" | grep LC_ID_DYLIB -A 5 > "${outfile}.tmp"
+ "${CLANG_BIN}/llvm-nm" -gP "${infile}" | cut -f1-2 -d" " | (grep -v 'U$' >> "${outfile}.tmp" || true)
cat <<EOF > "${depsfile}"
${outfile}: \\
- ${CROSS_COMPILE}/otool \\
- ${CROSS_COMPILE}/nm \\
+ ${CLANG_BIN}/llvm-objdump \\
+ ${CLANG_BIN}/llvm-nm \\
EOF
}
do_pe() {
- "${CROSS_COMPILE}objdump" -x "${infile}" | grep "^Name" | cut -f3 -d" " > "${outfile}.tmp"
- "${CROSS_COMPILE}nm" -g -f p "${infile}" | cut -f1-2 -d" " >> "${outfile}.tmp"
+ "${CLANG_BIN}/llvm-objdump" -x "${infile}" | grep "^Name" | cut -f3 -d" " > "${outfile}.tmp"
+ "${CLANG_BIN}/llvm-nm" -gP "${infile}" | cut -f1-2 -d" " >> "${outfile}.tmp"
cat <<EOF > "${depsfile}"
${outfile}: \\
- ${CROSS_COMPILE}objdump \\
- ${CROSS_COMPILE}nm \\
+ ${CLANG_BIN}/llvm-objdump \\
+ ${CLANG_BIN}/llvm-nm \\
EOF
}
@@ -98,8 +98,8 @@
usage
fi
-if [ -z "${CROSS_COMPILE:-}" ]; then
- echo "CROSS_COMPILE environment variable must be set"
+if [ -z "${CLANG_BIN:-}" ]; then
+ echo "CLANG_BIN environment variable must be set"
usage
fi
@@ -107,7 +107,7 @@
cat <<EOF > "${depsfile}"
${outfile}: \\
- ${CROSS_COMPILE}readelf \\
+ ${CLANG_BIN}/llvm-readelf \\
EOF
if [ -n "${elf:-}" ]; then
diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go
index e9d9051..6d35f9c 100644
--- a/sysprop/sysprop_test.go
+++ b/sysprop/sysprop_test.go
@@ -129,7 +129,7 @@
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.DeviceSystemSdkVersions = []string{"28"}
variables.DeviceVndkVersion = proptools.StringPtr("current")
- variables.Platform_vndk_version = proptools.StringPtr("VER")
+ variables.Platform_vndk_version = proptools.StringPtr("29")
}),
mockFS.AddToFixture(),
android.FixtureWithRootAndroidBp(bp),
@@ -246,10 +246,10 @@
// Check for generated cc_library
for _, variant := range []string{
- "android_vendor.VER_arm_armv7-a-neon_shared",
- "android_vendor.VER_arm_armv7-a-neon_static",
- "android_vendor.VER_arm64_armv8-a_shared",
- "android_vendor.VER_arm64_armv8-a_static",
+ "android_vendor.29_arm_armv7-a-neon_shared",
+ "android_vendor.29_arm_armv7-a-neon_static",
+ "android_vendor.29_arm64_armv8-a_shared",
+ "android_vendor.29_arm64_armv8-a_static",
} {
result.ModuleForTests("libsysprop-platform", variant)
result.ModuleForTests("libsysprop-vendor", variant)
@@ -277,15 +277,15 @@
// Check for exported includes
coreVariant := "android_arm64_armv8-a_static"
- vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
+ vendorVariant := "android_vendor.29_arm64_armv8-a_static"
platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
- platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
+ platformPublicVendorPath := "libsysprop-platform/android_vendor.29_arm64_armv8-a_static/gen/sysprop/public/include"
platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
- vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
+ vendorInternalPath := "libsysprop-vendor/android_vendor.29_arm64_armv8-a_static/gen/sysprop/include"
vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
platformClient := result.ModuleForTests("cc-client-platform", coreVariant)
@@ -371,6 +371,6 @@
android.AssertStringEquals(t, "min_sdk_version forwarding to cc module", "29", propFromCc)
javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
- propFromJava := javaModule.MinSdkVersion()
+ propFromJava := javaModule.MinSdkVersionString()
android.AssertStringEquals(t, "min_sdk_version forwarding to java module", "30", propFromJava)
}
diff --git a/ui/build/bazel.go b/ui/build/bazel.go
index ec561d5..0ebfcd8 100644
--- a/ui/build/bazel.go
+++ b/ui/build/bazel.go
@@ -149,6 +149,9 @@
cmd.Args = append(cmd.Args, "--action_env=PATH="+pathEnvValue)
}
+ // Allow Bazel actions to see the SHELL variable (passed to Bazel above)
+ cmd.Args = append(cmd.Args, "--action_env=SHELL")
+
// Append custom build flags to the Bazel command. Changes to these flags
// may invalidate Bazel's analysis cache.
// These should be appended as the final args, so that they take precedence.