Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
1119 dpurdie 1
########################################################################
2
# Copyright (C) 2007 ERG Limited, All rights reserved
3
#
4
# Module name   : jats.sh
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
5654 dpurdie 8
# Documents     : MASS-00232 Format of the Linux App Upgrade Manifest File
1119 dpurdie 9
#
10
# Description   : This package extends the JATS toolset at build time
11
#                 It provides additional directives to the JATS makefiles
12
#                 to simplify the directives.
13
#
14
#                 This directive does all its work at 'build' time
15
#                 It uses makefile.pl directives
16
#
17
# Operation     : This package adds the JATS directive ManifestFiles
18
#                 This is used to create linux manifest files
19
#
20
# Syntax        : ManifestFiles (<platforms>, Options+);
21
#                 See the function header for details
22
#
23
#......................................................................#
24
 
25
require 5.6.1;
26
use strict;
27
use warnings;
5649 dpurdie 28
use Digest::file qw(digest_file_hex);
5771 alewis 29
use Digest::file qw(digest_file_base64);
1119 dpurdie 30
 
31
#
32
#   Globals
33
#
34
my @Manifests;                      # Manifest entries
1125 alewis 35
my $Manifest_has_version = 1;       # Create Manifest_xxxx by default
1121 dpurdie 36
my %package_dirs;                   # Package dirs discovered and used
1125 alewis 37
my $pkg_subdir;                     # Alternate packaging
1119 dpurdie 38
 
39
#-------------------------------------------------------------------------------
40
# Function        : BEGIN
41
#
42
# Description     : Setup directive hooks
43
#                   Register a function to be called just before we start to
44
#                   generate makefiles. This will be used to process the data
45
#                   collected in all the ManifestFiles directives
46
#
47
# Inputs          : None
48
#
49
# Returns         : None
50
#
51
BEGIN
52
{
53
    RegisterMakefileGenerate (\&ManifestFiles_Generate);
54
}
55
 
56
#-------------------------------------------------------------------------------
57
# Function        : ManifestFiles
58
#
59
# Description     : Create a ManifestFiles entry
60
#
61
# Inputs          : Platform             - Active Platform Selector
62
#                   Options              - One or more options
63
#                       --Name=Name             - Mandatory
64
#                       --Tier=Name             - Mandatory
65
#                       --Architecture=xxxx     - Default actitecture is the current target
66
#                       --Product=yyyy          - Product Family
67
#                       --Debian=BaseName[,--Prod,--Debug,--Arch=xxxx,--Product=yyyy]
68
#                       --MugPackage=Package[,--Subdir=subdir[,subdir]+]
69
#                       --SrcFile=xxx
1125 alewis 70
#                       --SrcFileNoCopy=xxx
1123 dpurdie 71
#                       --Comment=xxx           - Add comment to Manifst
1125 alewis 72
#                       --NoManifestVersion     - Create unversioned Manifest File
73
#                       --PkgSubdir=xxx         - Specifies packaging subdir
5105 dpurdie 74
#                       --ImportManifest=Package[,--Subdir=subdir,--ReWrite] - Import Manifest from package
5649 dpurdie 75
#                       --Md5                   - Add MD5 checksums to the Manifest File
5767 alewis 76
#                       --Dmf                   - Generate the Device Management Framework
77
#                                                 combined archive ZIP file.
78
#                       --DmfVersion=xxxx       - Generate the Device Management Framework
79
#                                                 combined archive ZIP using a modified
80
#                                                 version number; only for testing!
1119 dpurdie 81
#
82
# Returns         : Nothing
83
#
84
sub ManifestFiles
85
{
86
    my( $platforms, @elements ) = @_;
87
    Debug2( "ManifestFiles($platforms, @elements)" );
88
    return if ( ! ActivePlatform($platforms) );
89
 
90
    my $name;
91
    my $tier;
92
    my @files;
93
    my $mug_dir;
94
    my $default_arch = $::ScmPlatform;
95
    my $default_prod = '';
1129 dpurdie 96
    my $imported_manifest = 0;
5649 dpurdie 97
    my $include_md5 = 0;
5767 alewis 98
    my $generate_dmf = 0;
5771 alewis 99
    my $dmf_version = $::ScmBuildVersionFull;
1119 dpurdie 100
 
101
    #
102
    #   Collect user options
103
    #
104
    foreach ( @elements )
105
    {
106
        if ( m~^--Name=(.+)~ ) {
107
            if ( $name )
108
            {
109
                ReportError ("ManifestFiles:--Name option is only allowed once");
110
                next;
111
            }
112
            $name = $1;
113
 
114
        } elsif ( m~^--Tier=(.+)~ ) {
115
            if ( $tier )
116
            {
117
                ReportError ("ManifestFiles:--Tier option is only allowed once");
118
                next;
119
            }
120
            $tier = $1;
121
 
1123 dpurdie 122
        } elsif ( m~^--Comment=~ ) {
123
            my $cmt = $_;
124
            $cmt =~ s~.+=~~;
125
            $cmt =~ s~\s*\n\s*~\n~g;
126
            push @files, {'cmt' => $cmt };
127
 
1119 dpurdie 128
        } elsif ( m~^--Debian=(.+)~ ) {
1123 dpurdie 129
            push @files, {'file' => LocateDebianFile($1, $default_arch, $default_prod)};
1119 dpurdie 130
 
131
        } elsif ( m~^--SrcFile=(.+)~ ) {
1123 dpurdie 132
            push @files, {'file' => LocatePreReq($1)};
5649 dpurdie 133
 
1125 alewis 134
        } elsif ( m~^--SrcFileNoCopy=(.+)~ ) {
135
            push @files, {'filenocopy' => $1};
5649 dpurdie 136
 
1119 dpurdie 137
        } elsif ( m~^--MugPackage=(.+)~ ) {
138
            if ( $mug_dir )
139
            {
140
                ReportError ("ManifestFiles:--MugPackage option is only allowed once");
141
                next;
5649 dpurdie 142
            }
1119 dpurdie 143
            $mug_dir = LocateMugDir($1);
144
 
145
        } elsif ( m/^--Arch(.*)=(.+)/ ) {
146
            $default_arch = $2;
147
 
148
        } elsif ( m/^--Product=(.+)/ ) {
149
            $default_prod = $1;
150
 
1125 alewis 151
        } elsif ( m/^--NoManifestVersion/i ) {
152
            $Manifest_has_version = 0;
153
 
154
        } elsif ( m/^--PkgSubdir=(.+)/i ) {
155
            if ( $pkg_subdir )
156
            {
1129 dpurdie 157
                ReportError ("ManifestFiles:--PkgSubdir option is only allowed once");
1125 alewis 158
                next;
159
            }
160
            $pkg_subdir = $1;
161
 
1129 dpurdie 162
        } elsif ( m/^--ImportManifest=(.+)/i ) {
5105 dpurdie 163
            my $import_info = ImportManifest($1, $tier, $name);
1129 dpurdie 164
#DebugDumpData("ImportInfo", $import_info );
165
            push @files, {'manifest' => $import_info };
166
 
167
            #
168
            #   Fill in details unless already provided
169
            #
170
            $tier = $import_info->{'tier'} unless ( defined $tier );
171
            $name = $import_info->{'name'} unless ( defined $name );
172
            $imported_manifest = 1;
173
 
5649 dpurdie 174
        } elsif (m/^--Md5/i) {
175
            $include_md5 = 1
176
 
5767 alewis 177
        } elsif (m/^--Dmf/i) {
178
            $generate_dmf = 1
179
 
180
        } elsif ( m/^--DmfVersion=(.+)/ ) {
181
            $generate_dmf = 1;
182
            $dmf_version = $1;
183
 
1119 dpurdie 184
        } else {
185
            ReportError ("ManifestFiles: Unknown option or argument: $_");
186
 
187
        }
188
    }
189
 
190
    #
191
    #   Sanity test the user options
192
    #
193
    ReportError ("ManifestFiles: No name specified")
194
        unless $name;
195
    ReportError ("ManifestFiles: No tier specified")
1129 dpurdie 196
        unless defined ($tier);
1119 dpurdie 197
    ReportError ("ManifestFiles: Cannot mix --Debian/--SrcFile with --MugPackage in one directive")
1129 dpurdie 198
        if ( $mug_dir && (@files || $imported_manifest) );
1119 dpurdie 199
    ReportError ("ManifestFiles: Must specify files to add to Manifest")
1129 dpurdie 200
        unless ( $mug_dir ||  @files || $imported_manifest);
1119 dpurdie 201
    ErrorDoExit();
202
 
203
    #
204
    #   Save information for processing at the end of the parsing phase
205
    #   Data collected from ALL the ManifestFiles directives will be collected
206
    #   and processed into one Manifest file
207
    #
208
    my %data;
209
    $data{tier} = $tier;
210
    $data{name} = $name;
211
    $data{files} = \@files;
212
    $data{mugdir} = $mug_dir;
1125 alewis 213
    $data{pkgsubdir} = $pkg_subdir;
5649 dpurdie 214
    $data{md5} = $include_md5;
5767 alewis 215
    $data{dmf} = $generate_dmf;
216
    $data{arch} = $default_arch;
217
    $data{dmf_version} = $dmf_version;
218
 
1129 dpurdie 219
#DebugDumpData("DirectiveData", \%data );
1119 dpurdie 220
 
221
    push @Manifests, \%data;
222
    return;
223
 
224
    #-------------------------------------------------------------------------------
225
    # Function        : LocateDebianFile
226
    #
227
    # Description     : Locate a debian file
228
    #                   Internal Function
229
    #
230
    #                   Scan packages for the Debian package specified
231
    #                   The user provides the base name of the package
232
    #                   A Debian Package name has several fields
233
    #                   These are:
234
    #                       1) Base Name - Provided by the user
235
    #                       2) Version - Version will be wildcarded
236
    #                       3) Architecture - Wildcarded. Uses bin/arch directory
5649 dpurdie 237
    #
1119 dpurdie 238
    #                   Expect to find Debian Packages in the bin/PLATFORM subdir
239
    #
240
    # Inputs          : Debian base name, complete with suboptions
241
    #
242
    # Returns         : Full path of the file
243
    #
244
    sub LocateDebianFile
245
    {
246
        my ($arg, $arch, $product) = @_;
247
        Verbose("LocateDebianFile: Processing: $arg");
248
 
249
        my @type = qw( P D );
250
        my @debian_file_path;
5649 dpurdie 251
 
1119 dpurdie 252
        #
253
        #   Extract sub-options
254
        #       --Prod[uction]
255
        #       --Debug
256
        #       --Arch[itecture]=yyy
257
        #
258
        my ($base_name, @opts) = split( ',', $arg );
259
        foreach ( @opts )
260
        {
261
            if ( m/^--Arch(.*)=(.+)/ ) {
262
                $arch=$2;
263
            } elsif ( m/^--Product=(.+)/ ) {
264
                $product=$1;
265
            } elsif ( m/^--Prod/ ) {
266
                @type = 'P';
267
            } elsif ( m/^--Debug/ ) {
268
                @type = 'D';
269
            }
270
        }
271
 
272
        #
273
        #   Create a list of products
274
        #   ie: PRODUCT_ARCH
275
        #
276
        my @products;
277
        push @products, $product . '_' . $arch if ( $product );
278
        push @products, $arch;
279
 
280
        #
281
        #   Scan all packages for the specified debian package
282
        #
283
        foreach my $package_dir ( getPackagePaths ('--All') )
284
        {
285
            foreach my $type ( @type )
286
            {
287
                foreach my $prd ( @products )
288
                {
289
                    foreach my $joiner ( qw(/ .) )
290
                    {
291
                        my $dir = "$package_dir/bin$joiner$prd$type";
292
                        Verbose("ManifestFiles: Search in $dir");
293
                        next unless ( -d $dir );
294
                        my @files = glob ( "$dir/${base_name}_*.deb" );
295
                        next unless ( @files );
296
                        push @debian_file_path, @files;
1121 dpurdie 297
                        $package_dirs{$package_dir}{used} = 1;
1119 dpurdie 298
                    }
299
                }
300
            }
301
        }
302
 
5752 dpurdie 303
        ReportError ("Required Debian package not found: $base_name") unless @debian_file_path;
1121 dpurdie 304
        ReportError ("Multiple matching Debian Packages located: $base_name", @debian_file_path ) if ( $#debian_file_path > 0 );
1119 dpurdie 305
        return $debian_file_path[0];
306
    }
307
 
308
    #-------------------------------------------------------------------------------
309
    # Function        : LocateMugDir
310
    #
311
    # Description     : Locate the directory containing the mugfiles
312
    #                   Internal Function
313
    #
314
    # Inputs          : Mufile package, with embedded options
315
    #
316
    # Returns         : Full path
317
    #
318
    sub LocateMugDir
319
    {
320
        my ($mug_package) = @_;
321
 
322
        #
323
        #   Locate the mugfile subdir
324
        #
325
        my $package_name = $mug_package;
326
        my @dirs = 'mug';
327
        my $mug_dir;
328
 
329
        #
330
        #   Extract sub options
331
        #       --Subdir=xxxx,yyyy,zzzz
332
        #
333
        if ( $package_name =~ m/(.*?),--Subdir=(.*)/ )
334
        {
335
            $package_name = $1;
336
            @dirs = split( ',', $2 );
337
        }
338
 
339
        my $package = GetPackageEntry( $package_name );
340
        unless ( $package )
341
        {
342
            ReportError ("ManifestFiles: Package not known to build: $package_name");
343
            return undef;
344
        }
345
 
346
        foreach my $subdir ( @dirs )
347
        {
348
            my $dir = "$package->{'ROOT'}/$subdir";
349
            if ( -d $dir )
350
            {
351
                Warning ("Multiple Mugfile directories located. Only the first will be used",
352
                         "Ignoring: $subdir" )if ( $mug_dir );
353
                $mug_dir = $dir;
354
            }
355
        }
356
        ReportError ("Mugfile directory not found in package: $package_name")
357
            unless $mug_dir;
358
 
359
        return $mug_dir;
360
    }
1129 dpurdie 361
 
362
    #-------------------------------------------------------------------------------
363
    # Function        : ImportManifest
364
    #
365
    # Description     : Import an existing manifest
366
    #
5105 dpurdie 367
    # Inputs          : Args    - PackageName[,Subdir=name,--ReWrite]
368
    #                   tier    - May be null
369
    #                   name    - May be null
1129 dpurdie 370
    #
371
    # Returns         : A hash of data to be used later
372
    #
373
    sub ImportManifest
374
    {
5105 dpurdie 375
        my ($args, $tier, $name) = @_;
1129 dpurdie 376
        my @file_contents;
377
        my @file_list;
378
 
379
        #
380
        #   Locate the mugfile subdir
381
        #
382
        my $package_name = $args;
383
        my @dirs = 'mug';
384
        my $pkg_dir;
385
        my $pkg_root;
386
        my $manifest;
387
        my $first_tier;
388
        my $first_name;
5105 dpurdie 389
        my $rewrite;
1129 dpurdie 390
 
391
        #
392
        #   Extract sub options
393
        #       --Subdir=xxxx,yyyy,zzzz
5105 dpurdie 394
        #       --ReWrite
1129 dpurdie 395
        #
5105 dpurdie 396
        if ( $package_name =~ m/(.*?)(,.*)/ )
1129 dpurdie 397
        {
398
            $package_name = $1;
5105 dpurdie 399
            my @subargs = split(',--', $2);
400
            foreach ( @subargs)
401
            {
402
                next unless (length($_) > 0);
403
                if (m~^Subdir=(.*)~i){
404
                    @dirs = split( ',', $1 );
405
 
406
                } elsif (m~^ReWrite~i) {
407
                    $rewrite = 1;
408
 
409
                } else {
410
                    ReportError("ManifestFiles: Unknown suboption to ImportManifest:" . $_);
411
                }
412
            }
1129 dpurdie 413
        }
414
 
415
        my $package = GetPackageEntry( $package_name );
416
        unless ( $package )
417
        {
418
            ReportError ("ManifestFiles: Package not known to build: $package_name");
419
            return undef;
420
        }
421
 
5105 dpurdie 422
        if (defined ($rewrite) && ( !defined($tier) || !defined($name)))
423
        {
424
            ReportError ("ManifestFiles: ImportManifest. --ReWrite cannot be used unless tier and name are specified");
425
            return undef;
426
        }
427
 
1129 dpurdie 428
        foreach my $subdir ( @dirs )
429
        {
430
            my $dir = "$package->{'ROOT'}/$subdir";
431
            my $root = $package->{'ROOT'};
432
            if ( -d $dir )
433
            {
434
                Warning ("Multiple Package directories located. Only the first will be used",
435
                         "Ignoring: $subdir" )if ( $pkg_dir );
436
                $pkg_dir = $dir;
437
                $pkg_root = $root;
438
            }
439
        }
440
 
5105 dpurdie 441
        unless ($pkg_dir)
442
        {
443
            ReportError ("Package directory not found in package: $package_name");
444
            return undef;
445
        }
446
 
1129 dpurdie 447
        #
448
        #   Determine Manifest File name
449
        #
450
        foreach my $file ( glob ($pkg_dir . '/Manifest*' ) )
451
        {
452
                next unless ( -f $file );
453
                Warning ("Multiple Manifest Files find. Only the first will be used",
454
                         "Using: $manifest",
455
                         "Ignoring: $file" ) if ( $manifest );
456
                $manifest = $file;
457
        }
458
 
5105 dpurdie 459
        unless ($manifest)
460
        {
461
            ReportError ("ImportManifest. No Manifest found: $package_name");
462
            return undef;
463
        }
1129 dpurdie 464
 
5105 dpurdie 465
 
1129 dpurdie 466
        #
467
        #
5649 dpurdie 468
        #
1129 dpurdie 469
        open (MF, '<', $manifest ) || Error ("Cannot open the Manifest file: $manifest", $!);
470
        while ( <MF> )
471
        {
1131 dpurdie 472
            #
5711 kspencer 473
            #   Clean trailing whitespace ( line-feed and new lines )
1131 dpurdie 474
            #   Comment out [Version] data
475
            #
1129 dpurdie 476
            s~\s+$~~;
1131 dpurdie 477
            s~(\s*\[Version])~#$1~;
1129 dpurdie 478
 
479
            #
480
            #   Part lines and determine files
481
            #
482
            next unless ( $_ );
483
            next if ( m~\s*#~ );
484
            next if ( m~\s*\[~ );
485
            my( $aname, $atier, $afile) = split(/\s*\,\s*/, $_);
486
#            print "---------- $_\n";
487
#            print "T: $atier, N:$aname, F:$afile\n";
488
            push @file_list, $afile;
489
 
490
            #
5105 dpurdie 491
            #   Rewrite the name and tier
1129 dpurdie 492
            #
5105 dpurdie 493
            if ($rewrite)
494
            {
495
                $_ = join(',', $name, $tier, $afile);
496
                $first_tier = $tier;
497
                $first_name = $name;
498
            }
499
            else
500
            {
501
                #
502
                #   Capture first tier and name
503
                #
504
                $first_tier = $atier unless ( defined $first_tier );
505
                $first_name = $aname unless ( defined $first_name );
506
            }
1129 dpurdie 507
        }
5105 dpurdie 508
        continue
509
        {
510
            push @file_contents, $_;
511
        }
1129 dpurdie 512
        close MF;
513
 
514
        #
515
        #   Create a hash of data that describes the manifest that has
516
        #   just been read in.
517
        #
518
        $package_dirs{$pkg_root}{used} = 1;
519
        $manifest =~ s~.*/~~;
520
        return { 'contents' => \@file_contents,
521
                  'files' => \@file_list,
522
                  'file_base' => $pkg_dir,
523
                  'manifest' => $manifest,
524
                  'pkg_dir' => $pkg_root,
525
                  'tier' => $first_tier,
526
                  'name' => $first_name,
5105 dpurdie 527
                  'rewrite' => $rewrite,
1129 dpurdie 528
                };
529
    }
1119 dpurdie 530
}
531
 
532
#-------------------------------------------------------------------------------
533
# Function        : ManifestFiles_Generate
534
#
535
# Description     : Internal Function
536
#                   Process all the collected data and create directives
537
#                   for the creation of the manifest
538
#
539
#                   This function will be called, just before the Makefile
540
#                   is created. The function will:
541
#                       1) Create the Manifest File
542
#                       2) Package the Manifest File
543
#                       3) Package the manifest file contents
544
#
545
#                   using (mostly) normal makefile.pl directives.
546
#
547
# Inputs          : None
548
#
549
# Returns         : Nothing
550
#
551
sub ManifestFiles_Generate
552
{
553
    Debug ("ManifestFiles_Generate");
554
    Message ("Generating Manifest File");
1123 dpurdie 555
 
556
    #
557
    #   Need at least one Manifest Entry
558
    #
559
    return unless ( @Manifests );
1119 dpurdie 560
#DebugDumpData ( "Manifests", \@Manifests );
561
 
562
    #
1125 alewis 563
    #   Determine the target packaging directory
564
    #   Default is .../mug
565
    #
566
    my $pkgdir = 'mug';
1129 dpurdie 567
    if ( exists $Manifests[0]->{pkgsubdir} && defined $Manifests[0]->{pkgsubdir} )
1125 alewis 568
    {
569
        my $subdir = $Manifests[0]->{pkgsubdir};
570
        $pkgdir .= '/' . $subdir;
571
        $pkgdir =~ s~^mug/mug~mug~;
572
    }
573
 
574
    #
1119 dpurdie 575
    #   Create the Manifest File as we process the lists
1125 alewis 576
    #   Place this in the 'lib' directory:
1119 dpurdie 577
    #       - So that it will be deleted on clobber
1123 dpurdie 578
    #       - So that it can be placed in a target-specific subdir
1125 alewis 579
    #       - So that we can have one per makefile.pl
1119 dpurdie 580
    #
581
    Error ("ManifestFiles: Needs local directory specified in build.pl") unless ( $::ScmLocal );
582
 
1125 alewis 583
    my $manifest_dir = "$::ScmPlatform.LIB";
1119 dpurdie 584
    System( "$::GBE_BIN/mkdir -p $manifest_dir" );
585
 
1125 alewis 586
    my $manifest_file = $manifest_dir . '/Manifest';
587
    $manifest_file .= '_' . $::ScmBuildVersion if ( $Manifest_has_version );
588
    ToolsetGenerate( $manifest_file );
1119 dpurdie 589
    Verbose ("ManifestFiles_Generate: File: $manifest_file");
5649 dpurdie 590
 
1125 alewis 591
    PackageFile ('*', $manifest_file, '--Subdir=' . $pkgdir, '--Strip' );
1119 dpurdie 592
 
593
    open (MF, '>', $manifest_file ) || Error ("Cannot create the Manifest file: $manifest_file");
594
 
5711 kspencer 595
    binmode (MF);
5767 alewis 596
 
1119 dpurdie 597
    print_mf ("# PackageName: $::ScmBuildPackage");
598
    print_mf ("# PackageVersion: $::ScmBuildVersion");
599
    print_mf ("# BuildDate: $::CurrentTime");
600
    print_mf ("#");
601
    print_mf ("[Version],$::ScmBuildVersion");
602
    print_mf ("#");
603
 
604
    #
1125 alewis 605
    #   Process each tier in the order presented in the source file
1119 dpurdie 606
    #
1123 dpurdie 607
    my $last_was_comment = 0;
1119 dpurdie 608
    foreach my $entry ( @Manifests )
609
    {
1127 alewis 610
    #print_mf ("#");
1119 dpurdie 611
 
612
#DebugDumpData ( "Manifest Entry", $entry );
613
 
614
        my $tier = $entry->{tier};
615
        my $name = $entry->{name};
5649 dpurdie 616
        my $include_md5 = $entry->{md5};
1119 dpurdie 617
 
5767 alewis 618
        if ( $entry->{dmf} )
619
        {
620
        	DmfGenerate($entry);
621
        }
622
 
1119 dpurdie 623
        #
624
        #   Insert all the files that have been specified
625
        #   The user specified order is preserved
626
        #
1123 dpurdie 627
        #   Entries may be either a file or a comment
628
        #   Comments: Merge multiple comments and create blocks
629
        #
630
        #
1119 dpurdie 631
        my @files = @{ $entry->{files} };
1123 dpurdie 632
        foreach my $fentry ( @files )
1119 dpurdie 633
        {
1123 dpurdie 634
            if ( my $cmt = $fentry->{'cmt'} )
635
            {
636
                print_mf ('') unless ( $last_was_comment ) ;
637
                print_mf ( map (('# ' . $_) , split ("\n", $cmt) ));
638
                $last_was_comment = 1;
639
                next;
640
            }
641
 
642
            print_mf ('#') if ( $last_was_comment );
643
            if ( my $file = $fentry->{'file'} )
644
            {
645
                my $base_file = StripDir( $file );
5649 dpurdie 646
                if ($include_md5) {
647
                    my $md5 = digest_file_hex($file, 'MD5');
5654 dpurdie 648
                    print_mf ('--NoCheckLineWidth', "$name,$tier,$base_file,MD5=$md5");
5649 dpurdie 649
                } else {
650
                    print_mf ("$name,$tier,$base_file");
651
                }
1125 alewis 652
                PackageFile ('*', $file, '--Subdir=' . $pkgdir, '--Strip' );
1123 dpurdie 653
                $last_was_comment = 0;
654
            }
1125 alewis 655
 
656
            if ( my $file = $fentry->{'filenocopy'} )
657
            {
658
                print_mf ("$name,$tier,$file");
659
                $last_was_comment = 0;
660
            }
1129 dpurdie 661
 
662
            if ( my $emf = $fentry->{'manifest'} )
663
            {
664
                $last_was_comment = 0;
665
                #
666
                #   Insert the entire manifest
667
                #   Items are:
668
                #        contents
669
                #        files
670
                #        file_base
671
                #        manifest
672
                #
673
#DebugDumpData ( "Embedded Manifest Entry", $emf );
674
                print_mf ( '## Included Manifest: ' .  $emf->{'manifest'}  );
675
                print_mf ($_) foreach  ( @{$emf->{'contents'}} );
676
                PackageFile ('*', $emf->{'file_base'}. '/' . $_, '--Subdir=' . $pkgdir, '--Strip' )foreach  ( @{$emf->{'files'}});;
677
                print_mf ( '## End Included Manifest' );
678
            }
1119 dpurdie 679
        }
680
 
681
        #
682
        #   Expand out the entire MUG directory
683
        #   All .mug files in the MUG directory will be added to the manifest
684
        #   The assumption is that the MUG directory has been created by
685
        #   something that knows what its doing
686
        #
687
        if ( my $mugdir = $entry->{mugdir} )
688
        {
689
            foreach my $file ( glob ($mugdir . '/*.mug' ) )
690
            {
691
                next unless ( -f $file );
692
                my $base_file = StripDir($file);
5654 dpurdie 693
                if ($include_md5) {
694
                    my $md5 = digest_file_hex($file, 'MD5');
695
                    print_mf ('--NoCheckLineWidth', "$name,$tier,$base_file,MD5=$md5");
696
                } else {
697
                    print_mf ("$name,$tier,$base_file");
698
                }
1119 dpurdie 699
                PackageFile ('*', $file, '--Subdir=mug', '--Strip' );
700
            }
701
        }
702
    }
703
 
704
    #
705
    #   Complete the creation of the Manifest File
706
    #
707
    print_mf ("#");
708
    print_mf ("# End of File");
709
    close MF;
710
    ErrorDoExit();
1121 dpurdie 711
 
712
    #
713
    #   Sanity test of packages that did not provide a debian file
714
    #   Just a hint that something may have been missed
715
    #
716
    my @not_used_packages;
717
    foreach my $package_dir ( getPackagePaths ('--All') )
718
    {
719
        next if ( $package_dir =~ m~/manifest-tool/~ );
720
        unless ( exists $package_dirs{$package_dir}{used} )
721
        {
722
            push @not_used_packages, $package_dir;
723
        }
724
    }
725
    if ( @not_used_packages )
726
    {
727
        Warning ("Packages that did not contribute packages to the manifest:",
728
                  @not_used_packages );
729
    }
730
 
1119 dpurdie 731
    return;
732
 
733
    #-------------------------------------------------------------------------------
734
    # Function        : print_mf
735
    #
736
    # Description     : Internal Function
737
    #                   Print one line to the Manifest File
738
    #                   Checks the length of the line being created
739
    #
740
    # Inputs          : $line
741
    #
5649 dpurdie 742
    # Returns         :
1119 dpurdie 743
    #
744
 
745
    sub print_mf
746
    {
5649 dpurdie 747
        my $check_line_width = 1;
748
 
749
        if ($_[0] eq '--NoCheckLineWidth')
750
        {
751
            shift @_;
752
            $check_line_width = 0;
753
        }
754
 
1119 dpurdie 755
        foreach  ( @_ )
756
        {
757
            ReportError ( "Manifest line too long",
5649 dpurdie 758
                    "Line: $_" ) if ( $check_line_width && length ($_) > 79);
1119 dpurdie 759
            print MF $_ . "\n";
760
        }
761
    }
762
}
763
 
5767 alewis 764
# Bring in the DMF build requirements.
765
my $directory;
766
BEGIN {
767
    use File::Spec::Functions qw(rel2abs);
768
    use File::Basename qw(dirname);
769
 
770
    my $path = rel2abs( __FILE__ );
771
    $directory = dirname( $path );
772
}
773
use lib $directory;
774
 
775
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
776
use JSON;
777
 
778
#-------------------------------------------------------------------------------
779
# Function        : DmfGenerate
780
#
781
# Description     : Import an existing manifest
782
#
783
# Inputs          : entry   - The manifest that is being processed.
784
#
785
# Returns         : Nothing
786
#
787
sub DmfGenerate
788
{
789
    my ($entry) = @_;
790
 
791
    # Get the generation time.
792
    my $gen_time = time();
793
 
794
    my $work_dir = "$::ScmPlatform.BIN/";
795
    System( "$::GBE_BIN/mkdir -p $work_dir" );
796
 
797
    my $name = $entry->{name};
798
    my $version = $entry->{dmf_version};
799
 
800
    # Configure base manifest information.
801
    my %manifest;
5771 alewis 802
    $manifest{'mugsetId'} = $name . '_' . $version;
5767 alewis 803
    $manifest{'name'} = $name;
804
    $manifest{'version'} = $version;
5771 alewis 805
    $manifest{'packageName'} = $::ScmBuildPackage;
806
    $manifest{'packageVersion'} = $::ScmBuildVersionFull;
5767 alewis 807
    $manifest{'datetime'} = localtime($gen_time);
808
    $gen_time *= 1000;  # Make to milliseconds
809
    $manifest{'timestamp'} = $gen_time;
810
    $manifest{'tier'} = $entry->{tier};
811
 
812
    # Process each file.
813
    my @files = @{ $entry->{files} };
814
    my $zip = Archive::Zip->new();
815
    my $i = 0;
816
    foreach my $fentry ( @files )
817
    {
818
        if ( my $file = $fentry->{'file'} )
819
        {
820
        	my $order = $i + 1;
821
            my $base_file = StripDir( $file );
822
            my $publish_file = $name . '_' . $version . '_' . $order . '.aup';
823
            my $aup_file = $work_dir . $publish_file;
824
 
825
            GenerateCesFile($file, $aup_file, 0x3, $gen_time, $publish_file);
826
 
827
            my $file_member = $zip->addFile( $aup_file, $publish_file );
828
 
829
            $manifest{'tasks'}[$i]{'order'} = 1 * $order;
830
            $manifest{'tasks'}[$i]{'filename'} = $base_file;
831
            $manifest{'tasks'}[$i]{'download'} = $publish_file;
5771 alewis 832
            $manifest{'tasks'}[$i]{'sha256'} = digest_file_base64($file, 'SHA-256');
833
            $manifest{'tasks'}[$i]{'size'} = -s $file;
834
 
5767 alewis 835
            if ($base_file =~ /\.sh$/)
836
            {
837
                $manifest{'tasks'}[$i]{'action'} = 'exec-shell';
838
            }
839
            elsif ($base_file =~ /\.deb$/)
840
            {
841
                $manifest{'tasks'}[$i]{'action'} = 'dpkg-install';
5771 alewis 842
 
843
                my ($pkg_name, $pkg_version, $pkg_arch) = ($base_file =~ /([^_]*)_([^_]*)_(.*)/);
844
                $manifest{'tasks'}[$i]{'arch'} = $pkg_arch;
845
                $manifest{'tasks'}[$i]{'name'} = $pkg_name;
846
                $manifest{'tasks'}[$i]{'version'} = $pkg_version;
5767 alewis 847
            }
848
            else
849
            {
850
                ReportError ("Manifest entry $base_file does not have a supported DMF install action");
851
            }
852
 
853
            $i = $i + 1;
854
        }
855
    }
856
 
857
    # Encode and commit the JSON.
858
    my $json_encoder = JSON->new->allow_nonref;
859
    my $json = $json_encoder->pretty->encode( \%manifest );
860
 
861
    my $manifest_filename = $name . '_' . $version;
862
    my $aum_filename = $manifest_filename . '_0.aum';
863
    my $manifest_file = $work_dir . $manifest_filename . '.json';
864
    my $aum_file = $work_dir . $aum_filename;
865
 
866
    # Save our manifest.
867
    open (J, '>', $manifest_file ) || Error ("Cannot create the DMF Manifest file");
868
    binmode (J);
869
    print J $json;
870
 
871
    close J;
872
 
873
    GenerateCesFile($manifest_file, $aum_file, 0x2, $gen_time, $aum_filename);
874
 
875
    $zip->addFile($aum_file, $aum_filename);
876
 
877
    my $zip_filename = $work_dir . $name . '_' . $version . '.zip';
878
    if ( $zip->writeToFileNamed($zip_filename) != AZ_OK )
879
    {
880
        ReportError("DMF ZIP file creation failed");
881
    }
882
    PackageFile('*', $zip_filename, '--Strip');
883
    PackageFile('*', $manifest_file, '--Strip');
884
 
885
}
886
 
887
#-------------------------------------------------------------------------------
888
# Function        : DmfGenerate
889
#
890
# Description     : Import an existing manifest
891
#
892
# Inputs          : src_file     - The input file.
893
#                   dst_file     - The output CES file.
894
#                   content_type - The content type to report.
895
#                   gen_time     - The generation time for the file.
896
#                   filename     - The filename to embed in the CES file.
897
#
898
#
899
# Returns         : Nothing
900
#
901
sub GenerateCesFile
902
{
903
    my ($src_file, $dst_file, $content_type, $gen_time, $filename) = @_;
904
 
905
    open (INF, '<', $src_file ) || Error ("Cannot open file $src_file for reading");
906
    binmode (INF);
907
 
908
    open (OUTF, '>', $dst_file ) || Error ("Cannot open file $dst_file for writing");
909
    binmode (OUTF);
910
 
911
    my $signing_key_name = "";
912
    my $signature_size = 0;
913
    my $format_version = 0xCE500000;
914
    my $compression_method = 0;
915
    my $encryption_method = 0;
916
    my $kek_name = "";
917
    my $encryption_key_size = 0;
918
    my $filename_size = length($filename);
919
 
920
    print OUTF pack("Z32", $signing_key_name);
921
    print OUTF pack("n", $signature_size);
922
    print OUTF pack("N", $format_version);
923
    print OUTF pack("N", $content_type);
924
    print OUTF pack("Q>", $gen_time);
925
    print OUTF pack("N", $compression_method);
926
    print OUTF pack("N", $encryption_method);
927
    print OUTF pack("Z32", $kek_name);
928
    print OUTF pack("n", $encryption_key_size);
929
    print OUTF pack("n", $filename_size);
930
    # Encryption key HERE
931
    print OUTF pack("A$filename_size", $filename);
932
 
933
    my $buf;
934
    while (read(INF,$buf,65536))
935
    {
936
        print OUTF $buf;
937
    }
938
    print OUTF $buf;
939
    close INF;
940
 
941
    # Signature HERE
942
 
943
    # Finish with file.
944
    close OUTF;
945
}
946
 
1119 dpurdie 947
1;