common/tools/populateziptemplate.pl
author Shabe Razvi <shaber@symbian.org>
Wed, 29 Apr 2009 17:39:06 +0100
changeset 76 a115d49b621f
parent 73 b8d6af733d6d
child 84 fcf94a72b33e
permissions -rw-r--r--
Include epl/sfl category in zipfile name
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
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};
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    59
	$package->{dst} =~ s{^/}{}g;
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    60
	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
    61
	{	    
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    62
		push @{$zipConfig->{config}->{config}->{src}->{config}->{$1}->{config}},
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
			set =>
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
				{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    67
					name => "name",
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    68
					value=> "src_$1_$2_$3",
73
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
				{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    71
					name => "include",
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    72
					value => "$package->{dst}/**",
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
	}
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    77
	elsif ($package->{source} =~ m{/rnd/([^/]+)/([^/]+)})
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    78
	{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    79
		# RnD repository
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    80
		my $name = "bin_rnd_$1_$2";
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    81
		# 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
    82
		(my $dosCompatibleDst = $package->{dst}) =~ s{/}{\\}g;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    83
		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
    84
		#print "@files\n";
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    85
		next unless @files;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    86
		# Add the files to this zip object
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    87
		@files = grep {
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    88
			chomp;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    89
			s{\\}{/}g;
76
a115d49b621f Include epl/sfl category in zipfile name
Shabe Razvi <shaber@symbian.org>
parents: 73
diff changeset
    90
			s!^[A-Z]:/$package->{dst}/!!i;
73
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    91
			m{^epoc32/}i;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    92
		} @files;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    93
		#print "@files\n";
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    94
		push @allRndFiles, @files;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    95
		# Create a zip object
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    96
		my @includes = map { {name => "include", value => "$_"} } @files;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
    97
		push @{$zipConfig->{config}->{config}->{src}->{config}->{rnd}->{config}},
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
			set =>
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   100
			[
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   101
				{
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   102
					name => "name",
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   103
					value=> "$name",
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
				@includes,
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
		};
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
	else
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
		die "Cannot determine license for '$package->{source}'";
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
}
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   114
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   115
# 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
   116
my @excludes = map { {name => "exclude", value => "$_"} } @allRndFiles;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   117
push @{$zipConfig->{config}->{config}->{bin}->{config}->{set}}, @excludes;
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   118
b8d6af733d6d Add first cut of packaging solution
Shabe Razvi <shaber@symbian.org>
parents:
diff changeset
   119
$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
   120