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

Fix DGP/KMP integration, so Dokka can 'see' code from shared source sets in target source sets #3814

Open
wants to merge 83 commits into
base: master
Choose a base branch
from

Conversation

adam-enko
Copy link
Member

@adam-enko adam-enko commented Sep 19, 2024

There are 3 main fixes in this PR:

  1. Update determining the Kotlin target for each source set. (See KotlinAdapter#determineKotlinPlatform). Filter out metadata targets (they're not relevant for target determination), and only fall back to KotlinPlatform.Common if necessary.
  2. Correctly resolve Konan dependencies: Use compilation.konanTarget.name instead of compilation.target.name.
  3. Fix fetching the classpath: For Android projects, fetch both jar and android-classes-jar dependencies. For KGP projects, use compileDependencyFiles.

The remaining changes are to support these fixes:

  • Add functional test to verify that Dokka can correctly generate docs when 'leaf' source sets (e.g. linuxX64) reference 'branch' source sets (e.g. commonMain, nativeMain).
  • Update DGPv2 AGP integration test data.
  • Create a factory for creating DokkaSourceSetSpecs, which means DGP can consistently use convention() to set default values.
  • Add/update KDoc.

Should fix KT-70857

@adam-enko adam-enko added the runner: Gradle plugin An issue/PR related to Dokka's Gradle plugin label Sep 19, 2024
@adam-enko adam-enko self-assigned this Sep 19, 2024
…ndents

# Conflicts:
#	dokka-runners/dokka-gradle-plugin/src/main/kotlin/internal/uriUtils.kt
- Filter out legacy KMP metadata compilations (they were retained to support Dokka v1).
- Fetch both `jar` and `android-classes-jar` from AGP (probably not necessary, but why not?)
- Only use `compilation.compileDependencyFiles` in non-AGP projects.
- Add more docs
- implement new JUnit extension to help set up and re-run DGP integration tests with different versions
…ses, tidy Android projects, fix suppress/analysisPlatform defaults.
adam-enko added a commit that referenced this pull request Oct 31, 2024
`fileTree.kt` contains a utility for logging pretty file trees, which is useful in providing human-readable context for test failures.

This PR updates the utility to only use NIO Path, rather than the older `java.io.File`.

This change was split off from #3814 to make the PR smaller
adam-enko added a commit that referenced this pull request Oct 31, 2024
`fileTree.kt` contains a utility for logging pretty file trees, which is useful in providing human-readable context for test failures.

This PR updates the utility to only use NIO Path, rather than the older `java.io.File`.

This change was split off from #3814 to make the PR smaller
…ndents

# Conflicts:
#	.gitattributes
#	build.gradle.kts
#	dokka-integration-tests/gradle/build.gradle.kts
#	dokka-runners/dokka-gradle-plugin/src/main/kotlin/tasks/DokkaGenerateTask.kt
#	dokka-runners/dokka-gradle-plugin/src/testFixtures/kotlin/GradleTestKitUtils.kt
#	dokka-runners/dokka-gradle-plugin/src/testFixtures/kotlin/fileTree.kt
@antohaby antohaby self-requested a review November 18, 2024 14:09
Base automatically changed from adam/feat/KT-70336/android-integration-tests to master November 20, 2024 09:45
…ndents

# Conflicts:
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/index.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/navigation.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/org.dokka.it.android.kmp.core/-menu-item/-menu-item.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/org.dokka.it.android.kmp.core/-menu-item/image-vector.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/org.dokka.it.android.kmp.core/-menu-item/index.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/org.dokka.it.android.kmp.core/-menu-item/is-important.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/org.dokka.it.android.kmp.core/-menu-item/label.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/org.dokka.it.android.kmp.core/-menu-item/on-click.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/core/org.dokka.it.android.kmp.core/index.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/material3/index.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/material3/navigation.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/material3/org.dokka.it.android.kmp.material3/-top-app-bar-action.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/material3/org.dokka.it.android.kmp.material3/index.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/navigation.html
#	dokka-integration-tests/gradle/projects/it-android-compose/expectedData/html/scripts/pages.json
#	dokka-integration-tests/gradle/projects/it-android/expectedData/html/it-android-0/it.android/-integration-test-activity/index.html
#	dokka-integration-tests/gradle/projects/it-android/expectedData/html/it-android-0/it.android/index.html
#	dokka-integration-tests/gradle/projects/it-android/expectedData/html/it-android-0/package-list
#	dokka-integration-tests/gradle/projects/it-android/expectedData/html/scripts/pages.json
#	dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/junit/DokkaGradlePluginTestExtension.kt
#	dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/junit/GradleTestProjectInitializer.kt
#	dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/junit/TestedVersions.kt
#	dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/junit/testTags.kt
#	dokka-integration-tests/gradle/src/main/kotlin/org/jetbrains/dokka/it/gradle/utils/SemVer.kt
#	dokka-integration-tests/gradle/src/test/kotlin/AndroidComposeIT.kt
#	dokka-integration-tests/gradle/src/test/kotlin/AndroidProjectIT.kt
#	dokka-integration-tests/gradle/src/testTemplateProjectAndroid/kotlin/Android0GradleIntegrationTest.kt
#	dokka-runners/dokka-gradle-plugin/src/main/kotlin/tasks/DokkaGenerateTask.kt
- Filter out metadata compilations when determining the source set target.
- Remove KotlinPlatform warning - it's always triggered for commonMain.
- Fetch _all_ dependent source sets, including transitives.
@adam-enko adam-enko changed the title Fix common source sets not propogated Fix DGP/KMP integration, so Dokka can 'see' code from shared source sets in target source sets Nov 21, 2024
@adam-enko adam-enko added this to the Dokka 2.0.0 milestone Nov 21, 2024
@adam-enko adam-enko marked this pull request as ready for review November 21, 2024 18:55
Copy link
Collaborator

@whyoleg whyoleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
Changes to defaults are looks logical for me, only the test placement worries me :)

if (compilation.target.platformType == androidJvm) {
attributes { artifactType(artifactType) }

// Setting lenient=true is not ideal, because it might hide problems.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious: is it possible to somehow log those problems in case of lenient=true or are they just silently ignored? just for troubleshooting?

@@ -91,7 +91,7 @@ private fun describeFileDifferences(
/* revisedFileName = */ actualFile.relativeTo(actualDir).invariantSeparatorsPathString,
/* originalLines = */ expectedLines,
/* patch = */ patch,
/* contextSize = */ 3,
/* contextSize = */ 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it an expected change?

import kotlin.io.path.walk

@Ignored("KMP: References is not linked if they are in shared code and there is an intermediate level between them https://github.com/Kotlin/dokka/issues/3382")
class KmpCommonSourceSharedWithDependentsTest : FunSpec({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this test should be placed into dokka-integration-tests so that we will be able to check it with different Kotlin versions.
In my understanding, functional tests in DGPv2 are more about plugin behavior while this test is more about overall Dokka behavior and so should be in IT

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably except here a test which checks that we set correct defaults for DokkaSourceSetSpec platform, dependsOn and etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
runner: Gradle plugin An issue/PR related to Dokka's Gradle plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants