Subversion Repositories DevTools

Rev

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