Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
###############################################################################
2
# CLASS BuildFile
3
# Processes & Stores information from the build.pl file
4
# 
5
#
6
# By convention all members/methods that begin with an '_' are private.
7
# 
8
###############################################################################
9
 
10
package DeployUtils::BuildFile;
11
 
12
use strict;
13
use File::Basename;
14
use DeployUtils::Logger;
15
 
16
 
17
#==============================================================================
18
#   Constructor
19
#==============================================================================
20
sub new
21
{
22
    my $obclass = shift;
23
    my $class = ref($obclass) || $obclass;
24
    my $buildFile = shift;
25
 
26
    $buildFile = "build.pl" if ( ! defined($buildFile) );
27
 
28
    LogDebug("BuildFile::new Instantiating new object of class $class");
29
    bless my $self = {
30
        _FILENAME           => $buildFile,
31
        _BUILDNAME          => "",
32
        _BUILDNAME_LC       => "",
33
        _BUILDVERSION       => "",
34
        _PLATFORMS          => [],
35
        _INTERFACE          => "",
36
        _DIRTREE            => [],
37
        _PREVVERSION        => "",
38
        _DPKGARCHIVE        => {}
39
    } => ( $class );
40
 
41
    $self->_buildInfo();
42
    return($self);
43
}   # new
44
 
45
 
46
sub _buildInfo
47
{
48
    my $self = shift;
49
    my $temp; 
50
 
51
    open( BUILD, $self->{_FILENAME}) || LogError("Cannot Open $self->{_FILENAME}");
52
nextline:
53
    while ( <BUILD> )
54
    {
55
        chomp;
56
 
57
        goto nextline if ( /^\s*(\#|$)/ );
58
 
59
        if ( /BuildName\s*\(\s*[\'\"](.+?)[\'\"]\s*,\s*[\'\"](.+?)[\'\"]/)
60
        {
61
            $self->{_BUILDNAME} = $self->{_BUILDNAME_LC} = $1;
62
            $self->{_BUILDNAME_LC} =~ tr/A-Z/a-z/;
63
            $self->{_BUILDVERSION} = $2;
64
            LogDebug("BuildFile::_buildInfo Set BuildName = $self->{_BUILDNAME}");
65
            LogDebug("BuildFile::_buildInfo Set BuildNameLc = $self->{_BUILDNAME_LC}");
66
            LogDebug("BuildFile::_buildInfo Set BuildVersion = $self->{_BUILDVERSION}");
67
        }
68
        elsif ( /(BuildPkgArchive|LinkPkgArchive)\s*\(\s*\'([^\'\"]*)\'\s*,\s*\'([^\'\"]*).*$/ )
69
        {
70
            my ( $type, $module, $version ) = ( $1, $2, $3 );
71
 
72
            LogError("BuildFile::_buildInfo Duplicate Dpkg_Archive found $module") if ( defined($self->{_DPKGARCHIVE}{$module}) );
73
 
74
            # we assume the version string could contain the following
75
            # format types
76
            #
77
            # N.N.N.pp
78
            # N.N.N.ppp
79
            # N.N.N.pppp
80
            # N.N.N
81
            # beta
82
            # beta.ppp
83
            # *.cots
84
            # *.singapore
85
            #
86
            my ( $proj, $versionNum ) = ( "", "");
87
            if ( $version =~ m/^([0-9]*\.[0-9]*\.[0-9]*)\.([a-z]{2,4})$/ ) # N.N.N.pp, N.N.N.ppp, N.N.N.pppp
88
            {
89
                $versionNum = "$1";
90
                $proj = "$2";
91
            }
92
            elsif ( $version =~ m/^[0-9]*\.[0-9]*\.[0-9]*$/ ) # N.N.N
93
            {
94
               $versionNum = "$version";
95
            }
96
            elsif ( $version =~ m/^[aA-zZ]*\.[a-z][a-z][a-z]$/ ) # beta.ppp
97
            {
98
               ($versionNum, $proj) = split /\./, $version;
99
            }
100
            elsif ( $version =~ m/^[aA-zZ]*$/ ) # beta
101
            {
102
                $versionNum = "$version";
103
            }
104
            elsif ( $version =~ m/^(.*)\.(cots|singapore)$/ )    # *.cots, #.singapore
105
            {
106
                $versionNum = "$1";
107
                $proj = "$2";
108
            }
109
            else
110
            {
111
                # here we just assume the version is the version
112
                # what else can we do...
113
                $versionNum = $version;
114
            }
115
 
116
            $self->{_DPKGARCHIVE}{$module}{type}    = $type;
117
            $self->{_DPKGARCHIVE}{$module}{version} = $versionNum;
118
            $self->{_DPKGARCHIVE}{$module}{versionFull} = $version;
119
            $self->{_DPKGARCHIVE}{$module}{proj}    = $proj;
120
            LogDebug("BuildFile::_buildInfo Set Added dpkg Archive $module = $type, $versionNum, $proj");
121
        }
122
        elsif ( /BuildPlatforms\s*\(\s*(.*)\s*\)/ )
123
        {
124
            $temp = $1;
125
            $temp =~ s/[\'\"]//g;
126
            $temp =~ s/\s//g;
127
            push(@{$self->{_PLATFORMS}}, split(",", $temp));
128
            LogDebug("BuildFile::_buildInfo Set Platforms $temp");
129
 
130
        }
131
        elsif ( /BuildInterface\s*\(\s*[\'\"](.+?)[\'\"]/ )
132
        {
133
            $self->{_INTERFACE} = $1;
134
            LogDebug("BuildFile::_buildInfo Set Interface to $self->{_INTERFACE}");
135
        }
136
        elsif ( /BuildDirTree\s*\(\s*(.*)\s*\)/ )
137
        {
138
            $temp = $1;
139
            $temp =~ s/[\'\"]//g;
140
            $temp =~ s/\s//g;
141
            push(@{$self->{_DIRTREE}}, split(",", $temp));
142
            LogDebug("BuildFile::_buildInfo Set DirTree to $temp");
143
        }
144
        elsif ( /BuildPreviousVersion\s*\(\s*[\'\"](.+?)[\'\"]/ )
145
        {
146
            $self->{_PREVVERSION} = $1;
147
            LogDebug("BuildFile::_buildInfo Set BuildPrevVersion = $self->{_PREVVERSION}");
148
        }
149
    }
150
}
151
 
152
 
153
#==============================================================================
154
#   dumpSelf, debugging member to dump selfs hash
155
#==============================================================================
156
sub dumpSelf
157
{
158
    use Data::Dumper;
159
 
160
    my $self = shift;
161
 
162
    print Data::Dumper->Dump([$self], [ref($self)]);
163
}   # dumpSelf
164
 
165
 
166
# Returns the buildName as a string
167
sub getBuildName
168
{
169
    my $self = shift;
170
    return $self->{_BUILDNAME};
171
}
172
 
173
# Returns the buildName in Lower case as a string
174
sub getBuildNameLc
175
{
176
    my $self = shift;
177
    return $self->{_BUILDNAME_LC};
178
}
179
 
180
# Returns the buildVersion as a string
181
sub getBuildVersion
182
{
183
    my $self = shift;
184
    return $self->{_BUILDVERSION};
185
}
186
 
187
# Returns the Interface as a string
188
sub getInterface
189
{
190
    my $self = shift;
191
    return $self->{_INTERFACE};
192
}
193
 
194
# Returns the previous Version as a string
195
sub getPreviousVersion
196
{
197
    my $self = shift;
198
    return $self->{_PREVVERSION};
199
}
200
 
201
# Returns an array containing the platforms defined
202
sub getPlatforms
203
{
204
    my $self = shift;
205
    return @{$self->{_PLATFORMS}};
206
}
207
 
208
# Returns an array containing the DirTree
209
sub getDirTree
210
{
211
    my $self = shift;
212
    return @{$self->{_DIRTREE}};
213
}
214
 
215
# returns a list of Modules in the DpkgArchive Hash
216
sub getDpkgArchiveList
217
{
218
    my $self = shift;
219
 
220
    return sort keys %{$self->{_DPKGARCHIVE}};
221
}
222
 
223
# returns a reference to a hash that contains the details of for the module passed
224
# The hash contains keys for type, version, proj
225
sub getDpkgArchiveInfo
226
{
227
    my $self = shift;
228
    my $module = shift;
229
 
230
    if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) )
231
    {
232
        return undef;
233
    }
234
    else
235
    {
236
        return \%{$self->{_DPKGARCHIVE}{$module}};
237
    }
238
}
239
 
240
# Returns a complete copy of the DPKG_Archive hash 
241
sub getDpkgArchiveHash
242
{
243
    my $self = shift;
244
    return %{$self->{_DPKGARCHIVE}};
245
}
246
 
247
sub getDpkgArchiveType
248
{
249
    my $self = shift;
250
    my $module = shift;
251
 
252
    if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) )
253
    {
254
        return undef;
255
    }
256
    else
257
    {
258
        return $self->{_DPKGARCHIVE}{$module}{type};
259
    }
260
}
261
 
262
 
263
sub getDpkgArchiveVersionNum
264
{
265
    my $self = shift;
266
    my $module = shift;
267
 
268
    if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) )
269
    {
270
        return undef;
271
    }
272
    else
273
    {
274
        return $self->{_DPKGARCHIVE}{$module}{version};
275
    }
276
}
277
 
278
 
279
sub getDpkgArchiveVersionFull
280
{
281
    my $self = shift;
282
    my $module = shift;
283
 
284
    if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) )
285
    {
286
        return undef;
287
    }
288
    else
289
    {
290
        return $self->{_DPKGARCHIVE}{$module}{versionFull};
291
    }
292
}
293
 
294
 
295
sub getDpkgArchiveVersionProj
296
{
297
    my $self = shift;
298
    my $module = shift;
299
 
300
    if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) )
301
    {
302
        return undef;
303
    }
304
    else
305
    {
306
        return $self->{_DPKGARCHIVE}{$module}{proj};
307
    }
308
}
309
 
310
1;