Repository navigation
msbuild: model the Unix path adjustment on every expansion (#987) - #992
Merged
Merged
Conversation
MSBuild passes each piece of an expansion (a literal run, a reference's value) and then the whole expanded value through MaybeAdjustFilePath on a non-Windows host. A value MSBuild stores without expanding it (a global, the environment, a toolset or reserved name, a task output) keeps its `\` until a read adjusts it, so the host's MSBuildUserExtensionsPath (`$(LocalAppData)` + `Microsoft\MSBuild`) read into a body is `.../Microsoft/MSBuild` in MSBuild and was committed raw by the walk. The walk also committed every other backslash-bearing body raw, including absolute project text such as `$(MSBuildProjectDirectory)\obj\`. `properties::substitute` now adjusts each piece and then the whole value (`path_fixup::adjust`): a probe of `.`/`..` hits, an absolute one is asked through `observed` with .NET's Directory.Exists / FileOrDirectoryExists, and a relative one turns on the working directory. Property entries record whether MSBuild stored them as given (`Origin::Seed`) or as an expansion's result. A seed's backslash that meets a relative probe, and any absolute probe on the path that asks no file system, declines with the new `PathAdjustmentUndecided` diagnostic. Project text's relative probe is still taken to miss: declining it would decline the SDK's own `obj\` (the deferred provenance dimension of the plan). A quoted condition operand is expanded, and adjusted, only when MSBuild's scanner saw something to expand in it. The executor, whose targets run in the project's directory, declines every relative probe, and any read of an item list beside a backslash (MSBuild adjusts that list only with the whole value). `path_fixup_expansion_diff` holds this to MSBuild started from an empty working directory and one holding every relative segment, over generated values from five sources (literal, written, global, environment, the host's MSBuildUserExtensionsPath) at four read sites (body, condition, Exists, property function). `fsproj_global_perturbation_diff` now reads MSBuildUserExtensionsPath into bodies, in a route case that must commit under every global set and in the generator's mixed population. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #987.
The rule, from MSBuild 18.9's source
On a non-Windows host every
ExpandIntoString…passes each piece of an expansion (a literal run, or what a$(…)returns:Expander.SpanBasedConcatenator) and then the whole value (Expander.ExpandIntoStringLeaveEscaped) throughFileUtilities.MaybeAdjustFilePath. The rewrite is kept when the first segment of the rewritten text is a directory. A segment under the root is probed withPath.Combine("", "/seg"), which ignores the working directory, so that answer is a fact of the file system. A relative segment depends on the working directory.What the fixup does to a value does not depend on where the value came from. What does depend on it is whether the fixup has already run: a property write is stored after expansion, while a global, the environment, a toolset or reserved name, or a task output is stored as given. So the host's
MSBuildUserExtensionsPath($(LocalAppData)+Microsoft\MSBuild) keeps its\until a body reads it. The read then rewrites it, because/Users(or/home) exists.The walk applied none of this to bodies. Every body holding a backslash was committed raw and trusted. That included absolute project text, such as
$(MSBuildProjectDirectory)\obj\, which MSBuild evaluates to…/obj/.The change
path_fixup::adjustasks each probe:./..and the root are directories; any other absolute segment is asked throughobservedwithdotnet_io'sDirectory.Exists/FileOrDirectoryExists; a relative segment depends on the working directory.properties::substituteadjusts each piece, then the whole value. Each property entry records how MSBuild stored it (Origin::SeedorOrigin::Expansion).PathAdjustmentUndecideddiagnostic: a seed's backslash that meets a relative probe, and any absolute probe on the path that asks no file system (parse_fsproj).obj\, and with it the NuGet chain (the deferred provenance dimension indocs/msbuild-unix-path-fixup-plan.md, updated here).Scanner.ParseQuotedString).substitute_in_target). It also declines any item list read beside a backslash, because MSBuild adjusts the list only together with the whole value. Codex found this case in round 2, and therunTargetsdifferential now generates it.Grading
path_fixup_expansion_diff: MSBuild runs from an empty working directory and from one that holds every generated relative segment. It covers values with\,/,\\,%5c, quotes,./.., absolute first segments that exist or are missing, relative segments and UNC prefixes. There are five sources: literal, written, global, environment, and the host'sMSBuildUserExtensionsPath. There are four read sites: body, condition,Exists, and property function (Combine/Concat). Every commit, with imports or without, must equal MSBuild's value from the empty directory. Where MSBuild's value moves between the two directories, we may commit only if the document's own text holds a\, so any movement that a seed causes must have been declined. The census floors commits per source. I soaked it for 45,000 cases on fresh seeds with no failures. The issue's shape is pinned as a separate test.fsproj_global_perturbation_diff: the body-read shape is back. A new route case readsMSBuildUserExtensionsPathinto two bodies and must commit under every global set, and the generator's mixed population can draw it.fsproj_target_execution_generative_diff: identities and values with a backslash next to an item list.late_sdk_seeding_overrides_prior_project_write_to_reserved_toolset_propertyexpected…\NuGet.propsraw. MSBuild gives…/NuGet.props, so I updated the expectation. TheFSharp.Compiler.Service.Releasepure-path snapshot drops two//lex.fsitems. Their include needs a probe of/lex.fs, which the pure path cannot make.Not covered (follow-ups)
\on Unix (MSB4025: it looks forp/q/…), but the walk evaluates it.Gates
cargo fmt --all --check: 0cargo clippy --workspace --all-targets -- -D warnings: 0cargo clippy -p borzoi-msbuild --all-targets --all-features -- -D warnings(final head): 0cargo clippy -p borzoi-msbuild --lib -- -D warnings: 0RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --document-private-items: 0RUSTDOCFLAGS="-D warnings" cargo doc -p borzoi-msbuild --no-deps --document-private-items: 0cargo test --workspace --no-fail-fast: 0. This ran on the head before the executor fix from codex round 2, and the fix touches only msbuild.cargo test -p borzoi-msbuild --no-fail-faston the final head: 0.fsproj_msbuild_corpus_diff -- --ignored: 0.sdk_chain_decline_attribution -- --ignored: 0.tools/ci/project-corpus-gate.sh: 0. All steps ran before the executor fix;restore-graphandrestore-conewere rerun on the final head: 0.Codex: round 1 had no findings. Round 2 found the item-list boundary issue, now fixed and generated. Round 3 had no findings.
🤖 Generated with Claude Code