12 FixSeparator ( const string
& s
)
15 char* p
= strchr ( &s2
[0], CBAD_SEP
);
19 p
= strchr ( p
, CBAD_SEP
);
24 Module::Module ( const Project
& project
,
25 const XMLElement
& moduleNode
,
26 const string
& modulePath
)
30 if ( node
.name
!= "module" )
31 throw Exception ( "internal tool error: Module created with non-<module> node" );
33 path
= FixSeparator ( modulePath
);
35 const XMLAttribute
* att
= moduleNode
.GetAttribute ( "name", true );
39 att
= moduleNode
.GetAttribute ( "type", true );
41 type
= GetModuleType ( node
.location
, *att
);
43 att
= moduleNode
.GetAttribute ( "extension", false );
45 extension
= att
->value
;
47 extension
= GetDefaultModuleExtension ();
53 for ( i
= 0; i
< files
.size(); i
++ )
55 for ( i
= 0; i
< libraries
.size(); i
++ )
57 for ( i
= 0; i
< includes
.size(); i
++ )
59 for ( i
= 0; i
< defines
.size(); i
++ )
61 for ( i
= 0; i
< invocations
.size(); i
++ )
62 delete invocations
[i
];
63 for ( i
= 0; i
< dependencies
.size(); i
++ )
64 delete dependencies
[i
];
71 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
72 ProcessXMLSubElement ( *node
.subElements
[i
], path
);
73 for ( i
= 0; i
< files
.size (); i
++ )
74 files
[i
]->ProcessXML ();
75 for ( i
= 0; i
< libraries
.size(); i
++ )
76 libraries
[i
]->ProcessXML ();
77 for ( i
= 0; i
< includes
.size(); i
++ )
78 includes
[i
]->ProcessXML ();
79 for ( i
= 0; i
< defines
.size(); i
++ )
80 defines
[i
]->ProcessXML ();
81 for ( i
= 0; i
< invocations
.size(); i
++ )
82 invocations
[i
]->ProcessXML ();
83 for ( i
= 0; i
< dependencies
.size(); i
++ )
84 dependencies
[i
]->ProcessXML ();
88 Module::ProcessXMLSubElement ( const XMLElement
& e
,
91 bool subs_invalid
= false;
92 string
subpath ( path
);
93 if ( e
.name
== "file" && e
.value
.size () > 0 )
95 files
.push_back ( new File ( FixSeparator ( path
+ CSEP
+ e
.value
) ) );
98 else if ( e
.name
== "library" && e
.value
.size () )
100 libraries
.push_back ( new Library ( e
, *this, e
.value
) );
103 else if ( e
.name
== "directory" )
105 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
107 subpath
= FixSeparator ( path
+ CSEP
+ att
->value
);
109 else if ( e
.name
== "include" )
111 includes
.push_back ( new Include ( project
, this, e
) );
114 else if ( e
.name
== "define" )
116 defines
.push_back ( new Define ( project
, this, e
) );
119 else if ( e
.name
== "invoke" )
121 invocations
.push_back ( new Invoke ( e
, *this ) );
122 subs_invalid
= false;
124 else if ( e
.name
== "dependency" )
126 dependencies
.push_back ( new Dependency ( e
, *this ) );
129 if ( subs_invalid
&& e
.subElements
.size() > 0 )
130 throw InvalidBuildFileException (
132 "<%s> cannot have sub-elements",
134 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
135 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
);
139 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
141 if ( attribute
.value
== "buildtool" )
143 if ( attribute
.value
== "staticlibrary" )
144 return StaticLibrary
;
145 if ( attribute
.value
== "kernelmodedll" )
146 return KernelModeDLL
;
147 throw InvalidAttributeValueException ( location
,
153 Module::GetDefaultModuleExtension () const
164 throw InvalidOperationException (__FILE__
,
169 Module::GetBasePath() const
175 Module::GetPath () const
177 return path
+ CSEP
+ name
+ extension
;
181 Module::GetTargets () const
183 if ( invocations
.size () > 0 )
185 string
targets ( "" );
186 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
188 Invoke
& invoke
= *invocations
[i
];
189 if ( targets
.length () > 0 )
191 targets
+= invoke
.GetTargets ();
200 Module::GetInvocationTarget ( const int index
) const
202 return ssprintf ( "%s_invoke_%d",
208 File::File ( const string
& _name
)
219 Library::Library ( const XMLElement
& _node
,
220 const Module
& _module
,
221 const string
& _name
)
226 if ( module
.name
== name
)
227 throw InvalidBuildFileException (
229 "module '%s' cannot link against itself",
234 Library::ProcessXML()
236 if ( !module
.project
.LocateModule ( name
) )
237 throw InvalidBuildFileException (
239 "module '%s' is trying to link against non-existant module '%s'",
245 Invoke::Invoke ( const XMLElement
& _node
,
246 const Module
& _module
)
255 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
257 invokeModule
= &module
;
260 invokeModule
= module
.project
.LocateModule ( att
->value
);
261 if ( invokeModule
== NULL
)
262 throw InvalidBuildFileException (
264 "module '%s' is trying to invoke non-existant module '%s'",
266 att
->value
.c_str() );
269 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
270 ProcessXMLSubElement ( *node
.subElements
[i
] );
274 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
276 bool subs_invalid
= false;
277 if ( e
.name
== "input" )
279 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
280 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
282 else if ( e
.name
== "output" )
284 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
285 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
287 if ( subs_invalid
&& e
.subElements
.size() > 0 )
288 throw InvalidBuildFileException ( e
.location
,
289 "<%s> cannot have sub-elements",
294 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
296 bool subs_invalid
= false;
297 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
299 input
.push_back ( new InvokeFile ( e
, FixSeparator ( module
.path
+ CSEP
+ e
.value
) ) );
302 if ( subs_invalid
&& e
.subElements
.size() > 0 )
303 throw InvalidBuildFileException ( e
.location
,
304 "<%s> cannot have sub-elements",
309 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
311 bool subs_invalid
= false;
312 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
314 output
.push_back ( new InvokeFile ( e
, FixSeparator ( module
.path
+ CSEP
+ e
.value
) ) );
317 if ( subs_invalid
&& e
.subElements
.size() > 0 )
318 throw InvalidBuildFileException ( e
.location
,
319 "<%s> cannot have sub-elements",
324 Invoke::GetTargets () const
326 string
targets ( "" );
327 for ( size_t i
= 0; i
< output
.size (); i
++ )
329 InvokeFile
& file
= *output
[i
];
330 if ( targets
.length () > 0 )
332 targets
+= file
.name
;
338 InvokeFile::InvokeFile ( const XMLElement
& _node
,
339 const string
& _name
)
343 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
345 switches
= att
->value
;
351 InvokeFile::ProcessXML()
356 Dependency::Dependency ( const XMLElement
& _node
,
357 const Module
& _module
)
360 dependencyModule (NULL
)
365 Dependency::ProcessXML()
367 dependencyModule
= module
.project
.LocateModule ( node
.value
);
368 if ( dependencyModule
== NULL
)
369 throw InvalidBuildFileException ( node
.location
,
370 "module '%s' depend on non-existant module '%s'",
372 node
.value
.c_str() );