File tree Expand file tree Collapse file tree 3 files changed +32
-5
lines changed
common-util/src/main/kotlin/com/google/devtools/ksp/processing/impl
compiler-plugin/src/main/kotlin/com/google/devtools/ksp
integration-tests/src/test/kotlin/com/google/devtools/ksp/test Expand file tree Collapse file tree 3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -156,11 +156,13 @@ class CodeGeneratorImpl(
156
156
}
157
157
158
158
private val File .relativeFile: File
159
- get() =
160
- if (this .startsWith(buildDir))
159
+ get() {
160
+ val buildDirPrefix = if (buildDir.path.startsWith(" /" )) buildDir.path else buildDir.path.replace(" \\ " , " /" )
161
+ return if (this .startsWith(buildDirPrefix))
161
162
relativeTo(buildDir)
162
163
else
163
164
relativeTo(projectBase)
165
+ }
164
166
165
167
private fun associate (sources : List <KSFile >, outputPath : File ) {
166
168
if (! isIncremental)
Original file line number Diff line number Diff line change @@ -230,11 +230,14 @@ class IncrementalContext(
230
230
231
231
// Ugly, but better than copying the private logics out of stdlib.
232
232
// TODO: get rid of `relativeTo` if possible.
233
- private fun String.toRelativeFile (): File =
234
- if (this .startsWith(buildDir.path))
233
+ private fun String.toRelativeFile (): File {
234
+ val buildDirPrefix = if (buildDir.path.startsWith(" /" )) buildDir.path else buildDir.path.replace(" \\ " , " /" )
235
+ return if (this .startsWith(buildDirPrefix)) {
235
236
File (this ).relativeTo(buildDir)
236
- else
237
+ } else {
237
238
File (this ).relativeTo(baseDir)
239
+ }
240
+ }
238
241
239
242
private val KSFile .relativeFile
240
243
get() = filePath.toRelativeFile()
Original file line number Diff line number Diff line change @@ -65,6 +65,28 @@ class PlaygroundIT {
65
65
project.restore(" workload/build.gradle.kts" )
66
66
}
67
67
68
+ @Test
69
+ fun testArbitraryBuildDir () {
70
+ Assume .assumeTrue(System .getProperty(" os.name" ).startsWith(" Windows" , ignoreCase = true ))
71
+ val gradleRunner = GradleRunner .create().withProjectDir(project.root)
72
+
73
+ File (project.root, " workload/build.gradle.kts" )
74
+ .appendText(" project.buildDir = File(\" D:/build/\" )" )
75
+ val result = gradleRunner.withArguments(" build" ).build()
76
+
77
+ Assert .assertEquals(TaskOutcome .SUCCESS , result.task(" :workload:build" )?.outcome)
78
+
79
+ val artifact = File (" D:/build/libs/workload-1.0-SNAPSHOT.jar" )
80
+ Assert .assertTrue(artifact.exists())
81
+
82
+ JarFile (artifact).use { jarFile ->
83
+ Assert .assertTrue(jarFile.getEntry(" TestProcessor.log" ).size > 0 )
84
+ Assert .assertTrue(jarFile.getEntry(" hello/HELLO.class" ).size > 0 )
85
+ Assert .assertTrue(jarFile.getEntry(" g/G.class" ).size > 0 )
86
+ Assert .assertTrue(jarFile.getEntry(" com/example/AClassBuilder.class" ).size > 0 )
87
+ }
88
+ }
89
+
68
90
@Test
69
91
fun testAllowSourcesFromOtherPlugins () {
70
92
fun checkGBuilder () {
You can’t perform that action at this time.
0 commit comments