Disable sanitizer flags and output files for sanitizer-enabled SDK members.

Test: build/soong/soong_ui.bash --make-mode \
      TARGET_PRODUCT=aosp_blueline_hwasan \
      TARGET_BUILD_VARIANT=userdebug nothing
Test: build/soong/scripts/build-aml-prebuilts.sh \
      runtime-module-{sdk,host-exports} \
      platform-mainline-{sdk,test-exports}
  Check that generated Android.bp files don't differ
Bug: 171754462
Change-Id: Ieef40ff202ceda2d9e613a5d9295f5c9d8160626
This commit is contained in:
Martin Stjernholm 2020-10-28 23:38:33 +00:00
parent 8683648981
commit 59e0c7a98f
2 changed files with 92 additions and 10 deletions

View File

@ -383,12 +383,25 @@ type nativeLibInfoProperties struct {
}
func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
addOutputFile := true
ccModule := variant.(*Module)
// If the library has some link types then it produces an output binary file, otherwise it
// is header only.
if !p.memberType.noOutputFiles {
p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
if s := ccModule.sanitize; s != nil {
// We currently do not capture sanitizer flags for libs with sanitizers
// enabled, because they may vary among variants that cannot be represented
// in the input blueprint files. In particular, sanitizerDepsMutator enables
// various sanitizers on dependencies, but in many cases only on static
// ones, and we cannot specify sanitizer flags at the link type level (i.e.
// in StaticOrSharedProperties).
if s.isUnsanitizedVariant() {
// This still captures explicitly disabled sanitizers, which may be
// necessary to avoid cyclic dependencies.
p.Sanitize = s.Properties.Sanitize
} else {
// Do not add the output file to the snapshot if we don't represent it
// properly.
addOutputFile = false
}
}
exportedInfo := ctx.SdkModuleContext().OtherModuleProvider(variant, FlagExporterInfoProvider).(FlagExporterInfo)
@ -431,8 +444,8 @@ func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberConte
p.StubsVersions = ccModule.AllStubsVersions()
}
if ccModule.sanitize != nil {
p.Sanitize = ccModule.sanitize.Properties.Sanitize
if !p.memberType.noOutputFiles && addOutputFile {
p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
}
}

View File

@ -464,7 +464,6 @@ func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
arm64: {
export_system_include_dirs: ["arm64/include"],
sanitize: {
hwaddress: true,
integer_overflow: false,
},
},
@ -496,7 +495,6 @@ cc_prebuilt_library_shared {
srcs: ["arm64/lib/mynativelib.so"],
export_system_include_dirs: ["arm64/include/arm64/include"],
sanitize: {
hwaddress: true,
integer_overflow: false,
},
},
@ -527,7 +525,6 @@ cc_prebuilt_library_shared {
srcs: ["arm64/lib/mynativelib.so"],
export_system_include_dirs: ["arm64/include/arm64/include"],
sanitize: {
hwaddress: true,
integer_overflow: false,
},
},
@ -548,7 +545,7 @@ sdk_snapshot {
`),
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
.intermediates/mynativelib/android_arm64_armv8-a_shared_hwasan/mynativelib.so -> arm64/lib/mynativelib.so
.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
)
@ -2727,3 +2724,75 @@ sdk_snapshot {
`),
)
}
func TestNoSanitizerMembers(t *testing.T) {
result := testSdkWithCc(t, `
sdk {
name: "mysdk",
native_shared_libs: ["mynativelib"],
}
cc_library_shared {
name: "mynativelib",
srcs: ["Test.cpp"],
export_include_dirs: ["include"],
arch: {
arm64: {
export_system_include_dirs: ["arm64/include"],
sanitize: {
hwaddress: true,
},
},
},
}
`)
result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
cc_prebuilt_library_shared {
name: "mysdk_mynativelib@current",
sdk_member_name: "mynativelib",
visibility: ["//visibility:public"],
installable: false,
compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
export_system_include_dirs: ["arm64/include/arm64/include"],
},
arm: {
srcs: ["arm/lib/mynativelib.so"],
},
},
}
cc_prebuilt_library_shared {
name: "mynativelib",
prefer: false,
visibility: ["//visibility:public"],
compile_multilib: "both",
export_include_dirs: ["include/include"],
arch: {
arm64: {
export_system_include_dirs: ["arm64/include/arm64/include"],
},
arm: {
srcs: ["arm/lib/mynativelib.so"],
},
},
}
sdk_snapshot {
name: "mysdk@current",
visibility: ["//visibility:public"],
native_shared_libs: ["mysdk_mynativelib@current"],
}
`),
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
)
}