qmake: Distinguish local header files by directory and name

Information about header files is cached by qmake. The key is the
filename of the #include directive. For system includes (<stdio.h>) this
is unique, according to the search order in INCLUDE_PATH.

For local includes, given as "foo.h", there may be name collisions. Usually a
compiler first searches in the directory of the current file (stored in the
sourceDir variable), and only in case of a miss the INCLUDE_PATH is
considered.

The dependency generation now distinguishes local header files by their full
relative path. This is implemented by forcing the use of the full relative
path as key into the SourceFiles data structure if the flag try_local is set.

Change-Id: Ifd75325b53496824054595f7fc98d71bbd9d8aa6
Fixes: QTBUG-72383
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Matthias Doerfel 2019-05-04 19:51:53 +03:00 committed by Kai Koehne
parent b5154b5254
commit f6238e2d3b

View File

@ -837,7 +837,9 @@ bool QMakeSourceFileInfo::findDeps(SourceFile *file)
if(inc) {
if(!includes)
includes = new SourceFiles;
SourceFile *dep = includes->lookupFile(inc);
/* QTBUG-72383: Local includes "foo.h" must first be resolved relative to the
* sourceDir, only global includes <bar.h> are unique. */
SourceFile *dep = try_local ? nullptr : includes->lookupFile(inc);
if(!dep) {
bool exists = false;
QMakeLocalFileName lfn(inc);
@ -876,7 +878,11 @@ bool QMakeSourceFileInfo::findDeps(SourceFile *file)
dep->file = lfn;
dep->type = QMakeSourceFileInfo::TYPE_C;
files->addFile(dep);
includes->addFile(dep, inc, false);
/* QTBUG-72383: Local includes "foo.h" are keyed by the resolved
* path (stored in dep itself), only global includes <bar.h> are
* unique keys immediately. */
const char *key = try_local ? nullptr : inc;
includes->addFile(dep, key, false);
}
dep->exists = exists;
}