Simplify missing whole_static_libs checking

Whole_static_libs required custom error checking when
AllowMissingDependencies was set because it could end up depending
on an empty list of objects, which would leave nothing in the
dependency tree that had been replaced with an ErrorRule.
Reuse the prebuilts case to depend on the .a file when there
are no objects and remove the custom error handling.

Test: TestEmptyWholeStaticLibsAllowMissingDependencies
Change-Id: Ic3216235f7e5ae8b5b6ab31ef2ca35c3994d82aa
This commit is contained in:
Colin Cross
2020-09-22 18:11:25 -07:00
parent 9dd2c4d543
commit e4f6ebaf6c
3 changed files with 56 additions and 21 deletions

View File

@@ -3780,3 +3780,46 @@ func TestProductVariableDefaults(t *testing.T) {
t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
}
}
func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
t.Parallel()
bp := `
cc_library_static {
name: "libfoo",
srcs: ["foo.c"],
whole_static_libs: ["libbar"],
}
cc_library_static {
name: "libbar",
whole_static_libs: ["libmissing"],
}
`
config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
ctx := CreateTestContext()
ctx.SetAllowMissingDependencies(true)
ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
if g, w := libbar.Rule, android.ErrorRule; g != w {
t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
}
if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
t.Errorf("Expected libbar error to contain %q, was %q", w, g)
}
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
}
}