|
1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "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 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 use XML::Simple; |
|
17 use File::Path; |
|
18 use File::Copy; |
|
19 use Win32::File; |
|
20 use Getopt::Long; |
|
21 use strict; |
|
22 |
|
23 my $outfile; |
|
24 my $verbose; |
|
25 GetOptions("o=s", \$outfile, "v+", \$verbose); |
|
26 |
|
27 if (!defined $outfile) { |
|
28 die "ERROR: Syntax: genkif.pl -o <kif filename>\n"; |
|
29 } elsif (-f $outfile) { |
|
30 print STDOUT "REMARK: KIF generation skipped due to it already existing (in '$outfile').\n"; |
|
31 exit 0; |
|
32 } elsif (-e $outfile) { |
|
33 die "ERROR: KIF output file '$outfile' must not be a directory or other non-file type\n"; |
|
34 } elsif ($verbose) { |
|
35 print "Got output file of '$outfile'\n"; |
|
36 } |
|
37 |
|
38 my $buildnum = $ENV{'BuildNumber'}; |
|
39 if (!defined $buildnum) { |
|
40 die "ERROR: KIF generation skipped due to the BuildNumber environment variable not being set.\n"; |
|
41 } elsif ($verbose) { |
|
42 print "Got build number of '$buildnum'\n"; |
|
43 } |
|
44 |
|
45 my $namespace = "ki"; |
|
46 my $nsuri = "http://www.symbian.com/kif1"; |
|
47 my $schema = "kif1.xsd"; |
|
48 |
|
49 my $build; |
|
50 my $version; |
|
51 if ($buildnum =~ /^(.*)_Symbian_OS_v(.*)$/) { |
|
52 $build = $1; |
|
53 $version = $2; |
|
54 print "Parsed build number as $build, os version $version\n" if $verbose; |
|
55 } else { |
|
56 die "ERROR: Build number '$buildnum' is not a valid build number\n"; |
|
57 } |
|
58 |
|
59 # Generate the Kit Information File |
|
60 |
|
61 print "Constructing the KIF data\n" if $verbose; |
|
62 |
|
63 my $mapper = new XML::Simple('rootname' => $namespace.':kitinfo', 'searchpath' => '.'); |
|
64 |
|
65 my $hash = { |
|
66 'xsi:schemaLocation' => "$nsuri $schema", |
|
67 "xmlns:".$namespace => $nsuri, |
|
68 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', |
|
69 'label' => $buildnum, |
|
70 $namespace.':release' => { |
|
71 'build' => $build, |
|
72 'version' => $version |
|
73 } |
|
74 }; |
|
75 |
|
76 print "Writing the KIF data to '$outfile'\n" if $verbose; |
|
77 |
|
78 open(my $out, ">$outfile") or die "ERROR: Couldn't open $outfile for writing: $!\n"; |
|
79 |
|
80 print $out $mapper->XMLout($hash, 'xmldecl' => "<?xml version='1.0'?>"); |
|
81 |
|
82 close($out) or die "ERROR: Couldn't write to $outfile".": $!\n"; |
|
83 |
|
84 print "Generated KIF in $outfile\n"; |