Merge "Allowlist ndk STL dependencies" into main
diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go
index 5cdf5b6..ed0961b 100644
--- a/aconfig/aconfig_declarations.go
+++ b/aconfig/aconfig_declarations.go
@@ -15,16 +15,18 @@
package aconfig
import (
- "android/soong/android"
"fmt"
"strings"
+ "android/soong/android"
+ "android/soong/bazel"
"github.com/google/blueprint"
)
type DeclarationsModule struct {
android.ModuleBase
android.DefaultableModuleBase
+ android.BazelModuleBase
// Properties for "aconfig_declarations"
properties struct {
@@ -47,8 +49,7 @@
android.InitAndroidModule(module)
android.InitDefaultableModule(module)
module.AddProperties(&module.properties)
- // TODO: bp2build
- //android.InitBazelModule(module)
+ android.InitBazelModule(module)
return module
}
@@ -73,7 +74,9 @@
// RELEASE_ACONFIG_VALUE_SETS, and add any aconfig_values that
// match our package.
valuesFromConfig := ctx.Config().ReleaseAconfigValueSets()
- ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig...)
+ if valuesFromConfig != "" {
+ ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig)
+ }
}
func (module *DeclarationsModule) OutputFiles(tag string) (android.Paths, error) {
@@ -159,3 +162,26 @@
})
}
+
+type bazelAconfigDeclarationsAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Package string
+}
+
+func (module *DeclarationsModule) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ if ctx.ModuleType() != "aconfig_declarations" {
+ return
+ }
+ srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, module.properties.Srcs))
+
+ attrs := bazelAconfigDeclarationsAttributes{
+ Srcs: srcs,
+ Package: module.properties.Package,
+ }
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "aconfig_declarations",
+ Bzl_load_location: "//build/bazel/rules/aconfig:aconfig_declarations.bzl",
+ }
+
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs)
+}
diff --git a/aconfig/aconfig_value_set.go b/aconfig/aconfig_value_set.go
index 252908f..af9ddd3 100644
--- a/aconfig/aconfig_value_set.go
+++ b/aconfig/aconfig_value_set.go
@@ -16,6 +16,7 @@
import (
"android/soong/android"
+ "android/soong/bazel"
"github.com/google/blueprint"
)
@@ -23,6 +24,7 @@
type ValueSetModule struct {
android.ModuleBase
android.DefaultableModuleBase
+ android.BazelModuleBase
properties struct {
// aconfig_values modules
@@ -36,8 +38,7 @@
android.InitAndroidModule(module)
android.InitDefaultableModule(module)
module.AddProperties(&module.properties)
- // TODO: bp2build
- //android.InitBazelModule(module)
+ android.InitBazelModule(module)
return module
}
@@ -90,3 +91,23 @@
AvailablePackages: packages,
})
}
+
+type bazelAconfigValueSetAttributes struct {
+ Values bazel.LabelListAttribute
+}
+
+func (module *ValueSetModule) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ if ctx.ModuleType() != "aconfig_value_set" {
+ return
+ }
+
+ attrs := bazelAconfigValueSetAttributes{
+ Values: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, module.properties.Values)),
+ }
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "aconfig_value_set",
+ Bzl_load_location: "//build/bazel/rules/aconfig:aconfig_value_set.bzl",
+ }
+
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs)
+}
diff --git a/aconfig/aconfig_values.go b/aconfig/aconfig_values.go
index 91f1c90..0aa6a72 100644
--- a/aconfig/aconfig_values.go
+++ b/aconfig/aconfig_values.go
@@ -16,6 +16,7 @@
import (
"android/soong/android"
+ "android/soong/bazel"
"github.com/google/blueprint"
)
@@ -23,6 +24,7 @@
type ValuesModule struct {
android.ModuleBase
android.DefaultableModuleBase
+ android.BazelModuleBase
properties struct {
// aconfig files, relative to this Android.bp file
@@ -39,8 +41,7 @@
android.InitAndroidModule(module)
android.InitDefaultableModule(module)
module.AddProperties(&module.properties)
- // TODO: bp2build
- //android.InitBazelModule(module)
+ android.InitBazelModule(module)
return module
}
@@ -68,3 +69,27 @@
}
ctx.SetProvider(valuesProviderKey, providerData)
}
+
+type bazelAconfigValuesAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Package string
+}
+
+func (module *ValuesModule) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ if ctx.ModuleType() != "aconfig_values" {
+ return
+ }
+
+ srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, module.properties.Srcs))
+
+ attrs := bazelAconfigValuesAttributes{
+ Srcs: srcs,
+ Package: module.properties.Package,
+ }
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "aconfig_values",
+ Bzl_load_location: "//build/bazel/rules/aconfig:aconfig_values.bzl",
+ }
+
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs)
+}
diff --git a/aconfig/init.go b/aconfig/init.go
index 797388d..c14f8ae 100644
--- a/aconfig/init.go
+++ b/aconfig/init.go
@@ -97,12 +97,12 @@
)
func init() {
- registerBuildComponents(android.InitRegistrationContext)
+ RegisterBuildComponents(android.InitRegistrationContext)
pctx.HostBinToolVariable("aconfig", "aconfig")
pctx.HostBinToolVariable("soong_zip", "soong_zip")
}
-func registerBuildComponents(ctx android.RegistrationContext) {
+func RegisterBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
ctx.RegisterModuleType("aconfig_values", ValuesFactory)
ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
diff --git a/aconfig/testing.go b/aconfig/testing.go
index 60cefeb..f6489ec 100644
--- a/aconfig/testing.go
+++ b/aconfig/testing.go
@@ -20,7 +20,7 @@
"android/soong/android"
)
-var PrepareForTestWithAconfigBuildComponents = android.FixtureRegisterWithContext(registerBuildComponents)
+var PrepareForTestWithAconfigBuildComponents = android.FixtureRegisterWithContext(RegisterBuildComponents)
func runTest(t *testing.T, errorHandler android.FixtureErrorHandler, bp string) *android.TestResult {
return android.GroupFixturePreparers(PrepareForTestWithAconfigBuildComponents).
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 732028c..bfc9b9e 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -910,6 +910,7 @@
"aidl_interface_headers",
"bpf",
"combined_apis",
+ "droiddoc_exported_dir",
"license",
"linker_config",
"java_import",
@@ -917,6 +918,9 @@
"java_sdk_library",
"sysprop_library",
"xsd_config",
+ "aconfig_declarations",
+ "aconfig_values",
+ "aconfig_value_set",
}
// Add the names of modules that bp2build should never convert, if it is
diff --git a/android/config.go b/android/config.go
index 645a263..445c6cd 100644
--- a/android/config.go
+++ b/android/config.go
@@ -197,9 +197,22 @@
return c.config.productVariables.ReleaseVersion
}
-// The flag values files passed to aconfig, derived from RELEASE_VERSION
-func (c Config) ReleaseAconfigValueSets() []string {
- return c.config.productVariables.ReleaseAconfigValueSets
+// The aconfig value set passed to aconfig, derived from RELEASE_VERSION
+func (c Config) ReleaseAconfigValueSets() string {
+ // This logic to handle both Soong module name and bazel target is temporary in order to
+ // provide backward compatibility where aosp and vendor/google both have the release
+ // aconfig value set but can't be updated at the same time to use bazel target
+ value := strings.Split(c.config.productVariables.ReleaseAconfigValueSets, ":")
+ value_len := len(value)
+ if value_len > 2 {
+ // This shouldn't happen as this should be either a module name or a bazel target path.
+ panic(fmt.Errorf("config file: invalid value for release aconfig value sets: %s",
+ c.config.productVariables.ReleaseAconfigValueSets))
+ }
+ if value_len > 0 {
+ return value[value_len-1]
+ }
+ return ""
}
// The flag default permission value passed to aconfig
diff --git a/android/fixture.go b/android/fixture.go
index 6660afd..5ad47e8 100644
--- a/android/fixture.go
+++ b/android/fixture.go
@@ -275,6 +275,15 @@
})
}
+// Sync the mock filesystem with the current config, then modify the context,
+// This allows context modification that requires filesystem access.
+func FixtureModifyContextWithMockFs(mutator func(ctx *TestContext)) FixturePreparer {
+ return newSimpleFixturePreparer(func(f *fixture) {
+ f.config.mockFileSystem("", f.mockFS)
+ mutator(f.ctx)
+ })
+}
+
func FixtureRegisterWithContext(registeringFunc func(ctx RegistrationContext)) FixturePreparer {
return FixtureModifyContext(func(ctx *TestContext) { registeringFunc(ctx) })
}
diff --git a/android/register.go b/android/register.go
index df97c75..f1c2986 100644
--- a/android/register.go
+++ b/android/register.go
@@ -15,9 +15,13 @@
package android
import (
+ "bufio"
"fmt"
+ "path/filepath"
"reflect"
+ "regexp"
+ "android/soong/shared"
"github.com/google/blueprint"
)
@@ -197,6 +201,56 @@
RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators)
}
+// RegisterExistingBazelTargets reads Bazel BUILD.bazel and BUILD files under
+// the workspace, and returns a map containing names of Bazel targets defined in
+// these BUILD files.
+// For example, maps "//foo/bar" to ["baz", "qux"] if `//foo/bar:{baz,qux}` exist.
+func (c *Context) RegisterExistingBazelTargets(topDir string, existingBazelFiles []string) error {
+ result := map[string][]string{}
+
+ // Search for instances of `name = "$NAME"` (with arbitrary spacing).
+ targetNameRegex := regexp.MustCompile(`(?m)^\s*name\s*=\s*\"([^\"]+)\"`)
+
+ parseBuildFile := func(path string) error {
+ fullPath := shared.JoinPath(topDir, path)
+ sourceDir := filepath.Dir(path)
+
+ fileInfo, err := c.Config().fs.Stat(fullPath)
+ if err != nil {
+ return fmt.Errorf("Error accessing Bazel file '%s': %s", path, err)
+ }
+ if !fileInfo.IsDir() &&
+ (fileInfo.Name() == "BUILD" || fileInfo.Name() == "BUILD.bazel") {
+ f, err := c.Config().fs.Open(fullPath)
+ if err != nil {
+ return fmt.Errorf("Error reading Bazel file '%s': %s", path, err)
+ }
+ defer f.Close()
+ scanner := bufio.NewScanner(f)
+ for scanner.Scan() {
+ line := scanner.Text()
+ matches := targetNameRegex.FindAllStringSubmatch(line, -1)
+ for _, match := range matches {
+ result[sourceDir] = append(result[sourceDir], match[1])
+ }
+ }
+ }
+ return nil
+ }
+
+ for _, path := range existingBazelFiles {
+ if !c.Config().Bp2buildPackageConfig.ShouldKeepExistingBuildFileForDir(filepath.Dir(path)) {
+ continue
+ }
+ err := parseBuildFile(path)
+ if err != nil {
+ return err
+ }
+ }
+ c.Config().SetBazelBuildFileTargets(result)
+ return nil
+}
+
// Register the pipeline of singletons, module types, and mutators for
// generating build.ninja and other files for Kati, from Android.bp files.
func (ctx *Context) Register() {
diff --git a/android/variable.go b/android/variable.go
index 524cdf7..6d9cc4b 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -476,8 +476,8 @@
ProductBrand string `json:",omitempty"`
BuildVersionTags []string `json:",omitempty"`
- ReleaseVersion string `json:",omitempty"`
- ReleaseAconfigValueSets []string `json:",omitempty"`
+ ReleaseVersion string `json:",omitempty"`
+ ReleaseAconfigValueSets string `json:",omitempty"`
ReleaseAconfigFlagDefaultPermission string `json:",omitempty"`
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index b675e5e..b321b38 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -62,6 +62,8 @@
"cc_test_conversion_test.go",
"cc_yasm_conversion_test.go",
"conversion_test.go",
+ "droiddoc_exported_dir_conversion_test.go",
+ "fdo_profile_conversion_test.go",
"filegroup_conversion_test.go",
"genrule_conversion_test.go",
"gensrcs_conversion_test.go",
diff --git a/bp2build/aconfig_conversion_test.go b/bp2build/aconfig_conversion_test.go
new file mode 100644
index 0000000..ddb62f7
--- /dev/null
+++ b/bp2build/aconfig_conversion_test.go
@@ -0,0 +1,92 @@
+// Copyright 2023 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/aconfig"
+ "android/soong/android"
+)
+
+func registerAconfigModuleTypes(ctx android.RegistrationContext) {
+ aconfig.RegisterBuildComponents(ctx)
+}
+
+func TestAconfigDeclarations(t *testing.T) {
+ bp := `
+ aconfig_declarations {
+ name: "foo",
+ srcs: [
+ "foo1.aconfig",
+ "test/foo2.aconfig",
+ ],
+ package: "com.android.foo",
+ }
+ `
+ expectedBazelTarget := MakeBazelTargetNoRestrictions(
+ "aconfig_declarations",
+ "foo",
+ AttrNameToString{
+ "srcs": `[
+ "foo1.aconfig",
+ "test/foo2.aconfig",
+ ]`,
+ "package": `"com.android.foo"`,
+ },
+ )
+ RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
+ Blueprint: bp,
+ ExpectedBazelTargets: []string{expectedBazelTarget},
+ })
+}
+
+func TestAconfigValues(t *testing.T) {
+ bp := `
+ aconfig_values {
+ name: "foo",
+ srcs: [
+ "foo1.textproto",
+ ],
+ package: "com.android.foo",
+ }
+ aconfig_value_set {
+ name: "bar",
+ values: [
+ "foo"
+ ]
+ }
+ `
+ expectedBazelTargets := []string{
+ MakeBazelTargetNoRestrictions(
+ "aconfig_values",
+ "foo",
+ AttrNameToString{
+ "srcs": `["foo1.textproto"]`,
+ "package": `"com.android.foo"`,
+ },
+ ),
+ MakeBazelTargetNoRestrictions(
+ "aconfig_value_set",
+ "bar",
+ AttrNameToString{
+ "values": `[":foo"]`,
+ },
+ )}
+ RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
+ Blueprint: bp,
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+}
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index 5aed4ad..d6db677 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -1315,6 +1315,7 @@
"tags": `["apex_available=myapex"]`,
}),
MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{
+ "api_surface": `"module-libapi"`,
"soname": `"foo.so"`,
"source_library_label": `"//:foo"`,
"symbol_file": `"foo.map.txt"`,
diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go
index 50b8358..3622e67 100644
--- a/bp2build/bp2build_product_config.go
+++ b/bp2build/bp2build_product_config.go
@@ -285,6 +285,12 @@
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_name=%s\n", proptools.String(productVariables.Platform_version_name)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_brand=%s\n", productVariables.ProductBrand))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_manufacturer=%s\n", productVariables.ProductManufacturer))
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_flag_default_permission=%s\n", productVariables.ReleaseAconfigFlagDefaultPermission))
+ // Empty string can't be used as label_flag on the bazel side
+ if len(productVariables.ReleaseAconfigValueSets) > 0 {
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_aconfig_value_sets=%s\n", productVariables.ReleaseAconfigValueSets))
+ }
+ result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:release_version=%s\n", productVariables.ReleaseVersion))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_version=%d\n", platform_sdk_version))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:safestack=%t\n", proptools.Bool(productVariables.Safestack)))
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:target_build_variant=%s\n", targetBuildVariant))
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index 4897566..cefa171 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -1926,6 +1926,69 @@
android.AssertStringEquals(t, "Print the common value if all keys in an axis have the same value", `[":libfoo.impl"]`, actual)
}
+func TestAlreadyPresentBuildTarget(t *testing.T) {
+ bp := `
+ custom {
+ name: "foo",
+ }
+ custom {
+ name: "bar",
+ }
+ `
+ alreadyPresentBuildFile :=
+ MakeBazelTarget(
+ "custom",
+ "foo",
+ AttrNameToString{},
+ )
+ expectedBazelTargets := []string{
+ MakeBazelTarget(
+ "custom",
+ "bar",
+ AttrNameToString{},
+ ),
+ }
+ registerCustomModule := func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("custom", customModuleFactoryHostAndDevice)
+ }
+ RunBp2BuildTestCase(t, registerCustomModule, Bp2buildTestCase{
+ AlreadyExistingBuildContents: alreadyPresentBuildFile,
+ Blueprint: bp,
+ ExpectedBazelTargets: expectedBazelTargets,
+ Description: "Not duplicating work for an already-present BUILD target.",
+ })
+}
+
+// Verifies that if a module is defined in pkg1/Android.bp, that a target present
+// in pkg2/BUILD.bazel does not result in the module being labeled "already defined
+// in a BUILD file".
+func TestBuildTargetPresentOtherDirectory(t *testing.T) {
+ bp := `
+ custom {
+ name: "foo",
+ }
+ `
+ expectedBazelTargets := []string{
+ MakeBazelTarget(
+ "custom",
+ "foo",
+ AttrNameToString{},
+ ),
+ }
+ registerCustomModule := func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("custom", customModuleFactoryHostAndDevice)
+ }
+ RunBp2BuildTestCase(t, registerCustomModule, Bp2buildTestCase{
+ KeepBuildFileForDirs: []string{"other_pkg"},
+ Filesystem: map[string]string{
+ "other_pkg/BUILD.bazel": MakeBazelTarget("custom", "foo", AttrNameToString{}),
+ },
+ Blueprint: bp,
+ ExpectedBazelTargets: expectedBazelTargets,
+ Description: "Not treating a BUILD target as the bazel definition for a module in another package",
+ })
+}
+
// If CommonAttributes.Dir is set, the bazel target should be created in that dir
func TestCreateBazelTargetInDifferentDir(t *testing.T) {
t.Parallel()
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 7af788e..3957ff7 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -2809,6 +2809,7 @@
"stubs_symbol_file": `"a.map.txt"`,
})
expectedBazelTargets = append(expectedBazelTargets, makeCcStubSuiteTargets("a", AttrNameToString{
+ "api_surface": `"module-libapi"`,
"soname": `"a.so"`,
"source_library_label": `"//foo/bar:a"`,
"stubs_symbol_file": `"a.map.txt"`,
@@ -3639,8 +3640,8 @@
{
description: "cc_library with afdo enabled and existing profile",
filesystem: map[string]string{
- "vendor/google_data/pgo_profile/sampling/BUILD": "",
- "vendor/google_data/pgo_profile/sampling/foo.afdo": "",
+ "vendor/google_data/pgo_profile/sampling/Android.bp": "",
+ "vendor/google_data/pgo_profile/sampling/foo.afdo": "",
},
expectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}),
@@ -3652,8 +3653,8 @@
{
description: "cc_library with afdo enabled and existing profile in AOSP",
filesystem: map[string]string{
- "toolchain/pgo-profiles/sampling/BUILD": "",
- "toolchain/pgo-profiles/sampling/foo.afdo": "",
+ "toolchain/pgo-profiles/sampling/Android.bp": "",
+ "toolchain/pgo-profiles/sampling/foo.afdo": "",
},
expectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}),
@@ -3665,8 +3666,8 @@
{
description: "cc_library with afdo enabled but profile filename doesn't match with module name",
filesystem: map[string]string{
- "toolchain/pgo-profiles/sampling/BUILD": "",
- "toolchain/pgo-profiles/sampling/bar.afdo": "",
+ "toolchain/pgo-profiles/sampling/Android.bp": "",
+ "toolchain/pgo-profiles/sampling/bar.afdo": "",
},
expectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}),
diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go
index 44b9722..921e6e3 100644
--- a/bp2build/cc_library_shared_conversion_test.go
+++ b/bp2build/cc_library_shared_conversion_test.go
@@ -218,12 +218,12 @@
func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared os-specific shared_libs",
- Filesystem: map[string]string{},
+ StubbedBuildDefinitions: []string{"shared_dep"},
+ Description: "cc_library_shared os-specific shared_libs",
+ Filesystem: map[string]string{},
Blueprint: soongCcLibrarySharedPreamble + `
cc_library_shared {
name: "shared_dep",
- bazel_module: { bp2build_available: false },
}
cc_library_shared {
name: "foo_shared",
@@ -243,20 +243,18 @@
func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) {
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared base, arch, and os-specific shared_libs",
- Filesystem: map[string]string{},
+ StubbedBuildDefinitions: []string{"shared_dep", "shared_dep2", "shared_dep3"},
+ Description: "cc_library_shared base, arch, and os-specific shared_libs",
+ Filesystem: map[string]string{},
Blueprint: soongCcLibrarySharedPreamble + `
cc_library_shared {
name: "shared_dep",
- bazel_module: { bp2build_available: false },
}
cc_library_shared {
name: "shared_dep2",
- bazel_module: { bp2build_available: false },
}
cc_library_shared {
name: "shared_dep3",
- bazel_module: { bp2build_available: false },
}
cc_library_shared {
name: "foo_shared",
@@ -543,6 +541,7 @@
},
Blueprint: soongCcLibraryPreamble,
ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
+ "api_surface": `"module-libapi"`,
"soname": `"a.so"`,
"source_library_label": `"//foo/bar:a"`,
"stubs_symbol_file": `"a.map.txt"`,
@@ -1442,6 +1441,7 @@
`,
ExpectedBazelTargets: []string{
makeCcStubSuiteTargets("a", AttrNameToString{
+ "api_surface": `"module-libapi"`,
"soname": `"a.so"`,
"source_library_label": `"//:a"`,
"stubs_symbol_file": `"a.map.txt"`,
@@ -1456,6 +1456,7 @@
"stubs_symbol_file": `"a.map.txt"`,
}),
makeCcStubSuiteTargets("b", AttrNameToString{
+ "api_surface": `"module-libapi"`,
"soname": `"b.so"`,
"source_library_label": `"//:b"`,
"stubs_symbol_file": `"b.map.txt"`,
diff --git a/bp2build/droiddoc_exported_dir_conversion_test.go b/bp2build/droiddoc_exported_dir_conversion_test.go
new file mode 100644
index 0000000..dee67f4
--- /dev/null
+++ b/bp2build/droiddoc_exported_dir_conversion_test.go
@@ -0,0 +1,60 @@
+// Copyright 2023 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 (
+ "regexp"
+ "testing"
+
+ "android/soong/java"
+)
+
+func TestDroiddocExportedDir(t *testing.T) {
+ bp := `
+ droiddoc_exported_dir {
+ name: "test-module",
+ path: "docs",
+ }
+ `
+ p := regexp.MustCompile(`\t*\|`)
+ dedent := func(s string) string {
+ return p.ReplaceAllString(s, "")
+ }
+ expectedBazelTargets := []string{
+ MakeBazelTargetNoRestrictions(
+ "droiddoc_exported_dir",
+ "test-module",
+ AttrNameToString{
+ "dir": `"docs"`,
+ "srcs": dedent(`[
+ | "docs/android/1.txt",
+ | "docs/android/nested-1/2.txt",
+ | "//docs/android/nested-2:3.txt",
+ | "//docs/android/nested-2:Android.bp",
+ | ]`),
+ }),
+ //note we are not excluding Android.bp files from subpackages for now
+ }
+ RunBp2BuildTestCase(t, java.RegisterDocsBuildComponents, Bp2buildTestCase{
+ Blueprint: bp,
+ ExpectedBazelTargets: expectedBazelTargets,
+ Filesystem: map[string]string{
+ "docs/android/1.txt": "",
+ "docs/android/nested-1/2.txt": "",
+ "docs/android/nested-2/Android.bp": "",
+ "docs/android/nested-2/3.txt": "",
+ },
+ })
+}
diff --git a/bp2build/fdo_profile_conversion_test.go b/bp2build/fdo_profile_conversion_test.go
new file mode 100644
index 0000000..4d04283
--- /dev/null
+++ b/bp2build/fdo_profile_conversion_test.go
@@ -0,0 +1,85 @@
+// Copyright 2023 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"
+)
+
+func runFdoProfileTestCase(t *testing.T, tc Bp2buildTestCase) {
+ t.Helper()
+ (&tc).ModuleTypeUnderTest = "fdo_profile"
+ (&tc).ModuleTypeUnderTestFactory = cc.FdoProfileFactory
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
+}
+
+func TestFdoProfile(t *testing.T) {
+ testcases := []struct {
+ name string
+ bp string
+ expectedBazelAttrs AttrNameToString
+ }{
+ {
+ name: "fdo_profile with arch-specific profiles",
+ bp: `
+fdo_profile {
+ name: "foo",
+ arch: {
+ arm: {
+ profile: "foo_arm.afdo",
+ },
+ arm64: {
+ profile: "foo_arm64.afdo",
+ }
+ }
+}`,
+ expectedBazelAttrs: AttrNameToString{
+ "profile": `select({
+ "//build/bazel/platforms/arch:arm": "foo_arm.afdo",
+ "//build/bazel/platforms/arch:arm64": "foo_arm64.afdo",
+ "//conditions:default": None,
+ })`,
+ },
+ },
+ {
+ name: "fdo_profile with arch-agnostic profile",
+ bp: `
+fdo_profile {
+ name: "foo",
+ profile: "foo.afdo",
+}`,
+ expectedBazelAttrs: AttrNameToString{
+ "profile": `"foo.afdo"`,
+ },
+ },
+ }
+
+ for _, test := range testcases {
+ t.Run(test.name, func(t *testing.T) {
+ expectedBazelTargets := []string{
+ // TODO(b/276287371): Add device-only restriction back to fdo_profile targets
+ MakeBazelTargetNoRestrictions("fdo_profile", "foo", test.expectedBazelAttrs),
+ }
+ runFdoProfileTestCase(t, Bp2buildTestCase{
+ Description: test.name,
+ Blueprint: test.bp,
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+ })
+ }
+}
diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go
index 8c78217..3260b1e 100644
--- a/bp2build/java_library_conversion_test.go
+++ b/bp2build/java_library_conversion_test.go
@@ -15,7 +15,6 @@
package bp2build
import (
- "fmt"
"testing"
"android/soong/android"
@@ -143,26 +142,6 @@
})
}
-func TestJavaLibraryFailsToConvertLibsWithNoSrcs(t *testing.T) {
- runJavaLibraryTestCase(t, Bp2buildTestCase{
- ExpectedErr: fmt.Errorf("Module has direct dependencies but no sources. Bazel will not allow this."),
- Blueprint: `java_library {
- name: "java-lib-1",
- libs: ["java-lib-2"],
- sdk_version: "current",
- bazel_module: { bp2build_available: true },
-}
-
-java_library {
- name: "java-lib-2",
- srcs: ["a.java"],
- sdk_version: "current",
- bazel_module: { bp2build_available: false },
-}`,
- ExpectedBazelTargets: []string{},
- })
-}
-
func TestJavaLibraryPlugins(t *testing.T) {
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
Blueprint: `java_library {
@@ -869,6 +848,30 @@
})
}
+func TestJavaLibraryLibsWithNoSrcs(t *testing.T) {
+ runJavaLibraryTestCase(t, Bp2buildTestCase{
+ Description: "java_library that has libs but no srcs",
+ Blueprint: `java_library {
+ name: "java-lib-1",
+ libs: ["java-lib-2"],
+ sdk_version: "current",
+ bazel_module: { bp2build_available: true },
+}
+
+java_library{
+ name: "java-lib-2",
+ bazel_module: { bp2build_available: false },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
+ "sdk_version": `"current"`,
+ }),
+ MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
+ },
+ })
+}
+
func TestJavaLibraryArchVariantDeps(t *testing.T) {
runJavaLibraryTestCase(t, Bp2buildTestCase{
Description: "java_library with arch variant libs",
diff --git a/bp2build/java_proto_conversion_test.go b/bp2build/java_proto_conversion_test.go
index dfef697..b254710 100644
--- a/bp2build/java_proto_conversion_test.go
+++ b/bp2build/java_proto_conversion_test.go
@@ -167,10 +167,7 @@
"sdk_version": `"current"`,
}),
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
- "exports": `[
- ":java-protos_java_proto_lite",
- ":java-lib-neverlink",
- ]`,
+ "exports": `[":java-protos_java_proto_lite"]`,
"java_version": `"7"`,
"sdk_version": `"current"`,
}),
diff --git a/bp2build/testing.go b/bp2build/testing.go
index 0e7ef44..82d40cf 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -21,6 +21,7 @@
import (
"fmt"
+ "path/filepath"
"sort"
"strings"
"testing"
@@ -82,7 +83,16 @@
// ExpectedBazelTargets compares the BazelTargets generated in `Dir` (if not empty).
// Otherwise, it checks the BazelTargets generated by `Blueprint` in the root directory.
ExpectedBazelTargets []string
- Filesystem map[string]string
+ // AlreadyExistingBuildContents, if non-empty, simulates an already-present source BUILD file
+ // in the directory under test. The BUILD file has the given contents. This BUILD file
+ // will also be treated as "BUILD file to keep" by the simulated bp2build environment.
+ AlreadyExistingBuildContents string
+ // StubbedBuildDefinitions, if non-empty, adds stub definitions to an already-present source
+ // BUILD file in the directory under test, for each target name given. These stub definitions
+ // are added to the BUILD file given in AlreadyExistingBuildContents, if it is set.
+ StubbedBuildDefinitions []string
+
+ Filesystem map[string]string
// Dir sets the directory which will be compared against the targets in ExpectedBazelTargets.
// This should used in conjunction with the Filesystem property to check for targets
// generated from a directory that is not the root.
@@ -110,11 +120,31 @@
func runBp2BuildTestCaseWithSetup(t *testing.T, extraPreparer android.FixturePreparer, tc Bp2buildTestCase) {
t.Helper()
- dir := "."
+ checkDir := "."
+ if tc.Dir != "" {
+ checkDir = tc.Dir
+ }
+ keepExistingBuildDirs := tc.KeepBuildFileForDirs
+ buildFilesToParse := []string{}
filesystem := make(map[string][]byte)
for f, content := range tc.Filesystem {
filesystem[f] = []byte(content)
}
+ alreadyExistingBuildContents := tc.AlreadyExistingBuildContents
+ if len(tc.StubbedBuildDefinitions) > 0 {
+ for _, targetName := range tc.StubbedBuildDefinitions {
+ alreadyExistingBuildContents += MakeBazelTarget(
+ "bp2build_test_stub",
+ targetName,
+ AttrNameToString{})
+ }
+ }
+ if len(alreadyExistingBuildContents) > 0 {
+ buildFilePath := filepath.Join(checkDir, "BUILD")
+ filesystem[buildFilePath] = []byte(alreadyExistingBuildContents)
+ keepExistingBuildDirs = append(keepExistingBuildDirs, checkDir)
+ buildFilesToParse = append(buildFilesToParse, buildFilePath)
+ }
preparers := []android.FixturePreparer{
extraPreparer,
@@ -123,7 +153,7 @@
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
ctx.RegisterModuleType(tc.ModuleTypeUnderTest, tc.ModuleTypeUnderTestFactory)
}),
- android.FixtureModifyContext(func(ctx *android.TestContext) {
+ android.FixtureModifyContextWithMockFs(func(ctx *android.TestContext) {
// A default configuration for tests to not have to specify bp2build_available on top level
// targets.
bp2buildConfig := android.NewBp2BuildAllowlist().SetDefaultConfig(
@@ -131,7 +161,7 @@
android.Bp2BuildTopLevel: allowlists.Bp2BuildDefaultTrueRecursively,
},
)
- for _, f := range tc.KeepBuildFileForDirs {
+ for _, f := range keepExistingBuildDirs {
bp2buildConfig.SetKeepExistingBuildFile(map[string]bool{
f: /*recursive=*/ false,
})
@@ -141,6 +171,10 @@
// from cloning modules to their original state after mutators run. This
// would lose some data intentionally set by these mutators.
ctx.SkipCloneModulesAfterMutators = true
+ err := ctx.RegisterExistingBazelTargets(".", buildFilesToParse)
+ if err != nil {
+ t.Errorf("error parsing build files in test setup: %s", err)
+ }
}),
android.FixtureModifyEnv(func(env map[string]string) {
if tc.UnconvertedDepsMode == errorModulesUnconvertedDeps {
@@ -159,10 +193,6 @@
return
}
- checkDir := dir
- if tc.Dir != "" {
- checkDir = tc.Dir
- }
expectedTargets := map[string][]string{
checkDir: tc.ExpectedBazelTargets,
}
@@ -644,6 +674,7 @@
return ""
}
STUB_SUITE_ATTRS := map[string]string{
+ "api_surface": "api_surface",
"stubs_symbol_file": "symbol_file",
"stubs_versions": "versions",
"soname": "soname",
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 039a3cf..ce8c96d 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -1000,6 +1000,8 @@
if module.afdo != nil && module.afdo.Properties.Afdo {
fdoProfileDep := bp2buildFdoProfile(ctx, module)
if fdoProfileDep != nil {
+ // TODO(b/276287371): Only set fdo_profile for android platform
+ // https://cs.android.com/android/platform/superproject/main/+/main:build/soong/cc/afdo.go;l=105;drc=2dbe160d1af445de32725098570ec594e3944fc5
(&compilerAttrs).fdoProfile.SetValue(*fdoProfileDep)
}
}
@@ -1109,22 +1111,15 @@
ctx android.Bp2buildMutatorContext,
m *Module,
) *bazel.Label {
+ // TODO(b/267229066): Convert to afdo boolean attribute and let Bazel handles finding
+ // fdo_profile target from AfdoProfiles product var
for _, project := range globalAfdoProfileProjects {
- // Ensure handcrafted BUILD file exists in the project
- BUILDPath := android.ExistentPathForSource(ctx, project, "BUILD")
- if BUILDPath.Valid() {
- // We handcraft a BUILD file with fdo_profile targets that use the existing profiles in the project
- // This implementation is assuming that every afdo profile in globalAfdoProfileProjects already has
- // an associated fdo_profile target declared in the same package.
+ // Ensure it's a Soong package
+ bpPath := android.ExistentPathForSource(ctx, project, "Android.bp")
+ if bpPath.Valid() {
// TODO(b/260714900): Handle arch-specific afdo profiles (e.g. `<module-name>-arm<64>.afdo`)
path := android.ExistentPathForSource(ctx, project, m.Name()+".afdo")
if path.Valid() {
- // FIXME: Some profiles only exist internally and are not released to AOSP.
- // When generated BUILD files are checked in, we'll run into merge conflict.
- // The cc_library_shared target in AOSP won't have reference to an fdo_profile target because
- // the profile doesn't exist. Internally, the same cc_library_shared target will
- // have reference to the fdo_profile.
- // For more context, see b/258682955#comment2
fdoProfileLabel := "//" + strings.TrimSuffix(project, "/") + ":" + m.Name()
return &bazel.Label{
Label: fdoProfileLabel,
diff --git a/cc/fdo_profile.go b/cc/fdo_profile.go
index 7fbe719..d61af7e 100644
--- a/cc/fdo_profile.go
+++ b/cc/fdo_profile.go
@@ -16,8 +16,10 @@
import (
"android/soong/android"
+ "android/soong/bazel"
"github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
)
func init() {
@@ -25,11 +27,12 @@
}
func RegisterFdoProfileBuildComponents(ctx android.RegistrationContext) {
- ctx.RegisterModuleType("fdo_profile", fdoProfileFactory)
+ ctx.RegisterModuleType("fdo_profile", FdoProfileFactory)
}
type fdoProfile struct {
android.ModuleBase
+ android.BazelModuleBase
properties fdoProfileProperties
}
@@ -38,6 +41,49 @@
Profile *string `android:"arch_variant"`
}
+type bazelFdoProfileAttributes struct {
+ Profile bazel.StringAttribute
+}
+
+func (fp *fdoProfile) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ var profileAttr bazel.StringAttribute
+
+ archVariantProps := fp.GetArchVariantProperties(ctx, &fdoProfileProperties{})
+ for axis, configToProps := range archVariantProps {
+ for config, _props := range configToProps {
+ if archProps, ok := _props.(*fdoProfileProperties); ok {
+ if axis.String() == "arch" || axis.String() == "no_config" {
+ if archProps.Profile != nil {
+ profileAttr.SetSelectValue(axis, config, archProps.Profile)
+ }
+ }
+ }
+ }
+ }
+
+ // Ideally, cc_library_shared's fdo_profile attr can be a select statement so that we
+ // don't lift the restriction here. However, in cc_library_shared macro, fdo_profile
+ // is used as a string, we need to temporarily lift the host restriction until we can
+ // pass use fdo_profile attr with select statement
+ // https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/cc/cc_library_shared.bzl;l=127;drc=cc01bdfd39857eddbab04ef69ab6db22dcb1858a
+ // TODO(b/276287371): Drop the restriction override after fdo_profile path is handled properly
+ var noRestriction bazel.BoolAttribute
+ noRestriction.SetSelectValue(bazel.NoConfigAxis, "", proptools.BoolPtr(true))
+
+ ctx.CreateBazelTargetModuleWithRestrictions(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "fdo_profile",
+ },
+ android.CommonAttributes{
+ Name: fp.Name(),
+ },
+ &bazelFdoProfileAttributes{
+ Profile: profileAttr,
+ },
+ noRestriction,
+ )
+}
+
// FdoProfileInfo is provided by FdoProfileProvider
type FdoProfileInfo struct {
Path android.Path
@@ -77,9 +123,10 @@
}
}
-func fdoProfileFactory() android.Module {
+func FdoProfileFactory() android.Module {
m := &fdoProfile{}
m.AddProperties(&m.properties)
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibBoth)
+ android.InitBazelModule(m)
return m
}
diff --git a/cc/library.go b/cc/library.go
index 2d4d604..7e0c55a 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -494,6 +494,7 @@
Soname: &soname,
Source_library_label: proptools.StringPtr(m.GetBazelLabel(ctx, m)),
Deps: baseAttributes.deps,
+ Api_surface: proptools.StringPtr("module-libapi"),
}
ctx.CreateBazelTargetModule(stubSuitesProps,
android.CommonAttributes{Name: m.Name() + "_stub_libs"},
@@ -3121,6 +3122,7 @@
Source_library_label *string
Soname *string
Deps bazel.LabelListAttribute
+ Api_surface *string
}
type bazelCcHeaderAbiCheckerAttributes struct {
diff --git a/cc/testing.go b/cc/testing.go
index 24d6b0f..07bee01 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -671,7 +671,7 @@
// PrepareForTestWithFdoProfile registers module types to test with fdo_profile
var PrepareForTestWithFdoProfile = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("soong_namespace", android.NamespaceFactory)
- ctx.RegisterModuleType("fdo_profile", fdoProfileFactory)
+ ctx.RegisterModuleType("fdo_profile", FdoProfileFactory)
})
// TestConfig is the legacy way of creating a test Config for testing cc modules.
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 626f076..d20847b 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -21,7 +21,6 @@
"fmt"
"os"
"path/filepath"
- "regexp"
"strings"
"time"
@@ -617,43 +616,6 @@
return excluded
}
-// buildTargetsByPackage parses Bazel BUILD.bazel and BUILD files under
-// the workspace, and returns a map containing names of Bazel targets defined in
-// these BUILD files.
-// For example, maps "//foo/bar" to ["baz", "qux"] if `//foo/bar:{baz,qux}` exist.
-func buildTargetsByPackage(ctx *android.Context) map[string][]string {
- existingBazelFiles, err := getExistingBazelRelatedFiles(topDir)
- maybeQuit(err, "Error determining existing Bazel-related files")
-
- result := map[string][]string{}
-
- // Search for instances of `name = "$NAME"` (with arbitrary spacing).
- targetNameRegex := regexp.MustCompile(`(?m)^\s*name\s*=\s*\"([^\"]+)\"`)
-
- for _, path := range existingBazelFiles {
- if !ctx.Config().Bp2buildPackageConfig.ShouldKeepExistingBuildFileForDir(filepath.Dir(path)) {
- continue
- }
- fullPath := shared.JoinPath(topDir, path)
- sourceDir := filepath.Dir(path)
- fileInfo, err := os.Stat(fullPath)
- maybeQuit(err, "Error accessing Bazel file '%s'", fullPath)
-
- if !fileInfo.IsDir() &&
- (fileInfo.Name() == "BUILD" || fileInfo.Name() == "BUILD.bazel") {
- // Process this BUILD file.
- buildFileContent, err := os.ReadFile(fullPath)
- maybeQuit(err, "Error reading Bazel file '%s'", fullPath)
-
- matches := targetNameRegex.FindAllStringSubmatch(string(buildFileContent), -1)
- for _, match := range matches {
- result[sourceDir] = append(result[sourceDir], match[1])
- }
- }
- }
- return result
-}
-
// Run Soong in the bp2build mode. This creates a standalone context that registers
// an alternate pipeline of mutators and singletons specifically for generating
// Bazel BUILD files instead of Ninja files.
@@ -662,7 +624,11 @@
ctx.EventHandler.Do("bp2build", func() {
ctx.EventHandler.Do("read_build", func() {
- ctx.Config().SetBazelBuildFileTargets(buildTargetsByPackage(ctx))
+ existingBazelFiles, err := getExistingBazelRelatedFiles(topDir)
+ maybeQuit(err, "Error determining existing Bazel-related files")
+
+ err = ctx.RegisterExistingBazelTargets(topDir, existingBazelFiles)
+ maybeQuit(err, "Error parsing existing Bazel-related files")
})
// Propagate "allow misssing dependencies" bit. This is normally set in
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index 4097e8a..0b542fe 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -289,31 +289,12 @@
}
}
- // Fix up the source tree due to a repo bug where it doesn't remove
- // linkfiles that have been removed
- fixBadDanglingLink(buildCtx, "hardware/qcom/sdm710/Android.bp")
- fixBadDanglingLink(buildCtx, "hardware/qcom/sdm710/Android.mk")
-
// Create a source finder.
f := build.NewSourceFinder(buildCtx, config)
defer f.Shutdown()
build.FindSources(buildCtx, config, f)
}
-func fixBadDanglingLink(ctx build.Context, name string) {
- _, err := os.Lstat(name)
- if err != nil {
- return
- }
- _, err = os.Stat(name)
- if os.IsNotExist(err) {
- err = os.Remove(name)
- if err != nil {
- ctx.Fatalf("Failed to remove dangling link %q: %v", name, err)
- }
- }
-}
-
func dumpVar(ctx build.Context, config build.Config, args []string) {
logAndSymlinkSetup(ctx, config)
flags := flag.NewFlagSet("dumpvar", flag.ExitOnError)
diff --git a/compliance/OWNERS b/compliance/OWNERS
deleted file mode 100644
index f52e201..0000000
--- a/compliance/OWNERS
+++ /dev/null
@@ -1,8 +0,0 @@
-# OSEP Build
-bbadour@google.com
-kanouche@google.com
-napier@google.com
-
-# Open Source Compliance Tools
-rtp@google.com
-austinyuan@google.com
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 3ba3065..fe0643a 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -22,6 +22,7 @@
"github.com/google/blueprint/proptools"
"android/soong/android"
+ "android/soong/bazel"
"android/soong/java/config"
)
@@ -844,6 +845,7 @@
type ExportedDroiddocDir struct {
android.ModuleBase
+ android.BazelModuleBase
properties ExportedDroiddocDirProperties
@@ -856,6 +858,7 @@
module := &ExportedDroiddocDir{}
module.AddProperties(&module.properties)
android.InitAndroidModule(module)
+ android.InitBazelModule(module)
return module
}
@@ -867,6 +870,28 @@
d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
}
+// ConvertWithBp2build implements android.BazelModule.
+func (d *ExportedDroiddocDir) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+ props := bazel.BazelTargetModuleProperties{
+ // Use the native py_library rule.
+ Rule_class: "droiddoc_exported_dir",
+ Bzl_load_location: "//build/bazel/rules/droiddoc:droiddoc_exported_dir.bzl",
+ }
+
+ type BazelAttrs struct {
+ Dir *string
+ Srcs bazel.LabelListAttribute
+ }
+
+ attrs := &BazelAttrs{
+ Dir: proptools.StringPtr(*d.properties.Path),
+ Srcs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, []string{filepath.Join(*d.properties.Path, "**/*")})),
+ }
+
+ ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: d.Name()}, attrs)
+
+}
+
// Defaults
type DocDefaults struct {
android.ModuleBase
diff --git a/java/java.go b/java/java.go
index 270f456..48e13fe 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2886,9 +2886,8 @@
// depending on the module type.
type bp2BuildJavaInfo struct {
// separates dependencies into dynamic dependencies and static dependencies.
- DepLabels *javaDependencyLabels
- hasKotlin bool
- onlyProtoInSrcs bool
+ DepLabels *javaDependencyLabels
+ hasKotlin bool
}
func javaXsdTargetName(xsd android.XsdConfigBp2buildTargets) string {
@@ -2951,9 +2950,6 @@
staticDeps.Append(srcPartitions[xsdSrcPartition])
- _, protoInSrcs := srcPartitions[protoSrcPartition]
- onlyProtoInSrcs := protoInSrcs && len(srcPartitions) == 1
-
if !srcPartitions[logtagSrcPartition].IsEmpty() {
logtagsLibName := m.Name() + "_logtags"
ctx.CreateBazelTargetModule(
@@ -3091,9 +3087,8 @@
}
bp2BuildInfo := &bp2BuildJavaInfo{
- DepLabels: depLabels,
- hasKotlin: hasKotlin,
- onlyProtoInSrcs: onlyProtoInSrcs,
+ DepLabels: depLabels,
+ hasKotlin: hasKotlin,
}
return commonAttrs, bp2BuildInfo, true
@@ -3137,19 +3132,12 @@
if !commonAttrs.Srcs.IsEmpty() {
deps.Append(exports) // we should only append these if there are sources to use them
} else if !deps.IsEmpty() {
- if bp2BuildInfo.onlyProtoInSrcs {
- // java_library does not accept deps when there are no srcs because
- // there is no compilation happening, but it accepts exports.
- // bp2build converts this module to 2 java_libraries + java_xx_proto_library + proto_library
- // the non-empty deps here are not necessary for compiling the protos, in which case
- // they're unnecessary as deps on the java_library as well since they aren't
- // being propagated to any dependencies.
- // so we can put the deps to exports and drop deps here.
- exports.Append(deps)
- deps = bazel.LabelListAttribute{}
- } else {
- ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
- }
+ // java_library does not accept deps when there are no srcs because
+ // there is no compilation happening, but it accepts exports.
+ // The non-empty deps here are unnecessary as deps on the java_library
+ // since they aren't being propagated to any dependencies.
+ // So we can drop deps here.
+ deps = bazel.LabelListAttribute{}
}
var props bazel.BazelTargetModuleProperties
attrs := &javaLibraryAttributes{
diff --git a/rust/config/riscv64_device.go b/rust/config/riscv64_device.go
index e9aa8ef..0a9c61a 100644
--- a/rust/config/riscv64_device.go
+++ b/rust/config/riscv64_device.go
@@ -24,8 +24,12 @@
Riscv64RustFlags = []string{
"-C force-frame-pointers=y",
}
- Riscv64ArchFeatureRustFlags = map[string][]string{"": {}}
- Riscv64LinkFlags = []string{}
+ Riscv64ArchFeatureRustFlags = map[string][]string{
+ "riscv64": {
+ "-C target-feature=+V,+Zba,+Zbb,+Zbs",
+ },
+ }
+ Riscv64LinkFlags = []string{}
Riscv64ArchVariantRustFlags = map[string][]string{"": {}}
)
diff --git a/sh/sh_binary.go b/sh/sh_binary.go
index 00794cd..4fe6fdd 100644
--- a/sh/sh_binary.go
+++ b/sh/sh_binary.go
@@ -190,6 +190,15 @@
return s.outputFilePath
}
+func (s *ShBinary) OutputFiles(tag string) (android.Paths, error) {
+ switch tag {
+ case "":
+ return android.Paths{s.outputFilePath}, nil
+ default:
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
+ }
+}
+
func (s *ShBinary) SubDir() string {
return proptools.String(s.properties.Sub_dir)
}