Deprecate depfile in gensrcs

All existing gensrsc modulePartners who use the property can use BUILD_BROKEN_DEP_FILE to bypass the error

Test: CI
Bug: 179452413
Fix: 179452413
Change-Id: I7cd39484b43eba693d79188b9a374f192198f90f
This commit is contained in:
Vinh Tran
2022-06-10 14:23:27 -04:00
parent 1c6502eba2
commit 140d588a3d
4 changed files with 85 additions and 0 deletions

View File

@@ -1693,6 +1693,10 @@ func (c *deviceConfig) BuildBrokenInputDir(name string) bool {
return InList(name, c.config.productVariables.BuildBrokenInputDirModules)
}
func (c *deviceConfig) BuildBrokenDepfile() bool {
return Bool(c.config.productVariables.BuildBrokenDepfile)
}
func (c *deviceConfig) RequiresInsecureExecmemForSwiftshader() bool {
return c.config.productVariables.RequiresInsecureExecmemForSwiftshader
}

View File

@@ -428,6 +428,7 @@ type productVariables struct {
ShippingApiLevel *string `json:",omitempty"`
BuildBrokenDepfile *bool `json:",omitempty"`
BuildBrokenEnforceSyspropOwner bool `json:",omitempty"`
BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"`
BuildBrokenVendorPropertyNamespace bool `json:",omitempty"`

View File

@@ -590,6 +590,18 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) {
}
func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Allowlist genrule to use depfile until we have a solution to remove it.
// TODO(b/235582219): Remove allowlist for genrule
if ctx.ModuleType() == "gensrcs" &&
!ctx.DeviceConfig().BuildBrokenDepfile() &&
Bool(g.properties.Depfile) {
ctx.PropertyErrorf(
"depfile",
"Deprecated to ensure the module type is convertible to Bazel. "+
"Try specifying the dependencies explicitly so that there is no need to use depfile. "+
"If not possible, the escape hatch is to use BUILD_BROKEN_DEPFILE to bypass the error.")
}
g.generateCommonBuildActions(ctx)
// For <= 6 outputs, just embed those directly in the users. Right now, that covers >90% of

View File

@@ -15,6 +15,7 @@
package genrule
import (
"fmt"
"os"
"regexp"
"testing"
@@ -626,6 +627,73 @@ func TestGenSrcs(t *testing.T) {
}
}
func TestGensrcsBuildBrokenDepfile(t *testing.T) {
tests := []struct {
name string
prop string
BuildBrokenDepfile *bool
err string
}{
{
name: `error when BuildBrokenDepfile is set to false`,
prop: `
depfile: true,
cmd: "cat $(in) > $(out) && cat $(depfile)",
`,
BuildBrokenDepfile: proptools.BoolPtr(false),
err: "depfile: Deprecated to ensure the module type is convertible to Bazel",
},
{
name: `error when BuildBrokenDepfile is not set`,
prop: `
depfile: true,
cmd: "cat $(in) > $(out) && cat $(depfile)",
`,
err: "depfile: Deprecated to ensure the module type is convertible to Bazel.",
},
{
name: `no error when BuildBrokenDepfile is explicitly set to true`,
prop: `
depfile: true,
cmd: "cat $(in) > $(out) && cat $(depfile)",
`,
BuildBrokenDepfile: proptools.BoolPtr(true),
},
{
name: `no error if depfile is not set`,
prop: `
cmd: "cat $(in) > $(out)",
`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
bp := fmt.Sprintf(`
gensrcs {
name: "foo",
srcs: ["data.txt"],
%s
}`, test.prop)
var expectedErrors []string
if test.err != "" {
expectedErrors = append(expectedErrors, test.err)
}
android.GroupFixturePreparers(
prepareForGenRuleTest,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
if test.BuildBrokenDepfile != nil {
variables.BuildBrokenDepfile = test.BuildBrokenDepfile
}
}),
).
ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(expectedErrors)).
RunTestWithBp(t, bp)
})
}
}
func TestGenruleDefaults(t *testing.T) {
bp := `
genrule_defaults {