-Add a new module type 'cabinet' to handle .cab files generation
[reactos.git] / reactos / tools / rbuild / compilationunit.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 CompilationUnit::CompilationUnit ( const File* file )
27 : project(NULL),
28 module(NULL),
29 node(NULL)
30 {
31 default_name = new FileLocation ( IntermediateDirectory,
32 "",
33 file->file.name );
34
35 name = file->file.relative_path + sSep + file->file.name;
36 files.push_back ( file );
37 }
38
39 CompilationUnit::CompilationUnit ( const Project* project,
40 const Module* module,
41 const XMLElement* node )
42 : project(project),
43 module(module),
44 node(node)
45 {
46 const XMLAttribute* att = node->GetAttribute ( "name", true );
47 assert(att);
48
49 default_name = new FileLocation ( IntermediateDirectory,
50 module ? module->output->relative_path : "",
51 att->value,
52 node );
53 name = module->output->relative_path + cSep + att->value;
54 }
55
56 CompilationUnit::~CompilationUnit ()
57 {
58 size_t i;
59 for ( i = 0; i < files.size (); i++ )
60 delete files[i];
61
62 delete default_name;
63 }
64
65 void
66 CompilationUnit::ProcessXML ()
67 {
68 size_t i;
69 for ( i = 0; i < files.size (); i++ )
70 const_cast<File*> ( files[i] )->ProcessXML ();
71 }
72
73 bool
74 CompilationUnit::IsGeneratedFile () const
75 {
76 if ( files.size () != 1 )
77 return false;
78 const File* file = files[0];
79 string extension = GetExtension ( file->file );
80 return ( extension == ".spec" || extension == ".SPEC" || extension == ".mc" || extension == ".MC");
81 }
82
83 bool
84 CompilationUnit::HasFileWithExtension ( const std::string& extension ) const
85 {
86 size_t i;
87 for ( i = 0; i < files.size (); i++ )
88 {
89 const File& file = *files[i];
90 string fileExtension = GetExtension ( file.file );
91 if ( !stricmp ( fileExtension.c_str (), extension.c_str () ) )
92 return true;
93 }
94 return false;
95 }
96
97 bool
98 CompilationUnit::IsFirstFile () const
99 {
100 if ( files.size () == 0 || files.size () > 1 )
101 return false;
102 const File* file = files[0];
103 return file->first;
104 }
105
106
107 const FileLocation&
108 CompilationUnit::GetFilename () const
109 {
110 if ( files.size () == 0 || files.size () > 1 )
111 return *default_name;
112
113 const File* file = files[0];
114 return file->file;
115 }
116
117 const std::string&
118 CompilationUnit::GetSwitches () const
119 {
120 static const std::string empty_string = std::string("");
121 if ( files.size () == 0 || files.size () > 1 )
122 return empty_string;
123 const File* file = files[0];
124 return file->switches;
125 }
126
127 void
128 CompilationUnit::AddFile ( const File * file )
129 {
130 files.push_back ( file );
131 }
132
133 const std::vector<const File*>
134 CompilationUnit::GetFiles () const
135 {
136 return files;
137 }