https://kotlinlang.org logo
#arrow-meta
Title
# arrow-meta
m

marios proto

10/10/2020, 7:02 PM
👋 I am trying to see more of arrow-meta in action, and trying to use the `
Copy code
Transform.newSources
function with a simple example to generate some code, within Android Studio the code is taken from arrow-meta documentation, as
Copy code
val Meta.transformNewSource: CliPlugin
    get() = "Transform New Source" {
        meta(
            classDeclaration(this, { name == "TestClass" }) {
                Transform.newSources(
                    """
     package com.example.arrowexplorer
     //metadebug
     class ${name}_Generated {
      fun sayHi() = println("Hi!")
     }
     """.file("${name}_Generated")
                )
            }
        )
    }
The problem is I cannot find the generated class file or reference it later. The file actually exists here on this path
/Users/userA/Library/Application Support/kotlin/daemon/build/generated/source/kapt/main/TestClass_Generated.kt
Also tried to use the
Copy code
file("${name}_Generated", filePath ="/path")
without success. Any help how can I include the generated file in my project?
d

David Stone

10/10/2020, 7:08 PM
I ran into this exact same thing. I think (and someone from the Arrow team should correct me if I’m wrong) that in addition to needing the cliplugin, if you’re generating new symbols (which you are because it’s a completely new class) then you also need to build an IDE plugin so IDEA/Android Studio can use the same synthetics that the compiler will use.
😮 1
That being said, I’ve been trying to get the ide example PR running and I’ve determined that I’m probably just not smart enough to understand how it all hooks together. 😄
m

marios proto

10/10/2020, 7:14 PM
thank you for your answer! It really is an overkill if that is needed indeed. I have worked quite much with annotation processors and KPoet and didn't have this issue. Hope someone from Arrow team can give some guidance.
I used this repo to actually make the plugin run https://github.com/ocampoleandro/arrow-meta-android-example
r

raulraja

10/10/2020, 9:52 PM
If you use Transform.newSources you should not need an IDE plugin because the new sources get fed to analysis as if the user had written them in separate files. Only when you mutate the tree in place you need synth descriptors support with an IDE plugin. You may need to add the output folder as sources for those to be recognized. You can control the output folder with this System property. In the future it will become a plugin arg bit for now it should allow you to set the one for your build folder in AS or you add that one as gen sources and it should pick them up.
m

marios proto

10/11/2020, 12:55 PM
Hi @raulraja. Thank you for your answer! It seems that the environment variable is getting ignored for some reason, whatever path I assign. The only thing that changes the path is the
filepath
option on
file (..,filePath ="")
and that only changes it under the
/daemon/
path. default path is as,
/Users/userA/Library/Application Support/kotlin/daemon/build/generated/source/kapt/main
Had to add a custom output path to include in the sourcesets, under the
daemon
folder, as you suggested to make the classes visible in my IDE. Would be nice to have an option of selecting any path for the code generation in the future
r

raulraja

10/11/2020, 12:56 PM
Try with System.setProperty, if that does not work @Rachel may be able to help
m

marios proto

10/11/2020, 1:33 PM
Just did, and still places under the daemon/ directory unfortunately
r

Rachel

10/19/2020, 4:05 PM
HI 👋 @David Stone that's a draft pull request to show how to create a new Intellij IDEA Plugin from Arrow Meta IDE Plugin - I hope it will be clear when it's merged on
master
branch and explained in the README file 🙌
Please @marios proto , what property did you create?
m

marios proto

10/19/2020, 4:09 PM
Hi, I created this property as
Copy code
System.setProperty("arrow.meta.generated.source.output","[/Users/userA/Documents/tests/arrow-meta-android-example-master/app/files]");
also set it in gradle, but no luck
d

David Stone

10/19/2020, 4:46 PM
@Rachel Yeah, I was just playing with it and trying to get my IDE plugin loaded. From looking at the arrow-meta idea plugin, it looked like what I needed to do was override the original entry point in the plugin.xml file, but then it seems like I can only have my IDEA plugin loaded, not mine and the arrow-meta plugin. Totally understand that I’m poking around a bunch of pre-release code and that it’s not released and documented yet…I was just trying to play. 😄
r

Rachel

10/19/2020, 5:51 PM
Thanks for the interest @David Stone Don't stop playing because your help can be very useful 🙌 Thanks!!
@marios proto maybe the new property is not considered when compiling the source code. Anyway I think I found a bug with the manipulation of paths that doesn't allow using absolute paths with
filePath
I'm preparing a pull request now 🙌
👏 1
Hi @marios proto 👋 The fix to use absolute paths in
filePath
is already available for latest SNAPSHOT. It's necessary the usual configuration to use fresh SNAPSHOTs:
Copy code
configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
or
--refresh-dependencies
Thanks!!
d

dalexander

10/20/2020, 9:49 PM
Hey I'm running into the issue where the generated sources are being produced in the strange gradle daemon directory. According to https://github.com/arrow-kt/arrow-meta/issues/591 they should be placed in the project where kapt produces its files, but I'm not seeing that even after refreshing my dependencies.
https://github.com/arrow-kt/arrow-meta/pull/608 seems like it's supposed to fix it, but it just lets me choose the path in that gradle daemon directory. I suppose it might be possible to pass the absolute path as a parameter in gradle, if that's been fixed though.
r

Rachel

10/20/2020, 9:59 PM
Hi @dalexander It's possible to use absolute paths for
filepath
(second arg for file - the example uses a relative one): https://github.com/arrow-kt/arrow-meta/blob/master/compiler-plugin/src/test/kotlin/arrow/meta/quotes/transform/plugins/TransformNewSourcePlugin.kt#L109 because of a recent fix. Please, feel free to re-open the issue in order to fix the default path. Thanks!! 🙌
d

dalexander

10/21/2020, 11:56 AM
Sounds good, I'll re-open the issue and use absolute paths in the meantime.
@Rachel I don't think I can actually re-open the ticket myself, but I did leave a comment https://github.com/arrow-kt/arrow-meta/issues/591#issuecomment-713518090
r

Rachel

10/21/2020, 12:11 PM
Thank you so much @dalexander!!
😀 1
Hi 👋 The fix is ready for review: https://github.com/arrow-kt/arrow-meta/pull/779
🙌 1
r

raulraja

10/27/2020, 10:04 PM
Thank you @Rachel!
m

marios proto

10/28/2020, 1:15 PM
Great! Thank you
3 Views