Skip to content

PathMap should prefer more specific prefix mapping #46061

@tmat

Description

@tmat

Currently the mappings are applied in the order they are specified, regardless of whether one prefix is more specific than other.

Thus a mapping specified earlier in the list overrides more specific mapping specified later in the list.

csc /target:library /debug:portable a.cs a\b.cs a\b\c.cs /pathmap:C:\temp\=/_1/,C:\temp\a\=/_2/,C:\temp\a\b\=/_3/

This behavior is not desirable since one might want to specify a SourceRoot that covers a specified directory with the goal to make all paths from such directory deterministic, but other SourceRoots might be available for subdirectories that add Source Link information. By ignoring the subdirectories and normalizing the the containing directory root the Source Link information is lost.

For example, NuGet targets set a SourceRoot for the entire package cache root to make sure source packages do not break deterministic build even when these packages don't define their own SourceRoot. Source packages built with with Source Link enabled do however add their SourceRoot entry (with Source Link metadata). This entry is however overridden in path map due to the above behavior.

Version Used:
3.8.0-1.20360.1 (ec2c0bc)

Steps to Reproduce:

  1. Unzip repro.zip.
  2. Run repro.cmd
  3. Run mdv a.pdb

Expected Behavior:

Document (index: 0x30, size: 24):
============================================================================================================================================================
   Name                   Language  HashAlgorithm  Hash
============================================================================================================================================================
1: '/_1/a.cs' (#84d)      C# (#4)   SHA-256 (#3)   86-6B-7E-F8-37-4C-22-F9-E9-3B-DA-2F-DC-9B-6C-2C-DB-AB-BA-55-F4-AA-77-B9-74-50-52-22-06-31-97-1A (#854)
2: '/_2/b.cs' (#87c)    C# (#4)   SHA-256 (#3)   B8-9B-74-2E-6D-FA-D2-A6-7F-80-7E-29-BA-07-93-0C-D3-5F-97-16-B6-6A-1B-26-21-C8-45-69-D0-96-4B-6C (#885)
3: '/_3/c.cs' (#8ad)  C# (#4)   SHA-256 (#3)   CE-8F-5A-CE-5C-4F-85-A8-81-5E-A4-B9-E0-B2-47-24-BD-FF-C0-4C-68-40-20-8F-A6-47-39-A5-67-2C-9F-3D (#8b8)

Actual Behavior:

Document (index: 0x30, size: 24):
============================================================================================================================================================
   Name                   Language  HashAlgorithm  Hash
============================================================================================================================================================
1: '/_1/a.cs' (#84d)      C# (#4)   SHA-256 (#3)   86-6B-7E-F8-37-4C-22-F9-E9-3B-DA-2F-DC-9B-6C-2C-DB-AB-BA-55-F4-AA-77-B9-74-50-52-22-06-31-97-1A (#854)
2: '/_1/a/b.cs' (#87c)    C# (#4)   SHA-256 (#3)   B8-9B-74-2E-6D-FA-D2-A6-7F-80-7E-29-BA-07-93-0C-D3-5F-97-16-B6-6A-1B-26-21-C8-45-69-D0-96-4B-6C (#885)
3: '/_1/a/b/c.cs' (#8ad)  C# (#4)   SHA-256 (#3)   CE-8F-5A-CE-5C-4F-85-A8-81-5E-A4-B9-E0-B2-47-24-BD-FF-C0-4C-68-40-20-8F-A6-47-39-A5-67-2C-9F-3D (#8b8)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions