|
1 #!perl -w |
|
2 # Copyright (c) 2009 Symbian Foundation Ltd |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of the License "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Symbian Foundation Ltd - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # Populates the template for packaging src and binaries in the build |
|
15 |
|
16 use strict; |
|
17 |
|
18 use FindBin; |
|
19 use lib "$FindBin::Bin/lib"; |
|
20 use Text::CSV; |
|
21 require XML::Simple; |
|
22 |
|
23 # Raw inputs come in as parameters to the script |
|
24 # TODO: Use a proper option parsing module |
|
25 my $sourcesCSV = shift or die "First arg must be source csv file"; |
|
26 my $template = shift or die "Second arg must be template file"; |
|
27 my $ftl = shift or die "Third arg must be output file"; |
|
28 shift and die "No more than three arguments please"; |
|
29 |
|
30 # Load CSV |
|
31 open my $csvText, "<", $sourcesCSV or die; |
|
32 my $csv = Text::CSV->new(); |
|
33 my @keys; |
|
34 my @packages; |
|
35 while (my $line = <$csvText>) |
|
36 { |
|
37 chomp $line; |
|
38 next unless $line; |
|
39 unless ($csv->parse($line)) |
|
40 { |
|
41 my $err = $csv->error_input(); |
|
42 die "Failed to parse line '$line': $err"; |
|
43 } |
|
44 |
|
45 if (! @keys) |
|
46 { |
|
47 # First line - note the column names |
|
48 @keys = $csv->fields(); |
|
49 } |
|
50 else |
|
51 { |
|
52 # Already got the keys, so get the data |
|
53 my %package; |
|
54 # Read into a hash slice |
|
55 @package{@keys} = $csv->fields(); |
|
56 push @packages, \%package; |
|
57 } |
|
58 } |
|
59 close $csvText; |
|
60 |
|
61 # This controls how the XML parsing decides what should be tags and what should be attributes |
|
62 # It's been worked out mostly by trial and error :-( |
|
63 my $keyAttr = { config => "name", name => "set"}; |
|
64 # Load template |
|
65 my $xml = XML::Simple->new(); |
|
66 my $zipConfig = $xml->XMLin($template, KeyAttr => $keyAttr); |
|
67 my @allRndFiles; |
|
68 |
|
69 # For each package in CSV... |
|
70 foreach my $package (@packages) |
|
71 { |
|
72 warn "Warning: Package $package->{dst} does not appear on the local system\n" unless -d $package->{dst}; |
|
73 $package->{dst} =~ s{^/}{}g; |
|
74 if ($package->{source} =~ m{/(sfl|oss)/(MCL|FCL)/sf/([^/]+)/([^/]+)}) |
|
75 { |
|
76 push @{$zipConfig->{config}->{config}->{src}->{config}->{$1}->{config}}, |
|
77 { |
|
78 set => |
|
79 [ |
|
80 { |
|
81 name => "name", |
|
82 value=> "src_$1_$3_$4", |
|
83 }, |
|
84 { |
|
85 name => "include", |
|
86 value => "$package->{dst}/**", |
|
87 }, |
|
88 ] |
|
89 }; |
|
90 } |
|
91 elsif ($package->{source} =~ m{/rnd/([^/]+)/([^/]+)}) |
|
92 { |
|
93 # RnD repository |
|
94 my $name = "bin_rnd_$1_$2"; |
|
95 # Create a zip object |
|
96 push @{$zipConfig->{config}->{config}->{src}->{config}->{rnd}->{config}}, |
|
97 { |
|
98 set => |
|
99 [ |
|
100 { |
|
101 name => "root.dir", |
|
102 value=> "\${build.drive}/$package->{dst}", |
|
103 }, |
|
104 { |
|
105 name => "name", |
|
106 value=> "$name", |
|
107 }, |
|
108 { |
|
109 name => "include", |
|
110 value=> "/**", |
|
111 }, |
|
112 ] |
|
113 }; |
|
114 # Enumerate all the files on the local disk that are in this repository |
|
115 (my $dosCompatibleDst = $package->{dst}) =~ s{/}{\\}g; |
|
116 my @files = `dir /b/s/a-d $dosCompatibleDst 2> nul:`; |
|
117 #print "@files\n"; |
|
118 next unless @files; |
|
119 # Add the files to this zip object |
|
120 @files = grep { |
|
121 s{\\}{/}g; |
|
122 s!^[A-Z]:/$package->{dst}/!!i; |
|
123 m{^epoc32/}i; |
|
124 } @files; |
|
125 push @allRndFiles, @files; |
|
126 |
|
127 open FILE, ">", $name ."_includefile.txt" or die "Cannot write includefile!"; |
|
128 print FILE @files; |
|
129 close FILE; |
|
130 } |
|
131 else |
|
132 { |
|
133 die "Cannot determine license for '$package->{source}'"; |
|
134 } |
|
135 } |
|
136 |
|
137 # Turn the RnD source inclusion lists into a binary exclusion list |
|
138 my @excludes = map { {name => "exclude", value => "$_"} } @allRndFiles; |
|
139 push @{$zipConfig->{config}->{config}->{bin}->{config}->{set}}, @excludes; |
|
140 |
|
141 $xml->XMLout($zipConfig, OutputFile => $ftl, XMLDecl => 1, RootName => 'build', KeyAttr => $keyAttr); |
|
142 |
|
143 # Output all rnd files into exclude list for later |
|
144 open FILE, "> rnd_excludefile.txt" or die "Cannot write exludefile!"; |
|
145 print FILE @allRndFiles; |
|
146 close FILE; |