Whitespace changes
[MPC.git] / modules / WB26WorkspaceCreator.pm
blobd60a8bf34c02f08df2a81c0fec5a4c4fe82a5a30
1 package WB26WorkspaceCreator;
3 # ************************************************************
4 # Description : Workbench 2.6 / VxWorks 6.4 generator
5 # Author : Johnny Willemsen
6 # Create Date : 07/01/2008
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use WB26ProjectCreator;
16 use WorkspaceCreator;
18 use vars qw(@ISA);
19 @ISA = qw(WorkspaceCreator);
21 # ************************************************************
22 # Subroutine Section
23 # ************************************************************
25 sub requires_make_coexistence {
26 #my $self = shift;
27 return 1;
30 sub supports_make_coexistence {
31 #my $self = shift;
32 return 1;
35 sub workspace_file_name {
36 #my $self = shift;
37 return 'org.eclipse.core.resources.prefs';
40 sub get_project_prefix {
41 return '';
44 sub pre_workspace {
45 my($self, $fh) = @_;
46 my $crlf = $self->crlf();
48 ## Optionally print the workspace comment
49 $self->print_workspace_comment($fh,
50 '#----------------------------------------------------------------------------', $crlf,
51 '# WindRiver Workbench generator', $crlf,
52 '#', $crlf,
53 '# This file was generated by MPC. Any changes made directly to', $crlf,
54 '# this file will be lost the next time it is generated.', $crlf,
55 '# This file should be placed in the .metadata/.plugins/org.eclipse.core.runtime/.settings directory', $crlf,
56 '#', $crlf,
57 '# MPC Command:', $crlf,
58 "# ", $self->create_command_line_string($0, @ARGV), $crlf,
59 '#----------------------------------------------------------------------------', $crlf);
61 ## Unchanging initial settings
62 print $fh 'version=1', $crlf,
63 'eclipse.preferences.version=1', $crlf,
64 'description.defaultbuildorder=false', $crlf;
67 sub write_comps {
68 my($self, $fh) = @_;
69 my $pjs = $self->get_project_info();
70 my @list = $self->sort_dependencies($self->get_projects(), 0);
71 my $pre = $self->get_project_prefix();
73 ## Print out the target
74 print $fh 'description.buildorder=';
75 foreach my $project (@list) {
76 print $fh $pre, $$pjs{$project}->[ProjectCreator::PROJECT_NAME], '/';
78 print $fh $self->crlf();
81 sub post_workspace {
82 my($self, $fh, $creator) = @_;
83 my $crlf = $self->crlf();
85 ## Clear out the seen dependency hash for use within the
86 ## add_dependencies method.
87 $self->{'seen_deps'} = {};
89 ## Print out the project dependencies
90 foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
91 print $fh "$project$crlf";
92 $self->add_dependencies($creator, $project);
96 sub get_additional_output {
97 ## Create the accompanying list file. It always goes in the same
98 ## directory as the first workspace output file. See
99 ## WorkspaceCreator.pm for a description of the array elements.
100 return [[undef, 'wb26projects.lst', \&list_file_body]];
103 sub list_file_body {
104 my($self, $fh) = @_;
105 my $crlf = $self->crlf();
107 ## Optionally print the workspace comment
108 $self->print_workspace_comment($fh,
109 '#----------------------------------------------------------------------------', $crlf,
110 '# WindRiver Workbench generator', $crlf,
111 '#', $crlf,
112 '# This file was generated by MPC. Any changes made directly to', $crlf,
113 '# this file will be lost the next time it is generated.', $crlf,
114 '# MPC Command:', $crlf,
115 "# ", $self->create_command_line_string($0, @ARGV), $crlf,
116 '#----------------------------------------------------------------------------', $crlf);
118 ## Print out each target separately
119 foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
120 print $fh $self->mpc_dirname($project), '/.project', $crlf;
124 sub add_dependencies {
125 my($self, $creator, $proj) = @_;
126 my $outdir = $self->mpc_dirname($proj);
127 my $into = $self->get_outdir();
128 $outdir = "$into/$outdir" if $into ne '.';
129 my $proj_pre = $self->get_project_prefix();
131 ## These values will be changed after the first time through the for
132 ## loop below.
133 my $pre = "\t\t" . '<project>';
134 my $post = '</project>';
135 my $outfile = $outdir . '/.project';
137 ## Go through twice to edit both the .project and .wrproject files
138 for(my $i = 0; $i < 2; $i++) {
139 my $fh = new FileHandle();
140 if (open($fh, $outfile)) {
141 ## Get the dependencies and store them based on the directory of
142 ## the project file. We will check them later.
143 my $deps = $self->get_validated_ordering($proj);
144 my $key = $self->mpc_basename($self->mpc_dirname($proj));
145 $self->{'seen_deps'}->{$key} = {};
146 foreach my $dep (@$deps) {
147 $self->{'seen_deps'}->{$key}->{$dep} = 1;
150 my @read = ();
151 my $cwd = $self->getcwd();
152 while(<$fh>) {
153 ## This is a comment found in wb26.mpd and wb26wrproject.mpd if
154 ## the project is an executable, contains the 'after' keyword
155 ## setting, and the 'enable_subprojects' template variable.
156 if (/MPC\s+ADD\s+DEPENDENCIES/) {
157 my $crlf = $self->crlf();
158 my %seen = ();
159 my @lines;
160 foreach my $dep (reverse @$deps) {
161 ## If we've seen this dependency, we don't need to add it
162 ## again. The build tool will handle it correctly.
163 if (!$seen{$dep}) {
164 my $relative = $self->get_relative_dep_file($creator,
165 "$cwd/$proj", $dep);
166 ## Since we're looking at the dependencies in reverse order
167 ## now, we need to unshift them into another array to keep
168 ## the correct order.
169 if (defined $relative) {
170 unshift(@lines, "$pre$proj_pre$dep$post$crlf");
173 ## We've now seen this dependency and all of the
174 ## projects upon which this one depends.
175 $seen{$dep} = 1;
176 foreach my $key (keys %{$self->{'seen_deps'}->{$dep}}) {
177 $seen{$key} = 1;
182 ## Add the dependency lines to the project file
183 push(@read, @lines);
185 else {
186 push(@read, $_);
189 close($fh);
191 ## We will always rewrite the project file (with or without
192 ## dependencies).
193 if (open($fh, ">$outfile")) {
194 foreach my $line (@read) {
195 print $fh $line;
197 close($fh);
201 ## The dependencies need to go into the .wrproject too, so transform
202 ## the name and the pre and post values.
203 $outfile = $outdir . '/.wrproject';
204 $pre = ' <subproject project="/';
205 $post = '"/>';