This patch transforms the given input headers to relative (angled)
include names using header search entries and some heuritics.
For example: /Path/To/Header.h will be included as <Header.h> with a
search path of -I /Path/To/; and
/Path/To/Framework.framework/Headers/Header.h will be included as
<Framework/Header.h>, given a search path of -F /Path/To.
Headermaps will also be queried in reverse to find a spelled name to
include headers.
Original Summary:
Proof-of-concept patch. Needs more work.
Transform input headers to relative (angle) includes.
getRelativeIncludeName walks HeaderSearchOptions::UserEntries to try
to find a relative include stem. Problems:
- do we want the exact logic of HeaderSearch::suggestPathToFileForDiagnostics?
- in ExtractAPIAction::PrepareToExecuteAction where the includes are transformed, we don't have a pre-processor yet, so we don't have access to a lot of useful information like HeaderSearch, headermaps, DirectoryLookup etc.
- we might not always want to transform an absolute path because the resulting relative include name might get remapped in a headermap, for example in test known_files_only_hmap.c. But how does it work with modules where we need relative includes? Is the setup in known_files_only_hmap even valid?
- reverse lookup in headermap when deciding if the symbol is coming from a knwon file: I think my current implementation is correct and necessary to solve the headermap problem, but might have problems due to the above point: an unknown file might be mapped to the transformed relative name of a known input.
I think the key problem is that, by passing in an input
/absolute/path/header.h, do we mean to process the actual content of
that particular header, or do we mean to use it just as a "lable" and
the thing we really want to process is whatever this lable points to
with the given search paths and headermaps?
In the example of frameworks, I think the latter is true: we want to
use DSTROOT to pass in the headers because DSTROOT has a defined
framework layout so that we can transform the paths to framework-style
relative includes by matching the layout pattern *.framework/Header/
and rely on headermaps/VFS/module/search paths to find the intended
headers.
In that sense, the known_files_only_hmap test is a really strange
setup with ambiguious intention and context.
This does rely on the path separator being "/". If stick with this regex, do we need to convert all paths to POSIX format? I think the best thing to do is to iterate through the given path components and match for just "(.+)\\.framework" to match just the framework name and the use the base name of the file directly instead of matching it via the regex as well...