deprecated/buildtools/buildsystemtools/genxml.pl
changeset 662 60be34e1b006
parent 655 3f65fd25dfd4
equal deleted inserted replaced
654:7c11c3d8d025 662:60be34e1b006
       
     1 # Copyright (c) 2003-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 # Script to Generate the XML command file from the xml files
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use FindBin;		# for FindBin::Bin
       
    20 use Getopt::Long;
       
    21 use File::Copy;
       
    22 
       
    23 use lib $FindBin::Bin;
       
    24 use lib "$FindBin::Bin/lib";
       
    25 
       
    26 # Process the commandline
       
    27 my ($iDataSource, $iDataOutput, $iLogFile, $iSourceDir, $iReallyClean, 
       
    28     $iClean, $iXmlSource, $iConfName, $iMergedXml, $iValidate,
       
    29     $iTextOutput, $iCBROutput, $iFilter, $iEffectiveDir) = ProcessCommandLine();
       
    30 
       
    31 if (scalar(@$iXmlSource))
       
    32 {
       
    33 	use GenXml;
       
    34 	&GenXml::Start($iXmlSource, $iDataOutput, $iLogFile, $iSourceDir, 
       
    35 	               $iConfName, $iMergedXml, $iValidate, $iTextOutput, $iCBROutput, $iFilter, $iEffectiveDir);
       
    36 } else {
       
    37 	use GenBuild;
       
    38 	# Start the generation of the XML
       
    39   print "Warning old .txt file input is being used\n";
       
    40 	&GenBuild::Start($iDataSource, $iDataOutput, $iLogFile, $iSourceDir, $iReallyClean, $iClean);
       
    41 }
       
    42 
       
    43 
       
    44 # ProcessCommandLine
       
    45 #
       
    46 # Inputs
       
    47 #
       
    48 # Outputs
       
    49 # @iDataSource array of multiple (txt file(s) to process)
       
    50 # $iDataOutput (XML file to generate)
       
    51 # $iLogFile (Log file to put processing errors)
       
    52 # $iSourceDir (Location of Source)
       
    53 # $iReallyClean (script to run the "abld reallyclean" command)
       
    54 # $iClean (script to run the "abld clean" command)
       
    55 # @iXmlSource array of multiple (XML file(s) to process)
       
    56 # $iConfName (Name of configuration to generate)
       
    57 # $iMergedXml - Hidden option to save the output of the merging xml process for debug use
       
    58 # $iValidate (Just validate the input)
       
    59 # $iText (txt file to generate)
       
    60 # $iFilter (filter to apply before generating merged XML file)
       
    61 # $iEffectiveDir (location at which source will be used)
       
    62 #
       
    63 # Description
       
    64 # This function processes the commandline
       
    65 
       
    66 sub ProcessCommandLine {
       
    67   my ($iHelp, $iPort, @iDataSource, $iLogFile, $iSourceDir, $iReallyClean, $iClean, 
       
    68       @iXmlSource, $iConfName, $iMergedXml, $iValidate, $iTextOutput, $iCBROutput, 
       
    69       $iFilter, $iEffectiveDir);
       
    70   GetOptions(
       
    71   	'h' => \$iHelp, 
       
    72   	'd=s@' =>\@iDataSource, 
       
    73   	'o=s' => \$iDataOutput, 
       
    74   	'l=s' => \$iLogFile, 
       
    75   	's=s' => \$iSourceDir, 
       
    76   	'e=s' => \$iEffectiveDir, 
       
    77   	'r=s' => \$iReallyClean, 
       
    78   	'c=s' => \$iClean, 	# or $iCBROutput in XML input mode
       
    79   	'x=s@' =>\@iXmlSource, 
       
    80   	'n=s' => \$iConfName, 
       
    81   	'm=s' => \$iMergedXml, 
       
    82   	'v' =>\$iValidate,
       
    83   	't=s' => \$iTextOutput,
       
    84   	'f=s' => \$iFilter);
       
    85 
       
    86   Usage() if ($iHelp);
       
    87   
       
    88   Usage("Must specify the root of the source tree with -s") if (!defined $iSourceDir);
       
    89   Usage("Must specify at least one input file") if ((!@iDataSource) && (!@iXmlSource));
       
    90   Usage("$iSourceDir is not a directory") if (!-d $iSourceDir);
       
    91 
       
    92   if (scalar @iXmlSource)
       
    93   	{
       
    94   	# Validation of options for XML input
       
    95   	
       
    96   	Usage("Can't mix -d and -x") if (scalar @iDataSource);
       
    97   	
       
    98   	$iCBROutput = $iClean;	# deal with ambiguity in -c option
       
    99   	$iClean = "";
       
   100   	
       
   101   	if ((!defined $iMergedXml) && (!defined $iDataOutput) 
       
   102   	     && (!defined $iTextOutput) && (!defined $iCBROutput))
       
   103   		{
       
   104   		Usage("Must specify at least one output file") if (!defined $iValidate);
       
   105   		}
       
   106   	else
       
   107   		{
       
   108   		Usage("Can't specify output files with -v") if (defined $iValidate);
       
   109   		}
       
   110   	if (defined $iDataOutput || defined $iTextOutput)
       
   111   		{
       
   112   		Usage("Must specify configuration for XML or list output") if (!defined $iConfName);
       
   113   		}
       
   114   	Usage("Can't specify reallyclean files with -x") if (defined $iReallyClean);
       
   115   	
       
   116   	$iEffectiveDir = $iSourceDir if (!defined $iEffectiveDir);
       
   117 	}
       
   118   else
       
   119     {
       
   120   	# Validation of options for component list input
       
   121 
       
   122     Usage("Must specify a logfile with -l") if (!defined $iLogFile);
       
   123 	Usage("Can't request validation on non-XML input") if (defined $iValidate);  	
       
   124   	Usage("Can't specify merged or text output with -d") if (defined $iTextOutput || defined $iMergedXml);
       
   125 	Usage ("Can't specify a filter for non-XML input") if (defined $iFilter);
       
   126 	Usage ("Can't specify a configuration for non-XML input") if (defined $iConfName);
       
   127     }
       
   128   
       
   129   foreach my $iFile (@iDataSource)
       
   130   {
       
   131     if (! -e $iFile)
       
   132     {
       
   133       die "Cannot open $iFile";
       
   134     }
       
   135   }
       
   136 
       
   137   foreach my $iFile (@iXmlSource)
       
   138   {
       
   139     if (! -e $iFile)
       
   140     {
       
   141       die "Cannot open $iFile";
       
   142     }
       
   143   }
       
   144 
       
   145   # Backup existing files
       
   146   
       
   147   &backupFile($iLogFile);
       
   148   &backupFile($iDataOutput);
       
   149   &backupFile($iMergedXml);
       
   150   &backupFile($iTextOutput);
       
   151   &backupFile($iCBROutput);
       
   152   &backupFile($iReallyClean);
       
   153   &backupFile($iClean);
       
   154 
       
   155   return(\@iDataSource, $iDataOutput, $iLogFile, $iSourceDir, $iReallyClean, $iClean, \@iXmlSource, $iConfName, $iMergedXml, $iValidate, $iTextOutput, $iCBROutput, $iFilter, $iEffectiveDir);
       
   156 }
       
   157 
       
   158 # backupFile
       
   159 #
       
   160 # Inputs
       
   161 # $iFile - filename to backup
       
   162 #
       
   163 # Outputs
       
   164 #
       
   165 # Description
       
   166 # This function renames a file with the .baknn extension, if necessary
       
   167 sub backupFile
       
   168 {
       
   169 	my ($iFile) = @_;
       
   170 	
       
   171 	return if (!$iFile || !-e $iFile);
       
   172 	
       
   173 	my ($iBak) = $iFile.".bak";
       
   174 	my ($i, $freefilename);
       
   175 	# Loop until you find a free file name by increamenting the number on the end of the .bak extension
       
   176 	while (!$freefilename)
       
   177 	{
       
   178 		if (-e $iBak.$i)
       
   179 		{
       
   180 			$i++;
       
   181 		} else {
       
   182 			$iBak .= $i;
       
   183 			$freefilename = 1;
       
   184 		}
       
   185 	}
       
   186 	print "WARNING: $iFile already exists, creating backup of original with new name of $iBak\n";
       
   187 	move($iFile,$iBak) or die "Could not backup $iFile to $iBak because of: $!\n";
       
   188 }
       
   189 
       
   190 # Usage
       
   191 #
       
   192 # Output Usage Information.
       
   193 #
       
   194 
       
   195 sub Usage {
       
   196   my ($reason) = @_;
       
   197   
       
   198   print "ERROR: $reason\n" if ($reason);
       
   199   print <<USAGE_EOF;
       
   200 
       
   201   Usage: Genxml.pl [options]
       
   202 
       
   203   options for XML input mode:
       
   204 
       
   205   -h  help
       
   206   -s  Source Directory
       
   207   -x  XML Data Source (XML file) [Multiple -x options allowed]
       
   208   -f  filter to apply to data source before main processing [optional]
       
   209   -m  Output merged & filtered XML file [optional]
       
   210   -n  Configuration name to use
       
   211   -l  Logfile [optional]
       
   212   -o  Output XML file [optional]
       
   213   -e  Effective source directory [optional]
       
   214   -t  Output TXT file corresponding to XML file [optional]
       
   215   -c  Output list of CBR components [optional]
       
   216   -v  Validate XML files only, Stop after merging and validating.
       
   217       Turns on extra INFO messages for Validation [optional]
       
   218 
       
   219   options for backward compatibility mode:
       
   220 
       
   221   -h  help
       
   222   -l  Logfile
       
   223   -s  Source Directory
       
   224   -d  Data Source (txt file) [Multiple -d options allowed]
       
   225   -o  Output XML file
       
   226   -r  Filename for ReallyClean xml file [optional]
       
   227   -c  Filename for Clean xml file [optional]
       
   228 
       
   229   Description:
       
   230   This program generates an XML file that is used by the Build
       
   231   Client-Server System. It expands the summarised configuration
       
   232   information stored in the input files to a detailed command by command
       
   233   instruction set for the Build System to use. This enabled the
       
   234   specified configuration to be built by the build system.
       
   235 
       
   236 USAGE_EOF
       
   237   exit 1;
       
   238 }