Show
Ignore:
Timestamp:
08/10/08 13:20:07 (5 months ago)
Author:
liamstask
Message:

- add compareConfigFile() to determine when we need to re-write the config file
- add tests for it

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • mcbuilder/trunk/src/Builder.cpp

    r799 r800  
    404404 
    405405/* 
     406  Check if we need to modify the config file for this project. 
     407  Compare the info currently in ProjectInfo with the info in config.h. 
     408  If they don't match or config.h doesn't exist, return true. 
     409  If we don't need to update/create config.h, return false. 
     410*/ 
     411bool Builder::compareConfigFile(QString projectPath) 
     412{ 
     413  bool retval = false; 
     414  QDir dir(projectPath); 
     415  QFile configFile(dir.filePath("config.h")); 
     416  if(configFile.open(QIODevice::ReadOnly|QFile::Text)) 
     417  { 
     418    QTextStream in(&configFile); 
     419    int maj, min, bld; 
     420    parseVersionNumber( &maj, &min, &bld ); 
     421     
     422    bool network = false; 
     423    bool osc = false; 
     424    bool usb = false; 
     425     
     426    QRegExp majorVersionExp("#define FIRMWARE_MAJOR_VERSION (\\d+)"); 
     427    QRegExp minorVersionExp("#define FIRMWARE_MINOR_VERSION (\\d+)"); 
     428    QRegExp buildVersionExp("#define FIRMWARE_BUILD_NUMBER (\\d+)"); 
     429     
     430    QRegExp heapExp("#define CONTROLLER_HEAPSIZE (\\d+)"); 
     431    QRegExp nameExp("#define FIRMWARE_NAME \"(.+)\""); 
     432     
     433    QRegExp mempoolExp("#define NETWORK_MEM_POOL (\\d+)"); 
     434    QRegExp udpExp("#define NETWORK_UDP_CONNS (\\d+)"); 
     435    QRegExp tcpExp("#define NETWORK_TCP_CONNS (\\d+)"); 
     436    QRegExp tcpListenExp("#define NETWORK_TCP_LISTEN_CONNS (\\d+)"); 
     437     
     438    QString line = in.readLine(); 
     439    while(!line.isNull()) 
     440    { 
     441      if( line.contains(majorVersionExp) ) // major version number 
     442      { 
     443        int majVer = majorVersionExp.cap(1).toInt(); 
     444        if(majVer != maj) 
     445          retval = true; 
     446      } 
     447      else if( line.contains(minorVersionExp) ) // minor version number 
     448      { 
     449        int minVer = minorVersionExp.cap(1).toInt(); 
     450        if(minVer != min) 
     451          retval = true; 
     452      } 
     453      else if( line.contains(buildVersionExp) ) // build version number 
     454      { 
     455        int bldVer = buildVersionExp.cap(1).toInt(); 
     456        if(bldVer != bld) 
     457          retval = true; 
     458      } 
     459      else if( line.contains(heapExp) ) // heap size 
     460      { 
     461        int heap = heapExp.cap(1).toInt(); 
     462        if(heap != projInfo->heapsize()) 
     463          retval = true; 
     464      } 
     465      else if( line.contains(nameExp) ) // project name 
     466      { 
     467        QString firmwareName = nameExp.cap(1); 
     468        if(firmwareName != dir.dirName()) 
     469          retval = true; 
     470      } 
     471      else if( line.contains("#define MAKE_CTRL_USB") ) // include USB 
     472        usb = true; 
     473      else if( line.contains("#define OSC") ) // include OSC 
     474        osc = true; 
     475      else if( line.contains("#define MAKE_CTRL_NETWORK") ) // include network 
     476        network = true; 
     477      else if( line.contains(mempoolExp) ) // network memory pool size 
     478      { 
     479        int mempool = mempoolExp.cap(1).toInt(); 
     480        if( mempool != projInfo->networkMempool() ) 
     481          retval = true; 
     482      } 
     483      else if( line.contains(udpExp) ) // number of UDP connections 
     484      { 
     485        int udp = udpExp.cap(1).toInt(); 
     486        if( udp != projInfo->udpSockets() ) 
     487          retval = true; 
     488      } 
     489      else if( line.contains(tcpExp) ) // number of TCP sockets 
     490      { 
     491        int tcp = tcpExp.cap(1).toInt(); 
     492        if( tcp != projInfo->tcpSockets() ) 
     493          retval = true; 
     494      } 
     495      else if( line.contains(tcpListenExp) ) // number of TCP server sockets 
     496      { 
     497        int tcpListen = tcpListenExp.cap(1).toInt(); 
     498        if( tcpListen != projInfo->tcpServers() ) 
     499          retval = true; 
     500      } 
     501       
     502      line = in.readLine(); 
     503    } 
     504     
     505    if(usb != projInfo->includeUsb() ) 
     506      retval = true; 
     507    if(osc != projInfo->includeOsc() ) 
     508      retval = true; 
     509    if(network != projInfo->includeNetwork() ) 
     510      retval = true; 
     511     
     512    configFile.close(); 
     513  } 
     514  else 
     515    retval = true; // file doesn't exist or couldn't be read 
     516  return retval; 
     517} 
     518 
     519/* 
    406520  Convert a version number string to 3 ints. 
    407521  We expect the version string to be in the form X.Y.Z