Subversion Repositories DevTools

Rev

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