Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Problem guessing build folder when deploying to Heroku #9

Closed
rjaros opened this issue Oct 25, 2019 · 4 comments
Closed

Problem guessing build folder when deploying to Heroku #9

rjaros opened this issue Oct 25, 2019 · 4 comments

Comments

@rjaros
Copy link

rjaros commented Oct 25, 2019

I've created the compiler plugin and it works fine when the build process is run locally. But when I try to deploy my application to Heroku the build process fails, because the guessingBuildFolder() function is not able to correctly identify build directory. It returns something like this:

/tmp/build_e07308a302dcea2bb1f4d06d3a3f73ab/src/commonMain/kotlin/com/example/Service.ktbuild
@Foso
Copy link
Owner

Foso commented Oct 28, 2019

Hi @rjaros , thank you for reporting this, but unfortunately i don't know if there is a way to always get the correct build folder from inside a compiler plugin. I think, the best way is it, to get it from an gradle plugin and then pass the path to the compiler plugin to a https://github.com/JetBrains/kotlin/blob/master/compiler/plugin-api/src/org/jetbrains/kotlin/compiler/plugin/CommandLineProcessor.kt

@rjaros
Copy link
Author

rjaros commented Nov 3, 2019

In my plugin I've just replaced guessingBuildFolder() call with this code:

val projectFolder = cl.canonicalFilePath()?.split("/src")?.get(0) ?: ""
val buildFolder = "$projectFolder/build"

Instead of searching for the module name it just takes everything before the "src" folder in the path. It works fine for me. You could consider this as a fallback in the guessingBuildFolder() method.

@Foso
Copy link
Owner

Foso commented Nov 6, 2019

This sounds great, i will use your code inside the method

@rjaros
Copy link
Author

rjaros commented Nov 7, 2019

The code above turned out to be too simple. It fails when the project dir is located on path containing /src. So I came up with a more sophisticated solution:

                    tailrec fun findBuildFolder(path: String): String {
                        val preSrcDir = path.substringBeforeLast("/src")
                        return if (path == preSrcDir || File(preSrcDir, "build").isDirectory) {
                            "$preSrcDir/build"
                        } else {
                            findBuildFolder(preSrcDir)
                        }
                    }
                    val buildFolder = cl.canonicalFilePath()?.let { path -> findBuildFolder(path) }

Feel free to use it in your project.

@Foso Foso closed this as completed Nov 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants