Update bmakecommon.mpt
[MPC.git] / modules / CDT6WorkspaceCreator.pm
blobf3ed42782dca1782342faf8947b785985c614d99
1 package CDT6WorkspaceCreator;
3 # ************************************************************
4 # Description : Eclipse CDT 6 generator
5 # Author : Chris Cleeland, Object Computing, Inc.
6 # Create Date : 23-Apr-2010
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use CDT6ProjectCreator;
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 my $wsn = $self->get_workspace_name();
38 return $self->get_modified_workspace_name("cdt_workspace_$wsn", '.txt');
41 sub pre_workspace {
42 my($self, $fh) = @_;
43 my $crlf = $self->crlf();
45 ## Optionally print the workspace comment
46 $self->print_workspace_comment($fh,
47 '#----------------------------------------------------------------------------', $crlf,
48 '# Eclipse CDT ', $self->get_cdt_version(), ' generator', $crlf,
49 '#', $crlf,
50 '# This file was generated by MPC. Any changes made directly to', $crlf,
51 '# this file will be lost the next time it is generated.', $crlf,
52 '# Listed below are the Eclipse projects created for this MPC workspace.', $crlf,
53 '# These should be imported into an existing Eclipse workspace.', $crlf,
54 '# Each project is listed on a line consisting of the project name and the full', $crlf,
55 '# path to its .project file (space-separated).', $crlf,
56 '# The projects are listed in dependency order.', $crlf,
57 '#', $crlf,
58 '# MPC Command:', $crlf,
59 '# ', $self->create_command_line_string($0, @ARGV), $crlf,
60 '#----------------------------------------------------------------------------', $crlf);
63 sub get_cdt_version {
64 return '6';
67 sub write_comps {
68 my($self, $fh, $creator) = @_;
69 my $info = $self->get_project_info();
70 my $crlf = $self->crlf();
71 $self->{'seen_deps'} = {};
73 foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
74 print $fh $$info{$project}->[ProjectCreator::PROJECT_NAME], ' ',
75 $self->abs_path($self->mpc_dirname($project)), '/.project', $crlf;
76 $self->add_dependencies($creator, $project);
80 sub add_dependencies {
81 my($self, $creator, $proj) = @_;
82 my $outdir = $self->mpc_dirname($proj);
83 my $into = $self->get_outdir();
84 $outdir = "$into/$outdir" if $into ne '.';
86 my $pre = ' <project>';
87 my $post = '</project>';
88 my $outfile = $outdir . '/.project';
90 my $fh = new FileHandle();
91 if (open($fh, $outfile)) {
92 ## Get the dependencies and store them based on the directory of
93 ## the project file. We will check them later.
94 my $deps = $self->get_validated_ordering($proj);
95 my $key = $self->mpc_basename($self->mpc_dirname($proj));
96 $self->{'seen_deps'}->{$key} = {};
97 foreach my $dep (@$deps) {
98 $self->{'seen_deps'}->{$key}->{$dep} = 1;
101 my @read = ();
102 my $cwd = $self->getcwd();
103 while(<$fh>) {
104 ## This is a comment found in cdt6project.mpd.
105 if (/MPC\s+ADD\s+DEPENDENCIES/) {
106 my $crlf = $self->crlf();
107 my %seen = ();
108 my @lines;
109 foreach my $dep (reverse @$deps) {
110 ## If we've seen this dependency, we don't need to add it
111 ## again. The build tool will handle it correctly.
112 if (!$seen{$dep}) {
113 my $relative = $self->get_relative_dep_file($creator,
114 "$cwd/$proj", $dep);
115 ## Since we're looking at the dependencies in reverse order
116 ## now, we need to unshift them into another array to keep
117 ## the correct order.
118 unshift(@lines, "$pre$dep$post$crlf") if (defined $relative);
120 ## We've now seen this dependency and all of the
121 ## projects upon which this one depends.
122 $seen{$dep} = 1;
123 foreach my $key (keys %{$self->{'seen_deps'}->{$dep}}) {
124 $seen{$key} = 1;
129 ## Add the dependency lines to the project file
130 push(@read, @lines);
132 else {
133 push(@read, $_);
136 close($fh);
138 ## We will always rewrite the project file (with or without dependencies)
139 if (open($fh, ">$outfile")) {
140 foreach my $line (@read) {
141 print $fh $line;
143 close($fh);