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(
156156 }
157157
158158 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))
161162 relativeTo(buildDir)
162163 else
163164 relativeTo(projectBase)
165+ }
164166
165167 private fun associate (sources : List <KSFile >, outputPath : File ) {
166168 if (! isIncremental)
Original file line number Diff line number Diff line change @@ -230,11 +230,14 @@ class IncrementalContext(
230230
231231 // Ugly, but better than copying the private logics out of stdlib.
232232 // 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)) {
235236 File (this ).relativeTo(buildDir)
236- else
237+ } else {
237238 File (this ).relativeTo(baseDir)
239+ }
240+ }
238241
239242 private val KSFile .relativeFile
240243 get() = filePath.toRelativeFile()
Original file line number Diff line number Diff line change @@ -65,6 +65,28 @@ class PlaygroundIT {
6565 project.restore(" workload/build.gradle.kts" )
6666 }
6767
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+
6890 @Test
6991 fun testAllowSourcesFromOtherPlugins () {
7092 fun checkGBuilder () {
You can’t perform that action at this time.
0 commit comments