pch.h can be used as pre-compiled header
[reactos.git] / reactos / tools / rbuild / project.cpp
1
2 #include "pch.h"
3
4 #include "rbuild.h"
5
6 using std::string;
7 using std::vector;
8
9 Project::Project()
10 {
11 }
12
13 Project::Project(const string& filename)
14 {
15 if ( !xmlfile.open ( filename ) )
16 throw FileNotFoundException ( filename );
17 ReadXml();
18 }
19
20 Project::~Project()
21 {
22 for ( size_t i = 0; i < modules.size(); i++ )
23 delete modules[i];
24 }
25
26 void Project::ReadXml()
27 {
28 Path path;
29 bool projectFound = false;
30 do
31 {
32 XMLElement* head = XMLParse ( xmlfile, path );
33 if ( !head )
34 throw InvalidBuildFileException ( "Document contains no 'project' tag." );
35
36 if ( head->name != "project" )
37 {
38 throw InvalidBuildFileException ( "Expected 'project', got '%s'.",
39 head->name.c_str());
40 }
41
42 this->ProcessXML ( *head, "." );
43 delete head;
44 projectFound = true;
45 } while (!projectFound);
46 }
47
48 void
49 Project::ProcessXML ( const XMLElement& e, const string& path )
50 {
51 const XMLAttribute *att;
52 string subpath(path);
53 if ( e.name == "project" )
54 {
55 att = e.GetAttribute ( "name", false );
56 if ( !att )
57 name = "Unnamed";
58 else
59 name = att->value;
60 }
61 else if ( e.name == "module" )
62 {
63 att = e.GetAttribute ( "name", true );
64 if ( !att )
65 return;
66 Module* module = new Module ( e, att->value, path );
67 modules.push_back ( module );
68 module->ProcessXML ( e, path );
69 return;
70 }
71 else if ( e.name == "directory" )
72 {
73 // this code is duplicated between Project::ProcessXML() and Module::ProcessXML() :(
74 const XMLAttribute* att = e.GetAttribute ( "name", true );
75 if ( !att )
76 return;
77 subpath = path + "/" + att->value;
78 }
79 for ( size_t i = 0; i < e.subElements.size(); i++ )
80 ProcessXML ( *e.subElements[i], subpath );
81 }