-
Notifications
You must be signed in to change notification settings - Fork 31
misc: enable gradle cache #1427
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
base: main
Are you sure you want to change the base?
Changes from all commits
fb49c72
b308e9d
9816fb2
7da0bed
ddca24a
4992189
fb1f2e1
72cdffc
8ec9e91
06457f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,67 +59,79 @@ kotlin { | |
} | ||
} | ||
|
||
open class LocalTestServers : DefaultTask() { | ||
@Internal | ||
var server: Closeable? = null | ||
private set | ||
|
||
@Internal | ||
lateinit var main: String | ||
abstract class TestServerProvider : | ||
BuildService<TestServerProvider.Params>, | ||
AutoCloseable { | ||
interface Params : BuildServiceParameters { | ||
val sslConfigPath: Property<String> | ||
val classpath: ConfigurableFileCollection | ||
} | ||
|
||
@Internal | ||
lateinit var classpath: FileCollection | ||
private var server: Closeable? = null | ||
|
||
@Input | ||
lateinit var sslConfigPath: String | ||
fun startServers() { | ||
if (server != null) return | ||
|
||
@TaskAction | ||
fun exec() { | ||
try { | ||
println("[TestServers] start") | ||
val urlClassLoaderSource = classpath.map { file -> file.toURI().toURL() }.toTypedArray() | ||
val urlClassLoaderSource = parameters.classpath.map { it.toURI().toURL() }.toTypedArray() | ||
val loader = URLClassLoader(urlClassLoaderSource, ClassLoader.getSystemClassLoader()) | ||
|
||
val mainClass = loader.loadClass(main) | ||
val mainClass = loader.loadClass("aws.smithy.kotlin.runtime.http.test.util.TestServersKt") | ||
val main = mainClass.getMethod("startServers", String::class.java) | ||
server = main.invoke(null, sslConfigPath) as Closeable | ||
server = main.invoke(null, parameters.sslConfigPath.get()) as Closeable | ||
println("[TestServers] started") | ||
} catch (cause: Throwable) { | ||
println("[TestServers] failed: ${cause.message}") | ||
throw cause | ||
} | ||
} | ||
|
||
fun stop() { | ||
if (server != null) { | ||
server?.close() | ||
println("[TestServers] stop") | ||
} | ||
override fun close() { | ||
server?.close() | ||
server = null | ||
println("[TestServers] stopped") | ||
} | ||
} | ||
|
||
val testServerProvider = gradle.sharedServices.registerIfAbsent("testServers", TestServerProvider::class) { | ||
parameters.sslConfigPath.set(File.createTempFile("ssl-", ".cfg").absolutePath) | ||
} | ||
|
||
afterEvaluate { | ||
testServerProvider.get().parameters.classpath.from(kotlin.targets.getByName("jvm").compilations["test"].runtimeDependencyFiles!!) | ||
} | ||
|
||
abstract class StartTestServersTask : DefaultTask() { | ||
@get:Internal | ||
abstract val serverProvider: Property<TestServerProvider> | ||
|
||
@TaskAction | ||
fun start() { | ||
serverProvider.get().startServers() | ||
} | ||
} | ||
|
||
val osName = System.getProperty("os.name") | ||
|
||
val startTestServers = task<LocalTestServers>("startTestServers") { | ||
val startTestServers = tasks.register<StartTestServersTask>("startTestServers") { | ||
dependsOn(tasks["jvmJar"]) | ||
|
||
main = "aws.smithy.kotlin.runtime.http.test.util.TestServersKt" | ||
val kotlinCompilation = kotlin.targets.getByName("jvm").compilations["test"] | ||
classpath = kotlinCompilation.runtimeDependencyFiles!! | ||
sslConfigPath = File.createTempFile("ssl-", ".cfg").absolutePath | ||
usesService(testServerProvider) | ||
serverProvider.set(testServerProvider) | ||
} | ||
|
||
val testTasks = listOf("allTests", "jvmTest") | ||
.forEach { | ||
tasks.named(it) { | ||
dependsOn(startTestServers) | ||
usesService(testServerProvider) | ||
} | ||
} | ||
|
||
tasks.jvmTest { | ||
// set test environment for proxy tests | ||
systemProperty("MITM_PROXY_SCRIPTS_ROOT", projectDir.resolve("proxy-scripts").absolutePath) | ||
systemProperty("SSL_CONFIG_PATH", startTestServers.sslConfigPath) | ||
systemProperty("SSL_CONFIG_PATH", testServerProvider.get().parameters.sslConfigPath.get()) | ||
|
||
val enableProxyTestsProp = "aws.test.http.enableProxyTests" | ||
val runningInCodeBuild = System.getenv().containsKey("CODEBUILD_BUILD_ID") | ||
|
@@ -128,7 +140,3 @@ tasks.jvmTest { | |
|
||
systemProperty(enableProxyTestsProp, System.getProperties().getOrDefault(enableProxyTestsProp, shouldRunProxyTests)) | ||
} | ||
|
||
gradle.buildFinished { | ||
startTestServers.stop() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor to address
Comment on lines
-132
to
-134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do the test servers get shut down now, when does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,27 +85,27 @@ tasks.generateSmithyProjections { | |
buildClasspath.set(codegen) | ||
} | ||
|
||
data class BenchmarkModel(val name: String) { | ||
val projectionRootDir: File | ||
get() = layout.buildDirectory.dir("smithyprojections/${project.name}/$name/kotlin-codegen/src/main/kotlin").get().asFile.absoluteFile | ||
abstract class StageGeneratedSourcesTask : DefaultTask() { | ||
@get:Input | ||
abstract val projectName: Property<String> | ||
|
||
val sourceSetRootDir: File | ||
get() = layout.buildDirectory.dir("generated-src/src").get().asFile.absoluteFile | ||
} | ||
@get:InputDirectory | ||
abstract val smithyProjectionsDir: DirectoryProperty | ||
|
||
val benchmarkModels = listOf( | ||
"twitter", | ||
"countries-states", | ||
).map { BenchmarkModel(it) } | ||
@get:OutputDirectory | ||
abstract val generatedSourcesDir: DirectoryProperty | ||
|
||
val stageGeneratedSources = tasks.register("stageGeneratedSources") { | ||
group = "codegen" | ||
dependsOn(tasks.generateSmithyProjections) | ||
doLast { | ||
benchmarkModels.forEach { | ||
copy { | ||
from("${it.projectionRootDir}") | ||
into("${it.sourceSetRootDir}") | ||
@get:Inject | ||
abstract val fs: FileSystemOperations | ||
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't we use the built-in file operations like we do in other Gradle tasks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using |
||
|
||
@TaskAction | ||
fun stage() { | ||
val models = listOf("twitter", "countries-states") | ||
|
||
models.forEach { modelName -> | ||
fs.copy { | ||
from(smithyProjectionsDir.dir("${projectName.get()}/$modelName/kotlin-codegen/src/main/kotlin")) | ||
into(generatedSourcesDir.get().asFile) | ||
include("**/model/*.kt") | ||
include("**/serde/*.kt") | ||
exclude("**/serde/*OperationSerializer.kt") | ||
|
@@ -115,6 +115,20 @@ val stageGeneratedSources = tasks.register("stageGeneratedSources") { | |
} | ||
} | ||
|
||
val stageGeneratedSources = tasks.register<StageGeneratedSourcesTask>("stageGeneratedSources") { | ||
group = "codegen" | ||
dependsOn(tasks.generateSmithyProjections) | ||
projectName.set(project.name) | ||
smithyProjectionsDir.set(layout.buildDirectory.dir("smithyprojections")) | ||
generatedSourcesDir.set(layout.buildDirectory.dir("generated-src/src")) | ||
} | ||
|
||
afterEvaluate { | ||
tasks.named("jvmSourcesJar") { | ||
dependsOn(stageGeneratedSources) | ||
} | ||
} | ||
Comment on lines
+126
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to configure this for JVM tasks? Does this work for Native builds too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was gettting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well I am a couple CI checks away from merging kn-main into main, you should be able to test it out when you rebase There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just merge it, seems like work fines for Native |
||
|
||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor to get rid of Gradle script object references |
||
dependsOn(stageGeneratedSources) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,18 +58,24 @@ dependencies { | |
|
||
val generatedSrcDir = project.layout.projectDirectory.dir("generated-src/main/kotlin") | ||
|
||
val stageGeneratedSources = tasks.register("stageGeneratedSources") { | ||
group = "codegen" | ||
dependsOn(tasks.generateSmithyProjections) | ||
outputs.dir(generatedSrcDir) | ||
// FIXME - this task up-to-date checks are wrong, likely something is not setup right with inputs/outputs somewhere | ||
// for now just always run it | ||
outputs.upToDateWhen { false } | ||
doLast { | ||
listOf("xml", "json").forEach { projectionName -> | ||
val fromDir = smithyBuild.smithyKotlinProjectionSrcDir(projectionName) | ||
logger.info("copying from ${fromDir.get()} to $generatedSrcDir") | ||
copy { | ||
abstract class StageGeneratedSourcesTask : DefaultTask() { | ||
@get:InputDirectory | ||
abstract val projectionsDir: DirectoryProperty | ||
|
||
@get:OutputDirectory | ||
abstract val generatedSrcDir: DirectoryProperty | ||
|
||
@get:Inject | ||
abstract val fs: FileSystemOperations | ||
|
||
@TaskAction | ||
fun stageGeneratedSources() { | ||
val projections = listOf("xml", "json") | ||
|
||
projections.forEach { projectionName -> | ||
val fromDir = projectionsDir.dir("$projectionName/kotlin-codegen/src/main/kotlin") | ||
logger.info("copying from ${fromDir.get()} to ${generatedSrcDir.get()}") | ||
fs.copy { | ||
from(fromDir) | ||
into(generatedSrcDir) | ||
include("**/model/*.kt") | ||
|
@@ -83,6 +89,13 @@ val stageGeneratedSources = tasks.register("stageGeneratedSources") { | |
} | ||
} | ||
|
||
val stageGeneratedSources = tasks.register<StageGeneratedSourcesTask>("stageGeneratedSources") { | ||
group = "codegen" | ||
dependsOn(tasks.generateSmithyProjections) | ||
generatedSrcDir.set(layout.projectDirectory.dir("generated-src/main/kotlin")) | ||
projectionsDir.set(layout.buildDirectory.dir("smithyprojections/serde-tests")) | ||
} | ||
|
||
tasks.kotlinSourcesJar { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor to get rid of Gradle script object references |
||
dependsOn( | ||
tasks.generateSmithyProjections, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor to get rid of Gradle script object references