fix: make build cache relocatable when using Baseline by storing relative paths#1074
fix: make build cache relocatable when using Baseline by storing relative paths#1074Copilot wants to merge 3 commits into
Conversation
…catable with baseline When using a shared build cache across different workspace directories with a baseline.xml, the cached error binary reports (.bin) contained absolute file paths. This caused the baseline filtering logic to fail matching cached errors against baseline entries, resulting in unexpected build failures. The fix stores file paths relative to the project directory in LintErrorResult. - KtLintWorkAction now converts absolute paths to relative before serializing - BaseKtLintCheckTask passes project directory to the work action and resolves relative paths back to absolute when loading previous errors - ConsoleReportWorkAction and GenerateReportsWorkAction resolve relative paths for absolute path operations (logging/reporting) while using them directly for baseline lookups - GenerateBaselineWorkAction uses the already-relative lintedFile.path directly - serialVersionUID bumped to invalidate stale cached data Fixes #1041
|
@copilot please fix the requirement for a change log file entry. Please remember that this needs to be added every time copilot creates a pull request |
Added a |
JLLeitschuh
left a comment
There was a problem hiding this comment.
This looks reasonable to me. @wakingrufus what do you think?
| ) : DefaultTask(), | ||
| PatternFilterable { | ||
|
|
||
| private val projectDir: File = projectLayout.projectDirectory.asFile |
There was a problem hiding this comment.
i think this should be a proper @InputDirectory property, and we should probably remove projectLayout from the constructor parameters and move the logic for setting properties derived from the layout to the plugin code which creates these tasks. this will make it work better with configuration cache
There was a problem hiding this comment.
If we make the entire projectDir an @InputDirectory won't that mean that the whole directory is tracked as an input? Thus any changes to any subfile, not just kotlin files would invalidate the task?
@copilot thoughts?
There was a problem hiding this comment.
Yes, that concern is valid. Annotating projectDirectory with @InputDirectory would cause Gradle to fingerprint every file under the project root, so any change to any file — including non-Kotlin files — would invalidate the task. That's exactly the kind of over-tracking we want to avoid.
The projectDirectory is only used as an anchor for computing relative paths (not as a content input), so the right annotation is @Internal. The actual content-based inputs are already tracked precisely via @get:InputFiles source with PathSensitivity.RELATIVE.
@wakingrufus's broader point about moving layout-derived property initialization out of the constructor and into the plugin's task-registration code is still a good one for configuration-cache hygiene, but that's orthogonal to the annotation question — and for the path-anchor use-case, @Internal is the correct choice regardless of where the value is set.
When using a shared build cache across different workspace directories,
LintErrorResultserializedlintedFileas an absolute path. On cache restoration in a relocated project, baseline filtering broke becausetoRelativeString(newProjectDir)on a stale absolute path produced a path like../../original/src/...instead ofsrc/..., causing all baseline-suppressed errors to surface as real failures.Changes
LintErrorResult— bumpedserialVersionUIDto invalidate stale cached binaries containing absolute pathsKtLintWorkAction— addedprojectDirectoryparameter; converts each linted file to a project-relative path before writing to the.binoutput:BaseKtLintCheckTask— storesprojectDireagerly; passes it to the work action; resolves stored relative paths back to absolute when loading prior errors for incremental runsConsoleReportWorkAction/GenerateReportsWorkAction— resolvelintedFileagainstprojectDirfor absolute-path operations (logging, reporter output); uselintedFile.pathdirectly for baseline map lookup (already relative)GenerateBaselineWorkAction— useslintedFile.pathdirectly instead oftoRelativeString(projectDir)since the path is now already relativeBuildCacheTest— addscheckWithBaselineIsRelocatable: generates a baseline, primes the cache in the original directory, then verifies bothrunKtlintCheckOverMainSourceSetandktlintMainSourceSetCheckareFROM_CACHEin the relocated project