Skip to content

Fix build-before-run skipping the build when relaunching within 10 seconds (#5132) - #5157

Open
DHIVAKAR R (dhivadhiva) wants to merge 3 commits into
microsoft:mainfrom
dhivadhiva:fix/5132-build-before-run-stale-cache
Open

DHIVAKAR R (dhivadhiva) wants to merge 3 commits into
microsoft:mainfrom
dhivadhiva:fix/5132-build-before-run-stale-cache

Conversation

@dhivadhiva

Copy link
Copy Markdown

This change addresses item #5132

This changes visible behavior

The following changes are proposed:

  • prepareLaunchTargetExecutable() only reuses a recently prepared result when it is called from the launch-target substitution commands (cmake.launchTargetPath, cmake.launchTargetDirectory, cmake.launchTargetFilename, cmake.launchTargetName). cmake.launchTarget (CMake: Run Without Debugging) and cmake.debugTarget (CMake: Debug) are a whole launch on their own, so they now always save, check the configuration and build.
  • The cache is dropped when a debug session starts (the launch it was populated for is under way) and when a document is saved (its result may be out of date), so a later launch that goes through the substitutions builds again as well.
  • Added end-to-end tests to the Debug/Launch interface suite, updated docs/debug-launch.md and CHANGELOG.md.

The purpose of this change

With cmake.buildBeforeRun enabled, rerunning CMake: Run Without Debugging within about 10 seconds of a previous launch runs the old executable: saved edits are ignored and there is no build output. 1.23.52 is not affected.

prepareLaunchTargetExecutable() has a 10-second cache so that the several ${command:cmake.launchTarget*} substitutions of one launch.json configuration share a single build (#5051). Since #5057 that cache also covers the active launch target, and it was consulted by every caller. launchTarget() and debugTarget() therefore got the cached target back before maybeAutoSaveAll(), the reconfigure check and the build.

The cache is meant to deduplicate builds within one launch, not across launches. VS Code does not tell us which substitutions belong to the same launch (see the first attempt in #5057), so this change keeps the TTL as a backstop and narrows the cache to the launch it was populated for:

Scenario Before After
Several substitutions in one launch.json configuration one build one build (unchanged)
CMake: Run Without Debugging / CMake: Debug, rerun within 10 s no save, no build, stale executable saves and builds
F5 through launch.json substitutions, edit and save, F5 again within 10 s no build, stale executable builds

Other Notes/Information

  • Tests added in test/end-to-end-tests/successful-build/test/debugger.test.ts:
  • Ran locally on Linux: yarn lint, yarn backendTests (508 passing) and the Debug/Launch interface end-to-end suite (28 passing).
  • The invalidation on debug-session start is not covered by a test, because the end-to-end environment stubs vscode.debug.startDebugging.
  • Clearing the cache on an unrelated save or debug session only costs one extra up-to-date build check, which is what happened on every launch before the cache existed.

…conds (microsoft#5132)

prepareLaunchTargetExecutable() keeps a 10-second cache so that the
several ${command:cmake.launchTarget*} substitutions of one launch.json
configuration share a single build (microsoft#5051). Since microsoft#5057 that cache also
covers the active launch target and was consulted by every caller, so
"CMake: Run Without Debugging" and "CMake: Debug" returned the cached
target before saving, checking the configuration or building. Rerunning
within 10 seconds of a previous launch silently ran the stale executable.

Scope the cache to the launch it was populated for:

- Only the substitution commands may reuse a recently prepared result.
  cmake.launchTarget and cmake.debugTarget are a whole launch on their
  own and now always prepare the target.
- Drop the cache when a debug session starts (the launch it served is
  under way) and when a document is saved (its result may be stale), so
  a later launch that goes through the substitutions builds again too.

Add end-to-end tests covering the coalescing of substitutions, relaunching
right away, and relaunching after a saved edit.
@dhivadhiva

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants