···116116 match rewrite_first prefix_map path with
117117 | None -> path
118118 | Some path -> path
119119+120120+let make_source path : pair option -> path option = function
121121+ | None -> None
122122+ | Some { target; source } ->
123123+ if String.starts_with ~prefix:target path then
124124+ Some (source ^ (String.sub path (String.length target)
125125+ (String.length path - String.length target)))
126126+ else None
127127+128128+let invert_all prefix_map path =
129129+ List.filter_map (make_source path) (List.rev prefix_map)
+7
utils/build_path_prefix_map.mli
···5959(** [rewrite path] uses [rewrite_first] to try to find a
6060 mapping for path. If found, it returns that, otherwise
6161 it just returns [path]. *)
6262+6363+val invert_all : map -> path -> path list
6464+(** [invert_all map path] finds all targets in [map] that are a prefix
6565+ of the input [path]. For each matching target, in priority order,
6666+ it replaces this prefix with the corresponding source and adds the
6767+ result to the returned list. If there are no matches, it just
6868+ returns [[]]. *)
+8
utils/misc.ml
···11381138 end;
11391139 !map_cache
1140114011411141+let invert_build_path_prefix_map path =
11421142+ match get_build_path_prefix_map () with
11431143+ | None -> [path]
11441144+ | Some prefix_map ->
11451145+ match Build_path_prefix_map.invert_all prefix_map path with
11461146+ | [] -> [path]
11471147+ | matches -> matches
11481148+11411149let debug_prefix_map_flags () =
11421150 if not Config.as_has_debug_prefix_map then
11431151 []
+5
utils/misc.mli
···607607(** Returns the map encoded in the [BUILD_PATH_PREFIX_MAP] environment
608608 variable. *)
609609610610+val invert_build_path_prefix_map: string -> string list
611611+(** Returns the potential paths (in priority order) from which the
612612+ given path can originate from before rewrite using
613613+ [BUILD_PATH_PREFIX_MAP] environment variable. *)
614614+610615val debug_prefix_map_flags: unit -> string list
611616(** Returns the list of [--debug-prefix-map] flags to be passed to the
612617 assembler, built from the [BUILD_PATH_PREFIX_MAP] environment variable. *)