Merge "modify cc_binary type to cc_test for test modules"
diff --git a/cc/binary.go b/cc/binary.go
index 48f70d9..c177a08 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -183,11 +183,6 @@
return deps
}
-func (binary *binaryDecorator) isDependencyRoot() bool {
- // Binaries are always the dependency root.
- return true
-}
-
// NewBinary builds and returns a new Module corresponding to a C++ binary.
// Individual module implementations which comprise a C++ binary should call this function,
// set some fields on the result, and then call the Init function.
diff --git a/cc/cc.go b/cc/cc.go
index 1f73149..ca88913 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1119,17 +1119,6 @@
return c
}
-// Returns true for dependency roots (binaries)
-// TODO(ccross): also handle dlopenable libraries
-func (c *Module) IsDependencyRoot() bool {
- if root, ok := c.linker.(interface {
- isDependencyRoot() bool
- }); ok {
- return root.isDependencyRoot()
- }
- return false
-}
-
func (c *Module) UseVndk() bool {
return c.Properties.VndkVersion != ""
}
diff --git a/cc/linkable.go b/cc/linkable.go
index dd87334..c42c875 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -14,11 +14,6 @@
// SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
SanitizePropDefined() bool
- // IsDependencyRoot returns whether a module is of a type which cannot be a linkage dependency
- // of another module. For example, cc_binary and rust_binary represent dependency roots as other
- // modules cannot have linkage dependencies against these types.
- IsDependencyRoot() bool
-
// IsSanitizerEnabled returns whether a sanitizer is enabled.
IsSanitizerEnabled(t SanitizerType) bool
diff --git a/cc/lto.go b/cc/lto.go
index fccb597..d9a0118 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -15,6 +15,8 @@
package cc
import (
+ "github.com/google/blueprint/proptools"
+
"android/soong/android"
)
@@ -67,14 +69,14 @@
func (lto *lto) begin(ctx BaseModuleContext) {
if ctx.Config().IsEnvTrue("DISABLE_LTO") {
- lto.Properties.Lto.Never = boolPtr(true)
+ 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 = boolPtr(true)
+ lto.Properties.Lto.Thin = proptools.BoolPtr(true)
}
}
}
@@ -229,12 +231,12 @@
// LTO properties for dependencies
if name == "lto-full" {
- variation.lto.Properties.Lto.Full = boolPtr(true)
- variation.lto.Properties.Lto.Thin = boolPtr(false)
+ 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 = boolPtr(false)
- variation.lto.Properties.Lto.Thin = boolPtr(true)
+ variation.lto.Properties.Lto.Full = proptools.BoolPtr(false)
+ variation.lto.Properties.Lto.Thin = proptools.BoolPtr(true)
}
variation.Properties.PreventInstall = true
variation.Properties.HideFromMake = true
diff --git a/cc/sanitize.go b/cc/sanitize.go
index cdd7dfb..e95a935 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -21,6 +21,7 @@
"sync"
"github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/cc/config"
@@ -73,14 +74,6 @@
type SanitizerType int
-func boolPtr(v bool) *bool {
- if v {
- return &v
- } else {
- return nil
- }
-}
-
const (
Asan SanitizerType = iota + 1
Hwasan
@@ -269,8 +262,8 @@
// cc_test targets default to SYNC MemTag unless explicitly set to ASYNC (via diag: {memtag_heap}).
if ctx.testBinary() && s.Memtag_heap == nil {
- s.Memtag_heap = boolPtr(true)
- s.Diag.Memtag_heap = boolPtr(true)
+ s.Memtag_heap = proptools.BoolPtr(true)
+ s.Diag.Memtag_heap = proptools.BoolPtr(true)
}
var globalSanitizers []string
@@ -291,48 +284,48 @@
if len(globalSanitizers) > 0 {
var found bool
if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil {
- s.All_undefined = boolPtr(true)
+ s.All_undefined = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil {
- s.Undefined = boolPtr(true)
+ s.Undefined = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("address", globalSanitizers); found && s.Address == nil {
- s.Address = boolPtr(true)
+ s.Address = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil {
- s.Thread = boolPtr(true)
+ s.Thread = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("fuzzer", globalSanitizers); found && s.Fuzzer == nil {
- s.Fuzzer = boolPtr(true)
+ s.Fuzzer = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil {
- s.Safestack = boolPtr(true)
+ s.Safestack = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil {
if !ctx.Config().CFIDisabledForPath(ctx.ModuleDir()) {
- s.Cfi = boolPtr(true)
+ s.Cfi = proptools.BoolPtr(true)
}
}
// Global integer_overflow builds do not support static libraries.
if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil {
if !ctx.Config().IntegerOverflowDisabledForPath(ctx.ModuleDir()) && !ctx.static() {
- s.Integer_overflow = boolPtr(true)
+ s.Integer_overflow = proptools.BoolPtr(true)
}
}
if found, globalSanitizers = removeFromList("scudo", globalSanitizers); found && s.Scudo == nil {
- s.Scudo = boolPtr(true)
+ s.Scudo = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("hwaddress", globalSanitizers); found && s.Hwaddress == nil {
- s.Hwaddress = boolPtr(true)
+ s.Hwaddress = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("writeonly", globalSanitizers); found && s.Writeonly == nil {
@@ -341,11 +334,11 @@
if s.Address == nil && s.Hwaddress == nil {
ctx.ModuleErrorf("writeonly modifier cannot be used without 'address' or 'hwaddress'")
}
- s.Writeonly = boolPtr(true)
+ s.Writeonly = proptools.BoolPtr(true)
}
if found, globalSanitizers = removeFromList("memtag_heap", globalSanitizers); found && s.Memtag_heap == nil {
if !ctx.Config().MemtagHeapDisabledForPath(ctx.ModuleDir()) {
- s.Memtag_heap = boolPtr(true)
+ s.Memtag_heap = proptools.BoolPtr(true)
}
}
@@ -356,17 +349,17 @@
// Global integer_overflow builds do not support static library diagnostics.
if found, globalSanitizersDiag = removeFromList("integer_overflow", globalSanitizersDiag); found &&
s.Diag.Integer_overflow == nil && Bool(s.Integer_overflow) && !ctx.static() {
- s.Diag.Integer_overflow = boolPtr(true)
+ s.Diag.Integer_overflow = proptools.BoolPtr(true)
}
if found, globalSanitizersDiag = removeFromList("cfi", globalSanitizersDiag); found &&
s.Diag.Cfi == nil && Bool(s.Cfi) {
- s.Diag.Cfi = boolPtr(true)
+ s.Diag.Cfi = proptools.BoolPtr(true)
}
if found, globalSanitizersDiag = removeFromList("memtag_heap", globalSanitizersDiag); found &&
s.Diag.Memtag_heap == nil && Bool(s.Memtag_heap) {
- s.Diag.Memtag_heap = boolPtr(true)
+ s.Diag.Memtag_heap = proptools.BoolPtr(true)
}
if len(globalSanitizersDiag) > 0 {
@@ -378,30 +371,30 @@
if ctx.Arch().ArchType == android.Arm64 {
if ctx.Config().MemtagHeapSyncEnabledForPath(ctx.ModuleDir()) {
if s.Memtag_heap == nil {
- s.Memtag_heap = boolPtr(true)
+ s.Memtag_heap = proptools.BoolPtr(true)
}
if s.Diag.Memtag_heap == nil {
- s.Diag.Memtag_heap = boolPtr(true)
+ s.Diag.Memtag_heap = proptools.BoolPtr(true)
}
} else if ctx.Config().MemtagHeapAsyncEnabledForPath(ctx.ModuleDir()) {
if s.Memtag_heap == nil {
- s.Memtag_heap = boolPtr(true)
+ s.Memtag_heap = proptools.BoolPtr(true)
}
}
}
// Enable CFI for all components in the include paths (for Aarch64 only)
if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && ctx.Arch().ArchType == android.Arm64 {
- s.Cfi = boolPtr(true)
+ s.Cfi = proptools.BoolPtr(true)
if inList("cfi", ctx.Config().SanitizeDeviceDiag()) {
- s.Diag.Cfi = boolPtr(true)
+ s.Diag.Cfi = proptools.BoolPtr(true)
}
}
// Is CFI actually enabled?
if !ctx.Config().EnableCFI() {
- s.Cfi = boolPtr(false)
- s.Diag.Cfi = boolPtr(false)
+ s.Cfi = nil
+ s.Diag.Cfi = nil
}
// HWASan requires AArch64 hardware feature (top-byte-ignore).
@@ -421,14 +414,14 @@
// Also disable CFI if ASAN is enabled.
if Bool(s.Address) || Bool(s.Hwaddress) {
- s.Cfi = boolPtr(false)
- s.Diag.Cfi = boolPtr(false)
+ s.Cfi = nil
+ s.Diag.Cfi = nil
}
// Disable sanitizers that depend on the UBSan runtime for windows/darwin builds.
if !ctx.Os().Linux() {
- s.Cfi = boolPtr(false)
- s.Diag.Cfi = boolPtr(false)
+ s.Cfi = nil
+ s.Diag.Cfi = nil
s.Misc_undefined = nil
s.Undefined = nil
s.All_undefined = nil
@@ -443,8 +436,8 @@
s.Cfi = nil
s.Diag.Cfi = nil
} else {
- s.Cfi = boolPtr(false)
- s.Diag.Cfi = boolPtr(false)
+ s.Cfi = nil
+ s.Diag.Cfi = nil
}
}
@@ -495,7 +488,7 @@
// TODO(b/131771163): CFI transiently depends on LTO, and thus Fuzzer is
// mutually incompatible.
if Bool(s.Fuzzer) {
- s.Cfi = boolPtr(false)
+ s.Cfi = nil
}
}
@@ -781,23 +774,27 @@
}
func (sanitize *sanitize) SetSanitizer(t SanitizerType, b bool) {
+ bPtr := proptools.BoolPtr(b)
+ if !b {
+ bPtr = nil
+ }
switch t {
case Asan:
- sanitize.Properties.Sanitize.Address = boolPtr(b)
+ sanitize.Properties.Sanitize.Address = bPtr
case Hwasan:
- sanitize.Properties.Sanitize.Hwaddress = boolPtr(b)
+ sanitize.Properties.Sanitize.Hwaddress = bPtr
case tsan:
- sanitize.Properties.Sanitize.Thread = boolPtr(b)
+ sanitize.Properties.Sanitize.Thread = bPtr
case intOverflow:
- sanitize.Properties.Sanitize.Integer_overflow = boolPtr(b)
+ sanitize.Properties.Sanitize.Integer_overflow = bPtr
case cfi:
- sanitize.Properties.Sanitize.Cfi = boolPtr(b)
+ sanitize.Properties.Sanitize.Cfi = bPtr
case scs:
- sanitize.Properties.Sanitize.Scs = boolPtr(b)
+ sanitize.Properties.Sanitize.Scs = bPtr
case memtag_heap:
- sanitize.Properties.Sanitize.Memtag_heap = boolPtr(b)
+ sanitize.Properties.Sanitize.Memtag_heap = bPtr
case Fuzzer:
- sanitize.Properties.Sanitize.Fuzzer = boolPtr(b)
+ sanitize.Properties.Sanitize.Fuzzer = bPtr
default:
panic(fmt.Errorf("unknown SanitizerType %d", t))
}
@@ -1253,7 +1250,7 @@
func sanitizerMutator(t SanitizerType) func(android.BottomUpMutatorContext) {
return func(mctx android.BottomUpMutatorContext) {
if c, ok := mctx.Module().(PlatformSanitizeable); ok && c.SanitizePropDefined() {
- if c.IsDependencyRoot() && c.IsSanitizerEnabled(t) {
+ if c.Binary() && c.IsSanitizerEnabled(t) {
modules := mctx.CreateVariations(t.variationName())
modules[0].(PlatformSanitizeable).SetSanitizer(t, true)
} else if c.IsSanitizerEnabled(t) || c.SanitizeDep() {
diff --git a/rust/binary.go b/rust/binary.go
index 8d0a0a7..2c3f548 100644
--- a/rust/binary.go
+++ b/rust/binary.go
@@ -155,7 +155,3 @@
}
return binary.baseCompiler.stdLinkage(ctx)
}
-
-func (binary *binaryDecorator) isDependencyRoot() bool {
- return true
-}
diff --git a/rust/compiler.go b/rust/compiler.go
index 1598ebf..0b28135 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -289,10 +289,6 @@
return android.OptionalPathForPath(compiler.cargoOutDir)
}
-func (compiler *baseCompiler) isDependencyRoot() bool {
- return false
-}
-
func (compiler *baseCompiler) strippedOutputFilePath() android.OptionalPath {
return compiler.strippedOutputFile
}
diff --git a/rust/rust.go b/rust/rust.go
index a11a04c..0a9869f 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -172,13 +172,6 @@
return mod.sanitize != nil && mod.compiler != nil
}
-func (mod *Module) IsDependencyRoot() bool {
- if mod.compiler != nil {
- return mod.compiler.isDependencyRoot()
- }
- panic("IsDependencyRoot called on a non-compiler Rust module")
-}
-
func (mod *Module) IsPrebuilt() bool {
if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
return true
@@ -449,7 +442,6 @@
SetDisabled()
stdLinkage(ctx *depsContext) RustLinkage
- isDependencyRoot() bool
strippedOutputFilePath() android.OptionalPath
}
diff --git a/sdk/sdk.go b/sdk/sdk.go
index afc6aa4..b1c8aeb 100644
--- a/sdk/sdk.go
+++ b/sdk/sdk.go
@@ -93,10 +93,6 @@
// dropped. Adding a rule to members that have //visibility:private will
// cause the //visibility:private to be discarded.
Prebuilt_visibility []string
-
- // Specifying whether the generated prebuilt SDK build rule should have the
- // prefer flag set or not.
- Prebuilts_prefer *bool // default: false
}
// Contains information about the sdk properties that list sdk members, e.g.
@@ -296,10 +292,6 @@
return s.properties.Snapshot
}
-func (s *sdk) PreferPrebuilts() bool {
- return proptools.BoolDefault(s.properties.Prebuilts_prefer, false)
-}
-
func (s *sdk) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if s.snapshot() {
// We don't need to create a snapshot out of sdk_snapshot.
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index 0933db2..a13b0d7 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -662,68 +662,3 @@
)
})
}
-
-// Ensure that sdk prebuilt_prefer works correctly.
-func TestSnapshot_PrebuiltPreferTrue(t *testing.T) {
- bp := `
- sdk {
- name: "mysdk",
- java_header_libs: ["myjavalib"],
- prebuilts_prefer: true,
- }
-
- java_library {
- name: "myjavalib",
- srcs: ["Test.java"],
- system_modules: "none",
- sdk_version: "none",
- compile_dex: true,
- host_supported: true,
- }
- `
- preparer := android.GroupFixturePreparers(
- prepareForSdkTestWithJava,
- android.FixtureWithRootAndroidBp(bp),
- )
-
- checkZipFile := func(t *testing.T, result *android.TestResult, expected string) {
- zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles")
- android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String())
- }
-
- t.Run("prefer=true", func(t *testing.T) {
- result := android.GroupFixturePreparers(
- preparer,
- ).RunTest(t)
-
- checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
-
- CheckSnapshot(t, result, "mysdk", "",
- checkAndroidBpContents(`
-// This is auto-generated. DO NOT EDIT.
-
-java_import {
- name: "mysdk_myjavalib@current",
- sdk_member_name: "myjavalib",
- visibility: ["//visibility:public"],
- apex_available: ["//apex_available:platform"],
- jars: ["java/myjavalib.jar"],
-}
-
-java_import {
- name: "myjavalib",
- prefer: true,
- visibility: ["//visibility:public"],
- apex_available: ["//apex_available:platform"],
- jars: ["java/myjavalib.jar"],
-}
-
-sdk_snapshot {
- name: "mysdk@current",
- visibility: ["//visibility:public"],
- java_header_libs: ["mysdk_myjavalib@current"],
-}
- `),
- )
- })
-}
diff --git a/sdk/update.go b/sdk/update.go
index 2ab45d7..b146b62 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -32,9 +32,8 @@
// ========================================================
//
// SOONG_SDK_SNAPSHOT_PREFER
-// By default every unversioned module in the generated snapshot has prefer set by the
-// sdk.prebuilts_prefer property. Building it with SOONG_SDK_SNAPSHOT_PREFER=true will force
-// them to use prefer: true.
+// By default every unversioned module in the generated snapshot has prefer: false. Building it
+// with SOONG_SDK_SNAPSHOT_PREFER=true will force them to use prefer: true.
//
// SOONG_SDK_SNAPSHOT_VERSION
// This provides control over the version of the generated snapshot.
@@ -1624,11 +1623,11 @@
// Do not add the prefer property if the member snapshot module is a source module type.
if !memberType.UsesSourceModuleTypeInSnapshot() {
- // Set the prefer based on the environment variable if present, else the sdk.prefer_prebuilts
- // value.
+ // Set the prefer based on the environment variable. This is a temporary work around to allow a
+ // snapshot to be created that sets prefer: true.
// TODO(b/174997203): Remove once the ability to select the modules to prefer can be done
// dynamically at build time not at snapshot generation time.
- prefer := ctx.sdkMemberContext.Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER") || s.PreferPrebuilts()
+ prefer := ctx.sdkMemberContext.Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER")
// Set prefer. Setting this to false is not strictly required as that is the default but it does
// provide a convenient hook to post-process the generated Android.bp file, e.g. in tests to