Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4f6ebaf authored by Colin Cross's avatar Colin Cross
Browse files

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
parent 9dd2c4d5
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -2559,17 +2559,20 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
					// in the context of proper cc.Modules.
					if ccWholeStaticLib, ok := ccDep.(*Module); ok {
						staticLib := ccWholeStaticLib.linker.(libraryInterface)
						if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
							postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
							for i := range missingDeps {
								missingDeps[i] += postfix
							}
							ctx.AddMissingDependencies(missingDeps)
						}
						if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
							depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
						if objs := staticLib.objs(); len(objs.objFiles) > 0 {
							depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(objs)
						} else {
							depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
							// This case normally catches prebuilt static
							// libraries, but it can also occur when
							// AllowMissingDependencies is on and the
							// dependencies has no sources of its own
							// but has a whole_static_libs dependency
							// on a missing library.  We want to depend
							// on the .a file so that there is something
							// in the dependency tree that contains the
							// error rule for the missing transitive
							// dependency.
							depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
						}
					} else {
						ctx.ModuleErrorf(
+43 −0
Original line number Diff line number Diff line
@@ -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)
	}

}
+0 −11
Original line number Diff line number Diff line
@@ -338,10 +338,6 @@ type libraryDecorator struct {
	flagExporter
	stripper Stripper

	// If we're used as a whole_static_lib, our missing dependencies need
	// to be given
	wholeStaticMissingDeps []string

	// For whole_static_libs
	objects Objects

@@ -682,7 +678,6 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
}

type libraryInterface interface {
	getWholeStaticMissingDeps() []string
	static() bool
	shared() bool
	objs() Objects
@@ -889,8 +884,6 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext,

	library.coverageOutputFile = TransformCoverageFilesToZip(ctx, library.objects, ctx.ModuleName())

	library.wholeStaticMissingDeps = ctx.GetMissingDependencies()

	ctx.CheckbuildFile(outputFile)

	return outputFile
@@ -1182,10 +1175,6 @@ func (library *libraryDecorator) buildShared() bool {
		BoolDefault(library.SharedProperties.Shared.Enabled, true)
}

func (library *libraryDecorator) getWholeStaticMissingDeps() []string {
	return append([]string(nil), library.wholeStaticMissingDeps...)
}

func (library *libraryDecorator) objs() Objects {
	return library.objects
}