Merge "Use aapt2"
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index b668042..fd8f403 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -169,6 +169,7 @@
"packages/apps/DevCamera": Bp2BuildDefaultTrue,
"packages/apps/HTMLViewer": Bp2BuildDefaultTrue,
"packages/apps/Protips": Bp2BuildDefaultTrue,
+ "packages/apps/WallpaperPicker": Bp2BuildDefaultTrue,
"packages/modules/StatsD/lib/libstatssocket": Bp2BuildDefaultTrueRecursively,
"packages/modules/adb": Bp2BuildDefaultTrue,
"packages/modules/adb/apex": Bp2BuildDefaultTrue,
@@ -182,6 +183,8 @@
"packages/screensavers/Basic": Bp2BuildDefaultTrue,
"packages/services/Car/tests/SampleRearViewCamera": Bp2BuildDefaultTrue,
"prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
+ "prebuilts/sdk/current/extras/app-toolkit": Bp2BuildDefaultTrue,
+ "prebuilts/sdk/current/support": Bp2BuildDefaultTrue,
"prebuilts/tools/common/m2": Bp2BuildDefaultTrue,
"system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures
"system/apex/apexer": Bp2BuildDefaultTrue,
@@ -258,7 +261,6 @@
"packages/apps/Music":/* recursive = */ true,
"packages/apps/QuickSearchBox":/* recursive = */ true,
- "packages/apps/WallpaperPicker":/* recursive = */ false,
"prebuilts/bazel":/* recursive = */ true,
"prebuilts/bundletool":/* recursive = */ true,
@@ -267,8 +269,6 @@
"prebuilts/jdk/jdk11":/* recursive = */ false,
"prebuilts/misc":/* recursive = */ false, // not recursive because we need bp2build converted build files in prebuilts/misc/common/asm
"prebuilts/sdk":/* recursive = */ false,
- "prebuilts/sdk/current/extras/app-toolkit":/* recursive = */ false,
- "prebuilts/sdk/current/support":/* recursive = */ false,
"prebuilts/sdk/tools":/* recursive = */ false,
"prebuilts/r8":/* recursive = */ false,
}
@@ -459,9 +459,12 @@
"generated_android_icu4j_test_resources", // depends on unconverted modules: android_icu4j_srcgen_binary, soong_zip
"host-libprotobuf-java-nano", // b/220869005, depends on libprotobuf-java-nano
"libadb_host", // depends on unconverted modules: AdbWinApi, libopenscreen-discovery, libopenscreen-platform-impl, libusb
+ "libapexutil", // depends on unconverted modules: apex-info-list-tinyxml
"libart", // depends on unconverted modules: apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, heapprofd_client_api, art_operator_srcs, libcpu_features, libodrstatslog, libelffile, art_cmdlineparser_headers, cpp-define-generator-definitions, libdexfile, libnativebridge, libnativeloader, libsigchain, libartbase, libprofile, cpp-define-generator-asm-support
"libart-runtime-gtest", // depends on unconverted modules: libgtest_isolated, libart-compiler, libdexfile, libprofile, libartbase, libartbase-art-gtest
"libart_headers", // depends on unconverted modules: art_libartbase_headers
+ "libartbase-art-gtest", // depends on unconverted modules: libgtest_isolated, libart, libart-compiler, libdexfile, libprofile
+ "libartbased-art-gtest", // depends on unconverted modules: libgtest_isolated, libartd, libartd-compiler, libdexfiled, libprofiled
"libartd", // depends on unconverted modules: art_operator_srcs, libcpu_features, libodrstatslog, libelffiled, art_cmdlineparser_headers, cpp-define-generator-definitions, libdexfiled, libnativebridge, libnativeloader, libsigchain, libartbased, libprofiled, cpp-define-generator-asm-support, apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, heapprofd_client_api
"libartd-runtime-gtest", // depends on unconverted modules: libgtest_isolated, libartd-compiler, libdexfiled, libprofiled, libartbased, libartbased-art-gtest
"libdebuggerd_handler", // depends on unconverted module libdebuggerd_handler_core
@@ -484,11 +487,10 @@
"stats-log-api-gen", // depends on unconverted modules: libstats_proto_host
"statslog.cpp", "statslog.h", "statslog.rs", // depends on unconverted modules: stats-log-api-gen
"statslog_art.cpp", "statslog_art.h", "statslog_header.rs", // depends on unconverted modules: stats-log-api-gen
- "timezone-host", // depends on unconverted modules: art.module.api.annotations
- "truth-host-prebuilt", // depends on unconverted modules: truth-prebuilt
- "truth-prebuilt", // depends on unconverted modules: asm-7.0, guava
- "libartbase-art-gtest", // depends on unconverted modules: libgtest_isolated, libart, libart-compiler, libdexfile, libprofile
- "libartbased-art-gtest", // depends on unconverted modules: libgtest_isolated, libartd, libartd-compiler, libdexfiled, libprofiled
+ "test_fips", // depends on unconverted modules: adb
+ "timezone-host", // depends on unconverted modules: art.module.api.annotations
+ "truth-host-prebuilt", // depends on unconverted modules: truth-prebuilt
+ "truth-prebuilt", // depends on unconverted modules: asm-7.0, guava
// b/215723302; awaiting tz{data,_version} to then rename targets conflicting with srcs
"tzdata",
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index 07557d6..1fabfaa 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -34,6 +34,7 @@
"soong-ui-metrics",
],
testSrcs: [
+ "aar_conversion_test.go",
"android_app_certificate_conversion_test.go",
"android_app_conversion_test.go",
"apex_conversion_test.go",
@@ -49,6 +50,7 @@
"cc_prebuilt_library_conversion_test.go",
"cc_prebuilt_library_shared_test.go",
"cc_prebuilt_library_static_test.go",
+ "cc_yasm_conversion_test.go",
"conversion_test.go",
"filegroup_conversion_test.go",
"genrule_conversion_test.go",
diff --git a/bp2build/aar_conversion_test.go b/bp2build/aar_conversion_test.go
new file mode 100644
index 0000000..8e7c2b5
--- /dev/null
+++ b/bp2build/aar_conversion_test.go
@@ -0,0 +1,138 @@
+// Copyright 2022 Google Inc. All rights reserved.
+//
+// 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 bp2build
+
+import (
+ "android/soong/android"
+ "android/soong/java"
+ "fmt"
+
+ "testing"
+)
+
+func TestConvertAndroidLibrary(t *testing.T) {
+ t.Helper()
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
+ Description: "Android Library - simple example",
+ ModuleTypeUnderTest: "android_library",
+ ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
+ Filesystem: map[string]string{
+ "lib.java": "",
+ "arm.java": "",
+ "x86.java": "",
+ "res/res.png": "",
+ "manifest/AndroidManifest.xml": "",
+ },
+ Blueprint: simpleModuleDoNotConvertBp2build("android_library", "static_lib_dep") + `
+android_library {
+ name: "TestLib",
+ srcs: ["lib.java"],
+ arch: {
+ arm: {
+ srcs: ["arm.java"],
+ },
+ x86: {
+ srcs: ["x86.java"],
+ }
+ },
+ manifest: "manifest/AndroidManifest.xml",
+ static_libs: ["static_lib_dep"],
+ java_version: "7",
+}
+`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget(
+ "android_library",
+ "TestLib",
+ AttrNameToString{
+ "srcs": `["lib.java"] + select({
+ "//build/bazel/platforms/arch:arm": ["arm.java"],
+ "//build/bazel/platforms/arch:x86": ["x86.java"],
+ "//conditions:default": [],
+ })`,
+ "manifest": `"manifest/AndroidManifest.xml"`,
+ "resource_files": `["res/res.png"]`,
+ "deps": `[":static_lib_dep"]`,
+ "exports": `[":static_lib_dep"]`,
+ "javacopts": `["-source 1.7 -target 1.7"]`,
+ }),
+ }})
+}
+
+func TestConvertAndroidLibraryWithNoSources(t *testing.T) {
+ t.Helper()
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
+ Description: "Android Library - modules with deps must have sources",
+ ModuleTypeUnderTest: "android_library",
+ ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
+ Filesystem: map[string]string{
+ "res/res.png": "",
+ "AndroidManifest.xml": "",
+ },
+ Blueprint: simpleModuleDoNotConvertBp2build("android_library", "lib_dep") + `
+android_library {
+ name: "TestLib",
+ srcs: [],
+ manifest: "AndroidManifest.xml",
+ libs: ["lib_dep"],
+}
+`,
+ ExpectedErr: fmt.Errorf("Module has direct dependencies but no sources. Bazel will not allow this."),
+ ExpectedBazelTargets: []string{},
+ })
+}
+
+func TestConvertAndroidLibraryImport(t *testing.T) {
+ t.Helper()
+ RunBp2BuildTestCase(
+ t,
+ func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("android_library", java.AndroidLibraryFactory)
+ },
+ Bp2buildTestCase{
+ Description: "Android Library Import",
+ ModuleTypeUnderTest: "android_library_import",
+ ModuleTypeUnderTestFactory: java.AARImportFactory,
+ Filesystem: map[string]string{
+ "import.aar": "",
+ },
+ // Bazel's aar_import can only export *_import targets, so we expect
+ // only "static_import_dep" in exports, but both "static_lib_dep" and
+ // "static_import_dep" in deps
+ Blueprint: simpleModuleDoNotConvertBp2build("android_library", "static_lib_dep") +
+ simpleModuleDoNotConvertBp2build("android_library_import", "static_import_dep") + `
+android_library_import {
+ name: "TestImport",
+ aars: ["import.aar"],
+ static_libs: ["static_lib_dep", "static_import_dep"],
+}
+`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget(
+ "aar_import",
+ "TestImport",
+ AttrNameToString{
+ "aar": `"import.aar"`,
+ "deps": `[
+ ":static_lib_dep",
+ ":static_import_dep",
+ ]`,
+ "exports": `[":static_import_dep"]`,
+ },
+ ),
+ },
+ },
+ )
+}
diff --git a/bp2build/cc_yasm_conversion_test.go b/bp2build/cc_yasm_conversion_test.go
index 6114a49..2a71834 100644
--- a/bp2build/cc_yasm_conversion_test.go
+++ b/bp2build/cc_yasm_conversion_test.go
@@ -20,9 +20,9 @@
"android/soong/cc"
)
-func runYasmTestCase(t *testing.T, tc bp2buildTestCase) {
+func runYasmTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
- runBp2BuildTestCase(t, registerYasmModuleTypes, tc)
+ RunBp2BuildTestCase(t, registerYasmModuleTypes, tc)
}
func registerYasmModuleTypes(ctx android.RegistrationContext) {
@@ -34,20 +34,20 @@
}
func TestYasmSimple(t *testing.T) {
- runYasmTestCase(t, bp2buildTestCase{
- description: "Simple yasm test",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- filesystem: map[string]string{
+ runYasmTestCase(t, Bp2buildTestCase{
+ Description: "Simple yasm test",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Filesystem: map[string]string{
"main.cpp": "",
"myfile.asm": "",
},
- blueprint: `
+ Blueprint: `
cc_library {
name: "foo",
srcs: ["main.cpp", "myfile.asm"],
}`,
- expectedBazelTargets: append([]string{
+ ExpectedBazelTargets: append([]string{
makeBazelTarget("yasm", "foo_yasm", map[string]string{
"include_dirs": `["."]`,
"srcs": `["myfile.asm"]`,
@@ -63,24 +63,24 @@
}
func TestYasmWithIncludeDirs(t *testing.T) {
- runYasmTestCase(t, bp2buildTestCase{
- description: "Simple yasm test",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- filesystem: map[string]string{
+ runYasmTestCase(t, Bp2buildTestCase{
+ Description: "Simple yasm test",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Filesystem: map[string]string{
"main.cpp": "",
"myfile.asm": "",
"include1/foo/myinclude.inc": "",
"include2/foo/myinclude2.inc": "",
},
- blueprint: `
+ Blueprint: `
cc_library {
name: "foo",
local_include_dirs: ["include1/foo"],
export_include_dirs: ["include2/foo"],
srcs: ["main.cpp", "myfile.asm"],
}`,
- expectedBazelTargets: append([]string{
+ ExpectedBazelTargets: append([]string{
makeBazelTarget("yasm", "foo_yasm", map[string]string{
"include_dirs": `[
"include1/foo",
@@ -104,15 +104,15 @@
}
func TestYasmConditionalBasedOnArch(t *testing.T) {
- runYasmTestCase(t, bp2buildTestCase{
- description: "Simple yasm test",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- filesystem: map[string]string{
+ runYasmTestCase(t, Bp2buildTestCase{
+ Description: "Simple yasm test",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Filesystem: map[string]string{
"main.cpp": "",
"myfile.asm": "",
},
- blueprint: `
+ Blueprint: `
cc_library {
name: "foo",
srcs: ["main.cpp"],
@@ -122,7 +122,7 @@
},
},
}`,
- expectedBazelTargets: append([]string{
+ ExpectedBazelTargets: append([]string{
makeBazelTarget("yasm", "foo_yasm", map[string]string{
"include_dirs": `["."]`,
"srcs": `select({
@@ -141,16 +141,16 @@
}
func TestYasmPartiallyConditional(t *testing.T) {
- runYasmTestCase(t, bp2buildTestCase{
- description: "Simple yasm test",
- moduleTypeUnderTest: "cc_library",
- moduleTypeUnderTestFactory: cc.LibraryFactory,
- filesystem: map[string]string{
+ runYasmTestCase(t, Bp2buildTestCase{
+ Description: "Simple yasm test",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Filesystem: map[string]string{
"main.cpp": "",
"myfile.asm": "",
"mysecondfile.asm": "",
},
- blueprint: `
+ Blueprint: `
cc_library {
name: "foo",
srcs: ["main.cpp", "myfile.asm"],
@@ -160,7 +160,7 @@
},
},
}`,
- expectedBazelTargets: append([]string{
+ ExpectedBazelTargets: append([]string{
makeBazelTarget("yasm", "foo_yasm", map[string]string{
"include_dirs": `["."]`,
"srcs": `["myfile.asm"] + select({
diff --git a/build_kzip.bash b/build_kzip.bash
index fa616b9..eeef7d4 100755
--- a/build_kzip.bash
+++ b/build_kzip.bash
@@ -45,11 +45,13 @@
declare -r source_root=$PWD
# For the Go code, we invoke the extractor directly. The two caveats are that
-# the extractor's rewrite rules are generated on the fly as they depend on the XREF_CORPUS
-# value, and that the name of the kzip file is derived from the directory name
-# by replacing '/' with '_'.
+# the extractor's rewrite rules are generated on the fly as they depend on the
+# value of XREF_CORPUS, and that the name of the kzip file is derived from the
+# directory name by replacing '/' with '_'.
+# Go extractor should succeed.
declare -ar go_modules=(build/blueprint build/soong
build/make/tools/canoninja build/make/tools/compliance build/make/tools/rbcrun)
+set -e
for dir in "${go_modules[@]}"; do
(cd "$dir";
outfile=$(echo "$dir" | sed -r 's|/|_|g;s|(.*)|\1.go.kzip|');
@@ -58,6 +60,7 @@
--canonicalize_package_corpus --output "${abspath_out}/soong/$outfile" ./...
)
done
+set +e
declare -r kzip_count=$(find "$out" -name '*.kzip' | wc -l)
(($kzip_count>100000)) || { printf "Too few kzip files were generated: %d\n" $kzip_count; exit 1; }
diff --git a/cc/cc.go b/cc/cc.go
index bc95813..fd57e9e 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -62,7 +62,6 @@
ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
ctx.TopDown("fuzz_deps", fuzzMutatorDeps)
- ctx.BottomUp("fuzz", fuzzMutator)
ctx.BottomUp("coverage", coverageMutator).Parallel()
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 24732bf..792a8e0 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -20,6 +20,7 @@
"path/filepath"
"reflect"
"regexp"
+ "runtime"
"strings"
"testing"
@@ -3342,9 +3343,9 @@
`)
}
-func TestAFLFuzzTarget(t *testing.T) {
- ctx := testCc(t, `
- cc_afl_fuzz {
+func VerifyAFLFuzzTargetVariant(t *testing.T, variant string) {
+ bp := `
+ cc_fuzz {
name: "test_afl_fuzz_target",
srcs: ["foo.c"],
host_supported: true,
@@ -3354,17 +3355,10 @@
shared_libs: [
"afl_fuzz_shared_lib",
],
- }
- cc_fuzz {
- name: "test_fuzz_target",
- srcs: ["foo.c"],
- static_libs: [
- "afl_fuzz_static_lib",
- "libfuzzer_only_static_lib",
- ],
- shared_libs: [
- "afl_fuzz_shared_lib",
- ],
+ fuzzing_frameworks: {
+ afl: true,
+ libfuzzer: false,
+ },
}
cc_library {
name: "afl_fuzz_static_lib",
@@ -3409,12 +3403,19 @@
host_supported: true,
srcs: ["second_file.c"],
}
- filegroup {
+ cc_object {
name: "aflpp_driver",
+ host_supported: true,
srcs: [
"aflpp_driver.c",
],
- }`)
+ }`
+
+ testEnv := map[string]string{
+ "FUZZ_FRAMEWORK": "AFL",
+ }
+
+ ctx := android.GroupFixturePreparers(prepareForCcTest, android.FixtureMergeEnv(testEnv)).RunTestWithBp(t, bp)
checkPcGuardFlag := func(
modName string, variantName string, shouldHave bool) {
@@ -3434,31 +3435,33 @@
}
}
- for _, vnt := range ctx.ModuleVariantsForTests("libfuzzer_only_static_lib") {
- if strings.Contains(vnt, "fuzzer_afl") {
- t.Errorf("libfuzzer_only_static_lib has afl variant and should not")
- }
- }
-
moduleName := "test_afl_fuzz_target"
- variantName := "android_arm64_armv8-a_fuzzer_afl"
- checkPcGuardFlag(moduleName, variantName, true)
+ checkPcGuardFlag(moduleName, variant+"_fuzzer", true)
moduleName = "afl_fuzz_static_lib"
- variantName = "android_arm64_armv8-a_static"
- checkPcGuardFlag(moduleName, variantName, false)
- checkPcGuardFlag(moduleName, variantName+"_fuzzer", false)
- checkPcGuardFlag(moduleName, variantName+"_fuzzer_afl", true)
+ checkPcGuardFlag(moduleName, variant+"_static", false)
+ checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true)
moduleName = "second_static_lib"
- checkPcGuardFlag(moduleName, variantName, false)
- checkPcGuardFlag(moduleName, variantName+"_fuzzer", false)
- checkPcGuardFlag(moduleName, variantName+"_fuzzer_afl", true)
+ checkPcGuardFlag(moduleName, variant+"_static", false)
+ checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true)
ctx.ModuleForTests("afl_fuzz_shared_lib",
"android_arm64_armv8-a_shared").Rule("cc")
ctx.ModuleForTests("afl_fuzz_shared_lib",
- "android_arm64_armv8-a_shared_fuzzer_afl").Rule("cc")
+ "android_arm64_armv8-a_shared_fuzzer").Rule("cc")
+}
+
+func TestAFLFuzzTargetForDevice(t *testing.T) {
+ VerifyAFLFuzzTargetVariant(t, "android_arm64_armv8-a")
+}
+
+func TestAFLFuzzTargetForLinuxHost(t *testing.T) {
+ if runtime.GOOS != "linux" {
+ t.Skip("requires linux")
+ }
+
+ VerifyAFLFuzzTargetVariant(t, "linux_glibc_x86_64")
}
// Simple smoke test for the cc_fuzz target that ensures the rule compiles
diff --git a/cc/config/global.go b/cc/config/global.go
index 26d93ab..357ea44 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -59,6 +59,10 @@
"-Werror=string-plus-int",
"-Werror=unreachable-code-loop-increment",
+ // Force deprecation warnings to be warnings for code that compiles with -Werror.
+ // Making deprecated usages an error causes extreme pain when trying to deprecate anything.
+ "-Wno-error=deprecated-declarations",
+
"-D__compiler_offsetof=__builtin_offsetof",
// Emit address-significance table which allows linker to perform safe ICF. Clang does
@@ -286,8 +290,7 @@
"-Wno-deprecated-non-prototype",
}
- llvmNextExtraCommonGlobalCflags = []string{
- }
+ llvmNextExtraCommonGlobalCflags = []string{}
IllegalFlags = []string{
"-w",
diff --git a/cc/fuzz.go b/cc/fuzz.go
index d6af97f..dfc718e 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -27,15 +27,12 @@
)
func init() {
- android.RegisterModuleType("cc_afl_fuzz", AFLFuzzFactory)
android.RegisterModuleType("cc_fuzz", LibFuzzFactory)
android.RegisterSingletonType("cc_fuzz_packaging", fuzzPackagingFactory)
- android.RegisterSingletonType("cc_afl_fuzz_packaging", fuzzAFLPackagingFactory)
}
type FuzzProperties struct {
- AFLEnabled bool `blueprint:"mutated"`
- AFLAddFlags bool `blueprint:"mutated"`
+ FuzzFramework fuzz.Framework `blueprint:"mutated"`
}
type fuzzer struct {
@@ -43,8 +40,13 @@
}
func (fuzzer *fuzzer) flags(ctx ModuleContext, flags Flags) Flags {
- if fuzzer.Properties.AFLAddFlags {
- flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-coverage=trace-pc-guard")
+ if fuzzer.Properties.FuzzFramework == fuzz.AFL {
+ flags.Local.CFlags = append(flags.Local.CFlags, []string{
+ "-fsanitize-coverage=trace-pc-guard",
+ "-Wno-unused-result",
+ "-Wno-unused-parameter",
+ "-Wno-unused-function",
+ }...)
}
return flags
@@ -60,7 +62,7 @@
return
}
- if currentModule.fuzzer == nil || !currentModule.fuzzer.Properties.AFLEnabled {
+ if currentModule.fuzzer == nil {
return
}
@@ -83,48 +85,16 @@
return false
}
- c.fuzzer.Properties.AFLEnabled = true
- c.fuzzer.Properties.AFLAddFlags = true
+ c.fuzzer.Properties.FuzzFramework = currentModule.fuzzer.Properties.FuzzFramework
return true
})
}
-func fuzzMutator(mctx android.BottomUpMutatorContext) {
- if c, ok := mctx.Module().(*Module); ok && c.fuzzer != nil {
- if !c.fuzzer.Properties.AFLEnabled {
- return
- }
-
- if c.Binary() {
- m := mctx.CreateVariations("afl")
- m[0].(*Module).fuzzer.Properties.AFLEnabled = true
- m[0].(*Module).fuzzer.Properties.AFLAddFlags = true
- } else {
- m := mctx.CreateVariations("", "afl")
- m[0].(*Module).fuzzer.Properties.AFLEnabled = false
- m[0].(*Module).fuzzer.Properties.AFLAddFlags = false
-
- m[1].(*Module).fuzzer.Properties.AFLEnabled = true
- m[1].(*Module).fuzzer.Properties.AFLAddFlags = true
- }
- }
-}
-
// cc_fuzz creates a host/device fuzzer binary. Host binaries can be found at
// $ANDROID_HOST_OUT/fuzz/, and device binaries can be found at /data/fuzz on
// your device, or $ANDROID_PRODUCT_OUT/data/fuzz in your build tree.
func LibFuzzFactory() android.Module {
- module := NewFuzzer(android.HostAndDeviceSupported, fuzz.Cc)
- return module.Init()
-}
-
-// cc_afl_fuzz creates a host/device AFL++ fuzzer binary.
-// AFL++ is an open source framework used to fuzz libraries
-// Host binaries can be found at $ANDROID_HOST_OUT/afl_fuzz/ and device
-// binaries can be found at $ANDROID_PRODUCT_OUT/data/afl_fuzz in your
-// build tree
-func AFLFuzzFactory() android.Module {
- module := NewFuzzer(android.HostAndDeviceSupported, fuzz.AFL)
+ module := NewFuzzer(android.HostAndDeviceSupported)
return module.Init()
}
@@ -133,7 +103,6 @@
*baseCompiler
fuzzPackagedModule fuzz.FuzzPackagedModule
installedSharedDeps []string
- fuzzType fuzz.FuzzType
}
func (fuzz *fuzzBinary) fuzzBinary() bool {
@@ -143,6 +112,7 @@
func (fuzz *fuzzBinary) linkerProps() []interface{} {
props := fuzz.binaryDecorator.linkerProps()
props = append(props, &fuzz.fuzzPackagedModule.FuzzProperties)
+
return props
}
@@ -151,16 +121,14 @@
}
func (fuzzBin *fuzzBinary) linkerDeps(ctx DepsContext, deps Deps) Deps {
- if fuzzBin.fuzzType == fuzz.AFL {
+ if ctx.Config().Getenv("FUZZ_FRAMEWORK") == "AFL" {
deps.HeaderLibs = append(deps.HeaderLibs, "libafl_headers")
- deps = fuzzBin.binaryDecorator.linkerDeps(ctx, deps)
- return deps
-
} else {
deps.StaticLibs = append(deps.StaticLibs, config.LibFuzzerRuntimeLibrary(ctx.toolchain()))
- deps = fuzzBin.binaryDecorator.linkerDeps(ctx, deps)
- return deps
}
+
+ deps = fuzzBin.binaryDecorator.linkerDeps(ctx, deps)
+ return deps
}
func (fuzz *fuzzBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
@@ -257,9 +225,6 @@
func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
installBase := "fuzz"
- if fuzzBin.fuzzType == fuzz.AFL {
- installBase = "afl_fuzz"
- }
fuzzBin.binaryDecorator.baseInstaller.dir = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
@@ -333,12 +298,9 @@
}
}
-func NewFuzzer(hod android.HostOrDeviceSupported, fuzzType fuzz.FuzzType) *Module {
+func NewFuzzer(hod android.HostOrDeviceSupported) *Module {
module, binary := newBinary(hod, false)
baseInstallerPath := "fuzz"
- if fuzzType == fuzz.AFL {
- baseInstallerPath = "afl_fuzz"
- }
binary.baseInstaller = NewBaseInstaller(baseInstallerPath, baseInstallerPath, InstallInData)
module.sanitize.SetSanitizer(Fuzzer, true)
@@ -346,12 +308,13 @@
fuzzBin := &fuzzBinary{
binaryDecorator: binary,
baseCompiler: NewBaseCompiler(),
- fuzzType: fuzzType,
}
module.compiler = fuzzBin
module.linker = fuzzBin
module.installer = fuzzBin
+ module.fuzzer.Properties.FuzzFramework = fuzz.LibFuzzer
+
// The fuzzer runtime is not present for darwin host modules, disable cc_fuzz modules when targeting darwin.
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
disableDarwinAndLinuxBionic := struct {
@@ -367,18 +330,18 @@
disableDarwinAndLinuxBionic.Target.Darwin.Enabled = BoolPtr(false)
disableDarwinAndLinuxBionic.Target.Linux_bionic.Enabled = BoolPtr(false)
ctx.AppendProperties(&disableDarwinAndLinuxBionic)
- })
- if fuzzType == fuzz.AFL {
- // Add cc_objects to Srcs
- fuzzBin.baseCompiler.Properties.Srcs = append(fuzzBin.baseCompiler.Properties.Srcs, ":aflpp_driver", ":afl-compiler-rt")
- module.fuzzer.Properties.AFLEnabled = true
- module.compiler.appendCflags([]string{
- "-Wno-unused-result",
- "-Wno-unused-parameter",
- "-Wno-unused-function",
- })
- }
+ targetFramework := fuzz.GetFramework(ctx, fuzz.Cc)
+ if !fuzz.IsValidFrameworkForModule(targetFramework, fuzz.Cc, fuzzBin.fuzzPackagedModule.FuzzProperties.Fuzzing_frameworks) {
+ ctx.Module().Disable()
+ return
+ }
+
+ if targetFramework == fuzz.AFL {
+ fuzzBin.baseCompiler.Properties.Srcs = append(fuzzBin.baseCompiler.Properties.Srcs, ":aflpp_driver", ":afl-compiler-rt")
+ module.fuzzer.Properties.FuzzFramework = fuzz.AFL
+ }
+ })
return module
}
@@ -399,17 +362,6 @@
fuzzTargetSharedDepsInstallPairs: "FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS",
allFuzzTargetsName: "ALL_FUZZ_TARGETS",
}
- fuzzPackager.FuzzType = fuzz.Cc
- return fuzzPackager
-}
-
-func fuzzAFLPackagingFactory() android.Singleton {
- fuzzPackager := &ccFuzzPackager{
- fuzzPackagingArchModules: "SOONG_AFL_FUZZ_PACKAGING_ARCH_MODULES",
- fuzzTargetSharedDepsInstallPairs: "AFL_FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS",
- allFuzzTargetsName: "ALL_AFL_FUZZ_TARGETS",
- }
- fuzzPackager.FuzzType = fuzz.AFL
return fuzzPackager
}
@@ -440,7 +392,7 @@
sharedLibsInstallDirPrefix := "lib"
fuzzModule, ok := ccModule.compiler.(*fuzzBinary)
- if !ok || fuzzModule.fuzzType != s.FuzzType {
+ if !ok {
return
}
@@ -455,9 +407,6 @@
}
intermediatePath := "fuzz"
- if s.FuzzType == fuzz.AFL {
- intermediatePath = "afl_fuzz"
- }
archString := ccModule.Arch().ArchType.String()
archDir := android.PathForIntermediates(ctx, intermediatePath, hostOrTargetString, archString)
@@ -484,7 +433,7 @@
}
})
- s.CreateFuzzPackage(ctx, archDirs, s.FuzzType, pctx)
+ s.CreateFuzzPackage(ctx, archDirs, fuzz.Cc, pctx)
}
func (s *ccFuzzPackager) MakeVars(ctx android.MakeVarsContext) {
@@ -511,9 +460,6 @@
var files []fuzz.FileToZip
fuzzDir := "fuzz"
- if s.FuzzType == fuzz.AFL {
- fuzzDir = "afl_fuzz"
- }
for _, library := range sharedLibraries {
files = append(files, fuzz.FileToZip{library, destinationPathPrefix})
diff --git a/cc/library.go b/cc/library.go
index ff485cf..546982b 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -400,7 +400,7 @@
if props, ok := props.(*LibraryProperties); ok {
if props.Inject_bssl_hash != nil {
// This is an edge case applies only to libcrypto
- if m.Name() == "libcrypto" {
+ if m.Name() == "libcrypto" || m.Name() == "libcrypto_for_testing" {
sharedTargetAttrs.Inject_bssl_hash.SetSelectValue(axis, config, props.Inject_bssl_hash)
} else {
ctx.PropertyErrorf("inject_bssl_hash", "only applies to libcrypto")
diff --git a/cc/testing.go b/cc/testing.go
index d70ec9b..79ae3c3 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -531,7 +531,6 @@
android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
- ctx.RegisterModuleType("cc_afl_fuzz", AFLFuzzFactory)
ctx.RegisterModuleType("cc_test", TestFactory)
ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
@@ -646,7 +645,6 @@
ctx := android.NewTestArchContext(config)
genrule.RegisterGenruleBuildComponents(ctx)
ctx.RegisterModuleType("cc_fuzz", LibFuzzFactory)
- ctx.RegisterModuleType("cc_afl_fuzz", AFLFuzzFactory)
ctx.RegisterModuleType("cc_test", TestFactory)
ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go
index 2474cbc..c8cd21b 100644
--- a/fuzz/fuzz_common.go
+++ b/fuzz/fuzz_common.go
@@ -27,13 +27,21 @@
"android/soong/android"
)
-type FuzzType string
+type Lang string
const (
- Cc FuzzType = ""
- Rust FuzzType = "rust"
- Java FuzzType = "java"
- AFL FuzzType = "AFL"
+ Cc Lang = "cc"
+ Rust Lang = "rust"
+ Java Lang = "java"
+)
+
+type Framework string
+
+const (
+ AFL Framework = "afl"
+ LibFuzzer Framework = "libfuzzer"
+ Jazzer Framework = "jazzer"
+ UnknownFramework Framework = "unknownframework"
)
var BoolDefault = proptools.BoolDefault
@@ -48,7 +56,6 @@
Packages android.Paths
FuzzTargets map[string]bool
SharedLibInstallStrings []string
- FuzzType FuzzType
}
type FileToZip struct {
@@ -146,6 +153,12 @@
IsJni *bool `json:"is_jni,omitempty"`
}
+type FuzzFrameworks struct {
+ Afl *bool
+ Libfuzzer *bool
+ Jazzer *bool
+}
+
type FuzzProperties struct {
// Optional list of seed files to be installed to the fuzz target's output
// directory.
@@ -155,6 +168,10 @@
Data []string `android:"path"`
// Optional dictionary to be installed to the fuzz target's output directory.
Dictionary *string `android:"path"`
+ // Define the fuzzing frameworks this fuzz target can be built for. If
+ // empty then the fuzz target will be available to be built for all fuzz
+ // frameworks available
+ Fuzzing_frameworks *FuzzFrameworks
// Config for running the target on fuzzing infrastructure.
Fuzz_config *FuzzConfig
}
@@ -169,6 +186,49 @@
DataIntermediateDir android.Path
}
+func GetFramework(ctx android.LoadHookContext, lang Lang) Framework {
+ framework := ctx.Config().Getenv("FUZZ_FRAMEWORK")
+
+ if lang == Cc {
+ switch strings.ToLower(framework) {
+ case "":
+ return LibFuzzer
+ case "libfuzzer":
+ return LibFuzzer
+ case "afl":
+ return AFL
+ }
+ } else if lang == Rust {
+ return LibFuzzer
+ } else if lang == Java {
+ return Jazzer
+ }
+
+ ctx.ModuleErrorf(fmt.Sprintf("%s is not a valid fuzzing framework for %s", framework, lang))
+ return UnknownFramework
+}
+
+func IsValidFrameworkForModule(targetFramework Framework, lang Lang, moduleFrameworks *FuzzFrameworks) bool {
+ if targetFramework == UnknownFramework {
+ return false
+ }
+
+ if moduleFrameworks == nil {
+ return true
+ }
+
+ switch targetFramework {
+ case LibFuzzer:
+ return proptools.BoolDefault(moduleFrameworks.Libfuzzer, true)
+ case AFL:
+ return proptools.BoolDefault(moduleFrameworks.Afl, true)
+ case Jazzer:
+ return proptools.BoolDefault(moduleFrameworks.Jazzer, true)
+ default:
+ panic("%s is not supported as a fuzz framework")
+ }
+}
+
func IsValid(fuzzModule FuzzModule) bool {
// Discard ramdisk + vendor_ramdisk + recovery modules, they're duplicates of
// fuzz targets we're going to package anyway.
@@ -267,7 +327,7 @@
return string(b)
}
-func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs map[ArchOs][]FileToZip, fuzzType FuzzType, pctx android.PackageContext) {
+func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs map[ArchOs][]FileToZip, fuzzType Lang, pctx android.PackageContext) {
var archOsList []ArchOs
for archOs := range archDirs {
archOsList = append(archOsList, archOs)
@@ -286,9 +346,7 @@
if fuzzType == Java {
zipFileName = "fuzz-java-" + hostOrTarget + "-" + arch + ".zip"
}
- if fuzzType == AFL {
- zipFileName = "fuzz-afl-" + hostOrTarget + "-" + arch + ".zip"
- }
+
outputFile := android.PathForOutput(ctx, zipFileName)
s.Packages = append(s.Packages, outputFile)
diff --git a/java/aar.go b/java/aar.go
index a59ecb8..d5996ba 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -21,6 +21,7 @@
"strings"
"android/soong/android"
+ "android/soong/bazel"
"android/soong/dexpreopt"
"github.com/google/blueprint"
@@ -490,6 +491,7 @@
type AndroidLibrary struct {
Library
aapt
+ android.BazelModuleBase
androidLibraryProperties androidLibraryProperties
@@ -605,6 +607,7 @@
android.InitApexModule(module)
InitJavaModule(module, android.DeviceSupported)
+ android.InitBazelModule(module)
return module
}
@@ -643,6 +646,7 @@
android.ModuleBase
android.DefaultableModuleBase
android.ApexModuleBase
+ android.BazelModuleBase
prebuilt android.Prebuilt
// Functionality common to Module and Import.
@@ -973,5 +977,96 @@
android.InitPrebuiltModule(module, &module.properties.Aars)
android.InitApexModule(module)
InitJavaModuleMultiTargets(module, android.DeviceSupported)
+ android.InitBazelModule(module)
return module
}
+
+type bazelAapt struct {
+ Manifest bazel.Label
+ Resource_files bazel.LabelListAttribute
+}
+
+type bazelAndroidLibrary struct {
+ *javaLibraryAttributes
+ *bazelAapt
+}
+
+type bazelAndroidLibraryImport struct {
+ Aar bazel.Label
+ Deps bazel.LabelListAttribute
+ Exports bazel.LabelListAttribute
+}
+
+func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) *bazelAapt {
+ manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
+
+ resourceFiles := bazel.LabelList{
+ Includes: []bazel.Label{},
+ }
+ for _, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") {
+ files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))
+ resourceFiles.Includes = append(resourceFiles.Includes, files...)
+ }
+ return &bazelAapt{
+ android.BazelLabelForModuleSrcSingle(ctx, manifest),
+ bazel.MakeLabelListAttribute(resourceFiles),
+ }
+}
+
+func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ aars := android.BazelLabelForModuleSrcExcludes(ctx, a.properties.Aars, []string{})
+ exportableStaticLibs := []string{}
+ // TODO(b/240716882): investigate and handle static_libs deps that are not imports. They are not supported for export by Bazel.
+ for _, depName := range a.properties.Static_libs {
+ if dep, ok := ctx.ModuleFromName(depName); ok {
+ switch dep.(type) {
+ case *AARImport, *Import:
+ exportableStaticLibs = append(exportableStaticLibs, depName)
+ }
+ }
+ }
+ name := android.RemoveOptionalPrebuiltPrefix(a.Name())
+ deps := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(append(a.properties.Static_libs, a.properties.Libs...))))
+ exports := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(exportableStaticLibs))
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "aar_import",
+ Bzl_load_location: "@rules_android//rules:rules.bzl",
+ },
+ android.CommonAttributes{Name: name},
+ &bazelAndroidLibraryImport{
+ Aar: aars.Includes[0],
+ Deps: bazel.MakeLabelListAttribute(deps),
+ Exports: bazel.MakeLabelListAttribute(exports),
+ },
+ )
+
+}
+
+func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ commonAttrs, depLabels := a.convertLibraryAttrsBp2Build(ctx)
+
+ deps := depLabels.Deps
+ if !commonAttrs.Srcs.IsEmpty() {
+ deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
+ } else if !depLabels.Deps.IsEmpty() {
+ ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
+ }
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "android_library",
+ Bzl_load_location: "@rules_android//rules:rules.bzl",
+ },
+ android.CommonAttributes{Name: a.Name()},
+ &bazelAndroidLibrary{
+ &javaLibraryAttributes{
+ javaCommonAttributes: commonAttrs,
+ Deps: deps,
+ Exports: depLabels.StaticDeps,
+ },
+ a.convertAaptAttrsWithBp2Build(ctx),
+ },
+ )
+}
diff --git a/java/app.go b/java/app.go
index 1995f13..3c8fcd3 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1444,10 +1444,9 @@
type bazelAndroidAppAttributes struct {
*javaCommonAttributes
+ *bazelAapt
Deps bazel.LabelListAttribute
- Manifest bazel.Label
Custom_package *string
- Resource_files bazel.LabelListAttribute
Certificate *bazel.Label
Certificate_name *string
}
@@ -1457,23 +1456,9 @@
commonAttrs, depLabels := a.convertLibraryAttrsBp2Build(ctx)
deps := depLabels.Deps
- if !commonAttrs.Srcs.IsEmpty() {
- deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
- } else if !deps.IsEmpty() || !depLabels.StaticDeps.IsEmpty() {
- ctx.ModuleErrorf("android_app has dynamic or static dependencies but no sources." +
- " Bazel does not allow direct dependencies without sources nor exported" +
- " dependencies on android_binary rule.")
- }
+ deps.Append(depLabels.StaticDeps)
- manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
-
- resourceFiles := bazel.LabelList{
- Includes: []bazel.Label{},
- }
- for _, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") {
- files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))
- resourceFiles.Includes = append(resourceFiles.Includes, files...)
- }
+ aapt := a.convertAaptAttrsWithBp2Build(ctx)
var certificate *bazel.Label
certificateNamePtr := a.overridableAppProperties.Certificate
@@ -1484,14 +1469,12 @@
certificate = &c
certificateNamePtr = nil
}
-
attrs := &bazelAndroidAppAttributes{
commonAttrs,
+ aapt,
deps,
- android.BazelLabelForModuleSrcSingle(ctx, manifest),
// TODO(b/209576404): handle package name override by product variable PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
a.overridableAppProperties.Package_name,
- bazel.MakeLabelListAttribute(resourceFiles),
certificate,
certificateNamePtr,
}
@@ -1500,7 +1483,6 @@
Rule_class: "android_binary",
Bzl_load_location: "//build/bazel/rules/android:android_binary.bzl",
}
-
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
}
diff --git a/java/java.go b/java/java.go
index f4ec04e..481c625 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2333,12 +2333,12 @@
var deps bazel.LabelList
if m.properties.Libs != nil {
- deps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Libs))
+ deps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Libs))))
}
var staticDeps bazel.LabelList
if m.properties.Static_libs != nil {
- staticDeps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Static_libs))
+ staticDeps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Static_libs))))
}
protoDepLabel := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition])
diff --git a/java/lint_defaults.txt b/java/lint_defaults.txt
index e99cb05..01e7e6e 100644
--- a/java/lint_defaults.txt
+++ b/java/lint_defaults.txt
@@ -101,7 +101,6 @@
--warning_check WrongViewCast # 1 occurences in 1 modules
--warning_check CoarseFineLocation
---warning_check ExtraText
--warning_check IntentFilterExportedReceiver
--warning_check MissingInflatedId
--warning_check NotificationPermission