Subversion Repositories gelsvn

Rev

Rev 107 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
package VC7WorkspaceCreator;
2
 
3
# ************************************************************
4
# Description   : A VC7 Workspace Creator
5
# Author        : Chad Elliott
6
# Create Date   : 5/14/2002
7
# ************************************************************
8
 
9
# ************************************************************
10
# Pragmas
11
# ************************************************************
12
 
13
use strict;
14
 
15
use VC7ProjectCreator;
16
use WorkspaceCreator;
17
 
18
use vars qw(@ISA);
19
@ISA = qw(WorkspaceCreator);
20
 
21
# ************************************************************
22
# Data Section
23
# ************************************************************
24
 
25
my(%guids) = ('cplusplus' => '8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942',
26
              'csharp'    => 'FAE04EC0-301F-11D3-BF4B-00C04F79EFBC',
27
              'vb'        => 'F184B08F-C81C-45F6-A57F-5ABD9991F28F',
28
             );
29
 
30
# ************************************************************
31
# Subroutine Section
32
# ************************************************************
33
 
34
sub compare_output {
35
  #my($self) = shift;
36
  return 1;
37
}
38
 
39
 
40
sub crlf {
41
  my($self) = shift;
42
  return $self->windows_crlf();
43
}
44
 
45
 
46
sub workspace_file_name {
47
  my($self) = shift;
48
  return $self->get_modified_workspace_name($self->get_workspace_name(),
49
                                            '.sln');
50
}
51
 
52
 
53
sub pre_workspace {
54
  my($self) = shift;
55
  my($fh)   = shift;
56
  my($crlf) = $self->crlf();
57
 
58
  print $fh 'Microsoft Visual Studio Solution File, Format Version 7.00', $crlf,
59
            '#', $crlf,
60
            '# $Id: VC7WorkspaceCreator.pm 107 2005-09-02 16:42:23Z bj $', $crlf,
61
            '#', $crlf,
62
            '# This file was generated by MPC.  Any changes made directly to', $crlf,
63
            '# this file will be lost the next time it is generated.', $crlf,
64
            '#', $crlf,
65
            '# MPC Command:', $crlf,
66
            "# $0 @ARGV", $crlf;
67
}
68
 
69
 
70
sub print_inner_project {
71
  #my($self)  = shift;
72
  #my($fh)    = shift;
73
  #my($gen)   = shift;
74
  #my($pguid) = shift;
75
  #my($deps)  = shift;
76
  #my($name)  = shift;
77
}
78
 
79
 
80
sub print_configs {
81
  my($self)    = shift;
82
  my($fh)      = shift;
83
  my($configs) = shift;
84
  my($crlf)    = $self->crlf();
85
  my($count)   = 0;
86
 
87
  foreach my $key (sort keys %$configs) {
88
    print $fh "\t\tConfigName.$count = $key$crlf";
89
    $count++;
90
  }
91
}
92
 
93
 
94
sub print_dependencies {
95
  my($self) = shift;
96
  my($fh)   = shift;
97
  my($gen)  = shift;
98
  my($list) = shift;
99
  my($pjs)  = shift;
100
  my($crlf) = $self->crlf();
101
 
102
  ## I hate to add yet another loop through all the projects, but
103
  ## we must have some way to map plain project names to guids.
104
  my(%name_to_guid_map) = ();
105
  foreach my $project (@$list) {
106
    my($name, $deps, $guid) = @{$$pjs{$project}};
107
    $name_to_guid_map{$name} = $guid;
108
  }
109
 
110
  ## Project Dependencies
111
  print $fh "\tGlobalSection(ProjectDependencies) = postSolution$crlf";
112
  foreach my $project (@$list) {
113
    my($name, $rawdeps, $project_guid) = @{$$pjs{$project}};
114
    my($deps) = $self->get_validated_ordering($project);
115
    if (defined $deps && $deps ne '') {
116
      my($darr) = $self->create_array($deps);
117
      my($i)    = 0;
118
      foreach my $dep (@$darr) {
119
        my($guid) = $name_to_guid_map{$dep};
120
        if (defined $guid && $guid ne $project_guid) {
121
          print $fh "\t\t{$project_guid}.$i = {$guid}$crlf";
122
          $i++;
123
        }
124
      }
125
    }
126
  }
127
  print $fh "\tEndGlobalSection$crlf";
128
}
129
 
130
 
131
sub write_comps {
132
  my($self)     = shift;
133
  my($fh)       = shift;
134
  my($gen)      = shift;
135
  my($projects) = $self->get_projects();
136
  my($language) = $self->get_language();
137
  my($vc7guid)  = $guids{$language};
138
  my($pjs)      = $self->get_project_info();
139
  my(@list)     = sort @$projects;
140
  my($crlf)     = $self->crlf();
141
 
142
  ## I hate to add yet another loop through all the projects, but
143
  ## we must have some way to map plain project names to guids.
144
  my(%name_to_guid_map) = ();
145
  foreach my $project (@list) {
146
    my($name, $deps, $guid) = @{$$pjs{$project}};
147
    $name_to_guid_map{$name} = $guid;
148
  }
149
 
150
  ## Project Information
151
  foreach my $project (@list) {
152
    my($name, $rawdeps, $guid) = @{$$pjs{$project}};
153
    my($deps) = $self->get_validated_ordering($project);
154
    ## Convert all /'s to \
155
    my($cpy) = $self->slash_to_backslash($project);
156
    print $fh "Project(\"{$vc7guid}\") = \"$name\", \"$cpy\", \"{$guid}\"$crlf";
157
    $self->print_inner_project($fh, $gen, $guid, $deps, $name, \%name_to_guid_map);
158
    print $fh "EndProject$crlf";
159
 
160
    if ($deps ne '' &&
161
        ($language eq 'csharp' || $language eq 'vb')) {
162
      $self->add_references($project, $vc7guid, $deps, \%name_to_guid_map);
163
    }
164
  }
165
 
166
  print $fh "Global$crlf",
167
            "\tGlobalSection(",
168
            $self->get_solution_config_section_name(),
169
            ") = preSolution$crlf";
170
 
171
  my(%configs) = ();
172
  foreach my $project (@list) {
173
    my($name, $deps, $pguid, @cfgs) = @{$$pjs{$project}};
174
    foreach my $cfg (@cfgs) {
175
      $cfg = $self->get_short_config_name($cfg);
176
      $configs{$cfg} = 1;
177
    }
178
  }
179
  $self->print_configs($fh, \%configs);
180
  print $fh "\tEndGlobalSection$crlf";
181
 
182
  ## Print dependencies if there are any
183
  $self->print_dependencies($fh, $gen, \@list, $pjs);
184
 
185
  ## Project Configuration Names
186
  print $fh "\tGlobalSection(",
187
            $self->get_project_config_section_name(),
188
            ") = postSolution$crlf";
189
 
190
  foreach my $project (@list) {
191
    my($name, $deps, $pguid, @cfgs) = @{$$pjs{$project}};
192
    foreach my $cfg (sort @cfgs) {
193
      my($c) = $self->get_short_config_name($cfg);
194
      print $fh "\t\t{$pguid}.$c.ActiveCfg = $cfg$crlf" .
195
                "\t\t{$pguid}.$c.Build.0 = $cfg$crlf";
196
    }
197
  }
198
  print $fh "\tEndGlobalSection$crlf";
199
 
200
  $self->print_additional_sections($fh);
201
 
202
  print $fh "EndGlobal$crlf";
203
}
204
 
205
 
206
sub get_short_config_name {
207
  my($self) = shift;
208
  my($cfg)  = shift;
209
  $cfg =~ s/\|.*//;
210
  return $cfg;
211
}
212
 
213
 
214
sub get_solution_config_section_name {
215
  #my($self) = shift;
216
  return 'SolutionConfiguration';
217
}
218
 
219
 
220
sub get_project_config_section_name {
221
  #my($self) = shift;
222
  return 'ProjectConfiguration';
223
}
224
 
225
 
226
sub print_additional_sections {
227
  my($self) = shift;
228
  my($fh)   = shift;
229
  my($crlf) = $self->crlf();
230
 
231
  print $fh "\tGlobalSection(ExtensibilityGlobals) = postSolution$crlf",
232
            "\tEndGlobalSection$crlf",
233
            "\tGlobalSection(ExtensibilityAddIns) = postSolution$crlf",
234
            "\tEndGlobalSection$crlf";
235
}
236
 
237
 
238
sub add_references {
239
  my($self)   = shift;
240
  my($proj)   = shift;
241
  my($pguid)  = shift;
242
  my($deps)   = shift;
243
  my($gmap)   = shift;
244
  my($crlf)   = $self->crlf();
245
  my($fh)     = new FileHandle();
246
  my($outdir) = $self->get_outdir();
247
 
248
  if (open($fh, "$outdir/$proj")) {
249
    my($write) = 0;
250
    my(@read)  = ();
251
    while(<$fh>) {
252
      if (/MPC\s+ADD\s+REFERENCES/) {
253
        $write = 1;
254
        my($darr) = $self->create_array($deps);
255
        foreach my $dep (@$darr) {
256
          push(@read, "                <Reference$crlf",
257
                      "                    Name = \"$dep\"$crlf",
258
                      "                    Project = \"{$$gmap{$dep}}\"$crlf",
259
                      "                    Package = \"{$pguid}\"$crlf",
260
                      "                />$crlf");
261
        }
262
      }
263
      else {
264
        push(@read, $_);
265
      }
266
    }
267
    close($fh);
268
 
269
    if ($write && open($fh, ">$outdir/$proj")) {
270
      foreach my $line (@read) {
271
        print $fh $line;
272
      }
273
      close($fh);
274
    }
275
  }
276
}
277
 
278
 
279
1;