Commit 445fe4a
authored
fix(depinfo): prevent invalid trailing backslash on Windows (#16223)
### What does this PR try to resolve?
Fixes #16096.
Finally found some time to trace the issue to its roots:
cargo tries to convert dep paths to relative ones. If a path is either
1. `pkg_root` or `build_root` itself (see
`DepInfoPathType::PackageRootRelative` and
`DepInfoPathType::BuildRootRelative`), causing the `EncodedDepInfo` to
store an empty path, or
2. an explicitly empty path is provided (e.g. via
`println!("cargo::rerun-if-changed=");`),
then cargo will join the respecive root paths with an empty path.
Joining with an empty path [adds a trailing path
separator](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=d36571ed84f4cd4476097050ff167f34).
On systems with a `/` main separator, this works fine. On Windows,
however, this adds a trailing backslash. Trailing backslashes are
incompatible with `.d` dep file paths.
This PR adds the necessary checks and ensures that instead of
`foo.join("")` we return `foo` (instead of effectively `foo +
std::path::MAIN_SEPARATOR_STR`).
Importantly, this PR does not change the behavior for any other paths
passed in (e.g. paths explicitly ending in a backslash), and only
focuses on unintentional backslashes outside of the user's control.
### How to test and review this PR?
The first commit shows the unintended behavior in two tests; the second
commit fixes the issue and alters the tests to reflect the new behavior.File tree
3 files changed
+124
-7
lines changed- src/cargo/core/compiler
- fingerprint
- tests/testsuite
3 files changed
+124
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
510 | 516 | | |
| 517 | + | |
| 518 | + | |
511 | 519 | | |
512 | 520 | | |
513 | 521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
90 | 99 | | |
91 | 100 | | |
92 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
0 commit comments