2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
2016-01-21 02:33:50 +00:00
|
|
|
** Copyright (C) 2016 Intel Corporation.
|
2016-01-15 12:36:27 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "makefiledeps.h"
|
|
|
|
#include "option.h"
|
2022-01-24 11:52:38 +00:00
|
|
|
#include <qfile.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <qdir.h>
|
|
|
|
#include <qdatetime.h>
|
|
|
|
#include <qfileinfo.h>
|
|
|
|
#include <qbuffer.h>
|
|
|
|
#include <qplatformdefs.h>
|
|
|
|
#if defined(Q_OS_UNIX)
|
|
|
|
# include <unistd.h>
|
|
|
|
#else
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
#include <qdebug.h>
|
|
|
|
#include <time.h>
|
2016-10-25 09:43:56 +00:00
|
|
|
#include <limits.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2015-11-12 15:30:15 +00:00
|
|
|
// FIXME: a line ending in CRLF gets counted as two lines.
|
2011-04-27 10:05:43 +00:00
|
|
|
#if 1
|
|
|
|
#define qmake_endOfLine(c) (c == '\r' || c == '\n')
|
|
|
|
#else
|
|
|
|
inline bool qmake_endOfLine(const char &c) { return (c == '\r' || c == '\n'); }
|
|
|
|
#endif
|
|
|
|
|
2019-08-06 12:35:04 +00:00
|
|
|
QMakeLocalFileName::QMakeLocalFileName(const QString &name)
|
|
|
|
: real_name(name)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
const QString
|
|
|
|
&QMakeLocalFileName::local() const
|
|
|
|
{
|
2019-08-06 12:35:04 +00:00
|
|
|
if (!isNull() && local_name.isNull())
|
2014-11-24 15:02:38 +00:00
|
|
|
local_name = Option::normalizePath(real_name);
|
2011-04-27 10:05:43 +00:00
|
|
|
return local_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SourceDependChildren;
|
|
|
|
struct SourceFile {
|
2018-08-02 22:22:24 +00:00
|
|
|
SourceFile() : deps(nullptr), type(QMakeSourceFileInfo::TYPE_UNKNOWN),
|
2011-04-27 10:05:43 +00:00
|
|
|
mocable(0), traversed(0), exists(1),
|
|
|
|
moc_checked(0), dep_checked(0), included_count(0) { }
|
|
|
|
~SourceFile();
|
|
|
|
QMakeLocalFileName file;
|
|
|
|
SourceDependChildren *deps;
|
|
|
|
QMakeSourceFileInfo::SourceFileType type;
|
|
|
|
uint mocable : 1, traversed : 1, exists : 1;
|
|
|
|
uint moc_checked : 1, dep_checked : 1;
|
|
|
|
uchar included_count;
|
|
|
|
};
|
|
|
|
struct SourceDependChildren {
|
|
|
|
SourceFile **children;
|
|
|
|
int num_nodes, used_nodes;
|
2018-08-02 22:22:24 +00:00
|
|
|
SourceDependChildren() : children(nullptr), num_nodes(0), used_nodes(0) { }
|
|
|
|
~SourceDependChildren() { if (children) free(children); children = nullptr; }
|
2011-04-27 10:05:43 +00:00
|
|
|
void addChild(SourceFile *s) {
|
|
|
|
if(num_nodes <= used_nodes) {
|
|
|
|
num_nodes += 200;
|
|
|
|
children = (SourceFile**)realloc(children, sizeof(SourceFile*)*(num_nodes));
|
|
|
|
}
|
|
|
|
children[used_nodes++] = s;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
SourceFile::~SourceFile() { delete deps; }
|
|
|
|
class SourceFiles {
|
|
|
|
int hash(const char *);
|
|
|
|
public:
|
|
|
|
SourceFiles();
|
|
|
|
~SourceFiles();
|
|
|
|
|
|
|
|
SourceFile *lookupFile(const char *);
|
|
|
|
inline SourceFile *lookupFile(const QString &f) { return lookupFile(f.toLatin1().constData()); }
|
|
|
|
inline SourceFile *lookupFile(const QMakeLocalFileName &f) { return lookupFile(f.local().toLatin1().constData()); }
|
2018-08-02 22:22:24 +00:00
|
|
|
void addFile(SourceFile *, const char *k = nullptr, bool own = true);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
struct SourceFileNode {
|
2018-08-02 22:22:24 +00:00
|
|
|
SourceFileNode() : key(nullptr), next(nullptr), file(nullptr), own_file(1) { }
|
2011-04-27 10:05:43 +00:00
|
|
|
~SourceFileNode() {
|
|
|
|
delete [] key;
|
|
|
|
if(own_file)
|
|
|
|
delete file;
|
|
|
|
}
|
|
|
|
char *key;
|
|
|
|
SourceFileNode *next;
|
|
|
|
SourceFile *file;
|
|
|
|
uint own_file : 1;
|
|
|
|
} **nodes;
|
|
|
|
int num_nodes;
|
|
|
|
};
|
|
|
|
SourceFiles::SourceFiles()
|
|
|
|
{
|
|
|
|
nodes = (SourceFileNode**)malloc(sizeof(SourceFileNode*)*(num_nodes=3037));
|
|
|
|
for(int n = 0; n < num_nodes; n++)
|
2018-08-02 22:22:24 +00:00
|
|
|
nodes[n] = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceFiles::~SourceFiles()
|
|
|
|
{
|
|
|
|
for(int n = 0; n < num_nodes; n++) {
|
|
|
|
for(SourceFileNode *next = nodes[n]; next;) {
|
|
|
|
SourceFileNode *next_next = next->next;
|
|
|
|
delete next;
|
|
|
|
next = next_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SourceFiles::hash(const char *file)
|
|
|
|
{
|
|
|
|
uint h = 0, g;
|
|
|
|
while (*file) {
|
|
|
|
h = (h << 4) + *file;
|
|
|
|
if ((g = (h & 0xf0000000)) != 0)
|
|
|
|
h ^= g >> 23;
|
|
|
|
h &= ~g;
|
|
|
|
file++;
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceFile *SourceFiles::lookupFile(const char *file)
|
|
|
|
{
|
|
|
|
int h = hash(file) % num_nodes;
|
|
|
|
for(SourceFileNode *p = nodes[h]; p; p = p->next) {
|
|
|
|
if(!strcmp(p->key, file))
|
|
|
|
return p->file;
|
|
|
|
}
|
2018-08-02 22:22:24 +00:00
|
|
|
return nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SourceFiles::addFile(SourceFile *p, const char *k, bool own_file)
|
|
|
|
{
|
2012-02-22 15:17:30 +00:00
|
|
|
const QByteArray ba = p->file.local().toLatin1();
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!k)
|
2012-02-22 15:17:30 +00:00
|
|
|
k = ba.constData();
|
2011-04-27 10:05:43 +00:00
|
|
|
int h = hash(k) % num_nodes;
|
|
|
|
SourceFileNode *pn = new SourceFileNode;
|
|
|
|
pn->own_file = own_file;
|
|
|
|
pn->key = qstrdup(k);
|
|
|
|
pn->file = p;
|
|
|
|
pn->next = nodes[h];
|
|
|
|
nodes[h] = pn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeSourceFileInfo::dependTreeWalker(SourceFile *node, SourceDependChildren *place)
|
|
|
|
{
|
|
|
|
if(node->traversed || !node->exists)
|
|
|
|
return;
|
|
|
|
place->addChild(node);
|
|
|
|
node->traversed = true; //set flag
|
|
|
|
if(node->deps) {
|
|
|
|
for(int i = 0; i < node->deps->used_nodes; i++)
|
|
|
|
dependTreeWalker(node->deps->children[i], place);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 09:11:44 +00:00
|
|
|
void QMakeSourceFileInfo::setDependencyPaths(const QList<QMakeLocalFileName> &l)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
// Ensure that depdirs does not contain the same paths several times, to minimize the stats
|
2020-07-06 09:11:44 +00:00
|
|
|
QList<QMakeLocalFileName> ll;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < l.count(); ++i) {
|
|
|
|
if (!ll.contains(l.at(i)))
|
|
|
|
ll.append(l.at(i));
|
|
|
|
}
|
|
|
|
depdirs = ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QMakeSourceFileInfo::dependencies(const QString &file)
|
|
|
|
{
|
|
|
|
QStringList ret;
|
|
|
|
if(!files)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if(SourceFile *node = files->lookupFile(QMakeLocalFileName(file))) {
|
|
|
|
if(node->deps) {
|
|
|
|
/* I stick them into a SourceDependChildren here because it is faster to just
|
|
|
|
iterate over the list to stick them in the list, and reset the flag, then it is
|
|
|
|
to loop over the tree (about 50% faster I saw) --Sam */
|
|
|
|
SourceDependChildren place;
|
|
|
|
for(int i = 0; i < node->deps->used_nodes; i++)
|
|
|
|
dependTreeWalker(node->deps->children[i], &place);
|
|
|
|
if(place.children) {
|
|
|
|
for(int i = 0; i < place.used_nodes; i++) {
|
|
|
|
place.children[i]->traversed = false; //reset flag
|
|
|
|
ret.append(place.children[i]->file.real());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QMakeSourceFileInfo::included(const QString &file)
|
|
|
|
{
|
|
|
|
if (!files)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(SourceFile *node = files->lookupFile(QMakeLocalFileName(file)))
|
|
|
|
return node->included_count;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QMakeSourceFileInfo::mocable(const QString &file)
|
|
|
|
{
|
|
|
|
if(SourceFile *node = files->lookupFile(QMakeLocalFileName(file)))
|
|
|
|
return node->mocable;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-15 08:42:30 +00:00
|
|
|
QMakeSourceFileInfo::QMakeSourceFileInfo()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
//dep_mode
|
|
|
|
dep_mode = Recursive;
|
|
|
|
|
|
|
|
//quick project lookups
|
2018-08-02 22:22:24 +00:00
|
|
|
includes = files = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
files_changed = false;
|
|
|
|
|
|
|
|
//buffer
|
2018-08-02 22:22:24 +00:00
|
|
|
spare_buffer = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
spare_buffer_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMakeSourceFileInfo::~QMakeSourceFileInfo()
|
|
|
|
{
|
|
|
|
//buffer
|
|
|
|
if(spare_buffer) {
|
|
|
|
free(spare_buffer);
|
2018-08-02 22:22:24 +00:00
|
|
|
spare_buffer = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
spare_buffer_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//quick project lookup
|
|
|
|
delete files;
|
|
|
|
delete includes;
|
|
|
|
}
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
void QMakeSourceFileInfo::addSourceFiles(const ProStringList &l, uchar seek,
|
2011-04-27 10:05:43 +00:00
|
|
|
QMakeSourceFileInfo::SourceFileType type)
|
|
|
|
{
|
|
|
|
for(int i=0; i<l.size(); ++i)
|
2012-09-06 10:21:38 +00:00
|
|
|
addSourceFile(l.at(i).toQString(), seek, type);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
void QMakeSourceFileInfo::addSourceFile(const QString &f, uchar seek,
|
|
|
|
QMakeSourceFileInfo::SourceFileType type)
|
|
|
|
{
|
|
|
|
if(!files)
|
|
|
|
files = new SourceFiles;
|
|
|
|
|
|
|
|
QMakeLocalFileName fn(f);
|
|
|
|
SourceFile *file = files->lookupFile(fn);
|
|
|
|
if(!file) {
|
|
|
|
file = new SourceFile;
|
|
|
|
file->file = fn;
|
|
|
|
files->addFile(file);
|
|
|
|
} else {
|
|
|
|
if(file->type != type && file->type != TYPE_UNKNOWN && type != TYPE_UNKNOWN)
|
|
|
|
warn_msg(WarnLogic, "%s is marked as %d, then %d!", f.toLatin1().constData(),
|
|
|
|
file->type, type);
|
|
|
|
}
|
|
|
|
if(type != TYPE_UNKNOWN)
|
|
|
|
file->type = type;
|
|
|
|
|
|
|
|
if(seek & SEEK_MOCS && !file->moc_checked)
|
|
|
|
findMocs(file);
|
|
|
|
if(seek & SEEK_DEPS && !file->dep_checked)
|
|
|
|
findDeps(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QMakeSourceFileInfo::containsSourceFile(const QString &f, SourceFileType type)
|
|
|
|
{
|
|
|
|
if(SourceFile *file = files->lookupFile(QMakeLocalFileName(f)))
|
|
|
|
return (file->type == type || file->type == TYPE_UNKNOWN || type == TYPE_UNKNOWN);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-09 18:56:31 +00:00
|
|
|
bool QMakeSourceFileInfo::isSystemInclude(const QString &name)
|
|
|
|
{
|
|
|
|
if (QDir::isRelativePath(name)) {
|
|
|
|
// if we got a relative path here, it's either an -I flag with a relative path
|
|
|
|
// or an include file we couldn't locate. Either way, conclude it's not
|
|
|
|
// a system include.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < systemIncludes.size(); ++i) {
|
|
|
|
// check if name is located inside the system include dir:
|
|
|
|
QDir systemDir(systemIncludes.at(i));
|
|
|
|
QString relativePath = systemDir.relativeFilePath(name);
|
|
|
|
|
|
|
|
// the relative path might be absolute if we're crossing drives on Windows
|
|
|
|
if (QDir::isAbsolutePath(relativePath) || relativePath.startsWith("../"))
|
|
|
|
continue;
|
|
|
|
debug_msg(5, "File/dir %s is in system dir %s, skipping",
|
|
|
|
qPrintable(name), qPrintable(systemIncludes.at(i)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
char *QMakeSourceFileInfo::getBuffer(int s) {
|
|
|
|
if(!spare_buffer || spare_buffer_size < s)
|
|
|
|
spare_buffer = (char *)realloc(spare_buffer, spare_buffer_size=s);
|
|
|
|
return spare_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(x) (x & _S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QMakeLocalFileName QMakeSourceFileInfo::fixPathForFile(const QMakeLocalFileName &f, bool)
|
|
|
|
{
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMakeLocalFileName QMakeSourceFileInfo::findFileForDep(const QMakeLocalFileName &/*dep*/,
|
|
|
|
const QMakeLocalFileName &/*file*/)
|
|
|
|
{
|
|
|
|
return QMakeLocalFileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo QMakeSourceFileInfo::findFileInfo(const QMakeLocalFileName &dep)
|
|
|
|
{
|
|
|
|
return QFileInfo(dep.real());
|
|
|
|
}
|
|
|
|
|
2015-11-24 13:45:52 +00:00
|
|
|
static int skipEscapedLineEnds(const char *buffer, int buffer_len, int offset, int *lines)
|
|
|
|
{
|
|
|
|
// Join physical lines to make logical lines, as in the C preprocessor
|
|
|
|
while (offset + 1 < buffer_len
|
|
|
|
&& buffer[offset] == '\\'
|
|
|
|
&& qmake_endOfLine(buffer[offset + 1])) {
|
|
|
|
offset += 2;
|
|
|
|
++*lines;
|
|
|
|
if (offset < buffer_len
|
|
|
|
&& buffer[offset - 1] == '\r'
|
|
|
|
&& buffer[offset] == '\n') // CRLF
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool matchWhileUnsplitting(const char *buffer, int buffer_len, int start,
|
|
|
|
const char *needle, int needle_len,
|
|
|
|
int *matchlen, int *lines)
|
|
|
|
{
|
|
|
|
int x = start;
|
2016-04-15 13:27:45 +00:00
|
|
|
for (int n = 0; n < needle_len;
|
2015-11-24 13:45:52 +00:00
|
|
|
n++, x = skipEscapedLineEnds(buffer, buffer_len, x + 1, lines)) {
|
2016-04-15 13:27:45 +00:00
|
|
|
if (x >= buffer_len || buffer[x] != needle[n])
|
2015-11-24 13:45:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// That also skipped any remaining BSNLs immediately after the match.
|
|
|
|
|
|
|
|
// Tell caller how long the match was:
|
|
|
|
*matchlen = x - start;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-08 13:50:45 +00:00
|
|
|
/* Advance from an opening quote at buffer[offset] to the matching close quote. */
|
|
|
|
static int scanPastString(char *buffer, int buffer_len, int offset, int *lines)
|
|
|
|
{
|
2016-09-06 17:21:50 +00:00
|
|
|
// http://en.cppreference.com/w/cpp/language/string_literal
|
2015-12-08 13:50:45 +00:00
|
|
|
// It might be a C++11 raw string.
|
|
|
|
bool israw = false;
|
|
|
|
if (buffer[offset] == '"' && offset > 0) {
|
|
|
|
int explore = offset - 1;
|
2016-09-06 17:21:50 +00:00
|
|
|
bool prefix = false; // One of L, U, u or u8 may appear before R
|
|
|
|
bool saw8 = false; // Partial scan of u8
|
|
|
|
while (explore >= 0) {
|
|
|
|
// Cope with backslash-newline interruptions of the prefix:
|
|
|
|
if (explore > 0
|
|
|
|
&& qmake_endOfLine(buffer[explore])
|
|
|
|
&& buffer[explore - 1] == '\\') {
|
2015-12-08 13:50:45 +00:00
|
|
|
explore -= 2;
|
2016-09-06 17:21:50 +00:00
|
|
|
} else if (explore > 1
|
|
|
|
&& buffer[explore] == '\n'
|
2015-12-08 13:50:45 +00:00
|
|
|
&& buffer[explore - 1] == '\r'
|
|
|
|
&& buffer[explore - 2] == '\\') {
|
|
|
|
explore -= 3;
|
2016-09-06 17:21:50 +00:00
|
|
|
// Remaining cases can only decrement explore by one at a time:
|
|
|
|
} else if (saw8 && buffer[explore] == 'u') {
|
|
|
|
explore--;
|
|
|
|
saw8 = false;
|
|
|
|
prefix = true;
|
|
|
|
} else if (saw8 || prefix) {
|
|
|
|
break;
|
|
|
|
} else if (explore > 1 && buffer[explore] == '8') {
|
|
|
|
explore--;
|
|
|
|
saw8 = true;
|
|
|
|
} else if (buffer[explore] == 'L'
|
|
|
|
|| buffer[explore] == 'U'
|
|
|
|
|| buffer[explore] == 'u') {
|
|
|
|
explore--;
|
|
|
|
prefix = true;
|
|
|
|
} else if (buffer[explore] == 'R') {
|
|
|
|
if (israw)
|
|
|
|
break;
|
|
|
|
explore--;
|
|
|
|
israw = true;
|
2015-12-08 13:50:45 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 17:21:50 +00:00
|
|
|
// Check the R (with possible prefix) isn't just part of an identifier:
|
|
|
|
if (israw && explore >= 0
|
|
|
|
&& (isalnum(buffer[explore]) || buffer[explore] == '_')) {
|
|
|
|
israw = false;
|
|
|
|
}
|
2015-12-08 13:50:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (israw) {
|
|
|
|
#define SKIP_BSNL(pos) skipEscapedLineEnds(buffer, buffer_len, (pos), lines)
|
|
|
|
|
|
|
|
offset = SKIP_BSNL(offset + 1);
|
|
|
|
const char *const delim = buffer + offset;
|
|
|
|
int clean = offset;
|
|
|
|
while (offset < buffer_len && buffer[offset] != '(') {
|
|
|
|
if (clean < offset)
|
|
|
|
buffer[clean++] = buffer[offset];
|
|
|
|
else
|
|
|
|
clean++;
|
|
|
|
|
|
|
|
offset = SKIP_BSNL(offset + 1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
Not checking correctness (trust real compiler to do that):
|
|
|
|
- no controls, spaces, '(', ')', '\\' or (presumably) '"' in delim;
|
|
|
|
- at most 16 bytes in delim
|
|
|
|
|
|
|
|
Raw strings are surely defined after phase 2, when BSNLs are resolved;
|
|
|
|
so the delimiter's exclusion of '\\' and space (including newlines)
|
|
|
|
applies too late to save us the need to cope with BSNLs in it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const int delimlen = buffer + clean - delim;
|
|
|
|
int matchlen = delimlen, extralines = 0;
|
|
|
|
while ((offset = SKIP_BSNL(offset + 1)) < buffer_len
|
|
|
|
&& (buffer[offset] != ')'
|
|
|
|
|| (delimlen > 0 &&
|
|
|
|
!matchWhileUnsplitting(buffer, buffer_len,
|
|
|
|
offset + 1, delim, delimlen,
|
|
|
|
&matchlen, &extralines))
|
|
|
|
|| buffer[offset + 1 + matchlen] != '"')) {
|
|
|
|
// skip, but keep track of lines
|
|
|
|
if (qmake_endOfLine(buffer[offset]))
|
|
|
|
++*lines;
|
|
|
|
extralines = 0;
|
|
|
|
}
|
|
|
|
*lines += extralines; // from the match
|
|
|
|
// buffer[offset] is ')'
|
|
|
|
offset += 1 + matchlen; // 1 for ')', then delim
|
|
|
|
// buffer[offset] is '"'
|
|
|
|
|
|
|
|
#undef SKIP_BSNL
|
|
|
|
} else { // Traditional string or char literal:
|
|
|
|
const char term = buffer[offset];
|
|
|
|
while (++offset < buffer_len && buffer[offset] != term) {
|
|
|
|
if (buffer[offset] == '\\')
|
|
|
|
++offset;
|
|
|
|
else if (qmake_endOfLine(buffer[offset]))
|
|
|
|
++*lines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
bool QMakeSourceFileInfo::findDeps(SourceFile *file)
|
|
|
|
{
|
|
|
|
if(file->dep_checked || file->type == TYPE_UNKNOWN)
|
|
|
|
return true;
|
|
|
|
files_changed = true;
|
|
|
|
file->dep_checked = true;
|
|
|
|
|
|
|
|
const QMakeLocalFileName sourceFile = fixPathForFile(file->file, true);
|
|
|
|
|
2018-08-02 22:22:24 +00:00
|
|
|
char *buffer = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
int buffer_len = 0;
|
|
|
|
{
|
2022-01-24 11:52:38 +00:00
|
|
|
QFile f(sourceFile.local());
|
|
|
|
if (!f.open(QIODevice::ReadOnly))
|
2011-04-27 10:05:43 +00:00
|
|
|
return false;
|
2022-01-24 11:52:38 +00:00
|
|
|
const qint64 fs = f.size();
|
|
|
|
buffer = getBuffer(fs);
|
2011-04-27 10:05:43 +00:00
|
|
|
for(int have_read = 0;
|
2022-01-24 11:52:38 +00:00
|
|
|
(have_read = f.read(buffer + buffer_len, fs - buffer_len));
|
2011-04-27 10:05:43 +00:00
|
|
|
buffer_len += have_read) ;
|
|
|
|
}
|
|
|
|
if(!buffer)
|
|
|
|
return false;
|
|
|
|
if(!file->deps)
|
|
|
|
file->deps = new SourceDependChildren;
|
|
|
|
|
|
|
|
int line_count = 1;
|
2015-11-24 13:45:52 +00:00
|
|
|
enum {
|
|
|
|
/*
|
|
|
|
States of C preprocessing (for TYPE_C only), after backslash-newline
|
|
|
|
elimination and skipping comments and spaces (i.e. in ANSI X3.159-1989
|
|
|
|
section 2.1.1.2's phase 4). We're about to study buffer[x] to decide
|
|
|
|
on which transition to do.
|
|
|
|
*/
|
|
|
|
AtStart, // start of logical line; a # may start a preprocessor directive
|
|
|
|
HadHash, // saw a # at start, looking for preprocessor keyword
|
|
|
|
WantName, // saw #include or #import, waiting for name
|
|
|
|
InCode // after directive, parsing non-#include directive or in actual code
|
|
|
|
} cpp_state = AtStart;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-04-13 11:35:45 +00:00
|
|
|
int x = 0;
|
|
|
|
if (buffer_len >= 3) {
|
|
|
|
const unsigned char *p = (unsigned char *)buffer;
|
|
|
|
// skip UTF-8 BOM, if present
|
|
|
|
if (p[0] == 0xEF && p[1] == 0xBB && p[2] == 0xBF)
|
|
|
|
x += 3;
|
|
|
|
}
|
|
|
|
for (; x < buffer_len; ++x) {
|
2011-04-27 10:05:43 +00:00
|
|
|
bool try_local = true;
|
2018-08-02 22:22:24 +00:00
|
|
|
char *inc = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
if(file->type == QMakeSourceFileInfo::TYPE_UI) {
|
|
|
|
// skip whitespaces
|
2015-11-12 09:39:13 +00:00
|
|
|
while (x < buffer_len && (buffer[x] == ' ' || buffer[x] == '\t'))
|
2011-04-27 10:05:43 +00:00
|
|
|
++x;
|
2015-11-12 09:39:13 +00:00
|
|
|
if (buffer[x] == '<') {
|
2011-04-27 10:05:43 +00:00
|
|
|
++x;
|
2015-11-12 09:39:13 +00:00
|
|
|
if (buffer_len >= x + 12 && !strncmp(buffer + x, "includehint", 11) &&
|
|
|
|
(buffer[x + 11] == ' ' || buffer[x + 11] == '>')) {
|
2016-04-15 13:27:45 +00:00
|
|
|
for (x += 11; x < buffer_len && buffer[x] != '>'; ++x) {} // skip
|
2011-04-27 10:05:43 +00:00
|
|
|
int inc_len = 0;
|
2016-04-15 13:27:45 +00:00
|
|
|
for (++x; x + inc_len < buffer_len && buffer[x + inc_len] != '<'; ++inc_len) {} // skip
|
|
|
|
if (x + inc_len < buffer_len) {
|
|
|
|
buffer[x + inc_len] = '\0';
|
|
|
|
inc = buffer + x;
|
|
|
|
}
|
2015-11-12 09:39:13 +00:00
|
|
|
} else if (buffer_len >= x + 13 && !strncmp(buffer + x, "customwidget", 12) &&
|
|
|
|
(buffer[x + 12] == ' ' || buffer[x + 12] == '>')) {
|
2016-04-15 13:27:45 +00:00
|
|
|
for (x += 13; x < buffer_len && buffer[x] != '>'; ++x) {} // skip up to >
|
2011-04-27 10:05:43 +00:00
|
|
|
while(x < buffer_len) {
|
2016-04-15 13:27:45 +00:00
|
|
|
while (++x < buffer_len && buffer[x] != '<') {} // skip up to <
|
2011-04-27 10:05:43 +00:00
|
|
|
x++;
|
|
|
|
if(buffer_len >= x + 7 && !strncmp(buffer+x, "header", 6) &&
|
2015-11-12 09:39:13 +00:00
|
|
|
(buffer[x + 6] == ' ' || buffer[x + 6] == '>')) {
|
2016-04-15 13:27:45 +00:00
|
|
|
for (x += 7; x < buffer_len && buffer[x] != '>'; ++x) {} // skip up to >
|
2011-04-27 10:05:43 +00:00
|
|
|
int inc_len = 0;
|
2016-04-15 13:27:45 +00:00
|
|
|
for (++x; x + inc_len < buffer_len && buffer[x + inc_len] != '<';
|
|
|
|
++inc_len) {} // skip
|
|
|
|
if (x + inc_len < buffer_len) {
|
|
|
|
buffer[x + inc_len] = '\0';
|
|
|
|
inc = buffer + x;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
} else if(buffer_len >= x + 14 && !strncmp(buffer+x, "/customwidget", 13) &&
|
2015-11-12 09:39:13 +00:00
|
|
|
(buffer[x + 13] == ' ' || buffer[x + 13] == '>')) {
|
2011-04-27 10:05:43 +00:00
|
|
|
x += 14;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(buffer_len >= x + 8 && !strncmp(buffer + x, "include", 7) &&
|
2015-11-12 09:39:13 +00:00
|
|
|
(buffer[x + 7] == ' ' || buffer[x + 7] == '>')) {
|
2016-04-15 13:27:45 +00:00
|
|
|
for (x += 8; x < buffer_len && buffer[x] != '>'; ++x) {
|
2015-11-12 09:39:13 +00:00
|
|
|
if (buffer_len >= x + 9 && buffer[x] == 'i' &&
|
|
|
|
!strncmp(buffer + x, "impldecl", 8)) {
|
2016-04-15 13:27:45 +00:00
|
|
|
for (x += 8; x < buffer_len && buffer[x] != '='; ++x) {} // skip
|
|
|
|
while (++x < buffer_len && (buffer[x] == '\t' || buffer[x] == ' ')) {} // skip
|
2011-04-27 10:05:43 +00:00
|
|
|
char quote = 0;
|
2016-04-15 13:27:45 +00:00
|
|
|
if (x < buffer_len && (buffer[x] == '\'' || buffer[x] == '"')) {
|
2015-11-12 09:39:13 +00:00
|
|
|
quote = buffer[x];
|
2011-04-27 10:05:43 +00:00
|
|
|
++x;
|
|
|
|
}
|
|
|
|
int val_len;
|
2016-04-15 13:27:45 +00:00
|
|
|
for (val_len = 0; x + val_len < buffer_len; ++val_len) {
|
2011-04-27 10:05:43 +00:00
|
|
|
if(quote) {
|
2015-11-12 09:39:13 +00:00
|
|
|
if (buffer[x + val_len] == quote)
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
2015-11-12 09:39:13 +00:00
|
|
|
} else if (buffer[x + val_len] == '>' ||
|
|
|
|
buffer[x + val_len] == ' ') {
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 09:39:13 +00:00
|
|
|
//? char saved = buffer[x + val_len];
|
2016-04-15 13:27:45 +00:00
|
|
|
if (x + val_len < buffer_len) {
|
|
|
|
buffer[x + val_len] = '\0';
|
|
|
|
if (!strcmp(buffer + x, "in implementation")) {
|
|
|
|
//### do this
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int inc_len = 0;
|
2016-04-15 13:27:45 +00:00
|
|
|
for (++x; x + inc_len < buffer_len && buffer[x + inc_len] != '<';
|
|
|
|
++inc_len) {} // skip
|
|
|
|
|
|
|
|
if (x + inc_len < buffer_len) {
|
|
|
|
buffer[x + inc_len] = '\0';
|
|
|
|
inc = buffer + x;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//read past new line now..
|
2015-11-12 09:39:13 +00:00
|
|
|
for (; x < buffer_len && !qmake_endOfLine(buffer[x]); ++x) {} // skip
|
2011-04-27 10:05:43 +00:00
|
|
|
++line_count;
|
|
|
|
} else if(file->type == QMakeSourceFileInfo::TYPE_QRC) {
|
|
|
|
} else if(file->type == QMakeSourceFileInfo::TYPE_C) {
|
2015-11-24 13:45:52 +00:00
|
|
|
// We've studied all buffer[i] for i < x
|
|
|
|
for (; x < buffer_len; ++x) {
|
|
|
|
// How to handle backslash-newline (BSNL) pairs:
|
|
|
|
#define SKIP_BSNL(pos) skipEscapedLineEnds(buffer, buffer_len, (pos), &line_count)
|
|
|
|
|
2015-11-12 09:39:13 +00:00
|
|
|
// Seek code or directive, skipping comments and space:
|
2016-04-15 13:27:45 +00:00
|
|
|
for (; (x = SKIP_BSNL(x)) < buffer_len; ++x) {
|
2015-11-12 09:39:13 +00:00
|
|
|
if (buffer[x] == ' ' || buffer[x] == '\t') {
|
2011-04-27 10:05:43 +00:00
|
|
|
// keep going
|
2015-11-24 13:45:52 +00:00
|
|
|
} else if (buffer[x] == '/') {
|
|
|
|
int extralines = 0;
|
|
|
|
int y = skipEscapedLineEnds(buffer, buffer_len, x + 1, &extralines);
|
2016-04-15 13:27:45 +00:00
|
|
|
if (y >= buffer_len) {
|
|
|
|
x = y;
|
|
|
|
break;
|
|
|
|
} else if (buffer[y] == '/') { // C++-style comment
|
2015-11-24 13:45:52 +00:00
|
|
|
line_count += extralines;
|
|
|
|
x = SKIP_BSNL(y + 1);
|
|
|
|
while (x < buffer_len && !qmake_endOfLine(buffer[x]))
|
|
|
|
x = SKIP_BSNL(x + 1); // skip
|
|
|
|
|
|
|
|
cpp_state = AtStart;
|
|
|
|
++line_count;
|
|
|
|
} else if (buffer[y] == '*') { // C-style comment
|
|
|
|
line_count += extralines;
|
|
|
|
x = y;
|
2016-04-15 13:27:45 +00:00
|
|
|
while ((x = SKIP_BSNL(++x)) < buffer_len) {
|
2015-11-12 10:01:31 +00:00
|
|
|
if (buffer[x] == '*') {
|
2015-11-24 13:45:52 +00:00
|
|
|
extralines = 0;
|
|
|
|
y = skipEscapedLineEnds(buffer, buffer_len,
|
|
|
|
x + 1, &extralines);
|
|
|
|
if (y < buffer_len && buffer[y] == '/') {
|
|
|
|
line_count += extralines;
|
|
|
|
x = y; // for loop shall step past this
|
2015-11-12 10:01:31 +00:00
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-12 10:01:31 +00:00
|
|
|
} else if (qmake_endOfLine(buffer[x])) {
|
|
|
|
++line_count;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
} else {
|
|
|
|
// buffer[x] is the division operator
|
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-12 09:39:13 +00:00
|
|
|
} else if (qmake_endOfLine(buffer[x])) {
|
2011-04-27 10:05:43 +00:00
|
|
|
++line_count;
|
2015-11-24 13:45:52 +00:00
|
|
|
cpp_state = AtStart;
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2015-11-24 13:45:52 +00:00
|
|
|
/* Drop out of phases 1, 2, 3, into phase 4 */
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
// Phase 4 study of buffer[x]:
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if(x >= buffer_len)
|
|
|
|
break;
|
|
|
|
|
2015-11-24 13:45:52 +00:00
|
|
|
switch (cpp_state) {
|
|
|
|
case HadHash:
|
|
|
|
{
|
|
|
|
// Read keyword; buffer[x] starts first preprocessing token after #
|
|
|
|
const char *const keyword = buffer + x;
|
|
|
|
int clean = x;
|
|
|
|
while (x < buffer_len && buffer[x] >= 'a' && buffer[x] <= 'z') {
|
|
|
|
// skip over keyword, consolidating it if it contains BSNLs
|
|
|
|
// (see WantName's similar code consolidating inc, below)
|
|
|
|
if (clean < x)
|
|
|
|
buffer[clean++] = buffer[x];
|
|
|
|
else
|
|
|
|
clean++;
|
|
|
|
|
|
|
|
x = SKIP_BSNL(x + 1);
|
2015-11-12 10:12:52 +00:00
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
const int keyword_len = buffer + clean - keyword;
|
|
|
|
x--; // Still need to study buffer[x] next time round for loop.
|
|
|
|
|
|
|
|
cpp_state =
|
|
|
|
((keyword_len == 7 && !strncmp(keyword, "include", 7)) // C & Obj-C
|
|
|
|
|| (keyword_len == 6 && !strncmp(keyword, "import", 6))) // Obj-C
|
|
|
|
? WantName : InCode;
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
2015-11-12 10:12:52 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-24 13:45:52 +00:00
|
|
|
case WantName:
|
|
|
|
{
|
|
|
|
char term = buffer[x];
|
|
|
|
if (term == '<') {
|
|
|
|
try_local = false;
|
|
|
|
term = '>';
|
|
|
|
} else if (term != '"') {
|
2015-11-25 10:57:36 +00:00
|
|
|
/*
|
2015-11-24 13:45:52 +00:00
|
|
|
Possibly malformed, but this may be something like:
|
|
|
|
#include IDENTIFIER
|
|
|
|
which does work, if #define IDENTIFIER "filename" is
|
|
|
|
in effect. This is beyond this noddy preprocessor's
|
|
|
|
powers of tracking. So give up and resume searching
|
|
|
|
for a directive. We haven't made sense of buffer[x],
|
|
|
|
so back up to ensure we do study it (now as code) next
|
|
|
|
time round the loop.
|
|
|
|
*/
|
|
|
|
x--;
|
|
|
|
cpp_state = InCode;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = SKIP_BSNL(x + 1);
|
|
|
|
inc = buffer + x;
|
|
|
|
int clean = x; // offset if we need to clear \-newlines
|
|
|
|
for (; x < buffer_len && buffer[x] != term; x = SKIP_BSNL(x + 1)) {
|
|
|
|
if (qmake_endOfLine(buffer[x])) { // malformed
|
|
|
|
cpp_state = AtStart;
|
|
|
|
++line_count;
|
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
If we do skip any BSNLs, we need to consolidate the
|
|
|
|
surviving text by copying to lower indices. For that
|
|
|
|
to be possible, we also have to keep 'clean' advanced
|
|
|
|
in step with x even when we've yet to see any BSNLs.
|
|
|
|
*/
|
|
|
|
if (clean < x)
|
|
|
|
buffer[clean++] = buffer[x];
|
|
|
|
else
|
|
|
|
clean++;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
if (cpp_state == WantName)
|
|
|
|
buffer[clean] = '\0';
|
|
|
|
else // i.e. malformed
|
2018-08-02 22:22:24 +00:00
|
|
|
inc = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-24 13:45:52 +00:00
|
|
|
cpp_state = InCode; // hereafter
|
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
|
|
|
|
case AtStart:
|
|
|
|
// Preprocessor directive?
|
|
|
|
if (buffer[x] == '#') {
|
|
|
|
cpp_state = HadHash;
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
cpp_state = InCode;
|
2019-06-05 08:47:28 +00:00
|
|
|
Q_FALLTHROUGH(); // to handle buffer[x] as such.
|
2015-11-24 13:45:52 +00:00
|
|
|
case InCode:
|
|
|
|
// matching quotes (string literals and character literals)
|
|
|
|
if (buffer[x] == '\'' || buffer[x] == '"') {
|
2015-12-08 13:50:45 +00:00
|
|
|
x = scanPastString(buffer, buffer_len, x, &line_count);
|
2015-11-24 13:45:52 +00:00
|
|
|
// for loop's ++x shall step over the closing quote.
|
|
|
|
}
|
|
|
|
// else: buffer[x] is just some code; move on.
|
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
|
|
|
|
if (inc) // We were in WantName and found a name.
|
|
|
|
break;
|
|
|
|
#undef SKIP_BSNL
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-24 13:45:52 +00:00
|
|
|
if(x >= buffer_len)
|
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(inc) {
|
|
|
|
if(!includes)
|
|
|
|
includes = new SourceFiles;
|
2019-05-04 16:51:53 +00:00
|
|
|
/* 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);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!dep) {
|
|
|
|
bool exists = false;
|
|
|
|
QMakeLocalFileName lfn(inc);
|
|
|
|
if(QDir::isRelativePath(lfn.real())) {
|
|
|
|
if(try_local) {
|
|
|
|
QDir sourceDir = findFileInfo(sourceFile).dir();
|
|
|
|
QMakeLocalFileName f(sourceDir.absoluteFilePath(lfn.local()));
|
|
|
|
if(findFileInfo(f).exists()) {
|
|
|
|
lfn = fixPathForFile(f);
|
|
|
|
exists = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!exists) { //path lookup
|
2019-08-06 13:01:49 +00:00
|
|
|
for (const QMakeLocalFileName &depdir : qAsConst(depdirs)) {
|
|
|
|
QMakeLocalFileName f(depdir.real() + Option::dir_sep + lfn.real());
|
2011-04-27 10:05:43 +00:00
|
|
|
QFileInfo fi(findFileInfo(f));
|
|
|
|
if(fi.exists() && !fi.isDir()) {
|
|
|
|
lfn = fixPathForFile(f);
|
|
|
|
exists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!exists) { //heuristic lookup
|
|
|
|
lfn = findFileForDep(QMakeLocalFileName(inc), file->file);
|
|
|
|
if((exists = !lfn.isNull()))
|
|
|
|
lfn = fixPathForFile(lfn);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
exists = QFile::exists(lfn.real());
|
|
|
|
}
|
2013-12-11 04:10:10 +00:00
|
|
|
if (!lfn.isNull() && !isSystemInclude(lfn.real())) {
|
2011-04-27 10:05:43 +00:00
|
|
|
dep = files->lookupFile(lfn);
|
|
|
|
if(!dep) {
|
|
|
|
dep = new SourceFile;
|
|
|
|
dep->file = lfn;
|
|
|
|
dep->type = QMakeSourceFileInfo::TYPE_C;
|
|
|
|
files->addFile(dep);
|
2019-05-04 16:51:53 +00:00
|
|
|
/* 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);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
dep->exists = exists;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(dep && dep->file != file->file) {
|
|
|
|
dep->included_count++;
|
|
|
|
if(dep->exists) {
|
|
|
|
debug_msg(5, "%s:%d Found dependency to %s", file->file.real().toLatin1().constData(),
|
|
|
|
line_count, dep->file.local().toLatin1().constData());
|
|
|
|
file->deps->addChild(dep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(dependencyMode() == Recursive) { //done last because buffer is shared
|
|
|
|
for(int i = 0; i < file->deps->used_nodes; i++) {
|
|
|
|
if(!file->deps->children[i]->deps)
|
|
|
|
findDeps(file->deps->children[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-12 09:39:13 +00:00
|
|
|
static bool isCWordChar(char c) {
|
|
|
|
return c == '_'
|
|
|
|
|| (c >= 'a' && c <= 'z')
|
|
|
|
|| (c >= 'A' && c <= 'Z')
|
|
|
|
|| (c >= '0' && c <= '9');
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
bool QMakeSourceFileInfo::findMocs(SourceFile *file)
|
|
|
|
{
|
|
|
|
if(file->moc_checked)
|
|
|
|
return true;
|
|
|
|
files_changed = true;
|
|
|
|
file->moc_checked = true;
|
|
|
|
|
2015-12-09 13:37:11 +00:00
|
|
|
int buffer_len = 0;
|
2018-08-02 22:22:24 +00:00
|
|
|
char *buffer = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2022-01-24 11:52:38 +00:00
|
|
|
QFile f(fixPathForFile(file->file, true).local());
|
|
|
|
if (!f.open(QIODevice::ReadOnly))
|
2011-04-27 10:05:43 +00:00
|
|
|
return false; //shouldn't happen
|
2022-01-24 11:52:38 +00:00
|
|
|
const qint64 fs = f.size();
|
|
|
|
buffer = getBuffer(fs);
|
|
|
|
while (int have_read = f.read(buffer + buffer_len, fs - buffer_len))
|
2015-12-09 13:37:11 +00:00
|
|
|
buffer_len += have_read;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug_msg(2, "findMocs: %s", file->file.local().toLatin1().constData());
|
|
|
|
int line_count = 1;
|
2021-11-22 07:42:49 +00:00
|
|
|
enum Keywords {
|
|
|
|
Q_OBJECT_Keyword,
|
|
|
|
Q_GADGET_Keyword,
|
Long live Q_GADGET_EXPORT!
Like Q_NAMESPACE_EXPORT for Q_NAMESPACE, this variant of Q_GADGET
allows passing an export macro. This is useful to avoid exporting the
whole class just to get the staticMetaObject hidden therein exported.
Before anyone asks: No, we don't need Q_OBJECT_EXPORT, because QObject
subclasses, being polymorphic, always need to have a class-level
export macro (to export their vtable), but while that technique also
works for value classes (the Q_GADGET audience), it is not desirable
for them, because it makes inline functions exported in Windows debug
builds, which is not what we want, because it needlessly restricts
what you can to with the inline functions (e.g. remove).
[ChangeLog][QtCore] Added the Q_GADGET_EXPORT macro, which is like
Q_GADGET, but allows passing an export macro (like Q_NAMESPACE_EXPORT
for Q_NAMESPACE).
Fixes: QTBUG-55458
Change-Id: I546297de1e8aa45d83381991bcd3fbca61e1eef0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-22 09:30:04 +00:00
|
|
|
Q_GADGET_EXPORT_Keyword,
|
2021-11-22 07:42:49 +00:00
|
|
|
Q_NAMESPACE_Keyword,
|
|
|
|
Q_NAMESPACE_EXPORT_Keyword,
|
|
|
|
|
|
|
|
NumKeywords
|
|
|
|
};
|
2021-11-22 07:42:49 +00:00
|
|
|
static const char keywords[][19] = {
|
|
|
|
"Q_OBJECT",
|
|
|
|
"Q_GADGET",
|
Long live Q_GADGET_EXPORT!
Like Q_NAMESPACE_EXPORT for Q_NAMESPACE, this variant of Q_GADGET
allows passing an export macro. This is useful to avoid exporting the
whole class just to get the staticMetaObject hidden therein exported.
Before anyone asks: No, we don't need Q_OBJECT_EXPORT, because QObject
subclasses, being polymorphic, always need to have a class-level
export macro (to export their vtable), but while that technique also
works for value classes (the Q_GADGET audience), it is not desirable
for them, because it makes inline functions exported in Windows debug
builds, which is not what we want, because it needlessly restricts
what you can to with the inline functions (e.g. remove).
[ChangeLog][QtCore] Added the Q_GADGET_EXPORT macro, which is like
Q_GADGET, but allows passing an export macro (like Q_NAMESPACE_EXPORT
for Q_NAMESPACE).
Fixes: QTBUG-55458
Change-Id: I546297de1e8aa45d83381991bcd3fbca61e1eef0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-22 09:30:04 +00:00
|
|
|
"Q_GADGET_EXPORT",
|
2021-11-22 07:42:49 +00:00
|
|
|
"Q_NAMESPACE",
|
|
|
|
"Q_NAMESPACE_EXPORT",
|
|
|
|
};
|
|
|
|
static_assert(std::size(keywords) == NumKeywords);
|
2021-11-22 07:42:49 +00:00
|
|
|
bool ignore[NumKeywords] = {};
|
2011-04-27 10:05:43 +00:00
|
|
|
/* qmake ignore Q_GADGET */
|
Long live Q_GADGET_EXPORT!
Like Q_NAMESPACE_EXPORT for Q_NAMESPACE, this variant of Q_GADGET
allows passing an export macro. This is useful to avoid exporting the
whole class just to get the staticMetaObject hidden therein exported.
Before anyone asks: No, we don't need Q_OBJECT_EXPORT, because QObject
subclasses, being polymorphic, always need to have a class-level
export macro (to export their vtable), but while that technique also
works for value classes (the Q_GADGET audience), it is not desirable
for them, because it makes inline functions exported in Windows debug
builds, which is not what we want, because it needlessly restricts
what you can to with the inline functions (e.g. remove).
[ChangeLog][QtCore] Added the Q_GADGET_EXPORT macro, which is like
Q_GADGET, but allows passing an export macro (like Q_NAMESPACE_EXPORT
for Q_NAMESPACE).
Fixes: QTBUG-55458
Change-Id: I546297de1e8aa45d83381991bcd3fbca61e1eef0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-11-22 09:30:04 +00:00
|
|
|
/* qmake ignore Q_GADGET_EXPORT */
|
2011-04-27 10:05:43 +00:00
|
|
|
/* qmake ignore Q_OBJECT */
|
2016-08-23 19:32:11 +00:00
|
|
|
/* qmake ignore Q_NAMESPACE */
|
2019-04-30 07:39:21 +00:00
|
|
|
/* qmake ignore Q_NAMESPACE_EXPORT */
|
2011-04-27 10:05:43 +00:00
|
|
|
for(int x = 0; x < buffer_len; x++) {
|
2015-12-09 09:27:58 +00:00
|
|
|
#define SKIP_BSNL(pos) skipEscapedLineEnds(buffer, buffer_len, (pos), &line_count)
|
|
|
|
x = SKIP_BSNL(x);
|
2015-11-12 09:39:13 +00:00
|
|
|
if (buffer[x] == '/') {
|
2015-12-09 09:27:58 +00:00
|
|
|
int extralines = 0;
|
|
|
|
int y = skipEscapedLineEnds(buffer, buffer_len, x + 1, &extralines);
|
|
|
|
if (buffer_len > y) {
|
|
|
|
// If comment, advance to the character that ends it:
|
|
|
|
if (buffer[y] == '/') { // C++-style comment
|
|
|
|
line_count += extralines;
|
|
|
|
x = y;
|
|
|
|
do {
|
|
|
|
x = SKIP_BSNL(x + 1);
|
|
|
|
} while (x < buffer_len && !qmake_endOfLine(buffer[x]));
|
|
|
|
|
|
|
|
} else if (buffer[y] == '*') { // C-style comment
|
|
|
|
line_count += extralines;
|
|
|
|
x = SKIP_BSNL(y + 1);
|
|
|
|
for (; x < buffer_len; x = SKIP_BSNL(x + 1)) {
|
2015-11-12 09:39:13 +00:00
|
|
|
if (buffer[x] == 't' || buffer[x] == 'q') { // ignore
|
2021-11-22 07:42:49 +00:00
|
|
|
const char tag[] = "make ignore ";
|
|
|
|
const auto starts_with = [](const char *haystack, const char *needle) {
|
|
|
|
return strncmp(haystack, needle, strlen(needle)) == 0;
|
|
|
|
};
|
|
|
|
const auto is_ignore = [&](const char *keyword) {
|
|
|
|
return buffer_len >= int(x + strlen(tag) + strlen(keyword)) &&
|
|
|
|
starts_with(buffer + x + 1, tag) &&
|
|
|
|
starts_with(buffer + x + 1 + strlen(tag), keyword);
|
|
|
|
};
|
|
|
|
int interest = 0;
|
|
|
|
for (const char *keyword : keywords) {
|
|
|
|
if (is_ignore(keyword)){
|
|
|
|
debug_msg(2, "Mocgen: %s:%d Found \"q%s%s\"",
|
|
|
|
file->file.real().toLatin1().constData(), line_count,
|
|
|
|
tag, keyword);
|
2021-11-30 10:30:36 +00:00
|
|
|
x += static_cast<int>(strlen(tag));
|
|
|
|
x += static_cast<int>(strlen(keyword));
|
2021-11-22 07:42:49 +00:00
|
|
|
ignore[interest] = true;
|
|
|
|
}
|
|
|
|
++interest;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-12 09:39:13 +00:00
|
|
|
} else if (buffer[x] == '*') {
|
2015-12-09 09:27:58 +00:00
|
|
|
extralines = 0;
|
|
|
|
y = skipEscapedLineEnds(buffer, buffer_len, x + 1, &extralines);
|
|
|
|
if (buffer_len > y && buffer[y] == '/') {
|
|
|
|
line_count += extralines;
|
|
|
|
x = y;
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-11-12 09:39:13 +00:00
|
|
|
} else if (Option::debug_level && qmake_endOfLine(buffer[x])) {
|
2011-04-27 10:05:43 +00:00
|
|
|
++line_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-09 09:27:58 +00:00
|
|
|
// else: don't update x, buffer[x] is just the division operator.
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-11-12 09:39:13 +00:00
|
|
|
} else if (buffer[x] == '\'' || buffer[x] == '"') {
|
2015-12-08 13:50:45 +00:00
|
|
|
x = scanPastString(buffer, buffer_len, x, &line_count);
|
|
|
|
// Leaves us on closing quote; for loop's x++ steps us past it.
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-12-08 13:50:45 +00:00
|
|
|
|
2015-12-09 09:27:58 +00:00
|
|
|
if (x < buffer_len && Option::debug_level && qmake_endOfLine(buffer[x]))
|
2011-04-27 10:05:43 +00:00
|
|
|
++line_count;
|
2015-12-09 09:27:58 +00:00
|
|
|
if (buffer_len > x + 8 && !isCWordChar(buffer[x])) {
|
|
|
|
int morelines = 0;
|
|
|
|
int y = skipEscapedLineEnds(buffer, buffer_len, x + 1, &morelines);
|
|
|
|
if (buffer[y] == 'Q') {
|
2021-11-22 07:42:49 +00:00
|
|
|
for (int interest = 0; interest < NumKeywords; ++interest) {
|
2015-12-15 15:56:09 +00:00
|
|
|
if (ignore[interest])
|
|
|
|
continue;
|
2015-12-09 09:27:58 +00:00
|
|
|
|
|
|
|
int matchlen = 0, extralines = 0;
|
2021-11-22 07:42:49 +00:00
|
|
|
size_t needle_len = strlen(keywords[interest]);
|
2016-10-25 09:43:56 +00:00
|
|
|
Q_ASSERT(needle_len <= INT_MAX);
|
2015-12-09 09:27:58 +00:00
|
|
|
if (matchWhileUnsplitting(buffer, buffer_len, y,
|
2021-11-22 07:42:49 +00:00
|
|
|
keywords[interest],
|
2016-10-25 09:43:56 +00:00
|
|
|
static_cast<int>(needle_len),
|
2015-12-09 09:27:58 +00:00
|
|
|
&matchlen, &extralines)
|
|
|
|
&& y + matchlen < buffer_len
|
|
|
|
&& !isCWordChar(buffer[y + matchlen])) {
|
|
|
|
if (Option::debug_level) {
|
|
|
|
buffer[y + matchlen] = '\0';
|
|
|
|
debug_msg(2, "Mocgen: %s:%d Found MOC symbol %s",
|
|
|
|
file->file.real().toLatin1().constData(),
|
|
|
|
line_count + morelines, buffer + y);
|
|
|
|
}
|
|
|
|
file->mocable = true;
|
|
|
|
return true;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-09 09:27:58 +00:00
|
|
|
#undef SKIP_BSNL
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|