common/tools/populateziptemplate.pl
author Simon Howkins <simonh@symbian.org>
Tue, 05 May 2009 14:21:55 +0100
changeset 84 fcf94a72b33e
parent 76 a115d49b621f
child 88 28463bb10fde
permissions -rw-r--r--
Improved zip template generation script, to take a third argument for the required location of the output file. Updated build script to supply third argument. Standardised indentation in build.xml - 4 columns; no tabs.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
84
fcf94a72b33e Improved zip template generation script, to take a third argument for the required location of the output file.
Simon Howkins <simonh@symbian.org>
parents: 76
diff changeset
     7
# Raw inputs come in as parameters to the script
fcf94a72b33e Improved zip template generation script, to take a third argument for the required location of the output file.
Simon Howkins <simonh@symbian.org>
parents: 76
diff changeset
     8
# TODO: Use a proper option parsing module
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
     9
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
    10
my $template = shift or die "Second arg must be template file";
84
fcf94a72b33e Improved zip template generation script, to take a third argument for the required location of the output file.
Simon Howkins <simonh@symbian.org>
parents: 76
diff changeset
    11
my $ftl = shift or die "Third arg must be output file";
fcf94a72b33e Improved zip template generation script, to take a third argument for the required location of the output file.
Simon Howkins <simonh@symbian.org>
parents: 76
diff changeset
    12
shift and die "No more than three arguments please";
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    13
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    14
# Load CSV
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    15
open my $csvText, "<", $sourcesCSV or die;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    16
my $csv = Text::CSV->new();
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    17
my @keys;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    18
my @packages;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    19
while (my $line = <$csvText>)
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    20
{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    21
	chomp $line;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    22
	next unless $line;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    23
	unless ($csv->parse($line))
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    24
	{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    25
		my $err = $csv->error_input;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    26
		die "Failed to parse line '$line': $err";
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    27
	}
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    28
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    29
	if (! @keys)
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
		# First line - note the column names
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    32
		@keys =  $csv->fields();
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    33
	}
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    34
	else
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
		# Already got the keys, so get the data
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    37
		my %package;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    38
		# Read into a hash slice
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    39
		@package{@keys} = $csv->fields();
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    40
		push @packages, \%package;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    41
	}
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    42
}
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    43
close $csvText;
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
# 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
    46
# 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
    47
my $keyAttr = { config => "name", name => "set"};
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    48
# Load template
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    49
my $xml = XML::Simple->new();
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    50
my $zipConfig = $xml->XMLin($template, KeyAttr => $keyAttr);
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    51
my @allRndFiles;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    52
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    53
# For each package in CSV...
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    54
foreach my $package (@packages)
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    55
{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    56
	warn "Warning: Package $package->{dst} does not appear on the local system\n" unless -d $package->{dst};
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    57
	$package->{dst} =~ s{^/}{}g;
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    58
	if ($package->{source} =~ m{/(sfl|epl)/sf/([^/]+)/([^/]+)})
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    59
	{	    
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    60
		push @{$zipConfig->{config}->{config}->{src}->{config}->{$1}->{config}},
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    61
		{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    62
			set =>
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    63
			[
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
					name => "name",
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    66
					value=> "src_$1_$2_$3",
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    67
				},
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
					name => "include",
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    70
					value => "$package->{dst}/**",
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    71
				},
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
	elsif ($package->{source} =~ m{/rnd/([^/]+)/([^/]+)})
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    76
	{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    77
		# RnD repository
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    78
		my $name = "bin_rnd_$1_$2";
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    79
		# 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
    80
		(my $dosCompatibleDst = $package->{dst}) =~ s{/}{\\}g;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    81
		my @files = `dir /b/s/a-d $dosCompatibleDst 2> nul:`;
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    82
		#print "@files\n";
73
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;
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    88
			s!^[A-Z]:/$package->{dst}/!!i;
73
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