Merge "Denylist genrules that fail to build with sandboxing" into main
diff --git a/README.md b/README.md
index 22daa95..5e9e04a 100644
--- a/README.md
+++ b/README.md
@@ -648,8 +648,8 @@
SOONG_DELVE=2345 SOONG_DELVE_STEPS='build,modulegraph' m
```
results in only `build` (main build step) and `modulegraph` being run in the debugger.
-The allowed step names are `api_bp2build`, `bp2build_files`, `bp2build_workspace`,
-`build`, `modulegraph`, `queryview`, `soong_docs`.
+The allowed step names are `bp2build_files`, `bp2build_workspace`, `build`,
+`modulegraph`, `queryview`, `soong_docs`.
Note setting or unsetting `SOONG_DELVE` causes a recompilation of `soong_build`. This
is because in order to debug the binary, it needs to be built with debug
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index b7faf34..7077f56 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -324,30 +324,31 @@
"libnativehelper": Bp2BuildDefaultTrueRecursively,
- "packages/apps/DevCamera": Bp2BuildDefaultTrue,
- "packages/apps/HTMLViewer": Bp2BuildDefaultTrue,
- "packages/apps/Protips": Bp2BuildDefaultTrue,
- "packages/apps/SafetyRegulatoryInfo": Bp2BuildDefaultTrue,
- "packages/apps/WallpaperPicker": Bp2BuildDefaultTrue,
- "packages/modules/NeuralNetworks/driver/cache": Bp2BuildDefaultTrueRecursively,
- "packages/modules/StatsD/lib/libstatssocket": Bp2BuildDefaultTrueRecursively,
- "packages/modules/adb": Bp2BuildDefaultTrue,
- "packages/modules/adb/apex": Bp2BuildDefaultTrue,
- "packages/modules/adb/fastdeploy": Bp2BuildDefaultTrue,
- "packages/modules/adb/crypto": Bp2BuildDefaultTrueRecursively,
- "packages/modules/adb/libs": Bp2BuildDefaultTrueRecursively,
- "packages/modules/adb/pairing_auth": Bp2BuildDefaultTrueRecursively,
- "packages/modules/adb/pairing_connection": Bp2BuildDefaultTrueRecursively,
- "packages/modules/adb/proto": Bp2BuildDefaultTrueRecursively,
- "packages/modules/adb/tls": Bp2BuildDefaultTrueRecursively,
- "packages/modules/Connectivity/staticlibs/native": Bp2BuildDefaultTrueRecursively,
- "packages/modules/Gki/libkver": Bp2BuildDefaultTrue,
- "packages/modules/NetworkStack/common/captiveportal": Bp2BuildDefaultTrue,
- "packages/modules/NeuralNetworks/apex": Bp2BuildDefaultTrue,
- "packages/modules/NeuralNetworks/apex/testing": Bp2BuildDefaultTrue,
- "packages/providers/MediaProvider/tools/dialogs": Bp2BuildDefaultFalse, // TODO(b/242834374)
- "packages/screensavers/Basic": Bp2BuildDefaultTrue,
- "packages/services/Car/tests/SampleRearViewCamera": Bp2BuildDefaultFalse, // TODO(b/242834321)
+ "packages/apps/DevCamera": Bp2BuildDefaultTrue,
+ "packages/apps/HTMLViewer": Bp2BuildDefaultTrue,
+ "packages/apps/Protips": Bp2BuildDefaultTrue,
+ "packages/apps/SafetyRegulatoryInfo": Bp2BuildDefaultTrue,
+ "packages/apps/WallpaperPicker": Bp2BuildDefaultTrue,
+ "packages/modules/NeuralNetworks/driver/cache": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/StatsD/lib/libstatssocket": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb": Bp2BuildDefaultTrue,
+ "packages/modules/adb/apex": Bp2BuildDefaultTrue,
+ "packages/modules/adb/fastdeploy": Bp2BuildDefaultTrue,
+ "packages/modules/adb/crypto": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/libs": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/pairing_auth": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/pairing_connection": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/proto": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/tls": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/Connectivity/staticlibs/native": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/Connectivity/staticlibs/netd/libnetdutils": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/Gki/libkver": Bp2BuildDefaultTrue,
+ "packages/modules/NetworkStack/common/captiveportal": Bp2BuildDefaultTrue,
+ "packages/modules/NeuralNetworks/apex": Bp2BuildDefaultTrue,
+ "packages/modules/NeuralNetworks/apex/testing": Bp2BuildDefaultTrue,
+ "packages/providers/MediaProvider/tools/dialogs": Bp2BuildDefaultFalse, // TODO(b/242834374)
+ "packages/screensavers/Basic": Bp2BuildDefaultTrue,
+ "packages/services/Car/tests/SampleRearViewCamera": Bp2BuildDefaultFalse, // TODO(b/242834321)
"platform_testing/libraries/annotations": Bp2BuildDefaultTrueRecursively,
"platform_testing/libraries/flag-helpers/libflagtest": Bp2BuildDefaultTrueRecursively,
@@ -633,7 +634,6 @@
"libneuralnetworks",
"libneuralnetworks_static",
"libgraphicsenv",
- "libhardware",
"libhardware_headers",
"libnativeloader-headers",
"libnativewindow_headers",
@@ -993,6 +993,7 @@
"tradefed-result-interfaces",
"tradefed-device-build-interfaces",
"tradefed-invocation-interfaces",
+ "tradefed-lib-core",
}
Bp2buildModuleTypeAlwaysConvertList = []string{
@@ -1019,6 +1020,7 @@
"ndk_headers",
"ndk_library",
"sysprop_library",
+ "versioned_ndk_headers",
"xsd_config",
// go/keep-sorted end
}
@@ -1045,6 +1047,8 @@
"libfsverity_rs",
"libtombstoned_client_rust",
+ "libhardware", //Depends on unconverted libapexsupport
+
// TODO(b/263326760): Failed already.
"minijail_compiler_unittest",
"minijail_parser_unittest",
diff --git a/android/api_domain.go b/android/api_domain.go
index 38f48e3..0a66c3d 100644
--- a/android/api_domain.go
+++ b/android/api_domain.go
@@ -14,14 +14,6 @@
package android
-func init() {
- RegisterApiDomainBuildComponents(InitRegistrationContext)
-}
-
-func RegisterApiDomainBuildComponents(ctx RegistrationContext) {
- ctx.RegisterModuleType("api_domain", ApiDomainFactory)
-}
-
type ApiSurface int
// TODO(b/246656800): Reconcile with android.SdkKind
@@ -44,50 +36,3 @@
return "invalid"
}
}
-
-type apiDomain struct {
- ModuleBase
- BazelModuleBase
-
- properties apiDomainProperties
-}
-
-type apiDomainProperties struct {
- // cc library contributions (.h files/.map.txt) of this API domain
- // This dependency is a no-op in Soong, but the corresponding Bazel target in the api_bp2build workspace
- // will provide a `CcApiContributionInfo` provider
- Cc_api_contributions []string
-
- // java library contributions (as .txt) of this API domain
- // This dependency is a no-op in Soong, but the corresponding Bazel target in the api_bp2build workspace
- // will provide a `JavaApiContributionInfo` provider
- Java_api_contributions []string
-}
-
-func ApiDomainFactory() Module {
- m := &apiDomain{}
- m.AddProperties(&m.properties)
- InitAndroidArchModule(m, DeviceSupported, MultilibBoth)
- return m
-}
-
-// Do not create any dependency edges in Soong for now to skip visibility checks for some systemapi libraries.
-// Currently, all api_domain modules reside in build/orchestrator/apis/Android.bp
-// However, cc libraries like libsigchain (com.android.art) restrict their visibility to art/*
-// When the api_domain module types are collocated with their contributions, this dependency edge can be restored
-func (a *apiDomain) DepsMutator(ctx BottomUpMutatorContext) {
-}
-
-// API domain does not have any builld actions yet
-func (a *apiDomain) GenerateAndroidBuildActions(ctx ModuleContext) {
-}
-
-const (
- apiContributionSuffix = ".contribution"
-)
-
-// ApiContributionTargetName returns the name of the bp2build target (e.g. cc_api_contribution) of contribution modules (e.g. ndk_library)
-// A suffix is necessary to prevent a name collision with the base target in the same bp2build bazel package
-func ApiContributionTargetName(moduleName string) string {
- return moduleName + apiContributionSuffix
-}
diff --git a/android/bazel.go b/android/bazel.go
index e307b18..b4e7ae5 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -693,15 +693,27 @@
if len(ctx.Module().GetMissingBp2buildDeps()) > 0 {
exampleDep := ctx.Module().GetMissingBp2buildDeps()[0]
- ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNCONVERTED_DEP, exampleDep)
+ ctx.MarkBp2buildUnconvertible(
+ bp2build_metrics_proto.UnconvertedReasonType_UNCONVERTED_DEP, exampleDep)
}
+ // Transitively mark modules unconvertible with the following set of conditions.
ctx.VisitDirectDeps(func(dep Module) {
- if dep.base().GetUnconvertedReason() != nil &&
- dep.base().GetUnconvertedReason().ReasonType != int(bp2build_metrics_proto.UnconvertedReasonType_DEFINED_IN_BUILD_FILE) &&
- ctx.OtherModuleDependencyTag(dep) == Bp2buildDepTag {
- ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNCONVERTED_DEP, dep.Name())
+ if dep.base().GetUnconvertedReason() == nil {
+ return
}
+
+ if dep.base().GetUnconvertedReason().ReasonType ==
+ int(bp2build_metrics_proto.UnconvertedReasonType_DEFINED_IN_BUILD_FILE) {
+ return
+ }
+
+ if ctx.OtherModuleDependencyTag(dep) != Bp2buildDepTag {
+ return
+ }
+
+ ctx.MarkBp2buildUnconvertible(
+ bp2build_metrics_proto.UnconvertedReasonType_UNCONVERTED_DEP, dep.Name())
})
}
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index a554775..d272ec2 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -103,7 +103,7 @@
// or ":<module>") and returns a Bazel-compatible label which corresponds to dependencies on the
// module within the given ctx.
func BazelLabelForModuleDeps(ctx Bp2buildMutatorContext, modules []string) bazel.LabelList {
- return BazelLabelForModuleDepsWithFn(ctx, modules, BazelModuleLabel, true)
+ return BazelLabelForModuleDepsWithFn(ctx, modules, BazelModuleLabel, /*markAsDeps=*/true)
}
// BazelLabelForModuleWholeDepsExcludes expects two lists: modules (containing modules to include in
@@ -154,11 +154,11 @@
// the excluded dependencies.
func BazelLabelForModuleDepsExcludesWithFn(ctx Bp2buildMutatorContext, modules, excludes []string,
moduleToLabelFn func(BazelConversionPathContext, blueprint.Module) string) bazel.LabelList {
- moduleLabels := BazelLabelForModuleDepsWithFn(ctx, RemoveListFromList(modules, excludes), moduleToLabelFn, true)
+ moduleLabels := BazelLabelForModuleDepsWithFn(ctx, RemoveListFromList(modules, excludes), moduleToLabelFn, /*markAsDeps=*/true)
if len(excludes) == 0 {
return moduleLabels
}
- excludeLabels := BazelLabelForModuleDepsWithFn(ctx, excludes, moduleToLabelFn, false)
+ excludeLabels := BazelLabelForModuleDepsWithFn(ctx, excludes, moduleToLabelFn, /*markAsDeps=*/false)
return bazel.LabelList{
Includes: moduleLabels.Includes,
Excludes: excludeLabels.Includes,
@@ -452,12 +452,34 @@
Label: ":" + dep + "__BP2BUILD__MISSING__DEP",
}
}
- if markAsDep {
+ // Returns true if a dependency from the current module to the target module
+ // should be skipped; doing so is a hack to circumvent certain problematic
+ // scenarios that will be addressed in the future.
+ shouldSkipDep := func(dep string) bool {
// Don't count dependencies of "libc". This is a hack to circumvent the
// fact that, in a variantless build graph, "libc" has a dependency on itself.
- if ctx.ModuleName() != "libc" {
- ctx.AddDependency(ctx.Module(), Bp2buildDepTag, dep)
+ if ctx.ModuleName() == "libc" {
+ return true
}
+
+ // TODO: b/303307672: Dependencies on this module happen to "work" because
+ // there is a source file with the same name as this module in the
+ // same directory. We should remove this hack and enforce the underlying
+ // module of this name is the actual one used.
+ if dep == "mke2fs.conf" {
+ return true
+ }
+
+ // TODO: b/303310285: Remove this special-casing once all dependencies of
+ // crtbegin_dynamic are convertible
+ if ctx.ModuleName() == "crtbegin_dynamic" {
+ return true
+ }
+
+ return false
+ }
+ if markAsDep && !shouldSkipDep(dep) {
+ ctx.AddDependency(ctx.Module(), Bp2buildDepTag, dep)
}
if !convertedToBazel(ctx, m) {
ctx.AddUnconvertedBp2buildDep(dep)
diff --git a/android/config.go b/android/config.go
index 622a672..a2d311d 100644
--- a/android/config.go
+++ b/android/config.go
@@ -167,7 +167,8 @@
}
// DisableHiddenApiChecks returns true if hiddenapi checks have been disabled.
-// For 'eng' target variant hiddenapi checks are disabled by default for performance optimisation,
+// For 'eng' target variant hiddenapi checks are disabled by default for performance optimisation
+// Hiddenapi checks are also disabled when RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE is set to false
// but can be enabled by setting environment variable ENABLE_HIDDENAPI_FLAGS=true.
// For other target variants hiddenapi check are enabled by default but can be disabled by
// setting environment variable UNSAFE_DISABLE_HIDDENAPI_FLAGS=true.
@@ -176,7 +177,8 @@
func (c Config) DisableHiddenApiChecks() bool {
return !c.IsEnvTrue("ENABLE_HIDDENAPI_FLAGS") &&
(c.IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") ||
- Bool(c.productVariables.Eng))
+ Bool(c.productVariables.Eng) ||
+ !c.ReleaseDefaultModuleBuildFromSource())
}
// MaxPageSizeSupported returns the max page size supported by the device. This
@@ -221,6 +223,13 @@
return c.config.productVariables.ReleaseAconfigFlagDefaultPermission
}
+// The flag indicating behavior for the tree wrt building modules or using prebuilts
+// derived from RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE
+func (c Config) ReleaseDefaultModuleBuildFromSource() bool {
+ return c.config.productVariables.ReleaseDefaultModuleBuildFromSource == nil ||
+ Bool(c.config.productVariables.ReleaseDefaultModuleBuildFromSource)
+}
+
// A DeviceConfig object represents the configuration for a particular device
// being built. For now there will only be one of these, but in the future there
// may be multiple devices being built.
@@ -297,8 +306,7 @@
// in tests when a path doesn't exist.
TestAllowNonExistentPaths bool
- // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
- // in tests when a path doesn't exist.
+ // If true, register the "bp2build_deps" mutator in the mutator pipeline.
Bp2buildDepsMutator bool
// The list of files that when changed, must invalidate soong_build to
diff --git a/android/register.go b/android/register.go
index f1c2986..6182159 100644
--- a/android/register.go
+++ b/android/register.go
@@ -181,8 +181,7 @@
return ctx
}
-// Helper function to register the module types used in bp2build and
-// api_bp2build.
+// Helper function to register the module types used in bp2build.
func registerModuleTypes(ctx *Context) {
for _, t := range moduleTypes {
t.register(ctx)
diff --git a/android/test_asserts.go b/android/test_asserts.go
index 3a2cb1a..c33ade5 100644
--- a/android/test_asserts.go
+++ b/android/test_asserts.go
@@ -148,7 +148,7 @@
return
}
if !ok {
- t.Errorf("%s does not match regular expression %s", s, expectedRex)
+ t.Errorf("%s: %s does not match regular expression %s", message, s, expectedRex)
}
}
diff --git a/android/variable.go b/android/variable.go
index 8882e80..006a77f 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -479,6 +479,8 @@
ReleaseAconfigFlagDefaultPermission string `json:",omitempty"`
+ ReleaseDefaultModuleBuildFromSource *bool `json:",omitempty"`
+
KeepVndk *bool `json:",omitempty"`
CheckVendorSeappViolations *bool `json:",omitempty"`
diff --git a/bp2build/aar_conversion_test.go b/bp2build/aar_conversion_test.go
index 57c38db..475c2d6 100644
--- a/bp2build/aar_conversion_test.go
+++ b/bp2build/aar_conversion_test.go
@@ -102,6 +102,7 @@
sdk_version: "current",
}
`,
+ StubbedBuildDefinitions: []string{"lib_dep"},
ExpectedBazelTargets: []string{
MakeBazelTarget(
"android_library",
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index f53588d..53c37b9 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -576,7 +576,7 @@
Dir: ctx.ModuleDir(m),
Deps: m.(*bootstrap.GoPackage).Deps(),
}
- } else if moduleType == "ndk_headers" {
+ } else if moduleType == "ndk_headers" || moduleType == "versioned_ndk_headers" {
ndkHeaders = append(ndkHeaders, m)
}
})
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index dc56a17..8e51d98 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -349,19 +349,6 @@
},
},
{
- Description: "non-existent dep",
- Blueprint: `custom {
- name: "has_dep",
- arch_paths: [":dep"],
- bazel_module: { bp2build_available: true },
-}`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("custom", "has_dep", AttrNameToString{
- "arch_paths": `[":dep__BP2BUILD__MISSING__DEP"]`,
- }),
- },
- },
- {
Description: "arch-variant srcs",
Blueprint: `custom {
name: "arch_paths",
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 3cce430..5ddae68 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -559,8 +559,8 @@
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Dir: "foo/bar",
- StubbedBuildDefinitions: []string{"//foo/bar:prebuilt_whole_static_lib_for_shared", "//foo/bar:prebuilt_whole_static_lib_for_static",
- "//foo/bar:prebuilt_whole_static_lib_for_both"},
+ StubbedBuildDefinitions: []string{"//foo/bar:whole_static_lib_for_shared", "//foo/bar:whole_static_lib_for_static",
+ "//foo/bar:whole_static_lib_for_both"},
Filesystem: map[string]string{
"foo/bar/Android.bp": `
cc_library {
@@ -3355,6 +3355,7 @@
Description: "cc_library with target.apex",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"bar", "baz", "buh"},
Blueprint: `
cc_library {
name: "foo",
@@ -3366,27 +3367,29 @@
exclude_static_libs: ["buh"],
}
}
-}`,
+}` + simpleModule("cc_library_static", "baz") +
+ simpleModule("cc_library_static", "buh") +
+ simpleModule("cc_library_static", "bar"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
- "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
+ "implementation_deps": `[":baz"] + select({
"//build/bazel/rules/apex:in_apex": [],
- "//conditions:default": [":buh__BP2BUILD__MISSING__DEP"],
+ "//conditions:default": [":buh"],
})`,
- "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
+ "implementation_dynamic_deps": `[":baz"] + select({
"//build/bazel/rules/apex:in_apex": [],
- "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
+ "//conditions:default": [":bar"],
})`,
"local_includes": `["."]`,
}),
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
+ "implementation_deps": `[":baz"] + select({
"//build/bazel/rules/apex:in_apex": [],
- "//conditions:default": [":buh__BP2BUILD__MISSING__DEP"],
+ "//conditions:default": [":buh"],
})`,
- "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
+ "implementation_dynamic_deps": `[":baz"] + select({
"//build/bazel/rules/apex:in_apex": [],
- "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
+ "//conditions:default": [":bar"],
})`,
"local_includes": `["."]`,
}),
@@ -3412,20 +3415,23 @@
exclude_static_libs: ["abc"],
}
}
-}`,
+}` + simpleModule("cc_library_static", "bar") +
+ simpleModule("cc_library_static", "baz") +
+ simpleModule("cc_library_static", "abc"),
+ StubbedBuildDefinitions: []string{"bar", "baz", "abc"},
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
"implementation_dynamic_deps": `select({
"//build/bazel/rules/apex:in_apex": [],
- "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
+ "//conditions:default": [":bar"],
})`,
"dynamic_deps": `select({
"//build/bazel/rules/apex:in_apex": [],
- "//conditions:default": [":baz__BP2BUILD__MISSING__DEP"],
+ "//conditions:default": [":baz"],
})`,
"deps": `select({
"//build/bazel/rules/apex:in_apex": [],
- "//conditions:default": [":abc__BP2BUILD__MISSING__DEP"],
+ "//conditions:default": [":abc"],
})`,
"local_includes": `["."]`,
}),
@@ -5214,3 +5220,34 @@
}
runCcLibraryTestCase(t, tc)
}
+
+func TestVersionedNdkHeadersConversion(t *testing.T) {
+ tc := Bp2buildTestCase{
+ Description: "versioned_ndk_headers conversion",
+ ModuleTypeUnderTest: "versioned_ndk_headers",
+ ModuleTypeUnderTestFactory: cc.VersionedNdkHeadersFactory,
+ Blueprint: `
+versioned_ndk_headers {
+ name: "libfoo_headers",
+ from: "from",
+ to: "to",
+}
+`,
+ Filesystem: map[string]string{
+ "from/foo.h": "",
+ "from/foo_other.h": "",
+ },
+ ExpectedBazelTargets: []string{
+ MakeBazelTargetNoRestrictions("ndk_headers", "libfoo_headers", AttrNameToString{
+ "strip_import_prefix": `"from"`,
+ "import_prefix": `"to"`,
+ "hdrs": `[
+ "from/foo.h",
+ "from/foo_other.h",
+ ]`,
+ "run_versioner": "True",
+ }),
+ },
+ }
+ runCcLibraryTestCase(t, tc)
+}
diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go
index e54f051..5168fe9 100644
--- a/bp2build/cc_library_headers_conversion_test.go
+++ b/bp2build/cc_library_headers_conversion_test.go
@@ -70,10 +70,6 @@
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers test",
Filesystem: map[string]string{
- "lib-1/lib1a.h": "",
- "lib-1/lib1b.h": "",
- "lib-2/lib2a.h": "",
- "lib-2/lib2b.h": "",
"dir-1/dir1a.h": "",
"dir-1/dir1b.h": "",
"dir-2/dir2a.h": "",
@@ -86,7 +82,6 @@
cc_library_headers {
name: "foo_headers",
export_include_dirs: ["dir-1", "dir-2"],
- header_libs: ["lib-1", "lib-2"],
arch: {
arm64: {
@@ -322,7 +317,7 @@
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers exported_static_lib_headers is reexported",
Filesystem: map[string]string{},
- StubbedBuildDefinitions: []string{"foo_export"},
+ StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "foo_headers",
@@ -330,7 +325,8 @@
static_libs: ["foo_export", "foo_no_reexport"],
bazel_module: { bp2build_available: true },
}
-` + simpleModule("cc_library_headers", "foo_export"),
+` + simpleModule("cc_library_headers", "foo_export") +
+ simpleModule("cc_library_headers", "foo_no_reexport"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
@@ -343,7 +339,7 @@
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers exported_shared_lib_headers is reexported",
Filesystem: map[string]string{},
- StubbedBuildDefinitions: []string{"foo_export"},
+ StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "foo_headers",
@@ -351,7 +347,8 @@
shared_libs: ["foo_export", "foo_no_reexport"],
bazel_module: { bp2build_available: true },
}
-` + simpleModule("cc_library_headers", "foo_export"),
+` + simpleModule("cc_library_headers", "foo_export") +
+ simpleModule("cc_library_headers", "foo_no_reexport"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
@@ -364,7 +361,7 @@
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers exported_header_lib_headers is reexported",
Filesystem: map[string]string{},
- StubbedBuildDefinitions: []string{"foo_export"},
+ StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "foo_headers",
@@ -372,7 +369,8 @@
header_libs: ["foo_export", "foo_no_reexport"],
bazel_module: { bp2build_available: true },
}
-` + simpleModule("cc_library_headers", "foo_export"),
+` + simpleModule("cc_library_headers", "foo_export") +
+ simpleModule("cc_library_headers", "foo_no_reexport"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
@@ -426,7 +424,7 @@
func TestPrebuiltCcLibraryHeadersPreferredRdepUpdated(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers prebuilt preferred is used as rdep",
- StubbedBuildDefinitions: []string{"foo_export"},
+ StubbedBuildDefinitions: []string{"foo_export", "//foo/bar:foo_headers"},
Filesystem: map[string]string{
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
},
@@ -458,7 +456,7 @@
func TestPrebuiltCcLibraryHeadersRdepUpdated(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers not preferred is not used for rdep",
- StubbedBuildDefinitions: []string{"foo_export"},
+ StubbedBuildDefinitions: []string{"foo_export", "//foo/bar:foo_headers"},
Filesystem: map[string]string{
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
},
diff --git a/bp2build/gensrcs_conversion_test.go b/bp2build/gensrcs_conversion_test.go
index e808340..e9fc61d 100644
--- a/bp2build/gensrcs_conversion_test.go
+++ b/bp2build/gensrcs_conversion_test.go
@@ -15,16 +15,22 @@
package bp2build
import (
+ "testing"
+
"android/soong/android"
"android/soong/genrule"
- "testing"
)
+func registerModulesForGensrcsTests(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
+}
+
func TestGensrcs(t *testing.T) {
testcases := []struct {
- name string
- bp string
- expectedBazelAttrs AttrNameToString
+ name string
+ bp string
+ expectedBazelAttrs AttrNameToString
+ stubbedBuildDefinitions []string
}{
{
name: "gensrcs with common usage of properties",
@@ -37,18 +43,22 @@
data: ["foo/file.txt", ":external_files"],
output_extension: "out",
bazel_module: { bp2build_available: true },
+ }
+ filegroup {
+ name: "external_files",
}`,
+ stubbedBuildDefinitions: []string{"external_files"},
expectedBazelAttrs: AttrNameToString{
"srcs": `[
"test/input.txt",
- ":external_files__BP2BUILD__MISSING__DEP",
+ ":external_files",
]`,
"tools": `["program.py"]`,
"output_extension": `"out"`,
- "cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files__BP2BUILD__MISSING__DEP)"`,
+ "cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files)"`,
"data": `[
"foo/file.txt",
- ":external_files__BP2BUILD__MISSING__DEP",
+ ":external_files",
]`,
},
},
@@ -73,12 +83,13 @@
MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
}
t.Run(test.name, func(t *testing.T) {
- RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
+ RunBp2BuildTestCase(t, registerModulesForGensrcsTests,
Bp2buildTestCase{
ModuleTypeUnderTest: "gensrcs",
ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
Blueprint: test.bp,
ExpectedBazelTargets: expectedBazelTargets,
+ StubbedBuildDefinitions: test.stubbedBuildDefinitions,
})
})
}
diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go
index 38571d4..426dffa 100644
--- a/bp2build/java_library_conversion_test.go
+++ b/bp2build/java_library_conversion_test.go
@@ -635,7 +635,7 @@
Description: "java_library with non adjacent aidl filegroup",
ModuleTypeUnderTest: "java_library",
ModuleTypeUnderTestFactory: java.LibraryFactory,
- StubbedBuildDefinitions: []string{"A_aidl"},
+ StubbedBuildDefinitions: []string{"//path/to/A:A_aidl"},
Filesystem: map[string]string{
"path/to/A/Android.bp": `
filegroup {
diff --git a/bp2build/java_proto_conversion_test.go b/bp2build/java_proto_conversion_test.go
index 4e96efe..cd89978 100644
--- a/bp2build/java_proto_conversion_test.go
+++ b/bp2build/java_proto_conversion_test.go
@@ -193,3 +193,46 @@
},
})
}
+
+func TestJavaProtoPlugin(t *testing.T) {
+ runJavaProtoTestCase(t, Bp2buildTestCase{
+ Description: "java_library proto plugin",
+ StubbedBuildDefinitions: []string{"protoc-gen-test-plugin"},
+ Blueprint: `java_library_static {
+ name: "java-protos",
+ srcs: ["a.proto"],
+ proto: {
+ plugin: "test-plugin",
+ },
+ sdk_version: "current",
+}
+
+java_library_static {
+ name: "protoc-gen-test-plugin",
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
+ "srcs": `["a.proto"]`,
+ }),
+ MakeBazelTarget(
+ "java_lite_proto_library",
+ "java-protos_java_proto_lite",
+ AttrNameToString{
+ "deps": `[":java-protos_proto"]`,
+ "plugin": `":protoc-gen-test-plugin"`,
+ "sdk_version": `"current"`,
+ }),
+ MakeBazelTarget("java_library", "java-protos", AttrNameToString{
+ "exports": `[":java-protos_java_proto_lite"]`,
+ "sdk_version": `"current"`,
+ }),
+ MakeNeverlinkDuplicateTargetWithAttrs(
+ "java_library",
+ "java-protos",
+ AttrNameToString{
+ "sdk_version": `"current"`,
+ }),
+ },
+ })
+}
diff --git a/cc/Android.bp b/cc/Android.bp
index c32d854..8fa0fbe 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -18,6 +18,7 @@
"soong-genrule",
"soong-multitree",
"soong-snapshot",
+ "soong-sysprop-bp2build",
"soong-tradefed",
],
srcs: [
@@ -49,7 +50,6 @@
"snapshot_utils.go",
"stl.go",
"strip.go",
- "sysprop.go",
"tidy.go",
"util.go",
"vendor_snapshot.go",
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 45fbf27..ec5d522 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -1904,7 +1904,7 @@
}
func bazelLabelForWholeDeps(ctx android.Bp2buildMutatorContext, modules []string) bazel.LabelList {
- return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticWholeModuleDeps, true)
+ return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticWholeModuleDeps, /*markAsDeps=*/true)
}
func bazelLabelForWholeDepsExcludes(ctx android.Bp2buildMutatorContext, modules, excludes []string) bazel.LabelList {
@@ -1916,11 +1916,11 @@
}
func bazelLabelForStaticDeps(ctx android.Bp2buildMutatorContext, modules []string) bazel.LabelList {
- return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticModule, true)
+ return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticModule, /*markAsDeps=*/true)
}
func bazelLabelForSharedDeps(ctx android.Bp2buildMutatorContext, modules []string) bazel.LabelList {
- return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForSharedModule, true)
+ return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForSharedModule, /*markAsDeps=*/true)
}
func bazelLabelForHeaderDeps(ctx android.Bp2buildMutatorContext, modules []string) bazel.LabelList {
diff --git a/cc/config/riscv64_device.go b/cc/config/riscv64_device.go
index e048622..d5bc760 100644
--- a/cc/config/riscv64_device.go
+++ b/cc/config/riscv64_device.go
@@ -27,6 +27,9 @@
"-Werror=implicit-function-declaration",
"-fno-emulated-tls",
"-march=rv64gcv_zba_zbb_zbs",
+ // Equivalent to "-munaligned-access", but our clang doesn't have that yet.
+ "-Xclang -target-feature -Xclang +unaligned-scalar-mem",
+ "-Xclang -target-feature -Xclang +unaligned-vector-mem",
}
riscv64ArchVariantCflags = map[string][]string{}
@@ -34,6 +37,9 @@
riscv64Ldflags = []string{
"-Wl,--hash-style=gnu",
"-march=rv64gcv_zba_zbb_zbs",
+ // Equivalent to "-munaligned-access", but our clang doesn't have that yet.
+ "-Xclang -target-feature -Xclang +unaligned-scalar-mem",
+ "-Xclang -target-feature -Xclang +unaligned-vector-mem",
}
riscv64Lldflags = append(riscv64Ldflags,
diff --git a/cc/gen.go b/cc/gen.go
index b15f164..151f23d 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -20,6 +20,7 @@
"android/soong/aidl_library"
"android/soong/bazel"
+ "android/soong/sysprop/bp2build"
"github.com/google/blueprint"
@@ -240,12 +241,13 @@
}
func bp2buildCcSysprop(ctx android.Bp2buildMutatorContext, moduleName string, minSdkVersion *string, srcs bazel.LabelListAttribute) *bazel.LabelAttribute {
- labels := SyspropLibraryLabels{
- SyspropLibraryLabel: moduleName + "_sysprop_library",
- StaticLibraryLabel: moduleName + "_cc_sysprop_library_static",
+ labels := bp2build.SyspropLibraryLabels{
+ SyspropLibraryLabel: moduleName + "_sysprop_library",
+ CcStaticLibraryLabel: moduleName + "_cc_sysprop_library_static",
}
- Bp2buildSysprop(ctx, labels, srcs, minSdkVersion)
- return createLabelAttributeCorrespondingToSrcs(":"+labels.StaticLibraryLabel, srcs)
+ bp2build.Bp2buildBaseSyspropLibrary(ctx, labels.SyspropLibraryLabel, srcs)
+ bp2build.Bp2buildSyspropCc(ctx, labels, minSdkVersion)
+ return createLabelAttributeCorrespondingToSrcs(":"+labels.CcStaticLibraryLabel, srcs)
}
// Creates a LabelAttribute for a given label where the value is only set for
diff --git a/cc/library_headers.go b/cc/library_headers.go
index fccdf99..4da2b48 100644
--- a/cc/library_headers.go
+++ b/cc/library_headers.go
@@ -161,18 +161,3 @@
Tags: tags,
}, attrs)
}
-
-// Append .contribution suffix to input labels
-func apiBazelTargets(ll bazel.LabelList) bazel.LabelList {
- labels := make([]bazel.Label, 0)
- for _, l := range ll.Includes {
- labels = append(labels, bazel.Label{
- Label: android.ApiContributionTargetName(l.Label),
- })
- }
- return bazel.MakeLabelList(labels)
-}
-
-var (
- allArches = []string{"arm", "arm64", "x86", "x86_64"}
-)
diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go
index da5db1c..461aa96 100644
--- a/cc/ndk_headers.go
+++ b/cc/ndk_headers.go
@@ -19,6 +19,7 @@
"path/filepath"
"github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/bazel"
@@ -151,6 +152,7 @@
Strip_import_prefix *string
Import_prefix *string
Hdrs bazel.LabelListAttribute
+ Run_versioner *bool
}
func (h *headerModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
@@ -217,6 +219,7 @@
// Note that this is really only built to handle bionic/libc/include.
type versionedHeaderModule struct {
android.ModuleBase
+ android.BazelModuleBase
properties versionedHeaderProperties
@@ -255,6 +258,25 @@
processHeadersWithVersioner(ctx, fromSrcPath, toOutputPath, m.srcPaths, installPaths)
}
+func (h *versionedHeaderModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
+ props := bazel.BazelTargetModuleProperties{
+ Rule_class: "ndk_headers",
+ Bzl_load_location: "//build/bazel/rules/cc:ndk_headers.bzl",
+ }
+ globPattern := headerGlobPattern(proptools.String(h.properties.From))
+ attrs := &bazelNdkHeadersAttributes{
+ Strip_import_prefix: h.properties.From,
+ Import_prefix: h.properties.To,
+ Run_versioner: proptools.BoolPtr(true),
+ Hdrs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, []string{globPattern})),
+ }
+ ctx.CreateBazelTargetModule(
+ props,
+ android.CommonAttributes{Name: h.Name()},
+ attrs,
+ )
+}
+
func processHeadersWithVersioner(ctx android.ModuleContext, srcDir, outDir android.Path,
srcPaths android.Paths, installPaths []android.WritablePath) android.Path {
// The versioner depends on a dependencies directory to simplify determining include paths
@@ -298,12 +320,13 @@
// Unlike the ndk_headers soong module, versioned_ndk_headers operates on a
// directory level specified in `from` property. This is only used to process
// the bionic/libc/include directory.
-func versionedNdkHeadersFactory() android.Module {
+func VersionedNdkHeadersFactory() android.Module {
module := &versionedHeaderModule{}
module.AddProperties(&module.properties)
android.InitAndroidModule(module)
+ android.InitBazelModule(module)
return module
}
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 3a84174..2064b1b 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -61,7 +61,7 @@
// because we don't want to spam the build output with "nothing
// changed" messages, so redirect output message to $out, and if
// changes were detected print the output and fail.
- Command: "$stgdiff $args --stg $in -o $out || (cat $out && false)",
+ Command: "$stgdiff $args --stg $in -o $out || (cat $out && false; echo 'Run $$ANDROID_BUILD_TOP/development/tools/ndk/update_ndk_abi.sh to update the ABI dumps.')",
CommandDeps: []string{"$stgdiff"},
}, "args")
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
index 54a2ee2..483d23b 100644
--- a/cc/ndk_sysroot.go
+++ b/cc/ndk_sysroot.go
@@ -64,7 +64,7 @@
func RegisterNdkModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("ndk_headers", NdkHeadersFactory)
ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
- ctx.RegisterModuleType("versioned_ndk_headers", versionedNdkHeadersFactory)
+ ctx.RegisterModuleType("versioned_ndk_headers", VersionedNdkHeadersFactory)
ctx.RegisterModuleType("preprocessed_ndk_headers", preprocessedNdkHeadersFactory)
ctx.RegisterParallelSingletonType("ndk", NdkSingleton)
}
diff --git a/cc/sysprop.go b/cc/sysprop.go
deleted file mode 100644
index be03004..0000000
--- a/cc/sysprop.go
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (C) 2019 The Android Open Source Project
-//
-// 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 cc
-
-import (
- "android/soong/android"
- "android/soong/bazel"
-)
-
-// TODO(b/240463568): Additional properties will be added for API validation
-type bazelSyspropLibraryAttributes struct {
- Srcs bazel.LabelListAttribute
- Tags bazel.StringListAttribute
-}
-
-type bazelCcSyspropLibraryAttributes struct {
- Dep bazel.LabelAttribute
- Min_sdk_version *string
- Tags bazel.StringListAttribute
-}
-
-type SyspropLibraryLabels struct {
- SyspropLibraryLabel string
- SharedLibraryLabel string
- StaticLibraryLabel string
-}
-
-func Bp2buildSysprop(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, srcs bazel.LabelListAttribute, minSdkVersion *string) {
- apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx, ctx.Module())
- ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Rule_class: "sysprop_library",
- Bzl_load_location: "//build/bazel/rules/sysprop:sysprop_library.bzl",
- },
- android.CommonAttributes{Name: labels.SyspropLibraryLabel},
- &bazelSyspropLibraryAttributes{
- Srcs: srcs,
- Tags: apexAvailableTags,
- },
- )
-
- attrs := &bazelCcSyspropLibraryAttributes{
- Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel),
- Min_sdk_version: minSdkVersion,
- Tags: apexAvailableTags,
- }
-
- if labels.SharedLibraryLabel != "" {
- ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Rule_class: "cc_sysprop_library_shared",
- Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
- },
- android.CommonAttributes{Name: labels.SharedLibraryLabel},
- attrs)
- }
-
- ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Rule_class: "cc_sysprop_library_static",
- Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
- },
- android.CommonAttributes{Name: labels.StaticLibraryLabel},
- attrs)
-}
diff --git a/java/proto.go b/java/proto.go
index 48adadc..c88d3d7 100644
--- a/java/proto.go
+++ b/java/proto.go
@@ -159,6 +159,8 @@
Sdk_version bazel.StringAttribute
Java_version bazel.StringAttribute
+
+ Plugin bazel.LabelAttribute
}
func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs bazel.LabelListAttribute, AdditionalProtoDeps bazel.LabelListAttribute) *bazel.Label {
@@ -189,12 +191,18 @@
ctx.PropertyErrorf("proto.type", "cannot handle conversion at this time: %q", typ)
}
+ plugin := bazel.LabelAttribute{}
+ if m.protoProperties.Proto.Plugin != nil {
+ plugin.SetValue(android.BazelLabelForModuleDepSingle(ctx, "protoc-gen-"+*m.protoProperties.Proto.Plugin))
+ }
+
protoAttrs := &protoAttributes{
Deps: bazel.MakeLabelListAttribute(protoInfo.Proto_libs),
Transitive_deps: bazel.MakeLabelListAttribute(protoInfo.Transitive_proto_libs),
Additional_proto_deps: AdditionalProtoDeps,
Java_version: bazel.StringAttribute{Value: m.properties.Java_version},
Sdk_version: bazel.StringAttribute{Value: m.deviceProperties.Sdk_version},
+ Plugin: plugin,
}
name := m.Name() + suffix
diff --git a/scripts/conv_linker_config.py b/scripts/conv_linker_config.py
index c6aa3d0..c6e6e30 100644
--- a/scripts/conv_linker_config.py
+++ b/scripts/conv_linker_config.py
@@ -62,8 +62,8 @@
if args.source:
for input in args.source.split(':'):
pb.MergeFrom(LoadJsonMessage(input))
- with open(args.output, 'wb') as f:
- f.write(pb.SerializeToString())
+
+ ValidateAndWriteAsPbFile(pb, args.output)
def Print(args):
@@ -90,8 +90,8 @@
for item in installed_libraries:
if item not in getattr(pb, 'provideLibs'):
getattr(pb, 'provideLibs').append(item)
- with open(args.output, 'wb') as f:
- f.write(pb.SerializeToString())
+
+ ValidateAndWriteAsPbFile(pb, args.output)
def Append(args):
@@ -106,8 +106,8 @@
else:
setattr(pb, args.key, args.value)
- with open(args.output, 'wb') as f:
- f.write(pb.SerializeToString())
+ ValidateAndWriteAsPbFile(pb, args.output)
+
def Merge(args):
@@ -116,8 +116,7 @@
with open(other, 'rb') as f:
pb.MergeFromString(f.read())
- with open(args.out, 'wb') as f:
- f.write(pb.SerializeToString())
+ ValidateAndWriteAsPbFile(pb, args.output)
def Validate(args):
@@ -151,6 +150,29 @@
sys.exit(f'Unknown type: {args.type}')
+def ValidateAndWriteAsPbFile(pb, output_path):
+ ValidateConfiguration(pb)
+ with open(output_path, 'wb') as f:
+ f.write(pb.SerializeToString())
+
+
+def ValidateConfiguration(pb):
+ """
+ Validate if the configuration is valid to be used as linker configuration
+ """
+
+ # Validate if provideLibs and requireLibs have common module
+ provideLibs = set(getattr(pb, 'provideLibs'))
+ requireLibs = set(getattr(pb, 'requireLibs'))
+
+ intersectLibs = provideLibs.intersection(requireLibs)
+
+ if intersectLibs:
+ for lib in intersectLibs:
+ print(f'{lib} exists both in requireLibs and provideLibs', file=sys.stderr)
+ sys.exit(1)
+
+
def GetArgParser():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
diff --git a/sysprop/Android.bp b/sysprop/Android.bp
index e5263fe..7f51000 100644
--- a/sysprop/Android.bp
+++ b/sysprop/Android.bp
@@ -12,6 +12,7 @@
"soong-bp2build",
"soong-cc",
"soong-java",
+ "soong-sysprop-bp2build",
],
srcs: [
"sysprop_library.go",
diff --git a/sysprop/bp2build/Android.bp b/sysprop/bp2build/Android.bp
new file mode 100644
index 0000000..1b9eda8
--- /dev/null
+++ b/sysprop/bp2build/Android.bp
@@ -0,0 +1,16 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+bootstrap_go_package {
+ name: "soong-sysprop-bp2build",
+ pkgPath: "android/soong/sysprop/bp2build",
+ deps: [
+ "soong-android",
+ "soong-bazel",
+ ],
+ srcs: [
+ "bp2build.go",
+ ],
+ pluginFor: ["soong_build"],
+}
diff --git a/sysprop/bp2build/bp2build.go b/sysprop/bp2build/bp2build.go
new file mode 100644
index 0000000..18991de
--- /dev/null
+++ b/sysprop/bp2build/bp2build.go
@@ -0,0 +1,106 @@
+// Copyright (C) 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package bp2build
+
+import (
+ "android/soong/android"
+ "android/soong/bazel"
+)
+
+type SyspropLibraryLabels struct {
+ SyspropLibraryLabel string
+ CcSharedLibraryLabel string
+ CcStaticLibraryLabel string
+ JavaLibraryLabel string
+}
+
+// TODO(b/240463568): Additional properties will be added for API validation
+type bazelSyspropLibraryAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Tags bazel.StringListAttribute
+}
+
+func Bp2buildBaseSyspropLibrary(ctx android.Bp2buildMutatorContext, name string, srcs bazel.LabelListAttribute) {
+ apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "sysprop_library",
+ Bzl_load_location: "//build/bazel/rules/sysprop:sysprop_library.bzl",
+ },
+ android.CommonAttributes{Name: name},
+ &bazelSyspropLibraryAttributes{
+ Srcs: srcs,
+ Tags: apexAvailableTags,
+ },
+ )
+}
+
+type bazelCcSyspropLibraryAttributes struct {
+ Dep bazel.LabelAttribute
+ Min_sdk_version *string
+ Tags bazel.StringListAttribute
+}
+
+func Bp2buildSyspropCc(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, minSdkVersion *string) {
+ apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
+
+ attrs := &bazelCcSyspropLibraryAttributes{
+ Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel),
+ Min_sdk_version: minSdkVersion,
+ Tags: apexAvailableTags,
+ }
+
+ if labels.CcSharedLibraryLabel != "" {
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_sysprop_library_shared",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
+ },
+ android.CommonAttributes{Name: labels.CcSharedLibraryLabel},
+ attrs)
+ }
+ if labels.CcStaticLibraryLabel != "" {
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_sysprop_library_static",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
+ },
+ android.CommonAttributes{Name: labels.CcStaticLibraryLabel},
+ attrs)
+ }
+}
+
+type bazelJavaLibraryAttributes struct {
+ Dep bazel.LabelAttribute
+ Min_sdk_version *string
+ Tags bazel.StringListAttribute
+}
+
+func Bp2buildSyspropJava(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, minSdkVersion *string) {
+ apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "java_sysprop_library",
+ Bzl_load_location: "//build/bazel/rules/java:java_sysprop_library.bzl",
+ },
+ android.CommonAttributes{Name: labels.JavaLibraryLabel},
+ &bazelJavaLibraryAttributes{
+ Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel),
+ Min_sdk_version: minSdkVersion,
+ Tags: apexAvailableTags,
+ })
+}
diff --git a/sysprop/sysprop_library.go b/sysprop/sysprop_library.go
index d16bf32..13cf68f 100644
--- a/sysprop/sysprop_library.go
+++ b/sysprop/sysprop_library.go
@@ -24,6 +24,8 @@
"sync"
"android/soong/bazel"
+ "android/soong/sysprop/bp2build"
+ "android/soong/ui/metrics/bp2build_metrics_proto"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -230,6 +232,10 @@
return m.BaseModuleName() + "_java_gen_public"
}
+func (m *syspropLibrary) bp2buildJavaImplementationModuleName() string {
+ return m.BaseModuleName() + "_java_library"
+}
+
func (m *syspropLibrary) BaseModuleName() string {
return m.ModuleBase.Name()
}
@@ -431,6 +437,7 @@
Min_sdk_version *string
Bazel_module struct {
Bp2build_available *bool
+ Label *string
}
}
@@ -551,8 +558,10 @@
Min_sdk_version: m.properties.Java.Min_sdk_version,
Bazel_module: struct {
Bp2build_available *bool
+ Label *string
}{
- Bp2build_available: proptools.BoolPtr(false),
+ Label: proptools.StringPtr(
+ fmt.Sprintf("//%s:%s", ctx.ModuleDir(), m.bp2buildJavaImplementationModuleName())),
},
})
@@ -573,6 +582,7 @@
Stem: proptools.StringPtr(m.BaseModuleName()),
Bazel_module: struct {
Bp2build_available *bool
+ Label *string
}{
Bp2build_available: proptools.BoolPtr(false),
},
@@ -592,13 +602,17 @@
// TODO(b/240463568): Additional properties will be added for API validation
func (m *syspropLibrary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
- labels := cc.SyspropLibraryLabels{
- SyspropLibraryLabel: m.BaseModuleName(),
- SharedLibraryLabel: m.CcImplementationModuleName(),
- StaticLibraryLabel: cc.BazelLabelNameForStaticModule(m.CcImplementationModuleName()),
+ if m.Owner() != "Platform" {
+ ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "Only sysprop libraries owned by platform are supported at this time")
+ return
}
- cc.Bp2buildSysprop(ctx,
- labels,
- bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Srcs)),
- m.properties.Cpp.Min_sdk_version)
+ labels := bp2build.SyspropLibraryLabels{
+ SyspropLibraryLabel: m.BaseModuleName(),
+ CcSharedLibraryLabel: m.CcImplementationModuleName(),
+ CcStaticLibraryLabel: cc.BazelLabelNameForStaticModule(m.CcImplementationModuleName()),
+ JavaLibraryLabel: m.bp2buildJavaImplementationModuleName(),
+ }
+ bp2build.Bp2buildBaseSyspropLibrary(ctx, labels.SyspropLibraryLabel, bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Srcs)))
+ bp2build.Bp2buildSyspropCc(ctx, labels, m.properties.Cpp.Min_sdk_version)
+ bp2build.Bp2buildSyspropJava(ctx, labels, m.properties.Java.Min_sdk_version)
}
diff --git a/sysprop/sysprop_library_conversion_test.go b/sysprop/sysprop_library_conversion_test.go
index 89adf7d..dabcc92 100644
--- a/sysprop/sysprop_library_conversion_test.go
+++ b/sysprop/sysprop_library_conversion_test.go
@@ -58,13 +58,18 @@
bp2build.AttrNameToString{
"dep": `":sysprop_foo"`,
}),
+ bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library",
+ "sysprop_foo_java_library",
+ bp2build.AttrNameToString{
+ "dep": `":sysprop_foo"`,
+ }),
},
})
}
func TestSyspropLibraryCppMinSdkVersion(t *testing.T) {
bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{
- Description: "sysprop_library with min_sdk_version",
+ Description: "sysprop_library with cpp min_sdk_version",
ModuleTypeUnderTest: "sysprop_library",
ModuleTypeUnderTestFactory: syspropLibraryFactory,
Filesystem: map[string]string{
@@ -105,6 +110,86 @@
"dep": `":sysprop_foo"`,
"min_sdk_version": `"5"`,
}),
+ bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library",
+ "sysprop_foo_java_library",
+ bp2build.AttrNameToString{
+ "dep": `":sysprop_foo"`,
+ }),
},
})
}
+
+func TestSyspropLibraryJavaMinSdkVersion(t *testing.T) {
+ bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{
+ Description: "sysprop_library with java min_sdk_version",
+ ModuleTypeUnderTest: "sysprop_library",
+ ModuleTypeUnderTestFactory: syspropLibraryFactory,
+ Filesystem: map[string]string{
+ "foo.sysprop": "",
+ "bar.sysprop": "",
+ },
+ Blueprint: `
+sysprop_library {
+ name: "sysprop_foo",
+ srcs: [
+ "foo.sysprop",
+ "bar.sysprop",
+ ],
+ java: {
+ min_sdk_version: "5",
+ },
+ property_owner: "Platform",
+}
+`,
+ ExpectedBazelTargets: []string{
+ bp2build.MakeBazelTargetNoRestrictions("sysprop_library",
+ "sysprop_foo",
+ bp2build.AttrNameToString{
+ "srcs": `[
+ "foo.sysprop",
+ "bar.sysprop",
+ ]`,
+ }),
+ bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_shared",
+ "libsysprop_foo",
+ bp2build.AttrNameToString{
+ "dep": `":sysprop_foo"`,
+ }),
+ bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_static",
+ "libsysprop_foo_bp2build_cc_library_static",
+ bp2build.AttrNameToString{
+ "dep": `":sysprop_foo"`,
+ }),
+ bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library",
+ "sysprop_foo_java_library",
+ bp2build.AttrNameToString{
+ "dep": `":sysprop_foo"`,
+ "min_sdk_version": `"5"`,
+ }),
+ },
+ })
+}
+
+func TestSyspropLibraryOwnerNotPlatformUnconvertible(t *testing.T) {
+ bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{
+ Description: "sysprop_library simple",
+ ModuleTypeUnderTest: "sysprop_library",
+ ModuleTypeUnderTestFactory: syspropLibraryFactory,
+ Filesystem: map[string]string{
+ "foo.sysprop": "",
+ "bar.sysprop": "",
+ },
+ Blueprint: `
+sysprop_library {
+ name: "sysprop_foo",
+ srcs: [
+ "foo.sysprop",
+ "bar.sysprop",
+ ],
+ property_owner: "Vendor",
+ device_specific: true,
+}
+`,
+ ExpectedBazelTargets: []string{},
+ })
+}
diff --git a/tests/lib.sh b/tests/lib.sh
index dbb10b7..fb3b374 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -8,6 +8,11 @@
REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)"
+function make_mock_top {
+ mock=$(mktemp -t -d st.XXXXX)
+ echo "$mock"
+}
+
if [[ -n "$HARDWIRED_MOCK_TOP" ]]; then
MOCK_TOP="$HARDWIRED_MOCK_TOP"
else
@@ -198,3 +203,11 @@
info "Completed test case \e[96;1m$f\e[0m"
done
}
+
+function move_mock_top {
+ MOCK_TOP2=$(make_mock_top)
+ rm -rf $MOCK_TOP2
+ mv $MOCK_TOP $MOCK_TOP2
+ MOCK_TOP=$MOCK_TOP2
+ trap cleanup_mock_top EXIT
+}
diff --git a/tests/run_integration_tests.sh b/tests/run_integration_tests.sh
index 6b9ff8b..223baa4 100755
--- a/tests/run_integration_tests.sh
+++ b/tests/run_integration_tests.sh
@@ -23,4 +23,4 @@
"$TOP/build/soong/tests/apex_cc_module_arch_variant_tests.sh" "aosp_cf_arm64_phone" "armv8-a" "cortex-a53"
"$TOP/build/bazel/ci/b_test.sh"
-
+"$TOP/build/soong/tests/symlinks_path_test.sh"
diff --git a/tests/symlinks_path_test.sh b/tests/symlinks_path_test.sh
new file mode 100755
index 0000000..ed42911
--- /dev/null
+++ b/tests/symlinks_path_test.sh
@@ -0,0 +1,51 @@
+#!/bin/bash -eu
+
+set -o pipefail
+
+# Test that relative symlinks work by recreating the bug in b/259191764
+# In some cases, developers prefer to move their checkouts. This causes
+# issues in that symlinked files (namely, the bazel wrapper script)
+# cannot be found. As such, we implemented relative symlinks so that a
+# moved checkout doesn't need a full clean before rebuilding.
+# The bazel output base will still need to be removed, as Starlark
+# doesn't seem to support relative symlinks yet.
+
+source "$(dirname "$0")/lib.sh"
+
+function check_link_has_mock_top_prefix {
+ input_link=$1
+ link_target=`readlink $input_link`
+ if [[ $link_target != "$MOCK_TOP"* ]]; then
+ echo "Symlink for file $input_link -> $link_target doesn't start with $MOCK_TOP"
+ exit 1
+ fi
+}
+
+function test_symlinks_updated_when_top_dir_changed {
+ setup
+
+ mkdir -p a
+ touch a/g.txt
+ cat > a/Android.bp <<'EOF'
+filegroup {
+ name: "g",
+ srcs: ["g.txt"],
+ bazel_module: {bp2build_available: true},
+}
+EOF
+ # A directory under $MOCK_TOP
+ outdir=out2
+
+ # Modify OUT_DIR in a subshell so it doesn't affect the top level one.
+ (export OUT_DIR=$MOCK_TOP/$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g)
+
+ g_txt="out2/soong/workspace/a/g.txt"
+ check_link_has_mock_top_prefix "$g_txt"
+
+ move_mock_top
+
+ (export OUT_DIR=$MOCK_TOP/$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g)
+ check_link_has_mock_top_prefix "$g_txt"
+}
+
+scan_and_run_tests
\ No newline at end of file
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 44c20a0..ac9bf3a 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -16,10 +16,13 @@
import (
"fmt"
+ "io/fs"
"os"
"path/filepath"
"strconv"
"strings"
+ "sync"
+ "sync/atomic"
"android/soong/bazel"
"android/soong/ui/metrics"
@@ -50,6 +53,13 @@
bootstrapEpoch = 1
)
+var (
+ // Used during parallel update of symlinks in out directory to reflect new
+ // TOP dir.
+ symlinkWg sync.WaitGroup
+ numFound, numUpdated uint32
+)
+
func writeEnvironmentFile(_ Context, envFile string, envDeps map[string]string) error {
data, err := shared.EnvFileContents(envDeps)
if err != nil {
@@ -465,10 +475,118 @@
}
}
+func updateSymlinks(ctx Context, dir, prevCWD, cwd string) error {
+ defer symlinkWg.Done()
+
+ visit := func(path string, d fs.DirEntry, err error) error {
+ if d.IsDir() && path != dir {
+ symlinkWg.Add(1)
+ go updateSymlinks(ctx, path, prevCWD, cwd)
+ return filepath.SkipDir
+ }
+ f, err := d.Info()
+ if err != nil {
+ return err
+ }
+ // If the file is not a symlink, we don't have to update it.
+ if f.Mode()&os.ModeSymlink != os.ModeSymlink {
+ return nil
+ }
+
+ atomic.AddUint32(&numFound, 1)
+ target, err := os.Readlink(path)
+ if err != nil {
+ return err
+ }
+ if strings.HasPrefix(target, prevCWD) &&
+ (len(target) == len(prevCWD) || target[len(prevCWD)] == '/') {
+ target = filepath.Join(cwd, target[len(prevCWD):])
+ if err := os.Remove(path); err != nil {
+ return err
+ }
+ if err := os.Symlink(target, path); err != nil {
+ return err
+ }
+ atomic.AddUint32(&numUpdated, 1)
+ }
+ return nil
+ }
+
+ if err := filepath.WalkDir(dir, visit); err != nil {
+ return err
+ }
+ return nil
+}
+
+func fixOutDirSymlinks(ctx Context, config Config, outDir string) error {
+ cwd, err := os.Getwd()
+ if err != nil {
+ return err
+ }
+
+ // Record the .top as the very last thing in the function.
+ tf := filepath.Join(outDir, ".top")
+ defer func() {
+ if err := os.WriteFile(tf, []byte(cwd), 0644); err != nil {
+ fmt.Fprintf(os.Stderr, fmt.Sprintf("Unable to log CWD: %v", err))
+ }
+ }()
+
+ // Find the previous working directory if it was recorded.
+ var prevCWD string
+ pcwd, err := os.ReadFile(tf)
+ if err != nil {
+ if os.IsNotExist(err) {
+ // No previous working directory recorded, nothing to do.
+ return nil
+ }
+ return err
+ }
+ prevCWD = strings.Trim(string(pcwd), "\n")
+
+ if prevCWD == cwd {
+ // We are in the same source dir, nothing to update.
+ return nil
+ }
+
+ symlinkWg.Add(1)
+ if err := updateSymlinks(ctx, outDir, prevCWD, cwd); err != nil {
+ return err
+ }
+ symlinkWg.Wait()
+ ctx.Println(fmt.Sprintf("Updated %d/%d symlinks in dir %v", numUpdated, numFound, outDir))
+ return nil
+}
+
+func migrateOutputSymlinks(ctx Context, config Config) error {
+ // Figure out the real out directory ("out" could be a symlink).
+ outDir := config.OutDir()
+ s, err := os.Lstat(outDir)
+ if err != nil {
+ if os.IsNotExist(err) {
+ // No out dir exists, no symlinks to migrate.
+ return nil
+ }
+ return err
+ }
+ if s.Mode()&os.ModeSymlink == os.ModeSymlink {
+ target, err := filepath.EvalSymlinks(outDir)
+ if err != nil {
+ return err
+ }
+ outDir = target
+ }
+ return fixOutDirSymlinks(ctx, config, outDir)
+}
+
func runSoong(ctx Context, config Config) {
ctx.BeginTrace(metrics.RunSoong, "soong")
defer ctx.EndTrace()
+ if err := migrateOutputSymlinks(ctx, config); err != nil {
+ ctx.Fatalf("failed to migrate output directory to current TOP dir: %v", err)
+ }
+
// We have two environment files: .available is the one with every variable,
// .used with the ones that were actually used. The latter is used to
// determine whether Soong needs to be re-run since why re-run it if only