-
Notifications
You must be signed in to change notification settings - Fork 5k
Handle scaladoc for Scala3 #18248
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
Handle scaladoc for Scala3 #18248
Conversation
bc2448f
to
0e570c6
Compare
24bca5b
to
1d9340c
Compare
@ljacomet could you take a look? :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! I left 2 comments, but otherwise looks good.
subprojects/scala/src/main/java/org/gradle/api/plugins/scala/ScalaPlugin.java
Outdated
Show resolved
Hide resolved
subprojects/scala/src/main/java/org/gradle/api/tasks/ScalaRuntime.java
Outdated
Show resolved
Hide resolved
022c987
to
41c8b61
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for working on this!
A couple questions / comments, see below:
subprojects/scala/src/main/java/org/gradle/api/tasks/scala/internal/GenerateScaladoc.java
Outdated
Show resolved
Hide resolved
subprojects/scala/src/main/java/org/gradle/api/tasks/scala/internal/GenerateScaladoc.java
Outdated
Show resolved
Hide resolved
Object scaladoc = scaladocClass.getDeclaredConstructor().newInstance(); | ||
process.invoke(scaladoc, new Object[]{args.toArray(new String[0])}); | ||
} | ||
|
||
private static String getScalaVersion(ClassLoader scalaClassLoader) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could not inject that information in the worker instead of having to load something here. After all, we had to ask the same question earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is impossible since the plugin is universal (it's just scala
) and we determine the version at runtime by the scala library dependency, but maybe you have some idea how to workaround it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path would be something like: ScalaBasePlugin
-> ScalaDoc
-> ScaladocParameters
-> GenerateScaladoc
makes sense?
@@ -83,4 +83,28 @@ class ScalaDocIntegrationTest extends AbstractIntegrationSpec implements Directo | |||
// Started Gradle worker daemon (0.399 secs) with fork options DaemonForkOptions{executable=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java, minHeapSize=null, maxHeapSize=234M, jvmArgs=[], keepAliveMode=DAEMON}. | |||
outputContains("maxHeapSize=234M") | |||
} | |||
|
|||
def "scaladoc uses scala3"() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything specific to Scala 3 scaladoc that we could test for here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll think about that, but I think the output is very alike to other doc tools. We can assert the existence of certain files I think.
My bad, I pushed one of the fixes too fast |
subprojects/scala/src/main/java/org/gradle/api/plugins/scala/ScalaPlugin.java
Outdated
Show resolved
Hide resolved
2fe7840
to
25f0eb3
Compare
Hi, I implemented the path you proposed for injecting whether it is scala 3 version. |
I forgot to run a sanity check previously so unused imports broke the CI, sorry. Now I checked |
Oh, I didn't know that |
It looks like |
cbccdba
to
572f3e0
Compare
I fixed |
@Incubating | ||
@Optional | ||
@Input | ||
public Boolean getIsScala3() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into my suggestion to inject the Scala version down here.
However adding a public field for this feels wrong.
I had a look at the other changes and what could be done instead is reach out to ScalaBasePlugin.isScala3
method, which would need to be made public.
This would also remove the need for adding a convention mapping - a concept we are trying to move away from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, reviewing #18347, let's just add the ScalaRuntime
as an @Internal
field instead.
See https://github.com/gradle/gradle/pull/18347/files#diff-bd022006e2ee4c0e9471eff5abec3f44a6e40a84e760796df120df9818c9ca3cR51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip, I just pushed the changes
@@ -198,6 +210,7 @@ protected void generate() { | |||
parameters.getClasspath().from(getClasspath()); | |||
parameters.getOutputDirectory().set(getDestinationDir()); | |||
parameters.getSources().from(getSource()); | |||
parameters.getIsScala3().set(getIsScala3()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As indicated, reach out to the ScalaBasePlugin
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
@@ -279,6 +288,7 @@ private void configureScaladoc(final Project project, final ScalaRuntime scalaRu | |||
scalaDoc.getConventionMapping().map("destinationDir", (Callable<File>) () -> project.getExtensions().getByType(JavaPluginExtension.class).getDocsDir().dir("scaladoc").get().getAsFile()); | |||
scalaDoc.getConventionMapping().map("title", (Callable<String>) () -> project.getExtensions().getByType(ReportingExtension.class).getApiDocTitle()); | |||
scalaDoc.getConventionMapping().map("scalaClasspath", (Callable<FileCollection>) () -> scalaRuntime.inferScalaClasspath(scalaDoc.getClasspath())); | |||
scalaDoc.getConventionMapping().map("isScala3", (Callable<Boolean>) () -> isScala3(scalaDoc.getScalaClasspath())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As indicated, remove this as the information is obtained in another way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
@BarkingBad Note that we are preparing 7.3 RC1 so if you rebase, make sure to rebase on the |
Ok, thanks, I'll try to do it today. One more question, do you know why this one test fails with leaking files (or how to use this tip |
4138d72
to
2f4ee4d
Compare
Let me relaunch a test suite and see |
655cb6c
to
48266a4
Compare
Well looks like I missed one way of fixing this which seems elegant enough and gets rid of the problem, thanks @big-guy @BarkingBad Any chance you can confirm this works on a real project? |
parameters.getSources().from(getSource()); | ||
boolean isScala3 = ScalaRuntimeHelper.findScalaJar(getScalaClasspath(), "library_3") != null; | ||
parameters.getIsScala3().set(isScala3); | ||
if (isScala3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This effectively assumes that a custom ScalaDoc
task on a custom source set would properly wire both the classpath
and the sources
and that we can simply here change what is to be considered "sources"
* Use test fixture for Maven Central * Fake scala jar to not have real dependency resolution Issue gradle#16527
OK, I've already triggered a build for you. |
Pre-tested commit build failed. |
@bot-gradle test and merge |
OK, I've already triggered a build for you. |
Sorry, I was absent this weekend, but I just have tested it on a small project and it is working fine :D |
@ljacomet @BarkingBad is this supposed to be working in 7.3-rc-1? |
Hi, it should be working right now. This error indicates some problems with the compiler itself and can be the result of wrongly gathered classpath for scaladoc generation. Could you share the repo so I could take a look, or try to generate scaladoc from the executable (installed manually or via coursier). Also, what scala version are you using, and is it completing the generation? There used to be problems in older scaladoc versions because it was not stable yet, but all these MatchErrors should not break the generation. |
Thanks!!! I am using Scala 3.1.1-RC1 (with Gradle 7.3-rc-1).
|
Hmm, I think I know what can cause the problem. I will experiment tomorrow. Thanks for the repo to test on :) |
Thank you! |
I've identified 3 parts that don't work as they should. For one I have an easy fix, but the other two I have to investigate. I hope you are not in a great hurry, because I don't know if I can handle them asap. I'll get back to you when I will have some more info about the case. |
Take your time and thank you for working on this! |
@dubinsky Could you open an issue for this please? |
Actually one of the problems is related to a bug in my Gradle implementation and the second one is probably on the compiler side (it is reproducible without Gradle). I will elaborate on them once the issue will be created. |
@ljacomet @BarkingBad issue: #18732 |
Fixes #16527
Context
The scaladoc was not working for scala 3. I still need help with creating proper integration tests.
Contributor Checklist
<subproject>/src/integTest
) to verify changes from a user perspective<subproject>/src/test
) to verify logic./gradlew sanityCheck
// warnings for other subprojects I haven't touched./gradlew <changed-subproject>:quickTest
Gradle Core Team Checklist