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