Add first cut of packaging solution
authorShabe Razvi <shaber@symbian.org>
Wed, 29 Apr 2009 14:39:49 +0100
changeset 73 b8d6af733d6d
parent 72 4846dd5df20a
child 74 d6aee860ab32
Add first cut of packaging solution
common/build.xml
common/templates/zip.cfg.xml.ftl.template
common/tools/populateziptemplate.pl
--- a/common/build.xml	Wed Apr 29 10:51:22 2009 +0100
+++ b/common/build.xml	Wed Apr 29 14:39:49 2009 +0100
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project name="SF-COMMON-CONFIG">
+<project name="SF-COMMON-CONFIG" xmlns:hlm="http://www.nokia.com/helium">
 
     <property environment="env"/> <!-- make environment variables available via env -->
     
@@ -229,7 +229,7 @@
     <property name="sf.currentlist_a.name"   value="${sf.list_a.name}"/> 
     <property name="sf.currentlist_b.name"   value="${sf.list_b.name}"/>
     <property name="sf.dir.location" value="${build.drive}/epoc32"/> 
-    		
+	
     <if>
       <istrue value="${sf.spec.dirdelta.enable}"/>
       <then>
@@ -303,12 +303,39 @@
               config: csv(${build.drive}/output/logs/BOM/config.csv,{separator:',',headers:[loc,dst,rev]})
               project: csv(${build.drive}/output/logs/BOM/project.csv,{separator:',',headers:[loc,dst,rev]})
               baseline: slicedText(${build.drive}/output/logs/BOM/baseline.txt,{trim})
-              sources: csv(${build.drive}/output/logs/BOM/sources.csv,{separator:',',headers:[loc,dst,rev]})
-              
+              sources: csv(${build.drive}/output/logs/BOM/sources.csv,{separator:',',headers:[loc,dst,rev]})              
         </data>
       </fmpp>
     </target>
 
+	<target name="sf-preprocess-package-config">
+        <exec executable="perl" dir="${build.drive}/" failonerror="true" output="${build.log.dir}/zipconfig.log">
+          <arg value="${sf.common.config.dir}/tools/populateziptemplate.pl"/>
+          <arg value="${sf.project.location}/${sf.spec.sourcesync.sourcespecfile}"/>
+          <arg value="${sf.common.config.dir}/templates/zip.cfg.xml.ftl.template"/>
+        </exec>
+	</target>
+	
+	<target name="sf-zip-content" depends="preprocess-zip-config">
+		<property name="zip.${zip.target.name}.log.file" location="${build.log.dir}/${build.id}_${zip.target.name}_zip.log" />
+		<property name="zips.${zip.target.name}.spec.name" value="${zip.target.name}" />
+		<hlm:zipContentMacro type="${zip.target.name}" file="${zip.config.file}" />
+	</target>
+	
+	<target name="sf-package-source" depends="sf-preprocess-package-config">
+		<antcall target="sf-zip-content">
+			<param name="zip.config.file" value="${sf.common.config.dir}/templates/zip.cfg.xml.ftl"/>
+			<param name="zip.target.name" value="src" />
+		</antcall>	
+	</target>
+	
+	<target name="sf-package-binary" depends="sf-preprocess-package-config">
+		<antcall target="sf-zip-content">
+		    <param name="zip.config.file" value="${sf.common.config.dir}/templates/zip.cfg.xml.ftl"/>
+			<param name="zip.target.name" value="bin" />
+		</antcall>	
+	</target>
+	
 </project>
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/templates/zip.cfg.xml.ftl.template	Wed Apr 29 14:39:49 2009 +0100
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<build>
+	<config abstract="true">
+		<!-- Options that apply accross the board -->
+		<set name="archive.tool" value="7za" />
+		<set name="root.dir" value="${build.drive}/" />
+		<set name="temp.build.dir" value="${temp.build.dir}" />
+		<set name="casesensitive" value="false" />
+		<set name="archives.dir" value="${build.output.dir}/zips" />
+		<set name="policy.internal.name" value="removed" />
+		<!--set name="policy.csv" value="${policy.csv}" /-->
+		<set name="policy.zip2zip" value="false" />
+		<set name="policy.default.value" value="" />
+		
+		<!--  Metadata creation -->
+		<set name="grace.template" value="${temp.build.dir}/release_metadata_template.xml" />
+		<set name="grace.metadata" value="true" />
+		<set name="grace.service" value="${grace.service.name}" />
+		<set name="grace.product" value="${grace.product.name}" />
+		<set name="grace.release" value="${grace.release.name}" />
+		
+		<!-- Specify this config to package all inputs to the build -->
+		<config name="src" abstract="true">
+			<config name="sfl" abstract="true">
+				<set name="grace.filters" value="src" />
+			</config>
+			<config name="epl" abstract="true">
+				<set name="grace.filters" value="src" />
+			</config>
+			<config name="rnd" abstract="true">
+				<set name="grace.filters" value="rnd" />
+			</config>
+		</config>
+		<!-- Specify this config to package all outputs from the build -->
+		<config name="bin" abstract="true">
+			<config>
+				<set name="name" value="binaries_epoc"/>
+				<set name="grace.filters" value="emu" />
+				<set name="include" value="epoc32/**"/>
+			</config>
+		</config>
+	</config>
+</build>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/tools/populateziptemplate.pl	Wed Apr 29 14:39:49 2009 +0100
@@ -0,0 +1,118 @@
+use strict;
+use warnings;
+
+use Text::CSV;
+require XML::Simple;
+
+# Raw inputs (should probably come in as parameters to the script)
+my $sourcesCSV = shift or die "First arg must be source csv file";
+my $template = shift or die "Second arg must be template file";
+
+# Derived values
+my ($ftl) = $template =~ m{(.*)\.template$};
+#$ftl =~ m{[^/\\]+$};
+#$ftl = $1;
+
+# Load CSV
+open my $csvText, "<", $sourcesCSV or die;
+my $csv = Text::CSV->new();
+my @keys;
+my @packages;
+while (my $line = <$csvText>)
+{
+	chomp $line;
+	next unless $line;
+	unless ($csv->parse($line))
+	{
+		my $err = $csv->error_input;
+		die "Failed to parse line '$line': $err";
+	}
+
+	if (! @keys)
+	{
+		# First line - note the column names
+		@keys =  $csv->fields();
+	}
+	else
+	{
+		# Already got the keys, so get the data
+		my %package;
+		# Read into a hash slice
+		@package{@keys} = $csv->fields();
+		push @packages, \%package;
+	}
+}
+close $csvText;
+
+# This controls how the XML parsing decides what should be tags and what should be attributes
+# It's been worked out mostly by trial and error :-(
+my $keyAttr = { config => "name", name => "set"};
+# Load template
+my $xml = XML::Simple->new();
+my $zipConfig = $xml->XMLin($template, KeyAttr => $keyAttr);
+my @allRndFiles;
+
+# For each package in CSV...
+foreach my $package (@packages)
+{
+	warn "Warning: Package $package->{dst} does not appear on the local system\n" unless -d $package->{dst};
+	if ($package->{source} =~ m{/(sfl|epl)/sf/([^/]+)/([^/]+)})
+	{
+		push @{$zipConfig->{config}->{config}->{src}->{config}->{$1}->{config}},
+		{
+			set =>
+			[
+				{
+					name => "name",
+					value=> "src_$2_$3",
+				},
+				{
+					name => "include",
+					value => "$package->{dst}/**",
+				},
+			]
+		};
+	}
+	elsif ($package->{source} =~ m{/rnd/([^/]+)/([^/]+)})
+	{
+		# RnD repository
+		my $name = "rnd_$1_$2";
+		# Enumerate all the files on the local disk that are in this repository
+		(my $dosCompatibleDst = $package->{dst}) =~ s{/}{\\}g;
+		my @files = `dir /b/s/a-d $dosCompatibleDst 2> nul:`;
+		next unless @files;
+		# Add the files to this zip object
+		@files = grep {
+			chomp;
+			s{\\}{/}g;
+			s!^[A-Z]:$package->{dst}/!!i;
+			m{^epoc32/}i;
+		} @files;
+		#print "@files\n";
+		push @allRndFiles, @files;
+		# Create a zip object
+		my @includes = map { {name => "include", value => "$_"} } @files;
+		push @{$zipConfig->{config}->{config}->{src}->{config}->{rnd}->{config}},
+		{
+			set =>
+			[
+				{
+					name => "name",
+					value=> "$name",
+				},
+				@includes,
+			]
+		};
+	}
+	else
+	{
+		die "Cannot determine license for '$package->{source}'";
+	}
+}
+
+# Turn the RnD source inclusion lists into a binary exclusion list
+my @excludes = map { {name => "exclude", value => "$_"} } @allRndFiles;
+push @{$zipConfig->{config}->{config}->{bin}->{config}->{set}}, @excludes;
+
+$xml->XMLout($zipConfig, OutputFile => $ftl, XMLDecl => 1, RootName => 'build', KeyAttr => $keyAttr);
+