Autotools: fixed parsing var assignment without space before =

Parser worked correctly with 'bin_PROGRAMS =', but failed on
'bin_PROGRAMS='. To reproduce problem on Ubuntu, perform 'apt-get source
gentoo' and open Makefile.am in downloaded folder as project: it will be
empty before this change.

Change-Id: I71d0866a2b9d8228ad5ac9237fa34be14b9e9b38
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Sergey Shambir
2013-02-03 20:47:45 +04:00
committed by hjk
parent c7ca78afd0
commit 68aeaa5fc4
2 changed files with 38 additions and 18 deletions

View File

@@ -137,26 +137,27 @@ bool MakefileParser::isCanceled() const
MakefileParser::TopTarget MakefileParser::topTarget() const
{
TopTarget topTarget = Undefined;
const QString line = m_line.simplified();
if (!line.isEmpty() && !line.startsWith(QLatin1Char('#'))) {
// TODO: Check how many fixed strings like AM_DEFAULT_SOURCE_EXT will
// be needed vs. variable strings like _SOURCES. Dependent on this a
// more clever way than this (expensive) if-cascading might be done.
if (line.startsWith(QLatin1String("AM_DEFAULT_SOURCE_EXT =")))
topTarget = AmDefaultSourceExt;
else if (line.startsWith(QLatin1String("bin_PROGRAMS =")))
topTarget = BinPrograms;
else if (line.startsWith(QLatin1String("BUILT_SOURCES =")))
topTarget = BuiltSources;
else if (line.contains(QLatin1String("SUBDIRS =")))
topTarget = SubDirs;
else if (line.contains(QLatin1String("_SOURCES =")))
topTarget = Sources;
}
return topTarget;
if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
return Undefined;
const QString id = parseIdentifierBeforeAssign(line);
if (id.isEmpty())
return Undefined;
if (id == QLatin1String("AM_DEFAULT_SOURCE_EXT"))
return AmDefaultSourceExt;
if (id == QLatin1String("bin_PROGRAMS"))
return BinPrograms;
if (id == QLatin1String("BUILT_SOURCES"))
return BuiltSources;
if (id == QLatin1String("SUBDIRS") || id == QLatin1String("DIST_SUBDIRS"))
return SubDirs;
if (id.endsWith(QLatin1String("_SOURCES")))
return Sources;
return Undefined;
}
void MakefileParser::parseBinPrograms()
@@ -410,6 +411,19 @@ void MakefileParser::appendHeader(QStringList &list, const QDir &dir, const QSt
}
}
QString MakefileParser::parseIdentifierBeforeAssign(const QString &line)
{
int end = 0;
for (; end < line.size(); ++end)
if (!line[end].isLetterOrNumber() && line[end] != QLatin1Char('_'))
break;
QString ret = line.left(end);
while (end < line.size() && line[end].isSpace())
++end;
return (line[end] == QLatin1Char('=')) ? ret : QString();
}
void MakefileParser::addAllSources()
{
QStringList extensions;

View File

@@ -205,6 +205,12 @@ private:
*/
static void appendHeader(QStringList &list, const QDir &dir, const QString &fileName);
/**
* If line starts with identifier and = goes next, return identifier.
* Identifier is valid target name and it matches regexp [a-zA-Z1-9_]+
*/
static QString parseIdentifierBeforeAssign(const QString &line);
private:
bool m_success; ///< Return value for MakefileParser::parse().