qmake: Scan source files with QFile

The C API we've used so far underlies stronger restrictions regarding
path length than QFile.  Since qmake is not bootstrapped anymore, we can
use QFile.

Task-number: QTBUG-99791
Change-Id: Ic7765b0c09a8aa07c208c1b1d02efe0c54bb44f2
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Joerg Bornemann 2022-01-24 12:52:38 +01:00
parent 31b8a7e5ed
commit 747bca3d67

View File

@ -29,6 +29,7 @@
#include "makefiledeps.h" #include "makefiledeps.h"
#include "option.h" #include "option.h"
#include <qfile.h>
#include <qdir.h> #include <qdir.h>
#include <qdatetime.h> #include <qdatetime.h>
#include <qfileinfo.h> #include <qfileinfo.h>
@ -40,16 +41,8 @@
# include <io.h> # include <io.h>
#endif #endif
#include <qdebug.h> #include <qdebug.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h> #include <time.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h> #include <limits.h>
#if defined(_MSC_VER) && _MSC_VER >= 1400
#include <share.h>
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -515,28 +508,17 @@ bool QMakeSourceFileInfo::findDeps(SourceFile *file)
const QMakeLocalFileName sourceFile = fixPathForFile(file->file, true); const QMakeLocalFileName sourceFile = fixPathForFile(file->file, true);
struct stat fst;
char *buffer = nullptr; char *buffer = nullptr;
int buffer_len = 0; int buffer_len = 0;
{ {
int fd; QFile f(sourceFile.local());
#if defined(_MSC_VER) && _MSC_VER >= 1400 if (!f.open(QIODevice::ReadOnly))
if (_sopen_s(&fd, sourceFile.local().toLatin1().constData(),
_O_RDONLY, _SH_DENYNO, _S_IREAD) != 0)
fd = -1;
#else
fd = open(sourceFile.local().toLatin1().constData(), O_RDONLY);
#endif
if (fd == -1 || fstat(fd, &fst) || S_ISDIR(fst.st_mode)) {
if (fd != -1)
QT_CLOSE(fd);
return false; return false;
} const qint64 fs = f.size();
buffer = getBuffer(fst.st_size); buffer = getBuffer(fs);
for(int have_read = 0; for(int have_read = 0;
(have_read = QT_READ(fd, buffer + buffer_len, fst.st_size - buffer_len)); (have_read = f.read(buffer + buffer_len, fs - buffer_len));
buffer_len += have_read) ; buffer_len += have_read) ;
QT_CLOSE(fd);
} }
if(!buffer) if(!buffer)
return false; return false;
@ -901,25 +883,13 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file)
int buffer_len = 0; int buffer_len = 0;
char *buffer = nullptr; char *buffer = nullptr;
{ {
struct stat fst; QFile f(fixPathForFile(file->file, true).local());
int fd; if (!f.open(QIODevice::ReadOnly))
#if defined(_MSC_VER) && _MSC_VER >= 1400
if (_sopen_s(&fd, fixPathForFile(file->file, true).local().toLocal8Bit().constData(),
_O_RDONLY, _SH_DENYNO, _S_IREAD) != 0)
fd = -1;
#else
fd = open(fixPathForFile(file->file, true).local().toLocal8Bit().constData(), O_RDONLY);
#endif
if (fd == -1 || fstat(fd, &fst) || S_ISDIR(fst.st_mode)) {
if (fd != -1)
QT_CLOSE(fd);
return false; //shouldn't happen return false; //shouldn't happen
} const qint64 fs = f.size();
buffer = getBuffer(fst.st_size); buffer = getBuffer(fs);
while (int have_read = QT_READ(fd, buffer + buffer_len, fst.st_size - buffer_len)) while (int have_read = f.read(buffer + buffer_len, fs - buffer_len))
buffer_len += have_read; buffer_len += have_read;
QT_CLOSE(fd);
} }
debug_msg(2, "findMocs: %s", file->file.local().toLatin1().constData()); debug_msg(2, "findMocs: %s", file->file.local().toLatin1().constData());