Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I test incremental compilation? #206

Open
nbirillo opened this issue Sep 23, 2021 · 4 comments
Open

How can I test incremental compilation? #206

nbirillo opened this issue Sep 23, 2021 · 4 comments

Comments

@nbirillo
Copy link

Hi! Can I imitate the incremental compilation process? I mean I have the following test case: I should compile a project that uses my compiler plugin, check results, save them, modify several files in the project, recompile the project and check new results. The problem is that I don't want to recompile the full project since it is important to check if clean (old, not dirty) files were analyzed by my compiler plugin.

@tschuchortdev
Copy link
Owner

KCT currently uses the same interface to the compiler as kotlinc. If you can do it with kotlinc then you should be able to do it in the same way with KCT. I'm afraid that incremental compilation is probably not supported by kotlinc and instead implemented in the kotlin gradle plugin in conjunction with new APIs in the compiler. That stuff is currently out of scope for me because the maintainance burden of exactly reproducing the logic from the gradle plugin would be huge, though I'm open to adding incremental compilation support if you're willing to do the ground work. I suppose in order to enable incremental compilation you'd have to look at the compiler source code to see what K2JVMCompiler (which is the class that represents the kotlinc cli) does to set up the compilation (creating the KotlinCoreEnvironment) and reimplement that in KCT. Then you have to look at the kotlin gradle plugin to find out how it keeps track of the intermediate compilation state (GenerationState maybe?) and triggers re-compilation on file changes. If you figure out how it works let me know.

@nbirillo
Copy link
Author

Oh, thank you for your response! I researched the source code of Incremental compilation in the Kotlin repository and discussed some points with its developers and decided, for me, it would be easier to implement these tests directly.
I use makeIncrementally function from the org.jetbrains.kotlin.incremental package. I created a list of the necessary arguments (e.g. path to the classpath and to my plugin jar). It has K2JVMCompilerArguments type.
The main pipeline is the following:
I compiled my project and got the compiler files and the compiler cache (in the folders, that I sent). After that, I apply some modifications to files and compile it again (with the old cache)/ In this case, the compiler knows the previous results and incremental compilation works.
To get the program output, I just run the compiled Main class.

I can share my tests classes if you want. Also, I can research how the incremental compilation process can be adopted to KCT later

@tschuchortdev
Copy link
Owner

I would be interested in your test classes. If you can find out how it can be integrated with KCT, that's even better.

@nbirillo
Copy link
Author

You can find them here

I can search for a way how it can be integrated into KCT after several days since currently, I am very busy at work

tschuchortdev pushed a commit that referenced this issue May 26, 2024
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants