Wed Jun 9 07:35:19 UTC 2010 Johnny Willemsen <jwillemsen@remedy.nl>
[MPC.git] / modules / VC8WorkspaceCreator.pm
blob1291e831389ee261850e62827206a3d8ca8d596f
1 package VC8WorkspaceCreator;
3 # ************************************************************
4 # Description : A VC8 Workspace Creator
5 # Author : Johnny Willemsen
6 # Create Date : 4/21/2004
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use VC8ProjectCreator;
16 use VC71WorkspaceCreator;
18 use vars qw(@ISA);
19 @ISA = qw(VC71WorkspaceCreator);
21 # ************************************************************
22 # Data Section
23 # ************************************************************
25 my %lang_map = (Creator::cplusplus => 'Visual C#',
26 Creator::csharp => 'Visual C#',
27 Creator::vb => 'Visual Basic',
28 Creator::java => 'Visual J#');
30 # ************************************************************
31 # Subroutine Section
32 # ************************************************************
34 sub pre_workspace {
35 my($self, $fh) = @_;
36 my $crlf = $self->crlf();
38 ## This identifies it as a Visual Studio 2005 file
39 print $fh '', $crlf,
40 'Microsoft Visual Studio Solution File, Format Version 9.00', $crlf;
42 ## Optionally print the workspace comment
43 $self->print_workspace_comment($fh,
44 '# Visual Studio 2005', $crlf,
45 '# $Id$', $crlf,
46 '#', $crlf,
47 '# This file was generated by MPC. Any changes made directly to', $crlf,
48 '# this file will be lost the next time it is generated.', $crlf,
49 '#', $crlf,
50 '# MPC Command:', $crlf,
51 '# ', $self->create_command_line_string($0, @ARGV), $crlf);
54 sub post_workspace {
55 my($self, $fh, $creator) = @_;
56 my $pjs = $self->get_project_info();
57 my @projects = $self->sort_dependencies($self->get_projects(), 0);
58 my %gmap;
60 ## Store a map of the project name to project guid and whether or not
61 ## it is suitable to be referenced. Adding a reference to a
62 ## non-managed c++ library or a "utility" project causes a warning in
63 ## Visual Studio 2008 and higher.
64 foreach my $project (@projects) {
65 my($name, $deps, $guid, $lang, $custom_only, $nocross, $managed) = @{$$pjs{$project}};
66 $gmap{$name} = [$guid, !$custom_only && ($managed ||
67 $lang ne Creator::cplusplus)];
70 ## Now go through the projects and check for the need to add external
71 ## references.
72 foreach my $project (@projects) {
73 my $ph = new FileHandle();
74 my $outdir = $self->get_outdir();
75 $outdir = $self->getcwd() if ($outdir eq '.');
76 if (open($ph, "$outdir/$project")) {
77 my $write;
78 my @read;
79 my $crlf = $self->crlf();
80 my $cwd = $self->getcwd();
81 my $lang = $$pjs{$project}->[3];
82 my $managed = $$pjs{$project}->[6];
84 while(<$ph>) {
85 ## This is a comment found in vc8.mpd if the project contains the
86 ## 'after' keyword setting and the 'add_references' template
87 ## variable setting.
88 if (/^(\s*)<!\-\-\s+MPC\s+ADD\s+DEPENDENCIES/) {
89 my $spc = $1;
90 my $deps = $self->get_validated_ordering($project);
91 foreach my $dep (@$deps) {
92 my $relative = $self->get_relative_dep_file($creator,
93 "$cwd/$project",
94 $dep);
95 if (defined $relative) {
96 if ($lang eq Creator::cplusplus) {
97 ## If the current project is not managed, then we will
98 ## add references (although I doubt that will be useful).
99 ## If the current project is managed, then the reference
100 ## project must be managed or a non-c++ project.
101 if (!$managed || ($managed && $gmap{$dep}->[1])) {
102 ## See if the dependency has an associated attribute.
103 ## If it does, split it into name value pairs for use in
104 ## the resulting generated XML.
105 my %attr;
106 my $attr = $creator->get_dependency_attribute($dep);
107 if (defined $attr) {
108 foreach my $a (split(',', $attr)) {
109 my @nvp = split('=', $a);
110 $attr{lc($nvp[0])} = $nvp[1]if (defined $nvp[0] &&
111 defined $nvp[1]);
115 push(@read, $spc . '<ProjectReference' . $crlf .
116 $spc . "\tReferencedProjectIdentifier=" .
117 "\"\{$gmap{$dep}->[0]\}\"$crlf" .
118 (defined $attr{'copylocal'} ? $spc .
119 "\tCopyLocal=\"" . $attr{'copylocal'} . "\"$crlf" : '') .
120 $spc . "\tRelativePathToProject=\"$relative\"$crlf" .
121 $spc . '/>' . $crlf);
124 ## This is a non-c++ language. So, it should not reference
125 ## unmanaged c++ libraries. If it's a managed project or
126 ## it's not a c++ project, it's ok to add a reference.
127 elsif ($gmap{$dep}->[1]) {
128 push(@read, $spc . '<ProjectReference Include="' .
129 $relative . '">' . $crlf,
130 $spc . ' <Project>{' . $gmap{$dep}->[0] .
131 '}</Project>' . $crlf,
132 $spc . ' <Name>' . $dep . '</Name>' . $crlf,
133 $spc . '</ProjectReference>' . $crlf);
136 ## Indicate that we need to re-write the file
137 $write = 1;
140 last if (!$write);
142 else {
143 push(@read, $_);
146 close($ph);
148 ## If we need to re-write the file, then do so
149 if ($write && open($ph, ">$outdir/$project")) {
150 foreach my $line (@read) {
151 print $ph $line;
153 close($ph);
159 sub adjust_names {
160 my($self, $name, $proj, $lang) = @_;
162 ## For websites, the project needs to be the directory of the actual
163 ## project file with a trailing slash. The name needs a trailing slash
164 ## too.
165 if ($lang eq Creator::website) {
166 $proj = $self->mpc_dirname($proj);
167 $proj .= '\\';
168 $name .= '\\';
171 ## This always needs to be a path with the Windows style directory
172 ## separator.
173 $proj =~ s/\//\\/g;
174 return $name, $proj;
177 sub get_short_config_name {
178 #my($self, $cfg) = @_;
179 return $_[1];
182 sub get_solution_config_section_name {
183 #my $self = shift;
184 return 'SolutionConfigurationPlatforms';
187 sub get_project_config_section_name {
188 #my $self = shift;
189 return 'ProjectConfigurationPlatforms';
192 sub print_additional_sections {
193 my($self, $fh) = @_;
194 my $crlf = $self->crlf();
196 print $fh "\tGlobalSection(SolutionProperties) = preSolution$crlf",
197 "\t\tHideSolutionNode = FALSE$crlf",
198 "\tEndGlobalSection$crlf";
201 sub allow_empty_dependencies {
202 #my $self = shift;
203 return 0;
206 sub print_inner_project {
207 my($self, $fh, $gen, $currguid, $deps, $name, $name_to_guid_map, $proj_language, $cfgs) = @_;
209 ## We need to perform a lot of work, but only for websites.
210 if ($proj_language eq Creator::website) {
211 my $crlf = $self->crlf();
212 my $directory = ($name eq '.\\' ?
213 $self->get_workspace_name() . '\\' : $name);
215 ## We need the directory name with no trailing back-slash for use
216 ## below.
217 my $notrail = $directory;
218 $notrail =~ s/\\$//;
220 # Print the website project.
221 print $fh "\tProjectSection(WebsiteProperties) = preProject", $crlf;
223 ## Print out the references
224 my $references;
225 foreach my $dep (@$deps) {
226 if (defined $$name_to_guid_map{$dep}) {
227 $references = "\t\t" .
228 'ProjectReferences = "' if (!defined $references);
229 $references .= "{$$name_to_guid_map{$dep}}|$dep;";
232 print $fh $references, '"', $crlf if (defined $references);
234 ## And now the configurations
235 my %cfg_seen;
236 foreach my $config (@$cfgs) {
237 $config =~ s/\|.*//;
238 if (!$cfg_seen{$config}) {
239 print $fh "\t\t$config.AspNetCompiler.VirtualPath = \"/$notrail\"", $crlf,
240 "\t\t$config.AspNetCompiler.PhysicalPath = \"$directory\"", $crlf,
241 "\t\t$config.AspNetCompiler.TargetPath = \"PrecompiledWeb\\$directory\"", $crlf,
242 "\t\t$config.AspNetCompiler.Updateable = \"true\"", $crlf,
243 "\t\t$config.AspNetCompiler.ForceOverwrite = \"true\"", $crlf,
244 "\t\t$config.AspNetCompiler.FixedNames = \"true\"", $crlf,
245 "\t\t$config.AspNetCompiler.Debug = \"",
246 ($config =~ /debug/i ? 'True' : 'False'), "\"", $crlf;
247 $cfg_seen{$config} = 1;
250 print $fh "\t\tVWDPort = \"1573\"", $crlf,
251 "\t\tDefaultWebSiteLanguage = \"",
252 $lang_map{$self->get_language()}, "\"", $crlf,
253 "\tEndProjectSection", $crlf;
255 else {
256 # We can ignore this project and pass it to the
257 # SUPER since it's not a website.
258 $self->SUPER::print_inner_project($fh, $gen, $currguid, $deps,
259 $name, $name_to_guid_map);