Remove droidstubs timestamps from droidcore dependencies

Currently, {check current api timestamp, check last released api
timestamp, api lint timestmp, check nullabilty warnings timestamp} of
all droidstubs modules are dependencies of `droidcore`. In other words,
metalava build action is run for all droidstubs modules when building
`droid` even if the stubs of the module is not used.

This is problematic from build performance perspective, as the
computation-heavy metalava build action would run in all `m` builds just
for building the timestamp files even if the stubs is not built. To fix
this behavior, this change modifies the dependencies between the
timestamp files. Specifically, all non-null non-check current api
timestamp timestamp files are now validations of the check current api
timestamp file. Given that the check current api timestamp files are the
validations of (from-text) stubs, all other timestamp files will be
built when the stubs are consumed. To summarize the changes of the
behavior:

Currently without this change:
- check current api timestamp files of all droidstubs modules are built
  when building `checkapi` and `droid`
- check last released timestamp files of all droidstubs modules are
  built when building `checkapi` and `droid`
- api lint timestamp files of all droidstubs modules are built when
  building `checkapi` and `droid`
- check nullability warnings timestamp files of all droidstubs modules
  are built when building `droid`

With this change:
- check current api timestamp files of all droidstubs modules are built
  when building `checkapi`, but are only built when the stubs are built
  when building `droid`.
- check last released timestamp files of all droidstubs modules are
  built when building `checkapi`, but are only built when the stubs are
  built when building `droid`.
- api lint timestamp files of all droidstubs modules are built when
  building `checkapi`, but are only built when the stubs are built when
  building `droid`.
- check nullability warnings timestamp files are built when building
  `checkapi`, but are only built when the stubs are built when building
  `droid`.

Note that the check nullability timestamp files were not built when
building `checkapi`, but are now built alongside with the check current
api timestamp files.

Test: diff aninja query of checkapi timestamp files
Bug: 389719475
Change-Id: Ic12b97ff7a7f1b230e8859e12de8fef8c3c1c832
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 91be7a4..0c6bab3 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -1199,7 +1199,6 @@
 	if d.checkCurrentApiTimestamp != nil {
 		ctx.Phony(fmt.Sprintf("%s-check-current-api", d.Name()), d.checkCurrentApiTimestamp)
 		ctx.Phony("checkapi", d.checkCurrentApiTimestamp)
-		ctx.Phony("droidcore", d.checkCurrentApiTimestamp)
 	}
 	if d.updateCurrentApiTimestamp != nil {
 		ctx.Phony(fmt.Sprintf("%s-update-current-api", d.Name()), d.updateCurrentApiTimestamp)
@@ -1207,17 +1206,12 @@
 	}
 	if d.checkLastReleasedApiTimestamp != nil {
 		ctx.Phony(fmt.Sprintf("%s-check-last-released-api", d.Name()), d.checkLastReleasedApiTimestamp)
-		ctx.Phony("checkapi", d.checkLastReleasedApiTimestamp)
-		ctx.Phony("droidcore", d.checkLastReleasedApiTimestamp)
 	}
 	if d.apiLintTimestamp != nil {
 		ctx.Phony(fmt.Sprintf("%s-api-lint", d.Name()), d.apiLintTimestamp)
-		ctx.Phony("checkapi", d.apiLintTimestamp)
-		ctx.Phony("droidcore", d.apiLintTimestamp)
 	}
 	if d.checkNullabilityWarningsTimestamp != nil {
 		ctx.Phony(fmt.Sprintf("%s-check-nullability-warnings", d.Name()), d.checkNullabilityWarningsTimestamp)
-		ctx.Phony("droidcore", d.checkNullabilityWarningsTimestamp)
 	}
 }
 
@@ -1264,6 +1258,41 @@
 	stubCmdParams.stubsType = Exportable
 	d.exportableStubCmd(ctx, stubCmdParams)
 
+	if String(d.properties.Check_nullability_warnings) != "" {
+		if d.everythingArtifacts.nullabilityWarningsFile == nil {
+			ctx.PropertyErrorf("check_nullability_warnings",
+				"Cannot specify check_nullability_warnings unless validating nullability")
+		}
+
+		checkNullabilityWarningsPath := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
+
+		d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, Everything.String(), "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.everythingArtifacts.nullabilityWarningsFile, checkNullabilityWarningsPath)
+
+		rule := android.NewRuleBuilder(pctx, ctx)
+
+		rule.Command().
+			Text("(").
+			Text("diff").Input(checkNullabilityWarningsPath).Input(d.everythingArtifacts.nullabilityWarningsFile).
+			Text("&&").
+			Text("touch").Output(d.checkNullabilityWarningsTimestamp).
+			Text(") || (").
+			Text("echo").Flag("-e").Flag(`"` + msg + `"`).
+			Text("; exit 38").
+			Text(")")
+
+		rule.Build("nullabilityWarningsCheck", "nullability warnings check")
+	}
+
 	if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") {
 
 		if len(d.Javadoc.properties.Out) > 0 {
@@ -1313,13 +1342,25 @@
 			`Note that DISABLE_STUB_VALIDATION=true does not bypass checkapi.\n`+
 			`******************************\n`, ctx.ModuleName())
 
-		rule.Command().
+		cmd := rule.Command().
 			Text("touch").Output(d.checkCurrentApiTimestamp).
 			Text(") || (").
 			Text("echo").Flag("-e").Flag(`"` + msg + `"`).
 			Text("; exit 38").
 			Text(")")
 
+		if d.apiLintTimestamp != nil {
+			cmd.Validation(d.apiLintTimestamp)
+		}
+
+		if d.checkLastReleasedApiTimestamp != nil {
+			cmd.Validation(d.checkLastReleasedApiTimestamp)
+		}
+
+		if d.checkNullabilityWarningsTimestamp != nil {
+			cmd.Validation(d.checkNullabilityWarningsTimestamp)
+		}
+
 		rule.Build("metalavaCurrentApiCheck", "check current API")
 
 		d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, Everything.String(), "update_current_api.timestamp")
@@ -1349,41 +1390,6 @@
 		rule.Build("metalavaCurrentApiUpdate", "update current API")
 	}
 
-	if String(d.properties.Check_nullability_warnings) != "" {
-		if d.everythingArtifacts.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, Everything.String(), "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.everythingArtifacts.nullabilityWarningsFile, checkNullabilityWarnings)
-
-		rule := android.NewRuleBuilder(pctx, ctx)
-
-		rule.Command().
-			Text("(").
-			Text("diff").Input(checkNullabilityWarnings).Input(d.everythingArtifacts.nullabilityWarningsFile).
-			Text("&&").
-			Text("touch").Output(d.checkNullabilityWarningsTimestamp).
-			Text(") || (").
-			Text("echo").Flag("-e").Flag(`"` + msg + `"`).
-			Text("; exit 38").
-			Text(")")
-
-		rule.Build("nullabilityWarningsCheck", "nullability warnings check")
-	}
-
 	android.SetProvider(ctx, DroidStubsInfoProvider, DroidStubsInfo{
 		CurrentApiTimestamp: d.CurrentApiTimestamp(),
 		EverythingArtifacts: StubsArtifactsInfo{