Changeset 370


Ignore:
Timestamp:
Dec 2, 2009, 1:41:39 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

qmake: os2/GNUMAKE: Improved processing of the project library list (LIBS variable) to avoid appearance of raw library names that require substitution (fixes the debug build of linguist).

Location:
trunk/qmake/generators/os2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/qmake/generators/os2/gnumake.cpp

    r292 r370  
    100100}
    101101
    102 QString
    103 GNUMakefileGenerator::findBestVersion(const QString &d, const QString &stem, const QString &ext)
    104 {
    105     QString bd = Option::fixPathToLocalOS(d, true);
    106     if(!exists(bd))
    107         return QString();
     102// Searches for the best version of the requested library named \a stem in
     103// \a dir and append the result to the \a found list. If the best version is
     104// found, it is appended first in the list, otherwise \a stem is appended as
     105// is. If a .prl file corresponding to \a stem is found, the library name is
     106// taken from there. If the .prl refers to other libraries the found one
     107// depends on, they are also appended to the returned list (as is).
     108//
     109// The function returns \c true if the best version for the given \a stem was
     110// actually found and \c false otherwise (\a found will remain untouched in this
     111// case).
     112//
     113// Note that if a circular reference to the project's target library or to a
     114// library we already processed is detected, the function returns \c true but
     115// \a found remains untouched; this indicates that the given \a stem should be
     116// dropped from the resulting library list at all.
     117bool
     118GNUMakefileGenerator::findBestVersion(const QString &dir, const QString &stem,
     119                                      const QString &ext, QStringList &found)
     120{
     121    QString localDir = Option::fixPathToLocalOS(dir, true);
     122    if(!exists(localDir)) {
     123        return false;
     124    }
    108125
    109126    QString dllStem = stem + QTDLL_POSTFIX;
     
    115132    if (project->isActiveConfig("link_prl")) {
    116133        QMakeMetaInfo libinfo;
    117         QString libfile = QMakeMetaInfo::findLib(bd + Option::dir_sep + dllStem);
    118         if (project->values("QMAKE_PRL_INTERNAL_FILES").contains(libfile)) {
    119             // already processed, return emtpy string to discard this lib
    120             return QString("");
    121         }
    122         if (libinfo.readLib(libfile)) {
    123             project->values("QMAKE_PRL_INTERNAL_FILES") += libfile;
     134        QString prl = QMakeMetaInfo::findLib(localDir + Option::dir_sep + dllStem);
     135        if (project->values("QMAKE_PRL_INTERNAL_FILES").contains(prl)) {
     136            // already processed, drop this stem
     137            return true;
     138        }
     139        if (libinfo.readLib(prl)) {
     140            // take the data from .prl
     141            project->values("QMAKE_PRL_INTERNAL_FILES") += prl;
    124142            QString target = libinfo.first("QMAKE_PRL_TARGET");
    125143            if (target == project->first("TARGET")) {
    126                 // circular reference to ourselves, return emtpy string to discard this lib
    127                 return QString("");
     144                // circular reference to ourselves, drop this stem
     145                return true;
    128146            }
    129147            if (target.isEmpty())
     
    135153                target += libinfo.first("QMAKE_PRL_VERSION").replace(".", "");
    136154
    137             const QStringList &in = libinfo.values("QMAKE_PRL_LIBS");
    138             QStringList &out = project->values("QMAKE_PRL_LIBS");
    139             for (QStringList::ConstIterator it = in.begin(); it != in.end(); ++it) {
    140                 if (!out.contains(*it))
    141                     out.append((*it));
    142             }
    143             return target;
    144         }
    145     }
    146 
    147     if (!versionOverride.isEmpty())
    148         return stem + versionOverride;
     155            // put the stem replacement as found in .prl
     156            found << target;
     157            // put all dependencies as is
     158            foreach (const QString &lib, libinfo.values("QMAKE_PRL_LIBS"))
     159                found << lib;
     160
     161            return true;
     162        }
     163    }
     164
     165    if (!versionOverride.isEmpty()) {
     166        // unconditionally use verrsion overrride
     167        found << stem + versionOverride;
     168        return true;
     169    }
    149170
    150171    int biggest = -1;
    151172    if(!project->isActiveConfig("no_versionlink")) {
    152         QDir dir(bd);
     173        // search for a library with the highest version number
     174        QDir dir(localDir);
    153175        QStringList entries = dir.entryList();
    154         QRegExp regx(QString("((lib)?%1([0-9]*))(%2)$").arg(dllStem).arg(ext), Qt::CaseInsensitive);
    155         for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) {
    156             if(regx.exactMatch((*it))) {
    157                                 if (!regx.cap(3).isEmpty()) {
    158                                         bool ok = true;
    159                                         int num = regx.cap(3).toInt(&ok);
    160                                         biggest = qMax(biggest, (!ok ? -1 : num));
    161                                 }
    162                         }
    163         }
    164     }
    165     if (biggest != -1)
    166         return stem + QString::number(biggest);
    167 
    168     return QString();
     176        QRegExp regx(QString("((lib)?%1([0-9]*))(%2)$").arg(dllStem).arg(ext),
     177                     Qt::CaseInsensitive);
     178        foreach (const QString &ent, entries) {
     179            if(regx.exactMatch(ent)) {
     180                if (!regx.cap(3).isEmpty()) {
     181                    bool ok = true;
     182                    int num = regx.cap(3).toInt(&ok);
     183                    biggest = qMax(biggest, (!ok ? -1 : num));
     184                }
     185            }
     186        }
     187    }
     188    if (biggest != -1) {
     189        found << stem + QString::number(biggest);
     190        return true;
     191    }
     192
     193    return false;
    169194}
    170195
    171196bool GNUMakefileGenerator::findLibraries()
    172197{
    173     QStringList &l = project->values("QMAKE_LIBS");
     198    QStringList &libs = project->values("QMAKE_LIBS");
    174199
    175200    QList<QMakeLocalFileName> dirs;
    176     {
    177         QStringList &libpaths = project->values("QMAKE_LIBDIR");
    178         for(QStringList::Iterator libpathit = libpaths.begin();
    179             libpathit != libpaths.end(); ++libpathit)
    180             dirs.append(QMakeLocalFileName((*libpathit)));
    181     }
    182 
    183     QStringList::Iterator it = l.begin();
    184 
    185     do {
    186         project->values("QMAKE_PRL_LIBS").clear();
    187         bool erase = false;
    188         for (; it != l.end(); erase ? (erase = false, it = l.erase(it)) : ++it) {
    189             if((*it).startsWith("-L")) {
    190                 dirs.append(QMakeLocalFileName((*it).mid(2)));
    191             } else {
    192                 QString stem = *it, out;
    193 
    194                 if (stem.startsWith("-l"))
    195                     stem = stem.mid(2);
    196 
    197                 QString suffix;
    198                 if (!project->isEmpty("QMAKE_" + stem.toUpper() + "_SUFFIX"))
    199                     suffix = project->first("QMAKE_" + stem.toUpper() + "_SUFFIX");
    200                 for (QList<QMakeLocalFileName>::Iterator dir_it = dirs.begin(); dir_it != dirs.end(); ++dir_it) {
    201                     QString best = findBestVersion((*dir_it).local(), stem,
    202                                                    QString("%1.lib").arg(suffix));
    203                     if (!best.isNull()) {
    204                         if (best.isEmpty()) {
    205                             // we are asked to discard this lib, do it
    206                             erase = true;
    207                             break;
    208                         }
    209                         out = best.prepend("-l");
    210                         break;
    211                     }
     201    foreach (const QString &path, project->values("QMAKE_LIBDIR"))
     202        dirs.append(QMakeLocalFileName(path));
     203
     204    QStringList seen;
     205
     206    for (QStringList::Iterator it = libs.begin(); it != libs.end(); /*below*/) {
     207        QString &lib = *it;
     208
     209        if (lib.startsWith("-L")) {
     210            // this is a library path
     211            dirs.append(QMakeLocalFileName((*it).mid(2)));
     212            ++it;
     213            continue;
     214        }
     215
     216        // this must be a library file
     217        if (lib.startsWith("-l"))
     218            lib = lib.mid(2);
     219
     220        if (seen.contains(lib, Qt::CaseInsensitive)) {
     221            // already processed, remove
     222            it = libs.erase(it);
     223            continue;
     224        }
     225
     226        seen << lib;
     227
     228        QString suffix;
     229        if (!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX"))
     230            suffix = project->first("QMAKE_" + lib.toUpper() + "_SUFFIX");
     231
     232        // try every libpath we have by now
     233        bool found = false;
     234        QStringList foundLibs;
     235        foreach (const QMakeLocalFileName &dir, dirs) {
     236            if ((found = findBestVersion(dir.local(), lib,
     237                                         QString("%1.lib").arg(suffix), foundLibs)))
     238                break;
     239        }
     240        if (!found) {
     241            // assume the stem is the exact specification and use as is
     242            foundLibs << lib;
     243        }
     244
     245        if (foundLibs.isEmpty()) {
     246            // circular reference detected, remove this library from the list
     247            it = libs.erase(it);
     248        } else {
     249            // replace the library with the best found one
     250            lib = foundLibs.takeFirst();
     251            // this may introduce a duplicate, check that
     252            bool remove = false;
     253            for (QStringList::ConstIterator it2 = libs.begin(); it2 != it; ++it2)
     254                if ((remove = it2->compare(lib, Qt::CaseInsensitive) == 0))
     255                    break;
     256            // append the dependencies
     257            if (!foundLibs.empty()) {
     258                int itDiff = it - libs.begin();
     259                foreach (const QString &foundLib, foundLibs) {
     260                    if (!libs.contains(foundLib, Qt::CaseInsensitive))
     261                        libs << foundLib;
    212262                }
    213                 if (!out.isEmpty()) // We assume if it never finds it then its correct
    214                     if (!project->values("QMAKE_LIBS").contains(out))
    215                         (*it) = out;
     263                // restore the iterator as appending invalidated it
     264                it = libs.begin() + itDiff;
    216265            }
    217         }
    218 
    219         // add the libraries from PRL and process them normally
    220         QStringList l2 = project->values("QMAKE_PRL_LIBS");
    221         int oldSize = l.size();
    222         for (QStringList::ConstIterator it2 = l2.begin(); it2 != l2.end(); ++it2) {
    223             if (!l.contains(*it2))
    224                 l.append(*it2);
    225         }
    226         it = l.begin() + oldSize;
    227 
    228     } while(it != l.end());
     266            if (remove)
     267                it = libs.erase(it);
     268            else
     269                ++it;
     270        }
     271    }
    229272
    230273    return true;
  • TabularUnified trunk/qmake/generators/os2/gnumake.h

    r103 r370  
    7777    QString preCompHeaderOut;
    7878
    79     QString findBestVersion(const QString &d, const QString &stem, const QString &ext);
     79    bool findBestVersion(const QString &dir, const QString &stem,
     80                         const QString &ext, QStringList &found);
     81
    8082    virtual bool findLibraries();
    8183    void fixTargetExt();
Note: See TracChangeset for help on using the changeset viewer.