-Add a new module type 'cabinet' to handle .cab files generation
[reactos.git] / reactos / 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
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 }
34
35 Include::Include ( const Project& project,
36 const XMLElement* includeNode,
37 const Module* module )
38 : directory ( NULL ),
39 project ( project ),
40 node ( includeNode ),
41 module ( module )
42 {
43 }
44
45 Include::Include ( const Project& project,
46 DirectoryLocation root,
47 const std::string& relative_path )
48 : project ( project ),
49 node ( NULL )
50 {
51 directory = new FileLocation ( root, relative_path, "" );
52 }
53
54 Include::~Include()
55 {
56 if ( directory )
57 delete directory;
58 }
59
60 void
61 Include::ProcessXML ()
62 {
63 DirectoryLocation root = SourceDirectory;
64 const Module *base = module;
65
66 string relative_path;
67 const XMLAttribute* att = node->GetAttribute ( "base", false );
68 if ( att )
69 {
70 if ( !module )
71 throw XMLInvalidBuildFileException (
72 node->location,
73 "'base' attribute illegal from global <include>" );
74
75 if ( att->value == project.name )
76 base = NULL;
77 else
78 {
79 base = project.LocateModule ( att->value );
80 if ( !base )
81 throw XMLInvalidBuildFileException (
82 node->location,
83 "<include> attribute 'base' references non-existant project or module '%s'",
84 att->value.c_str() );
85 root = GetDefaultDirectoryTree ( base );
86 }
87 }
88
89 if ( base )
90 {
91 relative_path = base->output->relative_path;
92 if ( node->value.length () > 0 && node->value != "." )
93 relative_path += sSep + node->value;
94 }
95 else
96 relative_path = node->value;
97
98 att = node->GetAttribute ( "root", false );
99 if ( att )
100 {
101 if ( att->value == "intermediate" )
102 root = IntermediateDirectory;
103 else if ( att->value == "output" )
104 root = OutputDirectory;
105 else
106 throw InvalidAttributeValueException ( node->location,
107 "root",
108 att->value );
109 }
110
111 directory = new FileLocation ( root,
112 relative_path,
113 "",
114 node );
115 }
116
117 DirectoryLocation
118 Include::GetDefaultDirectoryTree ( const Module* module ) const
119 {
120 if ( module != NULL &&
121 ( module->type == RpcServer ||
122 module->type == RpcClient ||
123 module->type == RpcProxy ||
124 module->type == IdlHeader) )
125 return IntermediateDirectory;
126 else
127 return SourceDirectory;
128 }