Skip to content

Commit

Permalink
Merge "Remove GithubPresubmitValidator" into studio-main
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-pollom authored and Android (Google) Code Review committed Mar 15, 2024
2 parents aed85e2 + c0512e1 commit b835bbc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.google.android.gradle_recipe.converter.converters.RecipeConverter.Mod
import com.google.android.gradle_recipe.converter.converters.RecipeConverter.Mode.SOURCE
import com.google.android.gradle_recipe.converter.converters.RecipeConverter.Mode.WORKINGCOPY
import com.google.android.gradle_recipe.converter.converters.RecursiveConverter
import com.google.android.gradle_recipe.converter.validators.GithubPresubmitValidator
import com.google.android.gradle_recipe.converter.validators.SourceValidator
import com.google.android.gradle_recipe.converter.validators.WorkingCopyValidator
import java.nio.file.Files
import java.nio.file.Path
Expand Down Expand Up @@ -161,65 +161,32 @@ fun main(args: Array<String>) {
// ensure no extra/unused values
validateNullArg(destination, "'destination' must not be provided for subcommand '$COMMAND_VALIDATE'")
validateNullArg(gradleVersion, "'gradleVersion' must not be provided for subcommand '$COMMAND_VALIDATE'")
validateNullArg(
sourceAll,
"'sourceAll' must not be provided for subcommand '$COMMAND_VALIDATE'"
)
if (source == null) {
printErrorAndTerminate(
"'source' must not be null with subcommand '$COMMAND_VALIDATE'"
)
}

if (mode != null) {
val cliMode = mode
if (cliMode != WORKINGCOPY) {
printErrorAndTerminate("""
'$COMMAND_VALIDATE' command with a mode, requires value '$WORKINGCOPY'.
To convert all recipes from '$SOURCE' mode, omit the argument
""".trimIndent())
when (mode) {
WORKINGCOPY -> {
val validator =
WorkingCopyValidator(context, agpVersion?.let { FullAgpVersion.of(it) })
validator.validate(Path.of(source))
}

// ensure no extra/unused values
validateNullArg(
sourceAll,
"'sourceAll' must not be provided for subcommand '$COMMAND_VALIDATE' and 'mode=$WORKINGCOPY'"
)

val validator =
WorkingCopyValidator(context, agpVersion?.let { FullAgpVersion.of(it) })
validator.validate(
Path.of(
source
?: printErrorAndTerminate("Source must not be null with subcommand '$COMMAND_VALIDATE' and 'mode=$WORKINGCOPY'")
)
)
} else {
// TODO(b/328820202) modify this else block to check a single recipe in source mode.
// ensure no extra/unused values
validateNullArg(
source,
"'source' must not be provided for subcommand '$COMMAND_VALIDATE' when not providing 'mode' argument"
)
validateNullArg(
agpVersion,
"'agpVersion' must not be provided for subcommand '$COMMAND_VALIDATE' when not providing 'mode' argument"
)
validateNullArg(
repoLocation,
"'repoLocation' must not be provided for subcommand '$COMMAND_VALIDATE' when not providing 'mode' argument"
)
validateNullArg(
gradlePath,
"'gradlePath' must not be provided for subcommand '$COMMAND_VALIDATE' when not providing 'mode' argument"
)
validateNullArg(
javaHome,
"'javaHome' must not be provided for subcommand '$COMMAND_VALIDATE' when not providing 'mode' argument"
)
validateNullArg(
androidHome,
"'androidHome' must not be provided for subcommand '$COMMAND_VALIDATE' when not providing 'mode' argument"
)

val validator = GithubPresubmitValidator(context)
validator.validateAll(
Path.of(
sourceAll
?: printErrorAndTerminate("SourceAll must not be null with subcommand '$COMMAND_VALIDATE' when not providing 'mode' argument")
SOURCE -> {
val validator =
SourceValidator(context, agpVersion?.let { FullAgpVersion.of(it) })
validator.validate(Path.of(source))
}
else -> {
printErrorAndTerminate(
"'$COMMAND_VALIDATE' command requires a 'mode' value of '$WORKINGCOPY' or '$SOURCE'"
)
)
}
}
}
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class GradleRecipeTest {
System.getProperty("gradle_path")
?: error("Missing required system property \"gradle_path\".")
val jdkVersion = System.getProperty("jdk_version")
val validateSource =
System.getProperty("validate_source")?.toBooleanStrict()
?: error("Missing required system property \"validate_source\".")


val context = DefaultContext.createDefaultContext(Paths.get("tools/gradle-recipes"))
val fullAgpVersion = FullAgpVersion.of(agpVersion)
Expand All @@ -71,6 +75,34 @@ class GradleRecipeTest {
val repos = System.getProperty("repos").split(",").map { File(it) }
repos.forEach { Gradle.addRepo(it, repoDir) }

// Validate with --mode source to test that code path, but the validation itself is
// redundant because the recipe is validated with --mode workingcopy below.
// Because of this redundancy, we only validate the source copy for "ToT" AGP.
if (validateSource) {
main(
arrayOf(
"validate",
"--mode",
"source",
"--source",
source.toFile().absolutePath,
"--gradleRecipesFolder",
Paths.get("tools/gradle-recipes").toFile().absolutePath,
"--agpVersion",
agpVersion,
"--repoLocation",
FileUtils.toSystemIndependentPath(repoDir.absolutePath),
"--gradlePath",
File(gradlePath).toURI().toString(),
"--javaHome",
getJDKPath(jdkVersion).toFile().absolutePath,
"--androidHome",
File(TestUtils.getRelativeSdk()).absolutePath,
"--ci"
)
)
}

// Convert to working copy
main(
arrayOf(
Expand Down
1 change: 1 addition & 0 deletions recipes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def recipe_test(
"-Dversion_mappings_file=$(location :version_mappings.txt)",
"-Dall_tested_agp_versions=" + ",".join(test_scenarios),
"-Dconvert_debug=true",
"-Dvalidate_source=" + ("true" if agp_version == "ToT" else "false"),
] +
(["-Djdk_version=" + str(test_scenarios[agp_version].get("jdk_version"))] if test_scenarios[agp_version].get("jdk_version") else []) +
(select({
Expand Down

0 comments on commit b835bbc

Please sign in to comment.