author | Shabe Razvi <shaber@symbian.org> |
Wed, 29 Apr 2009 14:39:49 +0100 | |
changeset 73 | b8d6af733d6d |
child 76 | a115d49b621f |
permissions | -rw-r--r-- |
73
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
1 |
use strict; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
2 |
use warnings; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
3 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
4 |
use Text::CSV; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
5 |
require XML::Simple; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
6 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
7 |
# Raw inputs (should probably come in as parameters to the script) |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
8 |
my $sourcesCSV = shift or die "First arg must be source csv file"; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
9 |
my $template = shift or die "Second arg must be template file"; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
10 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
11 |
# Derived values |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
12 |
my ($ftl) = $template =~ m{(.*)\.template$}; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
13 |
#$ftl =~ m{[^/\\]+$}; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
14 |
#$ftl = $1; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
15 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
16 |
# Load CSV |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
17 |
open my $csvText, "<", $sourcesCSV or die; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
18 |
my $csv = Text::CSV->new(); |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
19 |
my @keys; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
20 |
my @packages; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
21 |
while (my $line = <$csvText>) |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
22 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
23 |
chomp $line; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
24 |
next unless $line; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
25 |
unless ($csv->parse($line)) |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
26 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
27 |
my $err = $csv->error_input; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
28 |
die "Failed to parse line '$line': $err"; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
29 |
} |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
30 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
31 |
if (! @keys) |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
32 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
33 |
# First line - note the column names |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
34 |
@keys = $csv->fields(); |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
35 |
} |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
36 |
else |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
37 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
38 |
# Already got the keys, so get the data |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
39 |
my %package; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
40 |
# Read into a hash slice |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
41 |
@package{@keys} = $csv->fields(); |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
42 |
push @packages, \%package; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
43 |
} |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
44 |
} |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
45 |
close $csvText; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
46 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
47 |
# This controls how the XML parsing decides what should be tags and what should be attributes |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
48 |
# It's been worked out mostly by trial and error :-( |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
49 |
my $keyAttr = { config => "name", name => "set"}; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
50 |
# Load template |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
51 |
my $xml = XML::Simple->new(); |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
52 |
my $zipConfig = $xml->XMLin($template, KeyAttr => $keyAttr); |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
53 |
my @allRndFiles; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
54 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
55 |
# For each package in CSV... |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
56 |
foreach my $package (@packages) |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
57 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
58 |
warn "Warning: Package $package->{dst} does not appear on the local system\n" unless -d $package->{dst}; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
59 |
if ($package->{source} =~ m{/(sfl|epl)/sf/([^/]+)/([^/]+)}) |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
60 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
61 |
push @{$zipConfig->{config}->{config}->{src}->{config}->{$1}->{config}}, |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
62 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
63 |
set => |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
64 |
[ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
65 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
66 |
name => "name", |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
67 |
value=> "src_$2_$3", |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
68 |
}, |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
69 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
70 |
name => "include", |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
71 |
value => "$package->{dst}/**", |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
72 |
}, |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
73 |
] |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
74 |
}; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
75 |
} |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
76 |
elsif ($package->{source} =~ m{/rnd/([^/]+)/([^/]+)}) |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
77 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
78 |
# RnD repository |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
79 |
my $name = "rnd_$1_$2"; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
80 |
# Enumerate all the files on the local disk that are in this repository |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
81 |
(my $dosCompatibleDst = $package->{dst}) =~ s{/}{\\}g; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
82 |
my @files = `dir /b/s/a-d $dosCompatibleDst 2> nul:`; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
83 |
next unless @files; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
84 |
# Add the files to this zip object |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
85 |
@files = grep { |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
86 |
chomp; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
87 |
s{\\}{/}g; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
88 |
s!^[A-Z]:$package->{dst}/!!i; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
89 |
m{^epoc32/}i; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
90 |
} @files; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
91 |
#print "@files\n"; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
92 |
push @allRndFiles, @files; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
93 |
# Create a zip object |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
94 |
my @includes = map { {name => "include", value => "$_"} } @files; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
95 |
push @{$zipConfig->{config}->{config}->{src}->{config}->{rnd}->{config}}, |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
96 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
97 |
set => |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
98 |
[ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
99 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
100 |
name => "name", |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
101 |
value=> "$name", |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
102 |
}, |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
103 |
@includes, |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
104 |
] |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
105 |
}; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
106 |
} |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
107 |
else |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
108 |
{ |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
109 |
die "Cannot determine license for '$package->{source}'"; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
110 |
} |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
111 |
} |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
112 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
113 |
# Turn the RnD source inclusion lists into a binary exclusion list |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
114 |
my @excludes = map { {name => "exclude", value => "$_"} } @allRndFiles; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
115 |
push @{$zipConfig->{config}->{config}->{bin}->{config}->{set}}, @excludes; |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
116 |
|
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
117 |
$xml->XMLout($zipConfig, OutputFile => $ftl, XMLDecl => 1, RootName => 'build', KeyAttr => $keyAttr); |
b8d6af733d6d
Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff
changeset
|
118 |