Subversion Repositories gelsvn

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 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 68 2005-08-24 13:26:10Z 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
  ## Project Configurations
167
  print $fh "Global$crlf" .
168
            "\tGlobalSection(SolutionConfiguration) = preSolution$crlf";
169
 
170
  my(%configs) = ();
171
  foreach my $project (@list) {
172
    my($name, $deps, $pguid, @cfgs) = @{$$pjs{$project}};
173
    foreach my $cfg (@cfgs) {
174
      $cfg =~ s/\|.*//;
175
      $configs{$cfg} = 1;
176
    }
177
  }
178
  $self->print_configs($fh, \%configs);
179
  print $fh "\tEndGlobalSection$crlf";
180
 
181
  ## Print dependencies if there are any
182
  $self->print_dependencies($fh, $gen, \@list, $pjs);
183
 
184
  ## Project Configuration Names
185
  print $fh "\tGlobalSection(ProjectConfiguration) = postSolution$crlf";
186
  foreach my $project (@list) {
187
    my($name, $deps, $pguid, @cfgs) = @{$$pjs{$project}};
188
    foreach my $cfg (sort @cfgs) {
189
      my($c) = $cfg;
190
      $c =~ s/\|.*//;
191
      print $fh "\t\t{$pguid}.$c.ActiveCfg = $cfg$crlf" .
192
                "\t\t{$pguid}.$c.Build.0 = $cfg$crlf";
193
    }
194
  }
195
  print $fh "\tEndGlobalSection$crlf" .
196
            "\tGlobalSection(ExtensibilityGlobals) = postSolution$crlf" .
197
            "\tEndGlobalSection$crlf" .
198
            "\tGlobalSection(ExtensibilityAddIns) = postSolution$crlf" .
199
            "\tEndGlobalSection$crlf" .
200
            "EndGlobal$crlf";
201
}
202
 
203
 
204
sub add_references {
205
  my($self)   = shift;
206
  my($proj)   = shift;
207
  my($pguid)  = shift;
208
  my($deps)   = shift;
209
  my($gmap)   = shift;
210
  my($crlf)   = $self->crlf();
211
  my($fh)     = new FileHandle();
212
  my($outdir) = $self->get_outdir();
213
 
214
  if (open($fh, "$outdir/$proj")) {
215
    my($write) = 0;
216
    my(@read)  = ();
217
    while(<$fh>) {
218
      if (/MPC\s+ADD\s+REFERENCES/) {
219
        $write = 1;
220
        my($darr) = $self->create_array($deps);
221
        foreach my $dep (@$darr) {
222
          push(@read, "                <Reference$crlf",
223
                      "                    Name = \"$dep\"$crlf",
224
                      "                    Project = \"{$$gmap{$dep}}\"$crlf",
225
                      "                    Package = \"{$pguid}\"$crlf",
226
                      "                />$crlf");
227
        }
228
      }
229
      else {
230
        push(@read, $_);
231
      }
232
    }
233
    close($fh);
234
 
235
    if ($write && open($fh, ">$outdir/$proj")) {
236
      foreach my $line (@read) {
237
        print $fh $line;
238
      }
239
      close($fh);
240
    }
241
  }
242
}
243
 
244
 
245
1;