diff options
author | 2023-05-08 20:26:03 +0000 | |
---|---|---|
committer | 2023-05-08 20:26:03 +0000 | |
commit | 429b584f59a317803ddb93d237a954c85b66dda4 (patch) | |
tree | 1ed5d9f69020b57c6f6aa6f12e3d69bd1ad81f0c /build | |
parent | 32645f219cb3d4588c1aefcf9c7db944aef6cd45 (diff) |
Revert "Remove the codegen property"
This revert was created by Android Culprit Assistant. The culprit was identified in the following culprit search session (http://go/aca-get/88fe93a5-fc12-490e-8914-e81bb746b001).
Change-Id: I87dc85008a9c79c017055ae641f41809d19b1c78
Diffstat (limited to 'build')
-rw-r--r-- | build/Android.bp | 61 | ||||
-rw-r--r-- | build/art.go | 20 | ||||
-rw-r--r-- | build/codegen.go | 239 |
3 files changed, 282 insertions, 38 deletions
diff --git a/build/Android.bp b/build/Android.bp index a17bc42145..4569b5523f 100644 --- a/build/Android.bp +++ b/build/Android.bp @@ -21,6 +21,7 @@ bootstrap_go_package { ], srcs: [ "art.go", + "codegen.go", "makevars.go", ], pluginFor: ["soong_build"], @@ -173,37 +174,13 @@ art_module_art_global_defaults { }, target: { - // To use oprofile_android --callgraph, add these flags to the appropriate - // android_<arch> and recompile with - // mmma -j art - // "-fno-omit-frame-pointer", - // "-marm", - // "-mapcs", - android_arm: { - cflags: [ - "-DART_ENABLE_CODEGEN_arm", - ], - }, - android_arm64: { - cflags: [ - "-DART_ENABLE_CODEGEN_arm", - "-DART_ENABLE_CODEGEN_arm64", - ], - }, - android_riscv64: { - cflags: [ - "-DART_ENABLE_CODEGEN_riscv64", - ], - }, - android_x86: { - cflags: [ - "-DART_ENABLE_CODEGEN_x86", - ], - }, - android_x86_64: { + android: { cflags: [ - "-DART_ENABLE_CODEGEN_x86", - "-DART_ENABLE_CODEGEN_x86_64", + // To use oprofile_android --callgraph, uncomment this and recompile with + // mmma -j art + // "-fno-omit-frame-pointer", + // "-marm", + // "-mapcs", ], }, linux: { @@ -239,12 +216,6 @@ art_module_art_global_defaults { // Bug: 15446488. We don't omit the frame pointer to work around // clang/libunwind bugs that cause SEGVs in run-test-004-ThreadStress. "-fno-omit-frame-pointer", - - "-DART_ENABLE_CODEGEN_arm", - "-DART_ENABLE_CODEGEN_arm64", - "-DART_ENABLE_CODEGEN_riscv64", - "-DART_ENABLE_CODEGEN_x86", - "-DART_ENABLE_CODEGEN_x86_64", ], }, // The build assumes that all our x86/x86_64 hosts (such as buildbots and developer @@ -268,6 +239,24 @@ art_module_art_global_defaults { }, }, + codegen: { + arm: { + cflags: ["-DART_ENABLE_CODEGEN_arm"], + }, + arm64: { + cflags: ["-DART_ENABLE_CODEGEN_arm64"], + }, + riscv64: { + cflags: ["-DART_ENABLE_CODEGEN_riscv64"], + }, + x86: { + cflags: ["-DART_ENABLE_CODEGEN_x86"], + }, + x86_64: { + cflags: ["-DART_ENABLE_CODEGEN_x86_64"], + }, + }, + tidy_checks: art_clang_tidy_errors + art_clang_tidy_disabled, tidy_checks_as_errors: art_clang_tidy_errors, diff --git a/build/art.go b/build/art.go index b82e974bd8..0e5c055d26 100644 --- a/build/art.go +++ b/build/art.go @@ -377,7 +377,7 @@ func artHostTestApexBundleFactory() android.Module { } func artGlobalDefaultsFactory() android.Module { - module := cc.DefaultsFactory() + module := artDefaultsFactory() android.AddLoadHook(module, addImplicitFlags) android.AddLoadHook(module, globalDefaults) @@ -385,11 +385,18 @@ func artGlobalDefaultsFactory() android.Module { } func artDefaultsFactory() android.Module { - return cc.DefaultsFactory() + c := &codegenProperties{} + module := cc.DefaultsFactory(c) + android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticAndSharedLibrary) }) + + return module } func artLibrary() android.Module { module := cc.LibraryFactory() + + installCodegenCustomizer(module, staticAndSharedLibrary) + android.AddLoadHook(module, addImplicitFlags) android.AddInstallHook(module, addTestcasesFile) return module @@ -397,6 +404,9 @@ func artLibrary() android.Module { func artStaticLibrary() android.Module { module := cc.LibraryStaticFactory() + + installCodegenCustomizer(module, staticLibrary) + android.AddLoadHook(module, addImplicitFlags) return module } @@ -414,6 +424,9 @@ func artBinary() android.Module { func artTest() android.Module { // Disable bp2build. module := cc.NewTest(android.HostAndDeviceSupported, false /* bazelable */).Init() + + installCodegenCustomizer(module, binary) + android.AddLoadHook(module, addImplicitFlags) android.AddLoadHook(module, customLinker) android.AddLoadHook(module, prefer32Bit) @@ -423,6 +436,9 @@ func artTest() android.Module { func artTestLibrary() android.Module { module := cc.TestLibraryFactory() + + installCodegenCustomizer(module, staticAndSharedLibrary) + android.AddLoadHook(module, addImplicitFlags) android.AddLoadHook(module, prefer32Bit) android.AddInstallHook(module, testInstall) diff --git a/build/codegen.go b/build/codegen.go new file mode 100644 index 0000000000..3cc51a8e1f --- /dev/null +++ b/build/codegen.go @@ -0,0 +1,239 @@ +// Copyright (C) 2016 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package art + +// This file implements the "codegen" property to apply different properties based on the currently +// selected codegen arches, which defaults to all arches on the host and the primary and secondary +// arches on the device. + +import ( + "sort" + "strings" + + "android/soong/android" +) + +type moduleType struct { + library bool + static bool + shared bool +} + +var ( + staticLibrary = moduleType{true, true, false} + sharedLibrary = moduleType{true, false, true} + staticAndSharedLibrary = moduleType{true, true, true} + binary = moduleType{false, false, false} +) + +func codegen(ctx android.LoadHookContext, c *codegenProperties, t moduleType) { + var hostArches, deviceArches []string + + e := ctx.Config().Getenv("ART_HOST_CODEGEN_ARCHS") + if e == "" { + hostArches = supportedArches + } else { + hostArches = strings.Split(e, " ") + } + + e = ctx.Config().Getenv("ART_TARGET_CODEGEN_ARCHS") + if e == "" { + deviceArches = defaultDeviceCodegenArches(ctx) + } else { + deviceArches = strings.Split(e, " ") + } + + getCodegenArchProperties := func(archName string) *codegenArchProperties { + var arch *codegenArchProperties + switch archName { + case "arm": + arch = &c.Codegen.Arm + case "arm64": + arch = &c.Codegen.Arm64 + case "riscv64": + arch = &c.Codegen.Riscv64 + case "x86": + arch = &c.Codegen.X86 + case "x86_64": + arch = &c.Codegen.X86_64 + default: + ctx.ModuleErrorf("Unknown codegen architecture %q", archName) + } + return arch + } + + appendCodegenSourceArchProperties := func(p *CodegenSourceArchProperties, archName string) { + arch := getCodegenArchProperties(archName) + p.Srcs = append(p.Srcs, arch.CodegenSourceArchProperties.Srcs...) + } + + addCodegenSourceArchProperties := func(host bool, p *CodegenSourceArchProperties) { + type sourceProps struct { + Target struct { + Android *CodegenSourceArchProperties + Host *CodegenSourceArchProperties + } + } + + sp := &sourceProps{} + if host { + sp.Target.Host = p + } else { + sp.Target.Android = p + } + ctx.AppendProperties(sp) + } + + addCodegenArchProperties := func(host bool, archName string) { + type commonProps struct { + Target struct { + Android *CodegenCommonArchProperties + Host *CodegenCommonArchProperties + } + } + + type libraryProps struct { + Target struct { + Android *CodegenLibraryArchProperties + Host *CodegenLibraryArchProperties + } + } + + type sharedLibraryProps struct { + Target struct { + Android *CodegenLibraryArchSharedProperties + Host *CodegenLibraryArchSharedProperties + } + } + + type staticLibraryProps struct { + Target struct { + Android *CodegenLibraryArchStaticProperties + Host *CodegenLibraryArchStaticProperties + } + } + + arch := getCodegenArchProperties(archName) + + cp := &commonProps{} + lp := &libraryProps{} + sharedLP := &sharedLibraryProps{} + staticLP := &staticLibraryProps{} + if host { + cp.Target.Host = &arch.CodegenCommonArchProperties + lp.Target.Host = &arch.CodegenLibraryArchProperties + sharedLP.Target.Host = &arch.CodegenLibraryArchSharedProperties + staticLP.Target.Host = &arch.CodegenLibraryArchStaticProperties + } else { + cp.Target.Android = &arch.CodegenCommonArchProperties + lp.Target.Android = &arch.CodegenLibraryArchProperties + sharedLP.Target.Android = &arch.CodegenLibraryArchSharedProperties + staticLP.Target.Android = &arch.CodegenLibraryArchStaticProperties + } + + ctx.AppendProperties(cp) + if t.library { + ctx.AppendProperties(lp) + if t.static { + ctx.AppendProperties(staticLP) + } + if t.shared { + ctx.AppendProperties(sharedLP) + } + } + } + + addCodegenProperties := func(host bool, arches []string) { + sourceProps := &CodegenSourceArchProperties{} + for _, arch := range arches { + appendCodegenSourceArchProperties(sourceProps, arch) + addCodegenArchProperties(host, arch) + } + sourceProps.Srcs = android.FirstUniqueStrings(sourceProps.Srcs) + addCodegenSourceArchProperties(host, sourceProps) + } + + addCodegenProperties(false /* host */, deviceArches) + addCodegenProperties(true /* host */, hostArches) +} + +// These properties are allowed to contain the same source file name in different architectures. +// They we will be deduplicated automatically. +type CodegenSourceArchProperties struct { + Srcs []string +} + +type CodegenCommonArchProperties struct { + Cflags []string + Cppflags []string +} + +type CodegenLibraryArchProperties struct { + Static_libs []string + Export_static_lib_headers []string +} + +type CodegenLibraryArchStaticProperties struct { + Static struct { + Whole_static_libs []string + } +} +type CodegenLibraryArchSharedProperties struct { + Shared struct { + Shared_libs []string + Export_shared_lib_headers []string + } +} + +type codegenArchProperties struct { + CodegenSourceArchProperties + CodegenCommonArchProperties + CodegenLibraryArchProperties + CodegenLibraryArchStaticProperties + CodegenLibraryArchSharedProperties +} + +type codegenProperties struct { + Codegen struct { + Arm, Arm64, Riscv64, X86, X86_64 codegenArchProperties + } +} + +func defaultDeviceCodegenArches(ctx android.LoadHookContext) []string { + arches := make(map[string]bool) + for _, a := range ctx.DeviceConfig().Arches() { + s := a.ArchType.String() + arches[s] = true + if s == "arm64" { + arches["arm"] = true + } else if s == "riscv64" { + arches["riscv64"] = true + } else if s == "x86_64" { + arches["x86"] = true + } + } + ret := make([]string, 0, len(arches)) + for a := range arches { + ret = append(ret, a) + } + sort.Strings(ret) + return ret +} + +func installCodegenCustomizer(module android.Module, t moduleType) { + c := &codegenProperties{} + android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, t) }) + module.AddProperties(c) +} |