Skip to content

fix: forward --pathmap: option to FCS so CallerFilePath respects (PathMap)#4585

Draft
fable-repo-assist[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-pathmap-caller-file-path-4061-0b03ef4246fe586e
Draft

fix: forward --pathmap: option to FCS so CallerFilePath respects (PathMap)#4585
fable-repo-assist[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-pathmap-caller-file-path-4061-0b03ef4246fe586e

Conversation

@fable-repo-assist
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Fixes #4061[<CallerFilePath>] always produces absolute paths even when the project configures <PathMap>, <DeterministicSourcePaths>, or <SourceRoot>.

Root Cause

extractUsefulOptionsAndSources in ProjectCracker.fs selectively forwards only a small set of compiler options to FCS (--langversion:, --checknulls+, --nowarn, --warnon, --define:). The --pathmap: flag emitted by MSBuild (from <PathMap> / <DeterministicSourcePaths>) was silently dropped, leaving g.pathMap empty in FCS. Since PathMap.apply is a no-op on an empty map, [<CallerFilePath>] always returned the full absolute path.

Fix

Forward --pathmap: from the main project only — mirroring how --langversion:preview is handled — so that FCS applies the configured path mapping when resolving CallerFilePath arguments:

// Forward pathmap from the main project so CallerFilePath respects <PathMap>/<DeterministicSourcePaths>
elif line.StartsWith("--pathmap:", StringComparison.Ordinal) && isMainProj then
    accSources, line :: accOptions

Restricting this to isMainProj means path mappings from referenced libraries don't bleed into the compilation of the main project (consistent with how other project-level options are handled).

Testing

This is a project-cracker-level change. The fix takes effect as soon as the fsproj contains the relevant MSBuild properties, e.g.:

<PropertyGroup>
  <Deterministic>true</Deterministic>
  <DeterministicSourcePaths>true</DeterministicSourcePaths>
  <PathMap>$(MSBuildThisFileDirectory)=.</PathMap>
</PropertyGroup>

With this change, [<CallerFilePath>] should return ./Api/Program.fs instead of the full absolute path.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@51c8f6ad4357d2ecc06e47120031b3d75e80227d

…hMap>

When MSBuild generates compiler options for an fsproj that uses
<PathMap>, <DeterministicSourcePaths>, or <SourceRoot>, it emits a
--pathmap:... flag. Previously, extractUsefulOptionsAndSources discarded
this flag, so FCS always used an empty PathMap and CallerFilePath always
returned absolute paths regardless of the user's configuration.

Forward --pathmap: from the main project only (mirroring how --langversion:
is handled) so that [<CallerFilePath>] respects the configured path
mappings at compile time.

Closes #4061

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@fable-repo-assist fable-repo-assist Bot added automation Automated changes repo-assist Created by Repo Assist labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Automated changes repo-assist Created by Repo Assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deterministic/relative paths in CallerFilePath

0 participants