Changeset 800

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

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

Location:
mcbuilder/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • mcbuilder/trunk/include/Builder.h

    r799 r800  
    6969  bool createMakefile(QString projectPath); 
    7070  bool createConfigFile(QString projectPath); 
     71  bool compareConfigFile(QString projectPath); 
    7172  bool matchErrorOrWarning(QString msg); 
    7273  bool matchInFunction(QString msg); 
  • 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 
  • mcbuilder/trunk/tests/TestBuilder.cpp

    r799 r800  
    1717 
    1818#include "TestBuilder.h" 
    19 #include "ProjectInfo.h" 
    2019 
    2120#define TEST_PROJECT "resources/examples/Input-Output/AinToServo" 
     
    4039void TestBuilder::initTestCase() 
    4140{ 
     41  window->openProject(currentProjectPath()); 
    4242  builder = window->builder; 
    43   builder->currentProjectPath = currentProjectPath(); 
    4443} 
    4544 
     
    8584   
    8685  QStringList makeFiles; // list of files in the Makefile 
     86  QStringList makeFileDirs; // list of include dirs in the Makefile 
    8787  QVERIFY(makefile.open(QFile::ReadOnly | QFile::Text)); 
    8888  QTextStream in(&makefile); 
     
    9090  static const int BEGIN = 0; 
    9191  static const int FILES = 1; 
     92  static const int DIRS = 2; 
    9293  int state = BEGIN; 
    9394  while(!makeLine.isNull()) 
     
    101102      case FILES: 
    102103        if(makeLine.startsWith("INCLUDEDIRS")) 
     104          state = DIRS; 
     105        else if(!makeLine.isEmpty() && !makeLine.startsWith("ARM_SRC")) 
     106          makeFiles << makeLine.remove("\\").trimmed(); 
     107        break; 
     108      case DIRS: 
     109        if(makeLine.startsWith("CC")) 
    103110          state = BEGIN; 
    104         else 
    105         { 
    106           if(!makeLine.isEmpty() && !makeLine.startsWith("ARM_SRC")) 
    107             makeFiles.append(makeLine.remove("\\").trimmed()); 
    108         } 
    109         break; 
     111        else if(!makeLine.isEmpty()) 
     112          makeFileDirs << makeLine.remove("\\").remove("-I").trimmed(); 
    110113    } 
    111114    makeLine = in.readLine(); 
    112115  } 
    113116  QVERIFY(makeFiles.size()); // make sure we got something 
     117  QVERIFY(makeFileDirs.size()); 
    114118   
    115119  // now, let's compare our lists 
     
    128132  //qDebug("makefiles: %d, projectfiles: %d, matches: %d", makeFiles.size(), projectFiles.size(), matches); 
    129133  QVERIFY( matches == (makeFiles.size() - libraryFiles)); 
     134   
     135  // now check that the appropriate include directories have been added 
     136  QDomNodeList dirs = projectDoc.elementsByTagName("include_dirs").at(0).childNodes(); 
     137  QStringList includeDirs; 
     138  for(int i = 0; i < dirs.count(); i++) 
     139    includeDirs.append(builder->filteredPath(dirs.at(i).toElement().text())); 
     140  QVERIFY(includeDirs.size()); // make sure we got something 
     141   
     142  matches = 0; 
     143  int libraryDirs = 0; 
     144  foreach( QString dir, makeFileDirs ) 
     145  { 
     146    if(includeDirs.contains(dir)) 
     147      matches++; 
     148    else if(dir.contains("cores/makecontroller/libraries")) 
     149      libraryDirs++; 
     150  } 
     151  //qDebug("makefile dirs: %d, project file dirs: %d, matches: %d, library dirs: %d",  
     152  //         makeFileDirs.size(), includeDirs.size(), matches, libraryDirs); 
     153   
     154  // one additional difference is that the Makefile should include the project dir itself as an include dir 
     155  // whereas this is not specificed in the project file 
     156  QVERIFY(matches == (makeFileDirs.size() - libraryDirs - 1)); 
     157} 
     158 
     159/* 
     160  Create a config file. 
     161  Make sure it includes the appropriate elements, based on the  
     162  ProjectInfo. 
     163*/ 
     164void TestBuilder::testConfigFile() 
     165{ 
     166  QDir projDir(currentProjectPath()); 
     167  QFile configFile(projDir.filePath("config.h")); 
     168   
     169  if( configFile.exists() ) 
     170    projDir.remove("config.h"); // get rid of the file, so we can test creating it 
     171 
     172  builder->createConfigFile(currentProjectPath()); 
     173  // we haven't changed anything in the file yet, so this should return false 
     174  QVERIFY( builder->compareConfigFile(currentProjectPath()) == false ); 
     175   
     176  // now let's change a few things in the config file, and confirm that we need to update it 
     177//  QVERIFY(configFile.open(QFile::Text)); 
     178//  QTextStream in(&configFile); 
     179//   
     180//  configFile.close(); 
    130181} 
    131182 
  • mcbuilder/trunk/tests/TestBuilder.h

    r799 r800  
    4444  void loadLibs(); 
    4545  void testMakefile(); 
     46  void testConfigFile(); 
    4647}; 
    4748