Subversion Repositories DevTools

Rev

Rev 6734 | Rev 6933 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6734 Rev 6932
Line 22... Line 22...
22
#......................................................................#
22
#......................................................................#
23
 
23
 
24
require 5.6.1;
24
require 5.6.1;
25
use strict;
25
use strict;
26
use warnings;
26
use warnings;
27
use Digest::file qw(digest_file_hex);
-
 
28
use Digest::file qw(digest_file_base64);
-
 
29
use ArrayHashUtils;
27
use ArrayHashUtils;
30
 
28
 
31
#
29
#
32
#   Globals
30
#   Globals
-
 
31
#   These are exposed to all of JATS, so:
-
 
32
#       Limit the number (ideally none)
-
 
33
#       Be away of the potential name conflicts
33
#
34
#
34
my @Manifests;                      # Manifest entries
-
 
35
my $Manifest_has_version = 1;       # Create Manifest_xxxx by default
-
 
36
my %package_dirs;                   # Package dirs discovered and used
-
 
37
my $pkg_subdir;                     # Alternate packaging
-
 
38
my $ManifestLineWidth;              # Max length of lines
-
 
39
 
35
 
40
#-------------------------------------------------------------------------------
36
#-------------------------------------------------------------------------------
41
# Function        : BEGIN
37
# Function        : BEGIN
42
#
38
#
43
# Description     : Setup directive hooks
39
# Description     : Setup directive hooks
Line 49... Line 45...
49
#
45
#
50
# Returns         : None
46
# Returns         : None
51
#
47
#
52
BEGIN
48
BEGIN
53
{
49
{
54
    RegisterMakefileGenerate (\&ManifestFiles_Generate);
50
    RegisterMakefileGenerate (\&ManifestFiles::Generate);
55
}
51
}
56
 
52
 
57
#-------------------------------------------------------------------------------
53
#-------------------------------------------------------------------------------
58
# Function        : ManifestFiles
54
# Function        : ManifestFiles
59
#
55
#
Line 83... Line 79...
83
#                                                 combined archive ZIP using a modified
79
#                                                 combined archive ZIP using a modified
84
#                                                 version number; only for testing!
80
#                                                 version number; only for testing!
85
#                       --LineLength=nnn        - Limit line length. Default is 79
81
#                       --LineLength=nnn        - Limit line length. Default is 79
86
#                       --SubManifest           - Create a sub-manifest (not installable). Manifest will have no version.
82
#                       --SubManifest           - Create a sub-manifest (not installable). Manifest will have no version.
87
#                                                 Gives a default name, tier and subdir if not explicitly provided.
83
#                                                 Gives a default name, tier and subdir if not explicitly provided.
-
 
84
#                       --NoSignatures          - Prevent the generation of .sig files
-
 
85
#                                                 Default is to generate .sigFiles
-
 
86
#                       --NoWarn                - Supress warnings about unused packages
-
 
87
#                                                 Will supress sanity test. Useful when generating multiple
-
 
88
#                                                 manifests.                          
-
 
89
#                                                 
-
 
90
# Notes: On sig file generation
-
 
91
#   This tool will use an internal key file to generate signatures
-
 
92
#   UNLESS the tool is being run on a special build machine with a controlled signature file
-
 
93
#   the generated signatures will not work on-target.
-
 
94
#   
88
#
95
#
89
# Returns         : Nothing
96
# Returns         : Nothing
90
#
97
#
91
sub ManifestFiles
98
sub ManifestFiles
92
{
99
{
Line 132... Line 139...
132
            $cmt =~ s~.+=~~;
139
            $cmt =~ s~.+=~~;
133
            $cmt =~ s~\s*\n\s*~\n~g;
140
            $cmt =~ s~\s*\n\s*~\n~g;
134
            push @files, {'cmt' => $cmt };
141
            push @files, {'cmt' => $cmt };
135
 
142
 
136
        } elsif ( m~^--Debian=(.+)~ ) {
143
        } elsif ( m~^--Debian=(.+)~ ) {
137
            push @files, {'file' => _LocateDebianFile($1, $default_arch, $default_prod)};
144
            push @files, {'file' => ManifestFiles::_LocateDebianFile($1, $default_arch, $default_prod)};
138
 
145
 
139
        } elsif ( m~^--Apk=(.+)~ ) {
146
        } elsif ( m~^--Apk=(.+)~ ) {
140
            my $apkData = _LocateApkFile($1, $default_arch);
147
            my $apkData = ManifestFiles::_LocateApkFile($1, $default_arch);
141
            my ($fname, $fversion) = split($;, $apkData);
148
            my ($fname, $fversion) = split($;, $apkData);
142
            $fileVersions{$fname} = $fversion;
149
            $fileVersions{$fname} = $fversion;
143
            push @files, {'file' => $fname };
150
            push @files, {'file' => $fname };
144
            $useDefaultLineWidth = 0;
151
            $useDefaultLineWidth = 0;
145
 
152
 
Line 152... Line 159...
152
        } elsif ( m~^--MugPackage=(.+)~ ) {
159
        } elsif ( m~^--MugPackage=(.+)~ ) {
153
            if ( $mug_dir ) {
160
            if ( $mug_dir ) {
154
                ReportError ("ManifestFiles:--MugPackage option is only allowed once");
161
                ReportError ("ManifestFiles:--MugPackage option is only allowed once");
155
                next;
162
                next;
156
            }
163
            }
157
            $mug_dir = _LocateMugDir($1);
164
            $mug_dir = ManifestFiles::_LocateMugDir($1);
158
 
165
 
159
        } elsif ( m/^--Arch(.*)=(.+)/ ) {
166
        } elsif ( m/^--Arch(.*)=(.+)/ ) {
160
            $default_arch = $2;
167
            $default_arch = $2;
161
 
168
 
162
        } elsif ( m/^--Product=(.+)/ ) {
169
        } elsif ( m/^--Product=(.+)/ ) {
163
            $default_prod = $1;
170
            $default_prod = $1;
164
 
171
 
165
        } elsif ( m/^--NoManifestVersion/i ) {
172
        } elsif ( m/^--NoManifestVersion/i ) {
166
            $Manifest_has_version = 0;
173
            $ManifestFiles::Manifest_has_version = 0;
167
 
174
 
168
        } elsif ( m/^--PkgSubdir=(.+)/i ) {
175
        } elsif ( m/^--PkgSubdir=(.+)/i ) {
169
            if ( $pkg_subdir ) {
176
            if ( $ManifestFiles::pkg_subdir ) {
170
                ReportError ("ManifestFiles:--PkgSubdir option is only allowed once");
177
                ReportError ("ManifestFiles:--PkgSubdir option is only allowed once");
171
                next;
178
                next;
172
            }
179
            }
173
            $pkg_subdir = $1;
180
            $ManifestFiles::pkg_subdir = $1;
174
 
181
 
175
        } elsif ( m/^--ImportManifest=(.+)/i ) {
182
        } elsif ( m/^--ImportManifest=(.+)/i ) {
176
            my $import_info = _ImportManifest($1, $tier, $name);
183
            my $import_info = ManifestFiles::_ImportManifest($1, $tier, $name);
177
#DebugDumpData("ImportInfo", $import_info );
184
#DebugDumpData("ImportInfo", $import_info );
178
            push @files, {'manifest' => $import_info };
185
            push @files, {'manifest' => $import_info };
179
 
186
 
180
            #
187
            #
181
            #   Fill in details unless already provided
188
            #   Fill in details unless already provided
Line 194... Line 201...
194
        } elsif ( m/^--DmfVersion=(.+)/ ) {
201
        } elsif ( m/^--DmfVersion=(.+)/ ) {
195
            $generate_dmf = 1;
202
            $generate_dmf = 1;
196
            $dmf_version = $1;
203
            $dmf_version = $1;
197
 
204
 
198
        } elsif ( m/^--LineLength=(\d+)$/i ) {
205
        } elsif ( m/^--LineLength=(\d+)$/i ) {
199
            $ManifestLineWidth = $1;
206
            $ManifestFiles::ManifestLineWidth = $1;
200
            $useDefaultLineWidth = 0;
207
            $useDefaultLineWidth = 0;
201
 
208
 
202
        } elsif (m/^--SubManifest/i) {
209
        } elsif (m/^--SubManifest/i) {
203
            $is_sub_manifest = 1;
210
            $is_sub_manifest = 1;
204
            $Manifest_has_version = 0;
211
            $ManifestFiles::Manifest_has_version = 0;
205
            $name = $::ScmPlatform
212
            $name = $::ScmPlatform unless $name;
-
 
213
            $ManifestFiles::pkg_subdir = $name unless $ManifestFiles::pkg_subdir;
206
                unless $name;
214
            $tier = 0 unless defined($tier);
-
 
215
 
207
            $pkg_subdir = $name
216
        } elsif (m/^--(No)?Signatures/i) {
208
                unless $pkg_subdir;
217
           $ManifestFiles::noSigs = !! $1;
-
 
218
 
209
            $tier = 0
219
        } elsif (m/^--(No)?Warn/i) {
210
                unless defined($tier);
220
           $ManifestFiles::noWarn = !! $1;
211
 
221
 
212
        } else {
222
        } else {
213
            ReportError ("ManifestFiles: Unknown option or argument: $_");
223
            ReportError ("ManifestFiles: Unknown option or argument: $_");
214
 
224
 
215
        }
225
        }
Line 230... Line 240...
230
 
240
 
231
    #
241
    #
232
    #   Set ManifestLineWidth
242
    #   Set ManifestLineWidth
233
    #   The default is largely historical - for MOS
243
    #   The default is largely historical - for MOS
234
    #   
244
    #   
235
    unless (defined $ManifestLineWidth) {
245
    unless (defined $ManifestFiles::ManifestLineWidth) {
236
        $ManifestLineWidth = $useDefaultLineWidth ? 79 : 0;
246
        $ManifestFiles::ManifestLineWidth = $useDefaultLineWidth ? 79 : 0;
237
    }
247
    }
238
    Verbose("ManifestLineWidth:$ManifestLineWidth");
248
    Verbose("ManifestLineWidth:$ManifestFiles::ManifestLineWidth");
239
 
249
 
240
    #
250
    #
241
    #   Save information for processing at the end of the parsing phase
251
    #   Save information for processing at the end of the parsing phase
242
    #   Data collected from ALL the ManifestFiles directives will be collected
252
    #   Data collected from ALL the ManifestFiles directives will be collected
243
    #   and processed into one Manifest file
253
    #   and processed into one Manifest file
Line 246... Line 256...
246
    $data{tier} = $tier;
256
    $data{tier} = $tier;
247
    $data{name} = $name;
257
    $data{name} = $name;
248
    $data{files} = \@files;
258
    $data{files} = \@files;
249
    $data{fileVersions} = \%fileVersions;
259
    $data{fileVersions} = \%fileVersions;
250
    $data{mugdir} = $mug_dir;
260
    $data{mugdir} = $mug_dir;
251
    $data{pkgsubdir} = $pkg_subdir;
261
    $data{pkgsubdir} = $ManifestFiles::pkg_subdir;
252
    $data{md5} = $include_md5;
262
    $data{md5} = $include_md5;
253
    $data{dmf} = $generate_dmf;
263
    $data{dmf} = $generate_dmf;
254
    $data{arch} = $default_arch;
264
    $data{arch} = $default_arch;
255
    $data{dmf_version} = $dmf_version;
265
    $data{dmf_version} = $dmf_version;
256
    $data{is_sub_manifest} = $is_sub_manifest;
266
    $data{is_sub_manifest} = $is_sub_manifest;
257
 
267
 
258
#DebugDumpData("DirectiveData", \%data );
268
#DebugDumpData("DirectiveData", \%data );
259
 
269
 
260
    push @Manifests, \%data;
270
    push @ManifestFiles::Manifests, \%data;
261
    return;
-
 
262
}
271
}
263
 
272
 
-
 
273
#==================================================================================================
-
 
274
#   End of externally exposed methods
-
 
275
#   The remainder is package-internal
-
 
276
#
-
 
277
package ManifestFiles;
-
 
278
 
-
 
279
use strict;
-
 
280
use warnings;
-
 
281
use Digest::file qw(digest_file_hex);
-
 
282
use Digest::file qw(digest_file_base64);
-
 
283
use File::Spec::Functions qw(rel2abs);
-
 
284
use File::Basename qw(dirname);
-
 
285
 
-
 
286
use JatsError;
-
 
287
use FileUtils;
-
 
288
use ReadBuildConfig;
-
 
289
use ArrayHashUtils;
-
 
290
use JatsSystem;
-
 
291
 
-
 
292
#
-
 
293
#   Variables
-
 
294
#   Config - must be 'our'
-
 
295
#
-
 
296
our @Manifests;                     # Manifest entries
-
 
297
our $Manifest_has_version = 1;      # Create Manifest_xxxx by default
-
 
298
our $pkg_subdir;                    # Alternate packaging
-
 
299
our $ManifestLineWidth;             # Max length of lines
-
 
300
   
-
 
301
our %package_dirs;                  # Package dirs discovered and used
-
 
302
our $ManifestFiles;                 # Files in the Manifest
-
 
303
our $noWarn = 0;                    # Control unused package warnings
-
 
304
our $pkgBase;                       # Where the package is being sourced from
-
 
305
our $noSigs = 0;                    # Control signature generation
-
 
306
 
-
 
307
#
-
 
308
#   Internal
-
 
309
#
-
 
310
my $certName;                       # Signing Cert Name
-
 
311
my $certFile;                       # Path to the certificate
-
 
312
my $keyFile;                        # Path to the keyfile
-
 
313
my $opensslProg;                    # Path to openssl program
-
 
314
my $opensslConf;                    # Path to openssl config
-
 
315
 
-
 
316
BEGIN {
-
 
317
    my $path = rel2abs( __FILE__ );
-
 
318
    $pkgBase = dirname( $path );
-
 
319
}
-
 
320
 
-
 
321
#-------------------------------------------------------------------------------
-
 
322
# Bring in the DMF build requirements.
-
 
323
use lib $pkgBase;
-
 
324
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
-
 
325
use JSON;
-
 
326
 
264
#-------------------------------------------------------------------------------
327
#-------------------------------------------------------------------------------
265
# Function        : _LocateDebianFile
328
# Function        : _LocateDebianFile
266
#
329
#
267
# Description     : Locate a debian file
330
# Description     : Locate a debian file
268
#                   Internal Function
331
#                   Internal Function
Line 763... Line 826...
763
              'rewrite' => $rewrite,
826
              'rewrite' => $rewrite,
764
            };
827
            };
765
}
828
}
766
 
829
 
767
#-------------------------------------------------------------------------------
830
#-------------------------------------------------------------------------------
768
# Function        : ManifestFiles_Generate
831
# Function        : Generate
769
#
832
#
770
# Description     : Internal Function
833
# Description     : Internal Function
771
#                   Process all the collected data and create directives
834
#                   Process all the collected data and create directives
772
#                   for the creation of the manifest
835
#                   for the creation of the manifest
773
#
836
#
Line 781... Line 844...
781
#
844
#
782
# Inputs          : None
845
# Inputs          : None
783
#
846
#
784
# Returns         : Nothing
847
# Returns         : Nothing
785
#
848
#
786
sub ManifestFiles_Generate
849
sub Generate
787
{
850
{
788
    Debug ("ManifestFiles_Generate");
851
    Debug ("Generate");
789
    Message ("Generating Manifest File");
852
    Message ("Generating Manifest File");
790
 
853
 
791
    #
854
    #
792
    #   Need at least one Manifest Entry
855
    #   Need at least one Manifest Entry
793
    #
856
    #
794
    return unless ( @Manifests );
-
 
795
#DebugDumpData ( "Manifests", \@Manifests );
857
#DebugDumpData ( "Manifests", \@Manifests );
-
 
858
    return unless ( @Manifests );
-
 
859
 
-
 
860
    #
-
 
861
    #   Init the signing subsystem
-
 
862
    # 
-
 
863
    GenSigInit();
796
 
864
 
797
    #
865
    #
798
    #   Determine the target packaging directory
866
    #   Determine the target packaging directory
799
    #   Default is .../mug
867
    #   Default is .../mug
800
    #
868
    #
Line 818... Line 886...
818
    my $manifest_dir = "$::ScmPlatform.LIB";
886
    my $manifest_dir = "$::ScmPlatform.LIB";
819
    System( "$::GBE_BIN/mkdir -p $manifest_dir" );
887
    System( "$::GBE_BIN/mkdir -p $manifest_dir" );
820
 
888
 
821
    my $manifest_file = $manifest_dir . '/Manifest';
889
    my $manifest_file = $manifest_dir . '/Manifest';
822
    $manifest_file .= '_' . $::ScmBuildVersion if ( $Manifest_has_version );
890
    $manifest_file .= '_' . $::ScmBuildVersion if ( $Manifest_has_version );
823
    ToolsetGenerate( $manifest_file );
891
    ::ToolsetGenerate( $manifest_file );
824
    Verbose ("ManifestFiles_Generate: File: $manifest_file");
892
    Verbose ("Generate: File: $manifest_file");
825
 
-
 
826
    PackageFile ('*', $manifest_file, '--Subdir=' . $pkgdir, '--Strip' );
-
 
827
 
893
 
-
 
894
    PackageManifestFile ($manifest_file, $pkgdir);
828
    open (MF, '>', $manifest_file ) || Error ("Cannot create the Manifest file: $manifest_file");
895
    open (MF, '>', $manifest_file ) || Error ("Cannot create the Manifest file: $manifest_file");
829
 
896
 
830
    binmode (MF);
897
    binmode (MF);
831
 
898
 
832
    if ($Manifests[0]->{is_sub_manifest} == 1) {
899
    if ($Manifests[0]->{is_sub_manifest} == 1) {
Line 839... Line 906...
839
        print_mf ("[Version],$::ScmBuildVersion");
906
        print_mf ("[Version],$::ScmBuildVersion");
840
        print_mf ("#");
907
        print_mf ("#");
841
    }
908
    }
842
 
909
 
843
    #
910
    #
-
 
911
    #   Insert the certificate used to verify the files
-
 
912
    #       Currently we only handle one certificate
-
 
913
    #       Certificate name must end in .crt
-
 
914
    #   In production the .crt file MUST be signed by the VixManifestRoot-CA
-
 
915
    #   The assumtion is that the public key for VixManifestRoot-CA is on the device
-
 
916
    #
-
 
917
    unless (($Manifests[0]->{is_sub_manifest} == 1) || $noSigs) {
-
 
918
        print_mf ("");
-
 
919
        print_mf ("#");
-
 
920
        print_mf ("# Signing Certificate");
-
 
921
        print_mf ("[Certificate],$certName");
-
 
922
 
-
 
923
        ::PackageFile ('*', $certFile, '--Subdir=' . $pkgdir, '--Strip' );
-
 
924
    }
-
 
925
        
-
 
926
    #
844
    #   Process each tier in the order presented in the source file
927
    #   Process each tier in the order presented in the source file
845
    #
928
    #
846
    my $last_was_comment = 0;
929
    my $last_was_comment = 0;
847
    foreach my $entry ( @Manifests )
930
    foreach my $entry ( @Manifests )
848
    {
931
    {
Line 888... Line 971...
888
                }
971
                }
889
                if (exists $entry->{fileVersions} && exists $entry->{fileVersions}{$file} ) {
972
                if (exists $entry->{fileVersions} && exists $entry->{fileVersions}{$file} ) {
890
                    push @items, "VERSION=" . $entry->{fileVersions}{$file};
973
                    push @items, "VERSION=" . $entry->{fileVersions}{$file};
891
                }
974
                }
892
                print_mf (join (',', @items));
975
                print_mf (join (',', @items));
893
                PackageFile ('*', $file, '--Subdir=' . $pkgdir, '--Strip' );
976
                PackageManifestFile ($file, $pkgdir);
894
                $last_was_comment = 0;
977
                $last_was_comment = 0;
895
            }
978
            }
896
 
979
 
897
            if ( my $file = $fentry->{'filenocopy'} )
980
            if ( my $file = $fentry->{'filenocopy'} )
898
            {
981
            {
Line 927... Line 1010...
927
                            if ($include_md5 && $md5_added == 0) { # add md5 if requested and not already added from submanifest
1010
                            if ($include_md5 && $md5_added == 0) { # add md5 if requested and not already added from submanifest
928
                                my $md5 = digest_file_hex($emf->{'file_base'} . '/' . $item->{'file_name'}, 'MD5');
1011
                                my $md5 = digest_file_hex($emf->{'file_base'} . '/' . $item->{'file_name'}, 'MD5');
929
                                push @items, "MD5=$md5";
1012
                                push @items, "MD5=$md5";
930
                            }
1013
                            }
931
                            print_mf (join (',', @items));
1014
                            print_mf (join (',', @items));
932
                            PackageFile ('*', $emf->{'file_base'}. '/' . $item->{'file_name'}, '--Subdir=' . $pkgdir, '--Strip' );
1015
                            PackageManifestFile ( $emf->{'file_base'} . '/' . $item->{'file_name'}, $pkgdir);
933
                        }
1016
                        }
934
                        elsif (defined($item->{'comment'})) {
1017
                        elsif (defined($item->{'comment'})) {
935
                            print_mf($item->{'comment'});
1018
                            print_mf($item->{'comment'});
936
                        }
1019
                        }
937
                    }
1020
                    }
938
                    print_mf('#');
1021
                    print_mf('#');
939
                }
1022
                }
940
                else {
1023
                else {
941
                    print_mf ($_) foreach  ( @{$emf->{'contents'}} );
1024
                    print_mf ($_) foreach  ( @{$emf->{'contents'}} );
942
                    foreach my $item ( @{$emf->{'items'}}) {
1025
                    foreach my $item ( @{$emf->{'items'}}) {
-
 
1026
                        if (defined($item->{'file_name'})) {
943
                        PackageFile ('*', $emf->{'file_base'}. '/' . $item->{'file_name'}, '--Subdir=' . $pkgdir, '--Strip' )
1027
                            PackageManifestFile ( $emf->{'file_base'} . '/' . $item->{'file_name'}, $pkgdir);
944
                            if (defined($item->{'file_name'}));
1028
                        }
945
                    }
1029
                    }
946
                    print_mf('#');
1030
                    print_mf('#');
947
                }
1031
                }
948
            }
1032
            }
949
        }
1033
        }
Line 966... Line 1050...
966
                if ($include_md5) {
1050
                if ($include_md5) {
967
                    my $md5 = digest_file_hex($file, 'MD5');
1051
                    my $md5 = digest_file_hex($file, 'MD5');
968
                    push @items, "MD5=$md5" ;
1052
                    push @items, "MD5=$md5" ;
969
                }
1053
                }
970
                print_mf (join (',', @items));
1054
                print_mf (join (',', @items));
971
                PackageFile ('*', $file, '--Subdir=mug', '--Strip' );
1055
                PackageManifestFile ($file, 'mug');
972
            }
1056
            }
973
        }
1057
        }
974
    }
1058
    }
975
 
1059
 
976
    #
1060
    #
Line 979... Line 1063...
979
    print_mf ("# end of $::ScmBuildPackage");
1063
    print_mf ("# end of $::ScmBuildPackage");
980
    close MF;
1064
    close MF;
981
    ErrorDoExit();
1065
    ErrorDoExit();
982
 
1066
 
983
    #
1067
    #
-
 
1068
    #   Post process files from the manifest
-
 
1069
    #   May include signature generation
-
 
1070
    GenSignatures();
-
 
1071
 
-
 
1072
    #
984
    #   Sanity test of packages that did not provide a debian file
1073
    #   Sanity test of packages that did not provide a debian file
985
    #   Just a hint that something may have been missed
1074
    #   Just a hint that something may have been missed
986
    #
1075
    #
-
 
1076
    unless ($noWarn) {
987
    my @not_used_packages;
1077
        my @not_used_packages;
988
    foreach my $package_dir ( getPackagePaths ('--All') )
1078
        foreach my $package_dir ( getPackagePaths ('--All') )
989
    {
-
 
990
        next if ( $package_dir =~ m~/manifest-tool/~ );
-
 
991
        unless ( exists $package_dirs{$package_dir}{used} )
-
 
992
        {
1079
        {
-
 
1080
            next if ( $package_dir =~ m~/manifest-tool/~ );
-
 
1081
            unless ( exists $package_dirs{$package_dir}{used} )
-
 
1082
            {
993
            push @not_used_packages, $package_dir;
1083
                push @not_used_packages, $package_dir;
-
 
1084
            }
-
 
1085
        }
-
 
1086
        if ( @not_used_packages )
-
 
1087
        {
-
 
1088
            Warning ("Packages that did not contribute packages to the manifest:",
-
 
1089
                      @not_used_packages );
994
        }
1090
        }
995
    }
1091
    }
-
 
1092
}
-
 
1093
 
-
 
1094
#-------------------------------------------------------------------------------
-
 
1095
# Function        : print_mf
-
 
1096
#
-
 
1097
# Description     : Internal Function
-
 
1098
#                   Print one line to the Manifest File
-
 
1099
#                   Checks the length of the line being created
-
 
1100
#
-
 
1101
# Inputs          : $line
-
 
1102
#
-
 
1103
# Returns         :
-
 
1104
#
-
 
1105
 
-
 
1106
sub print_mf
-
 
1107
{
996
    if ( @not_used_packages )
1108
    foreach  ( @_ )
997
    {
1109
    {
-
 
1110
        my $ll = length ($_);
998
        Warning ("Packages that did not contribute packages to the manifest:",
1111
        ReportError ( "Manifest line too long: $ll. Max is $ManifestLineWidth.",
-
 
1112
                "Line: $_" ) if ( $ManifestLineWidth && $ll > $ManifestLineWidth);
999
                  @not_used_packages );
1113
        print MF $_ . "\n";
1000
    }
1114
    }
-
 
1115
}
-
 
1116
 
-
 
1117
#-------------------------------------------------------------------------------
-
 
1118
# Function        : PackageManifestFile  
-
 
1119
#
-
 
1120
# Description     : Process and package a manifest file
-
 
1121
#                       Reatin a list of files in the mnifest to allow postprocessing
-
 
1122
#                       such as signature generation
-
 
1123
#                   
-
 
1124
#
-
 
1125
# Inputs          : $srcFile        - Full path to the source file
-
 
1126
#                   $pkgPath        - Target path within the package    
-
 
1127
#
-
 
1128
# Returns         : Nothing
-
 
1129
#
-
 
1130
sub PackageManifestFile {
-
 
1131
    my ($srcFile, $pkgPath) = @_;
-
 
1132
    push @{$ManifestFiles}, ({srcFile => $srcFile, pkgPath => $pkgPath});
1001
 
1133
 
-
 
1134
    ::PackageFile ('*', $srcFile, '--Subdir=' . $pkgPath, '--Strip' );
-
 
1135
}
-
 
1136
 
-
 
1137
#-------------------------------------------------------------------------------
-
 
1138
# Function        : GenSigInit 
-
 
1139
#
-
 
1140
# Description     : Initialise the Siganture Generation process
-
 
1141
#                   Populate some globals for use in creating the manifest
-
 
1142
#                   Bail if there are errors
-
 
1143
#
-
 
1144
# Inputs          : 
-
 
1145
#
-
 
1146
# Returns         : 
-
 
1147
#
-
 
1148
sub GenSigInit
-
 
1149
{
-
 
1150
    Debug("GenSigInit: $noSigs");
1002
    return;
1151
    return if $noSigs;
-
 
1152
 
-
 
1153
    my @warnings;
1003
 
1154
 
1004
    #-------------------------------------------------------------------------------
-
 
1005
    # Function        : print_mf
-
 
1006
    #
1155
    #
1007
    # Description     : Internal Function
1156
    #   Signatures 'should' be generated for a target paltform of 'MANSIG'
1008
    #                   Print one line to the Manifest File
1157
    #       In the automated build system this will be a controlled machine
1009
    #                   Checks the length of the line being created
1158
    #   Warn if attemting to create signatures for a different target    
1010
    #
1159
    #
1011
    # Inputs          : $line
1160
    push @warnings, "# Package build for platform other than MANSIG - will generate test signatures" if ($::ScmPlatform ne 'MANSIG');
-
 
1161
 
-
 
1162
 
1012
    #
1163
    #
-
 
1164
    #   Locate the signature file
-
 
1165
    #   Use an internal key that unless being run on a controlled build machine
-
 
1166
    #   The controlled build machine will have
-
 
1167
    #       GBE_MANIFEST_KEY set to a path that contains the keyfile
-
 
1168
    #           Yes, a user can fudge this, but not with the real file
1013
    # Returns         :
1169
    #          
-
 
1170
    #  Internal cert created with:
-
 
1171
    #  openssl req -nodes -x509 -sha256 -newkey rsa:4096 -keyout VixPulseManifestTest.key -out VixPulseManifestTest.crt -days 10000 -subj "/C=AU/CN=Vix.Pulse.Manifest.Test"
1014
    #
1172
    #
1015
 
-
 
1016
    sub print_mf
1173
    $keyFile = CatPaths( $pkgBase, 'VixPulseManifestTest.key');
1017
    {
-
 
1018
        foreach  ( @_ )
1174
    my $localKey = 1;
1019
        {
-
 
1020
            my $ll = length ($_);
1175
    if (exists $ENV{GBE_MANIFEST_KEY} ) {
1021
            ReportError ( "Manifest line too long: $ll. Max is $ManifestLineWidth.",
-
 
1022
                    "Line: $_" ) if ( $ManifestLineWidth && $ll > $ManifestLineWidth);
-
 
1023
            print MF $_ . "\n";
1176
        $keyFile = $ENV{GBE_MANIFEST_KEY};
1024
        }
1177
        $localKey = 0;
1025
    }
1178
    }
-
 
1179
    $certFile = $keyFile;
-
 
1180
    $certFile =~ s~\.key$~.crt~;
-
 
1181
    $certName = $certFile;
-
 
1182
    $certName =~ s~.*[\\/]~~;
-
 
1183
 
-
 
1184
    ReportError ("Manifest signing key not found", $keyFile) unless -f $keyFile;
-
 
1185
    ReportError ("Manifest signing key not found", $certFile) unless -f $certFile;
-
 
1186
 
-
 
1187
    push @warnings, "#  Using uncontrolled test key to sign the manifest" if ($localKey);
-
 
1188
    Warning("#############################################################", "#",
-
 
1189
             @warnings,
-
 
1190
            "#", "#############################################################") if (@warnings);
-
 
1191
 
-
 
1192
    #
-
 
1193
    #   Locate and setup openssl
-
 
1194
    #   Should be provided by a package
-
 
1195
    #   set OPENSSL_CONF=...../openssl.cfg 
-
 
1196
    #   
-
 
1197
    $opensslProg = ::ToolExtensionProgram( 'openssl', '', '.exe');
-
 
1198
    ReportError ("The openssl utility is not available. Must be provided by a package") unless $opensslProg;  
-
 
1199
 
-
 
1200
    #   Generate  a dummy openssl.cnf - to keep the uitility happy (quiet)
-
 
1201
    $opensslConf = FullPath(CatPaths( $::ScmRoot, $::ScmInterface, 'openssl.cfg'));
-
 
1202
    TouchFile($opensslConf);
-
 
1203
    ::ToolsetGenerate($opensslConf);
-
 
1204
    $ENV{OPENSSL_CONF}= $opensslConf;
-
 
1205
 
-
 
1206
    ErrorDoExit();
-
 
1207
    Message("OpenSsl Prog: $opensslProg");
-
 
1208
    Message("OpenSsl Conf: $opensslConf");
-
 
1209
    Message("Signing with: $keyFile");
-
 
1210
 
1026
}
1211
}
1027
 
1212
 
-
 
1213
#-------------------------------------------------------------------------------
1028
# Bring in the DMF build requirements.
1214
# Function        : GenSignatures 
-
 
1215
#
-
 
1216
# Description     : Generate signatures on all packages
-
 
1217
#
-
 
1218
# Inputs          : Used the array of files in $ManifestFiles 
-
 
1219
#
-
 
1220
# Returns         : Nothing 
-
 
1221
#
1029
my $directory;
1222
sub GenSignatures
1030
BEGIN {
1223
{
1031
    use File::Spec::Functions qw(rel2abs);
1224
    Debug("GenSignatures: $noSigs");
1032
    use File::Basename qw(dirname);
1225
    return if $noSigs;
1033
 
1226
 
-
 
1227
    foreach my $entry ( @{$ManifestFiles}) {
-
 
1228
        Verbose("PostProcess: $entry->{srcFile}, $entry->{pkgPath}");
-
 
1229
 
-
 
1230
        #
-
 
1231
        #   Generate the name of the signature file
-
 
1232
        #   Generate Packaging directives for the signature
-
 
1233
        #   
-
 
1234
        my $sigFileName = CatPaths( "$::ScmPlatform.LIB", StripDir($entry->{srcFile}) . '.sig' );
-
 
1235
        ::PackageFile ('*', $sigFileName, '--Subdir=' . $entry->{pkgPath}, '--Strip' );
-
 
1236
        ::ToolsetGenerate($sigFileName);
-
 
1237
 
-
 
1238
        #
-
 
1239
        #   Generate package signature
-
 
1240
        #   The required custom(vix) 'sig' file has the format:
-
 
1241
        #       line-1 : name of the certificate to decode
-
 
1242
        #                Assume its the keyname with .key -> .crt - with no path elements
-
 
1243
        #       line-2 : Text representation of the signature
-
 
1244
        #                The openssl dgst command generates a binary output by default
-
 
1245
        #                This is then converted into base64 with -A option
-
 
1246
        #
-
 
1247
        my $tmp1 = CatPaths( "$::ScmPlatform.LIB", 'temp1');
-
 
1248
        my $tmp2 = CatPaths( "$::ScmPlatform.LIB", 'temp2');
-
 
1249
        ::ToolsetGenerate($tmp1, $tmp2);
-
 
1250
 
-
 
1251
        Verbose("Signing: " . StripDir($entry->{srcFile}));
-
 
1252
        System( '--Exit', '--NoShell', $opensslProg, 'dgst', '-sha256', '-sign', $keyFile, '-out', $tmp1, $entry->{srcFile} );
-
 
1253
        System( '--Exit', '--NoShell', $opensslProg, 'base64', '-A', '-in', $tmp1, '-out', $tmp2 );
1034
    my $path = rel2abs( __FILE__ );
1254
        my $base64 = TagFileRead($tmp2);
-
 
1255
 
-
 
1256
        #
-
 
1257
        #   In a development environment we don't want to create the signature file
-
 
1258
        #   every time we run. Its noisy. Solution:
-
 
1259
        #       Only generate a signature file if:
-
 
1260
        #           It doesn't exist
-
 
1261
        #           A copy of the signed digest doesn't exist (.fpp)
-
 
1262
        #           The signed digest has changed
-
 
1263
        #   
-
 
1264
        my $fppFileName = CatPaths( "$::ScmPlatform.LIB", StripDir($entry->{srcFile}) . '.fpp' );
-
 
1265
        ::ToolsetGenerate($fppFileName);
-
 
1266
        my $genSig = 0;
-
 
1267
        $genSig = 1 unless ( -e $sigFileName &&  -e $fppFileName);
-
 
1268
        unless ($genSig) {
-
 
1269
            my $ffp = TagFileRead($fppFileName);
1035
    $directory = dirname( $path );
1270
            $genSig = ($ffp ne $base64);
-
 
1271
        }
-
 
1272
 
-
 
1273
        if ($genSig) {
-
 
1274
            FileCreate($sigFileName, $certName, $base64);
-
 
1275
            rename $tmp2, $fppFileName ;
-
 
1276
        }
-
 
1277
 
-
 
1278
        unlink $tmp1;
-
 
1279
        unlink $tmp2;
-
 
1280
    }
-
 
1281
    unlink $opensslConf;
1036
}
1282
}
1037
use lib $directory;
-
 
1038
 
1283
 
1039
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
-
 
1040
use JSON;
-
 
1041
 
1284
 
1042
#-------------------------------------------------------------------------------
1285
#-------------------------------------------------------------------------------
1043
# Function        : DmfGenerate
1286
# Function        : DmfGenerate
1044
#
1287
#
1045
# Description     : Import an existing manifest
1288
# Description     : Import an existing manifest
Line 1129... Line 1372...
1129
 
1372
 
1130
    # Save our manifest.
1373
    # Save our manifest.
1131
    open (J, '>', $manifest_file ) || Error ("Cannot create the DMF Manifest file");
1374
    open (J, '>', $manifest_file ) || Error ("Cannot create the DMF Manifest file");
1132
    binmode (J);
1375
    binmode (J);
1133
    print J $json;
1376
    print J $json;
1134
 
-
 
1135
    close J;
1377
    close J;
1136
 
1378
 
1137
    GenerateCesFile($manifest_file, $aum_file, 0x2, $gen_time, $aum_filename);
1379
    GenerateCesFile($manifest_file, $aum_file, 0x2, $gen_time, $aum_filename);
1138
 
1380
 
1139
    $zip->addFile($aum_file, $aum_filename);
1381
    $zip->addFile($aum_file, $aum_filename);
Line 1147... Line 1389...
1147
    PackageFile('*', $manifest_file, '--Strip');
1389
    PackageFile('*', $manifest_file, '--Strip');
1148
 
1390
 
1149
}
1391
}
1150
 
1392
 
1151
#-------------------------------------------------------------------------------
1393
#-------------------------------------------------------------------------------
1152
# Function        : DmfGenerate
1394
# Function        : GenerateCesFile
1153
#
1395
#
1154
# Description     : Import an existing manifest
1396
# Description     : Import an existing manifest
1155
#
1397
#
1156
# Inputs          : src_file     - The input file.
1398
# Inputs          : src_file     - The input file.
1157
#                   dst_file     - The output CES file.
1399
#                   dst_file     - The output CES file.