Factories for Backend creation
[reactos.git] / reactos / tools / rbuild / project.cpp
1
2 #include "pch.h"
3 #include <assert.h>
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 delete head;
26 }
27
28 void
29 Project::ReadXml ()
30 {
31 Path path;
32
33 head = XMLParse ( xmlfile, path );
34 if ( !head )
35 throw InvalidBuildFileException ( "Document contains no 'project' tag." );
36
37 if ( head->name != "project" )
38 {
39 throw InvalidBuildFileException ( "Expected 'project', got '%s'.",
40 head->name.c_str());
41 }
42
43 this->ProcessXML ( *head, "." );
44 }
45
46 void
47 Project::ProcessXML ( const XMLElement& e, const string& path )
48 {
49 const XMLAttribute *att;
50 string subpath(path);
51 if ( e.name == "project" )
52 {
53 att = e.GetAttribute ( "name", false );
54 if ( !att )
55 name = "Unnamed";
56 else
57 name = att->value;
58
59 att = e.GetAttribute ( "makefile", true );
60 assert(att);
61 makefile = att->value;
62 }
63 else if ( e.name == "module" )
64 {
65 att = e.GetAttribute ( "name", true );
66 assert(att);
67 Module* module = new Module ( e, att->value, path );
68 modules.push_back ( module );
69 module->ProcessXML ( e, path );
70 return;
71 }
72 else if ( e.name == "directory" )
73 {
74 const XMLAttribute* att = e.GetAttribute ( "name", true );
75 assert(att);
76 subpath = path + "/" + att->value;
77 }
78 for ( size_t i = 0; i < e.subElements.size (); i++ )
79 ProcessXML ( *e.subElements[i], subpath );
80 }