rakish 0.9.01.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,256 @@
1
+ module Rakish
2
+
3
+ # Module to generate VCProject files for ocmpiel C++ specified in this build
4
+ # Not really part of public distributioin - too littered with local stuff
5
+ # specific to my main builds This needs to be converted to work in a more configurable way
6
+ class VcprojBuilder
7
+ include Rakish::Util
8
+
9
+ @@rakefileConfigTxt_=<<EOTEXT
10
+ <?xml version="1.0" encoding="utf-8"?>
11
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
12
+ <ItemGroup Label="ProjectConfigurations">
13
+ \#{getVCX10RakefileConfigList(indent)}
14
+ </ItemGroup>
15
+ <PropertyGroup Label="Globals">
16
+ <ProjectGuid>{\#{projectUuid}}</ProjectGuid>
17
+ <Keyword>MakeFileProj</Keyword>
18
+ <ProjectName>\#{projectName}</ProjectName>
19
+ </PropertyGroup>
20
+ <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />
21
+ \#{getVCX10RakefileConfigTypes(indent)}
22
+ <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props" />
23
+ <ImportGroup Label="ExtensionSettings">
24
+ </ImportGroup>
25
+ \#{getVCX10RakefilePropertySheets(indent)}
26
+ <PropertyGroup Label="UserMacros" />
27
+ \#{getVCX10RakefileUserMacros(indent)}
28
+ <ItemDefinitionGroup>
29
+ </ItemDefinitionGroup>
30
+ \#{getVCX10FileGroups(indent)}
31
+ <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" />
32
+ <ImportGroup Label="ExtensionTargets">
33
+ </ImportGroup>
34
+ </Project>
35
+ EOTEXT
36
+
37
+ def addVCX10ProjectConfig(out,config)
38
+ out << "<ProjectConfiguration Include=\"#{config}|Win32\">";
39
+ out << " <Configuration>#{config}</Configuration>";
40
+ out << ' <Platform>Win32</Platform>';
41
+ out << '</ProjectConfiguration>';
42
+ end
43
+
44
+ def getVCX10RakefileConfigList(indent)
45
+ indent = "%#{indent}s" % "";
46
+ out = [];
47
+ eachConfig do |cfg|
48
+ addVCX10ProjectConfig(out,cfg.configName);
49
+ end
50
+ out.join("\n#{indent}");
51
+ end
52
+
53
+ def addVCX10ConfigTypeCondition(out, config)
54
+ out << "<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='#{config}|Win32'\" Label=\"Configuration\">";
55
+ out << ' <ConfigurationType>Makefile</ConfigurationType>';
56
+ out << ' <UseDebugLibraries>false</UseDebugLibraries>';
57
+ out << " <IntDir>#{cppProject.nativeObjectPath()}</IntDir>";
58
+ out << " <OutDir>#{cppProject.binDir()}</OutDir>";
59
+ out << '</PropertyGroup>';
60
+ end
61
+
62
+ def getVCX10RakefileConfigTypes(indent)
63
+ indent = "%#{indent}s" % "";
64
+ out = [];
65
+ eachConfig do |cfg|
66
+ addVCX10ConfigTypeCondition(out,cfg.configName);
67
+ end
68
+ out.join("\n#{indent}");
69
+ end
70
+
71
+ def addVCX10RakefileImportGroup(out, config)
72
+ out << "<ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='#{config}|Win32'\">";
73
+ out << ' <Import Project="$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props" Condition="exists(\'$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\')" Label="LocalAppDataPlatform" />';
74
+ out << '</ImportGroup>';
75
+ end
76
+
77
+ def getVCX10RakefilePropertySheets(indent)
78
+ indent = "%#{indent}s" % "";
79
+ out = [];
80
+ eachConfig do |cfg|
81
+ addVCX10RakefileImportGroup(out, cfg.configName );
82
+ end
83
+ out.join("\n#{indent}");
84
+ end
85
+
86
+ def addVCX10RakefileUserMacroGroup(out, cfg)
87
+
88
+ out << "<PropertyGroup Condition=\"'$(Configuration)|$(Platform)\'=='#{cfg.configName}|Win32'\">";
89
+ out << " <NMakeOutput>#{cppProject.moduleName}.exe</NMakeOutput>";
90
+
91
+ begin
92
+ cppdefs = '';
93
+ delim = '';
94
+ cfg.cppDefines.each do |k,v|
95
+ cppdefs += "#{delim}#{k}#{v ? '='+v : ''}"
96
+ delim =';';
97
+ end
98
+ out << " <NMakePreprocessorDefinitions>#{cppdefs}</NMakePreprocessorDefinitions>";
99
+ end
100
+
101
+ if(cfg.configName === 'Autogen')
102
+ out << " <NMakeBuildCommandLine>#{rakeCommandLine} autogen</NMakeBuildCommandLine>";
103
+ out << " <NMakeReBuildCommandLine>#{rakeCommandLine} autogenclean autogen</NMakeReBuildCommandLine>";
104
+ out << " <NMakeCleanCommandLine>#{rakeCommandLine} autogenclean</NMakeCleanCommandLine>";
105
+ else
106
+ out << " <NMakeBuildCommandLine>#{rakeCommandLine} build</NMakeBuildCommandLine>";
107
+ out << " <NMakeReBuildCommandLine>#{rakeCommandLine} rebuild</NMakeReBuildCommandLine>";
108
+ out << " <NMakeCleanCommandLine>#{rakeCommandLine} clean</NMakeCleanCommandLine>";
109
+ # note intellisense doesn't like relative include paths.
110
+ out << " <NMakeIncludeSearchPath>#{cfg.includePaths.join(';')}</NMakeIncludeSearchPath>";
111
+ end
112
+ out << '</PropertyGroup>';
113
+ end
114
+
115
+ def getVCX10RakefileUserMacros(indent)
116
+ indent = "%#{indent}s" % "";
117
+ out = [];
118
+ eachConfig do |cfg|
119
+ addVCX10RakefileUserMacroGroup(out, cfg );
120
+ end
121
+ out.join("\n#{indent}");
122
+ end
123
+
124
+ def vcprojRelative(f)
125
+ getWindowsRelativePath(f,cppProject.vcprojDir);
126
+ end
127
+
128
+ def getVCX10FileGroups(indent)
129
+ indent = "%#{indent}s" % "";
130
+ out = []
131
+ files = cppProject.getSourceFiles();
132
+ unless(files.empty?)
133
+ out << '<ItemGroup>';
134
+ files.each do |f|
135
+ out << " <ClCompile Include=\"#{vcprojRelative(f)}\" />";
136
+ end
137
+ out << '</ItemGroup>';
138
+ end
139
+
140
+ files = cppProject.getIncludeFiles();
141
+ unless(files.empty?)
142
+ out << '<ItemGroup>';
143
+ files.each do |f|
144
+ out << " <ClInclude Include=\"#{vcprojRelative(f)}\" />";
145
+ end
146
+ out << '</ItemGroup>';
147
+ end
148
+ out << '<ItemGroup>';
149
+ out << " <None Include=\"#{vcprojRelative(cppProject.projectFile)}\" />";
150
+ out << '</ItemGroup>';
151
+ out.join("\n#{indent}");
152
+ end
153
+
154
+
155
+ def eachConfig(&b)
156
+ [
157
+ "Win32-VC10-MD-Debug",
158
+ "Win32-VC10-MDd-Debug",
159
+ "Win32-VC10-MT-Debug",
160
+ "Win32-VC10-MTd-Debug",
161
+ "Win32-VC10-MD-Release",
162
+ "Win32-VC10-MT-Release"
163
+ ].each do |cfg|
164
+ cfg = cppProject.resolveConfiguration(cfg);
165
+ next unless cfg
166
+ yield(cfg);
167
+ end
168
+ end
169
+
170
+
171
+ @@rakefileFiltersTxt_=<<EOTEXT
172
+ <?xml version="1.0" encoding="utf-8"?>
173
+ <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
174
+ <ItemGroup>
175
+ <Filter Include="Source Files">
176
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
177
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
178
+ </Filter>
179
+ <Filter Include="Header Files">
180
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
181
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
182
+ </Filter>
183
+ <Filter Include="Resource Files">
184
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
185
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
186
+ </Filter>
187
+ </ItemGroup>
188
+ <ItemGroup>
189
+ </ItemGroup>
190
+ </Project>
191
+ EOTEXT
192
+
193
+ attr_reader :cppProject
194
+ attr_reader :rakeCommandLine
195
+
196
+ def writeRakefileVCProj(file)
197
+ indent = "";
198
+ proj = cppProject;
199
+ projectUuid = proj.projectId;
200
+ projectName = proj.moduleName;
201
+
202
+ rakeCommand = vcprojRelative(File.join(proj.thirdPartyPath,'tools/exec-rake.bat'));
203
+ rakeFile = vcprojRelative(proj.projectFile);
204
+
205
+ @rakeCommandLine = "#{rakeCommand} -f #{rakeFile} \"RakishBuildRoot=$(SolutionDir)build\"";
206
+
207
+ rubyLinePP(@@rakefileConfigTxt_,file,binding());
208
+ end
209
+
210
+ def writeRakefileVCProjFilters(file)
211
+ rubyLinePP(@@rakefileFiltersTxt_,file,binding());
212
+ end
213
+
214
+ def writeVCProjFiles(proj)
215
+ @cppProject = proj;
216
+
217
+ defpath = File.join(proj.vcprojDir, proj.moduleName + '-rake.vcxproj');
218
+ filpath = "#{defpath}.filters"
219
+ tempPath = File.join(proj.vcprojDir, proj.moduleName + '.temp');
220
+
221
+ puts(" creating vcproj in #{defpath}")
222
+ begin
223
+ File.open(tempPath,'w') do |f|
224
+ writeRakefileVCProj(f);
225
+ end
226
+ if(textFilesDiffer(tempPath,defpath))
227
+ mv(tempPath, defpath);
228
+ end
229
+ File.open(tempPath,'w') do |f|
230
+ writeRakefileVCProjFilters(f);
231
+ end
232
+ if(textFilesDiffer(tempPath,filpath))
233
+ mv(tempPath, filpath);
234
+ end
235
+ rescue => exception
236
+ puts exception
237
+ # exception.backtrace
238
+ end
239
+ rm_f(tempPath);
240
+
241
+ end
242
+
243
+ def VcprojBuilder.onVcprojTask(proj)
244
+ builder = VcprojBuilder.new # do
245
+ builder.writeVCProjFiles(proj);
246
+ end
247
+
248
+ def VcprojBuilder.onVcprojCleanTask(proj)
249
+ defpath = File.join(proj.vcprojDir, proj.moduleName + '-rake.vcxproj');
250
+ filpath = "#{defpath}.filters";
251
+ proj.addCleanFiles(defpath,filpath);
252
+ end
253
+
254
+ end
255
+
256
+ end # Rakish