Skip to content

Fix paths of custom commands in vs backend - #16349

Open
bruchar1 wants to merge 3 commits into
mesonbuild:masterfrom
bruchar1:vs-backend-abs-paths
Open

bruchar1 wants to merge 3 commits into
mesonbuild:masterfrom
bruchar1:vs-backend-abs-paths

Conversation

@bruchar1

@bruchar1 bruchar1 commented Nov 6, 2026

Copy link
Copy Markdown
Member

VS runs commands relatively to the project file location, and not from the build root. This is why it was using target.absolute_paths to make it work. However, this wasn't working when using a custom target inside the arguments of another target, since paths where then resolved from the wrong root. This fixes that problem, and allows the use of relative paths inside the vs backend, while keeping the current behavior of the ninja backend.

Add a CommandPaths dataclass to the backend to keep track of absolute
and relative target command paths, to allow each backend implementation to use
what it needs. This replaces the `absolute_outputs` boolean.
Add a test case to ensure all backends will continue to handle
those paths correctly after refactors. At this point, generated ninja or
project are identical as before.
When a custom target is used as element of of another target arguments,
it was given a path relative to build root. This works with ninja,
but was broken on vs backend because vs runs the command from the
project root. Fixed using the CommandPaths object introduced in the
previous commit. Tests were updated for this case.

- removes `target.absolute_paths = True` from the VS backend, so the
  backend no longer modifies the build model.
- routes `@PRIVATE_DIR@` and the inputs through `CommandPaths`, which is
  what makes removing that line possible.
- xcode custom target input become absolute paths.
- ninja targets with `absolute_paths` get an absolute path for a custom
  target used in their command.
In the VS backend, use paths relative to the project file instead of
absolute paths for custom target commands.

- Fix dependency tracking for run targets in sub-directories (they were
  relative to build root, but VS resolves them from the project file
  dir)
- Normalize paths in `CommandPaths.build()` for prettier results.
- `get_target_depend_files()` now takes `CommandPaths` as argument
  instead of a boolean.
@bruchar1
bruchar1 requested a review from jpakkane as a code owner November 6, 2026 22:58
@bruchar1 bruchar1 added the backend:visualstudio Visual Studio project backends label Nov 6, 2026
@bonzini bonzini added this to the 1.14 milestone Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:visualstudio Visual Studio project backends

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants