Merge "Check that API is up-to-date when building java_sdk_library"

This commit is contained in:
Paul Duffin 2022-05-27 16:01:57 +00:00 committed by Gerrit Code Review
commit 54e0bb61f0

View file

@ -697,10 +697,53 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
zipSyncCleanupCmd(rule, srcJarDir)
if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") {
d.generateCheckCurrentCheckedInApiIsUpToDateBuildRules(ctx)
// Make sure that whenever the API stubs are generated that the current checked in API files are
// checked to make sure that they are up-to-date.
cmd.Validation(d.checkCurrentApiTimestamp)
}
rule.Build("metalava", "metalava merged")
if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") {
if String(d.properties.Check_nullability_warnings) != "" {
if d.nullabilityWarningsFile == nil {
ctx.PropertyErrorf("check_nullability_warnings",
"Cannot specify check_nullability_warnings unless validating nullability")
}
checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "metalava", "check_nullability_warnings.timestamp")
msg := fmt.Sprintf(`\n******************************\n`+
`The warnings encountered during nullability annotation validation did\n`+
`not match the checked in file of expected warnings. The diffs are shown\n`+
`above. You have two options:\n`+
` 1. Resolve the differences by editing the nullability annotations.\n`+
` 2. Update the file of expected warnings by running:\n`+
` cp %s %s\n`+
` and submitting the updated file as part of your change.`,
d.nullabilityWarningsFile, checkNullabilityWarnings)
rule := android.NewRuleBuilder(pctx, ctx)
rule.Command().
Text("(").
Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
Text("&&").
Text("touch").Output(d.checkNullabilityWarningsTimestamp).
Text(") || (").
Text("echo").Flag("-e").Flag(`"` + msg + `"`).
Text("; exit 38").
Text(")")
rule.Build("nullabilityWarningsCheck", "nullability warnings check")
}
}
func (d *Droidstubs) generateCheckCurrentCheckedInApiIsUpToDateBuildRules(ctx android.ModuleContext) {
if len(d.Javadoc.properties.Out) > 0 {
ctx.PropertyErrorf("out", "out property may not be combined with check_api")
}
@ -776,42 +819,6 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Text(")")
rule.Build("metalavaCurrentApiUpdate", "update current API")
}
if String(d.properties.Check_nullability_warnings) != "" {
if d.nullabilityWarningsFile == nil {
ctx.PropertyErrorf("check_nullability_warnings",
"Cannot specify check_nullability_warnings unless validating nullability")
}
checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "metalava", "check_nullability_warnings.timestamp")
msg := fmt.Sprintf(`\n******************************\n`+
`The warnings encountered during nullability annotation validation did\n`+
`not match the checked in file of expected warnings. The diffs are shown\n`+
`above. You have two options:\n`+
` 1. Resolve the differences by editing the nullability annotations.\n`+
` 2. Update the file of expected warnings by running:\n`+
` cp %s %s\n`+
` and submitting the updated file as part of your change.`,
d.nullabilityWarningsFile, checkNullabilityWarnings)
rule := android.NewRuleBuilder(pctx, ctx)
rule.Command().
Text("(").
Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
Text("&&").
Text("touch").Output(d.checkNullabilityWarningsTimestamp).
Text(") || (").
Text("echo").Flag("-e").Flag(`"` + msg + `"`).
Text("; exit 38").
Text(")")
rule.Build("nullabilityWarningsCheck", "nullability warnings check")
}
}
func StubsDefaultsFactory() android.Module {