diff options
| -rw-r--r-- | android/bazel.go | 12 | ||||
| -rw-r--r-- | apex/apex_test.go | 30 | ||||
| -rw-r--r-- | cc/cc.go | 10 | ||||
| -rw-r--r-- | cc/compiler.go | 21 | ||||
| -rw-r--r-- | cc/lto.go | 89 | ||||
| -rw-r--r-- | rust/compiler.go | 4 | ||||
| -rw-r--r-- | rust/compiler_test.go | 35 |
7 files changed, 102 insertions, 99 deletions
diff --git a/android/bazel.go b/android/bazel.go index 6aba75984..e4eaa37e3 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -182,8 +182,8 @@ var ( "external/boringssl": Bp2BuildDefaultTrueRecursively, "external/brotli": Bp2BuildDefaultTrue, "external/fmtlib": Bp2BuildDefaultTrueRecursively, - "external/googletest/googletest": Bp2BuildDefaultTrueRecursively, "external/google-benchmark": Bp2BuildDefaultTrueRecursively, + "external/googletest/googletest": Bp2BuildDefaultTrueRecursively, "external/gwp_asan": Bp2BuildDefaultTrueRecursively, "external/jemalloc_new": Bp2BuildDefaultTrueRecursively, "external/jsoncpp": Bp2BuildDefaultTrueRecursively, @@ -191,10 +191,15 @@ var ( "external/libcxx": Bp2BuildDefaultTrueRecursively, "external/libcxxabi": Bp2BuildDefaultTrueRecursively, "external/lz4/lib": Bp2BuildDefaultTrue, + "external/mdnsresponder": Bp2BuildDefaultTrueRecursively, + "external/minijail": Bp2BuildDefaultTrueRecursively, + "external/pcre": Bp2BuildDefaultTrueRecursively, "external/protobuf": Bp2BuildDefaultTrueRecursively, "external/python/six": Bp2BuildDefaultTrueRecursively, "external/scudo": Bp2BuildDefaultTrueRecursively, + "external/selinux/libselinux": Bp2BuildDefaultTrueRecursively, "external/zlib": Bp2BuildDefaultTrueRecursively, + "external/zstd": Bp2BuildDefaultTrueRecursively, "frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively, "packages/modules/adb": Bp2BuildDefaultTrue, "packages/modules/adb/crypto": Bp2BuildDefaultTrueRecursively, @@ -208,6 +213,7 @@ var ( "system/core/libasyncio": Bp2BuildDefaultTrue, "system/core/libcrypto_utils": Bp2BuildDefaultTrueRecursively, "system/core/libcutils": Bp2BuildDefaultTrueRecursively, + "system/core/libpackagelistparser": Bp2BuildDefaultTrueRecursively, "system/core/libprocessgroup": Bp2BuildDefaultTrue, "system/core/libprocessgroup/cgrouprc": Bp2BuildDefaultTrue, "system/core/libprocessgroup/cgrouprc_format": Bp2BuildDefaultTrue, @@ -241,6 +247,8 @@ var ( "libcap", // http://b/198595332, depends on _makenames, a cc_binary "cap_names.h", // http://b/198596102, depends on _makenames, a cc_binary + "libminijail", // depends on unconverted modules: libcap + // Tests. Handle later. "libbionic_tests_headers_posix", // http://b/186024507, cc_library_static, sched.h, time.h not found "libjemalloc5_integrationtest", @@ -282,7 +290,7 @@ var ( "libseccomp_policy_app_zygote_sources", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module. "libseccomp_policy_app_sources", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module. "libseccomp_policy_system_sources", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module. - + "minijail_constants_json", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module. } // Used for quicker lookups diff --git a/apex/apex_test.go b/apex/apex_test.go index 4a5373f66..78a6bb8f4 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -3183,7 +3183,6 @@ func TestMacro(t *testing.T) { "myapex", "otherapex", ], - use_apex_name_macro: true, recovery_available: true, min_sdk_version: "29", } @@ -3198,13 +3197,11 @@ func TestMacro(t *testing.T) { mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex29").Rule("cc").Args["cFlags"] ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and // each variant defines additional macros to distinguish which apex variant it is built for @@ -3213,42 +3210,15 @@ func TestMacro(t *testing.T) { mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") - // APEX variant has __ANDROID_APEX__ defined - mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] - ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") - ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") - - // APEX variant has __ANDROID_APEX__ defined - mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] - ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") - ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") - // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") - // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique - // variant. - // non-APEX variant does not have __ANDROID_APEX__ defined mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") - // APEX variant has __ANDROID_APEX__ defined - mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] - ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") - - // APEX variant has __ANDROID_APEX__ defined - mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] - ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") - // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ mylibCFlags = ctx.ModuleForTests("mylib2", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") @@ -3249,16 +3249,6 @@ func (c *Module) TestFor() []string { return c.Properties.Test_for } -func (c *Module) UniqueApexVariations() bool { - if u, ok := c.compiler.(interface { - uniqueApexVariations() bool - }); ok { - return u.uniqueApexVariations() - } else { - return false - } -} - func (c *Module) EverInstallable() bool { return c.installer != nil && // Check to see whether the module is actually ever installable. diff --git a/cc/compiler.go b/cc/compiler.go index 4f96712e6..2ac7bf332 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -209,15 +209,6 @@ type BaseCompilerProperties struct { // Build and link with OpenMP Openmp *bool `android:"arch_variant"` - - // Deprecated. - // Adds __ANDROID_APEX_<APEX_MODULE_NAME>__ macro defined for apex variants in addition to __ANDROID_APEX__ - Use_apex_name_macro *bool - - // Adds two macros for apex variants in addition to __ANDROID_APEX__ - // * __ANDROID_APEX_COM_ANDROID_FOO__ - // * __ANDROID_APEX_NAME__="com.android.foo" - UseApexNameMacro bool `blueprint:"mutated"` } func NewBaseCompiler() *baseCompiler { @@ -291,10 +282,6 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { return deps } -func (compiler *baseCompiler) useApexNameMacro() bool { - return Bool(compiler.Properties.Use_apex_name_macro) || compiler.Properties.UseApexNameMacro -} - // Return true if the module is in the WarningAllowedProjects. func warningsAreAllowed(subdir string) bool { subdir += "/" @@ -405,10 +392,6 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps if ctx.apexVariationName() != "" { flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_APEX__") - if compiler.useApexNameMacro() { - flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_APEX_"+makeDefineString(ctx.apexVariationName())+"__") - flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_APEX_NAME__='\""+ctx.apexVariationName()+"\"'") - } if ctx.Device() { flags.Global.CommonFlags = append(flags.Global.CommonFlags, fmt.Sprintf("-D__ANDROID_APEX_MIN_SDK_VERSION__=%d", @@ -634,10 +617,6 @@ func (compiler *baseCompiler) hasSrcExt(ext string) bool { return false } -func (compiler *baseCompiler) uniqueApexVariations() bool { - return compiler.useApexNameMacro() -} - var invalidDefineCharRegex = regexp.MustCompile("[^a-zA-Z0-9_]") // makeDefineString transforms a name of an APEX module into a value to be used as value for C define @@ -49,8 +49,9 @@ type LTOProperties struct { // Dep properties indicate that this module needs to be built with LTO // since it is an object dependency of an LTO module. - FullDep bool `blueprint:"mutated"` - ThinDep bool `blueprint:"mutated"` + FullDep bool `blueprint:"mutated"` + ThinDep bool `blueprint:"mutated"` + NoLtoDep bool `blueprint:"mutated"` // Use clang lld instead of gnu ld. Use_clang_lld *bool @@ -70,15 +71,6 @@ func (lto *lto) props() []interface{} { func (lto *lto) begin(ctx BaseModuleContext) { if ctx.Config().IsEnvTrue("DISABLE_LTO") { lto.Properties.Lto.Never = proptools.BoolPtr(true) - } else if ctx.Config().IsEnvTrue("GLOBAL_THINLTO") { - staticLib := ctx.static() && !ctx.staticBinary() - hostBin := ctx.Host() - vndk := ctx.isVndk() // b/169217596 - if !staticLib && !hostBin && !vndk { - if !lto.Never() && !lto.FullLTO() { - lto.Properties.Lto.Thin = proptools.BoolPtr(true) - } - } } } @@ -96,22 +88,27 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { return flags } - if lto.LTO() { - var ltoFlag string + if lto.LTO(ctx) { + var ltoCFlag string + var ltoLdFlag string if lto.ThinLTO() { - ltoFlag = "-flto=thin -fsplit-lto-unit" + ltoCFlag = "-flto=thin -fsplit-lto-unit" + } else if lto.FullLTO() { + ltoCFlag = "-flto" } else { - ltoFlag = "-flto" + ltoCFlag = "-flto=thin -fsplit-lto-unit" + ltoLdFlag = "-Wl,--lto-O0" } - flags.Local.CFlags = append(flags.Local.CFlags, ltoFlag) - flags.Local.LdFlags = append(flags.Local.LdFlags, ltoFlag) + flags.Local.CFlags = append(flags.Local.CFlags, ltoCFlag) + flags.Local.LdFlags = append(flags.Local.LdFlags, ltoCFlag) + flags.Local.LdFlags = append(flags.Local.LdFlags, ltoLdFlag) if Bool(lto.Properties.Whole_program_vtables) { flags.Local.CFlags = append(flags.Local.CFlags, "-fwhole-program-vtables") } - if lto.ThinLTO() && ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && lto.useClangLld(ctx) { + if (lto.DefaultThinLTO(ctx) || lto.ThinLTO()) && ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && lto.useClangLld(ctx) { // Set appropriate ThinLTO cache policy cacheDirFormat := "-Wl,--thinlto-cache-dir=" cacheDir := android.PathForOutput(ctx, "thinlto-cache").String() @@ -134,33 +131,40 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { return flags } -// Can be called with a null receiver -func (lto *lto) LTO() bool { - if lto == nil || lto.Never() { - return false - } +func (lto *lto) LTO(ctx BaseModuleContext) bool { + return lto.ThinLTO() || lto.FullLTO() || lto.DefaultThinLTO(ctx) +} - return lto.FullLTO() || lto.ThinLTO() +func (lto *lto) DefaultThinLTO(ctx BaseModuleContext) bool { + host := ctx.Host() + vndk := ctx.isVndk() // b/169217596 + return GlobalThinLTO(ctx) && !lto.Never() && !host && !vndk } func (lto *lto) FullLTO() bool { - return Bool(lto.Properties.Lto.Full) + return lto != nil && Bool(lto.Properties.Lto.Full) } func (lto *lto) ThinLTO() bool { - return Bool(lto.Properties.Lto.Thin) + return lto != nil && Bool(lto.Properties.Lto.Thin) } -// Is lto.never explicitly set to true? func (lto *lto) Never() bool { - return Bool(lto.Properties.Lto.Never) + return lto != nil && Bool(lto.Properties.Lto.Never) +} + +func GlobalThinLTO(ctx android.BaseModuleContext) bool { + return ctx.Config().IsEnvTrue("GLOBAL_THINLTO") } // Propagate lto requirements down from binaries func ltoDepsMutator(mctx android.TopDownMutatorContext) { - if m, ok := mctx.Module().(*Module); ok && m.lto.LTO() { + globalThinLTO := GlobalThinLTO(mctx) + + if m, ok := mctx.Module().(*Module); ok { full := m.lto.FullLTO() thin := m.lto.ThinLTO() + never := m.lto.Never() if full && thin { mctx.PropertyErrorf("LTO", "FullLTO and ThinLTO are mutually exclusive") } @@ -180,14 +184,16 @@ func ltoDepsMutator(mctx android.TopDownMutatorContext) { } } - if dep, ok := dep.(*Module); ok && dep.lto != nil && - !dep.lto.Never() { + if dep, ok := dep.(*Module); ok { if full && !dep.lto.FullLTO() { dep.lto.Properties.FullDep = true } - if thin && !dep.lto.ThinLTO() { + if !globalThinLTO && thin && !dep.lto.ThinLTO() { dep.lto.Properties.ThinDep = true } + if globalThinLTO && never && !dep.lto.Never() { + dep.lto.Properties.NoLtoDep = true + } } // Recursively walk static dependencies @@ -198,6 +204,8 @@ func ltoDepsMutator(mctx android.TopDownMutatorContext) { // Create lto variants for modules that need them func ltoMutator(mctx android.BottomUpMutatorContext) { + globalThinLTO := GlobalThinLTO(mctx) + if m, ok := mctx.Module().(*Module); ok && m.lto != nil { // Create variations for LTO types required as static // dependencies @@ -205,18 +213,25 @@ func ltoMutator(mctx android.BottomUpMutatorContext) { if m.lto.Properties.FullDep && !m.lto.FullLTO() { variationNames = append(variationNames, "lto-full") } - if m.lto.Properties.ThinDep && !m.lto.ThinLTO() { + if !globalThinLTO && m.lto.Properties.ThinDep && !m.lto.ThinLTO() { variationNames = append(variationNames, "lto-thin") } + if globalThinLTO && m.lto.Properties.NoLtoDep && !m.lto.Never() { + variationNames = append(variationNames, "lto-none") + } // Use correct dependencies if LTO property is explicitly set // (mutually exclusive) if m.lto.FullLTO() { mctx.SetDependencyVariation("lto-full") } - if m.lto.ThinLTO() { + if !globalThinLTO && m.lto.ThinLTO() { mctx.SetDependencyVariation("lto-thin") } + // Never must be the last, it overrides Thin or Full. + if globalThinLTO && m.lto.Never() { + mctx.SetDependencyVariation("lto-none") + } if len(variationNames) > 1 { modules := mctx.CreateVariations(variationNames...) @@ -232,16 +247,18 @@ func ltoMutator(mctx android.BottomUpMutatorContext) { // LTO properties for dependencies if name == "lto-full" { variation.lto.Properties.Lto.Full = proptools.BoolPtr(true) - variation.lto.Properties.Lto.Thin = proptools.BoolPtr(false) } if name == "lto-thin" { - variation.lto.Properties.Lto.Full = proptools.BoolPtr(false) variation.lto.Properties.Lto.Thin = proptools.BoolPtr(true) } + if name == "lto-none" { + variation.lto.Properties.Lto.Never = proptools.BoolPtr(true) + } variation.Properties.PreventInstall = true variation.Properties.HideFromMake = true variation.lto.Properties.FullDep = false variation.lto.Properties.ThinDep = false + variation.lto.Properties.NoLtoDep = false } } } diff --git a/rust/compiler.go b/rust/compiler.go index 1ce71f60b..cada9854a 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -449,6 +449,10 @@ func (compiler *baseCompiler) relativeInstallPath() string { // Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs. func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) { + if len(srcs) == 0 { + ctx.PropertyErrorf("srcs", "srcs must not be empty") + } + // The srcs can contain strings with prefix ":". // They are dependent modules of this module, with android.SourceDepTag. // They are not the main source file compiled by rustc. diff --git a/rust/compiler_test.go b/rust/compiler_test.go index f589b691d..ec6829a1b 100644 --- a/rust/compiler_test.go +++ b/rust/compiler_test.go @@ -98,6 +98,41 @@ func TestEnforceSingleSourceFile(t *testing.T) { }`) } +// Test that we reject _no_ source files. +func TestEnforceMissingSourceFiles(t *testing.T) { + + singleSrcError := "srcs must not be empty" + + // Test libraries + testRustError(t, singleSrcError, ` + rust_library_host { + name: "foo-bar-library", + crate_name: "foo", + }`) + + // Test binaries + testRustError(t, singleSrcError, ` + rust_binary_host { + name: "foo-bar-binary", + crate_name: "foo", + }`) + + // Test proc_macros + testRustError(t, singleSrcError, ` + rust_proc_macro { + name: "foo-bar-proc-macro", + crate_name: "foo", + }`) + + // Test prebuilts + testRustError(t, singleSrcError, ` + rust_prebuilt_dylib { + name: "foo-bar-prebuilt", + crate_name: "foo", + host_supported: true, + }`) +} + // Test environment vars for Cargo compat are set. func TestCargoCompat(t *testing.T) { ctx := testRust(t, ` |