Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved the test temp directory inside the gradle build directory #1472

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

@@ -0,0 +1,15 @@
package com.google.devtools.ksp

import org.gradle.api.tasks.Input
import org.gradle.api.tasks.LocalState
import org.gradle.process.CommandLineArgumentProvider
import java.io.File

class RelativizingLocalPathProvider(
@Input
val argumentName: String,
@LocalState
val file: File
) : CommandLineArgumentProvider {
override fun asArguments(): Iterable<String> = listOf("-D$argumentName=${file.absolutePath}")
}

This file was deleted.

18 changes: 8 additions & 10 deletions compiler-plugin/build.gradle.kts
@@ -1,4 +1,4 @@
import com.google.devtools.ksp.RelativizingPathProvider
import com.google.devtools.ksp.RelativizingLocalPathProvider
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

evaluationDependsOn(":common-util")
Expand Down Expand Up @@ -110,17 +110,15 @@ tasks.test {
events("passed", "skipped", "failed")
}

lateinit var tempTestDir: File
doFirst {
val ideaHomeDir = buildDir.resolve("tmp/ideaHome").takeIf { it.exists() || it.mkdirs() }!!
jvmArgumentProviders.add(RelativizingPathProvider("idea.home.path", ideaHomeDir))
val ideaHomeDir = File(buildDir, "tmp/ideaHome")
jvmArgumentProviders.add(RelativizingLocalPathProvider("idea.home.path", ideaHomeDir))

tempTestDir = createTempDir()
jvmArgumentProviders.add(RelativizingPathProvider("java.io.tmpdir", tempTestDir))
}
val tempTestDir = File(buildDir, "tmp/test")
jvmArgumentProviders.add(RelativizingLocalPathProvider("java.io.tmpdir", tempTestDir))

doLast {
delete(tempTestDir)
doFirst {
if (!ideaHomeDir.exists()) ideaHomeDir.mkdirs()
tempTestDir.deleteRecursively()
}
}

Expand Down
33 changes: 18 additions & 15 deletions gradle-plugin/build.gradle.kts
@@ -1,3 +1,4 @@
import com.google.devtools.ksp.RelativizingLocalPathProvider
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

description = "Kotlin Symbol Processor"
Expand Down Expand Up @@ -96,7 +97,8 @@ signing {
* Create a properties file with that can be read from the gradle-plugin tests to setup test
* projects.
*/
val testPropsOutDir = project.layout.buildDirectory.dir("test-config")
val tempTestDir = File(buildDir, "tmp/test")
val testPropsOutDir: Provider<Directory> = project.layout.buildDirectory.dir("test-config")
val writeTestPropsTask = tasks.register<WriteProperties>("prepareTestConfiguration") {
description = "Generates a properties file with the current environment for gradle integration tests"
this.setOutputFile(
Expand All @@ -105,19 +107,14 @@ val writeTestPropsTask = tasks.register<WriteProperties>("prepareTestConfigurati
}
)
property("kspVersion", version)
property("mavenRepoDir", File(rootProject.buildDir, "repos/test").absolutePath)
property("kspProjectRootDir", rootProject.projectDir.absolutePath)
property("processorClasspath", project.tasks["compileTestKotlin"].outputs.files.asPath)
}

normalization {
runtimeClasspath {
properties("**/testprops.properties") {
ignoreProperty("kspProjectRootDir")
ignoreProperty("mavenRepoDir")
ignoreProperty("processorClasspath")
}
}
property("mavenRepoDir", File(rootProject.buildDir, "repos/test").toRelativeString(projectDir))
property("kspProjectRootDir", rootProject.projectDir.toRelativeString(projectDir))
property(
"processorClasspath",
project.tasks["compileTestKotlin"].outputs.files
.map { it.toRelativeString(projectDir) }
.joinToString(File.pathSeparator)
)
}

java {
Expand All @@ -136,10 +133,16 @@ tasks.named("processTestResources").configure {
dependsOn(writeTestPropsTask)
}

tasks.named<Test>("test").configure {
tasks.test {
dependsOn(":api:publishAllPublicationsToTestRepository")
dependsOn(":gradle-plugin:publishAllPublicationsToTestRepository")
dependsOn(":symbol-processing:publishAllPublicationsToTestRepository")

jvmArgumentProviders.add(RelativizingLocalPathProvider("java.io.tmpdir", tempTestDir))

doFirst {
tempTestDir.deleteRecursively()
}
}

abstract class WriteVersionSrcTask @Inject constructor(
Expand Down
Expand Up @@ -58,7 +58,7 @@ data class TestConfig(
kspProjectProperties["agpBaseVersion"] as String
}

val mavenRepoPath = mavenRepoDir.path.replace(File.separatorChar, '/')
val mavenRepoPath = mavenRepoDir.absolutePath.replace(File.separatorChar, '/')

companion object {
/**
Expand All @@ -71,10 +71,17 @@ data class TestConfig(
}
return TestConfig(
kspProjectDir = File(props.get("kspProjectRootDir") as String),
processorClasspath = props.get("processorClasspath") as String,
processorClasspath = absoluteClasspath(props.get("processorClasspath") as String),
mavenRepoDir = File(props.get("mavenRepoDir") as String),
kspVersion = props.get("kspVersion") as String
)
}

private fun absoluteClasspath(classpathString: String): String {
return classpathString
.split(File.pathSeparator)
.map { File(it).absolutePath }
.joinToString(File.pathSeparator)
}
}
}
20 changes: 15 additions & 5 deletions integration-tests/build.gradle.kts
@@ -1,4 +1,4 @@
import com.google.devtools.ksp.RelativizingInternalPathProvider
import com.google.devtools.ksp.RelativizingLocalPathProvider

val junitVersion: String by project
val kotlinBaseVersion: String by project
Expand All @@ -19,16 +19,26 @@ dependencies {
}

tasks.named<Test>("test") {
systemProperty("kotlinVersion", kotlinBaseVersion)
systemProperty("kspVersion", version)
systemProperty("agpVersion", agpBaseVersion)
jvmArgumentProviders.add(RelativizingInternalPathProvider("testRepo", File(rootProject.buildDir, "repos/test")))
dependsOn(":api:publishAllPublicationsToTestRepository")
dependsOn(":gradle-plugin:publishAllPublicationsToTestRepository")
dependsOn(":symbol-processing:publishAllPublicationsToTestRepository")
dependsOn(":symbol-processing-cmdline:publishAllPublicationsToTestRepository")
dependsOn(":kotlin-analysis-api:publishAllPublicationsToTestRepository")

systemProperty("kotlinVersion", kotlinBaseVersion)
systemProperty("kspVersion", version)
systemProperty("agpVersion", agpBaseVersion)

val testBuildDir = File(buildDir, "tmp/test")
jvmArgumentProviders.add(RelativizingLocalPathProvider("java.io.tmpdir", testBuildDir))
val testRepo = File(rootProject.buildDir, "repos/test")
jvmArgumentProviders.add(RelativizingLocalPathProvider("testRepo", testRepo))

doFirst {
if (!testRepo.exists()) testRepo.mkdirs()
testBuildDir.deleteRecursively()
}

// JDK_9 environment property is required.
// To add a custom location (if not detected automatically) follow https://docs.gradle.org/current/userguide/toolchains.html#sec:custom_loc
if (System.getenv("JDK_9") == null) {
Expand Down
18 changes: 8 additions & 10 deletions kotlin-analysis-api/build.gradle.kts
@@ -1,5 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.google.devtools.ksp.RelativizingPathProvider
import com.google.devtools.ksp.RelativizingLocalPathProvider

description = "Kotlin Symbol Processing implementation using Kotlin Analysis API"

Expand Down Expand Up @@ -126,17 +126,15 @@ tasks.test {
events("passed", "skipped", "failed")
}

lateinit var tempTestDir: File
doFirst {
val ideaHomeDir = buildDir.resolve("tmp/ideaHome").takeIf { it.exists() || it.mkdirs() }!!
jvmArgumentProviders.add(RelativizingPathProvider("idea.home.path", ideaHomeDir))
val ideaHomeDir = File(buildDir, "tmp/ideaHome")
jvmArgumentProviders.add(RelativizingLocalPathProvider("idea.home.path", ideaHomeDir))

tempTestDir = createTempDir()
jvmArgumentProviders.add(RelativizingPathProvider("java.io.tmpdir", tempTestDir))
}
val tempTestDir = File(buildDir, "tmp/test")
jvmArgumentProviders.add(RelativizingLocalPathProvider("java.io.tmpdir", tempTestDir))

doLast {
delete(tempTestDir)
doFirst {
if (!ideaHomeDir.exists()) ideaHomeDir.mkdirs()
tempTestDir.deleteRecursively()
}
}

Expand Down