forked from qt-creator/qt-creator
AutotoolsPM: Make QTextStream a local variable
Create QFile on stack. Change-Id: I803da2be8f2dea7ace13e3bb2791082fe40ee892 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -18,14 +18,10 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace AutotoolsProjectManager::Internal {
|
namespace AutotoolsProjectManager::Internal {
|
||||||
|
|
||||||
MakefileParser::MakefileParser(const QString &makefile) : m_makefile(makefile)
|
MakefileParser::MakefileParser(const QString &makefile)
|
||||||
|
: m_makefile(makefile)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
MakefileParser::~MakefileParser()
|
|
||||||
{
|
|
||||||
delete m_textStream.device();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MakefileParser::parse()
|
bool MakefileParser::parse()
|
||||||
{
|
{
|
||||||
QFutureInterface<void> fi;
|
QFutureInterface<void> fi;
|
||||||
@@ -41,10 +37,9 @@ bool MakefileParser::parse(const QFuture<void> &future)
|
|||||||
m_outputData.m_sources.clear();
|
m_outputData.m_sources.clear();
|
||||||
m_outputData.m_makefiles.clear();
|
m_outputData.m_makefiles.clear();
|
||||||
|
|
||||||
auto file = new QFile(m_makefile);
|
QFile file(m_makefile);
|
||||||
if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
qWarning("%s: %s", qPrintable(m_makefile), qPrintable(file->errorString()));
|
qWarning("%s: %s", qPrintable(m_makefile), qPrintable(file.errorString()));
|
||||||
delete file;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,16 +48,16 @@ bool MakefileParser::parse(const QFuture<void> &future)
|
|||||||
|
|
||||||
emit status(Tr::tr("Parsing %1 in directory %2").arg(info.fileName()).arg(info.absolutePath()));
|
emit status(Tr::tr("Parsing %1 in directory %2").arg(info.fileName()).arg(info.absolutePath()));
|
||||||
|
|
||||||
m_textStream.setDevice(file);
|
QTextStream textStream(&file);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
m_line = m_textStream.readLine();
|
m_line = textStream.readLine();
|
||||||
switch (topTarget()) {
|
switch (topTarget()) {
|
||||||
case AmDefaultSourceExt: parseDefaultSourceExtensions(); break;
|
case AmDefaultSourceExt: parseDefaultSourceExtensions(&textStream); break;
|
||||||
case BinPrograms: parseBinPrograms(); break;
|
case BinPrograms: parseBinPrograms(&textStream); break;
|
||||||
case BuiltSources: break; // TODO: Add to m_sources?
|
case BuiltSources: break; // TODO: Add to m_sources?
|
||||||
case Sources: parseSources(); break;
|
case Sources: parseSources(&textStream); break;
|
||||||
case SubDirs: parseSubDirs(); break;
|
case SubDirs: parseSubDirs(&textStream); break;
|
||||||
case Undefined:
|
case Undefined:
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@@ -101,10 +96,10 @@ MakefileParser::TopTarget MakefileParser::topTarget() const
|
|||||||
return Undefined;
|
return Undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakefileParser::parseBinPrograms()
|
void MakefileParser::parseBinPrograms(QTextStream *textStream)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_line.contains(QLatin1String("bin_PROGRAMS")), return);
|
QTC_ASSERT(m_line.contains(QLatin1String("bin_PROGRAMS")), return);
|
||||||
const QStringList binPrograms = targetValues();
|
const QStringList binPrograms = targetValues(textStream);
|
||||||
|
|
||||||
// TODO: are multiple values possible?
|
// TODO: are multiple values possible?
|
||||||
if (binPrograms.size() == 1) {
|
if (binPrograms.size() == 1) {
|
||||||
@@ -113,12 +108,12 @@ void MakefileParser::parseBinPrograms()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakefileParser::parseSources()
|
void MakefileParser::parseSources(QTextStream *textStream)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_line.contains("_SOURCES") || m_line.contains("_HEADERS"), return);
|
QTC_ASSERT(m_line.contains("_SOURCES") || m_line.contains("_HEADERS"), return);
|
||||||
|
|
||||||
bool hasVariables = false;
|
bool hasVariables = false;
|
||||||
m_outputData.m_sources.append(targetValues(&hasVariables));
|
m_outputData.m_sources.append(targetValues(textStream, &hasVariables));
|
||||||
|
|
||||||
// Skip parsing of Makefile.am for getting the sub directories,
|
// Skip parsing of Makefile.am for getting the sub directories,
|
||||||
// as variables have been used. As fallback all sources will be added.
|
// as variables have been used. As fallback all sources will be added.
|
||||||
@@ -140,10 +135,10 @@ void MakefileParser::parseSources()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakefileParser::parseDefaultSourceExtensions()
|
void MakefileParser::parseDefaultSourceExtensions(QTextStream *textStream)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_line.contains(QLatin1String("AM_DEFAULT_SOURCE_EXT")), return);
|
QTC_ASSERT(m_line.contains(QLatin1String("AM_DEFAULT_SOURCE_EXT")), return);
|
||||||
const QStringList extensions = targetValues();
|
const QStringList extensions = targetValues(textStream);
|
||||||
if (extensions.isEmpty()) {
|
if (extensions.isEmpty()) {
|
||||||
m_success = false;
|
m_success = false;
|
||||||
return;
|
return;
|
||||||
@@ -157,7 +152,7 @@ void MakefileParser::parseDefaultSourceExtensions()
|
|||||||
m_outputData.m_sources.removeDuplicates();
|
m_outputData.m_sources.removeDuplicates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakefileParser::parseSubDirs()
|
void MakefileParser::parseSubDirs(QTextStream *textStream)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_line.contains(QLatin1String("SUBDIRS")), return);
|
QTC_ASSERT(m_line.contains(QLatin1String("SUBDIRS")), return);
|
||||||
if (m_future.isCanceled()) {
|
if (m_future.isCanceled()) {
|
||||||
@@ -170,7 +165,7 @@ void MakefileParser::parseSubDirs()
|
|||||||
const QString makefileName = info.fileName();
|
const QString makefileName = info.fileName();
|
||||||
|
|
||||||
bool hasVariables = false;
|
bool hasVariables = false;
|
||||||
QStringList subDirs = targetValues(&hasVariables);
|
QStringList subDirs = targetValues(textStream, &hasVariables);
|
||||||
if (hasVariables) {
|
if (hasVariables) {
|
||||||
// Skip parsing of Makefile.am for getting the sub directories,
|
// Skip parsing of Makefile.am for getting the sub directories,
|
||||||
// as variables have been used. As fallback all sources will be added.
|
// as variables have been used. As fallback all sources will be added.
|
||||||
@@ -294,7 +289,7 @@ QStringList MakefileParser::directorySources(const QString &directory,
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList MakefileParser::targetValues(bool *hasVariables)
|
QStringList MakefileParser::targetValues(QTextStream *textStream, bool *hasVariables)
|
||||||
{
|
{
|
||||||
QStringList values;
|
QStringList values;
|
||||||
if (hasVariables)
|
if (hasVariables)
|
||||||
@@ -340,7 +335,7 @@ QStringList MakefileParser::targetValues(bool *hasVariables)
|
|||||||
lineValues.push_back(last);
|
lineValues.push_back(last);
|
||||||
|
|
||||||
values.append(lineValues);
|
values.append(lineValues);
|
||||||
m_line = m_textStream.readLine();
|
m_line = textStream->readLine();
|
||||||
endReached = m_line.isNull();
|
endReached = m_line.isNull();
|
||||||
} else {
|
} else {
|
||||||
values.append(lineValues);
|
values.append(lineValues);
|
||||||
|
|||||||
@@ -60,8 +60,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
MakefileParser(const QString &makefile);
|
MakefileParser(const QString &makefile);
|
||||||
|
|
||||||
~MakefileParser();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the makefile. Must be invoked at least once, otherwise
|
* Parses the makefile. Must be invoked at least once, otherwise
|
||||||
* the getter functions of MakefileParser will return empty values.
|
* the getter functions of MakefileParser will return empty values.
|
||||||
@@ -97,13 +95,13 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Parses the bin_PROGRAM target and stores it in m_executable.
|
* Parses the bin_PROGRAM target and stores it in m_executable.
|
||||||
*/
|
*/
|
||||||
void parseBinPrograms();
|
void parseBinPrograms(QTextStream *textStream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses all values from a _SOURCE target and appends them to
|
* Parses all values from a _SOURCE target and appends them to
|
||||||
* the m_sources list.
|
* the m_sources list.
|
||||||
*/
|
*/
|
||||||
void parseSources();
|
void parseSources(QTextStream *textStream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses all sub directories for files having the extension
|
* Parses all sub directories for files having the extension
|
||||||
@@ -111,14 +109,14 @@ private:
|
|||||||
* append to the m_sources list. Corresponding header files
|
* append to the m_sources list. Corresponding header files
|
||||||
* will automatically be attached too.
|
* will automatically be attached too.
|
||||||
*/
|
*/
|
||||||
void parseDefaultSourceExtensions();
|
void parseDefaultSourceExtensions(QTextStream *textStream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses all sub directories specified by the SUBDIRS target and
|
* Parses all sub directories specified by the SUBDIRS target and
|
||||||
* adds the found sources to the m_sources list. The found makefiles
|
* adds the found sources to the m_sources list. The found makefiles
|
||||||
* get added to the m_makefiles list.
|
* get added to the m_makefiles list.
|
||||||
*/
|
*/
|
||||||
void parseSubDirs();
|
void parseSubDirs(QTextStream *textStream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function for parseDefaultExtensions(). Returns recursively all sources
|
* Helper function for parseDefaultExtensions(). Returns recursively all sources
|
||||||
@@ -145,7 +143,7 @@ private:
|
|||||||
* contained a variable like $(test). Note that all variables are not
|
* contained a variable like $(test). Note that all variables are not
|
||||||
* part of the return value, as they cannot get interpreted currently.
|
* part of the return value, as they cannot get interpreted currently.
|
||||||
*/
|
*/
|
||||||
QStringList targetValues(bool *hasVariables = nullptr);
|
QStringList targetValues(QTextStream *textStream, bool *hasVariables = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds recursively all sources of the current folder to m_sources and removes
|
* Adds recursively all sources of the current folder to m_sources and removes
|
||||||
@@ -217,7 +215,6 @@ private:
|
|||||||
QStringList m_cppflags; ///< The cpp flags, which will be part of both cflags and cxxflags
|
QStringList m_cppflags; ///< The cpp flags, which will be part of both cflags and cxxflags
|
||||||
|
|
||||||
QString m_line; ///< Current line of the makefile
|
QString m_line; ///< Current line of the makefile
|
||||||
QTextStream m_textStream; ///< Textstream that represents the makefile
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // AutotoolsProjectManager::Internal
|
} // AutotoolsProjectManager::Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user