Merge "Add noOverrideExternalGlobalCflags support to Soong"
diff --git a/android/arch.go b/android/arch.go
index 3cc5e82..e08fd5c 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -168,7 +168,7 @@
return archType
}
-// ArchTypeList returns the a slice copy of the 4 supported ArchTypes for arm,
+// ArchTypeList returns a slice copy of the 4 supported ArchTypes for arm,
// arm64, x86 and x86_64.
func ArchTypeList() []ArchType {
return append([]ArchType(nil), archTypeList...)
@@ -408,7 +408,7 @@
// addPathDepsForProps does not descend into sub structs, so we need to descend into the
// arch-specific properties ourselves
- properties := []interface{}{}
+ var properties []interface{}
for _, archProperties := range m.archProperties {
for _, archProps := range archProperties {
archPropValues := reflect.ValueOf(archProps).Elem()
@@ -995,8 +995,11 @@
// Store the original list of top level property structs
base.generalProperties = m.GetProperties()
+ if len(base.archProperties) != 0 {
+ panic(fmt.Errorf("module %s already has archProperties", m.Name()))
+ }
- for _, properties := range base.generalProperties {
+ getStructType := func(properties interface{}) reflect.Type {
propertiesValue := reflect.ValueOf(properties)
t := propertiesValue.Type()
if propertiesValue.Kind() != reflect.Ptr {
@@ -1006,10 +1009,14 @@
propertiesValue = propertiesValue.Elem()
if propertiesValue.Kind() != reflect.Struct {
- panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
+ panic(fmt.Errorf("properties must be a pointer to a struct, got a pointer to %T",
propertiesValue.Interface()))
}
+ return t
+ }
+ for _, properties := range base.generalProperties {
+ t := getStructType(properties)
// Get or create the arch-specific property struct types for this property struct type.
archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} {
return createArchPropTypeDesc(t)
diff --git a/android/bazel.go b/android/bazel.go
index fd3f23e..4114f37 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -15,6 +15,8 @@
package android
import (
+ "bufio"
+ "errors"
"fmt"
"io/ioutil"
"path/filepath"
@@ -206,7 +208,8 @@
"build/bazel/platforms":/* recursive = */ true,
"build/bazel/product_variables":/* recursive = */ true,
"build/bazel_common_rules":/* recursive = */ true,
- "build/make/tools":/* recursive = */ true,
+ // build/make/tools/signapk BUILD file is generated, so build/make/tools is not recursive.
+ "build/make/tools":/* recursive = */ false,
"build/pesto":/* recursive = */ true,
// external/bazelbuild-rules_android/... is needed by mixed builds, otherwise mixed builds analysis fails
@@ -237,6 +240,7 @@
"bootable/recovery/tools/recovery_l10n": Bp2BuildDefaultTrue,
"build/bazel/examples/soong_config_variables": Bp2BuildDefaultTrueRecursively,
"build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
+ "build/make/tools/signapk": Bp2BuildDefaultTrue,
"build/soong": Bp2BuildDefaultTrue,
"build/soong/cc/libbuildversion": Bp2BuildDefaultTrue, // Skip tests subdir
"build/soong/cc/ndkstubgen": Bp2BuildDefaultTrue,
@@ -279,7 +283,9 @@
"development/sdk": Bp2BuildDefaultTrueRecursively,
"external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively,
"external/boringssl": Bp2BuildDefaultTrueRecursively,
+ "external/bouncycastle": Bp2BuildDefaultTrue,
"external/brotli": Bp2BuildDefaultTrue,
+ "external/conscrypt": Bp2BuildDefaultTrue,
"external/fmtlib": Bp2BuildDefaultTrueRecursively,
"external/google-benchmark": Bp2BuildDefaultTrueRecursively,
"external/googletest": Bp2BuildDefaultTrueRecursively,
@@ -327,7 +333,7 @@
"packages/services/Car/tests/SampleRearViewCamera": Bp2BuildDefaultTrue,
"prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
"system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures
- "system/core/debuggerd": Bp2BuildDefaultTrue,
+ "system/core/debuggerd": Bp2BuildDefaultTrueRecursively,
"system/core/diagnose_usb": Bp2BuildDefaultTrueRecursively,
"system/core/libasyncio": Bp2BuildDefaultTrue,
"system/core/libcrypto_utils": Bp2BuildDefaultTrueRecursively,
@@ -349,6 +355,8 @@
"system/timezone/output_data": Bp2BuildDefaultTrueRecursively,
"system/unwinding/libbacktrace": Bp2BuildDefaultTrueRecursively,
"system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively,
+ "tools/apksig": Bp2BuildDefaultTrue,
+ "tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively,
}
// Per-module denylist to always opt modules out of both bp2build and mixed builds.
@@ -386,9 +394,13 @@
"libbacktrace", // depends on unconverted module libunwindstack
"libdebuggerd_handler", // depends on unconverted module libdebuggerd_handler_core
"libdebuggerd_handler_core", "libdebuggerd_handler_fallback", // depends on unconverted module libdebuggerd
- "unwind_for_offline", // depends on unconverted module libunwindstack_utils
- "libdebuggerd", // depends on unconverted modules libdexfile_support, libunwindstack, gwp_asan_crash_handler, libtombstone_proto, libprotobuf-cpp-lite
- "libdexfile_static", // depends on libartpalette, libartbase, libdexfile, which are of unsupported type: art_cc_library.
+ "unwind_for_offline", // depends on unconverted module libunwindstack_utils
+ "libdebuggerd", // depends on unconverted modules libdexfile_support, libunwindstack, gwp_asan_crash_handler, libtombstone_proto, libprotobuf-cpp-lite
+ "libdexfile_static", // depends on libartpalette, libartbase, libdexfile, which are of unsupported type: art_cc_library.
+
+ "crasher", // depends on unconverted modules: libseccomp_policy
+ "static_crasher", // depends on unconverted modules: libdebuggerd_handler, libseccomp_policy
+
"host_bionic_linker_asm", // depends on extract_linker, a go binary.
"host_bionic_linker_script", // depends on extract_linker, a go binary.
@@ -401,11 +413,12 @@
"libbase_ndk", // http://b/186826477, fails to link libctscamera2_jni for device (required for CtsCameraTestCases)
- "lib_linker_config_proto_lite", // contains .proto sources
-
"libprotobuf-python", // contains .proto sources
- "libprotobuf-internal-protos", // we don't handle path property for fileegroups
- "libprotobuf-internal-python-srcs", // we don't handle path property for fileegroups
+ "libprotobuf-internal-protos", // b/210751803, we don't handle path property for filegroups
+ "libprotobuf-internal-python-srcs", // b/210751803, we don't handle path property for filegroups
+ "libprotobuf-java-full", // b/210751803, we don't handle path property for filegroups
+ "libprotobuf-java-util-full", // b/210751803, we don't handle path property for filegroups
+ "conscrypt", // b/210751803, we don't handle path property for filegroups
"libseccomp_policy", // b/201094425: depends on func_to_syscall_nrs, which depends on py_binary, which is unsupported in mixed builds.
"libfdtrack", // depends on unconverted module libunwindstack
@@ -640,3 +653,22 @@
bModule.ConvertWithBp2build(ctx)
}
+
+// GetMainClassInManifest scans the manifest file specified in filepath and returns
+// the value of attribute Main-Class in the manifest file if it exists, or returns error.
+// WARNING: this is for bp2build converters of java_* modules only.
+func GetMainClassInManifest(c Config, filepath string) (string, error) {
+ file, err := c.fs.Open(filepath)
+ if err != nil {
+ return "", err
+ }
+ scanner := bufio.NewScanner(file)
+ for scanner.Scan() {
+ line := scanner.Text()
+ if strings.HasPrefix(line, "Main-Class:") {
+ return strings.TrimSpace(line[len("Main-Class:"):]), nil
+ }
+ }
+
+ return "", errors.New("Main-Class is not found.")
+}
diff --git a/android/defaults.go b/android/defaults.go
index 7b3d38c..0953f95 100644
--- a/android/defaults.go
+++ b/android/defaults.go
@@ -212,7 +212,6 @@
// The applicable licenses property for defaults is 'licenses'.
setPrimaryLicensesProperty(module, "licenses", &commonProperties.Licenses)
- base.module = module
}
var _ Defaults = (*DefaultsModuleBase)(nil)
diff --git a/android/module.go b/android/module.go
index 189781a..c479b59 100644
--- a/android/module.go
+++ b/android/module.go
@@ -2096,18 +2096,18 @@
return GlobFiles(e, globPattern, excludes)
}
-func (b *earlyModuleContext) IsSymlink(path Path) bool {
- fileInfo, err := b.config.fs.Lstat(path.String())
+func (e *earlyModuleContext) IsSymlink(path Path) bool {
+ fileInfo, err := e.config.fs.Lstat(path.String())
if err != nil {
- b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
+ e.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
}
return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
}
-func (b *earlyModuleContext) Readlink(path Path) string {
- dest, err := b.config.fs.Readlink(path.String())
+func (e *earlyModuleContext) Readlink(path Path) string {
+ dest, err := e.config.fs.Readlink(path.String())
if err != nil {
- b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
+ e.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
}
return dest
}
diff --git a/android/package_test.go b/android/package_test.go
index 7ea10a4..65c4240 100644
--- a/android/package_test.go
+++ b/android/package_test.go
@@ -11,7 +11,7 @@
}{
// Package default_visibility handling is tested in visibility_test.go
{
- name: "package must not accept visibility and name properties",
+ name: "package must not accept visibility, name or licenses properties",
fs: map[string][]byte{
"top/Android.bp": []byte(`
package {
@@ -48,8 +48,7 @@
default_visibility: ["//visibility:private"],
default_applicable_licenses: ["license"],
}
-
- package {
+ package {
}`),
},
expectedErrors: []string{
diff --git a/apex/apex.go b/apex/apex.go
index a28cd72..b7faa5b 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -96,6 +96,14 @@
// /system/sepolicy/apex/<module_name>_file_contexts.
File_contexts *string `android:"path"`
+ // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
+ // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
+ // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
+ // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
+ // capability. If this property is not set, or a file is missing in the file, default config
+ // is used.
+ Canned_fs_config *string `android:"path"`
+
ApexNativeDependencies
Multilib apexMultilibProperties
diff --git a/apex/apex_test.go b/apex/apex_test.go
index c71b6d0..a749ea1 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -2581,22 +2581,21 @@
`)
generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
- dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
+ cmd := generateFsRule.RuleParams.Command
// Ensure that the subdirectories are all listed
- ensureListContains(t, dirs, "etc")
- ensureListContains(t, dirs, "etc/foo")
- ensureListContains(t, dirs, "etc/foo/bar")
- ensureListContains(t, dirs, "lib64")
- ensureListContains(t, dirs, "lib64/foo")
- ensureListContains(t, dirs, "lib64/foo/bar")
- ensureListContains(t, dirs, "lib")
- ensureListContains(t, dirs, "lib/foo")
- ensureListContains(t, dirs, "lib/foo/bar")
-
- ensureListContains(t, dirs, "bin")
- ensureListContains(t, dirs, "bin/foo")
- ensureListContains(t, dirs, "bin/foo/bar")
+ ensureContains(t, cmd, "/etc ")
+ ensureContains(t, cmd, "/etc/foo ")
+ ensureContains(t, cmd, "/etc/foo/bar ")
+ ensureContains(t, cmd, "/lib64 ")
+ ensureContains(t, cmd, "/lib64/foo ")
+ ensureContains(t, cmd, "/lib64/foo/bar ")
+ ensureContains(t, cmd, "/lib ")
+ ensureContains(t, cmd, "/lib/foo ")
+ ensureContains(t, cmd, "/lib/foo/bar ")
+ ensureContains(t, cmd, "/bin ")
+ ensureContains(t, cmd, "/bin/foo ")
+ ensureContains(t, cmd, "/bin/foo/bar ")
}
func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) {
diff --git a/apex/builder.go b/apex/builder.go
index 5910784..ea25537 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -72,19 +72,6 @@
}
var (
- // Create a canned fs config file where all files and directories are
- // by default set to (uid/gid/mode) = (1000/1000/0644)
- // TODO(b/113082813) make this configurable using config.fs syntax
- generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
- Command: `( set -e; echo '/ 1000 1000 0755' ` +
- `&& for i in ${ro_paths}; do echo "/$$i 1000 1000 0644"; done ` +
- `&& for i in ${exec_paths}; do echo "/$$i 0 2000 0755"; done ` +
- `&& ( tr ' ' '\n' <${out}.apklist | for i in ${apk_paths}; do read apk; echo "/$$i 0 2000 0755"; zipinfo -1 $$apk | sed "s:\(.*\):/$$i/\1 1000 1000 0644:"; done ) ) > ${out}`,
- Description: "fs_config ${out}",
- Rspfile: "$out.apklist",
- RspfileContent: "$in",
- }, "ro_paths", "exec_paths", "apk_paths")
-
apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
Command: `rm -f $out && ${jsonmodify} $in ` +
`-a provideNativeLibs ${provideNativeLibs} ` +
@@ -583,55 +570,11 @@
// Figure out if need to compress apex.
compressionEnabled := ctx.Config().CompressedApex() && proptools.BoolDefault(a.properties.Compressible, false) && !a.testApex && !ctx.Config().UnbundledBuildApps()
if apexType == imageApex {
+
////////////////////////////////////////////////////////////////////////////////////
// Step 2: create canned_fs_config which encodes filemode,uid,gid of each files
// in this APEX. The file will be used by apexer in later steps.
- // TODO(jiyong): make this as a function
- // TODO(jiyong): use the RuleBuilder
- var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
- var executablePaths []string // this also includes dirs
- var extractedAppSetPaths android.Paths
- var extractedAppSetDirs []string
- for _, f := range a.filesInfo {
- pathInApex := f.path()
- if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
- executablePaths = append(executablePaths, pathInApex)
- for _, d := range f.dataPaths {
- readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel()))
- }
- for _, s := range f.symlinks {
- executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
- }
- } else if f.class == appSet {
- extractedAppSetPaths = append(extractedAppSetPaths, f.builtFile)
- extractedAppSetDirs = append(extractedAppSetDirs, f.installDir)
- } else {
- readOnlyPaths = append(readOnlyPaths, pathInApex)
- }
- dir := f.installDir
- for !android.InList(dir, executablePaths) && dir != "" {
- executablePaths = append(executablePaths, dir)
- dir, _ = filepath.Split(dir) // move up to the parent
- if len(dir) > 0 {
- // remove trailing slash
- dir = dir[:len(dir)-1]
- }
- }
- }
- sort.Strings(readOnlyPaths)
- sort.Strings(executablePaths)
- cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
- ctx.Build(pctx, android.BuildParams{
- Rule: generateFsConfig,
- Output: cannedFsConfig,
- Description: "generate fs config",
- Inputs: extractedAppSetPaths,
- Args: map[string]string{
- "ro_paths": strings.Join(readOnlyPaths, " "),
- "exec_paths": strings.Join(executablePaths, " "),
- "apk_paths": strings.Join(extractedAppSetDirs, " "),
- },
- })
+ cannedFsConfig := a.buildCannedFsConfig(ctx)
implicitInputs = append(implicitInputs, cannedFsConfig)
////////////////////////////////////////////////////////////////////////////////////
@@ -1072,3 +1015,65 @@
a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build())
}
+
+func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext) android.OutputPath {
+ var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
+ var executablePaths []string // this also includes dirs
+ var appSetDirs []string
+ appSetFiles := make(map[string]android.Path)
+ for _, f := range a.filesInfo {
+ pathInApex := f.path()
+ if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
+ executablePaths = append(executablePaths, pathInApex)
+ for _, d := range f.dataPaths {
+ readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel()))
+ }
+ for _, s := range f.symlinks {
+ executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
+ }
+ } else if f.class == appSet {
+ appSetDirs = append(appSetDirs, f.installDir)
+ appSetFiles[f.installDir] = f.builtFile
+ } else {
+ readOnlyPaths = append(readOnlyPaths, pathInApex)
+ }
+ dir := f.installDir
+ for !android.InList(dir, executablePaths) && dir != "" {
+ executablePaths = append(executablePaths, dir)
+ dir, _ = filepath.Split(dir) // move up to the parent
+ if len(dir) > 0 {
+ // remove trailing slash
+ dir = dir[:len(dir)-1]
+ }
+ }
+ }
+ sort.Strings(readOnlyPaths)
+ sort.Strings(executablePaths)
+ sort.Strings(appSetDirs)
+
+ cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
+ builder := android.NewRuleBuilder(pctx, ctx)
+ cmd := builder.Command()
+ cmd.Text("(")
+ cmd.Text("echo '/ 1000 1000 0755';")
+ for _, p := range readOnlyPaths {
+ cmd.Textf("echo '/%s 1000 1000 0644';", p)
+ }
+ for _, p := range executablePaths {
+ cmd.Textf("echo '/%s 0 2000 0755';", p)
+ }
+ for _, dir := range appSetDirs {
+ cmd.Textf("echo '/%s 0 2000 0755';", dir)
+ file := appSetFiles[dir]
+ cmd.Text("zipinfo -1").Input(file).Textf(`| sed "s:\(.*\):/%s/\1 1000 1000 0644:";`, dir)
+ }
+ // Custom fs_config is "appended" to the last so that entries from the file are preferred
+ // over default ones set above.
+ if a.properties.Canned_fs_config != nil {
+ cmd.Text("cat").Input(android.PathForModuleSrc(ctx, *a.properties.Canned_fs_config))
+ }
+ cmd.Text(")").FlagWithOutput("> ", cannedFsConfig)
+ builder.Build("generateFsConfig", fmt.Sprintf("Generating canned fs config for %s", a.BaseModuleName()))
+
+ return cannedFsConfig.OutputPath
+}
diff --git a/apex/vndk.go b/apex/vndk.go
index cf525a8..ef3e5e1 100644
--- a/apex/vndk.go
+++ b/apex/vndk.go
@@ -140,21 +140,5 @@
addSymlink("/apex/com.android.i18n/etc/icu", dir, "icu")
}
- // TODO(b/124106384): Clean up compat symlinks for ART binaries.
- if name == "com.android.art" {
- dir := android.PathForModuleInPartitionInstall(ctx, "system", "bin")
- addSymlink("/apex/com.android.art/bin/dalvikvm", dir, "dalvikvm")
- dex2oat := "dex2oat32"
- if ctx.Config().Android64() {
- dex2oat = "dex2oat64"
- }
- addSymlink("/apex/com.android.art/bin/"+dex2oat, dir, "dex2oat")
- } else if name == "com.android.art" || strings.HasPrefix(name, "com.android.art.") {
- dir := android.PathForModuleInPartitionInstall(ctx, "system", "bin")
- symlinks = append(symlinks,
- dir.Join(ctx, "dalvikvm"),
- dir.Join(ctx, "dex2oat"))
- }
-
return symlinks
}
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index 337fe86..ae0fb11 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -32,15 +32,17 @@
],
testSrcs: [
"android_app_certificate_conversion_test.go",
+ "android_app_conversion_test.go",
"apex_conversion_test.go",
"apex_key_conversion_test.go",
"build_conversion_test.go",
"bzl_conversion_test.go",
+ "cc_binary_conversion_test.go",
"cc_genrule_conversion_test.go",
"cc_library_conversion_test.go",
"cc_library_headers_conversion_test.go",
- "cc_library_static_conversion_test.go",
"cc_library_shared_conversion_test.go",
+ "cc_library_static_conversion_test.go",
"cc_object_conversion_test.go",
"conversion_test.go",
"filegroup_conversion_test.go",
@@ -50,6 +52,7 @@
"python_binary_conversion_test.go",
"python_library_conversion_test.go",
"sh_conversion_test.go",
+ "soong_config_module_type_conversion_test.go",
"testing.go",
],
pluginFor: [
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index b4eb28f..eaceea9 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -2041,3 +2041,121 @@
},
})
}
+
+func TestCcLibraryProtoFilegroups(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ blueprint: soongCcProtoPreamble +
+ simpleModuleDoNotConvertBp2build("filegroup", "a_fg_proto") +
+ simpleModuleDoNotConvertBp2build("filegroup", "b_protos") +
+ simpleModuleDoNotConvertBp2build("filegroup", "c-proto-srcs") +
+ simpleModuleDoNotConvertBp2build("filegroup", "proto-srcs-d") + `
+cc_library {
+ name: "a",
+ srcs: [":a_fg_proto"],
+ proto: {
+ canonical_path_from_root: false,
+ export_proto_headers: true,
+ },
+ include_build_directory: false,
+}
+
+cc_library {
+ name: "b",
+ srcs: [":b_protos"],
+ proto: {
+ canonical_path_from_root: false,
+ export_proto_headers: true,
+ },
+ include_build_directory: false,
+}
+
+cc_library {
+ name: "c",
+ srcs: [":c-proto-srcs"],
+ proto: {
+ canonical_path_from_root: false,
+ export_proto_headers: true,
+ },
+ include_build_directory: false,
+}
+
+cc_library {
+ name: "d",
+ srcs: [":proto-srcs-d"],
+ proto: {
+ canonical_path_from_root: false,
+ export_proto_headers: true,
+ },
+ include_build_directory: false,
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("proto_library", "a_proto", attrNameToString{
+ "srcs": `[":a_fg_proto"]`,
+ }), makeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", attrNameToString{
+ "deps": `[":a_proto"]`,
+ }), makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{
+ "deps": `[":libprotobuf-cpp-lite"]`,
+ "whole_archive_deps": `[":a_cc_proto_lite"]`,
+ "srcs": `[":a_fg_proto_cpp_srcs"]`,
+ "srcs_as": `[":a_fg_proto_as_srcs"]`,
+ "srcs_c": `[":a_fg_proto_c_srcs"]`,
+ }), makeBazelTarget("cc_library_shared", "a", attrNameToString{
+ "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
+ "whole_archive_deps": `[":a_cc_proto_lite"]`,
+ "srcs": `[":a_fg_proto_cpp_srcs"]`,
+ "srcs_as": `[":a_fg_proto_as_srcs"]`,
+ "srcs_c": `[":a_fg_proto_c_srcs"]`,
+ }), makeBazelTarget("proto_library", "b_proto", attrNameToString{
+ "srcs": `[":b_protos"]`,
+ }), makeBazelTarget("cc_lite_proto_library", "b_cc_proto_lite", attrNameToString{
+ "deps": `[":b_proto"]`,
+ }), makeBazelTarget("cc_library_static", "b_bp2build_cc_library_static", attrNameToString{
+ "deps": `[":libprotobuf-cpp-lite"]`,
+ "whole_archive_deps": `[":b_cc_proto_lite"]`,
+ "srcs": `[":b_protos_cpp_srcs"]`,
+ "srcs_as": `[":b_protos_as_srcs"]`,
+ "srcs_c": `[":b_protos_c_srcs"]`,
+ }), makeBazelTarget("cc_library_shared", "b", attrNameToString{
+ "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
+ "whole_archive_deps": `[":b_cc_proto_lite"]`,
+ "srcs": `[":b_protos_cpp_srcs"]`,
+ "srcs_as": `[":b_protos_as_srcs"]`,
+ "srcs_c": `[":b_protos_c_srcs"]`,
+ }), makeBazelTarget("proto_library", "c_proto", attrNameToString{
+ "srcs": `[":c-proto-srcs"]`,
+ }), makeBazelTarget("cc_lite_proto_library", "c_cc_proto_lite", attrNameToString{
+ "deps": `[":c_proto"]`,
+ }), makeBazelTarget("cc_library_static", "c_bp2build_cc_library_static", attrNameToString{
+ "deps": `[":libprotobuf-cpp-lite"]`,
+ "whole_archive_deps": `[":c_cc_proto_lite"]`,
+ "srcs": `[":c-proto-srcs_cpp_srcs"]`,
+ "srcs_as": `[":c-proto-srcs_as_srcs"]`,
+ "srcs_c": `[":c-proto-srcs_c_srcs"]`,
+ }), makeBazelTarget("cc_library_shared", "c", attrNameToString{
+ "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
+ "whole_archive_deps": `[":c_cc_proto_lite"]`,
+ "srcs": `[":c-proto-srcs_cpp_srcs"]`,
+ "srcs_as": `[":c-proto-srcs_as_srcs"]`,
+ "srcs_c": `[":c-proto-srcs_c_srcs"]`,
+ }), makeBazelTarget("proto_library", "d_proto", attrNameToString{
+ "srcs": `[":proto-srcs-d"]`,
+ }), makeBazelTarget("cc_lite_proto_library", "d_cc_proto_lite", attrNameToString{
+ "deps": `[":d_proto"]`,
+ }), makeBazelTarget("cc_library_static", "d_bp2build_cc_library_static", attrNameToString{
+ "deps": `[":libprotobuf-cpp-lite"]`,
+ "whole_archive_deps": `[":d_cc_proto_lite"]`,
+ "srcs": `[":proto-srcs-d_cpp_srcs"]`,
+ "srcs_as": `[":proto-srcs-d_as_srcs"]`,
+ "srcs_c": `[":proto-srcs-d_c_srcs"]`,
+ }), makeBazelTarget("cc_library_shared", "d", attrNameToString{
+ "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
+ "whole_archive_deps": `[":d_cc_proto_lite"]`,
+ "srcs": `[":proto-srcs-d_cpp_srcs"]`,
+ "srcs_as": `[":proto-srcs-d_as_srcs"]`,
+ "srcs_c": `[":proto-srcs-d_c_srcs"]`,
+ }),
+ },
+ })
+}
diff --git a/bp2build/java_binary_host_conversion_test.go b/bp2build/java_binary_host_conversion_test.go
new file mode 100644
index 0000000..96b8958
--- /dev/null
+++ b/bp2build/java_binary_host_conversion_test.go
@@ -0,0 +1,63 @@
+// Copyright 2021 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 (
+ "testing"
+
+ "android/soong/android"
+ "android/soong/cc"
+ "android/soong/java"
+)
+
+func runJavaBinaryHostTestCase(t *testing.T, tc bp2buildTestCase) {
+ t.Helper()
+ (&tc).moduleTypeUnderTest = "java_binary_host"
+ (&tc).moduleTypeUnderTestFactory = java.BinaryHostFactory
+ runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory)
+ }, tc)
+}
+
+var fs = map[string]string{
+ "test.mf": "Main-Class: com.android.test.MainClass",
+ "other/Android.bp": `cc_library_host_shared {
+ name: "jni-lib-1",
+ stl: "none",
+}`,
+}
+
+func TestJavaBinaryHost(t *testing.T) {
+ runJavaBinaryHostTestCase(t, bp2buildTestCase{
+ description: "java_binary_host with srcs, exclude_srcs, jni_libs and manifest.",
+ filesystem: fs,
+ blueprint: `java_binary_host {
+ name: "java-binary-host-1",
+ srcs: ["a.java", "b.java"],
+ exclude_srcs: ["b.java"],
+ manifest: "test.mf",
+ jni_libs: ["jni-lib-1"],
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{
+ "srcs": `["a.java"]`,
+ "main_class": `"com.android.test.MainClass"`,
+ "deps": `["//other:jni-lib-1"]`,
+ "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`,
+ }),
+ },
+ })
+}
diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go
new file mode 100644
index 0000000..5c65ec2
--- /dev/null
+++ b/bp2build/java_library_conversion_test.go
@@ -0,0 +1,57 @@
+// Copyright 2021 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 (
+ "testing"
+
+ "android/soong/android"
+ "android/soong/java"
+)
+
+func runJavaLibraryTestCase(t *testing.T, tc bp2buildTestCase) {
+ t.Helper()
+ (&tc).moduleTypeUnderTest = "java_library"
+ (&tc).moduleTypeUnderTestFactory = java.LibraryFactory
+ runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
+}
+
+func TestJavaLibrary(t *testing.T) {
+ runJavaLibraryTestCase(t, bp2buildTestCase{
+ description: "java_library with srcs, exclude_srcs and libs",
+ blueprint: `java_library {
+ name: "java-lib-1",
+ srcs: ["a.java", "b.java"],
+ exclude_srcs: ["b.java"],
+ libs: ["java-lib-2"],
+ bazel_module: { bp2build_available: true },
+}
+
+java_library {
+ name: "java-lib-2",
+ srcs: ["b.java"],
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("java_library", "java-lib-1", attrNameToString{
+ "srcs": `["a.java"]`,
+ "deps": `[":java-lib-2"]`,
+ }),
+ makeBazelTarget("java_library", "java-lib-2", attrNameToString{
+ "srcs": `["b.java"]`,
+ }),
+ },
+ })
+}
diff --git a/bp2build/java_library_host_conversion_test.go b/bp2build/java_library_host_conversion_test.go
new file mode 100644
index 0000000..6ac82db
--- /dev/null
+++ b/bp2build/java_library_host_conversion_test.go
@@ -0,0 +1,57 @@
+// Copyright 2021 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 (
+ "testing"
+
+ "android/soong/android"
+ "android/soong/java"
+)
+
+func runJavaLibraryHostTestCase(t *testing.T, tc bp2buildTestCase) {
+ t.Helper()
+ (&tc).moduleTypeUnderTest = "java_library_host"
+ (&tc).moduleTypeUnderTestFactory = java.LibraryHostFactory
+ runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
+}
+
+func TestJavaLibraryHost(t *testing.T) {
+ runJavaLibraryHostTestCase(t, bp2buildTestCase{
+ description: "java_library_host with srcs, exclude_srcs and libs",
+ blueprint: `java_library_host {
+ name: "java-lib-host-1",
+ srcs: ["a.java", "b.java"],
+ exclude_srcs: ["b.java"],
+ libs: ["java-lib-host-2"],
+ bazel_module: { bp2build_available: true },
+}
+
+java_library_host {
+ name: "java-lib-host-2",
+ srcs: ["c.java"],
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{
+ "srcs": `["a.java"]`,
+ "deps": `[":java-lib-host-2"]`,
+ }),
+ makeBazelTarget("java_library", "java-lib-host-2", attrNameToString{
+ "srcs": `["c.java"]`,
+ }),
+ },
+ })
+}
diff --git a/bp2build/testing.go b/bp2build/testing.go
index 15cf486..8ae1a38 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -133,8 +133,8 @@
android.FailIfErrored(t, errs)
}
if actualCount, expectedCount := len(bazelTargets), len(tc.expectedBazelTargets); actualCount != expectedCount {
- t.Errorf("%s: Expected %d bazel target, got `%d``",
- tc.description, expectedCount, actualCount)
+ t.Errorf("%s: Expected %d bazel target (%s), got `%d`` (%s)",
+ tc.description, expectedCount, tc.expectedBazelTargets, actualCount, bazelTargets)
} else {
for i, target := range bazelTargets {
if w, g := tc.expectedBazelTargets[i], target.content; w != g {
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 6c1646c..fad40be 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -16,6 +16,7 @@
import (
"fmt"
"path/filepath"
+ "regexp"
"strings"
"android/soong/android"
@@ -33,6 +34,12 @@
protoSrcPartition = "proto"
)
+var (
+ // ignoring case, checks for proto or protos as an independent word in the name, whether at the
+ // beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match
+ filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)")
+)
+
// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
// properties which apply to either the shared or static version of a cc_library module.
type staticOrSharedAttributes struct {
@@ -77,18 +84,18 @@
if !exists || !isFilegroup(m) {
return labelStr, false
}
- likelyProtos := strings.HasSuffix(labelStr, "proto") || strings.HasSuffix(labelStr, "protos")
+ likelyProtos := filegroupLikelyProtoPattern.MatchString(label.OriginalModuleName)
return labelStr, likelyProtos
}
// TODO(b/190006308): Handle language detection of sources in a Bazel rule.
partitioned := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{
- cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
- asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
+ protoSrcPartition: bazel.LabelPartition{Extensions: []string{".proto"}, LabelMapper: isProtoFilegroup},
+ cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
+ asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
// C++ is the "catch-all" group, and comprises generated sources because we don't
// know the language of these sources until the genrule is executed.
- cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
- protoSrcPartition: bazel.LabelPartition{Extensions: []string{".proto"}, LabelMapper: isProtoFilegroup},
+ cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
})
return partitioned
diff --git a/cc/cc.go b/cc/cc.go
index 0904bd9..5c4edb9 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -3453,23 +3453,27 @@
// ConvertWithBp2build converts Module to Bazel for bp2build.
func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ prebuilt := c.IsPrebuilt()
if c.Binary() {
- binaryBp2build(ctx, c, ctx.ModuleType())
- } else if c.Object() {
- objectBp2Build(ctx, c)
- } else if c.CcLibrary() {
- if c.hod == android.HostSupported {
- return
+ if !prebuilt {
+ binaryBp2build(ctx, c, ctx.ModuleType())
}
-
+ } else if c.Object() {
+ if !prebuilt {
+ objectBp2Build(ctx, c)
+ }
+ } else if c.CcLibrary() {
static := c.BuildStaticVariant()
shared := c.BuildSharedVariant()
- prebuilt := c.IsPrebuilt()
if static && shared {
- libraryBp2Build(ctx, c)
+ if !prebuilt {
+ libraryBp2Build(ctx, c)
+ }
} else if !static && !shared {
- libraryHeadersBp2Build(ctx, c)
+ if !prebuilt {
+ libraryHeadersBp2Build(ctx, c)
+ }
} else if static {
if prebuilt {
prebuiltLibraryStaticBp2Build(ctx, c)
diff --git a/cc/library.go b/cc/library.go
index aec699c..216c124 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -447,6 +447,8 @@
module, library := NewLibrary(android.HostSupported)
library.BuildOnlyShared()
module.sdkMemberTypes = []android.SdkMemberType{sharedLibrarySdkMemberType}
+ module.bazelable = true
+ module.bazelHandler = &ccLibraryBazelHandler{module: module}
return module.Init()
}
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index 4c3c7b4..feae812 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -552,7 +552,7 @@
}
func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
- module, binary := NewBinary(hod)
+ module, binary := newBinary(hod, false)
module.compiler = nil
prebuilt := &prebuiltBinaryLinker{
diff --git a/java/base.go b/java/base.go
index c0da215..c45ef64 100644
--- a/java/base.go
+++ b/java/base.go
@@ -372,6 +372,7 @@
android.DefaultableModuleBase
android.ApexModuleBase
android.SdkBase
+ android.BazelModuleBase
// Functionality common to Module and Import.
embeddableInModuleAndImport
@@ -1952,3 +1953,17 @@
}
var _ ModuleWithStem = (*Module)(nil)
+
+func (j *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ switch ctx.ModuleType() {
+ case "java_library", "java_library_host":
+ if lib, ok := ctx.Module().(*Library); ok {
+ javaLibraryBp2Build(ctx, lib)
+ }
+ case "java_binary_host":
+ if binary, ok := ctx.Module().(*Binary); ok {
+ javaBinaryHostBp2Build(ctx, binary)
+ }
+ }
+
+}
diff --git a/java/java.go b/java/java.go
index e7b1f4f..f77c694 100644
--- a/java/java.go
+++ b/java/java.go
@@ -21,7 +21,9 @@
import (
"fmt"
"path/filepath"
+ "strings"
+ "android/soong/bazel"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -756,6 +758,7 @@
android.InitApexModule(module)
android.InitSdkAwareModule(module)
+ android.InitBazelModule(module)
InitJavaModule(module, android.HostAndDeviceSupported)
return module
}
@@ -778,6 +781,7 @@
android.InitApexModule(module)
android.InitSdkAwareModule(module)
+ android.InitBazelModule(module)
InitJavaModule(module, android.HostSupported)
return module
}
@@ -1228,6 +1232,8 @@
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
android.InitDefaultableModule(module)
+ android.InitBazelModule(module)
+
return module
}
@@ -1245,6 +1251,7 @@
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
android.InitDefaultableModule(module)
+ android.InitBazelModule(module)
return module
}
@@ -1961,3 +1968,103 @@
clcMap.AddContextMap(dep.ClassLoaderContexts(), depName)
}
}
+
+type javaLibraryAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
+ Javacopts bazel.StringListAttribute
+}
+
+func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
+ srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs))
+ attrs := &javaLibraryAttributes{
+ Srcs: srcs,
+ }
+
+ if m.properties.Javacflags != nil {
+ attrs.Javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags)
+ }
+
+ if m.properties.Libs != nil {
+ attrs.Deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, m.properties.Libs))
+ }
+
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "java_library",
+ Bzl_load_location: "//build/bazel/rules/java:library.bzl",
+ }
+
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
+}
+
+type javaBinaryHostAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
+ Main_class string
+ Jvm_flags bazel.StringListAttribute
+}
+
+// JavaBinaryHostBp2Build is for java_binary_host bp2build.
+func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
+ mainClass := ""
+ if m.binaryProperties.Main_class != nil {
+ mainClass = *m.binaryProperties.Main_class
+ }
+ if m.properties.Manifest != nil {
+ mainClassInManifest, err := android.GetMainClassInManifest(ctx.Config(), android.PathForModuleSrc(ctx, *m.properties.Manifest).String())
+ if err != nil {
+ return
+ }
+ mainClass = mainClassInManifest
+ }
+ srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs))
+ attrs := &javaBinaryHostAttributes{
+ Srcs: srcs,
+ Main_class: mainClass,
+ }
+
+ // Attribute deps
+ deps := []string{}
+ if m.properties.Static_libs != nil {
+ deps = append(deps, m.properties.Static_libs...)
+ }
+ if m.binaryProperties.Jni_libs != nil {
+ deps = append(deps, m.binaryProperties.Jni_libs...)
+ }
+ if len(deps) > 0 {
+ attrs.Deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, deps))
+ }
+
+ // Attribute jvm_flags
+ if m.binaryProperties.Jni_libs != nil {
+ jniLibPackages := map[string]bool{}
+ for _, jniLibLabel := range android.BazelLabelForModuleDeps(ctx, m.binaryProperties.Jni_libs).Includes {
+ jniLibPackage := jniLibLabel.Label
+ indexOfColon := strings.Index(jniLibLabel.Label, ":")
+ if indexOfColon > 0 {
+ // JNI lib from other package
+ jniLibPackage = jniLibLabel.Label[2:indexOfColon]
+ } else if indexOfColon == 0 {
+ // JNI lib in the same package of java_binary
+ packageOfCurrentModule := m.GetBazelLabel(ctx, m)
+ jniLibPackage = packageOfCurrentModule[2:strings.Index(packageOfCurrentModule, ":")]
+ }
+ if _, inMap := jniLibPackages[jniLibPackage]; !inMap {
+ jniLibPackages[jniLibPackage] = true
+ }
+ }
+ jniLibPaths := []string{}
+ for jniLibPackage, _ := range jniLibPackages {
+ // See cs/f:.*/third_party/bazel/.*java_stub_template.txt for the use of RUNPATH
+ jniLibPaths = append(jniLibPaths, "$${RUNPATH}"+jniLibPackage)
+ }
+ attrs.Jvm_flags = bazel.MakeStringListAttribute([]string{"-Djava.library.path=" + strings.Join(jniLibPaths, ":")})
+ }
+
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "java_binary",
+ }
+
+ // Create the BazelTargetModule.
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
+}
diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go
index d5ff181..839dea2 100644
--- a/mk2rbc/mk2rbc.go
+++ b/mk2rbc/mk2rbc.go
@@ -105,7 +105,7 @@
"dist-for-goals": {baseName + ".mkdist_for_goals", starlarkTypeVoid, hiddenArgGlobal},
"enforce-product-packages-exist": {baseName + ".enforce_product_packages_exist", starlarkTypeVoid, hiddenArgNone},
"error": {baseName + ".mkerror", starlarkTypeVoid, hiddenArgNone},
- "findstring": {"!findstring", starlarkTypeInt, hiddenArgNone},
+ "findstring": {baseName + ".findstring", starlarkTypeString, hiddenArgNone},
"find-copy-subdir-files": {baseName + ".find_and_copy", starlarkTypeList, hiddenArgNone},
"find-word-in-list": {"!find-word-in-list", starlarkTypeUnknown, hiddenArgNone}, // internal macro
"filter": {baseName + ".filter", starlarkTypeList, hiddenArgNone},
@@ -1288,8 +1288,21 @@
right: &intLiteralExpr{-1},
isEq: !negate,
}
+ } else if s, ok := maybeString(xValue); ok {
+ if s2, ok := maybeString(xCall.args[0]); ok && s == s2 {
+ return &eqExpr{
+ left: &callExpr{
+ object: xCall.args[1],
+ name: "find",
+ args: []starlarkExpr{xCall.args[0]},
+ returnType: starlarkTypeInt,
+ },
+ right: &intLiteralExpr{-1},
+ isEq: negate,
+ }
+ }
}
- return ctx.newBadExpr(directive, "findstring result can be compared only to empty: %s", xValue)
+ return ctx.newBadExpr(directive, "$(findstring) can only be compared to nothing or its first argument")
}
func (ctx *parseContext) parseCompareStripFuncResult(directive *mkparser.Directive,
diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go
index 78444c9..a1731a2 100644
--- a/mk2rbc/mk2rbc_test.go
+++ b/mk2rbc/mk2rbc_test.go
@@ -633,15 +633,42 @@
desc: "findstring call",
mkname: "product.mk",
in: `
+result := $(findstring a,a b c)
+result := $(findstring b,x y z)
+`,
+ expected: `load("//build/make/core:product_config.rbc", "rblf")
+
+def init(g, handle):
+ cfg = rblf.cfg(handle)
+ _result = rblf.findstring("a", "a b c")
+ _result = rblf.findstring("b", "x y z")
+`,
+ },
+ {
+ desc: "findstring in if statement",
+ mkname: "product.mk",
+ in: `
+ifeq ($(findstring foo,$(PRODUCT_PACKAGES)),)
+endif
ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),)
endif
+ifeq ($(findstring foo,$(PRODUCT_PACKAGES)),foo)
+endif
+ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),foo)
+endif
`,
expected: `load("//build/make/core:product_config.rbc", "rblf")
def init(g, handle):
cfg = rblf.cfg(handle)
+ if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") == -1:
+ pass
if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1:
pass
+ if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1:
+ pass
+ if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") == -1:
+ pass
`,
},
{
diff --git a/rust/test.go b/rust/test.go
index 3eea0ad..250b765 100644
--- a/rust/test.go
+++ b/rust/test.go
@@ -210,6 +210,12 @@
func RustTestFactory() android.Module {
module, _ := NewRustTest(android.HostAndDeviceSupported)
+
+ // NewRustTest will set MultilibBoth true, however the host variant
+ // cannot produce the non-primary target. Therefore, add the
+ // rustTestHostMultilib load hook to set MultilibFirst for the
+ // host target.
+ android.AddLoadHook(module, rustTestHostMultilib)
return module.Init()
}
@@ -236,3 +242,16 @@
func (test *testDecorator) testBinary() bool {
return true
}
+
+func rustTestHostMultilib(ctx android.LoadHookContext) {
+ type props struct {
+ Target struct {
+ Host struct {
+ Compile_multilib *string
+ }
+ }
+ }
+ p := &props{}
+ p.Target.Host.Compile_multilib = proptools.StringPtr("first")
+ ctx.AppendProperties(p)
+}
diff --git a/scripts/build-mainline-modules.sh b/scripts/build-mainline-modules.sh
deleted file mode 100755
index 1e3f6ce..0000000
--- a/scripts/build-mainline-modules.sh
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/bash -e
-
-# Non exhaustive list of modules where we want prebuilts. More can be added as
-# needed.
-MAINLINE_MODULES=(
- com.android.art
- com.android.art.debug
- com.android.art.testing
- com.android.conscrypt
- com.android.i18n
- com.android.os.statsd
- com.android.runtime
- com.android.tzdata
-)
-
-# List of SDKs and module exports we know of.
-MODULES_SDK_AND_EXPORTS=(
- art-module-sdk
- art-module-test-exports
- conscrypt-module-host-exports
- conscrypt-module-sdk
- conscrypt-module-test-exports
- i18n-module-host-exports
- i18n-module-sdk
- i18n-module-test-exports
- platform-mainline-sdk
- platform-mainline-test-exports
- runtime-module-host-exports
- runtime-module-sdk
- statsd-module-sdk
- tzdata-module-test-exports
-)
-
-# List of libraries installed on the platform that are needed for ART chroot
-# testing.
-PLATFORM_LIBRARIES=(
- heapprofd_client_api
- libartpalette-system
- liblog
-)
-
-# We want to create apex modules for all supported architectures.
-PRODUCTS=(
- aosp_arm
- aosp_arm64
- aosp_x86
- aosp_x86_64
-)
-
-if [ ! -e "build/make/core/Makefile" ]; then
- echo "$0 must be run from the top of the tree"
- exit 1
-fi
-
-echo_and_run() {
- echo "$*"
- "$@"
-}
-
-lib_dir() {
- case $1 in
- (aosp_arm|aosp_x86) echo "lib";;
- (aosp_arm64|aosp_x86_64) echo "lib64";;
- esac
-}
-
-# Make sure this build builds from source, regardless of the default.
-export SOONG_CONFIG_art_module_source_build=true
-
-# This script does not intend to handle compressed APEX
-export OVERRIDE_PRODUCT_COMPRESSED_APEX=false
-
-OUT_DIR=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT= get_build_var OUT_DIR)
-DIST_DIR=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT= get_build_var DIST_DIR)
-
-for product in "${PRODUCTS[@]}"; do
- echo_and_run build/soong/soong_ui.bash --make-mode $@ \
- TARGET_PRODUCT=${product} \
- ${MAINLINE_MODULES[@]} \
- ${PLATFORM_LIBRARIES[@]}
-
- PRODUCT_OUT=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT=${product} get_build_var PRODUCT_OUT)
- TARGET_ARCH=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT=${product} get_build_var TARGET_ARCH)
- rm -rf ${DIST_DIR}/${TARGET_ARCH}/
- mkdir -p ${DIST_DIR}/${TARGET_ARCH}/
- for module in "${MAINLINE_MODULES[@]}"; do
- echo_and_run cp ${PWD}/${PRODUCT_OUT}/system/apex/${module}.apex ${DIST_DIR}/${TARGET_ARCH}/
- done
- for library in "${PLATFORM_LIBRARIES[@]}"; do
- libdir=$(lib_dir $product)
- echo_and_run cp ${PWD}/${PRODUCT_OUT}/system/${libdir}/${library}.so ${DIST_DIR}/${TARGET_ARCH}/
- done
-done
-
-# We use force building LLVM components flag (even though we actually don't
-# compile them) because we don't have bionic host prebuilts
-# for them.
-export FORCE_BUILD_LLVM_COMPONENTS=true
-
-# Create multi-archs SDKs in a different out directory. The multi-arch script
-# uses Soong in --soong-only mode which cannot use the same directory as normal
-# mode with make.
-export OUT_DIR=${OUT_DIR}/aml
-echo_and_run build/soong/scripts/build-aml-prebuilts.sh \
- TARGET_PRODUCT=mainline_sdk ${MODULES_SDK_AND_EXPORTS[@]}
-
-rm -rf ${DIST_DIR}/mainline-sdks
-echo_and_run cp -R ${OUT_DIR}/soong/mainline-sdks ${DIST_DIR}
diff --git a/scripts/gen_java_usedby_apex.sh b/scripts/gen_java_usedby_apex.sh
index 0cadb1a..e398541 100755
--- a/scripts/gen_java_usedby_apex.sh
+++ b/scripts/gen_java_usedby_apex.sh
@@ -32,7 +32,7 @@
touch "$out"
echo "<externals>" >> "$out"
for x in "$@"; do
- "$dexdeps" "$x" >> "$out" || true
+ "$dexdeps" "$x" >> "$out" || echo "</external>" >> "$out"
done
echo "</externals>" >> "$out"
}