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