KDevelop API Documentation

parts/outputviews/makeactionfilter.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 1999-2001 by Bernd Gehrmann and the KDevelop Team * 00003 * bernd@kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include <qdatetime.h> 00013 #include <kdebug.h> 00014 00015 #include "makeactionfilter.h" 00016 #include "makeactionfilter.moc" 00017 #include "makeitem.h" 00018 00019 #include <klocale.h> 00020 #include <kdebug.h> 00021 00022 //#define DEBUG 00023 00024 MakeActionFilter::ActionFormat::ActionFormat( const QString& _action, const QString& _tool, const char * regExp, int file ) 00025 : action( _action ) 00026 , tool( _tool ) 00027 , expression( regExp ) 00028 , fileGroup( file ) 00029 { 00030 } 00031 00032 MakeActionFilter::MakeActionFilter( OutputFilter& next ) 00033 : OutputFilter( next ) 00034 { 00035 00036 #ifdef DEBUG 00037 test(); 00038 #endif 00039 } 00040 00041 // returns an array of ActionFormat 00042 MakeActionFilter::ActionFormat* MakeActionFilter::actionFormats() 00043 { 00044 static ActionFormat formats[] = { 00045 ActionFormat( i18n("compiling"), "g++", "g\\+\\+\\S* (?:\\S* )*-c (?:\\S* )*`[^`]*`(?:[^/\\s;]*/)*([^/\\s;]+)", 1 ), 00046 ActionFormat( i18n("compiling"), "g++", "g\\+\\+\\S* (?:\\S* )*-c (?:\\S* )*(?:[^/]*/)*([^/\\s;]*)", 1 ), 00047 ActionFormat( i18n("compiling"), "gcc", "g\\c\\c\\S* (?:\\S* )*-c (?:\\S* )*`[^`]*`(?:[^/\\s;]*/)*([^/\\s;]+)", 1 ), 00048 ActionFormat( i18n("compiling"), "gcc", "g\\c\\c\\S* (?:\\S* )*-c (?:\\S* )*(?:[^/]*/)*([^/\\s;]*)", 1 ), 00049 ActionFormat( i18n("compiling"), "distcc", "distcc (?:\\S* )*-c (?:\\S* )*`[^`]*`(?:[^/\\s;]*/)*([^/\\s;]+)", 1 ), 00050 ActionFormat( i18n("compiling"), "distcc", "distcc (?:\\S* )*-c (?:\\S* )*(?:[^/]*/)*([^/\\s;]*)", 1 ), 00051 ActionFormat( i18n("compiling"), "unknown", "^compiling (.*)", 1 ), 00052 ActionFormat( i18n("generating"), "moc", "/moc\\b.*\\s-o\\s([^\\s;]+)", 1 ), 00053 ActionFormat( i18n("generating"), "uic", "/uic\\b.*\\s-o\\s([^\\s;]+)", 1 ), 00054 ActionFormat( i18n("linking"), "libtool", "/bin/sh\\s.*libtool.*--mode=link\\s.*\\s-o\\s([^\\s;]+)", 1 ), 00055 ActionFormat( i18n("linking"), "g++", "g\\+\\+\\S* (?:\\S* )*-o ([^\\s;]+)", 1 ), 00056 ActionFormat( i18n("linking"), "gcc", "g\\c\\c\\S* (?:\\S* )*-o ([^\\s;]+)", 1 ), 00057 ActionFormat( i18n("creating"), "", "/(?:bin/sh\\s.*mkinstalldirs).*\\s([^\\s;]+)", 1 ), 00058 ActionFormat( i18n("installing"), "", "/(?:usr/bin/install|bin/sh\\s.*mkinstalldirs|bin/sh\\s.*libtool.*--mode=install).*\\s([^\\s;]+)", 1 ), 00059 ActionFormat( i18n("generating"), "dcopidl", "dcopidl .* > ([^\\s;]+)", 1 ), 00060 ActionFormat( i18n("compiling"), "dcopidl2cpp", "dcopidl2cpp (?:\\S* )*([^\\s;]+)", 1 ), 00061 00062 ActionFormat( QString::null, QString::null, 0, 0 ) 00063 }; 00064 00065 return formats; 00066 } 00067 00068 void MakeActionFilter::processLine( const QString& line ) 00069 { 00070 ActionItem* actionItem = matchLine( line ); 00071 if ( actionItem != NULL ) 00072 { 00073 emit item( actionItem ); 00074 } 00075 else 00076 { 00077 OutputFilter::processLine( line ); 00078 } 00079 } 00080 00081 ActionItem* MakeActionFilter::matchLine( const QString& line ) 00082 { 00083 #ifdef DEBUG 00084 QTime t; 00085 t.start(); 00086 #endif 00087 00088 //900-1000ms to execute on an Athlon XP 2000+, while the UI is completely blocked. 00089 int i = 0; 00090 ActionFormat* aFormats = actionFormats(); 00091 ActionFormat* format = &aFormats[i]; 00092 00093 while ( !format->action.isNull() ) 00094 { 00095 // kdDebug(9004) << "Testing filter: " << format->action << ": " << format->tool << endl; 00096 QRegExp& regExp = format->expression; 00097 if ( regExp.search( line ) != -1 ) 00098 { 00099 return new ActionItem( format->action, regExp.cap( format->fileGroup ), format->tool, line ); 00100 } 00101 #ifdef DEBUG 00102 if ( t.elapsed() > 100 ) 00103 kdDebug(9004) << "MakeActionFilter::processLine: SLOW regexp matching: " << t.elapsed() << " ms \n"; 00104 #endif 00105 format = &aFormats[++i]; 00106 } 00107 return 0; 00108 } 00109 00110 struct TestItem 00111 { 00112 TestItem() {} 00113 TestItem( const QString& _line, const QString& _action, const QString& _tool, const QString& _file ) 00114 : line( _line ) 00115 , action( _action ) 00116 , tool( _tool ) 00117 , file( _file ) 00118 {} 00119 QString line; 00120 QString action; 00121 QString tool; 00122 QString file; 00123 }; 00124 00125 #ifdef DEBUG 00126 00127 void MakeActionFilter::test() 00128 { 00129 static QValueList<TestItem> testItems = QValueList<TestItem>() 00130 00131 << TestItem( // simple qmake compile 00132 "g++ -c -pipe -Wall -W -O2 -DQT_NO_DEBUG -I/home/john/src/kde/qt-copy/mkspecs/default -I. " 00133 "-I/home/john/src/kde/qt-copy/include -o test.o test.cpp", 00134 "compiling", "g++", "test.cpp" ) 00135 << TestItem( // simple qmake link 00136 "g++ -o ../bin/test test.o -Wl,-rpath,/home/john/src/kde/qt-copy/lib -L/home/john/src/kde/qt-copy/lib " 00137 "-L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm", 00138 "linking", "g++", "../bin/test" ) 00139 << TestItem( // automake 1.7, srcdir != builddir 00140 "if /bin/sh ../../libtool --silent --mode=compile --tag=CXX g++ -DHAVE_CONFIG_H -I. " 00141 "-I/home/john/src/kde/kdevelop/lib/interfaces -I../.. -I/usr/local/kde/include -I/home/john/src/kde/qt-copy/include " 00142 "-I/usr/X11R6/include -DQT_THREAD_SUPPORT -D_REENTRANT -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall -pedantic -W " 00143 "-Wpointer-arith -Wmissing-prototypes -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion " 00144 "-Wchar-subscripts -fno-builtin -g3 -Wformat-security -Wmissing-format-attribute -fno-exceptions -fno-check-new " 00145 "-fno-common -MT kdevcore.lo -MD -MP -MF \".deps/kdevcore.Tpo\" -c -o kdevcore.lo `test -f " 00146 "'/home/john/src/kde/kdevelop/lib/interfaces/kdevcore.cpp' || echo " 00147 "'/home/john/src/kde/kdevelop/lib/interfaces/'`/home/john/src/kde/kdevelop/lib/interfaces/kdevcore.cpp; then mv " 00148 "\".deps/kdevcore.Tpo\" \".deps/kdevcore.Plo\"; else rm -f \".deps/kdevcore.Tpo\"; exit 1; fi", 00149 "compiling", "g++", "kdevcore.cpp" ) 00150 << TestItem( // automake 1.7, srcdir != builddir 00151 "if g++ -DHAVE_CONFIG_H -I. -I/home/john/src/kde/kdevelop/src -I.. -I/home/john/src/kde/kdevelop/lib/interfaces " 00152 "-I/home/john/src/kde/kdevelop/lib/sourceinfo -I/home/john/src/kde/kdevelop/lib/util -I/home/john/src/kde/kdevelop/lib " 00153 "-I/home/john/src/kde/kdevelop/lib/qextmdi/include -I/home/john/src/kde/kdevelop/lib/structure -I/usr/local/kde/include " 00154 "-I/home/john/src/kde/qt-copy/include -I/usr/X11R6/include -DQT_THREAD_SUPPORT -D_REENTRANT -Wnon-virtual-dtor " 00155 "-Wno-long-long -Wundef -Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -ansi " 00156 "-D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -Wchar-subscripts -fno-builtin -g3 -Wformat-security " 00157 "-Wmissing-format-attribute -fno-exceptions -fno-check-new -fno-common -MT mainwindowideal.o -MD -MP -MF " 00158 "\".deps/mainwindowideal.Tpo\" -c -o mainwindowideal.o `test -f '/home/john/src/kde/kdevelop/src/mainwindowideal.cpp' " 00159 "|| echo '/home/john/src/kde/kdevelop/src/'`/home/john/src/kde/kdevelop/src/mainwindowideal.cpp; then mv " 00160 "\".deps/mainwindowideal.Tpo\" \".deps/mainwindowideal.Po\"; else rm -f \".deps/mainwindowideal.Tpo\"; exit 1; fi", 00161 "compiling", "g++", "mainwindowideal.cpp" ) 00162 << TestItem( 00163 "source='makewidget.cpp' object='makewidget.lo' libtool=yes depfile='.deps/makewidget.Plo' " 00164 "tmpdepfile='.deps/makewidget.TPlo' depmode=gcc3 /bin/sh ../../admin/depcomp /bin/sh ../../libtool --mode=compile " 00165 "--tag=CXX g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../lib/interfaces -I../../lib/util -I/opt/kde3/include " 00166 "-I/usr/lib/qt3/include -I/usr/X11R6/include -DQT_THREAD_SUPPORT -D_REENTRANT -Wnon-virtual-dtor -Wno-long-long -Wundef " 00167 "-Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE " 00168 "-Wcast-align -Wconversion -fno-builtin -g -O2 -g3 -O0 -fno-exceptions -fno-check-new -c -o makewidget.lo `test -f " 00169 "'makewidget.cpp' || echo './'`makewidget.cpp", 00170 "compiling", "g++", "makewidget.cpp" ) 00171 << TestItem( // automake 1.7, srcdir != builddir 00172 "/bin/sh ../../libtool --silent --mode=link --tag=CXX g++ -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall -pedantic " 00173 "-W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align " 00174 "-Wconversion -Wchar-subscripts -fno-builtin -g3 -Wformat-security -Wmissing-format-attribute -fno-exceptions " 00175 "-fno-check-new -fno-common -o libkdevoutputviews.la.closure libkdevoutputviews_la_closure.lo -L/usr/X11R6/lib " 00176 "-L/home/john/src/kde/qt-copy/lib -L/usr/local/kde/lib -avoid-version -module -no-undefined -R /usr/local/kde/lib " 00177 "-R /home/john/src/kde/qt-copy/lib -R /usr/X11R6/lib outputviewsfactory.lo makeviewpart.lo makewidget.lo " 00178 "appoutputviewpart.lo appoutputwidget.lo directorystatusmessagefilter.lo outputfilter.lo compileerrorfilter.lo " 00179 "commandcontinuationfilter.lo makeitem.lo makeactionfilter.lo otherfilter.lo ../../lib/libkdevelop.la", 00180 "linking", "libtool", "libkdevoutputviews.la.closure" ) 00181 << TestItem( //libtool, linking 2 00182 "/bin/sh ../libtool --silent --mode=link --tag=CXX g++ -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall -pedantic " 00183 "-W -Wpointer-arith -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -Wchar-subscripts " 00184 "-fno-builtin -g3 -fno-exceptions -fno-check-new -fno-common -o libkfilereplacepart.la.closure libkfilereplacepart_la_closure.lo " 00185 "-module -no-undefined -L/usr/X11R6/lib -L/usr/lib/qt3/lib -L/opt/kde3/lib -version-info 1:0:0 kfilereplacepart.lo kfilereplacedoc.lo " 00186 "kfilereplaceview.lo kaboutkfilereplace.lo kaddstringdlg.lo kconfirmdlg.lo kernel.lo kexpression.lo kfilereplacepref.lo " 00187 "klistviewstring.lo knewprojectdlg.lo koptionsdlg.lo kresultview.lo filelib.lo knewprojectdlgs.lo -lkio -lkparts -lkhtml", 00188 "linking", "libtool", "libkfilereplacepart.la.closure") 00189 << TestItem( //libtool, linking 3 00190 "/bin/sh ../libtool --silent --mode=link --tag=CXX g++ -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall -pedantic " 00191 "-W -Wpointer-arith -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -Wchar-subscripts " 00192 "-fno-builtin -g3 -fno-exceptions -fno-check-new -fno-common -o libkfilereplacepart.la -rpath /opt/kde3/lib/kde3 " 00193 "-module -no-undefined -L/usr/X11R6/lib -L/usr/lib/qt3/lib -L/opt/kde3/lib -version-info 1:0:0 kfilereplacepart.lo " 00194 "kfilereplacedoc.lo kfilereplaceview.lo kaboutkfilereplace.lo kaddstringdlg.lo kconfirmdlg.lo kernel.lo kexpression.lo " 00195 "kfilereplacepref.lo klistviewstring.lo knewprojectdlg.lo koptionsdlg.lo kresultview.lo filelib.lo knewprojectdlgs.lo -lkio -lkparts -lkhtml", 00196 "linking", "libtool", "libkfilereplacepart.la") 00197 << TestItem( //automake, builddir!=srcdir, libtool=no, compiling 00198 " g++ -DHAVE_CONFIG_H -I. -I/home/andris/cvs-developement/head/quanta/quanta/project " 00199 "-I../.. -I/home/andris/cvs-developement/head/quanta/quanta/dialogs -I/opt/kde3/include -I/usr/lib/qt3/include -I/usr/X11R6/include " 00200 "-I../../quanta/dialogs -DQT_THREAD_SUPPORT -D_REENTRANT -DKOMMANDER -DDESIGNER -DQT_NO_SQL -DHAVE_KDE -Wnon-virtual-dtor " 00201 "-Wno-long-long -Wundef -Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE " 00202 "-Wcast-align -Wconversion -Wchar-subscripts -fno-builtin -g3 -DKDE_NO_COMPAT -fno-exceptions -fno-check-new -fno-common -c -o project.o " 00203 "`test -f '/home/andris/cvs-developement/head/quanta/quanta/project/project.cpp' || " 00204 "echo '/home/andris/cvs-developement/head/quanta/quanta/project/'`/home/andris/cvs-developement/head/quanta/quanta/project/project.cpp ", 00205 "compiling", "g++", "project.cpp") 00206 << TestItem( 00207 "/usr/local/kde/bin/dcopidl /home/john/src/kde/kdevelop/lib/interfaces/KDevAppFrontendIface.h > KDevAppFrontendIface.kidl " 00208 "|| ( rm -f KDevAppFrontendIface.kidl ; /bin/false )", 00209 "generating", "dcopidl", "KDevAppFrontendIface.kidl" ) 00210 << TestItem( 00211 "/usr/local/kde/bin/dcopidl2cpp --c++-suffix cpp --no-signals --no-stub KDevAppFrontendIface.kidl", 00212 "compiling", "dcopidl2cpp", "KDevAppFrontendIface.kidl" ) 00213 << TestItem( //install 00214 "/usr/bin/install -c -p -m 644 /home/andris/development/quanta/quanta/kommander/editor/kmdr-editor.desktop " 00215 "/opt/kde3/share/applnk/Editors/kmdr-editor.desktop", "installing", "", "/opt/kde3/share/applnk/Editors/kmdr-editor.desktop") 00216 << TestItem( //libtool install 00217 "/bin/sh ../../libtool --silent --mode=install /usr/bin/install -c -p libkommanderwidgets.la " 00218 "/opt/kde3/lib/libkommanderwidgets.la", "installing", "", "/opt/kde3/lib/libkommanderwidgets.la") 00219 ; 00220 00221 QValueList<TestItem>::const_iterator it = testItems.begin(); 00222 for( ; it != testItems.end(); ++it ) 00223 { 00224 ActionItem* actionItem = matchLine( (*it).line ); 00225 if ( actionItem == NULL ) 00226 { 00227 kdError( 9004 ) << "MakeActionFilter::test(): match failed (no match):" << endl; 00228 kdError( 9004 ) << (*it).line << endl; 00229 } 00230 else if ( actionItem->m_action != (*it).action ) 00231 { 00232 kdError( 9004 ) << "MakeActionFilter::test(): match failed (expected action " 00233 << (*it).action << ", got " << actionItem->m_action << endl; 00234 kdError( 9004 ) << (*it).line << endl; 00235 } 00236 else if ( actionItem->m_tool != (*it).tool ) 00237 { 00238 kdError( 9004 ) << "MakeActionFilter::test(): match failed (expected tool " 00239 << (*it).tool << ", got " << actionItem->m_tool << endl; 00240 kdError( 9004 ) << (*it).line << endl; 00241 } 00242 else if ( actionItem->m_file != (*it).file ) 00243 { 00244 kdError( 9004 ) << "MakeActionFilter::test(): match failed (expected file " 00245 << (*it).file << ", got " << actionItem->m_file << endl; 00246 kdError( 9004 ) << (*it).line << endl; 00247 } else 00248 kdDebug( 9004 ) << "Test passed, " << actionItem->m_file << " (" << actionItem->m_action << ": " << actionItem->m_tool << ") found." << endl; 00249 if ( actionItem != NULL ) 00250 delete actionItem; 00251 } 00252 00253 } 00254 00255 #endif
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:52 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003