make .prl processing less convoluted

don't look up the files and normalize the paths multiple times, as this
is inefficient and hard to understand.
on the way, processPrlFile() got unnested, and libExists() got nuked.

note that a missing QMAKE_PRL_TARGET will be now complained about, which
really should never happen.

Change-Id: Ibcd77a7f963204c013548496ecd2d635e1a4baba
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Oswald Buddenhagen 2015-09-22 12:47:19 +02:00
parent 3e01f1ad3b
commit c00e11d573
4 changed files with 50 additions and 65 deletions

View File

@ -833,8 +833,8 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
encode the version number in the Project file which might be a bad encode the version number in the Project file which might be a bad
things in days to come? --Sam things in days to come? --Sam
*/ */
QString lib_file = (*lit) + Option::dir_sep + lib; QString lib_file = QMakeMetaInfo::findLib(Option::normalizePath((*lit) + Option::dir_sep + lib));
if(QMakeMetaInfo::libExists(lib_file)) { if (!lib_file.isEmpty()) {
QMakeMetaInfo libinfo(project); QMakeMetaInfo libinfo(project);
if(libinfo.readLib(lib_file)) { if(libinfo.readLib(lib_file)) {
if(!libinfo.isEmpty("QMAKE_PRL_TARGET")) { if(!libinfo.isEmpty("QMAKE_PRL_TARGET")) {

View File

@ -872,64 +872,56 @@ MakefileGenerator::init()
bool bool
MakefileGenerator::processPrlFile(QString &file) MakefileGenerator::processPrlFile(QString &file)
{ {
bool ret = false, try_replace_file=false; bool try_replace_file = false;
QString meta_file, orig_file = file; QString f = fileFixify(file, FileFixifyBackwards);
if(QMakeMetaInfo::libExists(file)) { QString meta_file = QMakeMetaInfo::findLib(f);
if (!meta_file.isEmpty()) {
try_replace_file = true; try_replace_file = true;
meta_file = file;
} else { } else {
QString tmp = file; QString tmp = f;
int ext = tmp.lastIndexOf('.'); int ext = tmp.lastIndexOf('.');
if(ext != -1) if(ext != -1)
tmp = tmp.left(ext); tmp = tmp.left(ext);
meta_file = tmp; meta_file = QMakeMetaInfo::findLib(tmp);
} }
// meta_file = fileFixify(meta_file); if (meta_file.isEmpty())
QString real_meta_file = Option::normalizePath(meta_file); return false;
if(!meta_file.isEmpty()) { QMakeMetaInfo libinfo(project);
QString f = fileFixify(real_meta_file, FileFixifyBackwards); debug_msg(1, "Processing PRL file: %s", meta_file.toLatin1().constData());
if(QMakeMetaInfo::libExists(f)) { if (!libinfo.readLib(meta_file)) {
QMakeMetaInfo libinfo(project); fprintf(stderr, "Error processing meta file %s\n", meta_file.toLatin1().constData());
debug_msg(1, "Processing PRL file: %s", real_meta_file.toLatin1().constData()); return false;
if(!libinfo.readLib(f)) { }
fprintf(stderr, "Error processing meta file: %s\n", real_meta_file.toLatin1().constData()); if (project->isActiveConfig("no_read_prl_" + libinfo.type().toLower())) {
} else if(project->isActiveConfig("no_read_prl_" + libinfo.type().toLower())) { debug_msg(2, "Ignored meta file %s [%s]",
debug_msg(2, "Ignored meta file %s [%s]", real_meta_file.toLatin1().constData(), libinfo.type().toLatin1().constData()); meta_file.toLatin1().constData(), libinfo.type().toLatin1().constData());
} else { return false;
ret = true; }
project->values("QMAKE_CURRENT_PRL_LIBS") = libinfo.values("QMAKE_PRL_LIBS"); project->values("QMAKE_CURRENT_PRL_LIBS") = libinfo.values("QMAKE_PRL_LIBS");
ProStringList &defs = project->values("DEFINES"); ProStringList &defs = project->values("DEFINES");
const ProStringList &prl_defs = project->values("PRL_EXPORT_DEFINES"); const ProStringList &prl_defs = project->values("PRL_EXPORT_DEFINES");
foreach (const ProString &def, libinfo.values("QMAKE_PRL_DEFINES")) foreach (const ProString &def, libinfo.values("QMAKE_PRL_DEFINES"))
if (!defs.contains(def) && prl_defs.contains(def)) if (!defs.contains(def) && prl_defs.contains(def))
defs.append(def); defs.append(def);
if (try_replace_file) { if (try_replace_file) {
ProString tgt = libinfo.first("QMAKE_PRL_TARGET"); ProString tgt = libinfo.first("QMAKE_PRL_TARGET");
if (!tgt.isEmpty()) { if (tgt.isEmpty()) {
int off = qMax(file.lastIndexOf('/'), file.lastIndexOf('\\')) + 1; fprintf(stderr, "Error: %s does not define QMAKE_PRL_TARGET\n",
debug_msg(1, " Replacing library reference %s with %s", meta_file.toLatin1().constData());
file.mid(off).toLatin1().constData(), tgt.toQString().toLatin1().constData()); } else {
file.replace(off, 1000, tgt.toQString()); int off = qMax(file.lastIndexOf('/'), file.lastIndexOf('\\')) + 1;
} debug_msg(1, " Replacing library reference %s with %s",
} file.mid(off).toLatin1().constData(),
} tgt.toQString().toLatin1().constData());
} file.replace(off, 1000, tgt.toQString());
if(ret) {
QString mf = QMakeMetaInfo::findLib(meta_file);
if(project->values("QMAKE_PRL_INTERNAL_FILES").indexOf(mf) == -1)
project->values("QMAKE_PRL_INTERNAL_FILES").append(mf);
if(project->values("QMAKE_INTERNAL_INCLUDED_FILES").indexOf(mf) == -1)
project->values("QMAKE_INTERNAL_INCLUDED_FILES").append(mf);
} }
} }
if(try_replace_file && file.isEmpty()) { QString mf = fileFixify(meta_file);
#if 0 if (!project->values("QMAKE_PRL_INTERNAL_FILES").contains(mf))
warn_msg(WarnLogic, "Found prl [%s] file with no target [%s]!", meta_file.toLatin1().constData(), project->values("QMAKE_PRL_INTERNAL_FILES").append(mf);
orig_file.toLatin1().constData()); if (!project->values("QMAKE_INTERNAL_INCLUDED_FILES").contains(mf))
#endif project->values("QMAKE_INTERNAL_INCLUDED_FILES").append(mf);
file = orig_file; return true;
}
return ret;
} }
void void

View File

@ -48,10 +48,8 @@ QMakeMetaInfo::QMakeMetaInfo(QMakeProject *_conf)
bool bool
QMakeMetaInfo::readLib(QString lib) QMakeMetaInfo::readLib(const QString &meta_file)
{ {
QString meta_file = findLib(lib);
if(cache_vars.contains(meta_file)) { if(cache_vars.contains(meta_file)) {
vars = cache_vars[meta_file]; vars = cache_vars[meta_file];
return true; return true;
@ -84,10 +82,8 @@ QMakeMetaInfo::readLib(QString lib)
QString QString
QMakeMetaInfo::findLib(QString lib) QMakeMetaInfo::findLib(const QString &lib)
{ {
lib = Option::normalizePath(lib);
QString ret; QString ret;
QString extns[] = { Option::prl_ext, /*Option::pkgcfg_ext, Option::libtool_ext,*/ QString() }; QString extns[] = { Option::prl_ext, /*Option::pkgcfg_ext, Option::libtool_ext,*/ QString() };
for(int extn = 0; !extns[extn].isNull(); extn++) { for(int extn = 0; !extns[extn].isNull(); extn++) {

View File

@ -55,11 +55,11 @@ class QMakeMetaInfo
public: public:
QMakeMetaInfo(QMakeProject *_conf); QMakeMetaInfo(QMakeProject *_conf);
bool readLib(QString lib); // These functions expect the path to be normalized
static QString findLib(QString lib); static QString findLib(const QString &lib);
static bool libExists(QString lib); bool readLib(const QString &meta_file);
QString type() const;
QString type() const;
bool isEmpty(const ProKey &v); bool isEmpty(const ProKey &v);
ProStringList &values(const ProKey &v); ProStringList &values(const ProKey &v);
ProString first(const ProKey &v); ProString first(const ProKey &v);
@ -91,9 +91,6 @@ inline ProString QMakeMetaInfo::first(const ProKey &v)
inline ProValueMap &QMakeMetaInfo::variables() inline ProValueMap &QMakeMetaInfo::variables()
{ return vars; } { return vars; }
inline bool QMakeMetaInfo::libExists(QString lib)
{ return !findLib(lib).isNull(); }
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // META_H #endif // META_H