Unverified Commit a91b813e authored by david-perez's avatar david-perez Committed by GitHub
Browse files

Fix `modifyMtime` task when `generateSmithyBuild` task is up to date (#1471)

When `generateSmithyBuild` task is up to date, the hashes of the build
are not calculated, so `modifyMtime` fails, because it expects them to
be registered in Gradle's project properties. This can happen if you run
a command like `./gradlew codegen-server-test:test` twice consecutively.

In this case, we should skip the `modifyMtime` task altogether.
Everything is up to date, so no codegen will run, and no artifacts will
change.
parent 5af3b106
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ fun Project.registerGenerateSmithyBuildTask(

            // If this is a rebuild, cache all the hashes of the generated Rust files. These are later used by the
            // `modifyMtime` task.
            project.extra["previousBuildHashes"] = project.buildDir.walk()
            project.extra[previousBuildHashesKey] = project.buildDir.walk()
                .filter { it.isFile }
                .map {
                    getChecksumForFile(it) to it.lastModified()
@@ -174,6 +174,8 @@ fun Project.registerGenerateCargoConfigTomlTask(
    }
}

const val previousBuildHashesKey = "previousBuildHashes"

fun Project.registerModifyMtimeTask() {
    // Cargo uses `mtime` (among other factors) to determine whether a compilation unit needs a rebuild. While developing,
    // it is likely that only a small number of the generated crate files are modified across rebuilds. This task compares
@@ -187,7 +189,10 @@ fun Project.registerModifyMtimeTask() {
        dependsOn("generateSmithyBuild")

        doFirst {
            @Suppress("UNCHECKED_CAST") val previousBuildHashes: Map<String, Long> = project.extra["previousBuildHashes"] as Map<String, Long>
            if (!project.extra.has(previousBuildHashesKey)) {
                println("No hashes from a previous build exist because `generateSmithyBuild` is up to date, skipping `mtime` fixups")
            } else {
                @Suppress("UNCHECKED_CAST") val previousBuildHashes: Map<String, Long> = project.extra[previousBuildHashesKey] as Map<String, Long>

                project.buildDir.walk()
                    .filter { it.isFile }
@@ -203,6 +208,7 @@ fun Project.registerModifyMtimeTask() {
            }
        }
    }
}

fun Project.registerCargoCommandsTasks(
    outputDir: File,