Subversion Repositories DevTools

Rev

Rev 227 | Rev 285 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
3
# Copyright ( C ) 2005 ERG Limited, All rights reserved
4
#
5
# Module name   : jats.sh
6
# Module type   : Perl Package
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : This package contains functions to manipulate
11
#                 the information required to create a DPACKAGE file
12
#
13
#......................................................................#
14
 
255 dpurdie 15
use 5.006_001;
227 dpurdie 16
use strict;
17
use warnings;
18
 
19
################################################################################
20
#   Global variables used by functions in this package
21
#   For historical reasons many of these variabeles are global
22
#
23
 
24
package JatsDPackage;
25
use JatsError;
26
use Data::Dumper;
27
use ConfigurationFile;
28
 
29
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
30
use Exporter;
31
 
32
$VERSION = 1.00;
33
@ISA = qw(Exporter);
34
 
35
# Symbols to autoexport (:DEFAULT tag)
36
@EXPORT = qw(
37
                DPackageAdd
38
                DPackageSave
39
                DPackageGenerate
40
            );
41
 
42
#
43
#   Global data
44
#
45
our %DPackageLibraryData;
46
our %DPackageLibraryDataStore;
47
 
48
#
49
#   Local Data
50
#
51
my $data_added;
52
my $cwd;
53
 
54
#-------------------------------------------------------------------------------
55
# Function        : DPackageAdd
56
#
57
# Description     : Called to insert new information into the data store
58
#
59
# Inputs          : platform    - This does not need to be an active platform
60
#                                 it is simply passed to the DPACKAGE builder
61
#
62
#                   using       - The "using" target
63
#
64
#                   ...         - Arguments for the Library directive
65
#
66
# Returns         :
67
#
68
sub DPackageAdd
69
{
70
    my ($platform, $using, @args ) = @_;
71
    push @{$DPackageLibraryData{$using}{$platform}}, @args;
72
    $data_added = 1;
73
    $cwd = $::Cwd;
74
}
75
 
76
#-------------------------------------------------------------------------------
77
# Function        : DPackageSave
78
#
79
# Description     : Merge collected DPackageLibraryData with data stored
80
#                   within the interface directory from other makefiles
81
#
82
#                   This function is called to save the data
83
#                   is written and before the DPACKAGE file is written
84
#
85
# Inputs          :
86
#
87
# Returns         :
88
#
89
sub DPackageSave
90
{
91
    my $must_save;
92
    #
93
    #   Do not save if there is nothing to save and nothing has ever been saved
94
    #   Must update if there is anything previously saved
95
    #
96
    return unless ( $data_added );
97
    Debug("DPackageSave");
98
 
99
    #
100
    #   Read in any existing data
101
    #   It will be held in %DPackageLibraryDataStore
102
    #   Then replace any data from this makefile with new information
103
    #
104
    Require ( "$::ScmRoot/$::ScmInterface", "Dpackage.cfg",
105
                "JATS internal file missing. Rebuild required" )
106
        if ( -f "$::ScmRoot/$::ScmInterface/Dpackage.cfg" );
107
 
108
#    DebugDumpData("%DPackageLibraryDataStore",\%DPackageLibraryDataStore );
109
    if ( defined %DPackageLibraryData )                 # Add this makefile.pl data
110
    {
111
 
112
        #
113
        #   Detect changes in the data
114
        #   Serialise the stored element and the element we wish to store
115
        #   If they are the same we don't need to write out new data.
116
        #
117
        my $list1 = Dumper($DPackageLibraryDataStore{$cwd});
118
        my $list2 = Dumper(\%DPackageLibraryData);
119
        if ( $list1 ne $list2 )
120
        {
121
            Debug("DPackageSave: Add DPACKAGE data");
122
            $DPackageLibraryDataStore{$cwd} = {%DPackageLibraryData};
123
            $must_save = 1;
124
        }
125
        else
126
        {
127
            Debug("DPackageSave: Add DPACKAGE data - no change");
128
        }
129
    }
130
    elsif ( $DPackageLibraryDataStore{$cwd}  )      # Data has gone. Remove entry
131
    {
132
        Debug("DPackageSave: Remove DPACKAGE data");
133
        delete $DPackageLibraryDataStore{$cwd};
134
        $must_save = 1;
135
    }
136
 
137
#    DebugDumpData("%DPackageLibraryDataStore",\%DPackageLibraryDataStore );
138
 
139
    #
140
    #   Write it out now that it has been merged
141
    #
142
    if ( $must_save )
143
    {
144
        Debug("DPackageSave: Save Data");
145
        my $fh = ConfigurationFile::New( "$::ScmRoot/$::ScmInterface/Dpackage.cfg" );
146
        $fh->Dump([\%DPackageLibraryDataStore], [qw(*DPackageLibraryDataStore)]);
147
        $fh->Close();
148
    }
149
}
150
 
151
#-------------------------------------------------------------------------------
152
# Function        : DPackageGenerate
153
#
154
# Description     : Create a simple DPACKAGE file based on collected information
155
#
156
#                   This function must be called after all the makefiles
157
#                   have been rebuilt. It is only at this time that all the
158
#                   information has been collected.
159
#
160
# Inputs          : None
161
#
162
# Returns         : Nothing
163
#
164
sub DPackageGenerate
165
{
166
    my ($ScmRoot, $ScmInterface ) = @_;
167
 
168
    #
169
    #   Do not generate DPACKAGE unless there is a Dpackage.cfg file
170
    #   DPACKAGE will be created in a user directory and thus we don't
171
    #   want to delete it unless we have created it
172
    #
173
    return
174
        unless ( -f "$ScmRoot/$ScmInterface/Dpackage.cfg" );
175
 
176
    #
177
    #   Validate globals
178
    #
179
    Error ("ScmSrcDir not present") unless ( $::ScmSrcDir );
180
 
181
    #
182
    #   User status information
183
    #
184
    Message ("Generating DPACKAGE");
185
 
186
    #
187
    #   Read in accumulated information for the creation of the DPACKAGE file
188
    #
189
    $::CurrentTime = localtime;
190
    Require ( "$ScmRoot/$ScmInterface", "Dpackage.cfg",
191
                "JATS internal file missing. Rebuild required" );
192
 
193
#    DebugDumpData("%::DPackageLibraryData",\%DPackageLibraryDataStore );
194
 
195
    #
196
    #   Delete and then re-create the the DPACKAGE file
197
    #
198
    my $fname = "$ScmRoot/$::ScmSrcDir/DPACKAGE";
199
    unlink $fname;
200
 
201
    my $fh = ConfigurationFile::New( $fname );
202
    $fh->Header( "Auto-generated DPACKAGE",
203
                              "JatsDPackage (version $VERSION)" );
204
 
205
    $fh->Write( "\n", "Version( 1, 0 );    # Interface version\n\n" );
206
 
207
    #
208
    #   Process each "Using" entry
209
    #   Within each entry process the "platform" targets
210
    #   and generate Libraries directives.
211
    #
212
    foreach my $mkfile (keys %DPackageLibraryDataStore )
213
    {
214
        my $pmkfile = $DPackageLibraryDataStore{$mkfile};
215
 
216
        $fh->Write( "\n#\n" );
217
        $fh->Write( "# Defined in: $mkfile\n" );
218
        $fh->Write( "#\n" );
219
        foreach my $using ( keys %{$pmkfile}  )
220
        {
221
            my $uentry = $pmkfile->{$using};
222
            $fh->Write( "Using( '$using' );    # Usage name\n" );
223
 
224
            foreach my $platform ( keys %{$uentry} )
225
            {
226
                my $pentry = $uentry->{$platform};
227
                $fh->Write( "\nLibraries('$platform',\n" );
228
                foreach my $entry ( @{$pentry} )
229
                {
230
                    $fh->Write( "        '$entry',\n" ),
231
                }
232
 
233
                $fh->Write( "        );\n" ),
234
            }
235
        }
236
    }
237
    $fh->Close();
238
}
239
 
240
#-------------------------------------------------------------------------------
241
# Function        : Require
242
#
243
# Description     : Internal implementation
244
#
245
# Inputs          : $path
246
#                   $file
247
#                   ...
248
#
249
# Returns         : 
250
#
251
sub Require
252
{
253
    my ($path, $file) = @_;
254
    $path .= "/$file";
255
 
256
    require $path;
257
}
258
 
259
1;
260
 
261