[2.x] feat: Add scriptedKeepTempDirectory setting#8621
Conversation
|
@eed3si9n Could you please review my PR? |
eed3si9n
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Overall the changes look good.
I probably need to grab this branch and test it manually.
|
@eed3si9n Can we merge this pr? |
eed3si9n
left a comment
There was a problem hiding this comment.
I couldn't test this using sbt/sbt. For sbt/sbt's scripted test this funnels the call from sbt 1.x into sbt 2.x via reflection. Could you surface your new setting in project/Scripted.scala's ScriptedKeys, and fold that in to the scriptedTask. See also:
ThisBuild / scriptedBufferLog := true
ThisBuild / scriptedPrescripted := { _ => }Thanks!
Added scriptedKeepTempDirectory to ScriptedKeys and updated scriptedTask to pass the setting through the reflection bridge to sbt 2.x. This allows the setting to be used from sbt 1.x when testing sbt 2.x.
@eed3si9n Fixed. Could you please review again? |
eed3si9n
left a comment
There was a problem hiding this comment.
If I add ThisBuild / scriptedKeepTempDirectory := true to build.sbt, and run scripted actions/compile I see
[info] Running 1 / 1 (100.00%) scripted tests with LauncherBased(/Users/xxxx/sbt-launch.jar)
[info] Temporary directory for scripted tests: /var/folders/hg/2602nfrs2958vnshglyl3srw0000gn/T/sbt_6446e5ca
[info] Running actions/compile
but the directory only contains global cache. Does it work for you locally?
The temp directory was being created and logged, but test files were being deleted after each test run. Now passes keepTempDirectory to runBatchedTests and conditionally skips the cleanup logic. This ensures test files remain in the temp directory for debugging.
|
I found the issue - the test files were being deleted after each test run regardless of the I've pushed a fix that:
The cleanup code was deleting all files except With this fix, when |
Added check to ensure only one scripted test is requested when scriptedKeepTempDirectory is true. This prevents batch test issues where multiple tests would share the same temp directory and see each other's files.
|
Fixed, please review it again. |
In PR #8621, I added a new `keepTempDirectory` parameter to `ScriptedRun.run()` and `invoke()` methods. To suppress MiMa warnings, I added `mimaBinaryIssueFilters` for: - `DirectMissingMethodProblem("sbt.ScriptedRun.run")` - `DirectMissingMethodProblem("sbt.ScriptedRun.invoke")` - `DirectMissingMethodProblem` for various internal `RunV1`, `RunV2`, `RunInParallelV1`, `RunInParallelV2` classes However, this broke binary compatibility, which prevents sbt 1.x from calling sbt 2.x for cross-building (building sbt 2.x plugins using sbt 1.x).
|
Very useful feature, thanks! |
feat: Add scriptedKeepTempDirectory setting to preserve temp directories
Fixes #3214
Problem
When running scripted tests to debug sbt plugins, the temporary directories (
/private/var/folder/...) are automatically deleted after tests complete. This makes it difficult to inspect the test state for debugging purposes, requiring workarounds like adding$ pausecommands and manually copying directories.Solution
Added a new
scriptedKeepTempDirectorysetting that allows users to preserve temporary directories after scripted tests complete. When enabled, the temporary directory path is logged so users can inspect it.Usage:
Changes
scriptedKeepTempDirectorysetting key (defaults tofalse)keepTempDirectoryparameter torun()method with backward-compatible versioning (V3 methods)keepTempDirectoryparameter torun(),runInParallel(), andbatchScriptedRunner()methodscreateTestRunners()to conditionally useIO.createTemporaryDirectoryinstead ofIO.withTemporaryDirectorywhenkeepTempDirectoryis trueTesting
false, existing behavior unchanged)Checklist
scalafmtAllapplied