summaryrefslogtreecommitdiff
path: root/ACE/MPC/modules/CCWorkspaceCreator.pm
blob: 5cb7bf7200d45675f8b2434d7b753682b5de4e4d (plain)
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
package CCWorkspaceCreator;

# ************************************************************
# Description   : A Code Composer Workspace creator
# Author        : Chad Elliott
# Create Date   : 9/18/2006
# ************************************************************

# ************************************************************
# Pragmas
# ************************************************************

use strict;

use CCProjectCreator;
use WinWorkspaceBase;
use WorkspaceCreator;

use vars qw(@ISA);
@ISA = qw(WinWorkspaceBase WorkspaceCreator);

# ************************************************************
# Subroutine Section
# ************************************************************

sub compare_output {
  #my $self = shift;
  return 1;
}


sub workspace_file_extension {
  #my $self = shift;
  return '.code_composer';
}


sub write_comps {
  my($self, $fh, $creator) = @_;
  my $crlf = $self->crlf();

  ## Workspace only consists of the name of the project.  Really, Code
  ## Composer doesn't use a workspace.  Each project contains the
  ## dependencies.
  foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
    print $fh "$project$crlf";
    $self->add_dependencies($creator, $project);
  }
}


sub add_dependencies {
  my($self, $creator, $proj) = @_;
  my $fh     = new FileHandle();
  my $outdir = $self->get_outdir();
  $outdir    = $self->getcwd() if ($outdir eq '.');

  if (open($fh, "$outdir/$proj")) {
    my @read;
    my $write;
    my $cwd = $self->getcwd();
    while(<$fh>) {
      ## This is a comment found in cc.mpd if the project contains the
      ## 'after' keyword setting.
      if (/MPC\s+ADD\s+DEPENDENCIES/) {
        my @projs;
        my $crlf = $self->crlf();
        my $deps = $self->get_validated_ordering($proj);
        foreach my $dep (@$deps) {
          my $relative = $self->get_relative_dep_file($creator,
                                                      "$cwd/$proj", $dep);
          if (defined $relative) {
            if (!$write) {
              ## Indicate that we need to re-write the file and add in
              ## the start of the project dependencies section
              $write = 1;
              push(@read, "[Project Dependencies]$crlf");
            }

            ## Add in the dependency and save the project name for later.
            push(@read, "Source=\"$relative\"$crlf");
            push(@projs, $relative);
          }
        }
        if ($write) {
          ## Finish off the dependency information for the current
          ## project.
          push(@read, $crlf);
          foreach my $proj (@projs) {
            push(@read, "[\"$proj\" Settings]$crlf",
                        "MatchConfigName=true$crlf", $crlf);
          }
        }
        else {
          ## We don't need to re-write the file, so we can stop reading
          ## it.
          last;
        }
      }
      else {
        ## Save the line to possibly be written out at the end.
        push(@read, $_);
      }
    }
    close($fh);

    ## If we need to re-write the file, then do so
    if ($write && open($fh, ">$outdir/$proj")) {
      foreach my $line (@read) {
        print $fh $line;
      }
      close($fh);
    }
  }
}

1;