Merge pull request #178 from DOCGroup/elliottc/more_databases
[MPC.git] / modules / CCWorkspaceCreator.pm
blob5cb7bf7200d45675f8b2434d7b753682b5de4e4d
1 package CCWorkspaceCreator;
3 # ************************************************************
4 # Description : A Code Composer Workspace creator
5 # Author : Chad Elliott
6 # Create Date : 9/18/2006
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use CCProjectCreator;
16 use WinWorkspaceBase;
17 use WorkspaceCreator;
19 use vars qw(@ISA);
20 @ISA = qw(WinWorkspaceBase WorkspaceCreator);
22 # ************************************************************
23 # Subroutine Section
24 # ************************************************************
26 sub compare_output {
27 #my $self = shift;
28 return 1;
32 sub workspace_file_extension {
33 #my $self = shift;
34 return '.code_composer';
38 sub write_comps {
39 my($self, $fh, $creator) = @_;
40 my $crlf = $self->crlf();
42 ## Workspace only consists of the name of the project. Really, Code
43 ## Composer doesn't use a workspace. Each project contains the
44 ## dependencies.
45 foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
46 print $fh "$project$crlf";
47 $self->add_dependencies($creator, $project);
52 sub add_dependencies {
53 my($self, $creator, $proj) = @_;
54 my $fh = new FileHandle();
55 my $outdir = $self->get_outdir();
56 $outdir = $self->getcwd() if ($outdir eq '.');
58 if (open($fh, "$outdir/$proj")) {
59 my @read;
60 my $write;
61 my $cwd = $self->getcwd();
62 while(<$fh>) {
63 ## This is a comment found in cc.mpd if the project contains the
64 ## 'after' keyword setting.
65 if (/MPC\s+ADD\s+DEPENDENCIES/) {
66 my @projs;
67 my $crlf = $self->crlf();
68 my $deps = $self->get_validated_ordering($proj);
69 foreach my $dep (@$deps) {
70 my $relative = $self->get_relative_dep_file($creator,
71 "$cwd/$proj", $dep);
72 if (defined $relative) {
73 if (!$write) {
74 ## Indicate that we need to re-write the file and add in
75 ## the start of the project dependencies section
76 $write = 1;
77 push(@read, "[Project Dependencies]$crlf");
80 ## Add in the dependency and save the project name for later.
81 push(@read, "Source=\"$relative\"$crlf");
82 push(@projs, $relative);
85 if ($write) {
86 ## Finish off the dependency information for the current
87 ## project.
88 push(@read, $crlf);
89 foreach my $proj (@projs) {
90 push(@read, "[\"$proj\" Settings]$crlf",
91 "MatchConfigName=true$crlf", $crlf);
94 else {
95 ## We don't need to re-write the file, so we can stop reading
96 ## it.
97 last;
100 else {
101 ## Save the line to possibly be written out at the end.
102 push(@read, $_);
105 close($fh);
107 ## If we need to re-write the file, then do so
108 if ($write && open($fh, ">$outdir/$proj")) {
109 foreach my $line (@read) {
110 print $fh $line;
112 close($fh);