Skip to content

Commit fb49c72

Browse files
committed
fix gradle cache issue
1 parent 61185ca commit fb49c72

File tree

4 files changed

+101
-73
lines changed

4 files changed

+101
-73
lines changed

codegen/smithy-kotlin-codegen/build.gradle.kts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ val codegenVersion: String by project
2020
group = "software.amazon.smithy.kotlin"
2121
version = codegenVersion
2222

23-
val sdkVersion: String by project
24-
val runtimeVersion = sdkVersion
23+
val runtimeVersion: Provider<String> = providers.gradleProperty("sdkVersion")
2524

2625
dependencies {
2726
api(libs.smithy.codegen.core)
@@ -42,16 +41,17 @@ dependencies {
4241
}
4342

4443
val generateSdkRuntimeVersion by tasks.registering {
45-
// generate the version of the runtime to use as a resource.
46-
// this keeps us from having to manually change version numbers in multiple places
47-
val resourcesDir = layout.buildDirectory.dir("resources/main/software/amazon/smithy/kotlin/codegen/core").get()
48-
val versionFile = file("$resourcesDir/sdk-version.txt")
49-
val gradlePropertiesFile = rootProject.file("gradle.properties")
50-
inputs.file(gradlePropertiesFile)
44+
val resourcesDir = layout.buildDirectory.dir("resources/main/software/amazon/smithy/kotlin/codegen/core")
45+
val versionFile = resourcesDir.map { it.file("sdk-version.txt") }
46+
47+
// declare inputs/outputs via providers
48+
inputs.property("runtimeVersion", runtimeVersion)
5149
outputs.file(versionFile)
52-
sourceSets.main.get().output.dir(resourcesDir)
50+
5351
doLast {
54-
versionFile.writeText(runtimeVersion)
52+
val version = inputs.properties["runtimeVersion"] as String
53+
val file = versionFile.get().asFile
54+
file.writeText(version)
5555
}
5656
}
5757

runtime/protocol/http-client-engines/test-suite/build.gradle.kts

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,67 +58,78 @@ kotlin {
5858
}
5959
}
6060

61-
open class LocalTestServers : DefaultTask() {
62-
@Internal
63-
var server: Closeable? = null
64-
private set
61+
val osName = System.getProperty("os.name")
6562

66-
@Internal
67-
lateinit var main: String
63+
abstract class TestServerService :
64+
BuildService<TestServerService.Params>,
65+
AutoCloseable {
66+
interface Params : BuildServiceParameters {
67+
val sslConfigPath: Property<String>
68+
val mainClass: Property<String>
69+
val classpath: ConfigurableFileCollection
70+
}
6871

69-
@Internal
70-
lateinit var classpath: FileCollection
72+
private var server: Closeable? = null
7173

72-
@Input
73-
lateinit var sslConfigPath: String
74+
fun startServers() {
75+
if (server != null) return
7476

75-
@TaskAction
76-
fun exec() {
7777
try {
7878
println("[TestServers] start")
79-
val urlClassLoaderSource = classpath.map { file -> file.toURI().toURL() }.toTypedArray()
79+
val urlClassLoaderSource = parameters.classpath.map { it.toURI().toURL() }.toTypedArray()
8080
val loader = URLClassLoader(urlClassLoaderSource, ClassLoader.getSystemClassLoader())
8181

82-
val mainClass = loader.loadClass(main)
83-
val main = mainClass.getMethod("startServers", String::class.java)
84-
server = main.invoke(null, sslConfigPath) as Closeable
82+
val mainClass = loader.loadClass(parameters.mainClass.get())
83+
val method = mainClass.getMethod("startServers", String::class.java)
84+
server = method.invoke(null, parameters.sslConfigPath.get()) as Closeable
8585
println("[TestServers] started")
8686
} catch (cause: Throwable) {
8787
println("[TestServers] failed: ${cause.message}")
8888
throw cause
8989
}
9090
}
9191

92-
fun stop() {
93-
if (server != null) {
94-
server?.close()
95-
println("[TestServers] stop")
96-
}
92+
override fun close() {
93+
server?.close()
94+
println("[TestServers] stopped")
9795
}
9896
}
9997

100-
val osName = System.getProperty("os.name")
98+
val testServerService = gradle.sharedServices.registerIfAbsent("testServers", TestServerService::class) {
99+
parameters.sslConfigPath.set(File.createTempFile("ssl-", ".cfg").absolutePath)
100+
parameters.mainClass.set("aws.smithy.kotlin.runtime.http.test.util.TestServersKt")
101+
val kotlinCompilation = kotlin.targets.getByName("jvm").compilations["test"]
102+
parameters.classpath.from(kotlinCompilation.runtimeDependencyFiles!!)
103+
}
101104

102-
val startTestServers = task<LocalTestServers>("startTestServers") {
103-
dependsOn(tasks["jvmJar"])
105+
abstract class StartTestServersTask : DefaultTask() {
106+
@get:Internal
107+
abstract val serverService: Property<TestServerService>
104108

105-
main = "aws.smithy.kotlin.runtime.http.test.util.TestServersKt"
106-
val kotlinCompilation = kotlin.targets.getByName("jvm").compilations["test"]
107-
classpath = kotlinCompilation.runtimeDependencyFiles!!
108-
sslConfigPath = File.createTempFile("ssl-", ".cfg").absolutePath
109+
@TaskAction
110+
fun start() {
111+
serverService.get().startServers()
112+
}
113+
}
114+
115+
val startTestServers = tasks.register<StartTestServersTask>("startTestServers") {
116+
dependsOn(tasks["jvmJar"])
117+
usesService(testServerService)
118+
serverService.set(testServerService)
109119
}
110120

111121
val testTasks = listOf("allTests", "jvmTest")
112122
.forEach {
113123
tasks.named(it) {
114124
dependsOn(startTestServers)
125+
usesService(testServerService)
115126
}
116127
}
117128

118129
tasks.jvmTest {
119130
// set test environment for proxy tests
120131
systemProperty("MITM_PROXY_SCRIPTS_ROOT", projectDir.resolve("proxy-scripts").absolutePath)
121-
systemProperty("SSL_CONFIG_PATH", startTestServers.sslConfigPath)
132+
systemProperty("SSL_CONFIG_PATH", testServerService.get().parameters.sslConfigPath)
122133

123134
val enableProxyTestsProp = "aws.test.http.enableProxyTests"
124135
val runningInCodeBuild = System.getenv().containsKey("CODEBUILD_BUILD_ID")
@@ -127,7 +138,3 @@ tasks.jvmTest {
127138

128139
systemProperty(enableProxyTestsProp, System.getProperties().getOrDefault(enableProxyTestsProp, shouldRunProxyTests))
129140
}
130-
131-
gradle.buildFinished {
132-
startTestServers.stop()
133-
}

tests/benchmarks/serde-benchmarks/build.gradle.kts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,27 @@ tasks.generateSmithyProjections {
8585
buildClasspath.set(codegen)
8686
}
8787

88-
data class BenchmarkModel(val name: String) {
89-
val projectionRootDir: File
90-
get() = layout.buildDirectory.dir("smithyprojections/${project.name}/$name/kotlin-codegen/src/main/kotlin").get().asFile.absoluteFile
88+
abstract class StageGeneratedSourcesTask : DefaultTask() {
89+
@get:Input
90+
abstract val projectName: Property<String>
9191

92-
val sourceSetRootDir: File
93-
get() = layout.buildDirectory.dir("generated-src/src").get().asFile.absoluteFile
94-
}
92+
@get:InputDirectory
93+
abstract val smithyProjectionsDir: DirectoryProperty
9594

96-
val benchmarkModels = listOf(
97-
"twitter",
98-
"countries-states",
99-
).map { BenchmarkModel(it) }
95+
@get:OutputDirectory
96+
abstract val generatedSourcesDir: DirectoryProperty
10097

101-
val stageGeneratedSources = tasks.register("stageGeneratedSources") {
102-
group = "codegen"
103-
dependsOn(tasks.generateSmithyProjections)
104-
doLast {
105-
benchmarkModels.forEach {
106-
copy {
107-
from("${it.projectionRootDir}")
108-
into("${it.sourceSetRootDir}")
98+
@get:Inject
99+
abstract val fs: FileSystemOperations
100+
101+
@TaskAction
102+
fun stage() {
103+
val models = listOf("twitter", "countries-states")
104+
105+
models.forEach { modelName ->
106+
fs.copy {
107+
from("$smithyProjectionsDir/$projectName/$modelName/kotlin-codegen/src/main/kotlin")
108+
into(generatedSourcesDir.get().asFile)
109109
include("**/model/*.kt")
110110
include("**/serde/*.kt")
111111
exclude("**/serde/*OperationSerializer.kt")
@@ -115,6 +115,14 @@ val stageGeneratedSources = tasks.register("stageGeneratedSources") {
115115
}
116116
}
117117

118+
val stageGeneratedSources = tasks.register<StageGeneratedSourcesTask>("stageGeneratedSources") {
119+
group = "codegen"
120+
dependsOn(tasks.generateSmithyProjections)
121+
projectName.set(project.name)
122+
smithyProjectionsDir.set(layout.buildDirectory.dir("smithyprojections"))
123+
generatedSourcesDir.set(layout.buildDirectory.dir("generated-src/src"))
124+
}
125+
118126
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
119127
dependsOn(stageGeneratedSources)
120128
}

tests/codegen/serde-tests/build.gradle.kts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,24 @@ dependencies {
5858

5959
val generatedSrcDir = project.layout.projectDirectory.dir("generated-src/main/kotlin")
6060

61-
val stageGeneratedSources = tasks.register("stageGeneratedSources") {
62-
group = "codegen"
63-
dependsOn(tasks.generateSmithyProjections)
64-
outputs.dir(generatedSrcDir)
65-
// FIXME - this task up-to-date checks are wrong, likely something is not setup right with inputs/outputs somewhere
66-
// for now just always run it
67-
outputs.upToDateWhen { false }
68-
doLast {
69-
listOf("xml", "json").forEach { projectionName ->
70-
val fromDir = smithyBuild.smithyKotlinProjectionSrcDir(projectionName)
71-
logger.info("copying from ${fromDir.get()} to $generatedSrcDir")
72-
copy {
61+
abstract class StageGeneratedSourcesTask : DefaultTask() {
62+
@get:InputDirectory
63+
abstract val projectionsDir: DirectoryProperty
64+
65+
@get:OutputDirectory
66+
abstract val generatedSrcDir: DirectoryProperty
67+
68+
@get:Inject
69+
abstract val fs: FileSystemOperations
70+
71+
@TaskAction
72+
fun stageGeneratedSources() {
73+
val projections = listOf("xml", "json")
74+
75+
projections.forEach { projectionName ->
76+
val fromDir = projectionsDir.dir("$projectionName/kotlin-codegen/src/main/kotlin")
77+
logger.info("copying from ${fromDir.get()} to ${generatedSrcDir.get()}")
78+
fs.copy {
7379
from(fromDir)
7480
into(generatedSrcDir)
7581
include("**/model/*.kt")
@@ -83,6 +89,13 @@ val stageGeneratedSources = tasks.register("stageGeneratedSources") {
8389
}
8490
}
8591

92+
val stageGeneratedSources = tasks.register<StageGeneratedSourcesTask>("stageGeneratedSources") {
93+
group = "codegen"
94+
dependsOn(tasks.generateSmithyProjections)
95+
generatedSrcDir.set(layout.projectDirectory.dir("generated-src/main/kotlin"))
96+
projectionsDir.set(layout.buildDirectory.dir("smithyprojections/serde-tests"))
97+
}
98+
8699
tasks.kotlinSourcesJar {
87100
dependsOn(
88101
tasks.generateSmithyProjections,

0 commit comments

Comments
 (0)