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