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