-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_packages_list
More file actions
executable file
·674 lines (555 loc) · 15.2 KB
/
build_packages_list
File metadata and controls
executable file
·674 lines (555 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#!/usr/bin/perl
use FindBin;
use lib $FindBin::Bin;
use strict;
use warnings FATAL => 'all';
use IO::Handle;
use File::Basename;
use File::Temp;
use _kxLab;
#
# Generate $(HARDWARE).pkglist file for current directory
#
# usage:
# $0 topdir toolchain hardware
#
# where:
# 'topdir' - is a absolute path to the top directory of checked out branch
# 'toolchain' - is a TOOLCHAIN name
# 'hardware' - is a HARDWARE variant
#
# global variables
my ($build_system);
my ($topdir, $toolchain, $hardware, $flavour);
my ($target_build_dir, $requires_file);
my ($pkglist_file);
my ($distro_name, $distro_version, $url);
my $tarball_suffix = "txz";
my %sub_trees;
my %tree;
sub usage
{
print <<EOF;
Usage: $0 topdir toolchain hardware
Where:
topdir - is a absolute path to the top of checked out branch;
toolchain - is a TOOLCHAIN name;
hardware - is a HARDWARE variant.
EOF
exit;
}
#
# Getting information from build-system/constants.mk
#
sub distro_name
{
my $build_system = shift;
my $name;
open( FILE, "< $build_system/constants.mk" );
while( <FILE> )
{
if( /^DISTRO_NAME(.+= +)(.+)/ )
{
$name = $2;
}
}
close( FILE );
return $name;
}
sub distro_version
{
my $build_system = shift;
my $name;
open( FILE, "< $build_system/constants.mk" );
while( <FILE> )
{
if( /^DISTRO_VERSION(.+= +)(.+)/ )
{
$name = $2;
}
}
close( FILE );
return $name;
}
sub bug_url
{
my $build_system = shift;
my $url;
open( FILE, "< $build_system/constants.mk" );
while( <FILE> )
{
if( /^BUG_URL(.+= +)(.+)/ )
{
$url = $2;
}
}
close( FILE );
return $url;
}
#
# Getting information from Makefile
#
sub pkg_rootfs_target
{
my $makefile = shift;
my $install = "";
open( FILE, "< $makefile" );
while( <FILE> )
{
if( /^ROOTFS_TARGETS(.+= +)(.+)/ )
{
if( $2 ne "" ) { $install = "install"; }
}
elsif( /^ROOTFS_UPDATE_TARGETS(.+= +)(.+)/ )
{
if( $2 ne "" ) { $install = "update"; }
}
}
close( FILE );
if( $install eq "" ) { $install = "no"; }
return $install;
}
sub pkg_group
{
my $makefile = shift;
my $group;
open( FILE, "< $makefile" );
while( <FILE> )
{
if( /^PKG_GROUP(.+= +)(.+)/ )
{
$group = $2;
}
}
close( FILE );
return $group;
}
sub pkg_name
{
my $makefile = shift;
my $name = "";
open( FILE, "< $makefile" );
while( <FILE> )
{
if( /^[A-Z_0-9]*_PKG_NAME(.+= +)(.+)/ )
{
$name = $2;
}
}
close( FILE );
return $name;
}
sub pkg_version
{
my $makefile = shift;
my $version;
open( FILE, "< $makefile" );
while( <FILE> )
{
if( /^[A-Z_0-9]*_PKG_VERSION(.+= +)(.+)/ )
{
$version = $2;
}
}
close( FILE );
return $version;
}
sub pkg_license
{
my $makefile = shift;
my $license;
open( FILE, "< $makefile" );
while( <FILE> )
{
if( /^[A-Z_0-9]*_PKG_LICENSE(.+= +)(.+)/ )
{
$license = $2;
}
}
close( FILE );
return $license;
}
sub pkg_short_description
{
my $makefile = shift;
my $description;
open( FILE, "< $makefile" );
while( <FILE> )
{
if( /^[A-Z_0-9]*_PKG_SHORT_DESCRIPTION(.+= +)(.+)/ )
{
$description = $2;
}
}
close( FILE );
#
# In Makefiles we have to mask characters '\', '&', '*', '(', ')' inside
# the new value in the assignment operator with backslash. So, for axample,
# the value "name & \ * ( ) end" we have to assign as follow
#
# ..._SHORT_DESCRIPTION = name \& \\ \* \( \) end
#
# Here we have to remove backslashes and fill escaped symbols as is:
#
$description =~ s/\\(.?)/$1/g;
return $description;
}
sub get_treedirs
{
my @list;
seek( REQUIRES_FILE, 0, SEEK_SET );
while( <REQUIRES_FILE> )
{
if( /^TREEDIRS(.+= +)(.+)/ )
{
@list = split( ' ', $2 );
}
}
return @list;
}
sub get_root
{
my $root;
seek( REQUIRES_FILE, 0, SEEK_SET );
while( <REQUIRES_FILE> )
{
if( /^# ROOT(=)(.+)/ )
{
$root = $2;
}
}
return $root;
}
sub get_deps
{
my %deps;
seek( REQUIRES_FILE, 0, SEEK_SET );
while( <REQUIRES_FILE> )
{
if( /(.+)(: +)(.+)/ )
{
$deps{$1} = $3;
}
}
return %deps;
}
my $root_node = 1;
#
# PACKAGE HASH:
# ============
#
# name => $(PKG_NAME) from Makefile
# version => $(PKG_VERSION) from Makefile
# group => $(PKG_GROUP) from Makefile {app,base,dev,libs,net,...}
#
# arch => $toolchain from comandline args
# hardware => $hardware from comandline args
# flavour => $flavour from comandline args for ROOT pkg, from REQUIRES for dependencies
# tarball => "$name-$version-$arch-$distro_name-$distro_version.$tarball_suffix"
#
# distro_name => $(DISTRO_NAME) from build-system/constants.mk
# distro_version => $(DISTRO_VERSION) from build-system/constants.mk
# url => $(BUG_URL) from build-system/constants.mk
# license => from Makefile
# short_description => from Makefile
# description => first line from .DESCRIPTION
# uncompressed_size => from .PKGINFO
# total_files => from .PKGINFO
#
# dir => path to Makefile from .$(HW)_requires
# children =>
#
sub fill_package_info
{
my $base_dir = shift;
my $makefile = shift;
my $flavour = shift;
my ( $product_path, $tarball_file );
my %pkg;
$pkg{'dir'} = $base_dir;
$pkg{'install'} = pkg_rootfs_target( $makefile );
$pkg{'name'} = pkg_name( $makefile );
if( $pkg{'name'} eq "" )
{
# There is no package for this Makefile
$pkg{'name'} = $pkg{'dir'};
return %pkg;
}
$pkg{'version'} = pkg_version( $makefile );
$pkg{'arch'} = $toolchain;
$pkg{'hardware'} = $hardware;
$pkg{'flavour'} = $flavour;
$pkg{'group'} = pkg_group( $makefile );
$pkg{'distro_name'} = $distro_name;
$pkg{'distro_version'} = $distro_version;
$pkg{'url'} = $url;
$pkg{'license'} = pkg_license( $makefile );
$pkg{'short_description'} = pkg_short_description( $makefile );
$pkg{'tarball'} = $pkg{'name'} . "-" .
$pkg{'version'} . "-" .
$pkg{'arch'} . "-" .
$distro_name . "-" .
$distro_version . "." .
$tarball_suffix;
return %pkg;
}
#
# Parse the command line options
#
# Get the rest arguments of the command line
$topdir = shift;
$toolchain = shift;
$hardware = shift;
$flavour = shift;
my $makefile = "Makefile";
if( ! defined $topdir or $topdir eq "" ) { usage; }
if( ! defined $toolchain or $toolchain eq "" ) { usage; }
if( ! defined $hardware or $hardware eq "" ) { usage; }
if( ! defined $flavour or $flavour eq "" ) { $flavour = ""; }
_kxLab::error( "$0: $topdir is not a directory" ) if( ! -d $topdir );
_kxLab::error( "$0: Makefile missing: $makefile" ) if ( ! -f $makefile );
$build_system = $topdir . "/build-system";
$distro_name = distro_name( $build_system );
$distro_version = distro_version( $build_system );
$url = bug_url( $build_system );
if( $flavour eq "" )
{
$target_build_dir = "." . $toolchain . "/" . $hardware;
}
else
{
$target_build_dir = "." . $toolchain . "/" . $hardware . "/" . $flavour;
}
$requires_file = $target_build_dir . "/.requires";
if( $flavour eq "" )
{
$pkglist_file = $target_build_dir . "/" . $hardware . ".pkglist";
}
else
{
$pkglist_file = $target_build_dir . "/" . $hardware . "-" . $flavour . ".pkglist";
}
# open the intput file
open(REQUIRES_FILE, "< $requires_file") or
_kxLab::error( "$0: Could not open $requires_file file: $!" );
# open the output files
open(PKGLIST_FILE, "> $pkglist_file") or
_kxLab::error( "$0: Could not open $pkglist_file file: $!" );
my $root = get_root();
my @treedirs = get_treedirs();
my %deps = get_deps();
#
# This is the root package
#
%tree = fill_package_info( $root, $makefile, $flavour );
my %sequence;
my $order = 0;
#################################################################
# if( there is any dependencies )
#
if( %deps )
{
my @dep_keys = keys %deps;
my $count = scalar( keys %deps );
foreach my $dir ( @treedirs )
{
if( ! grep { $_ eq $dir } @dep_keys )
{
my $key = $dir;
$sequence{$key} = ++$order;
@treedirs = grep { $_ ne $key } @treedirs;
# Split dir^flavour:
my ($d, $f);
$d = `echo $dir | cut -f 1 -d '^'`;
$d =~ s/^\s+|\s+$//;
if( $dir =~ m/\^/ )
{
$f = `echo $dir | cut -f 2 -d '^'`;
$f =~ s/^\s+|\s+$//;
}
else
{
$f = "";
}
# Insert into sub_trees:
my %pkg = fill_package_info( $d, $topdir . "/" . $d . "/Makefile", $f );
$sub_trees{$dir} = \%pkg;
delete $deps{$dir};
}
}
for( my $i = 0; $i < $count; ++$i )
{
my @installed = keys %sequence;
foreach my $key (sort keys %deps)
{
my $ok = 1;
my @dirs = split( ' ', $deps{$key} );
if( $key ne "all" )
{
foreach my $dir ( @dirs )
{
if( ! grep { $_ eq $dir } @installed )
{
$ok = 0;
}
}
if( $ok == 1 )
{
$sequence{$key} = ++$order;
# Split dir^flavour:
my ($d, $f);
$d = `echo $key | cut -f 1 -d '^'`;
$d =~ s/^\s+|\s+$//;
if( $key =~ m/\^/ )
{
$f = `echo $key | cut -f 2 -d '^'`;
$f =~ s/^\s+|\s+$//;
}
else
{
$f = "";
}
# create package node:
my %pkg = fill_package_info( $d, $topdir . "/" . $d . "/Makefile", $f );
# add children:
foreach my $dir ( @dirs )
{
my $child = $sub_trees{$dir};
push( @{$pkg{'children'}}, $child );
}
# insert new sub tree into $sub_tree:
$sub_trees{$key} = \%pkg;
delete $deps{$key};
}
}
}
}
#
# The root node children
#
my @dirs = split( ' ', $deps{'all'} );
foreach my $dir ( @dirs )
{
my $child = $sub_trees{$dir};
push( @{$tree{'children'}}, $child );
}
}
else
{
my %pkg;
$pkg{'dir'} = "void";
$pkg{'name'} = "void";
push( @{$tree{'children'}}, \%pkg );
}
#
# End if( there is any dependencies )
#################################################################
#################################################################
# Building Required Packages List:
#
sub compare_order
{
$sequence{$a} <=> $sequence{$b};
}
print PKGLIST_FILE "#\n";
print PKGLIST_FILE "# file format:\n";
print PKGLIST_FILE "# ===========\n";
print PKGLIST_FILE "#\n";
print PKGLIST_FILE "# Each line contains six fields separated by colon symbol ':' like following.\n";
print PKGLIST_FILE "#\n";
print PKGLIST_FILE "# pkgname:version:description:tarball:procedure:priority\n";
print PKGLIST_FILE "#\n";
print PKGLIST_FILE "# where:\n";
print PKGLIST_FILE "#\n";
print PKGLIST_FILE "# pkgname - should be the same as the value of pkgname in the '.DESCRIPTION' file;\n";
print PKGLIST_FILE "# version - package version for showing in check list dialog box if this file is\n";
print PKGLIST_FILE "# used to complete common check dialog for installing group of packages;\n";
print PKGLIST_FILE "# description - short description for showing in check list dialog box if this file is\n";
print PKGLIST_FILE "# used to complete common check dialog for installing group of packages;\n";
print PKGLIST_FILE "# tarball - should end in '." . $tarball_suffix . "';\n";
print PKGLIST_FILE "# procedure - installation procedure {install | update}:\n";
print PKGLIST_FILE "# * 'install' - if package requires normal installation,\n";
print PKGLIST_FILE "# * 'update' - if already installed package should be updated by this\n";
print PKGLIST_FILE "# package archive;\n";
print PKGLIST_FILE "# priority - { REQUIRED|RECOMMENDED|OPTIONAL|SKIP }\n";
print PKGLIST_FILE "# synonims:\n";
print PKGLIST_FILE "# { REQUIRED | required | REQ | req }\n";
print PKGLIST_FILE "# { RECOMMENDED | recommended | REC | rec }\n";
print PKGLIST_FILE "# { OPTIONAL | optional | OPT | opt }\n";
print PKGLIST_FILE "# { SKIP | skip | SKP | skp }\n";
print PKGLIST_FILE "#\n";
my $packages_done = 0;
sub print_result
{
my $out_string = sprintf( "####### Packages Install List (done: %4d packages)\n", $packages_done );
print $out_string;
}
print "#######\n";
foreach my $dir (sort compare_order( (keys %sequence) ))
{
my $package;
if( $dir ne "all" )
{
$package = $sub_trees{$dir};
#
# Currently gcc-runtime has not ROOTFS_TARGET and not all packages requires GCC.
# We will not add GCC in this procedure forcibly. But developers have to care about
# competing packages GCC and gcc-runtime.
#
if( $package->{'install'} ne "no" )
{
if( $package->{'flavour'} eq "" )
{
print PKGLIST_FILE $package->{'name'} . ":" .
$package->{'version'} . ":" .
$package->{'short_description'} . ":" .
$package->{'group'} . "/" .
$package->{'tarball'} . ":" .
$package->{'install'} . ":REQUIRED\n";
}
else
{
print PKGLIST_FILE $package->{'name'} . ":" .
$package->{'version'} . ":" .
$package->{'short_description'} . ":" .
$package->{'group'} . "/" .
$package->{'flavour'} . "/" .
$package->{'tarball'} . ":" .
$package->{'install'} . ":REQUIRED\n";
}
++$packages_done;
}
}
}
if( $tree{'install'} ne "no" )
{
if( $tree{'flavour'} eq "" )
{
print PKGLIST_FILE $tree{'name'} . ":" .
$tree{'version'} . ":" .
$tree{'short_description'} . ":" .
$tree{'group'} . "/" .
$tree{'tarball'} . ":" .
$tree{'install'} . ":REQUIRED\n";
}
else
{
print PKGLIST_FILE $tree{'name'} . ":" .
$tree{'version'} . ":" .
$tree{'short_description'} . ":" .
$tree{'group'} . "/" .
$tree{'flavour'} . "/" .
$tree{'tarball'} . ":" .
$tree{'install'} . ":REQUIRED\n";
}
++$packages_done;
}
print_result();
print "#######\n";
#
# End of Building Required Packages List.
#################################################################
# close input files
close REQUIRES_FILE;
# close output files
close PKGLIST_FILE;