[Gradle] Don't reinstall the K/N bundle over an existing installation - #7636
Open
Andrey Yastrebov (AYastrebov) wants to merge 1 commit into
Open
[Gradle] Don't reinstall the K/N bundle over an existing installation#7636Andrey Yastrebov (AYastrebov) wants to merge 1 commit into
Andrey Yastrebov (AYastrebov) wants to merge 1 commit into
Conversation
The Kotlin/Native toolchain treats a bundle directory as installed only when it holds the 'provisioned.ok' marker, and only the toolchain itself ever wrote that marker. A distribution installed by 'NativeCompilerDownloader' -- the configuration-phase path, used whenever 'kotlin.native.distribution.downloadFromMaven' is off -- has no marker, so the toolchain declares it unprovisioned and unpacks the archive on top of it. That re-extraction is neither necessary nor safe. Extraction shells out to tar, which unlinks each existing file before recreating it, so every shipped file in the distribution briefly does not exist. A build reading the distribution at that moment gets a NoSuchFileException, which is what AndroidX has been hitting on files such as klib/cache/<target>-gSTATIC-system/stdlib-per-file-cache/.../ir. They share one konan data dir between an outer build installing through 'NativeCompilerDownloader' and Gradle TestKit sub-builds installing through the toolchain, so the two paths meet routinely. Write the marker from 'NativeCompilerDownloader' as well, so that both installers agree on what a complete installation looks like and the toolchain leaves such a directory alone. The configuration-phase path had a second way to rewrite a live distribution. When its atomic rename failed because the directory was already there, it fell back to copying on top of it, which rewrites files another build may be reading. Skip that copy and, since this build then installed nothing, leave the marker to whoever did. ^KT-86251
Code Owners
PR commands for maintainers
|
Contributor
Author
|
/dry-run |
Andrey Yastrebov (AYastrebov)
requested a review
from Yahor Berdnikau (Tapchicoma)
August 21, 2026 13:38
|
THIS IS A DRY RUN Quality gate is triggered at https://buildserver.labs.intellij.net/build/1037930996 — use this link to get full insight. Quality gate was triggered with the following revisions:
Quality gate failed. See https://buildserver.labs.intellij.net/build/1037930996 to get full insight. |
Yahor Berdnikau (Tapchicoma)
requested a review
from Nataliya Valtman (nav-nav)
August 21, 2026 13:51
| if (installed) { | ||
| // without the marker a toolchain build sharing this konan data dir unpacks the archive over the | ||
| // distribution again (KT-86251). Keep it the last thing written. | ||
| compilerDirectory.resolve(NativeVersionValueSource.MARKER_FILE).createNewFile() |
Contributor
There was a problem hiding this comment.
Personally, I think the non-Gradle provisioner should also create such a file upon successful provisioning. And ideally, we should have only one provisioner implementation, which could be a BTA-X library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Kotlin/Native toolchain treats a bundle directory as installed only when it holds the
provisioned.okmarker, and only the toolchain itself ever wrote that marker. A distribution installed byNativeCompilerDownloader-- the configuration-phase path, used wheneverkotlin.native.distribution.downloadFromMavenis off -- has no marker, so the toolchain declares it unprovisioned and unpacks the archive on top of it.That re-extraction is neither necessary nor safe. Extraction shells out to tar, which unlinks each existing file before recreating it, so every shipped file in the distribution briefly does not exist. A build reading the distribution at that moment gets a NoSuchFileException, which is what AndroidX has been hitting on files such as
klib/cache/<target>-gSTATIC-system/stdlib-per-file-cache/.../ir. They share one konan data dir between an outer build installing through 'NativeCompilerDownloader' and Gradle TestKit sub-builds installing through the toolchain, so the two paths meet routinely.Write the marker from
NativeCompilerDownloaderas well, so that both installers agree on what a complete installation looks like and the toolchain leaves such a directory alone.The configuration-phase path had a second way to rewrite a live distribution. When its atomic rename failed because the directory was already there, it fell back to copying on top of it, which rewrites files another build may be reading. Skip that copy and, since this build then installed nothing, leave the marker to whoever did.
^KT-86251