* Bring back rbuild build to be used until bug 6372 is fixed.
[reactos.git] / tools / rbuild / include.cpp
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 #include "pch.h"
19 #include <assert.h>
20
21 #include "rbuild.h"
22
23 using std::string;
24 using std::vector;
25
26 Include::Include ( const Project& project,
27 const XMLElement* includeNode )
28 : directory ( NULL ),
29 project ( project ),
30 node ( includeNode ),
31 module ( NULL )
32 {
33 Initialize ();
34 }
35
36 Include::Include ( const Project& project,
37 const XMLElement* includeNode,
38 const Module* module )
39 : directory ( NULL ),
40 project ( project ),
41 node ( includeNode ),
42 module ( module )
43 {
44 Initialize ();
45 }
46
47 Include::Include ( const Project& project,
48 DirectoryLocation root,
49 const std::string& relative_path )
50 : project ( project ),
51 node ( NULL )
52 {
53 directory = new FileLocation ( root, relative_path, "" );
54 }
55
56 Include::~Include()
57 {
58 if ( directory )
59 delete directory;
60 }
61
62 void
63 Include::ProcessXML ()
64 {
65 DirectoryLocation root = SourceDirectory;
66 const Module *base = module;
67
68 string relative_path;
69 const XMLAttribute* att = node->GetAttribute ( "base", false );
70 if ( att )
71 {
72 if ( !module )
73 throw XMLInvalidBuildFileException (
74 node->location,
75 "'base' attribute illegal from global <include>" );
76
77 if ( att->value == project.name )
78 base = NULL;
79 else
80 {
81 base = project.LocateModule ( att->value );
82 if ( !base )
83 throw XMLInvalidBuildFileException (
84 node->location,
85 "<include> attribute 'base' references non-existant project or module '%s'",
86 att->value.c_str() );
87 root = GetDefaultDirectoryTree ( base );
88 }
89 }
90
91 if ( base )
92 {
93 relative_path = base->output->relative_path;
94 if ( node->value.length () > 0 && node->value != "." )
95 relative_path += sSep + node->value;
96 }
97 else
98 relative_path = node->value;
99
100 att = node->GetAttribute ( "root", false );
101 if ( att )
102 {
103 if ( att->value == "intermediate" )
104 root = IntermediateDirectory;
105 else if ( att->value == "output" )
106 root = OutputDirectory;
107 else
108 throw InvalidAttributeValueException ( node->location,
109 "root",
110 att->value );
111 }
112
113 directory = new FileLocation ( root,
114 relative_path,
115 "",
116 node );
117 }
118
119 DirectoryLocation
120 Include::GetDefaultDirectoryTree ( const Module* module ) const
121 {
122 if ( module != NULL &&
123 ( module->type == RpcServer ||
124 module->type == RpcClient ||
125 module->type == RpcProxy ||
126 module->type == IdlHeader ||
127 module->type == IdlInterface) )
128 return IntermediateDirectory;
129 else
130 return SourceDirectory;
131 }
132
133 void
134 Include::Initialize ()
135 {
136 ParseCompilers ( *node, "cpp" );
137 }