support libs for android_library

adds support for *-> android_library and android_library->* edges

Change-Id: I41d4e1d1b8106a17e67951d47e67b59ef3170d17
Test: manually inspected build files for libWallpaperPicker & android-suppor-v4
This commit is contained in:
Alix
2022-10-26 20:40:18 +00:00
parent 2266e02a3a
commit 82fb94e91e
4 changed files with 25 additions and 6 deletions

View File

@@ -68,6 +68,7 @@ android_library {
"exports": `[":static_lib_dep"]`, "exports": `[":static_lib_dep"]`,
"javacopts": `["-source 1.7 -target 1.7"]`, "javacopts": `["-source 1.7 -target 1.7"]`,
}), }),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
}}) }})
} }

View File

@@ -585,6 +585,7 @@ android_library {
"manifest": `"manifest/AndroidManifest.xml"`, "manifest": `"manifest/AndroidManifest.xml"`,
"resource_files": `[]`, "resource_files": `[]`,
}), }),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
}}) }})
} }
@@ -628,6 +629,7 @@ android_library {
"manifest": `"manifest/AndroidManifest.xml"`, "manifest": `"manifest/AndroidManifest.xml"`,
"resource_files": `[]`, "resource_files": `[]`,
}), }),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
}}) }})
} }
@@ -665,6 +667,7 @@ android_library {
"manifest": `"manifest/AndroidManifest.xml"`, "manifest": `"manifest/AndroidManifest.xml"`,
"resource_files": `[]`, "resource_files": `[]`,
}), }),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
}}) }})
} }

View File

@@ -1054,12 +1054,15 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
} }
name := a.Name()
props := bazel.BazelTargetModuleProperties{
Rule_class: "android_library",
Bzl_load_location: "@rules_android//rules:rules.bzl",
}
ctx.CreateBazelTargetModule( ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{ props,
Rule_class: "android_library", android.CommonAttributes{Name: name},
Bzl_load_location: "@rules_android//rules:rules.bzl",
},
android.CommonAttributes{Name: a.Name()},
&bazelAndroidLibrary{ &bazelAndroidLibrary{
&javaLibraryAttributes{ &javaLibraryAttributes{
javaCommonAttributes: commonAttrs, javaCommonAttributes: commonAttrs,
@@ -1069,4 +1072,16 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
a.convertAaptAttrsWithBp2Build(ctx), a.convertAaptAttrsWithBp2Build(ctx),
}, },
) )
neverlink := true
ctx.CreateBazelTargetModule(
props,
android.CommonAttributes{Name: name + "-neverlink"},
&bazelAndroidLibrary{
javaLibraryAttributes: &javaLibraryAttributes{
Neverlink: bazel.BoolAttribute{Value: &neverlink},
Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
},
},
)
} }

View File

@@ -2663,7 +2663,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
if m.properties.Libs != nil { if m.properties.Libs != nil {
// TODO 244210934 ALIX Check if this else statement breaks presubmits get rid of it if it doesn't // TODO 244210934 ALIX Check if this else statement breaks presubmits get rid of it if it doesn't
if strings.HasPrefix(ctx.ModuleType(), "java_binary") || strings.HasPrefix(ctx.ModuleType(), "java_library") { if strings.HasPrefix(ctx.ModuleType(), "java_binary") || strings.HasPrefix(ctx.ModuleType(), "java_library") || ctx.ModuleType() == "android_library" {
for _, d := range m.properties.Libs { for _, d := range m.properties.Libs {
neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d) neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d)
neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink" neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink"