Skip to content

msbuild: take MSBuildStartupDirectory as an input to the restore cone's evaluation (#674) - #971

Merged
Smaug123 merged 1 commit into
mainfrom
claude/msbuild-startup-directory-674
Nov 16, 2026
Merged

Smaug123 merged 1 commit into
mainfrom
claude/msbuild-startup-directory-674

Conversation

@Smaug123

Copy link
Copy Markdown
Collaborator

Part of #674: the second half, MSBuildStartupDirectory. The first half, MSBuildAssemblyVersion, landed in #954.

What

MSBuildStartupDirectory is the working directory of the MSBuild process. An evaluation the LSP serves models a build nobody launched, so it has no such directory and the name stays undefined. The restore cone (A₁) models the dotnet child that restore.rs starts in a directory it picks, so for that evaluation the directory is a fact borzoi controls.

  • The crate-internal parse_fsproj_probed and test_support::parse_fsproj_reads take startup_directory: Option<&Path>. parse_fsproj, parse_fsproj_with_imports and the _reusing/_asking_every_time variants do not, so the type system guarantees that a served evaluation never carries a guessed startup directory.
  • When a directory is given, State::new canonicalises it through observed::canonicalize, which puts it in the read set, so retargeting a link invalidates the evaluation. It then seeds it raw, as the MSBuildThisFile* names are. The seed goes in before the reserved set is built, so the name is reserved and protected, and the environment cannot displace it. The seed is Unix only. A path that isn't rooted, doesn't resolve, or isn't UTF-8 gets no seed.
  • extra_properties now rejects MSBuildStartupDirectory. The design comment says validate_inputs "already rejects it". It didn't: a caller global of that name was accepted and committed (the new startup_directory_in_extras_is_rejected test failed before the fix). dotnet msbuild -p:MSBuildStartupDirectory=/x is MSB4177, which I re-probed.
  • restore.rs moves the directory its child starts in into one function, child_start_directory. No behaviour change.
  • Docs reworded to the present rule: docs/msbuild-reserved-seeding-plan.md (c), the well_known doc, and the is_env_ignored_toolset_name note. That note was attached to enum EnvExtensionsPath instead of the function, so it has moved onto the function. Also docs/nuget-dgspec-boundary-plan.md: item 3 of A₁.3b is now landed, and its census table is restated from today's manifests.

Probed facts, checked against the oracle

Every fact in the design held: the value is the physical directory, it is spliced raw (%20 decodes and ; splits an Include), it has no trailing separator, -p: is MSB4177, and an environment variable of the name is ignored. One addition: MSBuild rejects a project that passes a ;-bearing startup directory to a scalar function (Exists, HasTrailingSlash). The walk commits nothing there, and the differential checks that.

Grading

  • tests/startup_directory_diff.rs (new): one oracle per working directory, covering the project's directory, a link to it, directories named plain, with space, semi;colon, pct%20enc, dollar$sign and $(Body), and a link to an unrelated directory. The name is read in a body, an imported file, an Include, an equality with MSBuildProjectDirectory, HasTrailingSlash, Exists, a <Choose> arm, an <Import> path and a gated Compile. With the directory, every read must commit and agree with MSBuild, and where MSBuild rejects the project, the walk must commit nothing. Without it, nothing the walk commits may differ from MSBuild's value from any of the nine directories. Non-vacuity checks confirm that each channel does move with the directory.
  • with_imports_tests::startup_directory (new): the read-set soundness sweep over a startup directory reached through a symlink. I mutated the seed to call host_fs::canonicalize and the sweep panicked on the relink, so the sweep catches a query that bypasses the observer. The module also checks that the environment doesn't displace the seed and that a directory the walk can't resolve gets no seed.
  • Restore-cone census: our evaluation starts where the oracle starts, through one start_directory helper. The probe-invariance check now runs both with a startup directory and without one. Exactly the nine MSBuildStartupDirectory lines move, from unset, inexact (the toolset); set in MSBuild to value agrees. Nothing else in either manifest moves.
  • sdk_chain_decline_attribution doesn't move: that walk is a served one, so the name stays in not_yet_seeded. Only its comment changed.

Not in this PR

The fsproj_global_perturbation_diff.rs axis: varying the startup directory within that harness's global-set sweep and generator, with per-case MSBuild pins. The new differential covers the four corner routes (gate, <Choose> arm, property-selected import, Compile item) in both modes across nine working directories, but under no globals. Crossing that axis with the global sweep is still open.

🤖 Generated with Claude Code

…'s evaluation (#674)

`MSBuildStartupDirectory` is the working directory of the MSBuild process.
An evaluation the LSP serves models a build nobody launched, so it has no
such directory and the name stays undefined. The restore cone (A₁) models
the `dotnet` child that `restore.rs` starts in a directory it chooses, so
for that evaluation the directory is a fact borzoi controls.

`parse_fsproj_probed` and `test_support::parse_fsproj_reads` take a
`startup_directory`. The public entry points do not, so a served
evaluation never carries a guessed one. Where it is given, `State::new`
canonicalises it through the observer (MSBuild reports the physical
directory, and retargeting a link must invalidate the evaluation) and
seeds it raw, as the `MSBuildThisFile*` names are, before the reserved set
is taken: so it is reserved and protected, and the environment cannot
displace it. Unix only. `extra_properties` now rejects the name, as
`-p:MSBuildStartupDirectory=` is MSB4177; it was accepted as a global
before.

`restore.rs` names the child's start directory in one function,
`child_start_directory`, with no change in behaviour.

Graded by:
- `tests/startup_directory_diff.rs`: MSBuild started in the project's
  directory, a link to it, directories named with a space, `;`, `%20`, `$`
  and `$(Body)`, and a link to a directory; the name read in a body, an
  import, an `Include`, conditions, a `<Choose>` arm, an import path and a
  gated `Compile`. Given the directory, every read commits and agrees;
  without it, nothing that moves with the directory is committed.
- `with_imports_tests::startup_directory`: the read-set soundness sweep over
  a startup directory reached through a link (it fails if the
  canonicalisation bypasses the observer), the environment, and directories
  that cannot be resolved.
- The restore-cone census starts our evaluation where the oracle starts.
  The nine `MSBuildStartupDirectory` reads move from "unset, inexact (the
  toolset); set in MSBuild" to "value agrees", and nothing else moves.

Part of #674.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant