diff options
97 files changed, 3338 insertions, 1337 deletions
diff --git a/aidl_library/Android.bp b/aidl_library/Android.bp new file mode 100644 index 000000000..ec2150427 --- /dev/null +++ b/aidl_library/Android.bp @@ -0,0 +1,32 @@ +// Copyright 2023 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 { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +bootstrap_go_package { + name: "soong-aidl-library", + pkgPath: "android/soong/aidl_library", + deps: [ + "soong-android", + ], + srcs: [ + "aidl_library.go", + ], + testSrcs: [ + "aidl_library_test.go", + ], + pluginFor: ["soong_build"], +} diff --git a/aidl_library/aidl_library.go b/aidl_library/aidl_library.go new file mode 100644 index 000000000..8a84e6bfa --- /dev/null +++ b/aidl_library/aidl_library.go @@ -0,0 +1,174 @@ +// Copyright 2023 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 aidl_library + +import ( + "android/soong/android" + "android/soong/bazel" + + "github.com/google/blueprint" + "github.com/google/blueprint/proptools" +) + +var PrepareForTestWithAidlLibrary = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { + registerAidlLibraryBuildComponents(ctx) +}) + +func init() { + registerAidlLibraryBuildComponents(android.InitRegistrationContext) +} + +func registerAidlLibraryBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterModuleType("aidl_library", AidlLibraryFactory) +} + +type aidlLibraryProperties struct { + // srcs lists files that are included in this module for aidl compilation + Srcs []string `android:"path"` + + // hdrs lists the headers that are imported by srcs but are not compiled by aidl to language binding code + // hdrs is provided to support Bazel migration. It is a no-op until + // we enable input sandbox in aidl compilation action + Hdrs []string `android:"path"` + + // The prefix to strip from the paths of the .aidl files + // The remaining path is the package path of the aidl interface + Strip_import_prefix *string + + // List of aidl files or aidl_library depended on by the module + Deps []string `android:"arch_variant"` +} + +type AidlLibrary struct { + android.ModuleBase + android.BazelModuleBase + properties aidlLibraryProperties +} + +type bazelAidlLibraryAttributes struct { + Srcs bazel.LabelListAttribute + Hdrs bazel.LabelListAttribute + Strip_import_prefix *string + Deps bazel.LabelListAttribute +} + +func (lib *AidlLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) { + srcs := bazel.MakeLabelListAttribute( + android.BazelLabelForModuleSrc( + ctx, + lib.properties.Srcs, + ), + ) + + hdrs := bazel.MakeLabelListAttribute( + android.BazelLabelForModuleSrc( + ctx, + lib.properties.Hdrs, + ), + ) + + tags := []string{"apex_available=//apex_available:anyapex"} + deps := bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, lib.properties.Deps)) + + attrs := &bazelAidlLibraryAttributes{ + Srcs: srcs, + Hdrs: hdrs, + Strip_import_prefix: lib.properties.Strip_import_prefix, + Deps: deps, + } + + props := bazel.BazelTargetModuleProperties{ + Rule_class: "aidl_library", + Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl", + } + + ctx.CreateBazelTargetModule( + props, + android.CommonAttributes{ + Name: lib.Name(), + Tags: bazel.MakeStringListAttribute(tags), + }, + attrs, + ) +} + +type AidlLibraryInfo struct { + // The direct aidl files of the module + Srcs android.Paths + // The include dirs to the direct aidl files and those provided from aidl_library deps + IncludeDirs android.DepSet +} + +// AidlLibraryProvider provides the srcs and the transitive include dirs +var AidlLibraryProvider = blueprint.NewProvider(AidlLibraryInfo{}) + +func (lib *AidlLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { + includeDirsDepSetBuilder := android.NewDepSetBuilder(android.PREORDER) + + if len(lib.properties.Srcs) == 0 && len(lib.properties.Hdrs) == 0 { + ctx.ModuleErrorf("at least srcs or hdrs prop must be non-empty") + } + + srcs := android.PathsForModuleSrc(ctx, lib.properties.Srcs) + if lib.properties.Strip_import_prefix != nil { + srcs = android.PathsWithModuleSrcSubDir( + ctx, + srcs, + android.String(lib.properties.Strip_import_prefix)) + } + + includeDir := android.PathForModuleSrc( + ctx, + proptools.StringDefault(lib.properties.Strip_import_prefix, ""), + ) + + includeDirsDepSetBuilder.Direct(includeDir) + + for _, dep := range ctx.GetDirectDepsWithTag(aidlLibraryTag) { + if ctx.OtherModuleHasProvider(dep, AidlLibraryProvider) { + info := ctx.OtherModuleProvider(dep, AidlLibraryProvider).(AidlLibraryInfo) + includeDirsDepSetBuilder.Transitive(&info.IncludeDirs) + } + } + + // TODO(b/279960133) Propagate direct and transitive headers/srcs when aidl action sandboxes inputs + ctx.SetProvider(AidlLibraryProvider, AidlLibraryInfo{ + Srcs: srcs, + IncludeDirs: *includeDirsDepSetBuilder.Build(), + }) +} + +// aidl_library contains a list of .aidl files and the strip_import_prefix to +// to strip from the paths of the .aidl files. The sub-path left-over after stripping +// corresponds to the aidl package path the aidl interfaces are scoped in +func AidlLibraryFactory() android.Module { + module := &AidlLibrary{} + module.AddProperties(&module.properties) + android.InitAndroidModule(module) + android.InitBazelModule(module) + return module +} + +type aidlDependencyTag struct { + blueprint.BaseDependencyTag +} + +var aidlLibraryTag = aidlDependencyTag{} + +func (lib *AidlLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { + for _, dep := range lib.properties.Deps { + ctx.AddDependency(lib, aidlLibraryTag, dep) + } +} diff --git a/aidl_library/aidl_library_test.go b/aidl_library/aidl_library_test.go new file mode 100644 index 000000000..d9b410acc --- /dev/null +++ b/aidl_library/aidl_library_test.go @@ -0,0 +1,122 @@ +// Copyright 2023 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 aidl_library + +import ( + "android/soong/android" + "testing" +) + +func TestAidlLibrary(t *testing.T) { + t.Parallel() + ctx := android.GroupFixturePreparers( + PrepareForTestWithAidlLibrary, + android.MockFS{ + "package_bar/Android.bp": []byte(` + aidl_library { + name: "bar", + srcs: ["x/y/Bar.aidl"], + strip_import_prefix: "x", + } + `), + }.AddToFixture(), + android.MockFS{ + "package_foo/Android.bp": []byte(` + aidl_library { + name: "foo", + srcs: ["a/b/Foo.aidl"], + hdrs: ["Header.aidl"], + strip_import_prefix: "a", + deps: ["bar"], + } + `), + }.AddToFixture(), + ).RunTest(t).TestContext + + foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) + actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) + + android.AssertArrayString( + t, + "aidl include dirs", + []string{"package_foo/a", "package_bar/x"}, + actualInfo.IncludeDirs.ToList().Strings(), + ) + + android.AssertPathsRelativeToTopEquals( + t, + "aidl srcs paths", + []string{"package_foo/a/b/Foo.aidl"}, + actualInfo.Srcs, + ) +} + +func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) { + t.Parallel() + ctx := android.GroupFixturePreparers( + PrepareForTestWithAidlLibrary, + android.MockFS{ + "package_bar/Android.bp": []byte(` + aidl_library { + name: "bar", + srcs: ["x/y/Bar.aidl"], + } + `), + }.AddToFixture(), + android.MockFS{ + "package_foo/Android.bp": []byte(` + aidl_library { + name: "foo", + srcs: ["a/b/Foo.aidl"], + hdrs: ["Header.aidl"], + deps: ["bar"], + } + `), + }.AddToFixture(), + ).RunTest(t).TestContext + + foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) + actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) + + android.AssertArrayString( + t, + "aidl include dirs", + []string{"package_foo", "package_bar"}, + actualInfo.IncludeDirs.ToList().Strings(), + ) + + android.AssertPathsRelativeToTopEquals( + t, + "aidl srcs paths", + []string{"package_foo/a/b/Foo.aidl"}, + actualInfo.Srcs, + ) +} + +func TestAidlLibraryWithNoSrcsHdrsDeps(t *testing.T) { + t.Parallel() + android.GroupFixturePreparers( + PrepareForTestWithAidlLibrary, + android.MockFS{ + "package_bar/Android.bp": []byte(` + aidl_library { + name: "bar", + } + `), + }.AddToFixture(), + ). + ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("at least srcs or hdrs prop must be non-empty")). + RunTest(t) +} diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index cccf6ad4b..64c58cf46 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -203,23 +203,24 @@ var ( "frameworks/av/media/audioaidlconversion": Bp2BuildDefaultTrueRecursively, "frameworks/av/media/codec2/components/aom": Bp2BuildDefaultTrueRecursively, "frameworks/av/media/codecs": Bp2BuildDefaultTrueRecursively, - "frameworks/av/media/module/codecs": Bp2BuildDefaultTrueRecursively, - "frameworks/av/media/module/foundation": Bp2BuildDefaultTrueRecursively, "frameworks/av/media/liberror": Bp2BuildDefaultTrueRecursively, "frameworks/av/media/libmediahelper": Bp2BuildDefaultTrue, "frameworks/av/media/libshmem": Bp2BuildDefaultTrueRecursively, + "frameworks/av/media/module/codecs": Bp2BuildDefaultTrueRecursively, + "frameworks/av/media/module/foundation": Bp2BuildDefaultTrueRecursively, "frameworks/av/media/module/minijail": Bp2BuildDefaultTrueRecursively, "frameworks/av/services/minijail": Bp2BuildDefaultTrueRecursively, "frameworks/base/libs/androidfw": Bp2BuildDefaultTrue, "frameworks/base/media/tests/MediaDump": Bp2BuildDefaultTrue, - "frameworks/base/services/tests/servicestests/aidl": Bp2BuildDefaultTrue, "frameworks/base/proto": Bp2BuildDefaultTrue, + "frameworks/base/services/tests/servicestests/aidl": Bp2BuildDefaultTrue, "frameworks/base/startop/apps/test": Bp2BuildDefaultTrue, "frameworks/base/tests/appwidgets/AppWidgetHostTest": Bp2BuildDefaultTrueRecursively, "frameworks/base/tools/aapt2": Bp2BuildDefaultTrue, "frameworks/base/tools/codegen": Bp2BuildDefaultTrueRecursively, "frameworks/base/tools/streaming_proto": Bp2BuildDefaultTrueRecursively, "frameworks/hardware/interfaces/stats/aidl": Bp2BuildDefaultTrue, + "frameworks/libs/modules-utils/build": Bp2BuildDefaultTrueRecursively, "frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively, "frameworks/native/libs/arect": Bp2BuildDefaultTrueRecursively, "frameworks/native/libs/gui": Bp2BuildDefaultTrue, @@ -313,6 +314,7 @@ var ( "prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively, "prebuilts/gradle-plugin": Bp2BuildDefaultTrueRecursively, "prebuilts/runtime/mainline/platform/sdk": Bp2BuildDefaultTrueRecursively, + "prebuilts/sdk": Bp2BuildDefaultTrue, "prebuilts/sdk/current/androidx": Bp2BuildDefaultTrue, "prebuilts/sdk/current/androidx-legacy": Bp2BuildDefaultTrue, "prebuilts/sdk/current/extras/constraint-layout-x": Bp2BuildDefaultTrue, @@ -1558,9 +1560,10 @@ var ( // also be built - do not add them to this list. StagingMixedBuildsEnabledList = []string{ // M13: media.swcodec launch - "com.android.media.swcodec", - "test_com.android.media.swcodec", - "libstagefright_foundation", + // TODO(b/282042844): reenable + // "com.android.media.swcodec", + // "test_com.android.media.swcodec", + // "libstagefright_foundation", } // These should be the libs that are included by the apexes in the ProdMixedBuildsEnabledList diff --git a/android/bazel.go b/android/bazel.go index 3fe063c51..114b1f5c2 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -71,7 +71,7 @@ type BazelConversionStatus struct { MissingDeps []string `blueprint:"mutated"` } -type bazelModuleProperties struct { +type BazelModuleProperties struct { // The label of the Bazel target replacing this Soong module. When run in conversion mode, this // will import the handcrafted build target into the autogenerated file. Note: this may result in // a conflict due to duplicate targets if bp2build_available is also set. @@ -96,7 +96,7 @@ type bazelModuleProperties struct { type properties struct { // In "Bazel mixed build" mode, this represents the Bazel target replacing // this Soong module. - Bazel_module bazelModuleProperties + Bazel_module BazelModuleProperties } // namespacedVariableProperties is a map from a string representing a Soong diff --git a/android/bazel_handler.go b/android/bazel_handler.go index 5291ecae9..10cf60a0a 100644 --- a/android/bazel_handler.go +++ b/android/bazel_handler.go @@ -29,6 +29,7 @@ import ( "android/soong/bazel/cquery" "android/soong/shared" "android/soong/starlark_fmt" + "github.com/google/blueprint" "github.com/google/blueprint/metrics" @@ -700,9 +701,6 @@ func (context *mixedBuildBazelContext) createBazelCommand(config Config, runName // We don't need to set --host_platforms because it's set in bazelrc files // that the bazel shell script wrapper passes - // Explicitly disable downloading rules (such as canonical C++ and Java rules) from the network. - "--experimental_repository_disable_download", - // Suppress noise "--ui_event_filters=-INFO", "--noshow_progress", diff --git a/android/bazel_test.go b/android/bazel_test.go index 87b2c8f42..77e251575 100644 --- a/android/bazel_test.go +++ b/android/bazel_test.go @@ -218,7 +218,7 @@ func (bcc *TestBazelConversionContext) Config() Config { var bazelableBazelModuleBase = BazelModuleBase{ bazelProperties: properties{ - Bazel_module: bazelModuleProperties{ + Bazel_module: BazelModuleProperties{ CanConvertToBazel: true, }, }, @@ -344,7 +344,7 @@ func TestBp2BuildAllowlist(t *testing.T) { }, BazelModuleBase: BazelModuleBase{ bazelProperties: properties{ - Bazel_module: bazelModuleProperties{ + Bazel_module: BazelModuleProperties{ CanConvertToBazel: true, Bp2build_available: proptools.BoolPtr(true), }, diff --git a/android/config.go b/android/config.go index 9e94e0517..acadb3ff3 100644 --- a/android/config.go +++ b/android/config.go @@ -183,6 +183,16 @@ func (c Config) MaxPageSizeSupported() string { return String(c.config.productVariables.DeviceMaxPageSizeSupported) } +// The release version passed to aconfig, derived from RELEASE_VERSION +func (c Config) ReleaseVersion() string { + return c.config.productVariables.ReleaseVersion +} + +// The flag values files passed to aconfig, derived from RELEASE_VERSION +func (c Config) ReleaseDeviceConfigValueSets() []string { + return c.config.productVariables.ReleaseDeviceConfigValueSets +} + // A DeviceConfig object represents the configuration for a particular device // being built. For now there will only be one of these, but in the future there // may be multiple devices being built. diff --git a/android/filegroup.go b/android/filegroup.go index 0ca5dc50e..f30ee5143 100644 --- a/android/filegroup.go +++ b/android/filegroup.go @@ -75,7 +75,8 @@ func isFilegroupWithPattern(pattern *regexp.Regexp) bazel.LabelMapper { // https://docs.bazel.build/versions/master/be/general.html#filegroup type bazelFilegroupAttributes struct { - Srcs bazel.LabelListAttribute + Srcs bazel.LabelListAttribute + Applicable_licenses bazel.LabelListAttribute } type bazelAidlLibraryAttributes struct { diff --git a/android/package.go b/android/package.go index 2bf652126..7fbc70041 100644 --- a/android/package.go +++ b/android/package.go @@ -15,6 +15,8 @@ package android import ( + "path/filepath" + "android/soong/bazel" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -39,8 +41,8 @@ type packageProperties struct { } type bazelPackageAttributes struct { - Default_visibility []string - Default_applicable_licenses bazel.LabelListAttribute + Default_visibility []string + Default_package_metadata bazel.LabelListAttribute } type packageModule struct { @@ -53,13 +55,32 @@ type packageModule struct { var _ Bazelable = &packageModule{} func (p *packageModule) ConvertWithBp2build(ctx TopDownMutatorContext) { + defaultPackageMetadata := bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses)) + // If METADATA file exists in the package, add it to package(default_package_metadata=) using a + // filegroup(name="default_metadata_file") which can be accessed later on each module in Bazel + // using attribute "applicable_licenses". + // Attribute applicable_licenses of filegroup "default_metadata_file" has to be set to [], + // otherwise Bazel reports cyclic reference error. + if existed, _, _ := ctx.Config().fs.Exists(filepath.Join(ctx.ModuleDir(), "METADATA")); existed { + ctx.CreateBazelTargetModule( + bazel.BazelTargetModuleProperties{ + Rule_class: "filegroup", + }, + CommonAttributes{Name: "default_metadata_file"}, + &bazelFilegroupAttributes{ + Srcs: bazel.MakeLabelListAttribute(BazelLabelForModuleSrc(ctx, []string{"METADATA"})), + Applicable_licenses: bazel.LabelListAttribute{Value: bazel.LabelList{Includes: []bazel.Label{}}, EmitEmptyList: true}, + }) + defaultPackageMetadata.Value.Add(&bazel.Label{Label: ":default_metadata_file"}) + } + ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "package", }, CommonAttributes{}, &bazelPackageAttributes{ - Default_applicable_licenses: bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses)), + Default_package_metadata: defaultPackageMetadata, // FIXME(asmundak): once b/221436821 is resolved Default_visibility: []string{"//visibility:public"}, }) diff --git a/android/variable.go b/android/variable.go index aaf0606e1..97171e7b9 100644 --- a/android/variable.go +++ b/android/variable.go @@ -473,6 +473,9 @@ type productVariables struct { ProductManufacturer string `json:",omitempty"` ProductBrand string `json:",omitempty"` BuildVersionTags []string `json:",omitempty"` + + ReleaseVersion string `json:",omitempty"` + ReleaseDeviceConfigValueSets []string `json:",omitempty"` } func boolPtr(v bool) *bool { @@ -541,124 +544,102 @@ type ProductConfigContext interface { Module() Module } -// ProductConfigProperty contains the information for a single property (may be a struct) paired -// with the appropriate ProductConfigVariable. +// ProductConfigOrSoongConfigProperty represents either a soong config variable + its value +// or a product config variable. You can get both a ConfigurationAxis and a SelectKey from it +// for use in bazel attributes. ProductVariableProperties() will return a map from properties -> +// this interface -> property structs for use in bp2build converters +type ProductConfigOrSoongConfigProperty interface { + // Name of the product variable or soong config variable + Name() string + // AlwaysEmit returns true for soong config variables but false for product variables. This + // is intended to indicate if we need to always emit empty lists in the select statements. + AlwaysEmit() bool + // ConfigurationAxis returns the bazel.ConfigurationAxis that represents this variable. The + // configuration axis will change depending on the variable and whether it's arch/os variant + // as well. + ConfigurationAxis() bazel.ConfigurationAxis + // SelectKey returns a string that represents the key of a select branch, however, it is not + // actually the real label written out to the build file. + // this.ConfigurationAxis().SelectKey(this.SelectKey()) will give the actual label. + SelectKey() string +} + +// ProductConfigProperty represents a product config variable, and if it is arch-variant or not. type ProductConfigProperty struct { // The name of the product variable, e.g. "safestack", "malloc_not_svelte", // "board" - Name string + name string - // Namespace of the variable, if this is a soong_config_module_type variable - // e.g. "acme", "ANDROID", "vendor_name" - Namespace string + arch string +} - // Unique configuration to identify this product config property (i.e. a - // primary key), as just using the product variable name is not sufficient. - // - // For product variables, this is the product variable name + optional - // archvariant information. e.g. - // - // product_variables: { - // foo: { - // cflags: ["-Dfoo"], - // }, - // }, - // - // FullConfig would be "foo". - // - // target: { - // android: { - // product_variables: { - // foo: { - // cflags: ["-Dfoo-android"], - // }, - // }, - // }, - // }, - // - // FullConfig would be "foo-android". - // - // For soong config variables, this is the namespace + product variable name - // + value of the variable, if applicable. The value can also be - // conditions_default. - // - // e.g. - // - // soong_config_variables: { - // feature1: { - // conditions_default: { - // cflags: ["-DDEFAULT1"], - // }, - // cflags: ["-DFEATURE1"], - // }, - // } - // - // where feature1 is created in the "acme" namespace, so FullConfig would be - // "acme__feature1" and "acme__feature1__conditions_default". - // - // e.g. - // - // soong_config_variables: { - // board: { - // soc_a: { - // cflags: ["-DSOC_A"], - // }, - // soc_b: { - // cflags: ["-DSOC_B"], - // }, - // soc_c: {}, - // conditions_default: { - // cflags: ["-DSOC_DEFAULT"] - // }, - // }, - // } - // - // where board is created in the "acme" namespace, so FullConfig would be - // "acme__board__soc_a", "acme__board__soc_b", and - // "acme__board__conditions_default" - FullConfig string +func (p ProductConfigProperty) Name() string { + return p.name +} - // keeps track of whether this product variable is nested under an arch variant - OuterAxis bazel.ConfigurationAxis +func (p ProductConfigProperty) AlwaysEmit() bool { + return false } -func (p *ProductConfigProperty) AlwaysEmit() bool { - return p.Namespace != "" +func (p ProductConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis { + return bazel.ProductVariableConfigurationAxis(p.arch != "", p.name+"__"+p.arch) } -func (p *ProductConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis { - if p.Namespace == "" { - return bazel.ProductVariableConfigurationAxis(p.FullConfig, p.OuterAxis) +func (p ProductConfigProperty) SelectKey() string { + if p.arch == "" { + return strings.ToLower(p.name) } else { - // Soong config variables can be uniquely identified by the namespace - // (e.g. acme, android) and the product variable name (e.g. board, size) - return bazel.ProductVariableConfigurationAxis(p.Namespace+"__"+p.Name, bazel.NoConfigAxis) + return strings.ToLower(p.name + "-" + p.arch) } } +// SoongConfigProperty represents a soong config variable, its value if it's a string variable, +// and if it's dependent on the OS or not +type SoongConfigProperty struct { + name string + namespace string + // Can be an empty string for bool/value soong config variables + value string + // If there is a target: field inside a soong config property struct, the os that it selects + // on will be represented here. + os string +} + +func (p SoongConfigProperty) Name() string { + return p.name +} + +func (p SoongConfigProperty) AlwaysEmit() bool { + return true +} + +func (p SoongConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis { + return bazel.ProductVariableConfigurationAxis(false, p.namespace+"__"+p.name+"__"+p.os) +} + // SelectKey returns the literal string that represents this variable in a BUILD // select statement. -func (p *ProductConfigProperty) SelectKey() string { - if p.Namespace == "" { - return strings.ToLower(p.FullConfig) - } - - if p.FullConfig == bazel.ConditionsDefaultConfigKey { +func (p SoongConfigProperty) SelectKey() string { + // p.value being conditions_default can happen with or without a desired os. When not using + // an os, we want to emit literally just //conditions:default in the select statement, but + // when using an os, we want to emit namespace__name__conditions_default__os, so that + // the branch is only taken if the variable is not set, and we're on the desired os. + // ConfigurationAxis#SelectKey will map the conditions_default result of this function to + // //conditions:default. + if p.value == bazel.ConditionsDefaultConfigKey && p.os == "" { return bazel.ConditionsDefaultConfigKey } - value := p.FullConfig - if value == p.Name { - value = "" + parts := []string{p.namespace, p.name} + if p.value != "" && p.value != bazel.ConditionsDefaultSelectKey { + parts = append(parts, p.value) } - - // e.g. acme__feature1, android__board__soc_a - selectKey := strings.ToLower(strings.Join([]string{p.Namespace, p.Name}, "__")) - if value != "" { - selectKey = strings.ToLower(strings.Join([]string{selectKey, value}, "__")) + if p.os != "" { + parts = append(parts, p.os) } - return selectKey + // e.g. acme__feature1, android__board__soc_a, my_namespace__my_variables__my_value__my_os + return strings.ToLower(strings.Join(parts, "__")) } // ProductConfigProperties is a map of maps to group property values according @@ -674,7 +655,7 @@ func (p *ProductConfigProperty) SelectKey() string { // // The value of the map is the interface{} representing the value of the // property, like ["-DDEFINES"] for cflags. -type ProductConfigProperties map[string]map[ProductConfigProperty]interface{} +type ProductConfigProperties map[string]map[ProductConfigOrSoongConfigProperty]interface{} // ProductVariableProperties returns a ProductConfigProperties containing only the properties which // have been set for the given module. @@ -685,26 +666,10 @@ func ProductVariableProperties(ctx ArchVariantContext, module Module) ProductCon if moduleBase.variableProperties != nil { productVariablesProperty := proptools.FieldNameForProperty("product_variables") - productVariableValues( - productVariablesProperty, - moduleBase.variableProperties, - "", - "", - &productConfigProperties, - bazel.ConfigurationAxis{}, - ) - - for axis, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) { + for /* axis */ _, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) { for config, props := range configToProps { - // GetArchVariantProperties is creating an instance of the requested type - // and productVariablesValues expects an interface, so no need to cast - productVariableValues( - productVariablesProperty, - props, - "", - config, - &productConfigProperties, - axis) + variableValues := reflect.ValueOf(props).Elem().FieldByName(productVariablesProperty) + productConfigProperties.AddProductConfigProperties(variableValues, config) } } } @@ -712,13 +677,8 @@ func ProductVariableProperties(ctx ArchVariantContext, module Module) ProductCon if m, ok := module.(Bazelable); ok && m.namespacedVariableProps() != nil { for namespace, namespacedVariableProps := range m.namespacedVariableProps() { for _, namespacedVariableProp := range namespacedVariableProps { - productVariableValues( - soongconfig.SoongConfigProperty, - namespacedVariableProp, - namespace, - "", - &productConfigProperties, - bazel.NoConfigAxis) + variableValues := reflect.ValueOf(namespacedVariableProp).Elem().FieldByName(soongconfig.SoongConfigProperty) + productConfigProperties.AddSoongConfigProperties(namespace, variableValues) } } } @@ -727,30 +687,49 @@ func ProductVariableProperties(ctx ArchVariantContext, module Module) ProductCon } func (p *ProductConfigProperties) AddProductConfigProperty( - propertyName, namespace, productVariableName, config string, property interface{}, outerAxis bazel.ConfigurationAxis) { - if (*p)[propertyName] == nil { - (*p)[propertyName] = make(map[ProductConfigProperty]interface{}) - } + propertyName, productVariableName, arch string, propertyValue interface{}) { productConfigProp := ProductConfigProperty{ - Namespace: namespace, // e.g. acme, android - Name: productVariableName, // e.g. size, feature1, feature2, FEATURE3, board - FullConfig: config, // e.g. size, feature1-x86, size__conditions_default - OuterAxis: outerAxis, + name: productVariableName, // e.g. size, feature1, feature2, FEATURE3, board + arch: arch, // e.g. "", x86, arm64 + } + + p.AddEitherProperty(propertyName, productConfigProp, propertyValue) +} + +func (p *ProductConfigProperties) AddSoongConfigProperty( + propertyName, namespace, variableName, value, os string, propertyValue interface{}) { + + soongConfigProp := SoongConfigProperty{ + namespace: namespace, + name: variableName, // e.g. size, feature1, feature2, FEATURE3, board + value: value, + os: os, // e.g. android, linux_x86 + } + + p.AddEitherProperty(propertyName, soongConfigProp, propertyValue) +} + +func (p *ProductConfigProperties) AddEitherProperty( + propertyName string, key ProductConfigOrSoongConfigProperty, propertyValue interface{}) { + if (*p)[propertyName] == nil { + (*p)[propertyName] = make(map[ProductConfigOrSoongConfigProperty]interface{}) } - if existing, ok := (*p)[propertyName][productConfigProp]; ok && namespace != "" { + if existing, ok := (*p)[propertyName][key]; ok { switch dst := existing.(type) { case []string: - if src, ok := property.([]string); ok { - dst = append(dst, src...) - (*p)[propertyName][productConfigProp] = dst + src, ok := propertyValue.([]string) + if !ok { + panic("Conflicting types") } + dst = append(dst, src...) + (*p)[propertyName][key] = dst default: - panic(fmt.Errorf("TODO: handle merging value %s", existing)) + panic(fmt.Errorf("TODO: handle merging value %#v", existing)) } } else { - (*p)[propertyName][productConfigProp] = property + (*p)[propertyName][key] = propertyValue } } @@ -787,10 +766,7 @@ func maybeExtractConfigVarProp(v reflect.Value) (reflect.Value, bool) { return v, true } -func (productConfigProperties *ProductConfigProperties) AddProductConfigProperties(namespace, suffix string, variableValues reflect.Value, outerAxis bazel.ConfigurationAxis) { - // variableValues can either be a product_variables or - // soong_config_variables struct. - // +func (productConfigProperties *ProductConfigProperties) AddProductConfigProperties(variableValues reflect.Value, arch string) { // Example of product_variables: // // product_variables: { @@ -803,19 +779,44 @@ func (productConfigProperties *ProductConfigProperties) AddProductConfigProperti // ], // }, // }, + + for i := 0; i < variableValues.NumField(); i++ { + // e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc. + productVariableName := variableValues.Type().Field(i).Name + + variableValue := variableValues.Field(i) + // Check if any properties were set for the module + if variableValue.IsZero() { + // e.g. feature1: {}, malloc_not_svelte: {} + continue + } + + for j := 0; j < variableValue.NumField(); j++ { + property := variableValue.Field(j) + // e.g. Asflags, Cflags, Enabled, etc. + propertyName := variableValue.Type().Field(j).Name + if property.Kind() != reflect.Interface { + productConfigProperties.AddProductConfigProperty(propertyName, productVariableName, arch, property.Interface()) + } + } + } + +} + +func (productConfigProperties *ProductConfigProperties) AddSoongConfigProperties(namespace string, soongConfigVariablesStruct reflect.Value) { // // Example of soong_config_variables: // // soong_config_variables: { // feature1: { - // conditions_default: { + // conditions_default: { // ... // }, // cflags: ... // }, // feature2: { // cflags: ... - // conditions_default: { + // conditions_default: { // ... // }, // }, @@ -823,7 +824,7 @@ func (productConfigProperties *ProductConfigProperties) AddProductConfigProperti // soc_a: { // ... // }, - // soc_a: { + // soc_b: { // ... // }, // soc_c: {}, @@ -832,36 +833,36 @@ func (productConfigProperties *ProductConfigProperties) AddProductConfigProperti // }, // }, // } - for i := 0; i < variableValues.NumField(); i++ { - // e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc. - productVariableName := variableValues.Type().Field(i).Name - - variableValue := variableValues.Field(i) + for i := 0; i < soongConfigVariablesStruct.NumField(); i++ { + // e.g. feature1, feature2, board + variableName := soongConfigVariablesStruct.Type().Field(i).Name + variableStruct := soongConfigVariablesStruct.Field(i) // Check if any properties were set for the module - if variableValue.IsZero() { - // e.g. feature1: {}, malloc_not_svelte: {} + if variableStruct.IsZero() { + // e.g. feature1: {} continue } // Unlike product variables, config variables require a few more // indirections to extract the struct from the reflect.Value. - if v, ok := maybeExtractConfigVarProp(variableValue); ok { - variableValue = v + if v, ok := maybeExtractConfigVarProp(variableStruct); ok { + variableStruct = v } - for j := 0; j < variableValue.NumField(); j++ { - property := variableValue.Field(j) - // e.g. Asflags, Cflags, Enabled, etc. - propertyName := variableValue.Type().Field(j).Name - // config can also be "conditions_default". - config := proptools.PropertyNameForField(propertyName) + for j := 0; j < variableStruct.NumField(); j++ { + propertyOrStruct := variableStruct.Field(j) + // propertyOrValueName can either be: + // - A property, like: Asflags, Cflags, Enabled, etc. + // - A soong config string variable's value, like soc_a, soc_b, soc_c in the example above + // - "conditions_default" + propertyOrValueName := variableStruct.Type().Field(j).Name // If the property wasn't set, no need to pass it along - if property.IsZero() { + if propertyOrStruct.IsZero() { continue } - if v, ok := maybeExtractConfigVarProp(property); ok { + if v, ok := maybeExtractConfigVarProp(propertyOrStruct); ok { // The field is a struct, which is used by: // 1) soong_config_string_variables // @@ -879,6 +880,9 @@ func (productConfigProperties *ProductConfigProperties) AddProductConfigProperti // cflags: ..., // static_libs: ... // } + // + // This means that propertyOrValueName is either conditions_default, or a soong + // config string variable's value. field := v // Iterate over fields of this struct prop. for k := 0; k < field.NumField(); k++ { @@ -888,47 +892,59 @@ func (productConfigProperties *ProductConfigProperties) AddProductConfigProperti if field.Field(k).IsZero() && namespace == "" { continue } - actualPropertyName := field.Type().Field(k).Name - - productConfigProperties.AddProductConfigProperty( - actualPropertyName, // e.g. cflags, static_libs - namespace, // e.g. acme, android - productVariableName, // e.g. size, feature1, FEATURE2, board - config, - field.Field(k).Interface(), // e.g. ["-DDEFAULT"], ["foo", "bar"], - outerAxis, - ) + + propertyName := field.Type().Field(k).Name + if propertyName == "Target" { + productConfigProperties.AddSoongConfigPropertiesFromTargetStruct(namespace, variableName, proptools.PropertyNameForField(propertyOrValueName), field.Field(k)) + } else if propertyName == "Arch" || propertyName == "Multilib" { + panic("Arch/Multilib are not currently supported in soong config variable structs") + } else { + productConfigProperties.AddSoongConfigProperty(propertyName, namespace, variableName, proptools.PropertyNameForField(propertyOrValueName), "", field.Field(k).Interface()) + } } - } else if property.Kind() != reflect.Interface { + } else if propertyOrStruct.Kind() != reflect.Interface { // If not an interface, then this is not a conditions_default or - // a struct prop. That is, this is a regular product variable, - // or a bool/value config variable. - config := productVariableName + suffix - productConfigProperties.AddProductConfigProperty( - propertyName, - namespace, - productVariableName, - config, - property.Interface(), - outerAxis, - ) + // a struct prop. That is, this is a bool/value config variable. + if propertyOrValueName == "Target" { + productConfigProperties.AddSoongConfigPropertiesFromTargetStruct(namespace, variableName, "", propertyOrStruct) + } else if propertyOrValueName == "Arch" || propertyOrValueName == "Multilib" { + panic("Arch/Multilib are not currently supported in soong config variable structs") + } else { + productConfigProperties.AddSoongConfigProperty(propertyOrValueName, namespace, variableName, "", "", propertyOrStruct.Interface()) + } } } } } -// productVariableValues uses reflection to convert a property struct for -// product_variables and soong_config_variables to structs that can be generated -// as select statements. -func productVariableValues( - fieldName string, variableProps interface{}, namespace, suffix string, productConfigProperties *ProductConfigProperties, outerAxis bazel.ConfigurationAxis) { - if suffix != "" { - suffix = "-" + suffix +func (productConfigProperties *ProductConfigProperties) AddSoongConfigPropertiesFromTargetStruct(namespace, soongConfigVariableName string, soongConfigVariableValue string, targetStruct reflect.Value) { + // targetStruct will be a struct with fields like "android", "host", "arm", "x86", + // "android_arm", etc. The values of each of those fields will be a regular property struct. + for i := 0; i < targetStruct.NumField(); i++ { + targetFieldName := targetStruct.Type().Field(i).Name + archOrOsSpecificStruct := targetStruct.Field(i) + for j := 0; j < archOrOsSpecificStruct.NumField(); j++ { + property := archOrOsSpecificStruct.Field(j) + // e.g. Asflags, Cflags, Enabled, etc. + propertyName := archOrOsSpecificStruct.Type().Field(j).Name + + if targetFieldName == "Android" { + productConfigProperties.AddSoongConfigProperty(propertyName, namespace, soongConfigVariableName, soongConfigVariableValue, "android", property.Interface()) + } else if targetFieldName == "Host" { + for _, os := range osTypeList { + if os.Class == Host { + productConfigProperties.AddSoongConfigProperty(propertyName, namespace, soongConfigVariableName, soongConfigVariableValue, os.Name, property.Interface()) + } + } + } else { + // One problem with supporting additional fields is that if multiple branches of + // "target" overlap, we don't want them to be in the same select statement (aka + // configuration axis). "android" and "host" are disjoint, so it's ok that we only + // have 2 axes right now. (soongConfigVariables and soongConfigVariablesPlusOs) + panic("TODO: support other target types in soong config variable structs: " + targetFieldName) + } + } } - - // variableValues represent the product_variables or soong_config_variables struct. - variableValues := reflect.ValueOf(variableProps).Elem().FieldByName(fieldName) - productConfigProperties.AddProductConfigProperties(namespace, suffix, variableValues, outerAxis) } func VariableMutator(mctx BottomUpMutatorContext) { diff --git a/apex/Android.bp b/apex/Android.bp index 7ffca0ea5..61d7fb2e2 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -38,6 +38,7 @@ bootstrap_go_package { "apex_test.go", "bootclasspath_fragment_test.go", "classpath_element_test.go", + "dexpreopt_bootjars_test.go", "metadata_test.go", "platform_bootclasspath_test.go", "systemserver_classpath_fragment_test.go", diff --git a/apex/apex.go b/apex/apex.go index 6a64ad6cd..ff7ee35c0 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -137,6 +137,10 @@ type apexBundleProperties struct { // List of filesystem images that are embedded inside this APEX bundle. Filesystems []string + // The minimum SDK version that this APEX must support at minimum. This is usually set to + // the SDK version that the APEX was first introduced. + Min_sdk_version *string + // Whether this APEX is considered updatable or not. When set to true, this will enforce // additional rules for making sure that the APEX is truly updatable. To be updatable, // min_sdk_version should be set as well. This will also disable the size optimizations like @@ -380,10 +384,6 @@ type overridableProperties struct { // Trim against a specific Dynamic Common Lib APEX Trim_against *string - - // The minimum SDK version that this APEX must support at minimum. This is usually set to - // the SDK version that the APEX was first introduced. - Min_sdk_version *string } type apexBundle struct { @@ -404,7 +404,7 @@ type apexBundle struct { /////////////////////////////////////////////////////////////////////////////////////////// // Inputs - // Keys for apex_paylaod.img + // Keys for apex_payload.img publicKeyFile android.Path privateKeyFile android.Path @@ -2287,16 +2287,13 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext, ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName) } case bcpfTag: - bcpfModule, ok := child.(*java.BootclasspathFragmentModule) + _, ok := child.(*java.BootclasspathFragmentModule) if !ok { ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName) return false } vctx.filesInfo = append(vctx.filesInfo, apexBootclasspathFragmentFiles(ctx, child)...) - for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() { - a.makeModulesToInstall = append(a.makeModulesToInstall, makeModuleName) - } return true case sscpfTag: if _, ok := child.(*java.SystemServerClasspathModule); !ok { @@ -2609,8 +2606,45 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { return a.depVisitor(&vctx, ctx, child, parent) }) vctx.normalizeFileInfo(ctx) if a.privateKeyFile == nil { - ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key)) - return + if ctx.Config().AllowMissingDependencies() { + // TODO(b/266099037): a better approach for slim manifests. + ctx.AddMissingDependencies([]string{String(a.overridableProperties.Key)}) + // Create placeholder paths for later stages that expect to see those paths, + // though they won't be used. + var unusedPath = android.PathForModuleOut(ctx, "nonexistentprivatekey") + ctx.Build(pctx, android.BuildParams{ + Rule: android.ErrorRule, + Output: unusedPath, + Args: map[string]string{ + "error": "Private key not available", + }, + }) + a.privateKeyFile = unusedPath + } else { + ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key)) + return + } + } + + if a.publicKeyFile == nil { + if ctx.Config().AllowMissingDependencies() { + // TODO(b/266099037): a better approach for slim manifests. + ctx.AddMissingDependencies([]string{String(a.overridableProperties.Key)}) + // Create placeholder paths for later stages that expect to see those paths, + // though they won't be used. + var unusedPath = android.PathForModuleOut(ctx, "nonexistentpublickey") + ctx.Build(pctx, android.BuildParams{ + Rule: android.ErrorRule, + Output: unusedPath, + Args: map[string]string{ + "error": "Public key not available", + }, + }) + a.publicKeyFile = unusedPath + } else { + ctx.PropertyErrorf("key", "public_key for %q could not be found", String(a.overridableProperties.Key)) + return + } } //////////////////////////////////////////////////////////////////////////////////////////// @@ -2662,19 +2696,6 @@ func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint. bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) var filesToAdd []apexFile - // Add the boot image files, e.g. .art, .oat and .vdex files. - if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() { - for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() { - dirInApex := filepath.Join("javalib", arch.String()) - for _, f := range files { - androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String()) - // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil - af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil) - filesToAdd = append(filesToAdd, af) - } - } - } - // Add classpaths.proto config. if af := apexClasspathFragmentProtoFile(ctx, module); af != nil { filesToAdd = append(filesToAdd, *af) @@ -2951,7 +2972,7 @@ func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string { // Only override the minSdkVersion value on Apexes which already specify // a min_sdk_version (it's optional for non-updatable apexes), and that its // min_sdk_version value is lower than the one to override with. - minApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.overridableProperties.Min_sdk_version)) + minApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version)) if minApiLevel.IsNone() { return "" } @@ -3242,7 +3263,6 @@ func makeApexAvailableBaseline() map[string][]string { // m["com.android.appsearch"] = []string{ "icing-java-proto-lite", - "libprotobuf-java-lite", } // // Module separator @@ -3258,11 +3278,8 @@ func makeApexAvailableBaseline() map[string][]string { // Module separator // m["com.android.extservices"] = []string{ - "error_prone_annotations", "ExtServices-core", - "ExtServices", "libtextclassifier-java", - "libz_current", "textclassifier-statsd", "TextClassifierNotificationLibNoManifest", "TextClassifierServiceLibNoManifest", @@ -3280,8 +3297,6 @@ func makeApexAvailableBaseline() map[string][]string { "android.hidl.memory@1.0", "android.hidl.safe_union@1.0", "libarect", - "libbuildversion", - "libmath", "libprocpartition", } // @@ -3311,15 +3326,12 @@ func makeApexAvailableBaseline() map[string][]string { // Module separator // m["com.android.runtime"] = []string{ - "bionic_libc_platform_headers", - "libarm-optimized-routines-math", "libc_aeabi", "libc_bionic", "libc_bionic_ndk", "libc_bootstrap", "libc_common", "libc_common_shared", - "libc_common_static", "libc_dns", "libc_dynamic_dispatch", "libc_fortify", @@ -3336,19 +3348,16 @@ func makeApexAvailableBaseline() map[string][]string { "libc_openbsd_large_stack", "libc_openbsd_ndk", "libc_pthread", - "libc_static_dispatch", "libc_syscalls", "libc_tzcode", "libc_unwind_static", "libdebuggerd", "libdebuggerd_common_headers", "libdebuggerd_handler_core", - "libdebuggerd_handler_fallback", "libdl_static", "libjemalloc5", "liblinker_main", "liblinker_malloc", - "liblz4", "liblzma", "libprocinfo", "libpropertyinfoparser", @@ -3366,17 +3375,7 @@ func makeApexAvailableBaseline() map[string][]string { m["com.android.tethering"] = []string{ "android.hardware.tetheroffload.config-V1.0-java", "android.hardware.tetheroffload.control-V1.0-java", - "android.hidl.base-V1.0-java", - "libcgrouprc", - "libcgrouprc_format", - "libtetherutilsjni", - "libvndksupport", "net-utils-framework-common", - "netd_aidl_interface-V3-java", - "netlink-client", - "networkstack-aidl-interfaces-java", - "tethering-aidl-interfaces-java", - "TetheringApiCurrentLib", } // // Module separator @@ -3396,48 +3395,22 @@ func makeApexAvailableBaseline() map[string][]string { "android.hardware.wifi.supplicant-V1.1-java", "android.hardware.wifi.supplicant-V1.2-java", "android.hardware.wifi.supplicant-V1.3-java", - "android.hidl.base-V1.0-java", - "android.hidl.manager-V1.0-java", - "android.hidl.manager-V1.1-java", - "android.hidl.manager-V1.2-java", "bouncycastle-unbundled", - "dnsresolver_aidl_interface-V2-java", - "error_prone_annotations", - "framework-wifi-pre-jarjar", "framework-wifi-util-lib", - "ipmemorystore-aidl-interfaces-V3-java", - "ipmemorystore-aidl-interfaces-java", "ksoap2", "libnanohttpd", - "libwifi-jni", - "net-utils-services-common", - "netd_aidl_interface-V2-java", - "netd_aidl_interface-unstable-java", - "netd_event_listener_interface-java", - "netlink-client", - "networkstack-client", - "services.net", "wifi-lite-protos", "wifi-nano-protos", "wifi-service-pre-jarjar", - "wifi-service-resources", - } - // - // Module separator - // - m["com.android.os.statsd"] = []string{ - "libstatssocket", } // // Module separator // m[android.AvailableToAnyApex] = []string{ - "libclang_rt", "libprofile-clang-extras", "libprofile-clang-extras_ndk", "libprofile-extras", "libprofile-extras_ndk", - "libunwind", } return m } @@ -3593,8 +3566,8 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but // given it's coming via config, we probably don't want to put it in here. var minSdkVersion bazel.StringAttribute - if a.overridableProperties.Min_sdk_version != nil { - minSdkVersion.SetValue(*a.overridableProperties.Min_sdk_version) + if a.properties.Min_sdk_version != nil { + minSdkVersion.SetValue(*a.properties.Min_sdk_version) } if props, ok := productVariableProps[minSdkVersionPropName]; ok { for c, p := range props { @@ -3700,6 +3673,8 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze commonAttrs := android.CommonAttributes{} if a.testApex { commonAttrs.Testonly = proptools.BoolPtr(true) + // Set the api_domain of the test apex + attrs.Base_apex_name = proptools.StringPtr(cc.GetApiDomain(a.Name())) } return attrs, props, commonAttrs diff --git a/apex/apex_test.go b/apex/apex_test.go index bf9c71b2e..c1d80a39f 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -147,7 +147,7 @@ var prepareForApexTest = android.GroupFixturePreparers( android.PrepareForTestWithAndroidBuildComponents, bpf.PrepareForTestWithBpf, cc.PrepareForTestWithCcBuildComponents, - java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithDexpreopt, prebuilt_etc.PrepareForTestWithPrebuiltEtc, rust.PrepareForTestWithRustDefaultModules, sh.PrepareForTestWithShBuildComponents, @@ -1368,6 +1368,8 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) { cc_library { name: "mylib", srcs: ["mylib.cpp"], + static_libs: ["libstatic"], + shared_libs: ["libshared"], runtime_libs: ["libfoo", "libbar"], system_shared_libs: [], stl: "none", @@ -1392,6 +1394,39 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) { apex_available: [ "myapex" ], } + cc_library { + name: "libstatic", + srcs: ["mylib.cpp"], + system_shared_libs: [], + stl: "none", + apex_available: [ "myapex" ], + runtime_libs: ["libstatic_to_runtime"], + } + + cc_library { + name: "libshared", + srcs: ["mylib.cpp"], + system_shared_libs: [], + stl: "none", + apex_available: [ "myapex" ], + runtime_libs: ["libshared_to_runtime"], + } + + cc_library { + name: "libstatic_to_runtime", + srcs: ["mylib.cpp"], + system_shared_libs: [], + stl: "none", + apex_available: [ "myapex" ], + } + + cc_library { + name: "libshared_to_runtime", + srcs: ["mylib.cpp"], + system_shared_libs: [], + stl: "none", + apex_available: [ "myapex" ], + } `) apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") @@ -1405,11 +1440,14 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) { // Ensure that runtime_libs dep in included ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") + ensureContains(t, copyCmds, "image.apex/lib64/libshared.so") + ensureContains(t, copyCmds, "image.apex/lib64/libshared_to_runtime.so") + + ensureNotContains(t, copyCmds, "image.apex/lib64/libstatic_to_runtime.so") apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") - } var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers( @@ -1461,6 +1499,10 @@ func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { sanitize: { never: true, }, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } `) ctx := result.TestContext @@ -1509,6 +1551,10 @@ func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { sanitize: { never: true, }, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } `) ctx := result.TestContext @@ -6533,6 +6579,72 @@ func TestApexAvailable_IndirectDep(t *testing.T) { }`) } +func TestApexAvailable_IndirectStaticDep(t *testing.T) { + testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + native_shared_libs: ["libfoo"], + updatable: false, + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + cc_library { + name: "libfoo", + stl: "none", + static_libs: ["libbar"], + system_shared_libs: [], + apex_available: ["myapex"], + } + + cc_library { + name: "libbar", + stl: "none", + shared_libs: ["libbaz"], + system_shared_libs: [], + apex_available: ["myapex"], + } + + cc_library { + name: "libbaz", + stl: "none", + system_shared_libs: [], + }`) + + testApexError(t, `requires "libbar" that doesn't list the APEX under 'apex_available'.`, ` + apex { + name: "myapex", + key: "myapex.key", + native_shared_libs: ["libfoo"], + updatable: false, + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + cc_library { + name: "libfoo", + stl: "none", + static_libs: ["libbar"], + system_shared_libs: [], + apex_available: ["myapex"], + } + + cc_library { + name: "libbar", + stl: "none", + system_shared_libs: [], + }`) +} + func TestApexAvailable_InvalidApexName(t *testing.T) { testApexError(t, "\"otherapex\" is not a valid module name", ` apex { @@ -8341,8 +8453,8 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) }) - t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { - err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` + t.Run("updatable jar from ART apex in the platform bootclasspath => error", func(t *testing.T) { + err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the platform bootclasspath` // Update the dexpreopt BootJars directly. preparer := android.GroupFixturePreparers( prepareSetBootJars("com.android.art.debug:some-art-lib"), @@ -8365,8 +8477,8 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, err, preparer) }) - t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { - err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` + t.Run("updatable jar from some other apex in the platform bootclasspath => error", func(t *testing.T) { + err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the platform bootclasspath` preparer := android.GroupFixturePreparers( java.FixtureConfigureBootJars("some-updatable-apex:some-updatable-apex-lib"), java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), @@ -8374,7 +8486,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, err, preparer) }) - t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { + t.Run("non-updatable jar from some other apex in the platform bootclasspath => ok", func(t *testing.T) { preparer := java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib") fragment := java.ApexVariantReference{ Apex: proptools.StringPtr("some-non-updatable-apex"), @@ -8389,7 +8501,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, err, preparer) }) - t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { + t.Run("nonexistent jar in the platform bootclasspath => error", func(t *testing.T) { err := `"platform-bootclasspath" depends on undefined module "nonexistent"` preparer := java.FixtureConfigureBootJars("platform:nonexistent") testNoUpdatableJarsInBootImage(t, err, preparer) @@ -8402,7 +8514,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) { testNoUpdatableJarsInBootImage(t, err, preparer) }) - t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { + t.Run("platform jar in the platform bootclasspath => ok", func(t *testing.T) { preparer := android.GroupFixturePreparers( java.FixtureConfigureBootJars("platform:some-platform-lib"), java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 3e55ccc11..1b5288696 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -115,20 +115,7 @@ func TestBootclasspathFragments(t *testing.T) { // Make sure that the art-bootclasspath-fragment is using the correct configuration. checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000", - "com.android.art:baz,com.android.art:quuz", ` -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat -dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex -`) + "com.android.art:baz,com.android.art:quuz") } func TestBootclasspathFragments_FragmentDependency(t *testing.T) { @@ -261,7 +248,7 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) { checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope) } -func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) { +func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string) { t.Helper() bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule) @@ -269,19 +256,6 @@ func checkBootclasspathFragment(t *testing.T, result *android.TestResult, module bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) modules := bootclasspathFragmentInfo.Modules() android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) - - // Get a list of all the paths in the boot image sorted by arch type. - allPaths := []string{} - bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() - for _, archType := range android.ArchTypeList() { - if paths, ok := bootImageFilesByArchType[archType]; ok { - for _, path := range paths { - allPaths = append(allPaths, android.NormalizePathForTesting(path)) - } - } - } - - android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n")) } func TestBootclasspathFragmentInArtApex(t *testing.T) { @@ -420,18 +394,6 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ "etc/boot-image.prof", "etc/classpaths/bootclasspath.pb", - "javalib/arm/boot.art", - "javalib/arm/boot.oat", - "javalib/arm/boot.vdex", - "javalib/arm/boot-bar.art", - "javalib/arm/boot-bar.oat", - "javalib/arm/boot-bar.vdex", - "javalib/arm64/boot.art", - "javalib/arm64/boot.oat", - "javalib/arm64/boot.vdex", - "javalib/arm64/boot-bar.art", - "javalib/arm64/boot-bar.oat", - "javalib/arm64/boot-bar.vdex", "javalib/bar.jar", "javalib/foo.jar", }) @@ -441,62 +403,12 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { `mybootclasspathfragment`, }) - // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. - ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "mybootclasspathfragment-dexpreopt-arm64-boot.art", - "mybootclasspathfragment-dexpreopt-arm64-boot.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot.art", - "mybootclasspathfragment-dexpreopt-arm-boot.oat", - "mybootclasspathfragment-dexpreopt-arm-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", - }) - // Make sure that the source bootclasspath_fragment copies its dex files to the predefined // locations for the art image. module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") }) - t.Run("boot image files from source no boot image in apex", func(t *testing.T) { - result := android.GroupFixturePreparers( - commonPreparer, - - // Configure some libraries in the art bootclasspath_fragment that match the source - // bootclasspath_fragment's contents property. - java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), - addSource("foo", "bar"), - java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"), - ).RunTest(t) - - ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "etc/boot-image.prof", - "etc/classpaths/bootclasspath.pb", - "javalib/bar.jar", - "javalib/foo.jar", - }) - - ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "mybootclasspathfragment-dexpreopt-arm64-boot.art", - "mybootclasspathfragment-dexpreopt-arm64-boot.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot.art", - "mybootclasspathfragment-dexpreopt-arm-boot.oat", - "mybootclasspathfragment-dexpreopt-arm-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", - }) - }) - t.Run("generate boot image profile even if dexpreopt is disabled", func(t *testing.T) { result := android.GroupFixturePreparers( commonPreparer, @@ -552,18 +464,6 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{ "etc/boot-image.prof", - "javalib/arm/boot.art", - "javalib/arm/boot.oat", - "javalib/arm/boot.vdex", - "javalib/arm/boot-bar.art", - "javalib/arm/boot-bar.oat", - "javalib/arm/boot-bar.vdex", - "javalib/arm64/boot.art", - "javalib/arm64/boot.oat", - "javalib/arm64/boot.vdex", - "javalib/arm64/boot-bar.art", - "javalib/arm64/boot-bar.oat", - "javalib/arm64/boot-bar.vdex", "javalib/bar.jar", "javalib/foo.jar", }) @@ -574,65 +474,12 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { `prebuilt_com.android.art`, }) - // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. - ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "mybootclasspathfragment-dexpreopt-arm64-boot.art", - "mybootclasspathfragment-dexpreopt-arm64-boot.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot.art", - "mybootclasspathfragment-dexpreopt-arm-boot.oat", - "mybootclasspathfragment-dexpreopt-arm-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", - }) - // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined // locations for the art image. module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art") checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") }) - t.Run("boot image files from preferred prebuilt no boot image in apex", func(t *testing.T) { - result := android.GroupFixturePreparers( - commonPreparer, - - // Configure some libraries in the art bootclasspath_fragment that match the source - // bootclasspath_fragment's contents property. - java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), - addSource("foo", "bar"), - - // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. - addPrebuilt(true, "foo", "bar"), - - java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"), - ).RunTest(t) - - ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{ - "etc/boot-image.prof", - "javalib/bar.jar", - "javalib/foo.jar", - }) - - ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ - "mybootclasspathfragment-dexpreopt-arm64-boot.art", - "mybootclasspathfragment-dexpreopt-arm64-boot.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot.art", - "mybootclasspathfragment-dexpreopt-arm-boot.oat", - "mybootclasspathfragment-dexpreopt-arm-boot.vdex", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", - "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", - }) - }) - t.Run("source with inconsistency between config and contents", func(t *testing.T) { android.GroupFixturePreparers( commonPreparer, @@ -782,10 +629,6 @@ func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art") checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") - - // Check that the right deapexer module was chosen for a boot image. - param := module.Output("out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art") - android.AssertStringDoesContain(t, "didn't find the expected deapexer in the input path", param.Input.String(), "/com.android.art.deapexer") }) t.Run("enabled alternative APEX", func(t *testing.T) { @@ -1250,7 +1093,7 @@ func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) { func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) { result := android.GroupFixturePreparers( prepareForTestWithBootclasspathFragment, - java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithDexpreopt, prepareForTestWithArtApex, prepareForTestWithMyapex, // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. diff --git a/apex/dexpreopt_bootjars_test.go b/apex/dexpreopt_bootjars_test.go new file mode 100644 index 000000000..bba8bb6cb --- /dev/null +++ b/apex/dexpreopt_bootjars_test.go @@ -0,0 +1,254 @@ +// Copyright 2019 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 apex + +import ( + "fmt" + "path/filepath" + "sort" + "testing" + + "android/soong/android" + "android/soong/java" +) + +func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string, preferPrebuilt bool) { + bp := ` + // Platform. + + java_sdk_library { + name: "foo", + srcs: ["a.java"], + api_packages: ["foo"], + } + + java_library { + name: "bar", + srcs: ["b.java"], + installable: true, + system_ext_specific: true, + } + + dex_import { + name: "baz", + jars: ["a.jar"], + } + + platform_bootclasspath { + name: "platform-bootclasspath", + fragments: [ + { + apex: "com.android.art", + module: "art-bootclasspath-fragment", + }, + ], + } + + // Source ART APEX. + + java_library { + name: "core-oj", + srcs: ["core-oj.java"], + installable: true, + apex_available: [ + "com.android.art", + ], + } + + bootclasspath_fragment { + name: "art-bootclasspath-fragment", + image_name: "art", + contents: ["core-oj"], + apex_available: [ + "com.android.art", + ], + hidden_api: { + split_packages: ["*"], + }, + } + + apex_key { + name: "com.android.art.key", + public_key: "com.android.art.avbpubkey", + private_key: "com.android.art.pem", + } + + apex { + name: "com.android.art", + key: "com.android.art.key", + bootclasspath_fragments: ["art-bootclasspath-fragment"], + updatable: false, + } + + // Prebuilt ART APEX. + + java_import { + name: "core-oj", + prefer: %[1]t, + jars: ["core-oj.jar"], + apex_available: [ + "com.android.art", + ], + } + + prebuilt_bootclasspath_fragment { + name: "art-bootclasspath-fragment", + prefer: %[1]t, + image_name: "art", + contents: ["core-oj"], + hidden_api: { + annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", + metadata: "my-bootclasspath-fragment/metadata.csv", + index: "my-bootclasspath-fragment/index.csv", + stub_flags: "my-bootclasspath-fragment/stub-flags.csv", + all_flags: "my-bootclasspath-fragment/all-flags.csv", + }, + apex_available: [ + "com.android.art", + ], + } + + prebuilt_apex { + name: "com.android.art", + prefer: %[1]t, + apex_name: "com.android.art", + src: "com.android.art-arm.apex", + exported_bootclasspath_fragments: ["art-bootclasspath-fragment"], + } + ` + + result := android.GroupFixturePreparers( + java.PrepareForTestWithDexpreopt, + java.PrepareForTestWithJavaSdkLibraryFiles, + java.FixtureWithLastReleaseApis("foo"), + java.FixtureConfigureBootJars("com.android.art:core-oj", "platform:foo", "system_ext:bar", "platform:baz"), + PrepareForTestWithApexBuildComponents, + prepareForTestWithArtApex, + ).RunTestWithBp(t, fmt.Sprintf(bp, preferPrebuilt)) + + platformBootclasspath := result.ModuleForTests("platform-bootclasspath", "android_common") + rule := platformBootclasspath.Output(ruleFile) + + inputs := rule.Implicits.Strings() + sort.Strings(inputs) + sort.Strings(expectedInputs) + + outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Strings() + sort.Strings(outputs) + sort.Strings(expectedOutputs) + + android.AssertStringPathsRelativeToTopEquals(t, "inputs", result.Config, expectedInputs, inputs) + + android.AssertStringPathsRelativeToTopEquals(t, "outputs", result.Config, expectedOutputs, outputs) +} + +func TestDexpreoptBootJarsWithSourceArtApex(t *testing.T) { + ruleFile := "boot.art" + + expectedInputs := []string{ + "out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/foo.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/bar.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/baz.jar", + "out/soong/dexpreopt_arm64/dex_artjars/boot.prof", + "out/soong/dexpreopt_arm64/dex_bootjars/boot.prof", + } + + expectedOutputs := []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat", + } + + testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, false) +} + +// The only difference is that the ART profile should be deapexed from the prebuilt APEX. Other +// inputs and outputs should be the same as above. +func TestDexpreoptBootJarsWithPrebuiltArtApex(t *testing.T) { + ruleFile := "boot.art" + + expectedInputs := []string{ + "out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/foo.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/bar.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/baz.jar", + "out/soong/.intermediates/com.android.art.deapexer/android_common/deapexer/etc/boot-image.prof", + "out/soong/dexpreopt_arm64/dex_bootjars/boot.prof", + } + + expectedOutputs := []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat", + "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat", + } + + testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, true) +} + +// Changes to the boot.zip structure may break the ART APK scanner. +func TestDexpreoptBootZip(t *testing.T) { + ruleFile := "boot.zip" + + ctx := android.PathContextForTesting(android.TestArchConfig("", nil, "", nil)) + expectedInputs := []string{} + for _, target := range ctx.Config().Targets[android.Android] { + for _, ext := range []string{".art", ".oat", ".vdex"} { + for _, suffix := range []string{"", "-foo", "-bar", "-baz"} { + expectedInputs = append(expectedInputs, + filepath.Join( + "out/soong/dexpreopt_arm64/dex_bootjars", + target.Os.String(), + "system/framework", + target.Arch.ArchType.String(), + "boot"+suffix+ext)) + } + } + } + + expectedOutputs := []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/boot.zip", + } + + testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, false) +} diff --git a/apex/metadata_test.go b/apex/metadata_test.go index f6ead424e..fed5beae7 100644 --- a/apex/metadata_test.go +++ b/apex/metadata_test.go @@ -27,7 +27,7 @@ import ( func TestModulesSingleton(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithApexMultitreeSingleton, - java.PrepareForTestWithDexpreopt, + java.PrepareForTestWithJavaDefaultModules, PrepareForTestWithApexBuildComponents, java.FixtureConfigureApexBootJars("myapex:foo"), java.PrepareForTestWithJavaSdkLibraryFiles, diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go index 4b48da8e2..05bb13689 100644 --- a/apex/platform_bootclasspath_test.go +++ b/apex/platform_bootclasspath_test.go @@ -20,6 +20,7 @@ import ( "testing" "android/soong/android" + "android/soong/dexpreopt" "android/soong/java" "github.com/google/blueprint" @@ -30,7 +31,7 @@ import ( // apexes. var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers( - java.PrepareForTestWithDexpreopt, + java.PrepareForTestWithJavaDefaultModules, PrepareForTestWithApexBuildComponents, ) @@ -249,6 +250,8 @@ func TestPlatformBootclasspathDependencies(t *testing.T) { java.FixtureConfigureApexBootJars("myapex:bar"), java.PrepareForTestWithJavaSdkLibraryFiles, java.FixtureWithLastReleaseApis("foo"), + java.PrepareForTestWithDexpreopt, + dexpreopt.FixtureDisableDexpreoptBootImages(false), ).RunTestWithBp(t, ` apex { name: "com.android.art", @@ -539,9 +542,6 @@ func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) { // Not a prebuilt as no prebuilt existed when it was added. "platform:legacy.core.platform.api.stubs", - // Needed for generating the boot image. - "platform:dex2oatd", - // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt // modules when available as it does not know which one will be preferred. "myapex:foo", diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 31cecf111..0d83830f1 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -199,14 +199,11 @@ func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) { p.apexFilesForAndroidMk = append(p.apexFilesForAndroidMk, af) } } else if tag == exportedBootclasspathFragmentTag { - bcpfModule, ok := child.(*java.PrebuiltBootclasspathFragmentModule) + _, ok := child.(*java.PrebuiltBootclasspathFragmentModule) if !ok { ctx.PropertyErrorf("exported_bootclasspath_fragments", "%q is not a prebuilt_bootclasspath_fragment module", name) return false } - for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() { - p.requiredModuleNames = append(p.requiredModuleNames, makeModuleName) - } // Visit the children of the bootclasspath_fragment. return true } else if tag == exportedSystemserverclasspathFragmentTag { diff --git a/bazel/configurability.go b/bazel/configurability.go index d01877dd5..d042fe8b8 100644 --- a/bazel/configurability.go +++ b/bazel/configurability.go @@ -69,8 +69,8 @@ const ( productVariableBazelPackage = "//build/bazel/product_variables" - AndroidAndInApex = "android-in_apex" - AndroidAndNonApex = "android-non_apex" + AndroidAndInApex = "android-in_apex" + AndroidPlatform = "system" InApex = "in_apex" NonApex = "non_apex" @@ -202,7 +202,7 @@ var ( osAndInApexMap = map[string]string{ AndroidAndInApex: "//build/bazel/rules/apex:android-in_apex", - AndroidAndNonApex: "//build/bazel/rules/apex:android-non_apex", + AndroidPlatform: "//build/bazel/rules/apex:system", osDarwin: "//build/bazel/platforms/os:darwin", osLinux: "//build/bazel/platforms/os:linux_glibc", osLinuxMusl: "//build/bazel/platforms/os:linux_musl", @@ -292,8 +292,7 @@ func (ca ConfigurationAxis) SelectKey(config string) string { case osArch: return platformOsArchMap[config] case productVariables: - if strings.HasSuffix(config, ConditionsDefaultConfigKey) { - // e.g. "acme__feature1__conditions_default" or "android__board__conditions_default" + if config == ConditionsDefaultConfigKey { return ConditionsDefaultSelectKey } return fmt.Sprintf("%s:%s", productVariableBazelPackage, config) @@ -325,11 +324,11 @@ var ( ) // ProductVariableConfigurationAxis returns an axis for the given product variable -func ProductVariableConfigurationAxis(variable string, outerAxis ConfigurationAxis) ConfigurationAxis { +func ProductVariableConfigurationAxis(archVariant bool, variable string) ConfigurationAxis { return ConfigurationAxis{ configurationType: productVariables, subType: variable, - outerAxisType: outerAxis.configurationType, + archVariant: archVariant, } } @@ -340,8 +339,8 @@ type ConfigurationAxis struct { // some configuration types (e.g. productVariables) have multiple independent axes, subType helps // distinguish between them without needing to list all 17 product variables. subType string - // used to keep track of which product variables are arch variant - outerAxisType configurationType + + archVariant bool } func (ca *ConfigurationAxis) less(other ConfigurationAxis) bool { diff --git a/bazel/properties.go b/bazel/properties.go index 1757bad49..e22f4dbe7 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -334,7 +334,7 @@ func (la *LabelAttribute) Collapse() error { if containsArch { allProductVariablesAreArchVariant := true for k := range la.ConfigurableValues { - if k.configurationType == productVariables && k.outerAxisType != arch { + if k.configurationType == productVariables && !k.archVariant { allProductVariablesAreArchVariant = false } } @@ -1434,4 +1434,6 @@ type StringMapAttribute map[string]string type ConfigSettingAttributes struct { // Each key in Flag_values is a label to a custom string_setting Flag_values StringMapAttribute + // Each element in Constraint_values is a label to a constraint_value + Constraint_values LabelListAttribute } diff --git a/bazel/properties_test.go b/bazel/properties_test.go index cf03eb5f6..c56d11f3f 100644 --- a/bazel/properties_test.go +++ b/bazel/properties_test.go @@ -248,13 +248,13 @@ func TestResolveExcludes(t *testing.T) { OsArchConfigurationAxis: labelListSelectValues{ "linux_x86": makeLabelList([]string{"linux_x86_include"}, []string{}), }, - ProductVariableConfigurationAxis("product_with_defaults", NoConfigAxis): labelListSelectValues{ + ProductVariableConfigurationAxis(false, "product_with_defaults"): labelListSelectValues{ "a": makeLabelList([]string{}, []string{"not_in_value"}), "b": makeLabelList([]string{"b_val"}, []string{}), "c": makeLabelList([]string{"c_val"}, []string{}), ConditionsDefaultConfigKey: makeLabelList([]string{"c_val", "default", "default2", "all_exclude"}, []string{}), }, - ProductVariableConfigurationAxis("product_only_with_excludes", NoConfigAxis): labelListSelectValues{ + ProductVariableConfigurationAxis(false, "product_only_with_excludes"): labelListSelectValues{ "a": makeLabelList([]string{}, []string{"product_config_exclude"}), }, }, @@ -282,13 +282,13 @@ func TestResolveExcludes(t *testing.T) { "linux_x86": makeLabels("linux_x86_include"), ConditionsDefaultConfigKey: nilLabels, }, - ProductVariableConfigurationAxis("product_with_defaults", NoConfigAxis): { + ProductVariableConfigurationAxis(false, "product_with_defaults"): { "a": nilLabels, "b": makeLabels("b_val"), "c": makeLabels("c_val"), ConditionsDefaultConfigKey: makeLabels("c_val", "default", "default2"), }, - ProductVariableConfigurationAxis("product_only_with_excludes", NoConfigAxis): { + ProductVariableConfigurationAxis(false, "product_only_with_excludes"): { "a": nilLabels, ConditionsDefaultConfigKey: makeLabels("product_config_exclude"), }, @@ -679,7 +679,7 @@ func TestDeduplicateAxesFromBase(t *testing.T) { OsArchConfigurationAxis: stringListSelectValues{ "linux_x86": {"linux_x86_include"}, }, - ProductVariableConfigurationAxis("a", NoConfigAxis): stringListSelectValues{ + ProductVariableConfigurationAxis(false, "a"): stringListSelectValues{ "a": []string{"not_in_value"}, }, }, @@ -704,7 +704,7 @@ func TestDeduplicateAxesFromBase(t *testing.T) { "linux": []string{"linux_include"}, }, OsArchConfigurationAxis: stringListSelectValues{}, - ProductVariableConfigurationAxis("a", NoConfigAxis): stringListSelectValues{ + ProductVariableConfigurationAxis(false, "a"): stringListSelectValues{ "a": []string{"not_in_value"}, }, } diff --git a/bp2build/Android.bp b/bp2build/Android.bp index b6635c430..9ec3a40b9 100644 --- a/bp2build/Android.bp +++ b/bp2build/Android.bp @@ -19,6 +19,7 @@ bootstrap_go_package { "testing.go", ], deps: [ + "soong-aidl-library", "soong-android", "soong-android-allowlists", "soong-android-soongconfig", @@ -37,6 +38,7 @@ bootstrap_go_package { ], testSrcs: [ "aar_conversion_test.go", + "aidl_library_conversion_test.go", "android_app_certificate_conversion_test.go", "android_app_conversion_test.go", "apex_conversion_test.go", diff --git a/bp2build/aidl_library_conversion_test.go b/bp2build/aidl_library_conversion_test.go new file mode 100644 index 000000000..0522da45e --- /dev/null +++ b/bp2build/aidl_library_conversion_test.go @@ -0,0 +1,119 @@ +// Copyright 2023 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 bp2build + +import ( + "testing" + + "android/soong/aidl_library" + "android/soong/android" +) + +func runAidlLibraryTestCase(t *testing.T, tc Bp2buildTestCase) { + t.Helper() + (&tc).ModuleTypeUnderTest = "aidl_library" + (&tc).ModuleTypeUnderTestFactory = aidl_library.AidlLibraryFactory + RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) +} + +func TestAidlLibrary(t *testing.T) { + testcases := []struct { + name string + bp string + expectedBazelAttrs AttrNameToString + }{ + { + name: "aidl_library with strip_import_prefix", + bp: ` + aidl_library { + name: "foo", + srcs: ["aidl/foo.aidl"], + hdrs: ["aidl/header.aidl"], + strip_import_prefix: "aidl", + }`, + expectedBazelAttrs: AttrNameToString{ + "srcs": `["aidl/foo.aidl"]`, + "hdrs": `["aidl/header.aidl"]`, + "strip_import_prefix": `"aidl"`, + "tags": `["apex_available=//apex_available:anyapex"]`, + }, + }, + { + name: "aidl_library without strip_import_prefix", + bp: ` + aidl_library { + name: "foo", + srcs: ["aidl/foo.aidl"], + hdrs: ["aidl/header.aidl"], + }`, + expectedBazelAttrs: AttrNameToString{ + "srcs": `["aidl/foo.aidl"]`, + "hdrs": `["aidl/header.aidl"]`, + "tags": `["apex_available=//apex_available:anyapex"]`, + }, + }, + } + + for _, test := range testcases { + t.Run(test.name, func(t *testing.T) { + expectedBazelTargets := []string{ + MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs), + } + runAidlLibraryTestCase(t, Bp2buildTestCase{ + Description: test.name, + Blueprint: test.bp, + ExpectedBazelTargets: expectedBazelTargets, + }) + }) + } +} + +func TestAidlLibraryWithDeps(t *testing.T) { + bp := ` + aidl_library { + name: "bar", + srcs: ["Bar.aidl"], + hdrs: ["aidl/BarHeader.aidl"], + } + aidl_library { + name: "foo", + srcs: ["aidl/Foo.aidl"], + hdrs: ["aidl/FooHeader.aidl"], + strip_import_prefix: "aidl", + deps: ["bar"], + }` + + t.Run("aidl_library with deps", func(t *testing.T) { + expectedBazelTargets := []string{ + MakeBazelTargetNoRestrictions("aidl_library", "bar", AttrNameToString{ + "srcs": `["Bar.aidl"]`, + "hdrs": `["aidl/BarHeader.aidl"]`, + "tags": `["apex_available=//apex_available:anyapex"]`, + }), + MakeBazelTargetNoRestrictions("aidl_library", "foo", AttrNameToString{ + "srcs": `["aidl/Foo.aidl"]`, + "hdrs": `["aidl/FooHeader.aidl"]`, + "strip_import_prefix": `"aidl"`, + "deps": `[":bar"]`, + "tags": `["apex_available=//apex_available:anyapex"]`, + }), + } + runAidlLibraryTestCase(t, Bp2buildTestCase{ + Description: "aidl_library with deps", + Blueprint: bp, + ExpectedBazelTargets: expectedBazelTargets, + }) + }) +} diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go index 928a1f2e1..7f7aa6a3a 100644 --- a/bp2build/android_app_conversion_test.go +++ b/bp2build/android_app_conversion_test.go @@ -80,6 +80,7 @@ android_app { static_libs: ["static_lib_dep"], java_version: "7", certificate: "foocert", + required: ["static_lib_dep"], } `, ExpectedBazelTargets: []string{ diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go index 1cc3f22ed..390cabe1f 100644 --- a/bp2build/apex_conversion_test.go +++ b/bp2build/apex_conversion_test.go @@ -1475,10 +1475,11 @@ apex_test { `, ExpectedBazelTargets: []string{ MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{ - "file_contexts": `"file_contexts_file"`, - "manifest": `"apex_manifest.json"`, - "testonly": `True`, - "tests": `[":cc_test_1"]`, + "file_contexts": `"file_contexts_file"`, + "base_apex_name": `"com.android.apogee"`, + "manifest": `"apex_manifest.json"`, + "testonly": `True`, + "tests": `[":cc_test_1"]`, }), }}) } diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go index 1b64055f7..e127fd542 100644 --- a/bp2build/build_conversion_test.go +++ b/bp2build/build_conversion_test.go @@ -21,6 +21,7 @@ import ( "android/soong/android" "android/soong/android/allowlists" + "android/soong/bazel" "android/soong/python" ) @@ -1931,3 +1932,17 @@ func TestGenerateConfigSetting(t *testing.T) { Description: "Generating API contribution Bazel targets for custom module", }) } + +// If values of all keys in an axis are equal to //conditions:default, drop the axis and print the common value +func TestPrettyPrintSelectMapEqualValues(t *testing.T) { + lla := bazel.LabelListAttribute{ + Value: bazel.LabelList{}, + } + libFooImplLabel := bazel.Label{ + Label: ":libfoo.impl", + } + lla.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidPlatform, bazel.MakeLabelList([]bazel.Label{libFooImplLabel})) + lla.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.MakeLabelList([]bazel.Label{libFooImplLabel})) + actual, _ := prettyPrintAttribute(lla, 0) + android.AssertStringEquals(t, "Print the common value if all keys in an axis have the same value", `[":libfoo.impl"]`, actual) +} diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go index 89eac8a00..6ec37031b 100644 --- a/bp2build/cc_binary_conversion_test.go +++ b/bp2build/cc_binary_conversion_test.go @@ -644,10 +644,7 @@ func TestCcBinaryWithInstructionSet(t *testing.T) { targets: []testBazelTarget{ {"cc_binary", "foo", AttrNameToString{ "features": `select({ - "//build/bazel/platforms/arch:arm": [ - "arm_isa_arm", - "-arm_isa_thumb", - ], + "//build/bazel/platforms/arch:arm": ["arm_isa_arm"], "//conditions:default": [], })`, "local_includes": `["."]`, diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 4ff525404..8c090d881 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -18,6 +18,7 @@ import ( "fmt" "testing" + "android/soong/aidl_library" "android/soong/android" "android/soong/cc" ) @@ -63,6 +64,7 @@ func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) + ctx.RegisterModuleType("aidl_library", aidl_library.AidlLibraryFactory) } func TestCcLibrarySimple(t *testing.T) { @@ -3042,7 +3044,8 @@ cc_library { }`, ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{ "implementation_dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:barlib"], + "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:barlib"], + "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:barlib"], "//conditions:default": [":barlib"], })`, "local_includes": `["."]`, @@ -3096,7 +3099,11 @@ cc_library { "//build/bazel/platforms/os:linux_glibc": [":quxlib"], "//build/bazel/platforms/os:linux_musl": [":quxlib"], "//build/bazel/platforms/os:windows": [":quxlib"], - "//build/bazel/rules/apex:android-in_apex": [ + "//build/bazel/rules/apex:foo": [ + "@api_surfaces//module-libapi/current:barlib", + "@api_surfaces//module-libapi/current:quxlib", + ], + "//build/bazel/rules/apex:system": [ "@api_surfaces//module-libapi/current:barlib", "@api_surfaces//module-libapi/current:quxlib", ], @@ -3214,10 +3221,7 @@ func TestCcLibraryWithInstructionSet(t *testing.T) { `, ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ "features": `select({ - "//build/bazel/platforms/arch:arm": [ - "arm_isa_arm", - "-arm_isa_thumb", - ], + "//build/bazel/platforms/arch:arm": ["arm_isa_arm"], "//conditions:default": [], })`, "local_includes": `["."]`, @@ -3310,6 +3314,46 @@ func TestCcLibraryArchVariantSuffix(t *testing.T) { }) } +func TestCcLibraryWithAidlLibrary(t *testing.T) { + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library with aidl_library", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: ` +aidl_library { + name: "A_aidl", + srcs: ["aidl/A.aidl"], + hdrs: ["aidl/Header.aidl"], + strip_import_prefix: "aidl", +} +cc_library { + name: "foo", + aidl: { + libs: ["A_aidl"], + } +}`, + ExpectedBazelTargets: []string{ + MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ + "srcs": `["aidl/A.aidl"]`, + "hdrs": `["aidl/Header.aidl"]`, + "strip_import_prefix": `"aidl"`, + "tags": `["apex_available=//apex_available:anyapex"]`, + }), + MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ + "deps": `[":A_aidl"]`, + }), + MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ + "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, + "local_includes": `["."]`, + }), + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ + "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, + "local_includes": `["."]`, + }), + }, + }) +} + func TestCcLibraryWithAidlSrcs(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with aidl srcs", @@ -3392,37 +3436,77 @@ cc_library { } func TestCcLibraryWithExportAidlHeaders(t *testing.T) { - runCcLibraryTestCase(t, Bp2buildTestCase{ - Description: "cc_library with export aidl headers", - ModuleTypeUnderTest: "cc_library", - ModuleTypeUnderTestFactory: cc.LibraryFactory, - Blueprint: ` -cc_library { - name: "foo", - srcs: [ - "Foo.aidl", - ], - aidl: { - export_aidl_headers: true, - } -}`, - ExpectedBazelTargets: []string{ - MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ - "srcs": `["Foo.aidl"]`, - }), - MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ - "deps": `[":foo_aidl_library"]`, - }), - MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ - "whole_archive_deps": `[":foo_cc_aidl_library"]`, - "local_includes": `["."]`, - }), - MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ - "whole_archive_deps": `[":foo_cc_aidl_library"]`, - "local_includes": `["."]`, - }), + t.Parallel() + + expectedBazelTargets := []string{ + MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ + "deps": `[":foo_aidl_library"]`, + }), + MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ + "whole_archive_deps": `[":foo_cc_aidl_library"]`, + "local_includes": `["."]`, + }), + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ + "whole_archive_deps": `[":foo_cc_aidl_library"]`, + "local_includes": `["."]`, + }), + } + testCases := []struct { + description string + bp string + expectedBazelTargets []string + }{ + { + description: "cc_library with aidl srcs and aidl.export_aidl_headers set", + bp: ` + cc_library { + name: "foo", + srcs: [ + "Foo.aidl", + ], + aidl: { + export_aidl_headers: true, + } + }`, + expectedBazelTargets: append( + expectedBazelTargets, + MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ + "srcs": `["Foo.aidl"]`, + })), }, - }) + { + description: "cc_library with aidl.libs and aidl.export_aidl_headers set", + bp: ` + aidl_library { + name: "foo_aidl_library", + srcs: ["Foo.aidl"], + } + cc_library { + name: "foo", + aidl: { + libs: ["foo_aidl_library"], + export_aidl_headers: true, + } + }`, + expectedBazelTargets: append( + expectedBazelTargets, + MakeBazelTargetNoRestrictions("aidl_library", "foo_aidl_library", AttrNameToString{ + "srcs": `["Foo.aidl"]`, + "tags": `["apex_available=//apex_available:anyapex"]`, + }), + ), + }, + } + + for _, testCase := range testCases { + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library with export aidl headers", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: testCase.bp, + ExpectedBazelTargets: testCase.expectedBazelTargets, + }) + } } func TestCcLibraryWithTargetApex(t *testing.T) { @@ -4139,44 +4223,34 @@ cc_library { name: "barlib", stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, bazel_module: { bp2build_available: false }, + apex_available: ["//apex_available:platform",], } cc_library { name: "bazlib", stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, bazel_module: { bp2build_available: false }, + apex_available: ["//apex_available:platform",], } cc_library { name: "foo", shared_libs: ["barlib", "bazlib"], export_shared_lib_headers: ["bazlib"], apex_available: [ - "apex_available:platform", + "//apex_available:platform", ], }`, ExpectedBazelTargets: []string{ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ - "implementation_dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:barlib"], - "//conditions:default": [":barlib"], - })`, - "dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:bazlib"], - "//conditions:default": [":bazlib"], - })`, - "local_includes": `["."]`, - "tags": `["apex_available=apex_available:platform"]`, + "implementation_dynamic_deps": `[":barlib"]`, + "dynamic_deps": `[":bazlib"]`, + "local_includes": `["."]`, + "tags": `["apex_available=//apex_available:platform"]`, }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ - "implementation_dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:barlib"], - "//conditions:default": [":barlib"], - })`, - "dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:bazlib"], - "//conditions:default": [":bazlib"], - })`, - "local_includes": `["."]`, - "tags": `["apex_available=apex_available:platform"]`, + "implementation_dynamic_deps": `[":barlib"]`, + "dynamic_deps": `[":bazlib"]`, + "local_includes": `["."]`, + "tags": `["apex_available=//apex_available:platform"]`, }), }, }) @@ -4473,11 +4547,12 @@ cc_library { ExpectedBazelTargets: []string{ MakeBazelTargetNoRestrictions( "config_setting", - "android-in_myapex", + "myapex", AttrNameToString{ "flag_values": `{ - "//build/bazel/rules/apex:apex_name": "myapex", + "//build/bazel/rules/apex:api_domain": "myapex", }`, + "constraint_values": `["//build/bazel/platforms/os:android"]`, }, ), }, diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index 47dff8a57..2ee9c99f9 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -609,7 +609,8 @@ cc_library_shared { ExpectedBazelTargets: []string{ MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ "implementation_dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"], + "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"], + "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"], "//conditions:default": [":a"], })`, "tags": `["apex_available=apex_b"]`, @@ -618,6 +619,64 @@ cc_library_shared { }) } +// Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib +func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared stubs", + ModuleTypeUnderTest: "cc_library_shared", + ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, + Blueprint: soongCcLibrarySharedPreamble + ` +cc_library_shared { + name: "libplatform_stable", + stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] }, + apex_available: ["//apex_available:platform"], + bazel_module: { bp2build_available: false }, + include_build_directory: false, +} +cc_library_shared { + name: "libapexfoo_stable", + stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] }, + apex_available: ["apexfoo"], + bazel_module: { bp2build_available: false }, + include_build_directory: false, +} +cc_library_shared { + name: "libutils", + shared_libs: ["libplatform_stable", "libapexfoo_stable",], + apex_available: ["//apex_available:platform", "apexfoo", "apexbar"], + include_build_directory: false, +} +`, + ExpectedBazelTargets: []string{ + MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{ + "implementation_dynamic_deps": `select({ + "//build/bazel/rules/apex:apexbar": [ + "@api_surfaces//module-libapi/current:libplatform_stable", + "@api_surfaces//module-libapi/current:libapexfoo_stable", + ], + "//build/bazel/rules/apex:apexfoo": [ + "@api_surfaces//module-libapi/current:libplatform_stable", + ":libapexfoo_stable", + ], + "//build/bazel/rules/apex:system": [ + "@api_surfaces//module-libapi/current:libplatform_stable", + "@api_surfaces//module-libapi/current:libapexfoo_stable", + ], + "//conditions:default": [ + ":libplatform_stable", + ":libapexfoo_stable", + ], + })`, + "tags": `[ + "apex_available=//apex_available:platform", + "apex_available=apexfoo", + "apex_available=apexbar", + ]`, + }), + }, + }) +} + func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) { runCcLibrarySharedTestCase(t, Bp2buildTestCase{ Description: "cc_library_shared stubs", @@ -641,7 +700,8 @@ cc_library_shared { ExpectedBazelTargets: []string{ MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ "implementation_dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"], + "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"], + "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"], "//conditions:default": [":a"], })`, "tags": `[ @@ -653,6 +713,34 @@ cc_library_shared { }) } +func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library depeends on impl for all configurations", + ModuleTypeUnderTest: "cc_library_shared", + ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, + Blueprint: soongCcLibrarySharedPreamble + ` +cc_library_shared { + name: "a", + stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, + bazel_module: { bp2build_available: false }, + apex_available: ["//apex_available:platform"], +} +cc_library_shared { + name: "b", + shared_libs: [":a"], + include_build_directory: false, + apex_available: ["//apex_available:platform"], +} +`, + ExpectedBazelTargets: []string{ + MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ + "implementation_dynamic_deps": `[":a"]`, + "tags": `["apex_available=//apex_available:platform"]`, + }), + }, + }) +} + func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) { runCcLibrarySharedTestCase(t, Bp2buildTestCase{ ModuleTypeUnderTest: "cc_library_shared", @@ -682,7 +770,7 @@ cc_library_shared { ExpectedBazelTargets: []string{ MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ "implementation_dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"], + "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"], "//conditions:default": [":a"], })`, "tags": `[ diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go index 948801486..2705aafe5 100644 --- a/bp2build/cc_library_static_conversion_test.go +++ b/bp2build/cc_library_static_conversion_test.go @@ -1504,6 +1504,7 @@ cc_library { versions: ["current"], }, bazel_module: { bp2build_available: false }, + apex_available: ["com.android.runtime"], } cc_library_static { @@ -1561,7 +1562,8 @@ cc_library_static { }), MakeBazelTarget("cc_library_static", "keep_with_stubs", AttrNameToString{ "implementation_dynamic_deps": `select({ - "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:libm"], + "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:libm"], + "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:libm"], "//conditions:default": [":libm"], })`, "system_dynamic_deps": `[]`, diff --git a/bp2build/configurability.go b/bp2build/configurability.go index 8e171031c..3d9f0a274 100644 --- a/bp2build/configurability.go +++ b/bp2build/configurability.go @@ -279,6 +279,10 @@ func prettyPrintSelectMap(selectMap map[string]reflect.Value, defaultValue *stri } if len(selects) == 0 { + // If there is a default value, and there are no selects for this axis, print that without any selects. + if val, exists := selectMap[bazel.ConditionsDefaultSelectKey]; exists { + return prettyPrint(val, indent, emitZeroValues) + } // No conditions (or all values are empty lists), so no need for a map. return "", nil } diff --git a/bp2build/package_conversion_test.go b/bp2build/package_conversion_test.go index 3704b2d7b..ce848e42d 100644 --- a/bp2build/package_conversion_test.go +++ b/bp2build/package_conversion_test.go @@ -15,9 +15,10 @@ package bp2build import ( + "testing" + "android/soong/android" "android/soong/genrule" - "testing" ) func registerDependentModules(ctx android.RegistrationContext) { @@ -29,6 +30,7 @@ func TestPackage(t *testing.T) { tests := []struct { description string modules string + fs map[string]string expected []ExpectedRuleTarget }{ { @@ -50,8 +52,50 @@ package { "package", "", AttrNameToString{ - "default_applicable_licenses": `[":my_license"]`, - "default_visibility": `["//visibility:public"]`, + "default_package_metadata": `[":my_license"]`, + "default_visibility": `["//visibility:public"]`, + }, + android.HostAndDeviceDefault, + }, + { + "android_license", + "my_license", + AttrNameToString{ + "license_kinds": `["SPDX-license-identifier-Apache-2.0"]`, + "license_text": `"NOTICE"`, + "visibility": `[":__subpackages__"]`, + }, + android.HostAndDeviceDefault, + }, + }, + }, + { + description: "package has METADATA file", + fs: map[string]string{ + "METADATA": ``, + }, + modules: ` +license { + name: "my_license", + visibility: [":__subpackages__"], + license_kinds: ["SPDX-license-identifier-Apache-2.0"], + license_text: ["NOTICE"], +} + +package { + default_applicable_licenses: ["my_license"], +} +`, + expected: []ExpectedRuleTarget{ + { + "package", + "", + AttrNameToString{ + "default_package_metadata": `[ + ":my_license", + ":default_metadata_file", + ]`, + "default_visibility": `["//visibility:public"]`, }, android.HostAndDeviceDefault, }, @@ -65,6 +109,15 @@ package { }, android.HostAndDeviceDefault, }, + { + "filegroup", + "default_metadata_file", + AttrNameToString{ + "applicable_licenses": `[]`, + "srcs": `["METADATA"]`, + }, + android.HostAndDeviceDefault, + }, }, }, } @@ -80,6 +133,7 @@ package { ModuleTypeUnderTestFactory: android.PackageFactory, Blueprint: test.modules, ExpectedBazelTargets: expected, + Filesystem: test.fs, }) } } diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go index ba42f34df..ad07f6833 100644 --- a/bp2build/soong_config_module_type_conversion_test.go +++ b/bp2build/soong_config_module_type_conversion_test.go @@ -1251,3 +1251,111 @@ cc_binary { srcs = ["main.cc"], )`}}) } + +func TestSoongConfigModuleType_CombinedWithArchVariantProperties(t *testing.T) { + bp := ` +soong_config_bool_variable { + name: "my_bool_variable", +} + +soong_config_string_variable { + name: "my_string_variable", + values: [ + "value1", + "value2", + ], +} + +soong_config_module_type { + name: "special_build_cc_defaults", + module_type: "cc_defaults", + config_namespace: "my_namespace", + bool_variables: ["my_bool_variable"], + variables: ["my_string_variable"], + properties: ["target.android.cflags", "cflags"], +} + +special_build_cc_defaults { + name: "sample_cc_defaults", + target: { + android: { + cflags: ["-DFOO"], + }, + }, + soong_config_variables: { + my_bool_variable: { + target: { + android: { + cflags: ["-DBAR"], + }, + }, + conditions_default: { + target: { + android: { + cflags: ["-DBAZ"], + }, + }, + }, + }, + my_string_variable: { + value1: { + cflags: ["-DVALUE1_NOT_ANDROID"], + target: { + android: { + cflags: ["-DVALUE1"], + }, + }, + }, + value2: { + target: { + android: { + cflags: ["-DVALUE2"], + }, + }, + }, + conditions_default: { + target: { + android: { + cflags: ["-DSTRING_VAR_CONDITIONS_DEFAULT"], + }, + }, + }, + }, + }, +} + +cc_binary { + name: "my_binary", + srcs: ["main.cc"], + defaults: ["sample_cc_defaults"], +}` + + runSoongConfigModuleTypeTest(t, Bp2buildTestCase{ + Description: "soong config variables - generates selects for library_linking_strategy", + ModuleTypeUnderTest: "cc_binary", + ModuleTypeUnderTestFactory: cc.BinaryFactory, + Blueprint: bp, + Filesystem: map[string]string{}, + ExpectedBazelTargets: []string{`cc_binary( + name = "my_binary", + copts = select({ + "//build/bazel/platforms/os:android": ["-DFOO"], + "//conditions:default": [], + }) + select({ + "//build/bazel/product_variables:my_namespace__my_bool_variable__android": ["-DBAR"], + "//build/bazel/product_variables:my_namespace__my_bool_variable__conditions_default__android": ["-DBAZ"], + "//conditions:default": [], + }) + select({ + "//build/bazel/product_variables:my_namespace__my_string_variable__value1": ["-DVALUE1_NOT_ANDROID"], + "//conditions:default": [], + }) + select({ + "//build/bazel/product_variables:my_namespace__my_string_variable__conditions_default__android": ["-DSTRING_VAR_CONDITIONS_DEFAULT"], + "//build/bazel/product_variables:my_namespace__my_string_variable__value1__android": ["-DVALUE1"], + "//build/bazel/product_variables:my_namespace__my_string_variable__value2__android": ["-DVALUE2"], + "//conditions:default": [], + }), + local_includes = ["."], + srcs = ["main.cc"], + target_compatible_with = ["//build/bazel/platforms/os:android"], +)`}}) +} diff --git a/cc/Android.bp b/cc/Android.bp index be2cc5a34..f49dc1a9e 100644 --- a/cc/Android.bp +++ b/cc/Android.bp @@ -9,6 +9,7 @@ bootstrap_go_package { "blueprint", "blueprint-pathtools", "soong", + "soong-aidl-library", "soong-android", "soong-bazel", "soong-cc-config", @@ -22,7 +23,6 @@ bootstrap_go_package { srcs: [ "afdo.go", "fdo_profile.go", - "androidmk.go", "api_level.go", "bp2build.go", diff --git a/cc/bp2build.go b/cc/bp2build.go index 55bca1a17..1980ab971 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -500,7 +500,7 @@ func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversi instructionSet := proptools.StringDefault(props.Instruction_set, "") if instructionSet == "arm" { - ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm", "-arm_isa_thumb"}) + ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm"}) } else if instructionSet != "" && instructionSet != "thumb" { ctx.ModuleErrorf("Unknown value for instruction_set: %s", instructionSet) } @@ -545,7 +545,7 @@ func (ca *compilerAttributes) convertProductVariables(ctx android.BazelConversio if !ok { ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName)) } - newFlags, _ := bazel.TryVariableSubstitutions(flags, productConfigProp.Name) + newFlags, _ := bazel.TryVariableSubstitutions(flags, productConfigProp.Name()) attr.SetSelectValue(productConfigProp.ConfigurationAxis(), productConfigProp.SelectKey(), newFlags) } } @@ -742,6 +742,8 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) compilerAttrs := compilerAttributes{} linkerAttrs := linkerAttributes{} + var aidlLibs bazel.LabelList + // Iterate through these axes in a deterministic order. This is required // because processing certain dependencies may result in concatenating // elements along other axes. (For example, processing NoConfig may result @@ -762,6 +764,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) compilerAttrs.yaccGenPositionHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_position_hh) } (&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, cfg, baseCompilerProps) + aidlLibs.Append(android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Aidl.Libs)) } var exportHdrs []string @@ -834,7 +837,14 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) (&linkerAttrs).wholeArchiveDeps.Add(protoDep.wholeStaticLib) (&linkerAttrs).implementationWholeArchiveDeps.Add(protoDep.implementationWholeStaticLib) - aidlDep := bp2buildCcAidlLibrary(ctx, module, compilerAttrs.aidlSrcs, linkerAttrs) + aidlDep := bp2buildCcAidlLibrary( + ctx, module, + compilerAttrs.aidlSrcs, + bazel.LabelListAttribute{ + Value: aidlLibs, + }, + linkerAttrs, + ) if aidlDep != nil { if lib, ok := module.linker.(*libraryDecorator); ok { if proptools.Bool(lib.Properties.Aidl.Export_aidl_headers) { @@ -979,11 +989,15 @@ func bp2buildFdoProfile( func bp2buildCcAidlLibrary( ctx android.Bp2buildMutatorContext, m *Module, - aidlLabelList bazel.LabelListAttribute, + aidlSrcs bazel.LabelListAttribute, + aidlLibs bazel.LabelListAttribute, linkerAttrs linkerAttributes, ) *bazel.LabelAttribute { - if !aidlLabelList.IsEmpty() { - aidlLibs, aidlSrcs := aidlLabelList.Partition(func(src bazel.Label) bool { + var aidlLibsFromSrcs, aidlFiles bazel.LabelListAttribute + apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module()) + + if !aidlSrcs.IsEmpty() { + aidlLibsFromSrcs, aidlFiles = aidlSrcs.Partition(func(src bazel.Label) bool { if fg, ok := android.ToFileGroupAsLibrary(ctx, src.OriginalModuleName); ok && fg.ShouldConvertToAidlLibrary(ctx) { return true @@ -991,55 +1005,59 @@ func bp2buildCcAidlLibrary( return false }) - apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module()) - sdkAttrs := bp2BuildParseSdkAttributes(m) - - if !aidlSrcs.IsEmpty() { + if !aidlFiles.IsEmpty() { aidlLibName := m.Name() + "_aidl_library" ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "aidl_library", Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl", }, - android.CommonAttributes{Name: aidlLibName}, - &aidlLibraryAttributes{ - Srcs: aidlSrcs, + android.CommonAttributes{ + Name: aidlLibName, Tags: apexAvailableTags, }, + &aidlLibraryAttributes{ + Srcs: aidlFiles, + }, ) - aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) + aidlLibsFromSrcs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) } + } - if !aidlLibs.IsEmpty() { - ccAidlLibrarylabel := m.Name() + "_cc_aidl_library" - // Since parent cc_library already has these dependencies, we can add them as implementation - // deps so that they don't re-export - implementationDeps := linkerAttrs.deps.Clone() - implementationDeps.Append(linkerAttrs.implementationDeps) - implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone() - implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps) + allAidlLibs := aidlLibs.Clone() + allAidlLibs.Append(aidlLibsFromSrcs) - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "cc_aidl_library", - Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl", - }, - android.CommonAttributes{Name: ccAidlLibrarylabel}, - &ccAidlLibraryAttributes{ - Deps: aidlLibs, - Implementation_deps: *implementationDeps, - Implementation_dynamic_deps: *implementationDynamicDeps, - Tags: apexAvailableTags, - sdkAttributes: sdkAttrs, - }, - ) - label := &bazel.LabelAttribute{ - Value: &bazel.Label{ - Label: ":" + ccAidlLibrarylabel, - }, - } - return label + if !allAidlLibs.IsEmpty() { + ccAidlLibrarylabel := m.Name() + "_cc_aidl_library" + // Since parent cc_library already has these dependencies, we can add them as implementation + // deps so that they don't re-export + implementationDeps := linkerAttrs.deps.Clone() + implementationDeps.Append(linkerAttrs.implementationDeps) + implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone() + implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps) + + sdkAttrs := bp2BuildParseSdkAttributes(m) + + ctx.CreateBazelTargetModule( + bazel.BazelTargetModuleProperties{ + Rule_class: "cc_aidl_library", + Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl", + }, + android.CommonAttributes{Name: ccAidlLibrarylabel}, + &ccAidlLibraryAttributes{ + Deps: *allAidlLibs, + Implementation_deps: *implementationDeps, + Implementation_dynamic_deps: *implementationDynamicDeps, + Tags: apexAvailableTags, + sdkAttributes: sdkAttrs, + }, + ) + label := &bazel.LabelAttribute{ + Value: &bazel.Label{ + Label: ":" + ccAidlLibrarylabel, + }, } + return label } return nil @@ -1261,16 +1279,34 @@ func availableToSameApexes(a, b []string) bool { } var ( - apexConfigSettingKey = android.NewOnceKey("apexConfigSetting") - apexConfigSettingLock sync.Mutex + apiDomainConfigSettingKey = android.NewOnceKey("apiDomainConfigSettingKey") + apiDomainConfigSettingLock sync.Mutex ) -func getApexConfigSettingMap(config android.Config) *map[string]bool { - return config.Once(apexConfigSettingKey, func() interface{} { +func getApiDomainConfigSettingMap(config android.Config) *map[string]bool { + return config.Once(apiDomainConfigSettingKey, func() interface{} { return &map[string]bool{} }).(*map[string]bool) } +var ( + testApexNameToApiDomain = map[string]string{ + "test_broken_com.android.art": "com.android.art", + } +) + +// GetApiDomain returns the canonical name of the apex. This is synonymous to the apex_name definition. +// https://cs.android.com/android/_/android/platform/build/soong/+/e3f0281b8897da1fe23b2f4f3a05f1dc87bcc902:apex/prebuilt.go;l=81-83;drc=2dc7244af985a6ad701b22f1271e606cabba527f;bpv=1;bpt=0 +// For test apexes, it uses a naming convention heuristic to determine the api domain. +// TODO (b/281548611): Move this build/soong/android +func GetApiDomain(apexName string) string { + if apiDomain, exists := testApexNameToApiDomain[apexName]; exists { + return apiDomain + } + // Remove `test_` prefix + return strings.TrimPrefix(apexName, "test_") +} + // Create a config setting for this apex in build/bazel/rules/apex // The use case for this is stub/impl selection in cc libraries // Long term, these config_setting(s) should be colocated with the respective apex definitions. @@ -1282,23 +1318,32 @@ func createInApexConfigSetting(ctx android.TopDownMutatorContext, apexName strin // These correspond to android-non_apex and android-in_apex return } - apexConfigSettingLock.Lock() - defer apexConfigSettingLock.Unlock() + apiDomainConfigSettingLock.Lock() + defer apiDomainConfigSettingLock.Unlock() // Return if a config_setting has already been created - acsm := getApexConfigSettingMap(ctx.Config()) - if _, exists := (*acsm)[apexName]; exists { + apiDomain := GetApiDomain(apexName) + acsm := getApiDomainConfigSettingMap(ctx.Config()) + if _, exists := (*acsm)[apiDomain]; exists { return } - (*acsm)[apexName] = true + (*acsm)[apiDomain] = true csa := bazel.ConfigSettingAttributes{ Flag_values: bazel.StringMapAttribute{ - "//build/bazel/rules/apex:apex_name": apexName, + "//build/bazel/rules/apex:api_domain": apiDomain, }, + // Constraint this to android + Constraint_values: bazel.MakeLabelListAttribute( + bazel.MakeLabelList( + []bazel.Label{ + bazel.Label{Label: "//build/bazel/platforms/os:android"}, + }, + ), + ), } ca := android.CommonAttributes{ - Name: "android-in_" + apexName, + Name: apiDomain, } ctx.CreateBazelConfigSetting( csa, @@ -1309,66 +1354,111 @@ func createInApexConfigSetting(ctx android.TopDownMutatorContext, apexName strin func inApexConfigSetting(apexAvailable string) string { if apexAvailable == android.AvailableToPlatform { - return bazel.AndroidAndNonApex + return bazel.AndroidPlatform } if apexAvailable == android.AvailableToAnyApex { return bazel.AndroidAndInApex } - return "//build/bazel/rules/apex:android-in_" + apexAvailable + apiDomain := GetApiDomain(apexAvailable) + return "//build/bazel/rules/apex:" + apiDomain +} + +// Inputs to stub vs impl selection. +type stubSelectionInfo struct { + // Label of the implementation library (e.g. //bionic/libc:libc) + impl bazel.Label + // Axis containing the implementation library + axis bazel.ConfigurationAxis + // Axis key containing the implementation library + config string + // API domain of the apex + // For test apexes (test_com.android.foo), this will be the source apex (com.android.foo) + apiDomain string + // List of dep labels + dynamicDeps *bazel.LabelListAttribute + // Boolean value for determining if the dep is in the same api domain + // If false, the label will be rewritten to to the stub label + sameApiDomain bool +} + +func useStubOrImplInApexWithName(ssi stubSelectionInfo) { + lib := ssi.impl + if !ssi.sameApiDomain { + lib = bazel.Label{ + Label: apiSurfaceModuleLibCurrentPackage + strings.TrimPrefix(lib.OriginalModuleName, ":"), + } + } + // Create a select statement specific to this apex + inApexSelectValue := ssi.dynamicDeps.SelectValue(bazel.OsAndInApexAxis, inApexConfigSetting(ssi.apiDomain)) + (&inApexSelectValue).Append(bazel.MakeLabelList([]bazel.Label{lib})) + ssi.dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, inApexConfigSetting(ssi.apiDomain), bazel.FirstUniqueBazelLabelList(inApexSelectValue)) + // Delete the library from the common config for this apex + implDynamicDeps := ssi.dynamicDeps.SelectValue(ssi.axis, ssi.config) + implDynamicDeps = bazel.SubtractBazelLabelList(implDynamicDeps, bazel.MakeLabelList([]bazel.Label{ssi.impl})) + ssi.dynamicDeps.SetSelectValue(ssi.axis, ssi.config, implDynamicDeps) + if ssi.axis == bazel.NoConfigAxis { + // Set defaults. Defaults (i.e. host) should use impl and not stubs. + defaultSelectValue := ssi.dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey) + (&defaultSelectValue).Append(bazel.MakeLabelList([]bazel.Label{ssi.impl})) + ssi.dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.FirstUniqueBazelLabelList(defaultSelectValue)) + } } func setStubsForDynamicDeps(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, config string, apexAvailable []string, dynamicLibs bazel.LabelList, dynamicDeps *bazel.LabelListAttribute, ind int, buildNonApexWithStubs bool) { - depsWithStubs := []bazel.Label{} - for _, l := range dynamicLibs.Includes { - dep, _ := ctx.ModuleFromName(l.OriginalModuleName) - if d, ok := dep.(*Module); ok && d.HasStubsVariants() { - depApexAvailable := d.ApexAvailable() - if !availableToSameApexes(apexAvailable, depApexAvailable) { - depsWithStubs = append(depsWithStubs, l) - } - } - } - if len(depsWithStubs) > 0 { - implDynamicDeps := bazel.SubtractBazelLabelList(dynamicLibs, bazel.MakeLabelList(depsWithStubs)) - dynamicDeps.SetSelectValue(axis, config, implDynamicDeps) - - stubLibLabels := []bazel.Label{} - for _, l := range depsWithStubs { - stubLabelInApiSurfaces := bazel.Label{ - Label: apiSurfaceModuleLibCurrentPackage + strings.TrimPrefix(l.OriginalModuleName, ":"), - } - stubLibLabels = append(stubLibLabels, stubLabelInApiSurfaces) - } - inApexSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex) - nonApexSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex) - defaultSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey) - nonApexDeps := depsWithStubs - if buildNonApexWithStubs { - nonApexDeps = stubLibLabels - } - if axis == bazel.NoConfigAxis { - (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels)) - (&nonApexSelectValue).Append(bazel.MakeLabelList(nonApexDeps)) - (&defaultSelectValue).Append(bazel.MakeLabelList(depsWithStubs)) - dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue)) - dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue)) - dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.FirstUniqueBazelLabelList(defaultSelectValue)) - } else if config == bazel.OsAndroid { - (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels)) - (&nonApexSelectValue).Append(bazel.MakeLabelList(nonApexDeps)) - dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue)) - dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue)) - } - } - // Create a config_setting for each apex_available. // This will be used to select impl of a dep if dep is available to the same apex. for _, aa := range apexAvailable { createInApexConfigSetting(ctx.(android.TopDownMutatorContext), aa) } + apiDomainForSelects := []string{} + for _, apex := range apexAvailable { + apiDomainForSelects = append(apiDomainForSelects, GetApiDomain(apex)) + } + // Always emit a select statement for the platform variant. + // This ensures that b build //foo --config=android works + // Soong always creates a platform variant even when the library might not be available to platform. + if !android.InList(android.AvailableToPlatform, apiDomainForSelects) { + apiDomainForSelects = append(apiDomainForSelects, android.AvailableToPlatform) + } + apiDomainForSelects = android.SortedUniqueStrings(apiDomainForSelects) + + // Create a select for each apex this library could be included in. + for _, l := range dynamicLibs.Includes { + dep, _ := ctx.ModuleFromName(l.OriginalModuleName) + if c, ok := dep.(*Module); !ok || !c.HasStubsVariants() { + continue + } + // TODO (b/280339069): Decrease the verbosity of the generated BUILD files + for _, apiDomain := range apiDomainForSelects { + var sameApiDomain bool + if apiDomain == android.AvailableToPlatform { + // Platform variants in Soong use equality of apex_available for stub/impl selection. + // https://cs.android.com/android/_/android/platform/build/soong/+/316b0158fe57ee7764235923e7c6f3d530da39c6:cc/cc.go;l=3393-3404;drc=176271a426496fa2688efe2b40d5c74340c63375;bpv=1;bpt=0 + // One of the factors behind this design choice is cc_test + // Tests only have a platform variant, and using equality of apex_available ensures + // that tests of an apex library gets its implementation and not stubs. + // TODO (b/280343104): Discuss if we can drop this special handling for platform variants. + sameApiDomain = availableToSameApexes(apexAvailable, dep.(*Module).ApexAvailable()) + if linkable, ok := ctx.Module().(LinkableInterface); ok && linkable.Bootstrap() { + sameApiDomain = true + } + } else { + sameApiDomain = android.InList(apiDomain, dep.(*Module).ApexAvailable()) + } + ssi := stubSelectionInfo{ + impl: l, + axis: axis, + config: config, + apiDomain: apiDomain, + dynamicDeps: dynamicDeps, + sameApiDomain: sameApiDomain, + } + useStubOrImplInApexWithName(ssi) + } + } } func (la *linkerAttributes) convertStripProps(ctx android.BazelConversionPathContext, module *Module) { @@ -1417,7 +1507,7 @@ func (la *linkerAttributes) convertProductVariables(ctx android.BazelConversionP // Collect all the configurations that an include or exclude property exists for. // We want to iterate all configurations rather than either the include or exclude because, for a // particular configuration, we may have either only an include or an exclude to handle. - productConfigProps := make(map[android.ProductConfigProperty]bool, len(props)+len(excludeProps)) + productConfigProps := make(map[android.ProductConfigOrSoongConfigProperty]bool, len(props)+len(excludeProps)) for p := range props { productConfigProps[p] = true } @@ -1463,7 +1553,6 @@ func (la *linkerAttributes) finalize(ctx android.BazelConversionPathContext) { la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove) la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, toRemove) - la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, toRemove) stubsToRemove := make([]bazel.Label, 0, len(la.usedSystemDynamicDepAsDynamicDep)) for _, lib := range toRemove.Includes { stubLabelInApiSurfaces := bazel.Label{ @@ -1471,7 +1560,12 @@ func (la *linkerAttributes) finalize(ctx android.BazelConversionPathContext) { } stubsToRemove = append(stubsToRemove, stubLabelInApiSurfaces) } - la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.MakeLabelList(stubsToRemove)) + // system libraries (e.g. libc, libm, libdl) belong the com.android.runtime api domain + // dedupe the stubs of these libraries from the other api domains (platform, other_apexes...) + for _, aa := range ctx.Module().(*Module).ApexAvailable() { + la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, inApexConfigSetting(aa), bazel.MakeLabelList(stubsToRemove)) + } + la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidPlatform, bazel.MakeLabelList(stubsToRemove)) } la.deps.ResolveExcludes() diff --git a/cc/builder.go b/cc/builder.go index fef00d4d5..f5e0dcca5 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -125,6 +125,14 @@ var ( }, "objcopyCmd", "prefix") + // Rule to run objcopy --remove-section=.llvm_addrsig on a partially linked object + noAddrSig = pctx.AndroidStaticRule("noAddrSig", + blueprint.RuleParams{ + Command: "rm -f ${out} && $objcopyCmd --remove-section=.llvm_addrsig ${in} ${out}", + CommandDeps: []string{"$objcopyCmd"}, + }, + "objcopyCmd") + _ = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh") _ = pctx.SourcePathVariable("xzCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/xz") _ = pctx.SourcePathVariable("createMiniDebugInfo", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/create_minidebuginfo") @@ -1008,6 +1016,21 @@ func transformBinaryPrefixSymbols(ctx android.ModuleContext, prefix string, inpu }) } +// Generate a rule for running objcopy --remove-section=.llvm_addrsig on a partially linked object +func transformObjectNoAddrSig(ctx android.ModuleContext, inputFile android.Path, outputFile android.WritablePath) { + objcopyCmd := "${config.ClangBin}/llvm-objcopy" + + ctx.Build(pctx, android.BuildParams{ + Rule: noAddrSig, + Description: "remove addrsig " + outputFile.Base(), + Output: outputFile, + Input: inputFile, + Args: map[string]string{ + "objcopyCmd": objcopyCmd, + }, + }) +} + // Registers a build statement to invoke `strip` (to discard symbols and data from object files). func transformStrip(ctx android.ModuleContext, inputFile android.Path, outputFile android.WritablePath, flags StripFlags) { @@ -27,6 +27,7 @@ import ( "github.com/google/blueprint" "github.com/google/blueprint/proptools" + "android/soong/aidl_library" "android/soong/android" "android/soong/bazel/cquery" "android/soong/cc/config" @@ -110,6 +111,9 @@ type Deps struct { // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py. SystemSharedLibs []string + // Used by DepMutator to pass aidl_library modules to aidl compiler + AidlLibs []string + // If true, statically link the unwinder into native libraries/binaries. StaticUnwinderIfLegacy bool @@ -182,6 +186,9 @@ type PathDeps struct { // For Darwin builds, the path to the second architecture's output that should // be combined with this architectures's output into a FAT MachO file. DarwinSecondArchOutput android.OptionalPath + + // Paths to direct srcs and transitive include dirs from direct aidl_library deps + AidlLibraryInfos []aidl_library.AidlLibraryInfo } // LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module @@ -765,6 +772,7 @@ var ( stubImplDepTag = dependencyTag{name: "stub_impl"} JniFuzzLibTag = dependencyTag{name: "jni_fuzz_lib_tag"} FdoProfileTag = dependencyTag{name: "fdo_profile"} + aidlLibraryTag = dependencyTag{name: "aidl_library"} ) func IsSharedDepTag(depTag blueprint.DependencyTag) bool { @@ -1086,7 +1094,7 @@ func (c *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule { panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", c.BaseModuleName())) } -func (c *Module) FuzzSharedLibraries() android.Paths { +func (c *Module) FuzzSharedLibraries() android.RuleBuilderInstalls { if fuzzer, ok := c.compiler.(*fuzzBinary); ok { return fuzzer.sharedLibraries } @@ -2751,6 +2759,14 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { } } + if len(deps.AidlLibs) > 0 { + actx.AddDependency( + c, + aidlLibraryTag, + deps.AidlLibs..., + ) + } + updateImportedLibraryDependency(ctx) } @@ -3055,6 +3071,17 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { return } + if depTag == aidlLibraryTag { + if ctx.OtherModuleHasProvider(dep, aidl_library.AidlLibraryProvider) { + depPaths.AidlLibraryInfos = append( + depPaths.AidlLibraryInfos, + ctx.OtherModuleProvider( + dep, + aidl_library.AidlLibraryProvider).(aidl_library.AidlLibraryInfo), + ) + } + } + ccDep, ok := dep.(LinkableInterface) if !ok { diff --git a/cc/cc_test.go b/cc/cc_test.go index f9e661ff2..d3d55e8ee 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -24,6 +24,7 @@ import ( "strings" "testing" + "android/soong/aidl_library" "android/soong/android" "android/soong/bazel/cquery" ) @@ -4418,9 +4419,65 @@ func TestStubsLibReexportsHeaders(t *testing.T) { } } +func TestAidlLibraryWithHeader(t *testing.T) { + t.Parallel() + ctx := android.GroupFixturePreparers( + prepareForCcTest, + aidl_library.PrepareForTestWithAidlLibrary, + android.MockFS{ + "package_bar/Android.bp": []byte(` + aidl_library { + name: "bar", + srcs: ["x/y/Bar.aidl"], + strip_import_prefix: "x", + } + `)}.AddToFixture(), + android.MockFS{ + "package_foo/Android.bp": []byte(` + aidl_library { + name: "foo", + srcs: ["a/b/Foo.aidl"], + strip_import_prefix: "a", + deps: ["bar"], + } + cc_library { + name: "libfoo", + aidl: { + libs: ["foo"], + } + } + `), + }.AddToFixture(), + ).RunTest(t).TestContext + + libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") + manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) + aidlCommand := manifest.Commands[0].GetCommand() + + expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x" + if !strings.Contains(aidlCommand, expectedAidlFlags) { + t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlags) + } + + outputs := strings.Join(libfoo.AllOutputs(), " ") + + android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/BpFoo.h") + android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/BnFoo.h") + android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/Foo.h") + android.AssertStringDoesContain(t, "aidl-generated cpp", outputs, "b/Foo.cpp") + // Confirm that the aidl header doesn't get compiled to cpp and h files + android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/BpBar.h") + android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/BnBar.h") + android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/Bar.h") + android.AssertStringDoesNotContain(t, "aidl-generated cpp", outputs, "y/Bar.cpp") +} + func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) { t.Parallel() - ctx := testCc(t, ` + ctx := android.GroupFixturePreparers( + prepareForCcTest, + aidl_library.PrepareForTestWithAidlLibrary, + ).RunTestWithBp(t, ` cc_library { name: "libfoo", srcs: ["a/Foo.aidl"], @@ -4705,7 +4762,15 @@ func TestIncludeDirsExporting(t *testing.T) { }) t.Run("ensure only aidl headers are exported", func(t *testing.T) { - ctx := testCc(t, genRuleModules+` + ctx := android.GroupFixturePreparers( + prepareForCcTest, + aidl_library.PrepareForTestWithAidlLibrary, + ).RunTestWithBp(t, ` + aidl_library { + name: "libfoo_aidl", + srcs: ["x/y/Bar.aidl"], + strip_import_prefix: "x", + } cc_library_shared { name: "libfoo", srcs: [ @@ -4714,10 +4779,11 @@ func TestIncludeDirsExporting(t *testing.T) { "a.proto", ], aidl: { + libs: ["libfoo_aidl"], export_aidl_headers: true, } } - `) + `).TestContext foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() checkIncludeDirs(t, ctx, foo, expectedIncludeDirs(` @@ -4728,11 +4794,17 @@ func TestIncludeDirsExporting(t *testing.T) { .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h + .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/Bar.h + .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BnBar.h + .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BpBar.h `), expectedOrderOnlyDeps(` .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h + .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/Bar.h + .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BnBar.h + .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BpBar.h `), ) }) diff --git a/cc/compiler.go b/cc/compiler.go index 88985b6f9..5da745e02 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -120,6 +120,9 @@ type BaseCompilerProperties struct { Lex *LexProperties Aidl struct { + // List of aidl_library modules + Libs []string + // list of directories that will be added to the aidl include paths. Include_dirs []string @@ -272,6 +275,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...) deps.GeneratedSources = removeListFromList(deps.GeneratedSources, compiler.Properties.Exclude_generated_sources) deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...) + deps.AidlLibs = append(deps.AidlLibs, compiler.Properties.Aidl.Libs...) android.ProtoDeps(ctx, &compiler.Proto) if compiler.hasSrcExt(".proto") { @@ -561,7 +565,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps "-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String()) } - if compiler.hasSrcExt(".aidl") { + if compiler.hasAidl(deps) { flags.aidlFlags = append(flags.aidlFlags, compiler.Properties.Aidl.Flags...) if len(compiler.Properties.Aidl.Local_include_dirs) > 0 { localAidlIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Aidl.Local_include_dirs) @@ -572,6 +576,14 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs)) } + var rootAidlIncludeDirs android.Paths + for _, aidlLibraryInfo := range deps.AidlLibraryInfos { + rootAidlIncludeDirs = append(rootAidlIncludeDirs, aidlLibraryInfo.IncludeDirs.ToList()...) + } + if len(rootAidlIncludeDirs) > 0 { + flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs)) + } + if proptools.BoolDefault(compiler.Properties.Aidl.Generate_traces, true) { flags.aidlFlags = append(flags.aidlFlags, "-t") } @@ -660,6 +672,10 @@ func ndkPathDeps(ctx ModuleContext) android.Paths { return nil } +func (compiler *baseCompiler) hasAidl(deps PathDeps) bool { + return len(deps.AidlLibraryInfos) > 0 || compiler.hasSrcExt(".aidl") +} + func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { pathDeps := deps.GeneratedDeps pathDeps = append(pathDeps, ndkPathDeps(ctx)...) @@ -668,7 +684,7 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD srcs := append(android.Paths(nil), compiler.srcsBeforeGen...) - srcs, genDeps, info := genSources(ctx, srcs, buildFlags) + srcs, genDeps, info := genSources(ctx, deps.AidlLibraryInfos, srcs, buildFlags) pathDeps = append(pathDeps, genDeps...) compiler.pathDeps = pathDeps diff --git a/cc/config/global.go b/cc/config/global.go index 20298dd5b..e5ce48ebe 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -111,9 +111,6 @@ var ( // Turn off FMA which got enabled by default in clang-r445002 (http://b/218805949) "-ffp-contract=off", - - // Turn off stack protector check for noreturn calls. (http://b/264965700) - "-mllvm -disable-check-noreturn-call", } commonGlobalConlyflags = []string{} @@ -150,9 +147,6 @@ var ( commonGlobalLldflags = []string{ "-fuse-ld=lld", "-Wl,--icf=safe", - - // Turn off stack protector check for noreturn calls. (http://b/264965700) - "-Wl,-mllvm,-disable-check-noreturn-call", } deviceGlobalCppflags = []string{ @@ -311,7 +305,7 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r487747b" + ClangDefaultVersion = "clang-r487747c" ClangDefaultShortVersion = "17" // Directories with warnings from Android.bp files. diff --git a/cc/fuzz.go b/cc/fuzz.go index 7aa8b91c7..dfefc11f2 100644 --- a/cc/fuzz.go +++ b/cc/fuzz.go @@ -103,7 +103,7 @@ type fuzzBinary struct { *baseCompiler fuzzPackagedModule fuzz.FuzzPackagedModule installedSharedDeps []string - sharedLibraries android.Paths + sharedLibraries android.RuleBuilderInstalls } func (fuzz *fuzzBinary) fuzzBinary() bool { @@ -213,19 +213,19 @@ func IsValidSharedDependency(dependency android.Module) bool { } func SharedLibraryInstallLocation( - libraryPath android.Path, isHost bool, fuzzDir string, archString string) string { + libraryBase string, isHost bool, fuzzDir string, archString string) string { installLocation := "$(PRODUCT_OUT)/data" if isHost { installLocation = "$(HOST_OUT)" } installLocation = filepath.Join( - installLocation, fuzzDir, archString, "lib", libraryPath.Base()) + installLocation, fuzzDir, archString, "lib", libraryBase) return installLocation } // Get the device-only shared library symbols install directory. -func SharedLibrarySymbolsInstallLocation(libraryPath android.Path, fuzzDir string, archString string) string { - return filepath.Join("$(PRODUCT_OUT)/symbols/data/", fuzzDir, archString, "/lib/", libraryPath.Base()) +func SharedLibrarySymbolsInstallLocation(libraryBase string, fuzzDir string, archString string) string { + return filepath.Join("$(PRODUCT_OUT)/symbols/data/", fuzzDir, archString, "/lib/", libraryBase) } func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) { @@ -242,15 +242,16 @@ func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) { // Grab the list of required shared libraries. fuzzBin.sharedLibraries, _ = CollectAllSharedDependencies(ctx) - for _, lib := range fuzzBin.sharedLibraries { + for _, ruleBuilderInstall := range fuzzBin.sharedLibraries { + install := ruleBuilderInstall.To fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps, SharedLibraryInstallLocation( - lib, ctx.Host(), installBase, ctx.Arch().ArchType.String())) + install, ctx.Host(), installBase, ctx.Arch().ArchType.String())) // Also add the dependency on the shared library symbols dir. if !ctx.Host() { fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps, - SharedLibrarySymbolsInstallLocation(lib, installBase, ctx.Arch().ArchType.String())) + SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String())) } } } @@ -422,7 +423,7 @@ func (s *ccRustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) files = append(files, GetSharedLibsToZip(ccModule.FuzzSharedLibraries(), ccModule, &s.FuzzPackager, archString, sharedLibsInstallDirPrefix, &sharedLibraryInstalled)...) // The executable. - files = append(files, fuzz.FileToZip{android.OutputFileForModule(ctx, ccModule, "unstripped"), ""}) + files = append(files, fuzz.FileToZip{SourceFilePath: android.OutputFileForModule(ctx, ccModule, "unstripped")}) archDirs[archOs], ok = s.BuildZipFile(ctx, module, fpm, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs) if !ok { @@ -453,19 +454,25 @@ func (s *ccRustFuzzPackager) MakeVars(ctx android.MakeVarsContext) { // GetSharedLibsToZip finds and marks all the transiently-dependent shared libraries for // packaging. -func GetSharedLibsToZip(sharedLibraries android.Paths, module LinkableInterface, s *fuzz.FuzzPackager, archString string, destinationPathPrefix string, sharedLibraryInstalled *map[string]bool) []fuzz.FileToZip { +func GetSharedLibsToZip(sharedLibraries android.RuleBuilderInstalls, module LinkableInterface, s *fuzz.FuzzPackager, archString string, destinationPathPrefix string, sharedLibraryInstalled *map[string]bool) []fuzz.FileToZip { var files []fuzz.FileToZip fuzzDir := "fuzz" - for _, library := range sharedLibraries { - files = append(files, fuzz.FileToZip{library, destinationPathPrefix}) + for _, ruleBuilderInstall := range sharedLibraries { + library := ruleBuilderInstall.From + install := ruleBuilderInstall.To + files = append(files, fuzz.FileToZip{ + SourceFilePath: library, + DestinationPathPrefix: destinationPathPrefix, + DestinationPath: install, + }) // For each architecture-specific shared library dependency, we need to // install it to the output directory. Setup the install destination here, // which will be used by $(copy-many-files) in the Make backend. installDestination := SharedLibraryInstallLocation( - library, module.Host(), fuzzDir, archString) + install, module.Host(), fuzzDir, archString) if (*sharedLibraryInstalled)[installDestination] { continue } @@ -483,7 +490,7 @@ func GetSharedLibsToZip(sharedLibraries android.Paths, module LinkableInterface, // we want symbolization tools (like `stack`) to be able to find the symbols // in $ANDROID_PRODUCT_OUT/symbols automagically. if !module.Host() { - symbolsInstallDestination := SharedLibrarySymbolsInstallLocation(library, fuzzDir, archString) + symbolsInstallDestination := SharedLibrarySymbolsInstallLocation(install, fuzzDir, archString) symbolsInstallDestination = strings.ReplaceAll(symbolsInstallDestination, "$", "$$") s.SharedLibInstallStrings = append(s.SharedLibInstallStrings, library.String()+":"+symbolsInstallDestination) @@ -497,12 +504,12 @@ func GetSharedLibsToZip(sharedLibraries android.Paths, module LinkableInterface, // VisitDirectDeps is used first to avoid incorrectly using the core libraries (sanitizer // runtimes, libc, libdl, etc.) from a dependency. This may cause issues when dependencies // have explicit sanitizer tags, as we may get a dependency on an unsanitized libc, etc. -func CollectAllSharedDependencies(ctx android.ModuleContext) (android.Paths, []android.Module) { +func CollectAllSharedDependencies(ctx android.ModuleContext) (android.RuleBuilderInstalls, []android.Module) { seen := make(map[string]bool) recursed := make(map[string]bool) deps := []android.Module{} - var sharedLibraries android.Paths + var sharedLibraries android.RuleBuilderInstalls // Enumerate the first level of dependencies, as we discard all non-library // modules in the BFS loop below. @@ -510,22 +517,36 @@ func CollectAllSharedDependencies(ctx android.ModuleContext) (android.Paths, []a if !IsValidSharedDependency(dep) { return } + if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) { + return + } if seen[ctx.OtherModuleName(dep)] { return } seen[ctx.OtherModuleName(dep)] = true deps = append(deps, dep) - sharedLibraries = append(sharedLibraries, android.OutputFileForModule(ctx, dep, "unstripped")) + + sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo) + installDestination := sharedLibraryInfo.SharedLibrary.Base() + ruleBuilderInstall := android.RuleBuilderInstall{android.OutputFileForModule(ctx, dep, "unstripped"), installDestination} + sharedLibraries = append(sharedLibraries, ruleBuilderInstall) }) ctx.WalkDeps(func(child, parent android.Module) bool { if !IsValidSharedDependency(child) { return false } + if !ctx.OtherModuleHasProvider(child, SharedLibraryInfoProvider) { + return false + } if !seen[ctx.OtherModuleName(child)] { seen[ctx.OtherModuleName(child)] = true deps = append(deps, child) - sharedLibraries = append(sharedLibraries, android.OutputFileForModule(ctx, child, "unstripped")) + + sharedLibraryInfo := ctx.OtherModuleProvider(child, SharedLibraryInfoProvider).(SharedLibraryInfo) + installDestination := sharedLibraryInfo.SharedLibrary.Base() + ruleBuilderInstall := android.RuleBuilderInstall{android.OutputFileForModule(ctx, child, "unstripped"), installDestination} + sharedLibraries = append(sharedLibraries, ruleBuilderInstall) } if recursed[ctx.OtherModuleName(child)] { @@ -18,7 +18,9 @@ import ( "path/filepath" "strings" + "android/soong/aidl_library" "android/soong/bazel" + "github.com/google/blueprint" "android/soong/android" @@ -124,11 +126,6 @@ func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile andr headerBn := outDir.Join(ctx, aidlPackage, "Bn"+shortName+".h") headerBp := outDir.Join(ctx, aidlPackage, "Bp"+shortName+".h") - baseDir := strings.TrimSuffix(aidlFile.String(), aidlFile.Rel()) - if baseDir != "" { - aidlFlags += " -I" + baseDir - } - cmd := rule.Command() cmd.BuiltTool("aidl-cpp"). FlagWithDepFile("-d", depFile). @@ -282,7 +279,10 @@ type generatedSourceInfo struct { syspropOrderOnlyDeps android.Paths } -func genSources(ctx android.ModuleContext, srcFiles android.Paths, +func genSources( + ctx android.ModuleContext, + aidlLibraryInfos []aidl_library.AidlLibraryInfo, + srcFiles android.Paths, buildFlags builderFlags) (android.Paths, android.Paths, generatedSourceInfo) { var info generatedSourceInfo @@ -330,7 +330,8 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths, aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"), android.PathForModuleGen(ctx, "aidl.sbox.textproto")) } - cppFile, aidlHeaders := genAidl(ctx, aidlRule, srcFile, buildFlags.aidlFlags) + baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel()) + cppFile, aidlHeaders := genAidl(ctx, aidlRule, srcFile, buildFlags.aidlFlags+" -I"+baseDir) srcFiles[i] = cppFile info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...) @@ -352,6 +353,24 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths, } } + for _, aidlLibraryInfo := range aidlLibraryInfos { + for _, aidlSrc := range aidlLibraryInfo.Srcs { + if aidlRule == nil { + // TODO(b/279960133): Sandbox inputs to ensure aidl headers are explicitly specified + aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"), + android.PathForModuleGen(ctx, "aidl.sbox.textproto")) + } + cppFile, aidlHeaders := genAidl(ctx, aidlRule, aidlSrc, buildFlags.aidlFlags) + + srcFiles = append(srcFiles, cppFile) + info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...) + // Use the generated headers as order only deps to ensure that they are up to date when + // needed. + // TODO: Reduce the size of the ninja file by using one order only dep for the whole rule + info.aidlOrderOnlyDeps = append(info.aidlOrderOnlyDeps, aidlHeaders...) + } + } + if aidlRule != nil { aidlRule.Build("aidl", "gen aidl") } diff --git a/cc/library.go b/cc/library.go index 13b333a12..ad4688fe6 100644 --- a/cc/library.go +++ b/cc/library.go @@ -2114,7 +2114,7 @@ func (library *libraryDecorator) link(ctx ModuleContext, // Optionally export aidl headers. if Bool(library.Properties.Aidl.Export_aidl_headers) { - if library.baseCompiler.hasSrcExt(".aidl") { + if library.baseCompiler.hasAidl(deps) { dir := android.PathForModuleGen(ctx, "aidl") library.reexportDirs(dir) diff --git a/cc/linkable.go b/cc/linkable.go index 9578807f8..557f5d2b3 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -130,7 +130,7 @@ type LinkableInterface interface { // FuzzSharedLibraries returns the shared library dependencies for this module. // Expects that IsFuzzModule returns true. - FuzzSharedLibraries() android.Paths + FuzzSharedLibraries() android.RuleBuilderInstalls Device() bool Host() bool diff --git a/cc/object.go b/cc/object.go index 5d6187233..ca1484538 100644 --- a/cc/object.go +++ b/cc/object.go @@ -309,6 +309,8 @@ func (object *objectLinker) link(ctx ModuleContext, }) } } else { + outputAddrSig := android.PathForModuleOut(ctx, "addrsig", outputName) + if String(object.Properties.Prefix_symbols) != "" { input := android.PathForModuleOut(ctx, "unprefixed", outputName) transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input, @@ -316,7 +318,12 @@ func (object *objectLinker) link(ctx ModuleContext, output = input } - transformObjsToObj(ctx, objs.objFiles, builderFlags, output, flags.LdFlagsDeps) + transformObjsToObj(ctx, objs.objFiles, builderFlags, outputAddrSig, flags.LdFlagsDeps) + + // ld -r reorders symbols and invalidates the .llvm_addrsig section, which then causes warnings + // if the resulting object is used with ld --icf=safe. Strip the .llvm_addrsig section to + // prevent the warnings. + transformObjectNoAddrSig(ctx, outputAddrSig, output) } ctx.CheckbuildFile(outputFile) diff --git a/cc/testing.go b/cc/testing.go index ced09290f..d346739bd 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -82,6 +82,10 @@ func commonDefaultModules() string { sanitize: { never: true, }, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } cc_prebuilt_library_static { diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 5de232664..cf6c1c7b8 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -133,6 +133,10 @@ func runMixedModeBuild(ctx *android.Context, extraNinjaDeps []string) string { ninjaDeps = append(ninjaDeps, writeBuildGlobsNinjaFile(ctx)...) writeDepFile(cmdlineArgs.OutFile, ctx.EventHandler, ninjaDeps) + + if ctx.Config().IsEnvTrue("SOONG_GENERATES_NINJA_HINT") { + writeNinjaHint(ctx) + } return cmdlineArgs.OutFile } @@ -455,6 +459,9 @@ func runSoongOnlyBuild(ctx *android.Context, extraNinjaDeps []string) string { // The actual output (build.ninja) was written in the RunBlueprint() call // above writeDepFile(cmdlineArgs.OutFile, ctx.EventHandler, ninjaDeps) + if ctx.Config().IsEnvTrue("SOONG_GENERATES_NINJA_HINT") { + writeNinjaHint(ctx) + } return cmdlineArgs.OutFile } } @@ -535,15 +542,18 @@ func main() { } else { finalOutputFile = runSoongOnlyBuild(ctx, extraNinjaDeps) } - if ctx.Config().IsEnvTrue("SOONG_GENERATES_NINJA_HINT") { - writeNinjaHint(ctx) - } writeMetrics(configuration, ctx.EventHandler, metricsDir) } - writeUsedEnvironmentFile(configuration, finalOutputFile) + writeUsedEnvironmentFile(configuration) + + // Touch the output file so that it's the newest file created by soong_build. + // This is necessary because, if soong_build generated any files which + // are ninja inputs to the main output file, then ninja would superfluously + // rebuild this output file on the next build invocation. + touch(shared.JoinPath(topDir, finalOutputFile)) } -func writeUsedEnvironmentFile(configuration android.Config, finalOutputFile string) { +func writeUsedEnvironmentFile(configuration android.Config) { if usedEnvFile == "" { return } @@ -562,11 +572,6 @@ func writeUsedEnvironmentFile(configuration android.Config, finalOutputFile stri } err = os.WriteFile(path, data, 0666) maybeQuit(err, "error writing used environment file '%s'", usedEnvFile) - - // Touch the output file so that it's not older than the file we just - // wrote. We can't write the environment file earlier because one an access - // new environment variables while writing it. - touch(shared.JoinPath(topDir, finalOutputFile)) } func touch(path string) { diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index bd774c645..eea41e6f3 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -92,14 +92,13 @@ var commands = []command{ stdio: stdio, run: runMake, }, { - flag: "--upload-metrics-only", - description: "upload metrics without building anything", + flag: "--finalize-bazel-metrics", + description: "finalize b metrics and upload", config: build.UploadOnlyConfig, stdio: stdio, - // Upload-only mode mostly skips to the metrics-uploading phase of soong_ui. - // However, this invocation marks the true "end of the build", and thus we - // need to update the total runtime of the build to include this upload step. - run: updateTotalRealTime, + // Finalize-bazel-metrics mode updates metrics files and calls the metrics + // uploader. This marks the end of a b invocation. + run: finalizeBazelMetrics, }, } @@ -203,8 +202,6 @@ func main() { bazelMetricsFile := filepath.Join(logsDir, c.logsPrefix+"bazel_metrics.pb") soongBuildMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_build_metrics.pb") - //the profile file generated by Bazel" - bazelProfileFile := filepath.Join(logsDir, c.logsPrefix+"analyzed_bazel_profile.txt") metricsFiles := []string{ buildErrorFile, // build error strings rbeMetricsFile, // high level metrics related to remote build execution. @@ -226,7 +223,7 @@ func main() { criticalPath.WriteToMetrics(met) met.Dump(soongMetricsFile) if !config.SkipMetricsUpload() { - build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, bazelProfileFile, bazelMetricsFile, metricsFiles...) + build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, metricsFiles...) } }() c.run(buildCtx, config, args) @@ -692,6 +689,15 @@ func setMaxFiles(ctx build.Context) { } } +func finalizeBazelMetrics(ctx build.Context, config build.Config, args []string) { + updateTotalRealTime(ctx, config, args) + + logsDir := config.LogsDir() + logsPrefix := config.GetLogsPrefix() + bazelMetricsFile := filepath.Join(logsDir, logsPrefix+"bazel_metrics.pb") + bazelProfileFile := filepath.Join(logsDir, logsPrefix+"analyzed_bazel_profile.txt") + build.ProcessBazelMetrics(bazelProfileFile, bazelMetricsFile, ctx, config) +} func updateTotalRealTime(ctx build.Context, config build.Config, args []string) { soongMetricsFile := filepath.Join(config.LogsDir(), "soong_metrics") diff --git a/device_config/Android.bp b/device_config/Android.bp new file mode 100644 index 000000000..360b3898a --- /dev/null +++ b/device_config/Android.bp @@ -0,0 +1,30 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +bootstrap_go_package { + name: "soong-device_config", + pkgPath: "android/soong/device_config", + deps: [ + "blueprint", + "blueprint-pathtools", + "sbox_proto", + "soong", + "soong-android", + "soong-bazel", + "soong-shared", + ], + srcs: [ + "device_config_definitions.go", + "device_config_values.go", + "device_config_value_set.go", + "init.go", + //"testing.go" + ], + /* + testSrcs: [ + "device_config_test.go", + ], + */ + pluginFor: ["soong_build"], +} diff --git a/device_config/device_config_definitions.go b/device_config/device_config_definitions.go new file mode 100644 index 000000000..c5657666c --- /dev/null +++ b/device_config/device_config_definitions.go @@ -0,0 +1,150 @@ +// Copyright 2023 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 device_config + +import ( + "android/soong/android" + "fmt" + "github.com/google/blueprint" + "strings" +) + +type DefinitionsModule struct { + android.ModuleBase + android.DefaultableModuleBase + + // Properties for "device_config_definitions" + properties struct { + // aconfig files, relative to this Android.bp file + Srcs []string `android:"path"` + + // Release config flag namespace + Namespace string + + // Values from TARGET_RELEASE / RELEASE_DEVICE_CONFIG_VALUE_SETS + Values []string `blueprint:"mutated"` + } + + intermediatePath android.WritablePath + srcJarPath android.WritablePath +} + +func DefinitionsFactory() android.Module { + module := &DefinitionsModule{} + + android.InitAndroidModule(module) + android.InitDefaultableModule(module) + module.AddProperties(&module.properties) + // TODO: bp2build + //android.InitBazelModule(module) + + return module +} + +type implicitValuesTagType struct { + blueprint.BaseDependencyTag +} + +var implicitValuesTag = implicitValuesTagType{} + +func (module *DefinitionsModule) DepsMutator(ctx android.BottomUpMutatorContext) { + // Validate Properties + if len(module.properties.Srcs) == 0 { + ctx.PropertyErrorf("srcs", "missing source files") + return + } + if len(module.properties.Namespace) == 0 { + ctx.PropertyErrorf("namespace", "missing namespace property") + } + + // Add a dependency on the device_config_value_sets defined in + // RELEASE_DEVICE_CONFIG_VALUE_SETS, and add any device_config_values that + // match our namespace. + valuesFromConfig := ctx.Config().ReleaseDeviceConfigValueSets() + ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig...) +} + +func (module *DefinitionsModule) OutputFiles(tag string) (android.Paths, error) { + switch tag { + case ".srcjar": + return []android.Path{module.srcJarPath}, nil + case "": + // The default output of this module is the intermediates format, which is + // not installable and in a private format that no other rules can handle + // correctly. + return []android.Path{module.intermediatePath}, nil + default: + return nil, fmt.Errorf("unsupported device_config_definitions module reference tag %q", tag) + } +} + +func joinAndPrefix(prefix string, values []string) string { + var sb strings.Builder + for _, v := range values { + sb.WriteString(prefix) + sb.WriteString(v) + } + return sb.String() +} + +func (module *DefinitionsModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { + // Get the values that came from the global RELEASE_DEVICE_CONFIG_VALUE_SETS flag + ctx.VisitDirectDeps(func(dep android.Module) { + if !ctx.OtherModuleHasProvider(dep, valueSetProviderKey) { + // Other modules get injected as dependencies too, for example the license modules + return + } + depData := ctx.OtherModuleProvider(dep, valueSetProviderKey).(valueSetProviderData) + valuesFiles, ok := depData.AvailableNamespaces[module.properties.Namespace] + if ok { + for _, path := range valuesFiles { + module.properties.Values = append(module.properties.Values, path.String()) + } + } + }) + + // Intermediate format + inputFiles := android.PathsForModuleSrc(ctx, module.properties.Srcs) + module.intermediatePath = android.PathForModuleOut(ctx, "intermediate.json") + ctx.Build(pctx, android.BuildParams{ + Rule: aconfigRule, + Inputs: inputFiles, + Output: module.intermediatePath, + Description: "device_config_definitions", + Args: map[string]string{ + "release_version": ctx.Config().ReleaseVersion(), + "namespace": module.properties.Namespace, + "values": joinAndPrefix(" --values ", module.properties.Values), + }, + }) + + // Generated java inside a srcjar + module.srcJarPath = android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar") + ctx.Build(pctx, android.BuildParams{ + Rule: srcJarRule, + Input: module.intermediatePath, + Output: module.srcJarPath, + Description: "device_config.srcjar", + }) + + // TODO: C++ + + // Phony target for debugging convenience + ctx.Build(pctx, android.BuildParams{ + Rule: blueprint.Phony, + Output: android.PathForPhony(ctx, ctx.ModuleName()), + Inputs: []android.Path{module.srcJarPath}, // TODO: C++ + }) +} diff --git a/device_config/device_config_test.go b/device_config/device_config_test.go new file mode 100644 index 000000000..91a06a781 --- /dev/null +++ b/device_config/device_config_test.go @@ -0,0 +1,61 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package device_config + +import ( + "os" + "testing" + + "android/soong/android" + "android/soong/java" +) + +func TestMain(m *testing.M) { + os.Exit(m.Run()) +} + +func test(t *testing.T, bp string) *android.TestResult { + t.Helper() + + mockFS := android.MockFS{ + "config.aconfig": nil, + } + + result := android.GroupFixturePreparers( + java.PrepareForTestWithJavaDefaultModules, + PrepareForTestWithSyspropBuildComponents, + // TODO: Consider values files, although maybe in its own test + // android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + // variables.ReleaseConfigValuesBasePaths = ... + //}) + mockFS.AddToFixture(), + android.FixtureWithRootAndroidBp(bp), + ).RunTest(t) + + return result +} + +func TestOutputs(t *testing.T) { + /*result := */ test(t, ` + device_config { + name: "my_device_config", + srcs: ["config.aconfig"], + } + `) + + // TODO: Make sure it exports a .srcjar, which is used by java libraries + // TODO: Make sure it exports an intermediates file + // TODO: Make sure the intermediates file is propagated to the Android.mk file +} diff --git a/device_config/device_config_value_set.go b/device_config/device_config_value_set.go new file mode 100644 index 000000000..e406d20e0 --- /dev/null +++ b/device_config/device_config_value_set.go @@ -0,0 +1,92 @@ +// Copyright 2023 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 device_config + +import ( + "android/soong/android" + "github.com/google/blueprint" +) + +// Properties for "device_config_value_set" +type ValueSetModule struct { + android.ModuleBase + android.DefaultableModuleBase + + properties struct { + // device_config_values modules + Values []string + } +} + +func ValueSetFactory() android.Module { + module := &ValueSetModule{} + + android.InitAndroidModule(module) + android.InitDefaultableModule(module) + module.AddProperties(&module.properties) + // TODO: bp2build + //android.InitBazelModule(module) + + return module +} + +// Dependency tag for values property +type valueSetType struct { + blueprint.BaseDependencyTag +} + +var valueSetTag = valueSetType{} + +// Provider published by device_config_value_set +type valueSetProviderData struct { + // The namespace of each of the + // (map of namespace --> device_config_module) + AvailableNamespaces map[string]android.Paths +} + +var valueSetProviderKey = blueprint.NewProvider(valueSetProviderData{}) + +func (module *ValueSetModule) DepsMutator(ctx android.BottomUpMutatorContext) { + deps := ctx.AddDependency(ctx.Module(), valueSetTag, module.properties.Values...) + for _, dep := range deps { + _, ok := dep.(*ValuesModule) + if !ok { + ctx.PropertyErrorf("values", "values must be a device_config_values module") + return + } + } +} + +func (module *ValueSetModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { + // Accumulate the namespaces of the values modules listed, and set that as an + // valueSetProviderKey provider that device_config modules can read and use + // to append values to their aconfig actions. + namespaces := make(map[string]android.Paths) + ctx.VisitDirectDeps(func(dep android.Module) { + if !ctx.OtherModuleHasProvider(dep, valuesProviderKey) { + // Other modules get injected as dependencies too, for example the license modules + return + } + depData := ctx.OtherModuleProvider(dep, valuesProviderKey).(valuesProviderData) + + srcs := make([]android.Path, len(depData.Values)) + copy(srcs, depData.Values) + namespaces[depData.Namespace] = srcs + + }) + ctx.SetProvider(valueSetProviderKey, valueSetProviderData{ + AvailableNamespaces: namespaces, + }) +} diff --git a/device_config/device_config_values.go b/device_config/device_config_values.go new file mode 100644 index 000000000..110f12a1c --- /dev/null +++ b/device_config/device_config_values.go @@ -0,0 +1,70 @@ +// Copyright 2023 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 device_config + +import ( + "android/soong/android" + "github.com/google/blueprint" +) + +// Properties for "device_config_value" +type ValuesModule struct { + android.ModuleBase + android.DefaultableModuleBase + + properties struct { + // aconfig files, relative to this Android.bp file + Srcs []string `android:"path"` + + // Release config flag namespace + Namespace string + } +} + +func ValuesFactory() android.Module { + module := &ValuesModule{} + + android.InitAndroidModule(module) + android.InitDefaultableModule(module) + module.AddProperties(&module.properties) + // TODO: bp2build + //android.InitBazelModule(module) + + return module +} + +// Provider published by device_config_value_set +type valuesProviderData struct { + // The namespace that this values module values + Namespace string + + // The values aconfig files, relative to the root of the tree + Values android.Paths +} + +var valuesProviderKey = blueprint.NewProvider(valuesProviderData{}) + +func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { + if len(module.properties.Namespace) == 0 { + ctx.PropertyErrorf("namespace", "missing namespace property") + } + + // Provide the our source files list to the device_config_value_set as a list of files + providerData := valuesProviderData{ + Namespace: module.properties.Namespace, + Values: android.PathsForModuleSrc(ctx, module.properties.Srcs), + } + ctx.SetProvider(valuesProviderKey, providerData) +} diff --git a/device_config/init.go b/device_config/init.go new file mode 100644 index 000000000..0a4645b2b --- /dev/null +++ b/device_config/init.go @@ -0,0 +1,70 @@ +// Copyright 2023 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 device_config + +import ( + "android/soong/android" + "github.com/google/blueprint" +) + +var ( + pctx = android.NewPackageContext("android/soong/device_config") + + // For device_config_definitions: Generate cache file + // TODO: Restat + aconfigRule = pctx.AndroidStaticRule("aconfig", + blueprint.RuleParams{ + Command: `${aconfig} create-cache` + + ` --namespace ${namespace}` + + ` --declarations ${in}` + + ` ${values}` + + ` --cache ${out}.tmp` + + ` && ( if cmp -s ${out}.tmp ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`, + // ` --build-id ${release_version}` + + CommandDeps: []string{ + "${aconfig}", + }, + Restat: true, + }, "release_version", "namespace", "values") + + // For device_config_definitions: Generate java file + srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar", + blueprint.RuleParams{ + Command: `rm -rf ${out}.tmp` + + ` && mkdir -p ${out}.tmp` + + ` && ${aconfig} create-java-lib` + + ` --cache ${in}` + + ` --out ${out}.tmp` + + ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` + + ` && rm -rf ${out}.tmp`, + CommandDeps: []string{ + "$aconfig", + "$soong_zip", + }, + Restat: true, + }) +) + +func init() { + registerBuildComponents(android.InitRegistrationContext) +} + +func registerBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterModuleType("device_config_definitions", DefinitionsFactory) + ctx.RegisterModuleType("device_config_values", ValuesFactory) + ctx.RegisterModuleType("device_config_value_set", ValueSetFactory) + pctx.HostBinToolVariable("aconfig", "aconfig") + pctx.HostBinToolVariable("soong_zip", "soong_zip") +} diff --git a/device_config/testing.go b/device_config/testing.go new file mode 100644 index 000000000..f0544766b --- /dev/null +++ b/device_config/testing.go @@ -0,0 +1,19 @@ +// Copyright (C) 2021 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package device_config + +import "android/soong/android" + +var PrepareForTestWithSyspropBuildComponents = android.FixtureRegisterWithContext(registerBuildComponents) diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index 6817dcef0..3e1bbded6 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -652,9 +652,7 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto prop := snapshot.SnapshotJsonFlags{} propOut := snapshotLibOut + ".json" prop.InitBaseSnapshotProps(m) - if m.subdirProperties.Relative_install_path != nil { - prop.RelativeInstallPath = *m.subdirProperties.Relative_install_path - } + prop.RelativeInstallPath = m.SubDir() if m.properties.Filename != nil { prop.Filename = *m.properties.Filename diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go index f76529d31..2a1b40452 100644 --- a/fuzz/fuzz_common.go +++ b/fuzz/fuzz_common.go @@ -61,6 +61,7 @@ type FuzzPackager struct { type FileToZip struct { SourceFilePath android.Path DestinationPathPrefix string + DestinationPath string } type ArchOs struct { @@ -443,7 +444,7 @@ func (s *FuzzPackager) PackageArtifacts(ctx android.SingletonContext, module and FlagWithOutput("-o ", corpusZip) rspFile := corpusZip.ReplaceExtension(ctx, "rsp") command.FlagWithRspFileInputList("-r ", rspFile, fuzzModule.Corpus) - files = append(files, FileToZip{corpusZip, ""}) + files = append(files, FileToZip{SourceFilePath: corpusZip}) } // Package the data into a zipfile. @@ -456,17 +457,17 @@ func (s *FuzzPackager) PackageArtifacts(ctx android.SingletonContext, module and command.FlagWithArg("-C ", intermediateDir) command.FlagWithInput("-f ", f) } - files = append(files, FileToZip{dataZip, ""}) + files = append(files, FileToZip{SourceFilePath: dataZip}) } // The dictionary. if fuzzModule.Dictionary != nil { - files = append(files, FileToZip{fuzzModule.Dictionary, ""}) + files = append(files, FileToZip{SourceFilePath: fuzzModule.Dictionary}) } // Additional fuzz config. if fuzzModule.Config != nil && IsValidConfig(fuzzModule, module.Name()) { - files = append(files, FileToZip{fuzzModule.Config, ""}) + files = append(files, FileToZip{SourceFilePath: fuzzModule.Config}) } return files @@ -485,6 +486,9 @@ func (s *FuzzPackager) BuildZipFile(ctx android.SingletonContext, module android } else { command.Flag("-P ''") } + if file.DestinationPath != "" { + command.FlagWithArg("-e ", file.DestinationPath) + } command.FlagWithInput("-f ", file.SourceFilePath) } @@ -502,7 +506,7 @@ func (s *FuzzPackager) BuildZipFile(ctx android.SingletonContext, module android } s.FuzzTargets[module.Name()] = true - archDirs[archOs] = append(archDirs[archOs], FileToZip{fuzzZip, ""}) + archDirs[archOs] = append(archDirs[archOs], FileToZip{SourceFilePath: fuzzZip}) return archDirs[archOs], true } diff --git a/java/Android.bp b/java/Android.bp index 27a0a3853..4af2a14eb 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -87,7 +87,6 @@ bootstrap_go_package { "device_host_converter_test.go", "dex_test.go", "dexpreopt_test.go", - "dexpreopt_bootjars_test.go", "dexpreopt_config_test.go", "droiddoc_test.go", "droidstubs_test.go", diff --git a/java/aar.go b/java/aar.go index f1b137de1..29e86e678 100644 --- a/java/aar.go +++ b/java/aar.go @@ -1056,7 +1056,7 @@ func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) { ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "aar_import", - Bzl_load_location: "//build/bazel/rules/android:rules.bzl", + Bzl_load_location: "//build/bazel/rules/android:aar_import.bzl", }, android.CommonAttributes{Name: name}, &bazelAndroidLibraryImport{ @@ -1086,7 +1086,7 @@ func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) { func AndroidLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties { return bazel.BazelTargetModuleProperties{ Rule_class: "android_library", - Bzl_load_location: "//build/bazel/rules/android:rules.bzl", + Bzl_load_location: "//build/bazel/rules/android:android_library.bzl", } } diff --git a/java/app.go b/java/app.go index da9c6f343..334464772 100755 --- a/java/app.go +++ b/java/app.go @@ -1539,7 +1539,7 @@ func androidAppCertificateBp2Build(ctx android.TopDownMutatorContext, module *An props := bazel.BazelTargetModuleProperties{ Rule_class: "android_app_certificate", - Bzl_load_location: "//build/bazel/rules/android:rules.bzl", + Bzl_load_location: "//build/bazel/rules/android:android_app_certificate.bzl", } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs) @@ -1592,7 +1592,7 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) { props := bazel.BazelTargetModuleProperties{ Rule_class: "android_binary", - Bzl_load_location: "//build/bazel/rules/android:rules.bzl", + Bzl_load_location: "//build/bazel/rules/android:android_binary.bzl", } if !bp2BuildInfo.hasKotlin { @@ -1622,7 +1622,7 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) { ctx.CreateBazelTargetModule( props, - android.CommonAttributes{Name: a.Name()}, + android.CommonAttributes{Name: a.Name(), SkipData: proptools.BoolPtr(true)}, appAttrs, ) diff --git a/java/app_test.go b/java/app_test.go index daff94ca9..8a69a03e7 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -443,9 +443,9 @@ func TestUpdatableApps_JniLibShouldBeBuiltAgainstMinSdkVersion(t *testing.T) { inputs := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits var crtbeginFound, crtendFound bool expectedCrtBegin := ctx.ModuleForTests("crtbegin_so", - "android_arm64_armv8-a_sdk_29").Rule("partialLd").Output + "android_arm64_armv8-a_sdk_29").Rule("noAddrSig").Output expectedCrtEnd := ctx.ModuleForTests("crtend_so", - "android_arm64_armv8-a_sdk_29").Rule("partialLd").Output + "android_arm64_armv8-a_sdk_29").Rule("noAddrSig").Output implicits := []string{} for _, input := range inputs { implicits = append(implicits, input.String()) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 6ccf5a331..108fdd483 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -241,10 +241,8 @@ type BootclasspathFragmentModule struct { // Collect the module directory for IDE info in java/jdeps.go. modulePaths []string - // Installs for on-device boot image files. This list has entries only if the installs should be - // handled by Make (e.g., the boot image should be installed on the system partition, rather than - // in the APEX). - bootImageDeviceInstalls []dexpreopterInstall + // Path to the boot image profile. + profilePath android.Path } // commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt @@ -264,16 +262,16 @@ type commonBootclasspathFragment interface { // If it could not create the files then it will return nil. Otherwise, it will return a map from // android.ArchType to the predefined paths of the boot image files. produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs + + // getImageName returns the `image_name` property of this fragment. + getImageName() *string + + // getProfilePath returns the path to the boot image profile. + getProfilePath() android.Path } var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil) -// bootImageFilesByArch is a map from android.ArchType to the paths to the boot image files. -// -// The paths include the .art, .oat and .vdex files, one for each of the modules from which the boot -// image is created. -type bootImageFilesByArch map[android.ArchType]android.Paths - func bootclasspathFragmentFactory() android.Module { m := &BootclasspathFragmentModule{} m.AddProperties(&m.properties, &m.sourceOnlyProperties) @@ -395,12 +393,6 @@ type BootclasspathFragmentApexContentInfo struct { // set image_name: "art". modules android.ConfiguredJarList - // Map from arch type to the boot image files. - bootImageFilesByArch bootImageFilesByArch - - // True if the boot image should be installed in the APEX. - shouldInstallBootImageInApex bool - // Map from the base module name (without prebuilt_ prefix) of a fragment's contents module to the // hidden API encoded dex jar path. contentModuleDexJarPaths bootDexJarByModule @@ -417,18 +409,6 @@ func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarLis return i.modules } -// Get a map from ArchType to the associated boot image's contents for Android. -// -// Extension boot images only return their own files, not the files of the boot images they extend. -func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() bootImageFilesByArch { - return i.bootImageFilesByArch -} - -// Return true if the boot image should be installed in the APEX. -func (i *BootclasspathFragmentApexContentInfo) ShouldInstallBootImageInApex() bool { - return i.shouldInstallBootImageInApex -} - // DexBootJarPathForContentModule returns the path to the dex boot jar for specified module. // // The dex boot jar is one which has had hidden API encoding performed on it. @@ -557,6 +537,7 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo // Delegate the production of the boot image files to a module type specific method. common := ctx.Module().(commonBootclasspathFragment) bootImageFiles = common.produceBootImageFiles(ctx, imageConfig) + b.profilePath = bootImageFiles.profile if shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) { // Zip the boot image files up, if available. This will generate the zip file in a @@ -566,25 +547,6 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo // Copy the dex jars of this fragment's content modules to their predefined locations. copyBootJarsToPredefinedLocations(ctx, hiddenAPIOutput.EncodedBootDexFilesByModule, imageConfig.dexPathsByModule) } - - for _, variant := range bootImageFiles.variants { - archType := variant.config.target.Arch.ArchType - arch := archType.String() - for _, install := range variant.deviceInstalls { - // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. - installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") - installBase := filepath.Base(install.To) - installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) - - b.bootImageDeviceInstalls = append(b.bootImageDeviceInstalls, dexpreopterInstall{ - name: arch + "-" + installBase, - moduleName: b.Name(), - outputPathOnHost: install.From, - installDirOnDevice: installPath, - installFileOnDevice: installBase, - }) - } - } } // A prebuilt fragment cannot contribute to an apex. @@ -643,12 +605,8 @@ func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleC info.profilePathOnHost = bootImageFiles.profile info.profileInstallPathInApex = imageConfig.profileInstallPathInApex } - - info.shouldInstallBootImageInApex = imageConfig.shouldInstallInApex() } - info.bootImageFilesByArch = bootImageFiles.byArch - // Make the apex content info available for other modules. ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info) } @@ -960,19 +918,15 @@ func (b *BootclasspathFragmentModule) AndroidMkEntries() []android.AndroidMkEntr }, }, }} - for _, install := range b.bootImageDeviceInstalls { - entriesList = append(entriesList, install.ToMakeEntries()) - } return entriesList } -// Returns the names of all Make modules that handle the installation of the boot image. -func (b *BootclasspathFragmentModule) BootImageDeviceInstallMakeModules() []string { - var makeModules []string - for _, install := range b.bootImageDeviceInstalls { - makeModules = append(makeModules, install.FullModuleName()) - } - return makeModules +func (b *BootclasspathFragmentModule) getImageName() *string { + return b.properties.Image_name +} + +func (b *BootclasspathFragmentModule) getProfilePath() android.Path { + return b.profilePath } // Collect information for opening IDE project files in java/jdeps.go. @@ -1262,59 +1216,25 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and // built without a profile as the prebuilt modules do not provide a profile. buildBootImageVariantsForBuildOs(ctx, imageConfig, profile) - if imageConfig.shouldInstallInApex() { - // If the boot image files for the android variants are in the prebuilt apex, we must use those - // rather than building new ones because those boot image files are going to be used on device. - files := bootImageFilesByArch{} - bootImageFiles := bootImageOutputs{ - byArch: files, - profile: profile, - } - for _, variant := range imageConfig.apexVariants() { - arch := variant.target.Arch.ArchType - bootImageFiles.variants = append(bootImageFiles.variants, bootImageVariantOutputs{ - variant, - // No device installs needed when installed in APEX. - nil, - }) - for _, toPath := range variant.imagesDeps { - apexRelativePath := apexRootRelativePathToBootImageFile(arch, toPath.Base()) - // Get the path to the file that the deapexer extracted from the prebuilt apex file. - fromPath := di.PrebuiltExportPath(apexRelativePath) - - // Return the toPath as the calling code expects the paths in the returned map to be the - // paths predefined in the bootImageConfig. - files[arch] = append(files[arch], toPath) - - // Copy the file to the predefined location. - ctx.Build(pctx, android.BuildParams{ - Rule: android.Cp, - Input: fromPath, - Output: toPath, - }) - } - } - return bootImageFiles - } else { - if profile == nil && imageConfig.isProfileGuided() { - ctx.ModuleErrorf("Unable to produce boot image files: neither boot image files nor profiles exists in the prebuilt apex") - return bootImageOutputs{} - } - // Build boot image files for the android variants from the dex files provided by the contents - // of this module. - return buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) + if profile == nil && imageConfig.isProfileGuided() { + ctx.ModuleErrorf("Unable to produce boot image files: profiles not found in the prebuilt apex") + return bootImageOutputs{} } + // Build boot image files for the android variants from the dex files provided by the contents + // of this module. + return buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) } -var _ commonBootclasspathFragment = (*PrebuiltBootclasspathFragmentModule)(nil) +func (b *PrebuiltBootclasspathFragmentModule) getImageName() *string { + return b.properties.Image_name +} -// createBootImageTag creates the tag to uniquely identify the boot image file among all of the -// files that a module requires from the prebuilt .apex file. -func createBootImageTag(arch android.ArchType, baseName string) string { - tag := fmt.Sprintf(".bootimage-%s-%s", arch, baseName) - return tag +func (b *PrebuiltBootclasspathFragmentModule) getProfilePath() android.Path { + return b.profilePath } +var _ commonBootclasspathFragment = (*PrebuiltBootclasspathFragmentModule)(nil) + // RequiredFilesFromPrebuiltApex returns the list of all files the prebuilt_bootclasspath_fragment // requires from a prebuilt .apex file. // @@ -1328,25 +1248,11 @@ func (module *PrebuiltBootclasspathFragmentModule) RequiredFilesFromPrebuiltApex // Add the boot image profile. files = append(files, imageConfig.profileInstallPathInApex) } - if imageConfig.shouldInstallInApex() { - // Add the boot image files, e.g. .art, .oat and .vdex files. - for _, variant := range imageConfig.apexVariants() { - arch := variant.target.Arch.ArchType - for _, path := range variant.imagesDeps.Paths() { - base := path.Base() - files = append(files, apexRootRelativePathToBootImageFile(arch, base)) - } - } - } return files } return nil } -func apexRootRelativePathToBootImageFile(arch android.ArchType, base string) string { - return filepath.Join("javalib", arch.String(), base) -} - var _ android.RequiredFilesFromPrebuiltApex = (*PrebuiltBootclasspathFragmentModule)(nil) func prebuiltBootclasspathFragmentFactory() android.Module { diff --git a/java/dex.go b/java/dex.go index f7c1361e2..7e7da00fd 100644 --- a/java/dex.go +++ b/java/dex.go @@ -161,7 +161,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8", "$r8Template": &remoteexec.REParams{ Labels: map[string]string{"type": "compile", "compiler": "r8"}, Inputs: []string{"$implicits", "${config.R8Jar}"}, - OutputFiles: []string{"${outUsage}"}, + OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}"}, ExecStrategy: "${config.RER8ExecStrategy}", ToolchainInputs: []string{"${config.JavaCmd}"}, Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, @@ -399,13 +399,16 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam args["implicits"] = strings.Join(r8Deps.Strings(), ",") } ctx.Build(pctx, android.BuildParams{ - Rule: rule, - Description: "r8", - Output: javalibJar, - ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip}, - Input: dexParams.classesJar, - Implicits: r8Deps, - Args: args, + Rule: rule, + Description: "r8", + Output: javalibJar, + ImplicitOutputs: android.WritablePaths{ + proguardDictionary, + proguardUsageZip, + proguardConfiguration}, + Input: dexParams.classesJar, + Implicits: r8Deps, + Args: args, }) } else { d8Flags, d8Deps := d8Flags(dexParams.flags) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 8e79674fb..f477f404e 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -250,11 +250,12 @@ type bootImageConfig struct { // Output directory for the image files with debug symbols. symbolsDir android.OutputPath - // Subdirectory where the image files are installed. - installDirOnHost string - - // Subdirectory where the image files on device are installed. - installDirOnDevice string + // The relative location where the image files are installed. On host, the location is relative to + // $ANDROID_PRODUCT_OUT. + // + // Only the configs that are built by platform_bootclasspath are installable on device. On device, + // the location is relative to "/". + installDir string // Install path of the boot image profile if it needs to be installed in the APEX, or empty if not // needed. @@ -294,6 +295,11 @@ type bootImageConfig struct { // The "--single-image" argument. singleImage bool + + // Profiles imported from other boot image configs. Each element must represent a + // `bootclasspath_fragment` of an APEX (i.e., the `name` field of each element must refer to the + // `image_name` property of a `bootclasspath_fragment`). + profileImports []*bootImageConfig } // Target-dependent description of a boot image. @@ -421,11 +427,6 @@ func (image *bootImageConfig) apexVariants() []*bootImageVariant { return variants } -// Returns true if the boot image should be installed in the APEX. -func (image *bootImageConfig) shouldInstallInApex() bool { - return strings.HasPrefix(image.installDirOnDevice, "apex/") -} - // Return boot image locations (as a list of symbolic paths). // // The image "location" is a symbolic path that, with multiarchitecture support, doesn't really @@ -596,6 +597,12 @@ func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImag buildBootImageForOsType(ctx, image, profile, ctx.Config().BuildOS) } +// bootImageFilesByArch is a map from android.ArchType to the paths to the boot image files. +// +// The paths include the .art, .oat and .vdex files, one for each of the modules from which the boot +// image is created. +type bootImageFilesByArch map[android.ArchType]android.Paths + // bootImageOutputs encapsulates information about boot images that were created/obtained by // commonBootclasspathFragment.produceBootImageFiles. type bootImageOutputs struct { @@ -656,8 +663,7 @@ func buildBootImageZipInPredefinedLocation(ctx android.ModuleContext, image *boo } type bootImageVariantOutputs struct { - config *bootImageVariant - deviceInstalls android.RuleBuilderInstalls + config *bootImageVariant } // Generate boot image build rules for a specific target. @@ -668,9 +674,9 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p arch := image.target.Arch.ArchType os := image.target.Os.String() // We need to distinguish host-x86 and device-x86. - symbolsDir := image.symbolsDir.Join(ctx, os, image.installDirOnHost, arch.String()) + symbolsDir := image.symbolsDir.Join(ctx, os, image.installDir, arch.String()) symbolsFile := symbolsDir.Join(ctx, image.stem+".oat") - outputDir := image.dir.Join(ctx, os, image.installDirOnHost, arch.String()) + outputDir := image.dir.Join(ctx, os, image.installDir, arch.String()) outputPath := outputDir.Join(ctx, image.stem+".oat") oatLocation := dexpreopt.PathToLocation(outputPath, arch) imagePath := outputPath.ReplaceExtension(ctx, "art") @@ -710,6 +716,34 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p cmd.FlagWithInput("--profile-file=", profile) } + fragments := make(map[string]commonBootclasspathFragment) + ctx.VisitDirectDepsWithTag(bootclasspathFragmentDepTag, func(child android.Module) { + fragment := child.(commonBootclasspathFragment) + if fragment.getImageName() != nil && android.IsModulePreferred(child) { + fragments[*fragment.getImageName()] = fragment + } + }) + + for _, profileImport := range image.profileImports { + fragment := fragments[profileImport.name] + if fragment == nil { + ctx.ModuleErrorf("Boot image config '%[1]s' imports profile from '%[2]s', but a "+ + "bootclasspath_fragment with image name '%[2]s' doesn't exist or is not added as a "+ + "dependency of '%[1]s'", + image.name, + profileImport.name) + return bootImageVariantOutputs{} + } + if fragment.getProfilePath() == nil { + ctx.ModuleErrorf("Boot image config '%[1]s' imports profile from '%[2]s', but '%[2]s' "+ + "doesn't provide a profile", + image.name, + profileImport.name) + return bootImageVariantOutputs{} + } + cmd.FlagWithInput("--profile-file=", fragment.getProfilePath()) + } + dirtyImageFile := "frameworks/base/config/dirty-image-objects" dirtyImagePath := android.ExistentPathForSource(ctx, dirtyImageFile) if dirtyImagePath.Valid() { @@ -796,11 +830,10 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage)) - installDir := filepath.Join("/", image.installDirOnHost, arch.String()) + installDir := filepath.Dir(image.imagePathOnDevice) var vdexInstalls android.RuleBuilderInstalls var unstrippedInstalls android.RuleBuilderInstalls - var deviceInstalls android.RuleBuilderInstalls for _, artOrOat := range image.moduleFiles(ctx, outputDir, ".art", ".oat") { cmd.ImplicitOutput(artOrOat) @@ -826,14 +859,6 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())}) } - if image.installDirOnHost != image.installDirOnDevice && !image.shouldInstallInApex() && !ctx.Config().UnbundledBuild() { - installDirOnDevice := filepath.Join("/", image.installDirOnDevice, arch.String()) - for _, file := range image.moduleFiles(ctx, outputDir, ".art", ".oat", ".vdex") { - deviceInstalls = append(deviceInstalls, - android.RuleBuilderInstall{file, filepath.Join(installDirOnDevice, file.Base())}) - } - } - rule.Build(image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String()) // save output and installed files for makevars @@ -849,7 +874,6 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p return bootImageVariantOutputs{ image, - deviceInstalls, } } diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go deleted file mode 100644 index 908380813..000000000 --- a/java/dexpreopt_bootjars_test.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2019 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package java - -import ( - "path/filepath" - "sort" - "testing" - - "android/soong/android" -) - -func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) { - bp := ` - java_sdk_library { - name: "foo", - srcs: ["a.java"], - api_packages: ["foo"], - } - - java_library { - name: "bar", - srcs: ["b.java"], - installable: true, - system_ext_specific: true, - } - - dex_import { - name: "baz", - jars: ["a.jar"], - } - - platform_bootclasspath { - name: "platform-bootclasspath", - } - ` - - result := android.GroupFixturePreparers( - prepareForJavaTest, - PrepareForTestWithJavaSdkLibraryFiles, - FixtureWithLastReleaseApis("foo"), - FixtureConfigureBootJars("platform:foo", "system_ext:bar", "platform:baz"), - ).RunTestWithBp(t, bp) - - platformBootclasspath := result.ModuleForTests("platform-bootclasspath", "android_common") - rule := platformBootclasspath.Output(ruleFile) - - for i := range expectedInputs { - expectedInputs[i] = filepath.Join("out/soong/dexpreopt_arm64", expectedInputs[i]) - } - - for i := range expectedOutputs { - expectedOutputs[i] = filepath.Join("out/soong/dexpreopt_arm64", expectedOutputs[i]) - } - - inputs := rule.Implicits.Strings() - sort.Strings(inputs) - sort.Strings(expectedInputs) - - outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Strings() - sort.Strings(outputs) - sort.Strings(expectedOutputs) - - android.AssertStringPathsRelativeToTopEquals(t, "inputs", result.Config, expectedInputs, inputs) - - android.AssertStringPathsRelativeToTopEquals(t, "outputs", result.Config, expectedOutputs, outputs) -} - -func TestDexpreoptBootJars(t *testing.T) { - ruleFile := "boot-foo.art" - - expectedInputs := []string{ - "dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "dex_bootjars_input/foo.jar", - "dex_bootjars_input/bar.jar", - "dex_bootjars_input/baz.jar", - } - - expectedOutputs := []string{ - "dex_bootjars/android/system/framework/arm64/boot.invocation", - "dex_bootjars/android/system/framework/arm64/boot-foo.art", - "dex_bootjars/android/system/framework/arm64/boot-bar.art", - "dex_bootjars/android/system/framework/arm64/boot-baz.art", - "dex_bootjars/android/system/framework/arm64/boot-foo.oat", - "dex_bootjars/android/system/framework/arm64/boot-bar.oat", - "dex_bootjars/android/system/framework/arm64/boot-baz.oat", - "dex_bootjars/android/system/framework/arm64/boot-foo.vdex", - "dex_bootjars/android/system/framework/arm64/boot-bar.vdex", - "dex_bootjars/android/system/framework/arm64/boot-baz.vdex", - "dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat", - "dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat", - "dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat", - } - - testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs) -} - -// Changes to the boot.zip structure may break the ART APK scanner. -func TestDexpreoptBootZip(t *testing.T) { - ruleFile := "boot.zip" - - ctx := android.PathContextForTesting(android.TestArchConfig("", nil, "", nil)) - expectedInputs := []string{} - for _, target := range ctx.Config().Targets[android.Android] { - for _, ext := range []string{".art", ".oat", ".vdex"} { - for _, jar := range []string{"foo", "bar", "baz"} { - expectedInputs = append(expectedInputs, - filepath.Join("dex_bootjars", target.Os.String(), "system/framework", target.Arch.ArchType.String(), "boot-"+jar+ext)) - } - } - } - - expectedOutputs := []string{ - "dex_bootjars/boot.zip", - } - - testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs) -} diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index 8f732cf56..9100e87c6 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -53,7 +53,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig global := dexpreopt.GetGlobalConfig(ctx) artModules := global.ArtApexJars - frameworkModules := global.BootJars.RemoveList(artModules) + frameworkModules := global.BootJars // This includes `artModules`. mainlineBcpModules := global.ApexBootJars frameworkSubdir := "system/framework" @@ -62,8 +62,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig artCfg := bootImageConfig{ name: artBootImageName, stem: bootImageStem, - installDirOnHost: "apex/art_boot_images/javalib", - installDirOnDevice: frameworkSubdir, + installDir: "apex/art_boot_images/javalib", profileInstallPathInApex: "etc/boot-image.prof", modules: artModules, preloadedClassesFile: "art/build/boot/preloaded-classes", @@ -74,26 +73,24 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig // Framework config for the boot image extension. // It includes framework libraries and depends on the ART config. frameworkCfg := bootImageConfig{ - extends: &artCfg, name: frameworkBootImageName, stem: bootImageStem, - installDirOnHost: frameworkSubdir, - installDirOnDevice: frameworkSubdir, + installDir: frameworkSubdir, modules: frameworkModules, preloadedClassesFile: "frameworks/base/config/preloaded-classes", compilerFilter: "speed-profile", singleImage: false, + profileImports: []*bootImageConfig{&artCfg}, } mainlineCfg := bootImageConfig{ - extends: &frameworkCfg, - name: mainlineBootImageName, - stem: bootImageStem, - installDirOnHost: frameworkSubdir, - installDirOnDevice: frameworkSubdir, - modules: mainlineBcpModules, - compilerFilter: "verify", - singleImage: true, + extends: &frameworkCfg, + name: mainlineBootImageName, + stem: bootImageStem, + installDir: frameworkSubdir, + modules: mainlineBcpModules, + compilerFilter: "verify", + singleImage: true, } return map[string]*bootImageConfig{ @@ -132,12 +129,12 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig { // Create target-specific variants. for _, target := range targets { arch := target.Arch.ArchType - imageDir := c.dir.Join(ctx, target.Os.String(), c.installDirOnHost, arch.String()) + imageDir := c.dir.Join(ctx, target.Os.String(), c.installDir, arch.String()) variant := &bootImageVariant{ bootImageConfig: c, target: target, imagePathOnHost: imageDir.Join(ctx, imageName), - imagePathOnDevice: filepath.Join("/", c.installDirOnDevice, arch.String(), imageName), + imagePathOnDevice: filepath.Join("/", c.installDir, arch.String(), imageName), imagesDeps: c.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex"), dexLocations: c.modules.DevicePaths(ctx.Config(), target.Os), } diff --git a/java/dexpreopt_config_testing.go b/java/dexpreopt_config_testing.go index 6b98ca58c..6f3aa2be8 100644 --- a/java/dexpreopt_config_testing.go +++ b/java/dexpreopt_config_testing.go @@ -147,8 +147,7 @@ type expectedConfig struct { stem string dir string symbolsDir string - installDirOnDevice string - installDirOnHost string + installDir string profileInstallPathInApex string modules android.ConfiguredJarList dexPaths []string @@ -209,8 +208,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b stem: "boot", dir: "out/soong/dexpreopt_arm64/dex_artjars", symbolsDir: "out/soong/dexpreopt_arm64/dex_artjars_unstripped", - installDirOnDevice: "system/framework", - installDirOnHost: "apex/art_boot_images/javalib", + installDir: "apex/art_boot_images/javalib", profileInstallPathInApex: "etc/boot-image.prof", modules: android.CreateTestConfiguredJarList([]string{"com.android.art:core1", "com.android.art:core2"}), dexPaths: []string{"out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar"}, @@ -222,7 +220,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b dexLocations: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - imagePathOnDevice: "/system/framework/arm64/boot.art", + imagePathOnDevice: "/apex/art_boot_images/javalib/arm64/boot.art", imagesDeps: []string{ "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", @@ -276,7 +274,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b dexLocations: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar"}, imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - imagePathOnDevice: "/system/framework/arm/boot.art", + imagePathOnDevice: "/apex/art_boot_images/javalib/arm/boot.art", imagesDeps: []string{ "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", @@ -330,7 +328,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b dexLocations: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - imagePathOnDevice: "/system/framework/x86_64/boot.art", + imagePathOnDevice: "/apex/art_boot_images/javalib/x86_64/boot.art", imagesDeps: []string{ "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", @@ -382,7 +380,7 @@ func checkArtBootImageConfig(t *testing.T, result *android.TestResult, mutated b dexLocations: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, dexLocationsDeps: []string{"host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar"}, imagePathOnHost: "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - imagePathOnDevice: "/system/framework/x86/boot.art", + imagePathOnDevice: "/apex/art_boot_images/javalib/x86/boot.art", imagesDeps: []string{ "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", @@ -462,40 +460,68 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut stem: "boot", dir: "out/soong/dexpreopt_arm64/dex_bootjars", symbolsDir: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped", - installDirOnDevice: "system/framework", - installDirOnHost: "system/framework", + installDir: "system/framework", profileInstallPathInApex: "", - modules: android.CreateTestConfiguredJarList([]string{"platform:framework"}), - dexPaths: []string{"out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar"}, - dexPathsDeps: []string{"out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar", "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar"}, - zip: "out/soong/dexpreopt_arm64/dex_bootjars/boot.zip", + modules: android.CreateTestConfiguredJarList([]string{ + "com.android.art:core1", + "com.android.art:core2", + "platform:framework", + }), + dexPaths: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars_input/core1.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core2.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar", + }, + dexPathsDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars_input/core1.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core2.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar", + }, + zip: "out/soong/dexpreopt_arm64/dex_bootjars/boot.zip", variants: []*expectedVariant{ { - archType: android.Arm64, - dexLocations: []string{"/system/framework/framework.jar"}, + archType: android.Arm64, + dexLocations: []string{ + "/apex/com.android.art/javalib/core1.jar", + "/apex/com.android.art/javalib/core2.jar", + "/system/framework/framework.jar", + }, dexLocationsDeps: []string{ "/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar", "/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", - imagePathOnDevice: "/system/framework/arm64/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + imagePathOnDevice: "/system/framework/arm64/boot.art", imagesDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", }, - baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art"}, - baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", - }, installs: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + to: "/system/framework/arm64/boot.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + to: "/system/framework/arm64/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art", + to: "/system/framework/arm64/boot-core2.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat", + to: "/system/framework/arm64/boot-core2.oat", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", to: "/system/framework/arm64/boot-framework.art", }, @@ -506,12 +532,28 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, vdexInstalls: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + to: "/system/framework/arm64/boot.vdex", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex", + to: "/system/framework/arm64/boot-core2.vdex", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", to: "/system/framework/arm64/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat", + to: "/system/framework/arm64/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-core2.oat", + to: "/system/framework/arm64/boot-core2.oat", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat", to: "/system/framework/arm64/boot-framework.oat", }, @@ -519,31 +561,48 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut licenseMetadataFile: expectedLicenseMetadataFile, }, { - archType: android.Arm, - dexLocations: []string{"/system/framework/framework.jar"}, + archType: android.Arm, + dexLocations: []string{ + "/apex/com.android.art/javalib/core1.jar", + "/apex/com.android.art/javalib/core2.jar", + "/system/framework/framework.jar", + }, dexLocationsDeps: []string{ "/apex/com.android.art/javalib/core1.jar", "/apex/com.android.art/javalib/core2.jar", "/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", - imagePathOnDevice: "/system/framework/arm/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", + imagePathOnDevice: "/system/framework/arm/boot.art", imagesDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", }, - baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art"}, - baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", - }, installs: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", + to: "/system/framework/arm/boot.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat", + to: "/system/framework/arm/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art", + to: "/system/framework/arm/boot-core2.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat", + to: "/system/framework/arm/boot-core2.oat", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", to: "/system/framework/arm/boot-framework.art", }, @@ -554,12 +613,28 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, vdexInstalls: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex", + to: "/system/framework/arm/boot.vdex", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex", + to: "/system/framework/arm/boot-core2.vdex", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", to: "/system/framework/arm/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot.oat", + to: "/system/framework/arm/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-core2.oat", + to: "/system/framework/arm/boot-core2.oat", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat", to: "/system/framework/arm/boot-framework.oat", }, @@ -567,31 +642,48 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut licenseMetadataFile: expectedLicenseMetadataFile, }, { - archType: android.X86_64, - dexLocations: []string{"host/linux-x86/system/framework/framework.jar"}, + archType: android.X86_64, + dexLocations: []string{ + "host/linux-x86/apex/com.android.art/javalib/core1.jar", + "host/linux-x86/apex/com.android.art/javalib/core2.jar", + "host/linux-x86/system/framework/framework.jar", + }, dexLocationsDeps: []string{ "host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar", "host/linux-x86/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", - imagePathOnDevice: "/system/framework/x86_64/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", + imagePathOnDevice: "/system/framework/x86_64/boot.art", imagesDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", }, - baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art"}, - baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", - }, installs: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", + to: "/system/framework/x86_64/boot.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat", + to: "/system/framework/x86_64/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art", + to: "/system/framework/x86_64/boot-core2.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat", + to: "/system/framework/x86_64/boot-core2.oat", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", to: "/system/framework/x86_64/boot-framework.art", }, @@ -602,12 +694,28 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, vdexInstalls: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex", + to: "/system/framework/x86_64/boot.vdex", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex", + to: "/system/framework/x86_64/boot-core2.vdex", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", to: "/system/framework/x86_64/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot.oat", + to: "/system/framework/x86_64/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-core2.oat", + to: "/system/framework/x86_64/boot-core2.oat", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat", to: "/system/framework/x86_64/boot-framework.oat", }, @@ -615,31 +723,48 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut licenseMetadataFile: expectedLicenseMetadataFile, }, { - archType: android.X86, - dexLocations: []string{"host/linux-x86/system/framework/framework.jar"}, + archType: android.X86, + dexLocations: []string{ + "host/linux-x86/apex/com.android.art/javalib/core1.jar", + "host/linux-x86/apex/com.android.art/javalib/core2.jar", + "host/linux-x86/system/framework/framework.jar", + }, dexLocationsDeps: []string{ "host/linux-x86/apex/com.android.art/javalib/core1.jar", "host/linux-x86/apex/com.android.art/javalib/core2.jar", "host/linux-x86/system/framework/framework.jar", }, - imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", - imagePathOnDevice: "/system/framework/x86/boot-framework.art", + imagePathOnHost: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", + imagePathOnDevice: "/system/framework/x86/boot.art", imagesDeps: []string{ + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", }, - baseImages: []string{"out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art"}, - baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", - }, installs: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", + to: "/system/framework/x86/boot.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat", + to: "/system/framework/x86/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art", + to: "/system/framework/x86/boot-core2.art", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat", + to: "/system/framework/x86/boot-core2.oat", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", to: "/system/framework/x86/boot-framework.art", }, @@ -650,12 +775,28 @@ func checkFrameworkBootImageConfig(t *testing.T, result *android.TestResult, mut }, vdexInstalls: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex", + to: "/system/framework/x86/boot.vdex", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex", + to: "/system/framework/x86/boot-core2.vdex", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", to: "/system/framework/x86/boot-framework.vdex", }, }, unstrippedInstalls: []normalizedInstall{ { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot.oat", + to: "/system/framework/x86/boot.oat", + }, + { + from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-core2.oat", + to: "/system/framework/x86/boot-core2.oat", + }, + { from: "out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat", to: "/system/framework/x86/boot-framework.oat", }, @@ -693,8 +834,7 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { stem: "boot", dir: "out/soong/dexpreopt_arm64/dex_mainlinejars", symbolsDir: "out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped", - installDirOnDevice: "system/framework", - installDirOnHost: "system/framework", + installDir: "system/framework", profileInstallPathInApex: "", modules: android.CreateTestConfiguredJarList([]string{ "com.android.foo:framework-foo", @@ -705,8 +845,8 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-bar.jar", }, dexPathsDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar", - "out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core1.jar", + "out/soong/dexpreopt_arm64/dex_bootjars_input/core2.jar", "out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar", "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-foo.jar", "out/soong/dexpreopt_arm64/dex_mainlinejars_input/framework-bar.jar", @@ -734,16 +874,15 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", }, baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex", @@ -793,16 +932,15 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", }, baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex", @@ -852,16 +990,15 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86_64/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", }, baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex", @@ -911,16 +1048,15 @@ func CheckMainlineBootImageConfig(t *testing.T, result *android.TestResult) { "out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex", }, baseImages: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", }, baseImagesDeps: []string{ - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat", - "out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat", + "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat", "out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex", @@ -999,8 +1135,7 @@ func nestedCheckBootImageConfig(t *testing.T, imageConfig *bootImageConfig, expe android.AssertStringEquals(t, "stem", expected.stem, imageConfig.stem) android.AssertPathRelativeToTopEquals(t, "dir", expected.dir, imageConfig.dir) android.AssertPathRelativeToTopEquals(t, "symbolsDir", expected.symbolsDir, imageConfig.symbolsDir) - android.AssertStringEquals(t, "installDirOnDevice", expected.installDirOnDevice, imageConfig.installDirOnDevice) - android.AssertStringEquals(t, "installDirOnHost", expected.installDirOnHost, imageConfig.installDirOnHost) + android.AssertStringEquals(t, "installDir", expected.installDir, imageConfig.installDir) android.AssertStringEquals(t, "profileInstallPathInApex", expected.profileInstallPathInApex, imageConfig.profileInstallPathInApex) android.AssertDeepEquals(t, "modules", expected.modules, imageConfig.modules) android.AssertPathsRelativeToTopEquals(t, "dexPaths", expected.dexPaths, imageConfig.dexPaths.Paths()) @@ -1056,18 +1191,18 @@ func checkDexpreoptMakeVars(t *testing.T, result *android.TestResult, expectedLi fmt.Fprintf(out, "%s=%s\n", v.Name(), android.StringRelativeToTop(result.Config, v.Value())) } format := ` -DEXPREOPT_BOOTCLASSPATH_DEX_FILES=out/soong/dexpreopt_arm64/dex_artjars_input/core1.jar out/soong/dexpreopt_arm64/dex_artjars_input/core2.jar out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar +DEXPREOPT_BOOTCLASSPATH_DEX_FILES=out/soong/dexpreopt_arm64/dex_bootjars_input/core1.jar out/soong/dexpreopt_arm64/dex_bootjars_input/core2.jar out/soong/dexpreopt_arm64/dex_bootjars_input/framework.jar DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS=/apex/com.android.art/javalib/core1.jar /apex/com.android.art/javalib/core2.jar /system/framework/framework.jar -DEXPREOPT_BOOT_JARS_MODULES=platform:framework +DEXPREOPT_BOOT_JARS_MODULES=com.android.art:core1:com.android.art:core2:platform:framework DEXPREOPT_GEN=out/host/linux-x86/bin/dexpreopt_gen DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art:/apex/art_boot_images/javalib/arm/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat:/apex/art_boot_images/javalib/arm/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.art:/apex/art_boot_images/javalib/arm/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-core2.oat:/apex/art_boot_images/javalib/arm/boot-core2.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art:/apex/art_boot_images/javalib/arm64/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art:/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art:/apex/art_boot_images/javalib/x86/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art:/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art:/apex/art_boot_images/javalib/x86_64/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art:/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art:/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art:/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art:/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat -DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art:/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art:/system/framework/arm/boot.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat:/system/framework/arm/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art:/system/framework/arm/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat:/system/framework/arm/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art:/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art:/system/framework/arm64/boot.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat:/system/framework/arm64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art:/system/framework/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat:/system/framework/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art:/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art:/system/framework/x86/boot.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat:/system/framework/x86/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art:/system/framework/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat:/system/framework/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art:/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat +DEXPREOPT_IMAGE_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art:/system/framework/x86_64/boot.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat:/system/framework/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art:/system/framework/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat:/system/framework/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art:/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art:/system/framework/arm/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat:/system/framework/arm/boot-framework-foo.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art:/system/framework/arm64/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat:/system/framework/arm64/boot-framework-foo.oat DEXPREOPT_IMAGE_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art:/system/framework/x86/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat:/system/framework/x86/boot-framework-foo.oat @@ -1076,10 +1211,10 @@ DEXPREOPT_IMAGE_DEPS_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/ DEXPREOPT_IMAGE_DEPS_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex DEXPREOPT_IMAGE_DEPS_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex DEXPREOPT_IMAGE_DEPS_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex -DEXPREOPT_IMAGE_DEPS_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex -DEXPREOPT_IMAGE_DEPS_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex +DEXPREOPT_IMAGE_DEPS_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.oat out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex DEXPREOPT_IMAGE_DEPS_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex DEXPREOPT_IMAGE_DEPS_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex DEXPREOPT_IMAGE_DEPS_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.oat out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex @@ -1096,12 +1231,12 @@ DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_arm=out/soong/.intermediates/framework DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_arm64=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_host_x86=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic DEXPREOPT_IMAGE_LICENSE_METADATA_mainline_host_x86_64=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic -DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEart=/system/framework/boot.art -DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEboot=/system/framework/boot.art:/system/framework/boot-framework.art -DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEmainline=/system/framework/boot.art:/system/framework/boot-framework.art:/system/framework/boot-framework-foo.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEart=/apex/art_boot_images/javalib/boot.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEboot=/system/framework/boot.art +DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICEmainline=/system/framework/boot.art:/system/framework/boot-framework-foo.art DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTart=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art -DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTboot=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot-framework.art -DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTmainline=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/boot.art:out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot-framework.art:out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/boot-framework-foo.art +DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTboot=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot.art +DEXPREOPT_IMAGE_LOCATIONS_ON_HOSTmainline=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/boot.art:out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/boot-framework-foo.art DEXPREOPT_IMAGE_NAMES=art boot mainline DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED=out/soong/dexpreopt_arm64/dex_bootjars/boot.bprof:/system/etc/boot-image.bprof out/soong/dexpreopt_arm64/dex_bootjars/boot.prof:/system/etc/boot-image.prof DEXPREOPT_IMAGE_PROFILE_LICENSE_METADATA=out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/meta_lic @@ -1109,10 +1244,10 @@ DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_arm64=out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot.oat:/apex/art_boot_images/javalib/arm64/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/android/apex/art_boot_images/javalib/arm64/boot-core2.oat:/apex/art_boot_images/javalib/arm64/boot-core2.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot.oat:/apex/art_boot_images/javalib/x86/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.oat:/apex/art_boot_images/javalib/x86/boot-core2.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.oat:/apex/art_boot_images/javalib/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_artjars_unstripped/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.oat:/apex/art_boot_images/javalib/x86_64/boot-core2.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat -DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot.oat:/system/framework/arm/boot.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-core2.oat:/system/framework/arm/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm/boot-framework.oat:/system/framework/arm/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat:/system/framework/arm64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-core2.oat:/system/framework/arm64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-framework.oat:/system/framework/arm64/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot.oat:/system/framework/x86/boot.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-core2.oat:/system/framework/x86/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86/boot-framework.oat:/system/framework/x86/boot-framework.oat +DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot.oat:/system/framework/x86_64/boot.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-core2.oat:/system/framework/x86_64/boot-core2.oat out/soong/dexpreopt_arm64/dex_bootjars_unstripped/linux_glibc/system/framework/x86_64/boot-framework.oat:/system/framework/x86_64/boot-framework.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/android/system/framework/arm/boot-framework-foo.oat:/system/framework/arm/boot-framework-foo.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/android/system/framework/arm64/boot-framework-foo.oat:/system/framework/arm64/boot-framework-foo.oat DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars_unstripped/linux_glibc/system/framework/x86/boot-framework-foo.oat:/system/framework/x86/boot-framework-foo.oat @@ -1121,10 +1256,10 @@ DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm=out/soong/dexpreopt_arm64/dex_artja DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex:/apex/art_boot_images/javalib/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-core2.vdex:/apex/art_boot_images/javalib/arm64/boot-core2.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.vdex:/apex/art_boot_images/javalib/x86/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot-core2.vdex:/apex/art_boot_images/javalib/x86/boot-core2.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.vdex:/apex/art_boot_images/javalib/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot-core2.vdex:/apex/art_boot_images/javalib/x86_64/boot-core2.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex:/system/framework/arm/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex:/system/framework/arm64/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex:/system/framework/x86/boot-framework.vdex -DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex:/system/framework/x86_64/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.vdex:/system/framework/arm/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-core2.vdex:/system/framework/arm/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.vdex:/system/framework/arm/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex:/system/framework/arm64/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-core2.vdex:/system/framework/arm64/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.vdex:/system/framework/arm64/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.vdex:/system/framework/x86/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-core2.vdex:/system/framework/x86/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.vdex:/system/framework/x86/boot-framework.vdex +DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.vdex:/system/framework/x86_64/boot.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-core2.vdex:/system/framework/x86_64/boot-core2.vdex out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.vdex:/system/framework/x86_64/boot-framework.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.vdex:/system/framework/arm/boot-framework-foo.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.vdex:/system/framework/arm64/boot-framework-foo.vdex DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.vdex:/system/framework/x86/boot-framework-foo.vdex @@ -1136,10 +1271,10 @@ DEXPREOPT_IMAGE_art_arm=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_b DEXPREOPT_IMAGE_art_arm64=out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art DEXPREOPT_IMAGE_art_host_x86=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86/boot.art DEXPREOPT_IMAGE_art_host_x86_64=out/soong/dexpreopt_arm64/dex_artjars/linux_glibc/apex/art_boot_images/javalib/x86_64/boot.art -DEXPREOPT_IMAGE_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot-framework.art -DEXPREOPT_IMAGE_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-framework.art -DEXPREOPT_IMAGE_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot-framework.art -DEXPREOPT_IMAGE_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot-framework.art +DEXPREOPT_IMAGE_boot_arm=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm/boot.art +DEXPREOPT_IMAGE_boot_arm64=out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art +DEXPREOPT_IMAGE_boot_host_x86=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86/boot.art +DEXPREOPT_IMAGE_boot_host_x86_64=out/soong/dexpreopt_arm64/dex_bootjars/linux_glibc/system/framework/x86_64/boot.art DEXPREOPT_IMAGE_mainline_arm=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm/boot-framework-foo.art DEXPREOPT_IMAGE_mainline_arm64=out/soong/dexpreopt_arm64/dex_mainlinejars/android/system/framework/arm64/boot-framework-foo.art DEXPREOPT_IMAGE_mainline_host_x86=out/soong/dexpreopt_arm64/dex_mainlinejars/linux_glibc/system/framework/x86/boot-framework-foo.art diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go index f91ac5cc3..fedd5640e 100644 --- a/java/dexpreopt_test.go +++ b/java/dexpreopt_test.go @@ -212,7 +212,7 @@ func TestDexpreoptEnabled(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { preparers := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, + PrepareForTestWithDexpreopt, PrepareForTestWithFakeApexMutator, dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), ) @@ -257,7 +257,7 @@ func TestDex2oatToolDeps(t *testing.T) { preparers := android.GroupFixturePreparers( cc.PrepareForTestWithCcDefaultModules, - PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd, + PrepareForTestWithDexpreoptWithoutFakeDex2oatd, dexpreopt.PrepareForTestByEnablingDexpreopt) testDex2oatToolDep := func(sourceEnabled, prebuiltEnabled, prebuiltPreferred bool, @@ -299,7 +299,7 @@ func TestDex2oatToolDeps(t *testing.T) { func TestDexpreoptBuiltInstalledForApex(t *testing.T) { preparers := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, + PrepareForTestWithDexpreopt, PrepareForTestWithFakeApexMutator, dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), ) @@ -386,7 +386,7 @@ func verifyEntries(t *testing.T, message string, expectedModule string, func TestAndroidMkEntriesForApex(t *testing.T) { preparers := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, + PrepareForTestWithDexpreopt, PrepareForTestWithFakeApexMutator, dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), ) diff --git a/java/fuzz.go b/java/fuzz.go index 1d6b91346..9a0c908a0 100644 --- a/java/fuzz.go +++ b/java/fuzz.go @@ -250,11 +250,11 @@ func generateBuildActions(s *fuzz.FuzzPackager, hostOrTargetString string, ctx a files = s.PackageArtifacts(ctx, module, javaFuzzModule.fuzzPackagedModule, archDir, builder) // Add .jar - files = append(files, fuzz.FileToZip{javaFuzzModule.implementationJarFile, ""}) + files = append(files, fuzz.FileToZip{SourceFilePath: javaFuzzModule.implementationJarFile}) // Add jni .so files for _, fPath := range javaFuzzModule.jniFilePaths { - files = append(files, fuzz.FileToZip{fPath, ""}) + files = append(files, fuzz.FileToZip{SourceFilePath: fPath}) } archDirs[archOs], ok = s.BuildZipFile(ctx, module, javaFuzzModule.fuzzPackagedModule, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs) diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index 75b7bb7c8..ef792f970 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -39,7 +39,9 @@ var prepareForTestWithDefaultPlatformBootclasspath = android.FixtureAddTextFile( `) var hiddenApiFixtureFactory = android.GroupFixturePreparers( - prepareForJavaTest, PrepareForTestWithHiddenApiBuildComponents) + PrepareForTestWithJavaDefaultModules, + PrepareForTestWithHiddenApiBuildComponents, +) func TestHiddenAPISingleton(t *testing.T) { result := android.GroupFixturePreparers( diff --git a/java/java.go b/java/java.go index 06130cd18..a98762cf1 100644 --- a/java/java.go +++ b/java/java.go @@ -2973,7 +2973,7 @@ type kotlinAttributes struct { func ktJvmLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties { return bazel.BazelTargetModuleProperties{ Rule_class: "kt_jvm_library", - Bzl_load_location: "//build/bazel/rules/kotlin:rules.bzl", + Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl", } } diff --git a/java/java_test.go b/java/java_test.go index 553b762ee..2a4913ecd 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -46,12 +46,11 @@ var prepareForJavaTest = android.GroupFixturePreparers( // Get the CC build components but not default modules. cc.PrepareForTestWithCcBuildComponents, // Include all the default java modules. - PrepareForTestWithJavaDefaultModules, + PrepareForTestWithDexpreopt, PrepareForTestWithOverlayBuildComponents, android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) }), - PrepareForTestWithDexpreopt, ) func TestMain(m *testing.M) { diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go index d5779f75b..07fb92cfe 100644 --- a/java/platform_bootclasspath.go +++ b/java/platform_bootclasspath.go @@ -129,8 +129,7 @@ func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.Botto // Add dependencies on all the non-updatable module configured in the "boot" boot image. That does // not include modules configured in the "art" boot image. - bootImageConfig := defaultBootImageConfig(ctx) - addDependenciesOntoBootImageModules(ctx, bootImageConfig.modules, platformBootclasspathBootJarDepTag) + addDependenciesOntoBootImageModules(ctx, b.platformJars(ctx), platformBootclasspathBootJarDepTag) // Add dependencies on all the apex jars. apexJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars @@ -187,7 +186,8 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments) buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule) - b.generateBootImageBuildActions(ctx, platformModules, apexModules) + b.generateBootImageBuildActions(ctx) + b.copyApexBootJarsForAppsDexpreopt(ctx, apexModules) } // Generate classpaths.proto config @@ -200,7 +200,7 @@ func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx and func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList { // Include all non APEX jars - jars := defaultBootImageConfig(ctx).modules + jars := b.platformJars(ctx) // Include jars from APEXes that don't populate their classpath proto config. remainingJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars @@ -217,6 +217,10 @@ func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) return jars } +func (b *platformBootclasspathModule) platformJars(ctx android.PathContext) android.ConfiguredJarList { + return defaultBootImageConfig(ctx).modules.RemoveList(artBootImageConfig(ctx).modules) +} + // checkPlatformModules ensures that the non-updatable modules supplied are not part of an // apex module. func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleContext, modules []android.Module) { @@ -226,7 +230,7 @@ func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleCon fromUpdatableApex := apexInfo.Updatable if fromUpdatableApex { // error: this jar is part of an updatable apex - ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the framework boot image", ctx.OtherModuleName(m), apexInfo.InApexVariants) + ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the platform bootclasspath", ctx.OtherModuleName(m), apexInfo.InApexVariants) } else { // ok: this jar is part of the platform or a non-updatable apex } @@ -396,7 +400,7 @@ func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.Make } // generateBootImageBuildActions generates ninja rules related to the boot image creation. -func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext, platformModules, apexModules []android.Module) { +func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext) { // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars // GenerateSingletonBuildActions method as it cannot create it for itself. dexpreopt.GetGlobalSoongConfig(ctx) @@ -408,15 +412,16 @@ func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android. frameworkBootImageConfig := defaultBootImageConfig(ctx) bootFrameworkProfileRule(ctx, frameworkBootImageConfig) - b.generateBootImage(ctx, frameworkBootImageName, platformModules) - b.generateBootImage(ctx, mainlineBootImageName, apexModules) - b.copyApexBootJarsForAppsDexpreopt(ctx, apexModules) + b.generateBootImage(ctx, frameworkBootImageName) + b.generateBootImage(ctx, mainlineBootImageName) dumpOatRules(ctx, frameworkBootImageConfig) } -func (b *platformBootclasspathModule) generateBootImage(ctx android.ModuleContext, imageName string, modules []android.Module) { +func (b *platformBootclasspathModule) generateBootImage(ctx android.ModuleContext, imageName string) { imageConfig := genBootImageConfigs(ctx)[imageName] + modules := b.getModulesForImage(ctx, imageConfig) + // Copy module dex jars to their predefined locations. bootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, modules) copyBootJarsToPredefinedLocations(ctx, bootDexJarsByModule, imageConfig.dexPathsByModule) @@ -446,3 +451,26 @@ func (b *platformBootclasspathModule) copyApexBootJarsForAppsDexpreopt(ctx andro apexBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, apexModules) copyBootJarsToPredefinedLocations(ctx, apexBootDexJarsByModule, config.dexPathsByModule) } + +func (b *platformBootclasspathModule) getModulesForImage(ctx android.ModuleContext, imageConfig *bootImageConfig) []android.Module { + modules := make([]android.Module, 0, imageConfig.modules.Len()) + for i := 0; i < imageConfig.modules.Len(); i++ { + found := false + for _, module := range b.configuredModules { + name := android.RemoveOptionalPrebuiltPrefix(module.Name()) + if name == imageConfig.modules.Jar(i) { + modules = append(modules, module) + found = true + break + } + } + if !found && !ctx.Config().AllowMissingDependencies() { + ctx.ModuleErrorf( + "Boot image '%s' module '%s' not added as a dependency of platform_bootclasspath", + imageConfig.name, + imageConfig.modules.Jar(i)) + return []android.Module{} + } + } + return modules +} diff --git a/java/platform_bootclasspath_test.go b/java/platform_bootclasspath_test.go index 10c918715..ff2da4bb2 100644 --- a/java/platform_bootclasspath_test.go +++ b/java/platform_bootclasspath_test.go @@ -18,14 +18,12 @@ import ( "testing" "android/soong/android" - "android/soong/dexpreopt" ) // Contains some simple tests for platform_bootclasspath. var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, - dexpreopt.PrepareForTestByEnablingDexpreopt, ) func TestPlatformBootclasspath(t *testing.T) { diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index 0740467eb..044802e4d 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -104,20 +104,51 @@ func prebuiltApiModuleName(mctx android.LoadHookContext, module, scope, version return fmt.Sprintf("%s_%s_%s_%s", mctx.ModuleName(), scope, version, module) } +func hasBazelPrebuilt(module string) bool { + return module == "android" || module == "core-for-system-modules" +} + +func bazelPrebuiltApiModuleName(module, scope, version string) string { + bazelModule := module + switch module { + case "android": + bazelModule = "android_jar" + case "core-for-system-modules": + bazelModule = "core_jar" + } + bazelVersion := version + if version == "current" { + bazelVersion = strconv.Itoa(android.FutureApiLevelInt) + } + bazelScope := scope + switch scope { + case "module-lib": + bazelScope = "module" + case "system-server": + bazelScope = "system_server" + } + return fmt.Sprintf("//prebuilts/sdk:%s_%s_%s", bazelScope, bazelVersion, bazelModule) +} + func createImport(mctx android.LoadHookContext, module, scope, version, path, sdkVersion string, compileDex bool) { props := struct { - Name *string - Jars []string - Sdk_version *string - Installable *bool - Compile_dex *bool - }{} - props.Name = proptools.StringPtr(prebuiltApiModuleName(mctx, module, scope, version)) - props.Jars = append(props.Jars, path) - props.Sdk_version = proptools.StringPtr(sdkVersion) - props.Installable = proptools.BoolPtr(false) - props.Compile_dex = proptools.BoolPtr(compileDex) - + Name *string + Jars []string + Sdk_version *string + Installable *bool + Compile_dex *bool + Bazel_module android.BazelModuleProperties + }{ + Name: proptools.StringPtr(prebuiltApiModuleName(mctx, module, scope, version)), + Jars: []string{path}, + Sdk_version: proptools.StringPtr(sdkVersion), + Installable: proptools.BoolPtr(false), + Compile_dex: proptools.BoolPtr(compileDex), + } + if hasBazelPrebuilt(module) { + props.Bazel_module = android.BazelModuleProperties{ + Label: proptools.StringPtr(bazelPrebuiltApiModuleName(module, scope, version))} + } mctx.CreateModule(ImportFactory, &props) } diff --git a/java/testing.go b/java/testing.go index f68e12ff4..6671bf0c7 100644 --- a/java/testing.go +++ b/java/testing.go @@ -80,9 +80,7 @@ var prepareForTestWithFrameworkDeps = android.GroupFixturePreparers( }.AddToFixture(), ) -// Test fixture preparer that will define all default java modules except the -// fake_tool_binary for dex2oatd. -var PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd = android.GroupFixturePreparers( +var prepareForTestWithJavaDefaultModulesBase = android.GroupFixturePreparers( // Make sure that all the module types used in the defaults are registered. PrepareForTestWithJavaBuildComponents, prepareForTestWithFrameworkDeps, @@ -92,13 +90,21 @@ var PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd = android.GroupFixtu // Test fixture preparer that will define default java modules, e.g. standard prebuilt modules. var PrepareForTestWithJavaDefaultModules = android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd, - dexpreopt.PrepareForTestWithFakeDex2oatd, + prepareForTestWithJavaDefaultModulesBase, + dexpreopt.FixtureDisableDexpreoptBootImages(true), + dexpreopt.FixtureDisableDexpreopt(true), ) // Provides everything needed by dexpreopt. var PrepareForTestWithDexpreopt = android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, + prepareForTestWithJavaDefaultModulesBase, + dexpreopt.PrepareForTestWithFakeDex2oatd, + dexpreopt.PrepareForTestByEnablingDexpreopt, +) + +// Provides everything needed by dexpreopt except the fake_tool_binary for dex2oatd. +var PrepareForTestWithDexpreoptWithoutFakeDex2oatd = android.GroupFixturePreparers( + prepareForTestWithJavaDefaultModulesBase, dexpreopt.PrepareForTestByEnablingDexpreopt, ) @@ -604,9 +610,9 @@ func FixtureModifyBootImageConfig(name string, configModifier func(*bootImageCon }) } -// Sets the value of `installDirOnDevice` of the boot image config with the given name. +// Sets the value of `installDir` of the boot image config with the given name. func FixtureSetBootImageInstallDirOnDevice(name string, installDir string) android.FixturePreparer { return FixtureModifyBootImageConfig(name, func(config *bootImageConfig) { - config.installDirOnDevice = installDir + config.installDir = installDir }) } diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go index 77394d964..8225df60d 100644 --- a/mk2rbc/mk2rbc.go +++ b/mk2rbc/mk2rbc.go @@ -163,6 +163,21 @@ var ignoredDefines = map[string]bool{ var identifierFullMatchRegex = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$") +func RelativeToCwd(path string) (string, error) { + cwd, err := os.Getwd() + if err != nil { + return "", err + } + path, err = filepath.Rel(cwd, path) + if err != nil { + return "", err + } + if strings.HasPrefix(path, "../") { + return "", fmt.Errorf("Could not make path relative to current working directory: " + path) + } + return path, nil +} + // Conversion request parameters type Request struct { MkFile string // file to convert @@ -320,6 +335,14 @@ func (gctx *generationContext) emitPreamble() { loadedSubConfigs := make(map[string]string) for _, mi := range gctx.starScript.inherited { uri := mi.path + if strings.HasPrefix(uri, "/") && !strings.HasPrefix(uri, "//") { + var err error + uri, err = RelativeToCwd(uri) + if err != nil { + panic(err) + } + uri = "//" + uri + } if m, ok := loadedSubConfigs[uri]; ok { // No need to emit load statement, but fix module name. mi.moduleLocalName = m diff --git a/mk2rbc/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc/mk2rbc.go index cc83430a8..08c363f1b 100644 --- a/mk2rbc/mk2rbc/mk2rbc.go +++ b/mk2rbc/mk2rbc/mk2rbc.go @@ -187,7 +187,7 @@ func main() { quit(fmt.Errorf("the product launcher input variables file failed to convert")) } - err := writeGenerated(*launcher, mk2rbc.Launcher(outputFilePath(files[0]), outputFilePath(*inputVariables), + err := writeGenerated(*launcher, mk2rbc.Launcher(outputModulePath(files[0]), outputModulePath(*inputVariables), mk2rbc.MakePath2ModuleName(files[0]))) if err != nil { fmt.Fprintf(os.Stderr, "%s: %s", files[0], err) @@ -205,7 +205,7 @@ func main() { quit(fmt.Errorf("the board launcher input variables file failed to convert")) } err := writeGenerated(*boardlauncher, mk2rbc.BoardLauncher( - outputFilePath(files[0]), outputFilePath(*inputVariables))) + outputModulePath(files[0]), outputModulePath(*inputVariables))) if err != nil { fmt.Fprintf(os.Stderr, "%s: %s", files[0], err) ok = false @@ -402,6 +402,15 @@ func outputFilePath(mkFile string) string { return path } +func outputModulePath(mkFile string) string { + path := outputFilePath(mkFile) + path, err := mk2rbc.RelativeToCwd(path) + if err != nil { + panic(err) + } + return "//" + path +} + func writeGenerated(path string, contents string) error { if err := os.MkdirAll(filepath.Dir(path), os.ModeDir|os.ModePerm); err != nil { return err diff --git a/mk2rbc/soong_variables_test.go b/mk2rbc/soong_variables_test.go index c883882c4..58e98f68e 100644 --- a/mk2rbc/soong_variables_test.go +++ b/mk2rbc/soong_variables_test.go @@ -42,8 +42,8 @@ func TestSoongVariables(t *testing.T) { {"BUILD_ID", VarClassSoong, starlarkTypeString}, {"PLATFORM_SDK_VERSION", VarClassSoong, starlarkTypeInt}, {"DEVICE_PACKAGE_OVERLAYS", VarClassSoong, starlarkTypeList}, - {"ENABLE_CFI", VarClassSoong, starlarkTypeBool}, - {"ENABLE_PREOPT", VarClassSoong, starlarkTypeBool}, + {"ENABLE_CFI", VarClassSoong, starlarkTypeString}, + {"ENABLE_PREOPT", VarClassSoong, starlarkTypeString}, }} if !reflect.DeepEqual(expected, actual) { t.Errorf("\nExpected: %v\n Actual: %v", expected, actual) diff --git a/rust/bindgen.go b/rust/bindgen.go index 13fa81e66..96645b075 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -29,7 +29,7 @@ var ( defaultBindgenFlags = []string{""} // bindgen should specify its own Clang revision so updating Clang isn't potentially blocked on bindgen failures. - bindgenClangVersion = "clang-r487747" + bindgenClangVersion = "clang-r487747c" _ = pctx.VariableFunc("bindgenClangVersion", func(ctx android.PackageVarContext) string { if override := ctx.Config().Getenv("LLVM_BINDGEN_PREBUILTS_VERSION"); override != "" { diff --git a/rust/config/global.go b/rust/config/global.go index 2d1f0c1f9..748bb3d2f 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -24,7 +24,7 @@ import ( var pctx = android.NewPackageContext("android/soong/rust/config") var ( - RustDefaultVersion = "1.68.0" + RustDefaultVersion = "1.69.0" RustDefaultBase = "prebuilts/rust/" DefaultEdition = "2021" Stdlibs = []string{ diff --git a/rust/fuzz.go b/rust/fuzz.go index d7e7ddfff..c2b940525 100644 --- a/rust/fuzz.go +++ b/rust/fuzz.go @@ -31,7 +31,7 @@ type fuzzDecorator struct { *binaryDecorator fuzzPackagedModule fuzz.FuzzPackagedModule - sharedLibraries android.Paths + sharedLibraries android.RuleBuilderInstalls installedSharedDeps []string } @@ -119,15 +119,17 @@ func (fuzz *fuzzDecorator) install(ctx ModuleContext) { // Grab the list of required shared libraries. fuzz.sharedLibraries, _ = cc.CollectAllSharedDependencies(ctx) - for _, lib := range fuzz.sharedLibraries { + for _, ruleBuilderInstall := range fuzz.sharedLibraries { + install := ruleBuilderInstall.To + fuzz.installedSharedDeps = append(fuzz.installedSharedDeps, cc.SharedLibraryInstallLocation( - lib, ctx.Host(), installBase, ctx.Arch().ArchType.String())) + install, ctx.Host(), installBase, ctx.Arch().ArchType.String())) // Also add the dependency on the shared library symbols dir. if !ctx.Host() { fuzz.installedSharedDeps = append(fuzz.installedSharedDeps, - cc.SharedLibrarySymbolsInstallLocation(lib, installBase, ctx.Arch().ArchType.String())) + cc.SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String())) } } } diff --git a/rust/rust.go b/rust/rust.go index 7b520cdb0..dc53cc028 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -649,7 +649,7 @@ func (mod *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule { panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", mod.BaseModuleName())) } -func (mod *Module) FuzzSharedLibraries() android.Paths { +func (mod *Module) FuzzSharedLibraries() android.RuleBuilderInstalls { if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { return fuzzer.sharedLibraries } diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 0d6496dd3..bef82d601 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -74,7 +74,7 @@ func fixtureAddPrebuiltApexForBootclasspathFragment(apex, fragment string) andro func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, - java.PrepareForTestWithJavaDefaultModules, + java.PrepareForTestWithDexpreopt, prepareForSdkTestWithApex, // Some additional files needed for the art apex. diff --git a/tests/bootstrap_test.sh b/tests/bootstrap_test.sh index fda5ca086..59352477c 100755 --- a/tests/bootstrap_test.sh +++ b/tests/bootstrap_test.sh @@ -885,4 +885,37 @@ function test_queryview_null_build() { fi } +# This test verifies that adding a new glob to a blueprint file only +# causes build.ninja to be regenerated on the *next* build, and *not* +# the build after. (This is a regression test for a bug where globs +# resulted in two successive regenerations.) +function test_new_glob_incrementality { + setup + + run_soong nothing + local -r mtime1=$(stat -c "%y" out/soong/build.ninja) + + mkdir -p globdefpkg/ + cat > globdefpkg/Android.bp <<'EOF' +filegroup { + name: "fg_with_glob", + srcs: ["*.txt"], +} +EOF + + run_soong nothing + local -r mtime2=$(stat -c "%y" out/soong/build.ninja) + + if [[ "$mtime1" == "$mtime2" ]]; then + fail "Ninja file was not regenerated, despite a new bp file" + fi + + run_soong nothing + local -r mtime3=$(stat -c "%y" out/soong/build.ninja) + + if [[ "$mtime2" != "$mtime3" ]]; then + fail "Ninja file was regenerated despite no previous bp changes" + fi +} + scan_and_run_tests diff --git a/ui/build/Android.bp b/ui/build/Android.bp index b79754cbe..959ae4c69 100644 --- a/ui/build/Android.bp +++ b/ui/build/Android.bp @@ -46,6 +46,7 @@ bootstrap_go_package { "soong-ui-tracer", ], srcs: [ + "bazel_metrics.go", "build.go", "cleanbuild.go", "config.go", diff --git a/ui/build/bazel_metrics.go b/ui/build/bazel_metrics.go new file mode 100644 index 000000000..c0690c1e7 --- /dev/null +++ b/ui/build/bazel_metrics.go @@ -0,0 +1,135 @@ +// Copyright 2023 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 build + +// This file contains functionality to parse bazel profile data into +// a bazel_metrics proto, defined in build/soong/ui/metrics/bazel_metrics_proto +// These metrics are later uploaded in upload.go + +import ( + "bufio" + "os" + "strconv" + "strings" + + "android/soong/shared" + "google.golang.org/protobuf/proto" + + bazel_metrics_proto "android/soong/ui/metrics/bazel_metrics_proto" +) + +func parseTimingToNanos(str string) int64 { + millisString := removeDecimalPoint(str) + timingMillis, _ := strconv.ParseInt(millisString, 10, 64) + return timingMillis * 1000000 +} + +func parsePercentageToTenThousandths(str string) int32 { + percentageString := removeDecimalPoint(str) + //remove the % at the end of the string + percentage := strings.ReplaceAll(percentageString, "%", "") + percentagePortion, _ := strconv.ParseInt(percentage, 10, 32) + return int32(percentagePortion) +} + +func removeDecimalPoint(numString string) string { + // The format is always 0.425 or 10.425 + return strings.ReplaceAll(numString, ".", "") +} + +func parseTotal(line string) int64 { + words := strings.Fields(line) + timing := words[3] + return parseTimingToNanos(timing) +} + +func parsePhaseTiming(line string) bazel_metrics_proto.PhaseTiming { + words := strings.Fields(line) + getPhaseNameAndTimingAndPercentage := func([]string) (string, int64, int32) { + // Sample lines include: + // Total launch phase time 0.011 s 2.59% + // Total target pattern evaluation phase time 0.011 s 2.59% + var beginning int + var end int + for ind, word := range words { + if word == "Total" { + beginning = ind + 1 + } else if beginning > 0 && word == "phase" { + end = ind + break + } + } + phaseName := strings.Join(words[beginning:end], " ") + + // end is now "phase" - advance by 2 for timing and 4 for percentage + percentageString := words[end+4] + timingString := words[end+2] + timing := parseTimingToNanos(timingString) + percentagePortion := parsePercentageToTenThousandths(percentageString) + return phaseName, timing, percentagePortion + } + + phaseName, timing, portion := getPhaseNameAndTimingAndPercentage(words) + phaseTiming := bazel_metrics_proto.PhaseTiming{} + phaseTiming.DurationNanos = &timing + phaseTiming.PortionOfBuildTime = &portion + + phaseTiming.PhaseName = &phaseName + return phaseTiming +} + +// This method takes a file created by bazel's --analyze-profile mode and +// writes bazel metrics data to the provided filepath. +func ProcessBazelMetrics(bazelProfileFile string, bazelMetricsFile string, ctx Context, config Config) { + if bazelProfileFile == "" { + return + } + + readBazelProto := func(filepath string) bazel_metrics_proto.BazelMetrics { + //serialize the proto, write it + bazelMetrics := bazel_metrics_proto.BazelMetrics{} + + file, err := os.ReadFile(filepath) + if err != nil { + ctx.Fatalln("Error reading metrics file\n", err) + } + + scanner := bufio.NewScanner(strings.NewReader(string(file))) + scanner.Split(bufio.ScanLines) + + var phaseTimings []*bazel_metrics_proto.PhaseTiming + for scanner.Scan() { + line := scanner.Text() + if strings.HasPrefix(line, "Total run time") { + total := parseTotal(line) + bazelMetrics.Total = &total + } else if strings.HasPrefix(line, "Total") { + phaseTiming := parsePhaseTiming(line) + phaseTimings = append(phaseTimings, &phaseTiming) + } + } + bazelMetrics.PhaseTimings = phaseTimings + + return bazelMetrics + } + + if _, err := os.Stat(bazelProfileFile); err != nil { + // We can assume bazel didn't run if the profile doesn't exist + return + } + bazelProto := readBazelProto(bazelProfileFile) + bazelProto.ExitCode = proto.Int32(config.bazelExitCode) + shared.Save(&bazelProto, bazelMetricsFile) +} diff --git a/ui/build/config.go b/ui/build/config.go index 8ec96800f..6b6ce7154 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -316,8 +316,9 @@ func UploadOnlyConfig(ctx Context, args ...string) Config { func NewConfig(ctx Context, args ...string) Config { ret := &configImpl{ - environ: OsEnvironment(), - sandboxConfig: &SandboxConfig{}, + environ: OsEnvironment(), + sandboxConfig: &SandboxConfig{}, + ninjaWeightListSource: HINT_FROM_SOONG, } // Default matching ninja diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go index b83b5cba3..efe747819 100644 --- a/ui/build/dumpvars.go +++ b/ui/build/dumpvars.go @@ -150,7 +150,6 @@ var BannerVars = []string{ "PRODUCT_INCLUDE_TAGS", "PRODUCT_SOURCE_ROOT_DIRS", "TARGET_PRODUCT", - "TARGET_RELEASE", "TARGET_BUILD_VARIANT", "TARGET_BUILD_APPS", "TARGET_BUILD_UNBUNDLED", diff --git a/ui/build/finder.go b/ui/build/finder.go index 3f628cf7b..62079fee9 100644 --- a/ui/build/finder.go +++ b/ui/build/finder.go @@ -87,6 +87,8 @@ func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) { "TEST_MAPPING", // Bazel top-level file to mark a directory as a Bazel workspace. "WORKSPACE", + // METADATA file of packages + "METADATA", }, // Bazel Starlark configuration files and all .mk files for product/board configuration. IncludeSuffixes: []string{".bzl", ".mk"}, @@ -189,6 +191,13 @@ func FindSources(ctx Context, config Config, f *finder.Finder) { ctx.Fatalf("Could not find OWNERS: %v", err) } + // Recursively look for all METADATA files. + metadataFiles := f.FindNamedAt(".", "METADATA") + err = dumpListToFile(ctx, config, metadataFiles, filepath.Join(dumpDir, "METADATA.list")) + if err != nil { + ctx.Fatalf("Could not find METADATA: %v", err) + } + // Recursively look for all TEST_MAPPING files. testMappings := f.FindNamedAt(".", "TEST_MAPPING") err = dumpListToFile(ctx, config, testMappings, filepath.Join(dumpDir, "TEST_MAPPING.list")) diff --git a/ui/build/soong.go b/ui/build/soong.go index 563199bee..18bf3b912 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -400,6 +400,8 @@ func bootstrapBlueprint(ctx Context, config Config) { pbi.Inputs = append(pbi.Inputs, config.Bp2BuildFilesMarkerFile(), filepath.Join(config.FileListDir(), "bazel.list")) + case bp2buildFilesTag: + pbi.Inputs = append(pbi.Inputs, filepath.Join(config.FileListDir(), "METADATA.list")) } invocations = append(invocations, pbi) } diff --git a/ui/build/upload.go b/ui/build/upload.go index ee4a5b345..9f14bdd7c 100644 --- a/ui/build/upload.go +++ b/ui/build/upload.go @@ -18,21 +18,16 @@ package build // another. import ( - "bufio" "fmt" "io/ioutil" "os" "path/filepath" - "strconv" - "strings" "time" - "android/soong/shared" "android/soong/ui/metrics" "google.golang.org/protobuf/proto" - bazel_metrics_proto "android/soong/ui/metrics/bazel_metrics_proto" upload_proto "android/soong/ui/metrics/upload_proto" ) @@ -78,123 +73,16 @@ func pruneMetricsFiles(paths []string) []string { return metricsFiles } -func parseTimingToNanos(str string) int64 { - millisString := removeDecimalPoint(str) - timingMillis, _ := strconv.ParseInt(millisString, 10, 64) - return timingMillis * 1000000 -} - -func parsePercentageToTenThousandths(str string) int32 { - percentageString := removeDecimalPoint(str) - //remove the % at the end of the string - percentage := strings.ReplaceAll(percentageString, "%", "") - percentagePortion, _ := strconv.ParseInt(percentage, 10, 32) - return int32(percentagePortion) -} - -func removeDecimalPoint(numString string) string { - // The format is always 0.425 or 10.425 - return strings.ReplaceAll(numString, ".", "") -} - -func parseTotal(line string) int64 { - words := strings.Fields(line) - timing := words[3] - return parseTimingToNanos(timing) -} - -func parsePhaseTiming(line string) bazel_metrics_proto.PhaseTiming { - words := strings.Fields(line) - getPhaseNameAndTimingAndPercentage := func([]string) (string, int64, int32) { - // Sample lines include: - // Total launch phase time 0.011 s 2.59% - // Total target pattern evaluation phase time 0.011 s 2.59% - var beginning int - var end int - for ind, word := range words { - if word == "Total" { - beginning = ind + 1 - } else if beginning > 0 && word == "phase" { - end = ind - break - } - } - phaseName := strings.Join(words[beginning:end], " ") - - // end is now "phase" - advance by 2 for timing and 4 for percentage - percentageString := words[end+4] - timingString := words[end+2] - timing := parseTimingToNanos(timingString) - percentagePortion := parsePercentageToTenThousandths(percentageString) - return phaseName, timing, percentagePortion - } - - phaseName, timing, portion := getPhaseNameAndTimingAndPercentage(words) - phaseTiming := bazel_metrics_proto.PhaseTiming{} - phaseTiming.DurationNanos = &timing - phaseTiming.PortionOfBuildTime = &portion - - phaseTiming.PhaseName = &phaseName - return phaseTiming -} - -// This method takes a file created by bazel's --analyze-profile mode and -// writes bazel metrics data to the provided filepath. -// TODO(b/279987768) - move this outside of upload.go -func processBazelMetrics(bazelProfileFile string, bazelMetricsFile string, ctx Context, config Config) { - if bazelProfileFile == "" { - return - } - - readBazelProto := func(filepath string) bazel_metrics_proto.BazelMetrics { - //serialize the proto, write it - bazelMetrics := bazel_metrics_proto.BazelMetrics{} - - file, err := os.ReadFile(filepath) - if err != nil { - ctx.Fatalln("Error reading metrics file\n", err) - } - - scanner := bufio.NewScanner(strings.NewReader(string(file))) - scanner.Split(bufio.ScanLines) - - var phaseTimings []*bazel_metrics_proto.PhaseTiming - for scanner.Scan() { - line := scanner.Text() - if strings.HasPrefix(line, "Total run time") { - total := parseTotal(line) - bazelMetrics.Total = &total - } else if strings.HasPrefix(line, "Total") { - phaseTiming := parsePhaseTiming(line) - phaseTimings = append(phaseTimings, &phaseTiming) - } - } - bazelMetrics.PhaseTimings = phaseTimings - - return bazelMetrics - } - - if _, err := os.Stat(bazelProfileFile); err != nil { - // We can assume bazel didn't run if the profile doesn't exist - return - } - bazelProto := readBazelProto(bazelProfileFile) - bazelProto.ExitCode = proto.Int32(config.bazelExitCode) - shared.Save(&bazelProto, bazelMetricsFile) -} - // UploadMetrics uploads a set of metrics files to a server for analysis. // The metrics files are first copied to a temporary directory // and the uploader is then executed in the background to allow the user/system // to continue working. Soong communicates to the uploader through the // upload_proto raw protobuf file. -func UploadMetrics(ctx Context, config Config, simpleOutput bool, buildStarted time.Time, bazelProfileFile string, bazelMetricsFile string, paths ...string) { +func UploadMetrics(ctx Context, config Config, simpleOutput bool, buildStarted time.Time, paths ...string) { ctx.BeginTrace(metrics.RunSetupTool, "upload_metrics") defer ctx.EndTrace() uploader := config.MetricsUploaderApp() - processBazelMetrics(bazelProfileFile, bazelMetricsFile, ctx, config) - if uploader == "" { // If the uploader path was not specified, no metrics shall be uploaded. return diff --git a/ui/build/upload_test.go b/ui/build/upload_test.go index 58d923702..1fcded921 100644 --- a/ui/build/upload_test.go +++ b/ui/build/upload_test.go @@ -166,7 +166,7 @@ func TestUploadMetrics(t *testing.T) { metricsUploader: tt.uploader, }} - UploadMetrics(ctx, config, false, time.Now(), "out/bazel_metrics.txt", "out/bazel_metrics.pb", metricsFiles...) + UploadMetrics(ctx, config, false, time.Now(), metricsFiles...) }) } } @@ -221,7 +221,7 @@ func TestUploadMetricsErrors(t *testing.T) { metricsUploader: "echo", }} - UploadMetrics(ctx, config, true, time.Now(), "", "", metricsFile) + UploadMetrics(ctx, config, true, time.Now(), metricsFile) t.Errorf("got nil, expecting %q as a failure", tt.expectedErr) }) } diff --git a/zip/cmd/main.go b/zip/cmd/main.go index def76aa62..a2ccc2011 100644 --- a/zip/cmd/main.go +++ b/zip/cmd/main.go @@ -78,6 +78,15 @@ func (rspFiles) Set(s string) error { return nil } +type explicitFile struct{} + +func (explicitFile) String() string { return `""` } + +func (explicitFile) Set(s string) error { + fileArgsBuilder.ExplicitPathInZip(s) + return nil +} + type dir struct{} func (dir) String() string { return `""` } @@ -173,6 +182,7 @@ func main() { flags.Var(&nonDeflatedFiles, "s", "file path to be stored within the zip without compression") flags.Var(&relativeRoot{}, "C", "path to use as relative root of files in following -f, -l, or -D arguments") flags.Var(&junkPaths{}, "j", "junk paths, zip files without directory names") + flags.Var(&explicitFile{}, "e", "filename to use in the zip file for the next -f argument") flags.Parse(expandedArgs[1:]) diff --git a/zip/zip.go b/zip/zip.go index 6f1a8adaf..5e1a10462 100644 --- a/zip/zip.go +++ b/zip/zip.go @@ -80,6 +80,7 @@ type pathMapping struct { type FileArg struct { PathPrefixInZip, SourcePrefixToStrip string + ExplicitPathInZip string SourceFiles []string JunkPaths bool GlobDir string @@ -124,6 +125,10 @@ func (b *FileArgsBuilder) File(name string) *FileArgsBuilder { arg := b.state arg.SourceFiles = []string{name} b.fileArgs = append(b.fileArgs, arg) + + if b.state.ExplicitPathInZip != "" { + b.state.ExplicitPathInZip = "" + } return b } @@ -189,6 +194,12 @@ func (b *FileArgsBuilder) RspFile(name string) *FileArgsBuilder { return b } +// ExplicitPathInZip sets the path in the zip file for the next File call. +func (b *FileArgsBuilder) ExplicitPathInZip(s string) *FileArgsBuilder { + b.state.ExplicitPathInZip = s + return b +} + func (b *FileArgsBuilder) Error() error { if b == nil { return nil @@ -425,7 +436,9 @@ func fillPathPairs(fa FileArg, src string, pathMappings *[]pathMapping, var dest string - if fa.JunkPaths { + if fa.ExplicitPathInZip != "" { + dest = fa.ExplicitPathInZip + } else if fa.JunkPaths { dest = filepath.Base(src) } else { var err error diff --git a/zip/zip_test.go b/zip/zip_test.go index e7fdea839..c64c3f499 100644 --- a/zip/zip_test.go +++ b/zip/zip_test.go @@ -454,6 +454,60 @@ func TestZip(t *testing.T) { fhWithSHA256("c", fileC, zip.Deflate, sha256FileC), }, }, + { + name: "explicit path", + args: fileArgsBuilder(). + ExplicitPathInZip("foo"). + File("a/a/a"). + File("a/a/b"), + compressionLevel: 9, + + files: []zip.FileHeader{ + fh("foo", fileA, zip.Deflate), + fh("a/a/b", fileB, zip.Deflate), + }, + }, + { + name: "explicit path with prefix", + args: fileArgsBuilder(). + PathPrefixInZip("prefix"). + ExplicitPathInZip("foo"). + File("a/a/a"). + File("a/a/b"), + compressionLevel: 9, + + files: []zip.FileHeader{ + fh("prefix/foo", fileA, zip.Deflate), + fh("prefix/a/a/b", fileB, zip.Deflate), + }, + }, + { + name: "explicit path with glob", + args: fileArgsBuilder(). + ExplicitPathInZip("foo"). + File("a/a/a*"). + File("a/a/b"), + compressionLevel: 9, + + files: []zip.FileHeader{ + fh("foo", fileA, zip.Deflate), + fh("a/a/b", fileB, zip.Deflate), + }, + }, + { + name: "explicit path with junk paths", + args: fileArgsBuilder(). + JunkPaths(true). + ExplicitPathInZip("foo/bar"). + File("a/a/a*"). + File("a/a/b"), + compressionLevel: 9, + + files: []zip.FileHeader{ + fh("foo/bar", fileA, zip.Deflate), + fh("b", fileB, zip.Deflate), + }, + }, // errors { @@ -490,6 +544,22 @@ func TestZip(t *testing.T) { File("d/a/a"), err: ConflictingFileError{}, }, + { + name: "error explicit path conflicting", + args: fileArgsBuilder(). + ExplicitPathInZip("foo"). + File("a/a/a"). + ExplicitPathInZip("foo"). + File("a/a/b"), + err: ConflictingFileError{}, + }, + { + name: "error explicit path conflicting glob", + args: fileArgsBuilder(). + ExplicitPathInZip("foo"). + File("a/a/*"), + err: ConflictingFileError{}, + }, } for _, test := range testCases { |