47 #include <arcs/arcsxmlhandler.h>
48 #include <arcs/arcsapplicationcomponent.h>
49 #include <arcs/arcsfactory.h>
50 #include <QCoreApplication>
57 #include <QStringList>
62 #include <QTextStream>
88 QMap<QString,LibraryPath> libraryDirBounds;
93 QString getLibraryName(QString libpath)
95 QString lname = libpath.right(libpath.length() - libpath.lastIndexOf(QDir::separator())-1 );
96 lname = lname.left(lname.lastIndexOf(
'.'));
97 if (lname.startsWith(
"lib"))
99 lname = lname.right(lname.length()-3);
106 void exploreProjectFile(QString profile)
109 QFileInfo fi(profile) ;
110 QString name = fi.baseName();
111 QString path = fi.absolutePath();
117 QFile filepro(profile);
118 filepro.open(QIODevice::ReadOnly);
119 QTextStream ts(&filepro);
120 QRegExp linematcher(
"^\\s*TARGET\\s*=\\s*(\\w+)\\W*$");
126 line = ts.readLine();
127 if (linematcher.exactMatch(line))
129 target = linematcher.cap(1);
132 while ( !line.isNull());
135 if (target.isEmpty())
137 std::cout << std::setw(15) << qPrintable(name) <<
" => " << qPrintable(path) << std::endl;
138 libraryDirBounds[name] = libraryPath(path,
false);
142 std::cout << std::setw(15) << qPrintable(target) <<
" => " << qPrintable(path) << std::endl;
143 libraryDirBounds[target] = libraryPath(path,
false);
148 bool launchProcess(QString processName, QString path)
151 pr.setWorkingDirectory(path);
152 std::cout <<
" " << qPrintable(processName);
153 pr.start(processName);
154 while (pr.state() == QProcess::Running)
165 std::cout << std::endl;
166 pr.waitForFinished();
167 return (pr.exitStatus() == QProcess::NormalExit && pr.exitCode() == 0);
171 void buildBounds(QString path)
177 if (path.at(path.length()-1) != QDir::separator())
178 path += QDir::separator();
181 QStringList profiles = d.entryList(QStringList(
"*.pro"));
182 for (i=0; i < profiles.count() ; i++)
183 exploreProjectFile(path + profiles[i]);
185 if( profiles.count() == 0)
187 std::cout <<
"Storing alxfiles" << std::endl;
188 QStringList alxfiles = d.entryList(QStringList(
"*.alx"));
189 for (i=0; i < alxfiles.count() ; i++)
191 std::cout << qPrintable(d.dirName()) << std::endl;
192 libraryDirBounds[d.dirName()] = libraryPath( path,
true );
197 QStringList dirs = d.entryList(QDir::Dirs);
198 for (i=0; i < dirs.count() ; i++)
201 if (dirs[i].at(0) !=
'.' )
202 buildBounds(path + dirs[i]);
207 bool buildLibrary(QString path,
bool libmaker=
false)
210 if (!launchProcess(
"arcslibmaker",path))
212 if (!launchProcess(
"qmake",path))
214 if (!launchProcess(
"make",path))
220 int buildApplication(QStringList libs, QString path)
224 std::cout <<
"Looking for bindings between libs and directories" << std::endl;
227 for (
int i=0; i < libs.count() ; i++)
229 QString libname = getLibraryName(libs[i]);
230 std::cout <<
"Trying to build library " << qPrintable(libname) << std::endl;
231 QString dir = libraryDirBounds[libname].path;
234 if (buildLibrary(dir,libraryDirBounds[libname].libmaker))
236 std::cout << std::setw(10) <<
" " <<
" Success !" << std::endl;
240 std::cout << std::setw(10) <<
" " <<
"Failed !" << std::endl;
245 std::cout << std::setw(10) <<
" " <<
"Failed !" << std::endl;
253 void usage(
char* name)
255 std::cerr <<
"Usage: " << name <<
" application_file.xml [component/sources/path/]" << std::endl;
256 std::cerr <<
"Where: \"application_file.xml\" is an application file ;" << std::endl;
257 std::cerr <<
" \"component/sources/path/\" is an optional source path. " << std::endl;
261 int main(
int argc,
char* argv[])
264 QCoreApplication app(argc,argv);
265 if ((argc == 1) || (argc > 3))
271 char* buildpath = getenv(
"ARCSBUILDPATH");
273 if (buildpath == NULL)
274 std::cerr <<
"ARCSBUILDPATH environment variable not found." << std::endl;
276 path = QString(buildpath);
278 if (buildpath == NULL && argc < 3)
285 path = QString(argv[2]);
290 query.bindVariable(
"file",QVariant(QDir::currentPath() + QDir::separator() + QString(argv[1])));
291 query.setQuery(
"doc($file)/application/context/libraries/library/string(data(@path))");
293 if (query.evaluateTo(&libList))
295 int res = buildApplication(libList,path);
296 if (res != libList.count())
297 std::cerr <<
"Failed to build some libraries required by your application." << std::endl;
299 std::cout <<
"All libraries successfully built." << std::endl;
303 std::cerr <<
"Failed to load file " << argv[1] << std::endl;