From 0aa578930f10b4d8fc890752e3cb14c56b5c31af Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 28 Apr 2022 14:13:30 +0000 Subject: Allow framework-media to build the framework-media.impl (cherry picked from commit a083ec4acf53bd65676df31a5d99db2574a6b0aa) The framework-media java_sdk_library is currently api_only for legacy reasons. This change allows it to also build the framework-media.impl library by making the following changes: * Adds impl_only_static_libs to allow the implementation to statically include other libraries, something no other java_sdk_library has needed to do. * Passes the apex_availability property through to the impl library so it can be statically included in the updatable-media which is what is included in the apex, again for legacy reasons. Bug: 190807367 Bug: 229932396 Test: m com.android.media media-module-sdk # Compare before and after this change (and corresponding change # to updatable-media/framework-media. Merged-In: I9e1837edcca6f5fa84fc611274cf8fbba8a896b8 Change-Id: I9e1837edcca6f5fa84fc611274cf8fbba8a896b8 --- java/sdk_library.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/java/sdk_library.go b/java/sdk_library.go index c37ed1a27..fb032559e 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -377,6 +377,9 @@ type sdkLibraryProperties struct { // List of Java libraries that will be in the classpath when building the implementation lib Impl_only_libs []string `android:"arch_variant"` + // List of Java libraries that will included in the implementation lib. + Impl_only_static_libs []string `android:"arch_variant"` + // List of Java libraries that will be in the classpath when building stubs Stub_only_libs []string `android:"arch_variant"` @@ -1346,10 +1349,12 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) visibility := childModuleVisibility(module.sdkLibraryProperties.Impl_library_visibility) props := struct { - Name *string - Visibility []string - Instrument bool - Libs []string + Name *string + Visibility []string + Instrument bool + Libs []string + Static_libs []string + Apex_available []string }{ Name: proptools.StringPtr(module.implLibraryModuleName()), Visibility: visibility, @@ -1358,6 +1363,12 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) // Set the impl_only libs. Note that the module's "Libs" get appended as well, via the // addition of &module.properties below. Libs: module.sdkLibraryProperties.Impl_only_libs, + // Set the impl_only static libs. Note that the module's "static_libs" get appended as well, via the + // addition of &module.properties below. + Static_libs: module.sdkLibraryProperties.Impl_only_static_libs, + // Pass the apex_available settings down so that the impl library can be statically + // embedded within a library that is added to an APEX. Needed for updatable-media. + Apex_available: module.ApexAvailable(), } properties := []interface{}{ @@ -1814,8 +1825,9 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookCont *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) } - // Add the impl_only_libs *after* we're done using the Libs prop in submodules. + // Add the impl_only_libs and impl_only_static_libs *after* we're done using them in submodules. module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) + module.properties.Static_libs = append(module.properties.Static_libs, module.sdkLibraryProperties.Impl_only_static_libs...) } func (module *SdkLibrary) InitSdkLibraryProperties() { -- cgit v1.2.3 From cfbdc3bb69fc2952653d21a0b67da58f46701753 Mon Sep 17 00:00:00 2001 From: William Escande Date: Fri, 3 Jun 2022 19:10:26 -0700 Subject: Clear apex.go entries for bluetooth libs The module availability to Bluetooth is currently hard-coded in apex.go. We are in the process of cleaning the apex.go by adding the availability in each required module Test: Build + TH + boot phone & use bluetooth Bug: 216433795 Change-Id: I545ad6039e501c70e3ff5d9fc74fabfd37067145 --- apex/apex.go | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 6e6174334..66a98c0bc 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2776,31 +2776,7 @@ func makeApexAvailableBaseline() map[string][]string { // Module separator // m["com.android.bluetooth"] = []string{ - "bluetooth-protos-lite", - "internal_include_headers", - "libaudio-a2dp-hw-utils", - "libaudio-hearing-aid-hw-utils", - "libbluetooth", - "libbluetooth-types", - "libbluetooth-types-header", - "libbluetooth_gd", - "libbluetooth_headers", - "libbluetooth_jni", - "libbt-audio-hal-interface", - "libbt-bta", - "libbt-common", - "libbt-hci", - "libbt-platform-protos-lite", - "libbt-protos-lite", - "libbt-sbc-decoder", - "libbt-sbc-encoder", - "libbt-stack", - "libbt-utils", - "libbtcore", - "libbtdevice", - "libbte", - "libbtif", - "libchrome", + // empty } // // Module separator -- cgit v1.2.3 From 5990257d46b4407ffdd675dae201d3804ceb707b Mon Sep 17 00:00:00 2001 From: Kousik Kumar Date: Fri, 18 Mar 2022 02:50:31 -0400 Subject: Do not dump metrics if reproxy was never started Dumping of RBE metrics should only happen when reproxy was started. Reproxy is started only when Soong is run in make / build mode and not in dumpvars mode. Doc: https://docs.google.com/document/d/1Iqhu5QgozB_rA9fucMHO6X4U6A8e8qFtZyub9j83ICQ/edit# Test: Ran a build with / without RBE. No metrics dumped during lunch without RBE and metrics dumping worked as expected with RBE. Bug: b/197213143 Bug: b/236909178 Bug: b/235861862 Merged-In: Ic3403331e1f4ac2c7c72fd9169aa7b82a7545c75 Change-Id: Ic3403331e1f4ac2c7c72fd9169aa7b82a7545c75 --- cmd/soong_ui/main.go | 1 - ui/build/build.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index 22922c0e5..5366ba2fa 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -216,7 +216,6 @@ func main() { } defer build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, files...) defer met.Dump(soongMetricsFile) - defer build.DumpRBEMetrics(buildCtx, config, rbeMetricsFile) } // Read the time at the starting point. diff --git a/ui/build/build.go b/ui/build/build.go index 8f050d9be..9668efde0 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -245,6 +245,7 @@ func Build(ctx Context, config Config) { if config.StartRBE() { startRBE(ctx, config) + defer DumpRBEMetrics(ctx, config, filepath.Join(config.LogsDir(), "rbe_metrics.pb")) } if what&RunProductConfig != 0 { -- cgit v1.2.3 From dbc313375a64c4bcafaee2bf60249595456a46e1 Mon Sep 17 00:00:00 2001 From: Kousik Kumar Date: Thu, 13 Jan 2022 02:13:10 -0500 Subject: Pass along local resource fraction to reproxy Reproxy should be respecting the -j value set by the user and not be doing excessive local executions assuming the whole machine is available to it. The local_resource_fraction flag is a way to ensure reproxy consumes CPU only upto the -j value specified by the user. Test: 1. Ran with `USE_RBE=true m -j 10 nothing` and local_resource_fraction was set to 0.14 on a 72-core workstation. 2. Ran with `USE_RBE=true m nothing` and local_resource_fraction was set to 1.0 on a 72-core machine. Bug: b/207296459 Bug: b/236909178 Bug: b/235861862 Merged-In: I118bc10109f5a55df7a6c1ecd79499320055f2ed Change-Id: I118bc10109f5a55df7a6c1ecd79499320055f2ed --- ui/build/rbe.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/build/rbe.go b/ui/build/rbe.go index d74f26210..8f9a69991 100644 --- a/ui/build/rbe.go +++ b/ui/build/rbe.go @@ -19,6 +19,7 @@ import ( "math/rand" "os" "path/filepath" + "runtime" "syscall" "time" @@ -87,6 +88,13 @@ func getRBEVars(ctx Context, config Config) map[string]string { } vars["RBE_server_address"] = fmt.Sprintf("unix://%v", name) } + + rf := 1.0 + if config.Parallel() < runtime.NumCPU() { + rf = float64(config.Parallel()) / float64(runtime.NumCPU()) + } + vars["RBE_local_resource_fraction"] = fmt.Sprintf("%.2f", rf) + k, v := config.rbeAuth() vars[k] = v return vars -- cgit v1.2.3 From 29cbe14265c9679d6de5a5785a95137c178fe1eb Mon Sep 17 00:00:00 2001 From: Kousik Kumar Date: Fri, 27 May 2022 07:48:37 -0400 Subject: [RESTRICT AUTOMERGE] Cleanup RBE logs directory RBE logs directory is currently messy: 1. We use RBE_output_dir variable to specify where rbe_metrics.txt / rbe_metrics.pb file should go to. 2. We use proxy_log_dir to specify where *.rpl / *.rpi (detailed per action info log file) should go to. 3. We use RBE_log_dir to specify where reproxy.* / bootstrap.* log files should go to. Ideally, all RBE related logs should go to one single directory. In this CL, I'm creating a temporary log directory under out/soong/.temp/rbe/ where all RBE related log files per build would go to. The log dir prefix is also being set to the same prefix as the socket address file. Test: Ran a sample build with `m libc` and ensured that logs are getting cleared across rebuilds and that `rbe_metrics.pb` file is properly generated and being copied to the right location (i.e., from out/soong/.temp/rbe/ to out/ dir) Bug: b/233382420 Bug: b/236909178 Bug: b/235861862 Merged-In: I46bd38d50419cb9e54e8202d24222979e47ff5ca Change-Id: I46bd38d50419cb9e54e8202d24222979e47ff5ca --- ui/build/build.go | 1 + ui/build/config.go | 59 ++++++++++++++++++++++++++++++++++------------------ ui/build/rbe.go | 47 +++++++++++++++++++---------------------- ui/build/rbe_test.go | 3 ++- 4 files changed, 63 insertions(+), 47 deletions(-) diff --git a/ui/build/build.go b/ui/build/build.go index 9668efde0..8f7f64b11 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -244,6 +244,7 @@ func Build(ctx Context, config Config) { } if config.StartRBE() { + cleanupRBELogsDir(ctx, config) startRBE(ctx, config) defer DumpRBEMetrics(ctx, config, filepath.Join(config.LogsDir(), "rbe_metrics.pb")) } diff --git a/ui/build/config.go b/ui/build/config.go index 4ee759f85..249af3a1a 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -18,11 +18,13 @@ import ( "encoding/json" "fmt" "io/ioutil" + "math/rand" "os" "path/filepath" "runtime" "strconv" "strings" + "syscall" "time" "android/soong/shared" @@ -37,6 +39,15 @@ const ( jsonSuffix = "json" ) +var ( + rbeRandPrefix int +) + +func init() { + rand.Seed(time.Now().UnixNano()) + rbeRandPrefix = rand.Intn(1000) +} + type Config struct{ *configImpl } type configImpl struct { @@ -998,34 +1009,25 @@ func (c *configImpl) StartRBE() bool { return true } -func (c *configImpl) rbeLogDir() string { - for _, f := range []string{"RBE_log_dir", "FLAG_log_dir"} { - if v, ok := c.environ.Get(f); ok { - return v - } - } - if c.Dist() { - return c.LogsDir() - } - return c.OutDir() -} - -func (c *configImpl) rbeStatsOutputDir() string { - for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} { +func (c *configImpl) rbeProxyLogsDir() string { + for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} { if v, ok := c.environ.Get(f); ok { return v } } - return c.rbeLogDir() + buildTmpDir := shared.TempDirForOutDir(c.SoongOutDir()) + return filepath.Join(buildTmpDir, "rbe") } -func (c *configImpl) rbeLogPath() string { - for _, f := range []string{"RBE_log_path", "FLAG_log_path"} { - if v, ok := c.environ.Get(f); ok { - return v +func (c *configImpl) shouldCleanupRBELogsDir() bool { + // Perform a log directory cleanup only when the log directory + // is auto created by the build rather than user-specified. + for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} { + if _, ok := c.environ.Get(f); ok { + return false } } - return fmt.Sprintf("text://%v/reproxy_log.txt", c.rbeLogDir()) + return true } func (c *configImpl) rbeExecRoot() string { @@ -1077,6 +1079,23 @@ func (c *configImpl) rbeAuth() (string, string) { return "RBE_use_application_default_credentials", "true" } +func (c *configImpl) rbeSockAddr(dir string) (string, error) { + maxNameLen := len(syscall.RawSockaddrUnix{}.Path) + base := fmt.Sprintf("reproxy_%v.sock", rbeRandPrefix) + + name := filepath.Join(dir, base) + if len(name) < maxNameLen { + return name, nil + } + + name = filepath.Join("/tmp", base) + if len(name) < maxNameLen { + return name, nil + } + + return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen) +} + func (c *configImpl) UseRemoteBuild() bool { return c.UseGoma() || c.UseRBE() } diff --git a/ui/build/rbe.go b/ui/build/rbe.go index 8f9a69991..3e558f738 100644 --- a/ui/build/rbe.go +++ b/ui/build/rbe.go @@ -16,12 +16,9 @@ package build import ( "fmt" - "math/rand" "os" "path/filepath" "runtime" - "syscall" - "time" "android/soong/ui/metrics" ) @@ -54,34 +51,16 @@ func rbeCommand(ctx Context, config Config, rbeCmd string) string { return cmdPath } -func sockAddr(dir string) (string, error) { - maxNameLen := len(syscall.RawSockaddrUnix{}.Path) - rand.Seed(time.Now().UnixNano()) - base := fmt.Sprintf("reproxy_%v.sock", rand.Intn(1000)) - - name := filepath.Join(dir, base) - if len(name) < maxNameLen { - return name, nil - } - - name = filepath.Join("/tmp", base) - if len(name) < maxNameLen { - return name, nil - } - - return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen) -} - func getRBEVars(ctx Context, config Config) map[string]string { vars := map[string]string{ - "RBE_log_path": config.rbeLogPath(), - "RBE_log_dir": config.rbeLogDir(), + "RBE_log_dir": config.rbeProxyLogsDir(), "RBE_re_proxy": config.rbeReproxy(), "RBE_exec_root": config.rbeExecRoot(), - "RBE_output_dir": config.rbeStatsOutputDir(), + "RBE_output_dir": config.rbeProxyLogsDir(), + "RBE_proxy_log_dir": config.rbeProxyLogsDir(), } if config.StartRBE() { - name, err := sockAddr(absPath(ctx, config.TempDir())) + name, err := config.rbeSockAddr(absPath(ctx, config.TempDir())) if err != nil { ctx.Fatalf("Error retrieving socket address: %v", err) return nil @@ -100,6 +79,17 @@ func getRBEVars(ctx Context, config Config) map[string]string { return vars } +func cleanupRBELogsDir(ctx Context, config Config) { + if !config.shouldCleanupRBELogsDir() { + return + } + + rbeTmpDir := config.rbeProxyLogsDir() + if err := os.RemoveAll(rbeTmpDir); err != nil { + fmt.Fprintln(ctx.Writer, "\033[33mUnable to remove RBE log directory: ", err, "\033[0m") + } +} + func startRBE(ctx Context, config Config) { ctx.BeginTrace(metrics.RunSetupTool, "rbe_bootstrap") defer ctx.EndTrace() @@ -110,6 +100,11 @@ func startRBE(ctx Context, config Config) { if n := ulimitOrFatal(ctx, config, "-n"); n < rbeLeastNFiles { ctx.Fatalf("max open files is insufficient: %d; want >= %d.\n", n, rbeLeastNFiles) } + if _, err := os.Stat(config.rbeProxyLogsDir()); os.IsNotExist(err) { + if err := os.MkdirAll(config.rbeProxyLogsDir(), 0744); err != nil { + ctx.Fatalf("Unable to create logs dir (%v) for RBE: %v", config.rbeProxyLogsDir, err) + } + } cmd := Command(ctx, config, "startRBE bootstrap", rbeCommand(ctx, config, bootstrapCmd)) @@ -151,7 +146,7 @@ func DumpRBEMetrics(ctx Context, config Config, filename string) { return } - outputDir := config.rbeStatsOutputDir() + outputDir := config.rbeProxyLogsDir() if outputDir == "" { ctx.Fatal("RBE output dir variable not defined. Aborting metrics dumping.") } diff --git a/ui/build/rbe_test.go b/ui/build/rbe_test.go index 8ff96bcbb..266f76b35 100644 --- a/ui/build/rbe_test.go +++ b/ui/build/rbe_test.go @@ -56,7 +56,8 @@ func TestDumpRBEMetrics(t *testing.T) { env := Environment(tt.env) env.Set("OUT_DIR", tmpDir) env.Set("RBE_DIR", tmpDir) - env.Set("RBE_output_dir", t.TempDir()) + env.Set("RBE_output_dir", tmpDir) + env.Set("RBE_proxy_log_dir", tmpDir) config := Config{&configImpl{ environ: &env, }} -- cgit v1.2.3 From c3d9ea5a545eb35c30f7a01db1a4395ee7316fb5 Mon Sep 17 00:00:00 2001 From: Kousik Kumar Date: Fri, 27 May 2022 07:48:37 -0400 Subject: Cleanup RBE logs directory RBE logs directory is currently messy: 1. We use RBE_output_dir variable to specify where rbe_metrics.txt / rbe_metrics.pb file should go to. 2. We use proxy_log_dir to specify where *.rpl / *.rpi (detailed per action info log file) should go to. 3. We use RBE_log_dir to specify where reproxy.* / bootstrap.* log files should go to. Ideally, all RBE related logs should go to one single directory. In this CL, I'm creating a temporary log directory under out/soong/.temp/rbe/ where all RBE related log files per build would go to. The log dir prefix is also being set to the same prefix as the socket address file. Test: Ran a sample build with `m libc` and ensured that logs are getting cleared across rebuilds and that `rbe_metrics.pb` file is properly generated and being copied to the right location (i.e., from out/soong/.temp/rbe/ to out/ dir) Bug: b/233382420 Bug: b/236909178 Bug: b/235861862 Merged-In: I46bd38d50419cb9e54e8202d24222979e47ff5ca Change-Id: I46bd38d50419cb9e54e8202d24222979e47ff5ca --- ui/build/build.go | 1 + ui/build/config.go | 59 ++++++++++++++++++++++++++++++++++------------------ ui/build/rbe.go | 47 +++++++++++++++++++---------------------- ui/build/rbe_test.go | 3 ++- 4 files changed, 63 insertions(+), 47 deletions(-) diff --git a/ui/build/build.go b/ui/build/build.go index aadf4af4e..ec42b7004 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -266,6 +266,7 @@ func Build(ctx Context, config Config) { } if config.StartRBE() { + cleanupRBELogsDir(ctx, config) startRBE(ctx, config) defer DumpRBEMetrics(ctx, config, filepath.Join(config.LogsDir(), "rbe_metrics.pb")) } diff --git a/ui/build/config.go b/ui/build/config.go index e271bfca2..5765f2123 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -19,12 +19,14 @@ import ( "encoding/json" "fmt" "io/ioutil" + "math/rand" "os" "os/exec" "path/filepath" "runtime" "strconv" "strings" + "syscall" "time" "android/soong/shared" @@ -42,6 +44,15 @@ const ( envConfigFetchTimeout = 10 * time.Second ) +var ( + rbeRandPrefix int +) + +func init() { + rand.Seed(time.Now().UnixNano()) + rbeRandPrefix = rand.Intn(1000) +} + type Config struct{ *configImpl } type configImpl struct { @@ -1144,34 +1155,25 @@ func (c *configImpl) StartRBE() bool { return true } -func (c *configImpl) rbeLogDir() string { - for _, f := range []string{"RBE_log_dir", "FLAG_log_dir"} { - if v, ok := c.environ.Get(f); ok { - return v - } - } - if c.Dist() { - return c.LogsDir() - } - return c.OutDir() -} - -func (c *configImpl) rbeStatsOutputDir() string { - for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} { +func (c *configImpl) rbeProxyLogsDir() string { + for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} { if v, ok := c.environ.Get(f); ok { return v } } - return c.rbeLogDir() + buildTmpDir := shared.TempDirForOutDir(c.SoongOutDir()) + return filepath.Join(buildTmpDir, "rbe") } -func (c *configImpl) rbeLogPath() string { - for _, f := range []string{"RBE_log_path", "FLAG_log_path"} { - if v, ok := c.environ.Get(f); ok { - return v +func (c *configImpl) shouldCleanupRBELogsDir() bool { + // Perform a log directory cleanup only when the log directory + // is auto created by the build rather than user-specified. + for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} { + if _, ok := c.environ.Get(f); ok { + return false } } - return fmt.Sprintf("text://%v/reproxy_log.txt", c.rbeLogDir()) + return true } func (c *configImpl) rbeExecRoot() string { @@ -1223,6 +1225,23 @@ func (c *configImpl) rbeAuth() (string, string) { return "RBE_use_application_default_credentials", "true" } +func (c *configImpl) rbeSockAddr(dir string) (string, error) { + maxNameLen := len(syscall.RawSockaddrUnix{}.Path) + base := fmt.Sprintf("reproxy_%v.sock", rbeRandPrefix) + + name := filepath.Join(dir, base) + if len(name) < maxNameLen { + return name, nil + } + + name = filepath.Join("/tmp", base) + if len(name) < maxNameLen { + return name, nil + } + + return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen) +} + func (c *configImpl) UseRemoteBuild() bool { return c.UseGoma() || c.UseRBE() } diff --git a/ui/build/rbe.go b/ui/build/rbe.go index 8f9a69991..3e558f738 100644 --- a/ui/build/rbe.go +++ b/ui/build/rbe.go @@ -16,12 +16,9 @@ package build import ( "fmt" - "math/rand" "os" "path/filepath" "runtime" - "syscall" - "time" "android/soong/ui/metrics" ) @@ -54,34 +51,16 @@ func rbeCommand(ctx Context, config Config, rbeCmd string) string { return cmdPath } -func sockAddr(dir string) (string, error) { - maxNameLen := len(syscall.RawSockaddrUnix{}.Path) - rand.Seed(time.Now().UnixNano()) - base := fmt.Sprintf("reproxy_%v.sock", rand.Intn(1000)) - - name := filepath.Join(dir, base) - if len(name) < maxNameLen { - return name, nil - } - - name = filepath.Join("/tmp", base) - if len(name) < maxNameLen { - return name, nil - } - - return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen) -} - func getRBEVars(ctx Context, config Config) map[string]string { vars := map[string]string{ - "RBE_log_path": config.rbeLogPath(), - "RBE_log_dir": config.rbeLogDir(), + "RBE_log_dir": config.rbeProxyLogsDir(), "RBE_re_proxy": config.rbeReproxy(), "RBE_exec_root": config.rbeExecRoot(), - "RBE_output_dir": config.rbeStatsOutputDir(), + "RBE_output_dir": config.rbeProxyLogsDir(), + "RBE_proxy_log_dir": config.rbeProxyLogsDir(), } if config.StartRBE() { - name, err := sockAddr(absPath(ctx, config.TempDir())) + name, err := config.rbeSockAddr(absPath(ctx, config.TempDir())) if err != nil { ctx.Fatalf("Error retrieving socket address: %v", err) return nil @@ -100,6 +79,17 @@ func getRBEVars(ctx Context, config Config) map[string]string { return vars } +func cleanupRBELogsDir(ctx Context, config Config) { + if !config.shouldCleanupRBELogsDir() { + return + } + + rbeTmpDir := config.rbeProxyLogsDir() + if err := os.RemoveAll(rbeTmpDir); err != nil { + fmt.Fprintln(ctx.Writer, "\033[33mUnable to remove RBE log directory: ", err, "\033[0m") + } +} + func startRBE(ctx Context, config Config) { ctx.BeginTrace(metrics.RunSetupTool, "rbe_bootstrap") defer ctx.EndTrace() @@ -110,6 +100,11 @@ func startRBE(ctx Context, config Config) { if n := ulimitOrFatal(ctx, config, "-n"); n < rbeLeastNFiles { ctx.Fatalf("max open files is insufficient: %d; want >= %d.\n", n, rbeLeastNFiles) } + if _, err := os.Stat(config.rbeProxyLogsDir()); os.IsNotExist(err) { + if err := os.MkdirAll(config.rbeProxyLogsDir(), 0744); err != nil { + ctx.Fatalf("Unable to create logs dir (%v) for RBE: %v", config.rbeProxyLogsDir, err) + } + } cmd := Command(ctx, config, "startRBE bootstrap", rbeCommand(ctx, config, bootstrapCmd)) @@ -151,7 +146,7 @@ func DumpRBEMetrics(ctx Context, config Config, filename string) { return } - outputDir := config.rbeStatsOutputDir() + outputDir := config.rbeProxyLogsDir() if outputDir == "" { ctx.Fatal("RBE output dir variable not defined. Aborting metrics dumping.") } diff --git a/ui/build/rbe_test.go b/ui/build/rbe_test.go index 8ff96bcbb..266f76b35 100644 --- a/ui/build/rbe_test.go +++ b/ui/build/rbe_test.go @@ -56,7 +56,8 @@ func TestDumpRBEMetrics(t *testing.T) { env := Environment(tt.env) env.Set("OUT_DIR", tmpDir) env.Set("RBE_DIR", tmpDir) - env.Set("RBE_output_dir", t.TempDir()) + env.Set("RBE_output_dir", tmpDir) + env.Set("RBE_proxy_log_dir", tmpDir) config := Config{&configImpl{ environ: &env, }} -- cgit v1.2.3 From 89bca3f301bb4aaac4d55c9e384ffa9a530fd85d Mon Sep 17 00:00:00 2001 From: William Escande Date: Tue, 28 Jun 2022 18:03:30 -0700 Subject: Clear apex.go entries for bluetooth libs The module availability to Bluetooth is currently hard-coded in apex.go. We are in the process of cleaning the apex.go by adding the availability in each required module Test: Build + TH + boot phone & use bluetooth Bug: 216433795 Change-Id: I883a12f89a6d7eb43778e04ac50d6af38dd97116 --- apex/apex.go | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 56ccd15f7..f12c517e9 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2776,31 +2776,7 @@ func makeApexAvailableBaseline() map[string][]string { // Module separator // m["com.android.btservices"] = []string{ - "bluetooth-protos-lite", - "internal_include_headers", - "libaudio-a2dp-hw-utils", - "libaudio-hearing-aid-hw-utils", - "libbluetooth", - "libbluetooth-types", - "libbluetooth-types-header", - "libbluetooth_gd", - "libbluetooth_headers", - "libbluetooth_jni", - "libbt-audio-hal-interface", - "libbt-bta", - "libbt-common", - "libbt-hci", - "libbt-platform-protos-lite", - "libbt-protos-lite", - "libbt-sbc-decoder", - "libbt-sbc-encoder", - "libbt-stack", - "libbt-utils", - "libbtcore", - "libbtdevice", - "libbte", - "libbtif", - "libchrome", + // empty } // // Module separator -- cgit v1.2.3 From 040867f3b884c1e5959b7075e16bcae4230a2ada Mon Sep 17 00:00:00 2001 From: Kousik Kumar Date: Fri, 27 May 2022 07:48:37 -0400 Subject: [RESTRICT AUTOMERGE] Cleanup RBE logs directory RBE logs directory is currently messy: 1. We use RBE_output_dir variable to specify where rbe_metrics.txt / rbe_metrics.pb file should go to. 2. We use proxy_log_dir to specify where *.rpl / *.rpi (detailed per action info log file) should go to. 3. We use RBE_log_dir to specify where reproxy.* / bootstrap.* log files should go to. Ideally, all RBE related logs should go to one single directory. In this CL, I'm creating a temporary log directory under out/soong/.temp/rbe/ where all RBE related log files per build would go to. The log dir prefix is also being set to the same prefix as the socket address file. Test: Ran a sample build with `m libc` and ensured that logs are getting cleared across rebuilds and that `rbe_metrics.pb` file is properly generated and being copied to the right location (i.e., from out/soong/.temp/rbe/ to out/ dir) Bug: b/233382420 Bug: b/236909178 Bug: b/235861862 Merged-In: I46bd38d50419cb9e54e8202d24222979e47ff5ca Change-Id: I46bd38d50419cb9e54e8202d24222979e47ff5ca (cherry picked from commit 29cbe14265c9679d6de5a5785a95137c178fe1eb) --- ui/build/build.go | 1 + ui/build/config.go | 59 ++++++++++++++++++++++++++++++++++------------------ ui/build/rbe.go | 47 +++++++++++++++++++---------------------- ui/build/rbe_test.go | 3 ++- 4 files changed, 63 insertions(+), 47 deletions(-) diff --git a/ui/build/build.go b/ui/build/build.go index 9668efde0..8f7f64b11 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -244,6 +244,7 @@ func Build(ctx Context, config Config) { } if config.StartRBE() { + cleanupRBELogsDir(ctx, config) startRBE(ctx, config) defer DumpRBEMetrics(ctx, config, filepath.Join(config.LogsDir(), "rbe_metrics.pb")) } diff --git a/ui/build/config.go b/ui/build/config.go index 4ee759f85..249af3a1a 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -18,11 +18,13 @@ import ( "encoding/json" "fmt" "io/ioutil" + "math/rand" "os" "path/filepath" "runtime" "strconv" "strings" + "syscall" "time" "android/soong/shared" @@ -37,6 +39,15 @@ const ( jsonSuffix = "json" ) +var ( + rbeRandPrefix int +) + +func init() { + rand.Seed(time.Now().UnixNano()) + rbeRandPrefix = rand.Intn(1000) +} + type Config struct{ *configImpl } type configImpl struct { @@ -998,34 +1009,25 @@ func (c *configImpl) StartRBE() bool { return true } -func (c *configImpl) rbeLogDir() string { - for _, f := range []string{"RBE_log_dir", "FLAG_log_dir"} { - if v, ok := c.environ.Get(f); ok { - return v - } - } - if c.Dist() { - return c.LogsDir() - } - return c.OutDir() -} - -func (c *configImpl) rbeStatsOutputDir() string { - for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} { +func (c *configImpl) rbeProxyLogsDir() string { + for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} { if v, ok := c.environ.Get(f); ok { return v } } - return c.rbeLogDir() + buildTmpDir := shared.TempDirForOutDir(c.SoongOutDir()) + return filepath.Join(buildTmpDir, "rbe") } -func (c *configImpl) rbeLogPath() string { - for _, f := range []string{"RBE_log_path", "FLAG_log_path"} { - if v, ok := c.environ.Get(f); ok { - return v +func (c *configImpl) shouldCleanupRBELogsDir() bool { + // Perform a log directory cleanup only when the log directory + // is auto created by the build rather than user-specified. + for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} { + if _, ok := c.environ.Get(f); ok { + return false } } - return fmt.Sprintf("text://%v/reproxy_log.txt", c.rbeLogDir()) + return true } func (c *configImpl) rbeExecRoot() string { @@ -1077,6 +1079,23 @@ func (c *configImpl) rbeAuth() (string, string) { return "RBE_use_application_default_credentials", "true" } +func (c *configImpl) rbeSockAddr(dir string) (string, error) { + maxNameLen := len(syscall.RawSockaddrUnix{}.Path) + base := fmt.Sprintf("reproxy_%v.sock", rbeRandPrefix) + + name := filepath.Join(dir, base) + if len(name) < maxNameLen { + return name, nil + } + + name = filepath.Join("/tmp", base) + if len(name) < maxNameLen { + return name, nil + } + + return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen) +} + func (c *configImpl) UseRemoteBuild() bool { return c.UseGoma() || c.UseRBE() } diff --git a/ui/build/rbe.go b/ui/build/rbe.go index 8f9a69991..3e558f738 100644 --- a/ui/build/rbe.go +++ b/ui/build/rbe.go @@ -16,12 +16,9 @@ package build import ( "fmt" - "math/rand" "os" "path/filepath" "runtime" - "syscall" - "time" "android/soong/ui/metrics" ) @@ -54,34 +51,16 @@ func rbeCommand(ctx Context, config Config, rbeCmd string) string { return cmdPath } -func sockAddr(dir string) (string, error) { - maxNameLen := len(syscall.RawSockaddrUnix{}.Path) - rand.Seed(time.Now().UnixNano()) - base := fmt.Sprintf("reproxy_%v.sock", rand.Intn(1000)) - - name := filepath.Join(dir, base) - if len(name) < maxNameLen { - return name, nil - } - - name = filepath.Join("/tmp", base) - if len(name) < maxNameLen { - return name, nil - } - - return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen) -} - func getRBEVars(ctx Context, config Config) map[string]string { vars := map[string]string{ - "RBE_log_path": config.rbeLogPath(), - "RBE_log_dir": config.rbeLogDir(), + "RBE_log_dir": config.rbeProxyLogsDir(), "RBE_re_proxy": config.rbeReproxy(), "RBE_exec_root": config.rbeExecRoot(), - "RBE_output_dir": config.rbeStatsOutputDir(), + "RBE_output_dir": config.rbeProxyLogsDir(), + "RBE_proxy_log_dir": config.rbeProxyLogsDir(), } if config.StartRBE() { - name, err := sockAddr(absPath(ctx, config.TempDir())) + name, err := config.rbeSockAddr(absPath(ctx, config.TempDir())) if err != nil { ctx.Fatalf("Error retrieving socket address: %v", err) return nil @@ -100,6 +79,17 @@ func getRBEVars(ctx Context, config Config) map[string]string { return vars } +func cleanupRBELogsDir(ctx Context, config Config) { + if !config.shouldCleanupRBELogsDir() { + return + } + + rbeTmpDir := config.rbeProxyLogsDir() + if err := os.RemoveAll(rbeTmpDir); err != nil { + fmt.Fprintln(ctx.Writer, "\033[33mUnable to remove RBE log directory: ", err, "\033[0m") + } +} + func startRBE(ctx Context, config Config) { ctx.BeginTrace(metrics.RunSetupTool, "rbe_bootstrap") defer ctx.EndTrace() @@ -110,6 +100,11 @@ func startRBE(ctx Context, config Config) { if n := ulimitOrFatal(ctx, config, "-n"); n < rbeLeastNFiles { ctx.Fatalf("max open files is insufficient: %d; want >= %d.\n", n, rbeLeastNFiles) } + if _, err := os.Stat(config.rbeProxyLogsDir()); os.IsNotExist(err) { + if err := os.MkdirAll(config.rbeProxyLogsDir(), 0744); err != nil { + ctx.Fatalf("Unable to create logs dir (%v) for RBE: %v", config.rbeProxyLogsDir, err) + } + } cmd := Command(ctx, config, "startRBE bootstrap", rbeCommand(ctx, config, bootstrapCmd)) @@ -151,7 +146,7 @@ func DumpRBEMetrics(ctx Context, config Config, filename string) { return } - outputDir := config.rbeStatsOutputDir() + outputDir := config.rbeProxyLogsDir() if outputDir == "" { ctx.Fatal("RBE output dir variable not defined. Aborting metrics dumping.") } diff --git a/ui/build/rbe_test.go b/ui/build/rbe_test.go index 8ff96bcbb..266f76b35 100644 --- a/ui/build/rbe_test.go +++ b/ui/build/rbe_test.go @@ -56,7 +56,8 @@ func TestDumpRBEMetrics(t *testing.T) { env := Environment(tt.env) env.Set("OUT_DIR", tmpDir) env.Set("RBE_DIR", tmpDir) - env.Set("RBE_output_dir", t.TempDir()) + env.Set("RBE_output_dir", tmpDir) + env.Set("RBE_proxy_log_dir", tmpDir) config := Config{&configImpl{ environ: &env, }} -- cgit v1.2.3 From b0c28d63d608572cc55cf2ec5edd9fc3ef257ec0 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 1 Jul 2022 15:56:06 +0000 Subject: Stop exporting systemserverclasspath_fragment when targeting S Previously, when targeting the S release the generated sdk snapshot would contain prebuilt_systemserverclasspath_fragment modules even though they were only added in T. This allows SdkMemberTypes to specify the set of target build releases they support and ignores them when targeting an unsupported target build release. The Merged-In value was chosen to prevent this from being merged into branches where it will conflict due to https://r.android.com/2105804. That will allow this change to be submitted in tm-dev before it is submitted in AOSP. Test: m nothing packages/modules/common/build/mainline_modules_sdks.sh # Check that the for-S-build snapshots do not include SSCPFs. Bug: 237718221 Change-Id: I2df08c2fcebf9b866695d691572a9d3783758b17 Merged-In: Ib6d1b72bc8399fbb39075494ae37da92f4b28d03 --- android/sdk.go | 13 ++++++ java/java.go | 3 ++ java/systemserver_classpath_fragment.go | 3 ++ sdk/systemserverclasspath_fragment_sdk_test.go | 65 +++++++++++++++++++++++--- sdk/update.go | 35 ++++++++++++-- 5 files changed, 110 insertions(+), 9 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index 3a5624030..1967a3250 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -661,6 +661,10 @@ type SdkMemberType interface { // an Android.bp file. RequiresBpProperty() bool + // SupportedBuildReleases returns the string representation of a set of target build releases that + // support this member type. + SupportedBuildReleases() string + // UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot, // false otherwise. UsableWithSdkAndSdkSnapshot() bool @@ -760,6 +764,11 @@ type SdkMemberTypeBase struct { // property to be specifiable in an Android.bp file. BpPropertyNotRequired bool + // The name of the first targeted build release. + // + // If not specified then it is assumed to be available on all targeted build releases. + SupportedBuildReleaseSpecification string + SupportsSdk bool HostOsDependent bool @@ -780,6 +789,10 @@ func (b *SdkMemberTypeBase) RequiresBpProperty() bool { return !b.BpPropertyNotRequired } +func (b *SdkMemberTypeBase) SupportedBuildReleases() string { + return b.SupportedBuildReleaseSpecification +} + func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool { return b.SupportsSdk } diff --git a/java/java.go b/java/java.go index c8fb93cca..9ab77a54e 100644 --- a/java/java.go +++ b/java/java.go @@ -164,6 +164,9 @@ var ( android.SdkMemberTypeBase{ PropertyName: "java_systemserver_libs", SupportsSdk: true, + + // This was only added in Tiramisu. + SupportedBuildReleaseSpecification: "Tiramisu+", }, func(ctx android.SdkMemberContext, j *Library) android.Path { // Java systemserver libs are only provided in the SDK to provide access to their dex diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index fa61ea68c..79d2ee9f7 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -28,6 +28,9 @@ func init() { SdkMemberTypeBase: android.SdkMemberTypeBase{ PropertyName: "systemserverclasspath_fragments", SupportsSdk: true, + + // This was only added in Tiramisu. + SupportedBuildReleaseSpecification: "Tiramisu+", }, }) } diff --git a/sdk/systemserverclasspath_fragment_sdk_test.go b/sdk/systemserverclasspath_fragment_sdk_test.go index 16e3e7fa9..819083d23 100644 --- a/sdk/systemserverclasspath_fragment_sdk_test.go +++ b/sdk/systemserverclasspath_fragment_sdk_test.go @@ -22,13 +22,16 @@ import ( "android/soong/java" ) -func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) { +func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRelease string, expectedUnversionedSdkSnapshot string, expectedVersionedSdkSnapshot string) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, java.PrepareForTestWithJavaDefaultModules, java.PrepareForTestWithJavaSdkLibraryFiles, java.FixtureWithLastReleaseApis("mysdklibrary"), dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"), + android.FixtureModifyEnv(func(env map[string]string) { + env["SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE"] = targetBuildRelease + }), prepareForSdkTestWithApex, android.FixtureWithRootAndroidBp(` @@ -83,7 +86,58 @@ func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) { ).RunTest(t) CheckSnapshot(t, result, "mysdk", "", - checkUnversionedAndroidBpContents(` + checkUnversionedAndroidBpContents(expectedUnversionedSdkSnapshot), + checkVersionedAndroidBpContents(expectedVersionedSdkSnapshot), + ) +} + +func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) { + t.Run("target-s", func(t *testing.T) { + testSnapshotWithSystemServerClasspathFragment(t, "S", ` +// This is auto-generated. DO NOT EDIT. + +java_sdk_library_import { + name: "mysdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: false, + public: { + jars: ["sdk_library/public/mysdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], + current_api: "sdk_library/public/mysdklibrary.txt", + removed_api: "sdk_library/public/mysdklibrary-removed.txt", + sdk_version: "current", + }, +} +`, ` +// This is auto-generated. DO NOT EDIT. + +java_sdk_library_import { + name: "mysdk_mysdklibrary@current", + sdk_member_name: "mysdklibrary", + visibility: ["//visibility:public"], + apex_available: ["myapex"], + shared_library: false, + public: { + jars: ["sdk_library/public/mysdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], + current_api: "sdk_library/public/mysdklibrary.txt", + removed_api: "sdk_library/public/mysdklibrary-removed.txt", + sdk_version: "current", + }, +} + +sdk_snapshot { + name: "mysdk@current", + visibility: ["//visibility:public"], + java_sdk_libs: ["mysdk_mysdklibrary@current"], +} +`) + }) + + t.Run("target-t", func(t *testing.T) { + testSnapshotWithSystemServerClasspathFragment(t, "Tiramisu", ` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -120,8 +174,7 @@ prebuilt_systemserverclasspath_fragment { "mysdklibrary", ], } -`), - checkVersionedAndroidBpContents(` +`, ` // This is auto-generated. DO NOT EDIT. java_sdk_library_import { @@ -166,6 +219,6 @@ sdk_snapshot { java_systemserver_libs: ["mysdk_mylib@current"], systemserverclasspath_fragments: ["mysdk_mysystemserverclasspathfragment@current"], } -`), - ) +`) + }) } diff --git a/sdk/update.go b/sdk/update.go index 5db604b7c..740b23c1d 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -242,7 +242,7 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) { // Finally, the member type slices are concatenated together to form a single slice. The order in // which they are concatenated is the order in which the member types were registered in the // android.SdkMemberTypesRegistry. -func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, memberVariantDeps []sdkMemberVariantDep) []*sdkMember { +func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, targetBuildRelease *buildRelease, memberVariantDeps []sdkMemberVariantDep) []*sdkMember { byType := make(map[android.SdkMemberType][]*sdkMember) byName := make(map[string]*sdkMember) @@ -265,13 +265,39 @@ func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, mem var members []*sdkMember for _, memberListProperty := range s.memberTypeListProperties() { - membersOfType := byType[memberListProperty.memberType] + memberType := memberListProperty.memberType + + if !isMemberTypeSupportedByTargetBuildRelease(memberType, targetBuildRelease) { + continue + } + + membersOfType := byType[memberType] members = append(members, membersOfType...) } return members } +// isMemberTypeSupportedByTargetBuildRelease returns true if the member type is supported by the +// target build release. +func isMemberTypeSupportedByTargetBuildRelease(memberType android.SdkMemberType, targetBuildRelease *buildRelease) bool { + supportedByTargetBuildRelease := true + supportedBuildReleases := memberType.SupportedBuildReleases() + if supportedBuildReleases == "" { + supportedBuildReleases = "S+" + } + + set, err := parseBuildReleaseSet(supportedBuildReleases) + if err != nil { + panic(fmt.Errorf("member type %s has invalid supported build releases %q: %s", + memberType.SdkPropertyName(), supportedBuildReleases, err)) + } + if !set.contains(targetBuildRelease) { + supportedByTargetBuildRelease = false + } + return supportedByTargetBuildRelease +} + func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware { for _, v := range variants { if v == newVariant { @@ -416,7 +442,7 @@ be unnecessary as every module in the sdk already has its own licenses property. // Group the variants for each member module together and then group the members of each member // type together. - members := s.groupMemberVariantsByMemberThenType(ctx, memberVariantDeps) + members := s.groupMemberVariantsByMemberThenType(ctx, targetBuildRelease, memberVariantDeps) // Create the prebuilt modules for each of the member modules. traits := s.gatherTraits() @@ -795,6 +821,9 @@ func (s *sdk) addSnapshotPropertiesToPropertySet(builder *snapshotBuilder, prope if memberListProperty.getter == nil { continue } + if !isMemberTypeSupportedByTargetBuildRelease(memberListProperty.memberType, builder.targetBuildRelease) { + continue + } names := memberListProperty.getter(dynamicMemberTypeListProperties) if len(names) > 0 { propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false)) -- cgit v1.2.3 From 3c0ae3317ef7516fe2b5cc14197eb08a04740e2c Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Wed, 13 Jul 2022 23:16:52 -0700 Subject: Add ability to force compile as 64 bit. When trying to build a single 64 bit and 32 bit image, there are a few executables that are prefer32. When set, this will force all of those targets to be compiled as 64 bit. Bug: 229787331 Test: With this option, drmserver/mediaserver are built as 64 bit. Test: Without this option, drmserver/mediaserver are built as 32 bit. Change-Id: I1c3dbe229f9b612ff76b857ca7163b14e7dc92c5 Merged-In: I1c3dbe229f9b612ff76b857ca7163b14e7dc92c5 --- android/arch.go | 12 ++++++++++-- android/config.go | 4 ++++ android/variable.go | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/android/arch.go b/android/arch.go index cbf77c758..3587b469f 100644 --- a/android/arch.go +++ b/android/arch.go @@ -655,7 +655,8 @@ func archMutator(bpctx blueprint.BottomUpMutatorContext) { prefer32 := os == Windows // Determine the multilib selection for this module. - multilib, extraMultilib := decodeMultilib(base, os) + force_first_on_device := mctx.Config().ForceMultilibFirstOnDevice() + multilib, extraMultilib := decodeMultilib(base, os, force_first_on_device) // Convert the multilib selection into a list of Targets. targets, err := decodeMultilibTargets(multilib, osTargets, prefer32) @@ -730,7 +731,7 @@ func addTargetProperties(m Module, target Target, multiTargets []Target, primary // multilib from the factory's call to InitAndroidArchModule if none was set. For modules that // called InitAndroidMultiTargetsArchModule it always returns "common" for multilib, and returns // the actual multilib in extraMultilib. -func decodeMultilib(base *ModuleBase, os OsType) (multilib, extraMultilib string) { +func decodeMultilib(base *ModuleBase, os OsType, force_first_on_device bool) (multilib, extraMultilib string) { // First check the "android.compile_multilib" or "host.compile_multilib" properties. switch os.Class { case Device: @@ -749,6 +750,13 @@ func decodeMultilib(base *ModuleBase, os OsType) (multilib, extraMultilib string multilib = base.commonProperties.Default_multilib } + // If a device is configured with multiple targets, this option + // force all device targets that prefer32 to be compiled only as + // the first target. + if force_first_on_device && os.Class == Device && (multilib == "prefer32" || multilib == "first_prefer32") { + multilib = "first" + } + if base.commonProperties.UseTargetVariants { // Darwin has the concept of "universal binaries" which is implemented in Soong by // building both x86_64 and arm64 variants, and having select module types know how to diff --git a/android/config.go b/android/config.go index ba95c5a20..3c99659f9 100644 --- a/android/config.go +++ b/android/config.go @@ -1701,6 +1701,10 @@ func (c *deviceConfig) GenerateAidlNdkPlatformBackend() bool { return c.config.productVariables.GenerateAidlNdkPlatformBackend } +func (c *config) ForceMultilibFirstOnDevice() bool { + return c.productVariables.ForceMultilibFirstOnDevice +} + // The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs. // Such lists are used in the build system for things like bootclasspath jars or system server jars. // The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a diff --git a/android/variable.go b/android/variable.go index 373891ae4..442068423 100644 --- a/android/variable.go +++ b/android/variable.go @@ -443,6 +443,8 @@ type productVariables struct { SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"` GenerateAidlNdkPlatformBackend bool `json:",omitempty"` + + ForceMultilibFirstOnDevice bool `json:",omitempty"` } func boolPtr(v bool) *bool { -- cgit v1.2.3 From 8a61b59e1798d3dce5208881c005dbe9526f4043 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 15 Jul 2022 13:12:35 +0000 Subject: Use implementation jar for updatable-media in snapshot for S While enabling prebuilts in T we hit b/229932396 which was caused by some parts of the build depending on the prebuilt updatable-media jar which used to be a full implementation jar but which is now an invalid jar as the snapshot must not be including implementation details. We fixed the issue in T but we are hitting the same problem in S with the M-2022-07. That is the first train in which the prebuilt updatable-media module provides an invalid jar, prior to that it was always providing an implementation jar. This change tweaks the sdk snapshot generation code to use an implementation jar for updatable-media in the S snapshot to avoid partners having to cherry pick changes similar to those needed to fix b/229932396 in T. Bug: 239121291 Test: packages/modules/common/build/mainline_modules_sdks.sh # Check that S media snapshot includes implementation jar. # Check that S art snapshot includes invalid jar. # Check that T media snapshot includes invalid jar. Change-Id: Ib49484d00a60b4ed7f8268e04f9c10a3498edb56 (cherry picked from commit 1364891fad13901c3b47d31e9d9dfaaf04ecaa79) Merged-In: Ib49484d00a60b4ed7f8268e04f9c10a3498edb56 --- android/sdk.go | 4 +++ java/java.go | 30 +++++++++++++++++----- sdk/build_release.go | 12 ++++++--- sdk/java_sdk_test.go | 71 ++++++++++++++++++++++++++++++++++++++++++++++------ sdk/update.go | 6 +++++ 5 files changed, 105 insertions(+), 18 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index 1967a3250..1ce692fb6 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -946,6 +946,10 @@ type SdkMemberContext interface { // RequiresTrait returns true if this member is expected to provide the specified trait. RequiresTrait(trait SdkMemberTrait) bool + + // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is + // being generated is before Tiramisu, i.e. S. + IsTargetBuildBeforeTiramisu() bool } // ExportedComponentsInfo contains information about the components that this module exports to an diff --git a/java/java.go b/java/java.go index 9ab77a54e..1e99aa32f 100644 --- a/java/java.go +++ b/java/java.go @@ -118,6 +118,16 @@ var ( copyEverythingToSnapshot, } + snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool { + // In the S build the build will break if updatable-media does not provide a full implementation + // jar. That issue was fixed in Tiramisu by b/229932396. + if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" { + return true + } + + return false + } + // Supports adding java boot libraries to module_exports and sdk. // // The build has some implicit dependencies (via the boot jars configuration) on a number of @@ -135,13 +145,21 @@ var ( SupportsSdk: true, }, func(ctx android.SdkMemberContext, j *Library) android.Path { + if snapshotRequiresImplementationJar(ctx) { + return exportImplementationClassesJar(ctx, j) + } + // Java boot libs are only provided in the SDK to provide access to their dex implementation // jar for use by dexpreopting and boot jars package check. They do not need to provide an // actual implementation jar but the java_import will need a file that exists so just copy an // empty file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, - func(osPrefix, name string) string { + func(ctx android.SdkMemberContext, osPrefix, name string) string { + if snapshotRequiresImplementationJar(ctx) { + return sdkSnapshotFilePathForJar(ctx, osPrefix, name) + } + // Create a special name for the implementation jar to try and provide some useful information // to a developer that attempts to compile against this. // TODO(b/175714559): Provide a proper error message in Soong not ninja. @@ -175,7 +193,7 @@ var ( // file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, - func(osPrefix, name string) string { + func(_ android.SdkMemberContext, osPrefix, name string) string { // Create a special name for the implementation jar to try and provide some useful information // to a developer that attempts to compile against this. // TODO(b/175714559): Provide a proper error message in Soong not ninja. @@ -649,7 +667,7 @@ const ( ) // path to the jar file of a java library. Relative to / -func sdkSnapshotFilePathForJar(osPrefix, name string) string { +func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string { return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) } @@ -666,7 +684,7 @@ type librarySdkMemberType struct { // Function to compute the snapshot relative path to which the named library's // jar should be copied. - snapshotPathGetter func(osPrefix, name string) string + snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string // True if only the jar should be copied to the snapshot, false if the jar plus any additional // files like aidl files should also be copied. @@ -724,7 +742,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte exportedJar := p.JarToExport if exportedJar != nil { // Delegate the creation of the snapshot relative path to the member type. - snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name()) + snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name()) // Copy the exported jar to the snapshot. builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) @@ -1190,7 +1208,7 @@ func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, exportedJar := p.JarToExport if exportedJar != nil { - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name()) + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) diff --git a/sdk/build_release.go b/sdk/build_release.go index 4c2277e85..0494a28ee 100644 --- a/sdk/build_release.go +++ b/sdk/build_release.go @@ -24,18 +24,22 @@ import ( // buildRelease represents the version of a build system used to create a specific release. // -// The name of the release, is the same as the code for the dessert release, e.g. S, T, etc. +// The name of the release, is the same as the code for the dessert release, e.g. S, Tiramisu, etc. type buildRelease struct { - // The name of the release, e.g. S, T, etc. + // The name of the release, e.g. S, Tiramisu, etc. name string // The index of this structure within the buildReleases list. ordinal int } +func (br *buildRelease) EarlierThan(other *buildRelease) bool { + return br.ordinal < other.ordinal +} + // String returns the name of the build release. -func (s *buildRelease) String() string { - return s.name +func (br *buildRelease) String() string { + return br.name } // buildReleaseSet represents a set of buildRelease objects. diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index a99fa1ff0..2cadd60f4 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -15,6 +15,7 @@ package sdk import ( + "fmt" "testing" "android/soong/android" @@ -339,8 +340,8 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { android.FixtureAddFile("aidl", nil), android.FixtureAddFile("resource.txt", nil), ).RunTestWithBp(t, ` - module_exports { - name: "myexports", + sdk { + name: "mysdk", java_boot_libs: ["myjavalib"], } @@ -360,7 +361,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { } `) - CheckSnapshot(t, result, "myexports", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -377,7 +378,7 @@ java_import { // This is auto-generated. DO NOT EDIT. java_import { - name: "myexports_myjavalib@current", + name: "mysdk_myjavalib@current", sdk_member_name: "myjavalib", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], @@ -385,19 +386,73 @@ java_import { permitted_packages: ["pkg.myjavalib"], } -module_exports_snapshot { - name: "myexports@current", +sdk_snapshot { + name: "mysdk@current", visibility: ["//visibility:public"], - java_boot_libs: ["myexports_myjavalib@current"], + java_boot_libs: ["mysdk_myjavalib@current"], } `), checkAllCopyRules(` -.intermediates/myexports/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar +.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar `), ) } +func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) { + runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) { + result := android.GroupFixturePreparers( + prepareForSdkTestWithJava, + android.FixtureMergeEnv(map[string]string{ + "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, + }), + ).RunTestWithBp(t, ` + sdk { + name: "mysdk", + java_boot_libs: ["updatable-media"], + } + + java_library { + name: "updatable-media", + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + compile_dex: true, + permitted_packages: ["pkg.media"], + apex_available: ["com.android.media"], + } + `) + + CheckSnapshot(t, result, "mysdk", "", + checkUnversionedAndroidBpContents(fmt.Sprintf(` +// This is auto-generated. DO NOT EDIT. + +java_import { + name: "updatable-media", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["com.android.media"], + jars: ["%s"], + permitted_packages: ["pkg.media"], +} +`, expectedJarPath)), + checkAllCopyRules(expectedCopyRule), + ) + } + + t.Run("updatable-media in S", func(t *testing.T) { + runTest(t, "S", "java/updatable-media.jar", ` +.intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar +`) + }) + + t.Run("updatable-media in T", func(t *testing.T) { + runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", ` +.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar +`) + }) +} + func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, diff --git a/sdk/update.go b/sdk/update.go index 740b23c1d..017887461 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -1931,6 +1931,12 @@ func (m *memberContext) RequiresTrait(trait android.SdkMemberTrait) bool { return m.requiredTraits.Contains(trait) } +func (m *memberContext) IsTargetBuildBeforeTiramisu() bool { + return m.builder.targetBuildRelease.EarlierThan(buildReleaseT) +} + +var _ android.SdkMemberContext = (*memberContext)(nil) + func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) { memberType := member.memberType -- cgit v1.2.3 From 234f595cce32003645b3d93aa8d055b532923e4f Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Mon, 19 Sep 2022 16:26:00 +0000 Subject: Make writing command-line arguments as a comment in the generated file optional Bug: 246630004 Test: ./update_prebuilts.py -x ###### Merged-In: Ic7d5d5ba55f5bba5cc2d0866a7a25f753f3428f8 Change-Id: Ic7d5d5ba55f5bba5cc2d0866a7a25f753f3428f8 --- cmd/pom2bp/pom2bp.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index f8844fc94..e0638b8ed 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -150,6 +150,7 @@ var sdkVersion string var defaultMinSdkVersion string var useVersion string var staticDeps bool +var writeCmd bool var jetifier bool func InList(s string, list []string) bool { @@ -810,6 +811,9 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib -use-version If the maven directory contains multiple versions of artifacts and their pom files, -use-version can be used to only write Android.bp files for a specific version of those artifacts. + -write-cmd + Whether to write the command line arguments used to generate the build file as a comment at + the top of the build file itself. -jetifier Sets jetifier: true for all modules. @@ -836,6 +840,7 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib flag.StringVar(&defaultMinSdkVersion, "default-min-sdk-version", "24", "Default min_sdk_version to use, if one is not available from AndroidManifest.xml. Default: 24") flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version") flag.BoolVar(&staticDeps, "static-deps", false, "Statically include direct dependencies") + flag.BoolVar(&writeCmd, "write-cmd", true, "Write command line arguments as a comment") flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules") flag.StringVar(®en, "regen", "", "Rewrite specified file") flag.BoolVar(&pom2build, "pom2build", false, "If true, will generate a Bazel BUILD file *instead* of a .bp file") @@ -962,8 +967,13 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib if pom2build { commentString = "#" } - fmt.Fprintln(buf, commentString, "Automatically generated with:") - fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) + + fmt.Fprintln(buf, commentString, "This is a generated file. Do not modify directly.") + + if writeCmd { + fmt.Fprintln(buf, commentString, "Automatically generated with:") + fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) + } depsTemplate := bpDepsTemplate template := bpTemplate -- cgit v1.2.3 From e58dac223de1d2a6b8e288900e29d48a9eb01a63 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Wed, 27 Apr 2022 14:20:11 -0700 Subject: Allow BoringSSL's Rust bindings to build Bug: 177080016 Test: mm in boringssl Change-Id: I3cdf031ebf7c5bafce00c078107fd7fb3a26ba2d Merged-In: I3cdf031ebf7c5bafce00c078107fd7fb3a26ba2d (cherry picked from commit 14f26aaa4ecae6b4565f8af72005476f69c3d0b4) --- rust/config/allowed_list.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go index 802e1da7f..746857916 100644 --- a/rust/config/allowed_list.go +++ b/rust/config/allowed_list.go @@ -8,6 +8,7 @@ var ( RustAllowedPaths = []string{ "device/google/cuttlefish", "external/adhd", + "external/boringssl", "external/crosvm", "external/libchromeos-rs", "external/minijail", -- cgit v1.2.3 From 26d3d716190efadb329f5e72ec3490ffddf584bd Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 3 May 2022 14:20:24 -0700 Subject: Treat kotlin-annotations the same as kotlin-stdlib Upgrading dagger uncovers an issue where java-only modules with kotlin-containing dependencies may see org.jetbrains.annotations.NotNull annotations. Include the kotlin-annotations in the output jar the same way kotlin-stdlib is included. Bug: 227669740 Test: TestKotlin Change-Id: Ifc33a32b121c1b9a9d1911bdec332264b78b571c (cherry picked from commit 063544747e414f66a0bcc14ec55a3232aff1ed0d) Merged-In: Ifc33a32b121c1b9a9d1911bdec332264b78b571c --- java/base.go | 9 ++++----- java/kotlin_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/java/base.go b/java/base.go index 7aa281495..f4a91f56c 100644 --- a/java/base.go +++ b/java/base.go @@ -749,9 +749,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { // Kotlin files ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8") - if len(j.properties.Plugins) > 0 { - ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations") - } + ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations") } // Framework libraries need special handling in static coverage builds: they should not have @@ -1107,8 +1105,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { flags.classpath = append(flags.classpath, deps.kotlinStdlib...) flags.classpath = append(flags.classpath, deps.kotlinAnnotations...) - flags.dexClasspath = append(flags.dexClasspath, deps.kotlinAnnotations...) - flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...) flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...) @@ -1140,9 +1136,12 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // Jar kotlin classes into the final jar after javac if BoolDefault(j.properties.Static_kotlin_stdlib, true) { kotlinJars = append(kotlinJars, deps.kotlinStdlib...) + kotlinJars = append(kotlinJars, deps.kotlinAnnotations...) kotlinHeaderJars = append(kotlinHeaderJars, deps.kotlinStdlib...) + kotlinHeaderJars = append(kotlinHeaderJars, deps.kotlinAnnotations...) } else { flags.dexClasspath = append(flags.dexClasspath, deps.kotlinStdlib...) + flags.dexClasspath = append(flags.dexClasspath, deps.kotlinAnnotations...) } } diff --git a/java/kotlin_test.go b/java/kotlin_test.go index 435d78294..491ce2939 100644 --- a/java/kotlin_test.go +++ b/java/kotlin_test.go @@ -42,6 +42,11 @@ func TestKotlin(t *testing.T) { } `) + kotlinStdlib := ctx.ModuleForTests("kotlin-stdlib", "android_common"). + Output("turbine-combined/kotlin-stdlib.jar").Output + kotlinAnnotations := ctx.ModuleForTests("kotlin-annotations", "android_common"). + Output("turbine-combined/kotlin-annotations.jar").Output + fooKotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc") fooJavac := ctx.ModuleForTests("foo", "android_common").Rule("javac") fooJar := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar") @@ -69,6 +74,16 @@ func TestKotlin(t *testing.T) { fooJar.Inputs.Strings(), fooKotlincClasses.String()) } + if !inList(kotlinStdlib.String(), fooJar.Inputs.Strings()) { + t.Errorf("foo jar inputs %v does not contain %v", + fooJar.Inputs.Strings(), kotlinStdlib.String()) + } + + if !inList(kotlinAnnotations.String(), fooJar.Inputs.Strings()) { + t.Errorf("foo jar inputs %v does not contain %v", + fooJar.Inputs.Strings(), kotlinAnnotations.String()) + } + if !inList(fooKotlincHeaderClasses.String(), fooHeaderJar.Inputs.Strings()) { t.Errorf("foo header jar inputs %v does not contain %q", fooHeaderJar.Inputs.Strings(), fooKotlincHeaderClasses.String()) -- cgit v1.2.3 From 9c94a64e4b5905ee73b0af0a13a9ac7f619fcf31 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Fri, 16 Sep 2022 11:59:56 -0400 Subject: update MultiAbiTargeting matching logic The logic here has diverged from the logic in bundletool and resulted in the wrong APEX variant being chosen for a 64bit-only product. Bug: 246476965 Test: go test . Change-Id: Ic3b067e98a65146cfa399e7c9b231f397e51c23e Merged-In: Ic3b067e98a65146cfa399e7c9b231f397e51c23e --- cmd/extract_apks/main.go | 90 +++++++++-- cmd/extract_apks/main_test.go | 364 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 438 insertions(+), 16 deletions(-) diff --git a/cmd/extract_apks/main.go b/cmd/extract_apks/main.go index 1cf64de8b..e39f8d765 100644 --- a/cmd/extract_apks/main.go +++ b/cmd/extract_apks/main.go @@ -29,6 +29,7 @@ import ( "google.golang.org/protobuf/proto" + "android/soong/cmd/extract_apks/bundle_proto" android_bundle_proto "android/soong/cmd/extract_apks/bundle_proto" "android/soong/third_party/zip" ) @@ -197,6 +198,49 @@ type multiAbiTargetingMatcher struct { *android_bundle_proto.MultiAbiTargeting } +type multiAbiValue []*bundle_proto.Abi + +func (m multiAbiValue) compare(other multiAbiValue) int { + min := func(a, b int) int { + if a < b { + return a + } + return b + } + + sortAbis := func(abiSlice multiAbiValue) func(i, j int) bool { + return func(i, j int) bool { + // sort priorities greatest to least + return multiAbiPriorities[abiSlice[i].Alias] > multiAbiPriorities[abiSlice[j].Alias] + } + } + + m = append(multiAbiValue{}, m...) + sort.Slice(m, sortAbis(m)) + other = append(multiAbiValue{}, other...) + sort.Slice(other, sortAbis(other)) + + for i := 0; i < min(len(m), len(other)); i++ { + if multiAbiPriorities[m[i].Alias] > multiAbiPriorities[other[i].Alias] { + return 1 + } + if multiAbiPriorities[m[i].Alias] < multiAbiPriorities[other[i].Alias] { + return -1 + } + } + + if len(m) == len(other) { + return 0 + } + if len(m) > len(other) { + return 1 + } + return -1 +} + +// this logic should match the logic in bundletool at +// https://github.com/google/bundletool/blob/ae0fc0162fd80d92ef8f4ef4527c066f0106942f/src/main/java/com/android/tools/build/bundletool/device/MultiAbiMatcher.java#L43 +// (note link is the commit at time of writing; but logic should always match the latest) func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if t.MultiAbiTargeting == nil { return true @@ -204,31 +248,45 @@ func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if _, ok := config.abis[android_bundle_proto.Abi_UNSPECIFIED_CPU_ARCHITECTURE]; ok { return true } - // Find the one with the highest priority. - highestPriority := 0 - for _, v := range t.GetValue() { - for _, a := range v.GetAbi() { - if _, ok := config.abis[a.Alias]; ok { - if highestPriority < multiAbiPriorities[a.Alias] { - highestPriority = multiAbiPriorities[a.Alias] - } + + multiAbiIsValid := func(m multiAbiValue) bool { + for _, abi := range m { + if _, ok := config.abis[abi.Alias]; !ok { + return false } } + return true + } + + // ensure that the current value is valid for our config + valueSetContainsViableAbi := false + multiAbiSet := t.GetValue() + for _, multiAbi := range multiAbiSet { + if multiAbiIsValid(multiAbi.GetAbi()) { + valueSetContainsViableAbi = true + } } - if highestPriority == 0 { + + if !valueSetContainsViableAbi { return false } + // See if there are any matching alternatives with a higher priority. - for _, v := range t.GetAlternatives() { - for _, a := range v.GetAbi() { - if _, ok := config.abis[a.Alias]; ok { - if highestPriority < multiAbiPriorities[a.Alias] { - // There's a better one. Skip this one. - return false - } + for _, altMultiAbi := range t.GetAlternatives() { + if !multiAbiIsValid(altMultiAbi.GetAbi()) { + continue + } + + for _, multiAbi := range multiAbiSet { + valueAbis := multiAbiValue(multiAbi.GetAbi()) + altAbis := multiAbiValue(altMultiAbi.GetAbi()) + if valueAbis.compare(altAbis) < 0 { + // An alternative has a higher priority, don't use this one + return false } } } + return true } diff --git a/cmd/extract_apks/main_test.go b/cmd/extract_apks/main_test.go index f5e40466a..c1d712df4 100644 --- a/cmd/extract_apks/main_test.go +++ b/cmd/extract_apks/main_test.go @@ -420,6 +420,370 @@ bundletool { } } +func TestSelectApks_ApexSet_Variants(t *testing.T) { + testCases := []testDesc{ + { + protoText: ` +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-armeabi_v7a.apex" + } + } + variant_number: 0 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: ARM64_V8A}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: ARM64_V8A}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-arm64_v8a.apex" + } + } + variant_number: 1 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-armeabi_v7a.arm64_v8a.apex" + } + } + variant_number: 2 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: X86}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: X86}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-x86.apex" + } + } + variant_number: 3 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value { + abi {alias: X86} + abi {alias: X86_64} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value { + abi {alias: X86} + abi {alias: X86_64} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + } + } + path: "standalones/standalone-x86.x86_64.apex" + } + } + variant_number: 4 +} +`, + configs: []testConfigDesc{ + { + name: "multi-variant multi-target ARM", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + bp.Abi_ARMEABI_V7A: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-armeabi_v7a.arm64_v8a.apex", + }, + }, + }, + { + name: "multi-variant single-target arm", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARMEABI_V7A: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-armeabi_v7a.apex", + }, + }, + }, + { + name: "multi-variant single-target arm64", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-arm64_v8a.apex", + }, + }, + }, + { + name: "multi-variant multi-target x86", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86: 0, + bp.Abi_X86_64: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-x86.x86_64.apex", + }, + }, + }, + { + name: "multi-variant single-target x86", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-x86.apex", + }, + }, + }, + { + name: "multi-variant single-target x86_64", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86_64: 0, + }, + }, + expected: SelectionResult{}, + }, + { + name: "multi-variant multi-target cross-target", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + bp.Abi_X86_64: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-arm64_v8a.apex", + }, + }, + }, + }, + }, + } + for _, testCase := range testCases { + var toc bp.BuildApksResult + if err := prototext.Unmarshal([]byte(testCase.protoText), &toc); err != nil { + t.Fatal(err) + } + for _, config := range testCase.configs { + t.Run(config.name, func(t *testing.T) { + actual := selectApks(&toc, config.targetConfig) + if !reflect.DeepEqual(config.expected, actual) { + t.Errorf("expected %v, got %v", config.expected, actual) + } + }) + } + } +} + type testZip2ZipWriter struct { entries map[string]string } -- cgit v1.2.3 From 6c5fae512be51e9d13390b21b7def412ee718b0e Mon Sep 17 00:00:00 2001 From: Motomu Utsumi Date: Wed, 19 Oct 2022 01:50:10 +0000 Subject: Revert "update MultiAbiTargeting matching logic" This reverts commit 9c94a64e4b5905ee73b0af0a13a9ac7f619fcf31. Reason for revert: b/254332635 build falure Change-Id: I4ed1f59fd28ac7bb60939a10d15311cb7a5bfa42 --- cmd/extract_apks/main.go | 90 ++--------- cmd/extract_apks/main_test.go | 364 ------------------------------------------ 2 files changed, 16 insertions(+), 438 deletions(-) diff --git a/cmd/extract_apks/main.go b/cmd/extract_apks/main.go index e39f8d765..1cf64de8b 100644 --- a/cmd/extract_apks/main.go +++ b/cmd/extract_apks/main.go @@ -29,7 +29,6 @@ import ( "google.golang.org/protobuf/proto" - "android/soong/cmd/extract_apks/bundle_proto" android_bundle_proto "android/soong/cmd/extract_apks/bundle_proto" "android/soong/third_party/zip" ) @@ -198,49 +197,6 @@ type multiAbiTargetingMatcher struct { *android_bundle_proto.MultiAbiTargeting } -type multiAbiValue []*bundle_proto.Abi - -func (m multiAbiValue) compare(other multiAbiValue) int { - min := func(a, b int) int { - if a < b { - return a - } - return b - } - - sortAbis := func(abiSlice multiAbiValue) func(i, j int) bool { - return func(i, j int) bool { - // sort priorities greatest to least - return multiAbiPriorities[abiSlice[i].Alias] > multiAbiPriorities[abiSlice[j].Alias] - } - } - - m = append(multiAbiValue{}, m...) - sort.Slice(m, sortAbis(m)) - other = append(multiAbiValue{}, other...) - sort.Slice(other, sortAbis(other)) - - for i := 0; i < min(len(m), len(other)); i++ { - if multiAbiPriorities[m[i].Alias] > multiAbiPriorities[other[i].Alias] { - return 1 - } - if multiAbiPriorities[m[i].Alias] < multiAbiPriorities[other[i].Alias] { - return -1 - } - } - - if len(m) == len(other) { - return 0 - } - if len(m) > len(other) { - return 1 - } - return -1 -} - -// this logic should match the logic in bundletool at -// https://github.com/google/bundletool/blob/ae0fc0162fd80d92ef8f4ef4527c066f0106942f/src/main/java/com/android/tools/build/bundletool/device/MultiAbiMatcher.java#L43 -// (note link is the commit at time of writing; but logic should always match the latest) func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if t.MultiAbiTargeting == nil { return true @@ -248,45 +204,31 @@ func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if _, ok := config.abis[android_bundle_proto.Abi_UNSPECIFIED_CPU_ARCHITECTURE]; ok { return true } - - multiAbiIsValid := func(m multiAbiValue) bool { - for _, abi := range m { - if _, ok := config.abis[abi.Alias]; !ok { - return false + // Find the one with the highest priority. + highestPriority := 0 + for _, v := range t.GetValue() { + for _, a := range v.GetAbi() { + if _, ok := config.abis[a.Alias]; ok { + if highestPriority < multiAbiPriorities[a.Alias] { + highestPriority = multiAbiPriorities[a.Alias] + } } } - return true - } - - // ensure that the current value is valid for our config - valueSetContainsViableAbi := false - multiAbiSet := t.GetValue() - for _, multiAbi := range multiAbiSet { - if multiAbiIsValid(multiAbi.GetAbi()) { - valueSetContainsViableAbi = true - } } - - if !valueSetContainsViableAbi { + if highestPriority == 0 { return false } - // See if there are any matching alternatives with a higher priority. - for _, altMultiAbi := range t.GetAlternatives() { - if !multiAbiIsValid(altMultiAbi.GetAbi()) { - continue - } - - for _, multiAbi := range multiAbiSet { - valueAbis := multiAbiValue(multiAbi.GetAbi()) - altAbis := multiAbiValue(altMultiAbi.GetAbi()) - if valueAbis.compare(altAbis) < 0 { - // An alternative has a higher priority, don't use this one - return false + for _, v := range t.GetAlternatives() { + for _, a := range v.GetAbi() { + if _, ok := config.abis[a.Alias]; ok { + if highestPriority < multiAbiPriorities[a.Alias] { + // There's a better one. Skip this one. + return false + } } } } - return true } diff --git a/cmd/extract_apks/main_test.go b/cmd/extract_apks/main_test.go index c1d712df4..f5e40466a 100644 --- a/cmd/extract_apks/main_test.go +++ b/cmd/extract_apks/main_test.go @@ -420,370 +420,6 @@ bundletool { } } -func TestSelectApks_ApexSet_Variants(t *testing.T) { - testCases := []testDesc{ - { - protoText: ` -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - path: "standalones/standalone-armeabi_v7a.apex" - } - } - variant_number: 0 -} -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value {abi {alias: ARM64_V8A}} - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value {abi {alias: ARM64_V8A}} - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - path: "standalones/standalone-arm64_v8a.apex" - } - } - variant_number: 1 -} -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARMEABI_V7A}} - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARMEABI_V7A}} - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - path: "standalones/standalone-armeabi_v7a.arm64_v8a.apex" - } - } - variant_number: 2 -} -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value {abi {alias: X86}} - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value {abi {alias: X86}} - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - path: "standalones/standalone-x86.apex" - } - } - variant_number: 3 -} -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value { - abi {alias: X86} - abi {alias: X86_64} - } - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value { - abi {alias: X86} - abi {alias: X86_64} - } - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - } - } - path: "standalones/standalone-x86.x86_64.apex" - } - } - variant_number: 4 -} -`, - configs: []testConfigDesc{ - { - name: "multi-variant multi-target ARM", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_ARM64_V8A: 0, - bp.Abi_ARMEABI_V7A: 1, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-armeabi_v7a.arm64_v8a.apex", - }, - }, - }, - { - name: "multi-variant single-target arm", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_ARMEABI_V7A: 0, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-armeabi_v7a.apex", - }, - }, - }, - { - name: "multi-variant single-target arm64", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_ARM64_V8A: 0, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-arm64_v8a.apex", - }, - }, - }, - { - name: "multi-variant multi-target x86", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_X86: 0, - bp.Abi_X86_64: 1, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-x86.x86_64.apex", - }, - }, - }, - { - name: "multi-variant single-target x86", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_X86: 0, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-x86.apex", - }, - }, - }, - { - name: "multi-variant single-target x86_64", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_X86_64: 0, - }, - }, - expected: SelectionResult{}, - }, - { - name: "multi-variant multi-target cross-target", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_ARM64_V8A: 0, - bp.Abi_X86_64: 1, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-arm64_v8a.apex", - }, - }, - }, - }, - }, - } - for _, testCase := range testCases { - var toc bp.BuildApksResult - if err := prototext.Unmarshal([]byte(testCase.protoText), &toc); err != nil { - t.Fatal(err) - } - for _, config := range testCase.configs { - t.Run(config.name, func(t *testing.T) { - actual := selectApks(&toc, config.targetConfig) - if !reflect.DeepEqual(config.expected, actual) { - t.Errorf("expected %v, got %v", config.expected, actual) - } - }) - } - } -} - type testZip2ZipWriter struct { entries map[string]string } -- cgit v1.2.3 From 3dcaf7550f44ae83c3b5f2da31d7d4b9e5a86b10 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Tue, 28 Jun 2022 14:41:27 -0700 Subject: Use the current java version for -jvm-target This is a partial revert of aosp/541879. In that cl, the kotlin jvm version was always set to 1.8 because that's what the kotlin complier supported at the time, but now it supports more versions: $ ./external/kotlinc/bin/kotlinc -jvm-target foo error: unknown JVM target version: foo Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17 Bug: 69160377 Bug: 236431222 Test: Treehugger Change-Id: I273e0b4d1f484013889e17c60bc1b299a3f975a1 --- java/java.go | 14 ++++++++++++++ java/kotlin.go | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/java/java.go b/java/java.go index 1e99aa32f..9830d08dd 100644 --- a/java/java.go +++ b/java/java.go @@ -526,6 +526,20 @@ func (v javaVersion) String() string { } } +func (v javaVersion) StringForKotlinc() string { + // $ ./external/kotlinc/bin/kotlinc -jvm-target foo + // error: unknown JVM target version: foo + // Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17 + switch v { + case JAVA_VERSION_7: + return "1.6" + case JAVA_VERSION_9: + return "9" + default: + return v.String() + } +} + // Returns true if javac targeting this version uses system modules instead of a bootclasspath. func (v javaVersion) usesJavaModules() bool { return v >= 9 diff --git a/java/kotlin.go b/java/kotlin.go index 903c6249b..9bff5ea01 100644 --- a/java/kotlin.go +++ b/java/kotlin.go @@ -119,9 +119,8 @@ func kotlinCompile(ctx android.ModuleContext, outputFile, headerOutputFile andro "srcJarDir": android.PathForModuleOut(ctx, "kotlinc", "srcJars").String(), "kotlinBuildFile": android.PathForModuleOut(ctx, "kotlinc-build.xml").String(), "emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(), - // http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8 - "kotlinJvmTarget": "1.8", - "name": kotlinName, + "kotlinJvmTarget": flags.javaVersion.StringForKotlinc(), + "name": kotlinName, }, }) } -- cgit v1.2.3 From 8053f8269718e24540176bf3cc0722f66403d7d7 Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Tue, 18 Oct 2022 17:09:28 -0400 Subject: Add kotlinx.coroutines to "neverallow" allowlist Bug: 239834928 Test: manual -- all existing tests and builds should pass Change-Id: Ie5fb0d6cbd8d624f71b80bb1afe003917410aa3d --- android/neverallow.go | 1 + 1 file changed, 1 insertion(+) diff --git a/android/neverallow.go b/android/neverallow.go index aa47bcaeb..e3bdd63b2 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -153,6 +153,7 @@ func createJavaDeviceForHostRules() []Rule { javaDeviceForHostProjectsAllowedList := []string{ "development/build", "external/guava", + "external/kotlinx.coroutines", "external/robolectric-shadows", "frameworks/layoutlib", } -- cgit v1.2.3 From bccfca63bd7380d4bf9628969e5655ec0edd0c59 Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Wed, 19 Oct 2022 10:16:23 +0000 Subject: Revert "Revert "update MultiAbiTargeting matching logic"" This reverts commit 6c5fae512be51e9d13390b21b7def412ee718b0e. Reason for revert: re-submitting in a topic Fix: b/246476965 Change-Id: I442e34d035da867ba36462f8e714c4d3c655af2f (cherry picked from commit 87dd12cb7626d83a3c7519a012d582d17cd16185) Merged-In: I442e34d035da867ba36462f8e714c4d3c655af2f --- cmd/extract_apks/main.go | 90 +++++++++-- cmd/extract_apks/main_test.go | 364 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 438 insertions(+), 16 deletions(-) diff --git a/cmd/extract_apks/main.go b/cmd/extract_apks/main.go index 1cf64de8b..e39f8d765 100644 --- a/cmd/extract_apks/main.go +++ b/cmd/extract_apks/main.go @@ -29,6 +29,7 @@ import ( "google.golang.org/protobuf/proto" + "android/soong/cmd/extract_apks/bundle_proto" android_bundle_proto "android/soong/cmd/extract_apks/bundle_proto" "android/soong/third_party/zip" ) @@ -197,6 +198,49 @@ type multiAbiTargetingMatcher struct { *android_bundle_proto.MultiAbiTargeting } +type multiAbiValue []*bundle_proto.Abi + +func (m multiAbiValue) compare(other multiAbiValue) int { + min := func(a, b int) int { + if a < b { + return a + } + return b + } + + sortAbis := func(abiSlice multiAbiValue) func(i, j int) bool { + return func(i, j int) bool { + // sort priorities greatest to least + return multiAbiPriorities[abiSlice[i].Alias] > multiAbiPriorities[abiSlice[j].Alias] + } + } + + m = append(multiAbiValue{}, m...) + sort.Slice(m, sortAbis(m)) + other = append(multiAbiValue{}, other...) + sort.Slice(other, sortAbis(other)) + + for i := 0; i < min(len(m), len(other)); i++ { + if multiAbiPriorities[m[i].Alias] > multiAbiPriorities[other[i].Alias] { + return 1 + } + if multiAbiPriorities[m[i].Alias] < multiAbiPriorities[other[i].Alias] { + return -1 + } + } + + if len(m) == len(other) { + return 0 + } + if len(m) > len(other) { + return 1 + } + return -1 +} + +// this logic should match the logic in bundletool at +// https://github.com/google/bundletool/blob/ae0fc0162fd80d92ef8f4ef4527c066f0106942f/src/main/java/com/android/tools/build/bundletool/device/MultiAbiMatcher.java#L43 +// (note link is the commit at time of writing; but logic should always match the latest) func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if t.MultiAbiTargeting == nil { return true @@ -204,31 +248,45 @@ func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if _, ok := config.abis[android_bundle_proto.Abi_UNSPECIFIED_CPU_ARCHITECTURE]; ok { return true } - // Find the one with the highest priority. - highestPriority := 0 - for _, v := range t.GetValue() { - for _, a := range v.GetAbi() { - if _, ok := config.abis[a.Alias]; ok { - if highestPriority < multiAbiPriorities[a.Alias] { - highestPriority = multiAbiPriorities[a.Alias] - } + + multiAbiIsValid := func(m multiAbiValue) bool { + for _, abi := range m { + if _, ok := config.abis[abi.Alias]; !ok { + return false } } + return true + } + + // ensure that the current value is valid for our config + valueSetContainsViableAbi := false + multiAbiSet := t.GetValue() + for _, multiAbi := range multiAbiSet { + if multiAbiIsValid(multiAbi.GetAbi()) { + valueSetContainsViableAbi = true + } } - if highestPriority == 0 { + + if !valueSetContainsViableAbi { return false } + // See if there are any matching alternatives with a higher priority. - for _, v := range t.GetAlternatives() { - for _, a := range v.GetAbi() { - if _, ok := config.abis[a.Alias]; ok { - if highestPriority < multiAbiPriorities[a.Alias] { - // There's a better one. Skip this one. - return false - } + for _, altMultiAbi := range t.GetAlternatives() { + if !multiAbiIsValid(altMultiAbi.GetAbi()) { + continue + } + + for _, multiAbi := range multiAbiSet { + valueAbis := multiAbiValue(multiAbi.GetAbi()) + altAbis := multiAbiValue(altMultiAbi.GetAbi()) + if valueAbis.compare(altAbis) < 0 { + // An alternative has a higher priority, don't use this one + return false } } } + return true } diff --git a/cmd/extract_apks/main_test.go b/cmd/extract_apks/main_test.go index f5e40466a..c1d712df4 100644 --- a/cmd/extract_apks/main_test.go +++ b/cmd/extract_apks/main_test.go @@ -420,6 +420,370 @@ bundletool { } } +func TestSelectApks_ApexSet_Variants(t *testing.T) { + testCases := []testDesc{ + { + protoText: ` +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-armeabi_v7a.apex" + } + } + variant_number: 0 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: ARM64_V8A}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: ARM64_V8A}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-arm64_v8a.apex" + } + } + variant_number: 1 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-armeabi_v7a.arm64_v8a.apex" + } + } + variant_number: 2 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: X86}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: X86}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-x86.apex" + } + } + variant_number: 3 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value { + abi {alias: X86} + abi {alias: X86_64} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value { + abi {alias: X86} + abi {alias: X86_64} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + } + } + path: "standalones/standalone-x86.x86_64.apex" + } + } + variant_number: 4 +} +`, + configs: []testConfigDesc{ + { + name: "multi-variant multi-target ARM", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + bp.Abi_ARMEABI_V7A: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-armeabi_v7a.arm64_v8a.apex", + }, + }, + }, + { + name: "multi-variant single-target arm", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARMEABI_V7A: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-armeabi_v7a.apex", + }, + }, + }, + { + name: "multi-variant single-target arm64", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-arm64_v8a.apex", + }, + }, + }, + { + name: "multi-variant multi-target x86", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86: 0, + bp.Abi_X86_64: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-x86.x86_64.apex", + }, + }, + }, + { + name: "multi-variant single-target x86", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-x86.apex", + }, + }, + }, + { + name: "multi-variant single-target x86_64", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86_64: 0, + }, + }, + expected: SelectionResult{}, + }, + { + name: "multi-variant multi-target cross-target", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + bp.Abi_X86_64: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-arm64_v8a.apex", + }, + }, + }, + }, + }, + } + for _, testCase := range testCases { + var toc bp.BuildApksResult + if err := prototext.Unmarshal([]byte(testCase.protoText), &toc); err != nil { + t.Fatal(err) + } + for _, config := range testCase.configs { + t.Run(config.name, func(t *testing.T) { + actual := selectApks(&toc, config.targetConfig) + if !reflect.DeepEqual(config.expected, actual) { + t.Errorf("expected %v, got %v", config.expected, actual) + } + }) + } + } +} + type testZip2ZipWriter struct { entries map[string]string } -- cgit v1.2.3 From a1fb0d98dad224e82ad2377ed8b9705259022e98 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Thu, 11 Aug 2022 10:59:12 -0400 Subject: Add support for prepending text from a file Bug: b/241826272 Bug: b/258279262 Test: ./update_prebuilts.py -x Change-Id: I47146fc8a4f9120891ee28d15b006448d66aaff7 --- cmd/pom2bp/pom2bp.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index e0638b8ed..0e8ad05a9 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -828,6 +828,7 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib var regen string var pom2build bool + var prepend string flag.Var(&excludes, "exclude", "Exclude module") flag.Var(&extraStaticLibs, "extra-static-libs", "Extra static dependencies needed when depending on a module") @@ -844,6 +845,7 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules") flag.StringVar(®en, "regen", "", "Rewrite specified file") flag.BoolVar(&pom2build, "pom2build", false, "If true, will generate a Bazel BUILD file *instead* of a .bp file") + flag.StringVar(&prepend, "prepend", "", "Path to a file containing text to insert at the beginning of the generated build file") flag.Parse() if regen != "" { @@ -975,6 +977,15 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) } + if prepend != "" { + contents, err := ioutil.ReadFile(prepend) + if err != nil { + fmt.Fprintln(os.Stderr, "Error reading", prepend, err) + os.Exit(1) + } + fmt.Fprintln(buf, string(contents)) + } + depsTemplate := bpDepsTemplate template := bpTemplate if pom2build { -- cgit v1.2.3 From 688e6960fa1f3ee887c0f8159d6b0af50453028a Mon Sep 17 00:00:00 2001 From: Brett Chabot Date: Wed, 12 Oct 2022 12:12:02 -0700 Subject: Add support for pom with packaging=apk to pom2bp. Bug: b/258279262 Bug: 251825866 Test: ./prebuilts/misc/common/androidx-test/update-from-gmaven.py Change-Id: I7811898d9801bb733f3b43c55308f6741778a378 Test: None --- cmd/pom2bp/pom2bp.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index 0e8ad05a9..ba0648d19 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -207,6 +207,10 @@ func (p Pom) IsJar() bool { return p.Packaging == "jar" } +func (p Pom) IsApk() bool { + return p.Packaging == "apk" +} + func (p Pom) IsHostModule() bool { return hostModuleNames.IsHostModule(p.GroupId, p.ArtifactId) } @@ -244,6 +248,8 @@ func (p Pom) BazelTargetType() string { func (p Pom) ImportModuleType() string { if p.IsAar() { return "android_library_import" + } else if p.IsApk() { + return "android_app_import" } else if p.IsHostOnly() { return "java_import_host" } else { @@ -254,6 +260,8 @@ func (p Pom) ImportModuleType() string { func (p Pom) BazelImportTargetType() string { if p.IsAar() { return "aar_import" + } else if p.IsApk() { + return "apk_import" } else { return "java_import" } @@ -262,6 +270,8 @@ func (p Pom) BazelImportTargetType() string { func (p Pom) ImportProperty() string { if p.IsAar() { return "aars" + } else if p.IsApk() { + return "apk" } else { return "jars" } @@ -270,6 +280,8 @@ func (p Pom) ImportProperty() string { func (p Pom) BazelImportProperty() string { if p.IsAar() { return "aar" + } else if p.IsApk() { + return "apk" } else { return "jars" } @@ -493,8 +505,12 @@ func (p *Pom) ExtractMinSdkVersion() error { var bpTemplate = template.Must(template.New("bp").Parse(` {{.ImportModuleType}} { name: "{{.BpName}}", + {{- if .IsApk}} + {{.ImportProperty}}: "{{.ArtifactFile}}", + {{- else}} {{.ImportProperty}}: ["{{.ArtifactFile}}"], sdk_version: "{{.SdkVersion}}", + {{- end}} {{- if .Jetifier}} jetifier: true, {{- end}} @@ -535,8 +551,14 @@ var bpTemplate = template.Must(template.New("bp").Parse(` ], {{- end}} {{- else if not .IsHostOnly}} + {{- if not .IsApk}} min_sdk_version: "{{.DefaultMinSdkVersion}}", {{- end}} + {{- end}} + {{- if .IsApk}} + presigned: true + {{- end}} + } `)) @@ -995,7 +1017,7 @@ Usage: %s [--rewrite =] [--exclude ] [--extra-static-lib for _, pom := range poms { var err error - if staticDeps { + if staticDeps && !pom.IsApk() { err = depsTemplate.Execute(buf, pom) } else { err = template.Execute(buf, pom) -- cgit v1.2.3 From ebaac47e4edcc5a04048c822bcba5bf5805e3fe6 Mon Sep 17 00:00:00 2001 From: Rex Hoffman Date: Mon, 14 Nov 2022 04:06:48 +0000 Subject: Enable new_robolectric Allow new robolectric to break soong's exepected machine type restrictions Test: mma in /external/robolectric Bug: 244627502 Change-Id: If58a36b2d84804d586d9c8a773e2e739867fa987 Merged-In: If58a36b2d84804d586d9c8a773e2e739867fa987 --- android/neverallow.go | 1 + java/robolectric.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/android/neverallow.go b/android/neverallow.go index aa47bcaeb..5f069b877 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -154,6 +154,7 @@ func createJavaDeviceForHostRules() []Rule { "development/build", "external/guava", "external/robolectric-shadows", + "external/robolectric", "frameworks/layoutlib", } diff --git a/java/robolectric.go b/java/robolectric.go index f71952172..80be04612 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -23,6 +23,8 @@ import ( "android/soong/android" "android/soong/java/config" "android/soong/tradefed" + + "github.com/google/blueprint/proptools" ) func init() { @@ -63,6 +65,10 @@ type robolectricProperties struct { // The version number of a robolectric prebuilt to use from prebuilts/misc/common/robolectric // instead of the one built from source in external/robolectric-shadows. Robolectric_prebuilt_version *string + + // Use /external/robolectric rather than /external/robolectric-shadows as the version of robolectri + // to use. /external/robolectric closely tracks github's master, and will fully replace /external/robolectric-shadows + Upstream *bool } type robolectricTest struct { @@ -106,7 +112,11 @@ func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) { if v := String(r.robolectricProperties.Robolectric_prebuilt_version); v != "" { ctx.AddVariationDependencies(nil, libTag, fmt.Sprintf(robolectricPrebuiltLibPattern, v)) } else { - ctx.AddVariationDependencies(nil, libTag, robolectricCurrentLib) + if proptools.Bool(r.robolectricProperties.Upstream) { + ctx.AddVariationDependencies(nil, libTag, robolectricCurrentLib+"_upstream") + } else { + ctx.AddVariationDependencies(nil, libTag, robolectricCurrentLib) + } } ctx.AddVariationDependencies(nil, libTag, robolectricDefaultLibs...) -- cgit v1.2.3 From ebbab553906ccbabac7151b45bb1dfde46f19475 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Wed, 27 Apr 2022 14:20:11 -0700 Subject: Allow BoringSSL's Rust bindings to build Bug: 177080016 Test: mm in boringssl Change-Id: I3cdf031ebf7c5bafce00c078107fd7fb3a26ba2d Merged-In: I3cdf031ebf7c5bafce00c078107fd7fb3a26ba2d (cherry picked from commit 14f26aaa4ecae6b4565f8af72005476f69c3d0b4) (cherry picked from commit e58dac223de1d2a6b8e288900e29d48a9eb01a63) Merged-In: I3cdf031ebf7c5bafce00c078107fd7fb3a26ba2d --- rust/config/allowed_list.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go index 802e1da7f..746857916 100644 --- a/rust/config/allowed_list.go +++ b/rust/config/allowed_list.go @@ -8,6 +8,7 @@ var ( RustAllowedPaths = []string{ "device/google/cuttlefish", "external/adhd", + "external/boringssl", "external/crosvm", "external/libchromeos-rs", "external/minijail", -- cgit v1.2.3 From e0c45acc6bb833bbb7cc22de03e6cdb7cc43b499 Mon Sep 17 00:00:00 2001 From: Rex Hoffman Date: Wed, 30 Nov 2022 23:20:51 +0000 Subject: Support robolectric zip expectations (similar to command line zip) Test: mma in /external/robolectric Bug: 244627502 Change-Id: Id6b2b0bdb7b666a1e598b5451f869bf3d56953e5 --- third_party/zip/writer.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/third_party/zip/writer.go b/third_party/zip/writer.go index f5268385d..8a957e163 100644 --- a/third_party/zip/writer.go +++ b/third_party/zip/writer.go @@ -162,9 +162,17 @@ func (w *Writer) Close() error { if records > uint16max { records = uint16max } + // Only store uint32max for the size and the offset if they don't fit. + // Robolectric currently doesn't support zip64 and fails to find the + // offset to the central directory when the number of files in the zip + // is larger than 2^16. + if size > uint32max { + size = uint32max + } + if offset > uint32max { + offset = uint32max + } // END ANDROID CHANGE - size = uint32max - offset = uint32max } // write end record -- cgit v1.2.3 From a8033c94db8a676d095f588158c219435d79b0a0 Mon Sep 17 00:00:00 2001 From: Rex Hoffman Date: Thu, 1 Dec 2022 20:46:08 +0000 Subject: Support robolectric zip expectations (similar to command line zip) Test: mma in /external/robolectric Bug: 244627502 Change-Id: Id6b2b0bdb7b666a1e598b5451f869bf3d56953e5 Merged-In: Id6b2b0bdb7b666a1e598b5451f869bf3d56953e5 --- third_party/zip/writer.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/third_party/zip/writer.go b/third_party/zip/writer.go index f5268385d..8a957e163 100644 --- a/third_party/zip/writer.go +++ b/third_party/zip/writer.go @@ -162,9 +162,17 @@ func (w *Writer) Close() error { if records > uint16max { records = uint16max } + // Only store uint32max for the size and the offset if they don't fit. + // Robolectric currently doesn't support zip64 and fails to find the + // offset to the central directory when the number of files in the zip + // is larger than 2^16. + if size > uint32max { + size = uint32max + } + if offset > uint32max { + offset = uint32max + } // END ANDROID CHANGE - size = uint32max - offset = uint32max } // write end record -- cgit v1.2.3 From be8bf85b03f42663f9771b92860fbfdd8cccd2b6 Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Wed, 19 Oct 2022 10:16:23 +0000 Subject: Revert "Revert "update MultiAbiTargeting matching logic"" This reverts commit 6c5fae512be51e9d13390b21b7def412ee718b0e. Reason for revert: re-submitting in a topic Fix: b/246476965 Change-Id: I442e34d035da867ba36462f8e714c4d3c655af2f Merged-In: Ic3b067e98a65146cfa399e7c9b231f397e51c23e --- cmd/extract_apks/main.go | 90 +++++++++-- cmd/extract_apks/main_test.go | 364 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 438 insertions(+), 16 deletions(-) diff --git a/cmd/extract_apks/main.go b/cmd/extract_apks/main.go index 1cf64de8b..e39f8d765 100644 --- a/cmd/extract_apks/main.go +++ b/cmd/extract_apks/main.go @@ -29,6 +29,7 @@ import ( "google.golang.org/protobuf/proto" + "android/soong/cmd/extract_apks/bundle_proto" android_bundle_proto "android/soong/cmd/extract_apks/bundle_proto" "android/soong/third_party/zip" ) @@ -197,6 +198,49 @@ type multiAbiTargetingMatcher struct { *android_bundle_proto.MultiAbiTargeting } +type multiAbiValue []*bundle_proto.Abi + +func (m multiAbiValue) compare(other multiAbiValue) int { + min := func(a, b int) int { + if a < b { + return a + } + return b + } + + sortAbis := func(abiSlice multiAbiValue) func(i, j int) bool { + return func(i, j int) bool { + // sort priorities greatest to least + return multiAbiPriorities[abiSlice[i].Alias] > multiAbiPriorities[abiSlice[j].Alias] + } + } + + m = append(multiAbiValue{}, m...) + sort.Slice(m, sortAbis(m)) + other = append(multiAbiValue{}, other...) + sort.Slice(other, sortAbis(other)) + + for i := 0; i < min(len(m), len(other)); i++ { + if multiAbiPriorities[m[i].Alias] > multiAbiPriorities[other[i].Alias] { + return 1 + } + if multiAbiPriorities[m[i].Alias] < multiAbiPriorities[other[i].Alias] { + return -1 + } + } + + if len(m) == len(other) { + return 0 + } + if len(m) > len(other) { + return 1 + } + return -1 +} + +// this logic should match the logic in bundletool at +// https://github.com/google/bundletool/blob/ae0fc0162fd80d92ef8f4ef4527c066f0106942f/src/main/java/com/android/tools/build/bundletool/device/MultiAbiMatcher.java#L43 +// (note link is the commit at time of writing; but logic should always match the latest) func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if t.MultiAbiTargeting == nil { return true @@ -204,31 +248,45 @@ func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if _, ok := config.abis[android_bundle_proto.Abi_UNSPECIFIED_CPU_ARCHITECTURE]; ok { return true } - // Find the one with the highest priority. - highestPriority := 0 - for _, v := range t.GetValue() { - for _, a := range v.GetAbi() { - if _, ok := config.abis[a.Alias]; ok { - if highestPriority < multiAbiPriorities[a.Alias] { - highestPriority = multiAbiPriorities[a.Alias] - } + + multiAbiIsValid := func(m multiAbiValue) bool { + for _, abi := range m { + if _, ok := config.abis[abi.Alias]; !ok { + return false } } + return true + } + + // ensure that the current value is valid for our config + valueSetContainsViableAbi := false + multiAbiSet := t.GetValue() + for _, multiAbi := range multiAbiSet { + if multiAbiIsValid(multiAbi.GetAbi()) { + valueSetContainsViableAbi = true + } } - if highestPriority == 0 { + + if !valueSetContainsViableAbi { return false } + // See if there are any matching alternatives with a higher priority. - for _, v := range t.GetAlternatives() { - for _, a := range v.GetAbi() { - if _, ok := config.abis[a.Alias]; ok { - if highestPriority < multiAbiPriorities[a.Alias] { - // There's a better one. Skip this one. - return false - } + for _, altMultiAbi := range t.GetAlternatives() { + if !multiAbiIsValid(altMultiAbi.GetAbi()) { + continue + } + + for _, multiAbi := range multiAbiSet { + valueAbis := multiAbiValue(multiAbi.GetAbi()) + altAbis := multiAbiValue(altMultiAbi.GetAbi()) + if valueAbis.compare(altAbis) < 0 { + // An alternative has a higher priority, don't use this one + return false } } } + return true } diff --git a/cmd/extract_apks/main_test.go b/cmd/extract_apks/main_test.go index f5e40466a..c1d712df4 100644 --- a/cmd/extract_apks/main_test.go +++ b/cmd/extract_apks/main_test.go @@ -420,6 +420,370 @@ bundletool { } } +func TestSelectApks_ApexSet_Variants(t *testing.T) { + testCases := []testDesc{ + { + protoText: ` +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-armeabi_v7a.apex" + } + } + variant_number: 0 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: ARM64_V8A}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: ARM64_V8A}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-arm64_v8a.apex" + } + } + variant_number: 1 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-armeabi_v7a.arm64_v8a.apex" + } + } + variant_number: 2 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: X86}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: X86}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-x86.apex" + } + } + variant_number: 3 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value { + abi {alias: X86} + abi {alias: X86_64} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value { + abi {alias: X86} + abi {alias: X86_64} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + } + } + path: "standalones/standalone-x86.x86_64.apex" + } + } + variant_number: 4 +} +`, + configs: []testConfigDesc{ + { + name: "multi-variant multi-target ARM", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + bp.Abi_ARMEABI_V7A: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-armeabi_v7a.arm64_v8a.apex", + }, + }, + }, + { + name: "multi-variant single-target arm", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARMEABI_V7A: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-armeabi_v7a.apex", + }, + }, + }, + { + name: "multi-variant single-target arm64", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-arm64_v8a.apex", + }, + }, + }, + { + name: "multi-variant multi-target x86", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86: 0, + bp.Abi_X86_64: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-x86.x86_64.apex", + }, + }, + }, + { + name: "multi-variant single-target x86", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-x86.apex", + }, + }, + }, + { + name: "multi-variant single-target x86_64", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86_64: 0, + }, + }, + expected: SelectionResult{}, + }, + { + name: "multi-variant multi-target cross-target", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + bp.Abi_X86_64: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-arm64_v8a.apex", + }, + }, + }, + }, + }, + } + for _, testCase := range testCases { + var toc bp.BuildApksResult + if err := prototext.Unmarshal([]byte(testCase.protoText), &toc); err != nil { + t.Fatal(err) + } + for _, config := range testCase.configs { + t.Run(config.name, func(t *testing.T) { + actual := selectApks(&toc, config.targetConfig) + if !reflect.DeepEqual(config.expected, actual) { + t.Errorf("expected %v, got %v", config.expected, actual) + } + }) + } + } +} + type testZip2ZipWriter struct { entries map[string]string } -- cgit v1.2.3 From 1cc8ed5dee39e5a4c1def3e0304c28d284fb1368 Mon Sep 17 00:00:00 2001 From: Xiaowen Lei Date: Thu, 22 Dec 2022 20:28:03 +0000 Subject: Revert^2 "Revert "update MultiAbiTargeting matching logic"" be8bf85b03f42663f9771b92860fbfdd8cccd2b6 Change-Id: I70802042e5665baa471a3e9e0bc27efaf7a97944 Merged-In: Ic3b067e98a65146cfa399e7c9b231f397e51c23e --- cmd/extract_apks/main.go | 90 ++--------- cmd/extract_apks/main_test.go | 364 ------------------------------------------ 2 files changed, 16 insertions(+), 438 deletions(-) diff --git a/cmd/extract_apks/main.go b/cmd/extract_apks/main.go index e39f8d765..1cf64de8b 100644 --- a/cmd/extract_apks/main.go +++ b/cmd/extract_apks/main.go @@ -29,7 +29,6 @@ import ( "google.golang.org/protobuf/proto" - "android/soong/cmd/extract_apks/bundle_proto" android_bundle_proto "android/soong/cmd/extract_apks/bundle_proto" "android/soong/third_party/zip" ) @@ -198,49 +197,6 @@ type multiAbiTargetingMatcher struct { *android_bundle_proto.MultiAbiTargeting } -type multiAbiValue []*bundle_proto.Abi - -func (m multiAbiValue) compare(other multiAbiValue) int { - min := func(a, b int) int { - if a < b { - return a - } - return b - } - - sortAbis := func(abiSlice multiAbiValue) func(i, j int) bool { - return func(i, j int) bool { - // sort priorities greatest to least - return multiAbiPriorities[abiSlice[i].Alias] > multiAbiPriorities[abiSlice[j].Alias] - } - } - - m = append(multiAbiValue{}, m...) - sort.Slice(m, sortAbis(m)) - other = append(multiAbiValue{}, other...) - sort.Slice(other, sortAbis(other)) - - for i := 0; i < min(len(m), len(other)); i++ { - if multiAbiPriorities[m[i].Alias] > multiAbiPriorities[other[i].Alias] { - return 1 - } - if multiAbiPriorities[m[i].Alias] < multiAbiPriorities[other[i].Alias] { - return -1 - } - } - - if len(m) == len(other) { - return 0 - } - if len(m) > len(other) { - return 1 - } - return -1 -} - -// this logic should match the logic in bundletool at -// https://github.com/google/bundletool/blob/ae0fc0162fd80d92ef8f4ef4527c066f0106942f/src/main/java/com/android/tools/build/bundletool/device/MultiAbiMatcher.java#L43 -// (note link is the commit at time of writing; but logic should always match the latest) func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if t.MultiAbiTargeting == nil { return true @@ -248,45 +204,31 @@ func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if _, ok := config.abis[android_bundle_proto.Abi_UNSPECIFIED_CPU_ARCHITECTURE]; ok { return true } - - multiAbiIsValid := func(m multiAbiValue) bool { - for _, abi := range m { - if _, ok := config.abis[abi.Alias]; !ok { - return false + // Find the one with the highest priority. + highestPriority := 0 + for _, v := range t.GetValue() { + for _, a := range v.GetAbi() { + if _, ok := config.abis[a.Alias]; ok { + if highestPriority < multiAbiPriorities[a.Alias] { + highestPriority = multiAbiPriorities[a.Alias] + } } } - return true - } - - // ensure that the current value is valid for our config - valueSetContainsViableAbi := false - multiAbiSet := t.GetValue() - for _, multiAbi := range multiAbiSet { - if multiAbiIsValid(multiAbi.GetAbi()) { - valueSetContainsViableAbi = true - } } - - if !valueSetContainsViableAbi { + if highestPriority == 0 { return false } - // See if there are any matching alternatives with a higher priority. - for _, altMultiAbi := range t.GetAlternatives() { - if !multiAbiIsValid(altMultiAbi.GetAbi()) { - continue - } - - for _, multiAbi := range multiAbiSet { - valueAbis := multiAbiValue(multiAbi.GetAbi()) - altAbis := multiAbiValue(altMultiAbi.GetAbi()) - if valueAbis.compare(altAbis) < 0 { - // An alternative has a higher priority, don't use this one - return false + for _, v := range t.GetAlternatives() { + for _, a := range v.GetAbi() { + if _, ok := config.abis[a.Alias]; ok { + if highestPriority < multiAbiPriorities[a.Alias] { + // There's a better one. Skip this one. + return false + } } } } - return true } diff --git a/cmd/extract_apks/main_test.go b/cmd/extract_apks/main_test.go index c1d712df4..f5e40466a 100644 --- a/cmd/extract_apks/main_test.go +++ b/cmd/extract_apks/main_test.go @@ -420,370 +420,6 @@ bundletool { } } -func TestSelectApks_ApexSet_Variants(t *testing.T) { - testCases := []testDesc{ - { - protoText: ` -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - path: "standalones/standalone-armeabi_v7a.apex" - } - } - variant_number: 0 -} -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value {abi {alias: ARM64_V8A}} - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value {abi {alias: ARM64_V8A}} - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - path: "standalones/standalone-arm64_v8a.apex" - } - } - variant_number: 1 -} -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARMEABI_V7A}} - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARMEABI_V7A}} - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - path: "standalones/standalone-armeabi_v7a.arm64_v8a.apex" - } - } - variant_number: 2 -} -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value {abi {alias: X86}} - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value {abi {alias: X86}} - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives { - abi {alias: X86} - abi {alias: X86_64} - } - } - } - path: "standalones/standalone-x86.apex" - } - } - variant_number: 3 -} -variant { - targeting { - sdk_version_targeting {value {min {value: 29}}} - multi_abi_targeting { - value { - abi {alias: X86} - abi {alias: X86_64} - } - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - } - } - apk_set { - module_metadata { - name: "base" - delivery_type: INSTALL_TIME - } - apk_description { - targeting { - multi_abi_targeting { - value { - abi {alias: X86} - abi {alias: X86_64} - } - alternatives {abi {alias: ARMEABI_V7A}} - alternatives { - abi {alias: ARMEABI_V7A} - abi {alias: ARM64_V8A} - } - alternatives {abi {alias: ARM64_V8A}} - alternatives {abi {alias: X86}} - } - } - path: "standalones/standalone-x86.x86_64.apex" - } - } - variant_number: 4 -} -`, - configs: []testConfigDesc{ - { - name: "multi-variant multi-target ARM", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_ARM64_V8A: 0, - bp.Abi_ARMEABI_V7A: 1, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-armeabi_v7a.arm64_v8a.apex", - }, - }, - }, - { - name: "multi-variant single-target arm", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_ARMEABI_V7A: 0, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-armeabi_v7a.apex", - }, - }, - }, - { - name: "multi-variant single-target arm64", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_ARM64_V8A: 0, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-arm64_v8a.apex", - }, - }, - }, - { - name: "multi-variant multi-target x86", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_X86: 0, - bp.Abi_X86_64: 1, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-x86.x86_64.apex", - }, - }, - }, - { - name: "multi-variant single-target x86", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_X86: 0, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-x86.apex", - }, - }, - }, - { - name: "multi-variant single-target x86_64", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_X86_64: 0, - }, - }, - expected: SelectionResult{}, - }, - { - name: "multi-variant multi-target cross-target", - targetConfig: TargetConfig{ - sdkVersion: 33, - screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ - bp.ScreenDensity_DENSITY_UNSPECIFIED: true, - }, - abis: map[bp.Abi_AbiAlias]int{ - bp.Abi_ARM64_V8A: 0, - bp.Abi_X86_64: 1, - }, - }, - expected: SelectionResult{ - "base", - []string{ - "standalones/standalone-arm64_v8a.apex", - }, - }, - }, - }, - }, - } - for _, testCase := range testCases { - var toc bp.BuildApksResult - if err := prototext.Unmarshal([]byte(testCase.protoText), &toc); err != nil { - t.Fatal(err) - } - for _, config := range testCase.configs { - t.Run(config.name, func(t *testing.T) { - actual := selectApks(&toc, config.targetConfig) - if !reflect.DeepEqual(config.expected, actual) { - t.Errorf("expected %v, got %v", config.expected, actual) - } - }) - } - } -} - type testZip2ZipWriter struct { entries map[string]string } -- cgit v1.2.3 From 4114bfa398f57550a6dbf7ea7be6f9cd81328c93 Mon Sep 17 00:00:00 2001 From: Bob Hanji Date: Thu, 5 Jan 2023 18:03:03 +0000 Subject: Revert^3 "Revert "update MultiAbiTargeting matching logic"" 1cc8ed5dee39e5a4c1def3e0304c28d284fb1368 Bug: 263438687 Change-Id: I7d8585c97ca1e9a960d9725135f99579b0ae5762 Merged-In: Ic3b067e98a65146cfa399e7c9b231f397e51c23e (cherry picked from commit dc4f18317d0e296961a5569424f9038296697275) Merged-In: I7d8585c97ca1e9a960d9725135f99579b0ae5762 --- cmd/extract_apks/main.go | 90 +++++++++-- cmd/extract_apks/main_test.go | 364 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 438 insertions(+), 16 deletions(-) diff --git a/cmd/extract_apks/main.go b/cmd/extract_apks/main.go index 1cf64de8b..e39f8d765 100644 --- a/cmd/extract_apks/main.go +++ b/cmd/extract_apks/main.go @@ -29,6 +29,7 @@ import ( "google.golang.org/protobuf/proto" + "android/soong/cmd/extract_apks/bundle_proto" android_bundle_proto "android/soong/cmd/extract_apks/bundle_proto" "android/soong/third_party/zip" ) @@ -197,6 +198,49 @@ type multiAbiTargetingMatcher struct { *android_bundle_proto.MultiAbiTargeting } +type multiAbiValue []*bundle_proto.Abi + +func (m multiAbiValue) compare(other multiAbiValue) int { + min := func(a, b int) int { + if a < b { + return a + } + return b + } + + sortAbis := func(abiSlice multiAbiValue) func(i, j int) bool { + return func(i, j int) bool { + // sort priorities greatest to least + return multiAbiPriorities[abiSlice[i].Alias] > multiAbiPriorities[abiSlice[j].Alias] + } + } + + m = append(multiAbiValue{}, m...) + sort.Slice(m, sortAbis(m)) + other = append(multiAbiValue{}, other...) + sort.Slice(other, sortAbis(other)) + + for i := 0; i < min(len(m), len(other)); i++ { + if multiAbiPriorities[m[i].Alias] > multiAbiPriorities[other[i].Alias] { + return 1 + } + if multiAbiPriorities[m[i].Alias] < multiAbiPriorities[other[i].Alias] { + return -1 + } + } + + if len(m) == len(other) { + return 0 + } + if len(m) > len(other) { + return 1 + } + return -1 +} + +// this logic should match the logic in bundletool at +// https://github.com/google/bundletool/blob/ae0fc0162fd80d92ef8f4ef4527c066f0106942f/src/main/java/com/android/tools/build/bundletool/device/MultiAbiMatcher.java#L43 +// (note link is the commit at time of writing; but logic should always match the latest) func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if t.MultiAbiTargeting == nil { return true @@ -204,31 +248,45 @@ func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool { if _, ok := config.abis[android_bundle_proto.Abi_UNSPECIFIED_CPU_ARCHITECTURE]; ok { return true } - // Find the one with the highest priority. - highestPriority := 0 - for _, v := range t.GetValue() { - for _, a := range v.GetAbi() { - if _, ok := config.abis[a.Alias]; ok { - if highestPriority < multiAbiPriorities[a.Alias] { - highestPriority = multiAbiPriorities[a.Alias] - } + + multiAbiIsValid := func(m multiAbiValue) bool { + for _, abi := range m { + if _, ok := config.abis[abi.Alias]; !ok { + return false } } + return true + } + + // ensure that the current value is valid for our config + valueSetContainsViableAbi := false + multiAbiSet := t.GetValue() + for _, multiAbi := range multiAbiSet { + if multiAbiIsValid(multiAbi.GetAbi()) { + valueSetContainsViableAbi = true + } } - if highestPriority == 0 { + + if !valueSetContainsViableAbi { return false } + // See if there are any matching alternatives with a higher priority. - for _, v := range t.GetAlternatives() { - for _, a := range v.GetAbi() { - if _, ok := config.abis[a.Alias]; ok { - if highestPriority < multiAbiPriorities[a.Alias] { - // There's a better one. Skip this one. - return false - } + for _, altMultiAbi := range t.GetAlternatives() { + if !multiAbiIsValid(altMultiAbi.GetAbi()) { + continue + } + + for _, multiAbi := range multiAbiSet { + valueAbis := multiAbiValue(multiAbi.GetAbi()) + altAbis := multiAbiValue(altMultiAbi.GetAbi()) + if valueAbis.compare(altAbis) < 0 { + // An alternative has a higher priority, don't use this one + return false } } } + return true } diff --git a/cmd/extract_apks/main_test.go b/cmd/extract_apks/main_test.go index f5e40466a..c1d712df4 100644 --- a/cmd/extract_apks/main_test.go +++ b/cmd/extract_apks/main_test.go @@ -420,6 +420,370 @@ bundletool { } } +func TestSelectApks_ApexSet_Variants(t *testing.T) { + testCases := []testDesc{ + { + protoText: ` +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-armeabi_v7a.apex" + } + } + variant_number: 0 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: ARM64_V8A}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: ARM64_V8A}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-arm64_v8a.apex" + } + } + variant_number: 1 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-armeabi_v7a.arm64_v8a.apex" + } + } + variant_number: 2 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value {abi {alias: X86}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value {abi {alias: X86}} + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives { + abi {alias: X86} + abi {alias: X86_64} + } + } + } + path: "standalones/standalone-x86.apex" + } + } + variant_number: 3 +} +variant { + targeting { + sdk_version_targeting {value {min {value: 29}}} + multi_abi_targeting { + value { + abi {alias: X86} + abi {alias: X86_64} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + } + } + apk_set { + module_metadata { + name: "base" + delivery_type: INSTALL_TIME + } + apk_description { + targeting { + multi_abi_targeting { + value { + abi {alias: X86} + abi {alias: X86_64} + } + alternatives {abi {alias: ARMEABI_V7A}} + alternatives { + abi {alias: ARMEABI_V7A} + abi {alias: ARM64_V8A} + } + alternatives {abi {alias: ARM64_V8A}} + alternatives {abi {alias: X86}} + } + } + path: "standalones/standalone-x86.x86_64.apex" + } + } + variant_number: 4 +} +`, + configs: []testConfigDesc{ + { + name: "multi-variant multi-target ARM", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + bp.Abi_ARMEABI_V7A: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-armeabi_v7a.arm64_v8a.apex", + }, + }, + }, + { + name: "multi-variant single-target arm", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARMEABI_V7A: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-armeabi_v7a.apex", + }, + }, + }, + { + name: "multi-variant single-target arm64", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-arm64_v8a.apex", + }, + }, + }, + { + name: "multi-variant multi-target x86", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86: 0, + bp.Abi_X86_64: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-x86.x86_64.apex", + }, + }, + }, + { + name: "multi-variant single-target x86", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86: 0, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-x86.apex", + }, + }, + }, + { + name: "multi-variant single-target x86_64", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_X86_64: 0, + }, + }, + expected: SelectionResult{}, + }, + { + name: "multi-variant multi-target cross-target", + targetConfig: TargetConfig{ + sdkVersion: 33, + screenDpi: map[bp.ScreenDensity_DensityAlias]bool{ + bp.ScreenDensity_DENSITY_UNSPECIFIED: true, + }, + abis: map[bp.Abi_AbiAlias]int{ + bp.Abi_ARM64_V8A: 0, + bp.Abi_X86_64: 1, + }, + }, + expected: SelectionResult{ + "base", + []string{ + "standalones/standalone-arm64_v8a.apex", + }, + }, + }, + }, + }, + } + for _, testCase := range testCases { + var toc bp.BuildApksResult + if err := prototext.Unmarshal([]byte(testCase.protoText), &toc); err != nil { + t.Fatal(err) + } + for _, config := range testCase.configs { + t.Run(config.name, func(t *testing.T) { + actual := selectApks(&toc, config.targetConfig) + if !reflect.DeepEqual(config.expected, actual) { + t.Errorf("expected %v, got %v", config.expected, actual) + } + }) + } + } +} + type testZip2ZipWriter struct { entries map[string]string } -- cgit v1.2.3 From 48d9ec056458a4bff78a9c572bc9c185dc037ccc Mon Sep 17 00:00:00 2001 From: Shikha Panwar Date: Wed, 21 Dec 2022 12:54:45 +0000 Subject: Expose avb_hash_algorithm as a property. When avb_hash_algorithm is set, for filesystem type build targets, add_hashtree_footer will be called with the appropriate --hash_algorithm flag. Bug: 262892300 Test: Build succeeds Merged-In: If2f9c9aa1e98314b3d3e2f8bf25c1bab193f908e Merged-In: Ief4b0f0fd89ebf64b45b29962a3811698bc922d6 Change-Id: I3bf5aecbfd717036a5b167696b107ee6cb1830b4 (cherry picked from commit f3d1e8c24cba69b93d9fdd2f01d770927988eeb1) Merged-In: I3bf5aecbfd717036a5b167696b107ee6cb1830b4 --- filesystem/filesystem.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index ccf9e9d3b..665faaaed 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -66,9 +66,13 @@ type filesystemProperties struct { // TODO(jiyong): allow apex_key to be specified here Avb_private_key *string `android:"path"` - // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096. + // Signing algorithm for avbtool. Default is SHA256_RSA4096. Avb_algorithm *string + // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to + // avbtool. Default used by avbtool is sha1. + Avb_hash_algorithm *string + // Name of the partition stored in vbmeta desc. Defaults to the name of this module. Partition_name *string @@ -318,7 +322,11 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android. addStr("avb_algorithm", algorithm) key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) addPath("avb_key_path", key) - addStr("avb_add_hashtree_footer_args", "--do_not_generate_fec") + avb_add_hashtree_footer_args := "--do_not_generate_fec" + if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" { + avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm + } + addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name()) addStr("partition_name", partitionName) } -- cgit v1.2.3