From df0289bfbdb770d45adcb388c8ebb455eafa81d8 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Thu, 28 Mar 2024 06:10:30 +0000 Subject: [PATCH 1/4] Revert^4 "Enable full LTO optimization by default" 97f68587fff22676d3f71b7e0ea7f2d2c4649558 Change-Id: I722e046ed23874a75f407d3d211124251b652aae --- cc/lto.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cc/lto.go b/cc/lto.go index a084db7be..a7e777526 100644 --- a/cc/lto.go +++ b/cc/lto.go @@ -54,6 +54,9 @@ type LTOProperties struct { // Use -fwhole-program-vtables cflag. Whole_program_vtables *bool + + // Use --lto-O0 flag. + Lto_O0 *bool } type lto struct { @@ -106,12 +109,8 @@ func (lto *lto) flags(ctx ModuleContext, flags Flags) Flags { ltoCFlags := []string{"-flto=thin", "-fsplit-lto-unit"} var ltoLdFlags []string - // The module did not explicitly turn on LTO. Only leverage LTO's - // better dead code elimination and CFG simplification, but do - // not perform costly optimizations for a balance between compile - // time, binary size and performance. - // Apply the same for Eng builds as well. - if !lto.ThinLTO() || ctx.Config().Eng() { + // Do not perform costly LTO optimizations for Eng builds. + if Bool(lto.Properties.Lto_O0) || ctx.Config().Eng() { ltoLdFlags = append(ltoLdFlags, "-Wl,--lto-O0") } From 5591460e81b03ad816f3850806178dd3ce7f48da Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 13 Jun 2024 10:49:13 -0700 Subject: [PATCH 2/4] Remove debug/release cflags These were never fully implemented, release cflags are the same as regular cflags, and debug cflags are not used at all. Bug: 346922064 Test: Presubmits Change-Id: I0e8914e03f3a092bbc816cabf75255c55c3531e4 --- cc/compiler.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/cc/compiler.go b/cc/compiler.go index ede6a5d0a..7de081064 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -172,12 +172,6 @@ type BaseCompilerProperties struct { Target_api *string } - Debug, Release struct { - // list of module-specific flags that will be used for C and C++ compiles in debug or - // release builds - Cflags []string `android:"arch_variant"` - } `android:"arch_variant"` - Target struct { Vendor, Product struct { // list of source files that should only be used in vendor or @@ -478,11 +472,6 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps ctx.ModuleErrorf("%s", err) } - CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags) - - // TODO: debug - flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Release.Cflags)...) - if !ctx.DeviceConfig().BuildBrokenClangCFlags() && len(compiler.Properties.Clang_cflags) != 0 { ctx.PropertyErrorf("clang_cflags", "property is deprecated, see Changes.md file") } else { From e81e77a2b16936610c90c5af36efb8e4a5b47b3c Mon Sep 17 00:00:00 2001 From: mrziwang Date: Thu, 13 Jun 2024 17:02:59 -0700 Subject: [PATCH 3/4] Add another way for TestingModule to get its output files In OutputFiles method, TestingModule is able to get its own output files by reading its module base property. If the TestingModule never updates its outputFiles property, it will fall back to use the OutputFileProducer interface. Only empty string tag case is added in this CL since all the testing modules are getting the output files using empty string tag. Test: CI Bug: 339477385 Change-Id: I3009ae45d8d909653e3b6b222bced9ccabbaede7 --- android/testing.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/android/testing.go b/android/testing.go index 6518f4a53..6fb2997cb 100644 --- a/android/testing.go +++ b/android/testing.go @@ -1014,10 +1014,18 @@ func (m TestingModule) VariablesForTestsRelativeToTop() map[string]string { return normalizeStringMapRelativeToTop(m.config, m.module.VariablesForTests()) } -// OutputFiles calls OutputFileProducer.OutputFiles on the encapsulated module, exits the test -// immediately if there is an error and otherwise returns the result of calling Paths.RelativeToTop +// OutputFiles first checks if module base outputFiles property has any output +// files can be used to return. +// If not, it calls OutputFileProducer.OutputFiles on the +// encapsulated module, exits the test immediately if there is an error and +// otherwise returns the result of calling Paths.RelativeToTop // on the returned Paths. func (m TestingModule) OutputFiles(t *testing.T, tag string) Paths { + // TODO: add non-empty-string tag case and remove OutputFileProducer part + if tag == "" && m.module.base().outputFiles.DefaultOutputFiles != nil { + return m.module.base().outputFiles.DefaultOutputFiles.RelativeToTop() + } + producer, ok := m.module.(OutputFileProducer) if !ok { t.Fatalf("%q must implement OutputFileProducer\n", m.module.Name()) From ad18649d293ccdf039a217ac6afbb1528bf463b4 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Fri, 14 Jun 2024 14:13:54 -0700 Subject: [PATCH 4/4] Remove saveToBazelConfigFile Bug: 315353489 Test: Presubmits Change-Id: I781f0fd9d0241b9742b0b84f5df4088e7bba16c7 --- android/config.go | 80 +---------------------------------------------- 1 file changed, 1 insertion(+), 79 deletions(-) diff --git a/android/config.go b/android/config.go index a18cb8be8..da76f0dd2 100644 --- a/android/config.go +++ b/android/config.go @@ -22,7 +22,6 @@ import ( "fmt" "os" "path/filepath" - "reflect" "runtime" "strconv" "strings" @@ -37,9 +36,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android/soongconfig" - "android/soong/bazel" "android/soong/remoteexec" - "android/soong/starlark_fmt" ) // Bool re-exports proptools.Bool for the android package. @@ -413,7 +410,7 @@ func loadFromConfigFile(configurable *ProductVariables, filename string) error { proptools.StringPtr(String(configurable.Platform_sdk_codename)) } - return saveToBazelConfigFile(configurable, filepath.Dir(filename)) + return nil } // atomically writes the config file in case two copies of soong_build are running simultaneously @@ -447,81 +444,6 @@ func saveToConfigFile(config *ProductVariables, filename string) error { return nil } -type productVariableStarlarkRepresentation struct { - soongType string - selectable bool - archVariant bool -} - -func saveToBazelConfigFile(config *ProductVariables, outDir string) error { - dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config") - err := createDirIfNonexistent(dir, os.ModePerm) - if err != nil { - return fmt.Errorf("Could not create dir %s: %s", dir, err) - } - - allProductVariablesType := reflect.TypeOf((*ProductVariables)(nil)).Elem() - productVariablesInfo := make(map[string]productVariableStarlarkRepresentation) - p := variableProperties{} - t := reflect.TypeOf(p.Product_variables) - for i := 0; i < t.NumField(); i++ { - f := t.Field(i) - archVariant := proptools.HasTag(f, "android", "arch_variant") - if mainProductVariablesStructField, ok := allProductVariablesType.FieldByName(f.Name); ok { - productVariablesInfo[f.Name] = productVariableStarlarkRepresentation{ - soongType: stringRepresentationOfSimpleType(mainProductVariablesStructField.Type), - selectable: true, - archVariant: archVariant, - } - } else { - panic("Unknown variable " + f.Name) - } - } - - err = pathtools.WriteFileIfChanged(filepath.Join(dir, "product_variable_constants.bzl"), []byte(fmt.Sprintf(` -# product_var_constant_info is a map of product variables to information about them. The fields are: -# - soongType: The type of the product variable as it appears in soong's ProductVariables struct. -# examples are string, bool, int, *bool, *string, []string, etc. This may be an overly -# conservative estimation of the type, for example a *bool could oftentimes just be a -# bool that defaults to false. -# - selectable: if this product variable can be selected on in Android.bp/build files. This means -# it's listed in the "variableProperties" soong struct. Currently all variables in -# this list are selectable because we only need the selectable ones at the moment, -# but the list may be expanded later. -# - archVariant: If the variable is tagged as arch variant in the "variableProperties" struct. -product_var_constant_info = %s -product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable] -arch_variant_product_var_constraints = [k for k, v in product_var_constant_info.items() if v.selectable and v.archVariant] -`, starlark_fmt.PrintAny(productVariablesInfo, 0))), 0644) - if err != nil { - return fmt.Errorf("Could not write .bzl config file %s", err) - } - err = pathtools.WriteFileIfChanged(filepath.Join(dir, "BUILD"), - []byte(bazel.GeneratedBazelFileWarning), 0644) - if err != nil { - return fmt.Errorf("Could not write BUILD config file %s", err) - } - - return nil -} - -func stringRepresentationOfSimpleType(ty reflect.Type) string { - switch ty.Kind() { - case reflect.String: - return "string" - case reflect.Bool: - return "bool" - case reflect.Int: - return "int" - case reflect.Slice: - return "[]" + stringRepresentationOfSimpleType(ty.Elem()) - case reflect.Pointer: - return "*" + stringRepresentationOfSimpleType(ty.Elem()) - default: - panic("unimplemented type: " + ty.Kind().String()) - } -} - // NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that // use the android package. func NullConfig(outDir, soongOutDir string) Config {