Wed Jun 9 07:35:19 UTC 2010 Johnny Willemsen <jwillemsen@remedy.nl>
[MPC.git] / modules / WB26WorkspaceCreator.pm
blob63ec046ca71e195027707e96daf7fcbde1e64038
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 pre_workspace {
41 my($self, $fh) = @_;
42 my $crlf = $self->crlf();
44 ## Optionally print the workspace comment
45 $self->print_workspace_comment($fh,
46 '#----------------------------------------------------------------------------', $crlf,
47 '# WindRiver Workbench generator', $crlf,
48 '#', $crlf,
49 '# $Id$', $crlf,
50 '#', $crlf,
51 '# This file was generated by MPC. Any changes made directly to', $crlf,
52 '# this file will be lost the next time it is generated.', $crlf,
53 '# This file should be placed in the .metadata\.plugins\org.eclipse.core.runtime\.settings directory', $crlf,
54 '#', $crlf,
55 '# MPC Command:', $crlf,
56 "# $0 @ARGV", $crlf,
57 '#----------------------------------------------------------------------------', $crlf);
59 ## Unchanging initial settings
60 print $fh 'version=1', $crlf,
61 'eclipse.preferences.version=1', $crlf,
62 'description.defaultbuildorder=false', $crlf;
65 sub write_comps {
66 my($self, $fh) = @_;
67 my $pjs = $self->get_project_info();
68 my @list = $self->sort_dependencies($self->get_projects(), 0);
70 ## Print out the target
71 print $fh 'description.buildorder=';
72 foreach my $project (@list) {
73 print $fh "$$pjs{$project}->[0]/";
75 print $fh $self->crlf();
78 sub post_workspace {
79 my($self, $fh, $creator) = @_;
80 my $crlf = $self->crlf();
82 ## Clear out the seen dependency hash for use within the
83 ## add_dependencies method.
84 $self->{'seen_deps'} = {};
86 ## Print out the project dependencies
87 foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
88 print $fh "$project$crlf";
89 $self->add_dependencies($creator, $project);
93 sub get_additional_output {
94 ## Create the accompanying list file. It always goes in the same
95 ## directory as the first workspace output file. See
96 ## WorkspaceCreator.pm for a description of the array elements.
97 return [[undef, 'wb26projects.lst', \&list_file_body]];
100 sub list_file_body {
101 my($self, $fh) = @_;
102 my $crlf = $self->crlf();
104 ## Optionally print the workspace comment
105 $self->print_workspace_comment($fh,
106 '#----------------------------------------------------------------------------', $crlf,
107 '# WindRiver Workbench generator', $crlf,
108 '#', $crlf,
109 '# $Id$', $crlf,
110 '#', $crlf,
111 '# This file was generated by MPC. Any changes made directly to', $crlf,
112 '# this file will be lost the next time it is generated.', $crlf,
113 '# MPC Command:', $crlf,
114 "# $0 @ARGV", $crlf,
115 '#----------------------------------------------------------------------------', $crlf);
117 ## Print out each target separately
118 foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
119 print $fh Cwd::abs_path($self->mpc_dirname($project)), '/.project', $crlf;
123 sub add_dependencies {
124 my($self, $creator, $proj) = @_;
125 my $outdir = $self->mpc_dirname($proj);
127 ## These values will be changed after the first time through the for
128 ## loop below.
129 my $pre = "\t\t" . '<project>';
130 my $post = '</project>';
131 my $outfile = $outdir . '/.project';
133 ## Go through twice to edit both the .project and .wrproject files
134 for(my $i = 0; $i < 2; $i++) {
135 my $fh = new FileHandle();
136 if (open($fh, $outfile)) {
137 ## Get the dependencies and store them based on the directory of
138 ## the project file. We will check them later.
139 my $deps = $self->get_validated_ordering($proj);
140 my $key = $self->mpc_basename($self->mpc_dirname($proj));
141 $self->{'seen_deps'}->{$key} = {};
142 foreach my $dep (@$deps) {
143 $self->{'seen_deps'}->{$key}->{$dep} = 1;
146 my @read = ();
147 my $cwd = $self->getcwd();
148 while(<$fh>) {
149 ## This is a comment found in wb26.mpd and wb26wrproject.mpd if
150 ## the project is an executable, contains the 'after' keyword
151 ## setting, and the 'enable_subprojects' template variable.
152 if (/MPC\s+ADD\s+DEPENDENCIES/) {
153 my $crlf = $self->crlf();
154 my %seen = ();
155 my @lines;
156 foreach my $dep (reverse @$deps) {
157 ## If we've seen this dependency, we don't need to add it
158 ## again. The build tool will handle it correctly.
159 if (!$seen{$dep}) {
160 my $relative = $self->get_relative_dep_file($creator,
161 "$cwd/$proj", $dep);
162 ## Since we're looking at the dependencies in reverse order
163 ## now, we need to unshift them into another array to keep
164 ## the correct order.
165 unshift(@lines, "$pre$dep$post$crlf") if (defined $relative);
167 ## We've now seen this dependency and all of the
168 ## projects upon which this one depends.
169 $seen{$dep} = 1;
170 foreach my $key (keys %{$self->{'seen_deps'}->{$dep}}) {
171 $seen{$key} = 1;
176 ## Add the dependency lines to the project file
177 push(@read, @lines);
179 else {
180 push(@read, $_);
183 close($fh);
185 ## We will always rewrite the project file (with or without
186 ## dependencies).
187 if (open($fh, ">$outfile")) {
188 foreach my $line (@read) {
189 print $fh $line;
191 close($fh);
195 ## The dependencies need to go into the .wrproject too, so transform
196 ## the name and the pre and post values.
197 $outfile = $outdir . '/.wrproject';
198 $pre = ' <subproject project="/';
199 $post = '"/>';