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

Add new API to retrieve name of the current module to the Resolver #1015

Closed
popovanton0 opened this issue Jun 7, 2022 · 4 comments
Closed
Labels
feature request Feature request for discussion

Comments

@popovanton0
Copy link

popovanton0 commented Jun 7, 2022

ResolverImpl contains this info, but it is not exposed through the Resolver API. Maybe it is possible to enhance the API by adding moduleName property to Resolver?

1

2

https://kotlinlang.slack.com/archives/C013BA8EQSE/p1649968377169569

@neetopia neetopia added enhancement New feature or request feature request Feature request for discussion and removed enhancement New feature or request labels Jun 9, 2022
@OliverO2
Copy link

Module names seem to be quite peculiar. When testing #1021, this is what I found:

Given

  • a multi-project Gradle build with these subprojects
include(":annotations")
include(":workload")
include(":test-processor")
  • a Kotlin multiplatform JVM/Js configuration in :workload with an extra custom clientMain source set.

This would produce the following module names:

Task Module
:workload:kspCommonMainKotlinMetadata <main>
:workload:kspClientMainKotlinMetadata <main>
:workload:kspKotlinJvm <workload>
:workload:kspKotlinJs <dummyOutput>
:workload:kspTestKotlinJvm <workload>

So I wonder: Are these module names of interest or is it about something else?

@louna997
Copy link

louna997 commented Aug 5, 2022

Any updates on this?
Or does a workaround exist to fetch the module name in the processor?

@popovanton0
Copy link
Author

popovanton0 commented Aug 5, 2022

Workaround:

https://github.com/popovanton0/kira/blob/191b4b0c11a6d9556e5022fcf156c2ca1ee9483d/kira-processor/src/main/java/com/popovanton0/kira/processing/generators/DeclarationsAggregator.kt#L97-L111

    /**
     * todo use `resolver.moduleName` when [https://github.com/google/ksp/issues/1015] is done
     * @return gradle module name
     */
    private fun moduleName(resolver: Resolver): String {
        val moduleDescriptor = resolver::class.java
            .getDeclaredField("module")
            .apply { isAccessible = true }
            .get(resolver)
        val rawName = moduleDescriptor::class.java
            .getMethod("getName")
            .invoke(moduleDescriptor)
            .toString()
        return rawName.removeSurrounding("<", ">")
    }

@neetopia
Copy link
Collaborator

note that this is highly implementation dependent, might break, and will not work for the K2 implementation of KSP.
You can try to pass module name as the KSP processor options in your gradle script.
closing as resolved for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request for discussion
Projects
None yet
Development

No branches or pull requests

4 participants