deprecated/buildtools/buildsystemtools/GenXml.pm
author jascui
Wed, 17 Nov 2010 13:39:51 +0800
changeset 688 27f7c5c966fc
parent 655 3f65fd25dfd4
permissions -rw-r--r--
delete orig.txt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
# Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
# All rights reserved.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
# This component and the accompanying materials are made available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
# which accompanies this distribution, and is available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
# Initial Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
# Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
# Description:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
package GenXml;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
  use strict;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
  use FindBin;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
  use lib "$FindBin::Bin/lib";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
  use XML::DOM;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
  use XML::DOM::ValParser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
  # produces the "Use of uninitialized value in concatenation (.) or string" warning
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
  use XML::XQL;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
  use XML::XQL::DOM;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
  # Variable to indicate the version of xml file used.  It will be set by subroutine Parse_xml
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
  my $iVer = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
  # Used by debug prints
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
  #my $count;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
my ($gHiResTimer) = 0; 		#Flag - true (1) if HiRes Timer module available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
my ($gLogFileH); 		# Log file handle
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
my ($gEmbeddedLog) = 0; 	# Flag false (0) if logging must include scanlog headers etc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
my ($gValidateFailed) = 0; 	# Flag true (1) if the XML validation has failed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
my ($gValidate) = 0; 		# Flag true (1) if to do XML validation only
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
  #assign STDERR to STDOUT so both are printed in the same file, without overwriting lines
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
  open (STDERR, ">&STDOUT") or die("ERROR: Unable to redirect STDERR to STDOUT: $!");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
  select((select(STDOUT), $|=1)[0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
  select((select(STDERR), $|=1)[0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
# Check if HiRes Timer is available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
if (eval "require Time::HiRes;") {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
  $gHiResTimer = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
} else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
  print "Cannot load HiResTimer Module, install the Perl module Time-HiRes for more accurate timing data\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
# Start
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
# $iXMLSource - ref to array of XML filenames, to be merged into one
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
# $iLogFile - name of logfile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
# $iSourceDir - root of the current source tree
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
# $iEffectiveDir - root of source tree in which output files will be used
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
# $iValidate - if true, validate the input and then stop
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
# $iFilter - (optional) filter the merged file against this value
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
# $iMergedXml - (optional) create file of this name containing the merged XML
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
# $iConfName - name of the configuration: needed by subsequent arguments
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
# $iDataOutput - (optional) create file of this name containing the XML build commands
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
# $iTextOutput - (optional) create file of this name containing the list of components
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
# $iCBROutput - (optional) create file of this name containing the list of MRP files
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
# This function merges multiple XML files into one document, then optionally outputs various
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
# files. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
sub Start
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
  my ($iXmlSource, $iDataOutput, $iLogFile, $iSourceDir, $iConfName, $iMergedXml, $iValidate, $iTextOutput, $iCBROutput, $iFilter, $iEffectiveDir) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
  # Set global validation Flag
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
  $GenXml::gValidate = $iValidate;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
  my $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
  if ($iLogFile)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
    # Open Log file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
    $GenXml::gLogFileH = IO::File->new("> $iLogFile")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
      or die "ERROR: RealTimeBuild: Couldn't open $iLogFile for writing: $!\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
    $gEmbeddedLog = 0; # Generate scanlog-compatible log format
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
  } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
    $GenXml::gLogFileH = *STDOUT;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
    $gEmbeddedLog = 1; # Assume that we are embedded in a scanlog-format log file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
  if (!$gEmbeddedLog)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
    # Logfile headers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
    print $GenXml::gLogFileH "===-------------------------------------------------\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
    print $GenXml::gLogFileH "=== Genxml\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
    print $GenXml::gLogFileH "===-------------------------------------------------\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
    print $GenXml::gLogFileH "=== Genxml started ".localtime()."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
  # $iSourceDir must end in a \
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
  # Add a \ if not present
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
  # And make sure they are in windows style
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
  if ($iSourceDir !~ /\\$/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
    $iSourceDir =~ s/\//\\/g;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
    $iSourceDir .= "\\";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
  if ($iEffectiveDir !~ /\\$/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
    $iEffectiveDir =~ s/\//\\/g;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
    $iEffectiveDir .= "\\";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
  # Parse all the files into one DOM doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
  $doc = &Parse_files($iXmlSource, \$iVer);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
  # ... XML::DOM::Document was created sucessfully ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
	  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
  # Exit here if validating only
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
  exit if ($GenXml::gValidate);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
	  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
  # Try normalising it
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
  $doc->normalize;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
	  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
  # filter it, if desired
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
  if ($iFilter && $iVer == 1)  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
    &logfileHeader("Filtering model against $iFilter");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
    &Filter_doc($doc, $iFilter);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
    &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
  } elsif ($iFilter && $iVer == 2) { 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
    &logfileHeader("Filtering model against $iFilter");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
    &Filter_doc2($doc, $iFilter);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
    &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
  # Debug dump new doc to file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
  #~ $doc->printToFile("$iMergedXml") if ($iMergedXml);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
  #################write only non-empty lines################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
  if ($iMergedXml)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
    open(HANDLE, "+> $iMergedXml") or die "Error: Can't open $iMergedXml: $!";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
    my $MergedXMLString = $doc->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
    my @lines = split(/\n/,$MergedXMLString);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
    my @tempLines = ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
    foreach (@lines)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
      push @tempLines, $_ if $_ !~ /^[\s]*$/;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
    $MergedXMLString = join("\n",@tempLines);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
    seek(HANDLE,0,0);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
    print HANDLE $MergedXMLString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
    truncate(HANDLE,tell(HANDLE));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
    close HANDLE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
  #################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
  if ($iConfName)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
    # Process the configuration to get the lists of units, tasks and options
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
    &logfileHeader("Processing configuration $iConfName");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
    my ($topunits, $subunits, $options, $tasks) = &process_configuration($doc,$iConfName, $iVer);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
    my @topbldList = &compute_bldList($iSourceDir,$iEffectiveDir,$topunits, $iVer); 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
    &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
    if ($iTextOutput)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
  	  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
	  &logfileHeader("Generating text output $iTextOutput");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
	  # Generate old-style text output
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175
	  &write_component_list($doc, $iTextOutput, $iConfName, \@topbldList, $options, $tasks, $iEffectiveDir, $iVer);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
	  &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
	  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
    if ($iCBROutput)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
	  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
	  &logfileHeader("Generating CBR component list $iCBROutput");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
	  # Generate list of CBR components for "makecbr"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
	  my @allunits;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
   #if ($iVer == 1) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
		  @allunits = (@$topunits, @$subunits);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
   #} else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
  #  @allunits = (@$topunits);  # No subunits required for the new version of system_definition.xml
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   190
   #}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   191
	  my @fullbldList = &compute_bldList($iSourceDir,$iEffectiveDir,\@allunits, $iVer); 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   192
	  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   193
	  &write_CBR_list($iCBROutput, \@fullbldList);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   194
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   195
	  &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   196
	  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   197
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   198
    if ($iDataOutput)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   199
	  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   200
	  &logfileHeader("Generating output XML $iDataOutput");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   201
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   202
	  # Generate the output document by applying the tasks to the bldList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   203
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   204
	  my $ID = 1; # Execute Element ID counter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   205
	  my $Stage = 1; # Execute Element Stage counter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   206
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   207
	  my ($outDoc, $docElem, $commands) = &start_output_doc($iConfName, $iVer);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   208
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   209
	  process_prebuilt(\$outDoc, \$commands, \$ID, \$Stage, $topunits, 'N', $iVer);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   210
	  foreach my $task (@{$tasks})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   211
		  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   212
		  &process_task($task, $doc, \$outDoc, \$commands, \$ID, \$Stage, \@topbldList, $options, $iSourceDir, $iEffectiveDir, $iVer);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   213
		  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   214
	  process_prebuilt(\$outDoc, \$commands, \$ID, \$Stage, $topunits, 'Y', $iVer);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   215
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   216
	  $docElem->appendChild($commands);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   217
	  $docElem->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   218
	  #print $outDoc->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   219
	  $outDoc->printToFile($iDataOutput);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   220
	  $outDoc->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   221
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   222
	  &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   223
	  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   224
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   225
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   226
  if (!$gEmbeddedLog)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   227
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   228
    # Print Genxml log footer
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   229
    print $GenXml::gLogFileH "=== Genxml finished ".localtime()."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   230
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   231
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   232
  # Close file handles
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   233
  close($GenXml::gLogFileH);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   234
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   235
  $doc->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   236
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   237
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   238
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   239
# Error Processing function for the XML Validation
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   240
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   241
# Throws an exception (with die) when an error is encountered, this
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   242
# will stop the parsing process.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   243
# Don't die if a warning or info message is encountered, just print a message.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   244
sub my_fail
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   245
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   246
  my $code = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   247
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   248
  if ($code < 200)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   249
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   250
    print $GenXml::gLogFileH "ERROR: ".XML::Checker::error_string ($code, @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   251
    # Set Flag so all the errors are reported before dieing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   252
    $GenXml::gValidateFailed = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   253
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   254
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   255
  # Useful debug output
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   256
  print $GenXml::gLogFileH XML::Checker::error_string ($code, @_) if ($GenXml::gValidate);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   257
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   258
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   259
sub my_Unparsed_handler
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   260
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   261
  my ($Parser, $Entity, $Base, $Sysid, $Pubid, $Notation) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   262
  print $GenXml::gLogFileH "$Entity Unparsed";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   263
  die "ERROR: RealTimeBuild: Processing error\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   264
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   265
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   266
# Parse_files
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   267
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   268
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   269
# $iXMLSource - ref to array of filenames
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   270
# $iVersion - Version of xml file (new or old) ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   271
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   272
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   273
# $doc - XML DOM doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   274
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   275
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   276
# This function merges multiple XML files into one document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   277
sub Parse_files
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   278
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   279
  my ($iXmlSource, $iVersion) = @_;	# Version info passed for conditional processing of xml files
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   280
  my (@docs);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   281
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   282
  # Load the XML document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   283
  my %expat_options = (KeepCDATA => 1, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   284
          Handlers => [ Unparsed => \&my_Unparsed_handler ]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   285
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   286
  for (my $i = 0; $i < scalar(@$iXmlSource); $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   287
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   288
    # Create header for parsing each file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   289
    &logfileHeader(@$iXmlSource[$i]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   290
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   291
    my $parser = new XML::DOM::ValParser (%expat_options);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   292
    XML::DOM::ignoreReadOnly (1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   293
    local $XML::Checker::FAIL = \&my_fail;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   294
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   295
    # Useful debug output
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   296
    #print "Parsing ".@$iXmlSource[$i]."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   297
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   298
    $docs[$i] = $parser->parsefile (@$iXmlSource[$i]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   299
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   300
    # Create footer for parsing each file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   301
    &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   302
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   303
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   304
  # Check to see if any of the XML files failed validation and die
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   305
  die "ERROR: RealTimeBuild: Validation failed\n" if ($GenXml::gValidateFailed);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   306
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   307
# Set the appropriate version number
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   308
  for (my $i = 0; $i < scalar(@docs); $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   309
  { if((scalar(@docs))>1)  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   310
    if ($docs[$i]->getDocumentElement->getAttribute('schema') =~ /^2\./ && 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   311
	$docs[$i]->getDocumentElement->getTagName eq "SystemDefinition" &&
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   312
        $docs[1]->getDocumentElement->getTagName eq "SystemBuild")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   313
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   314
	$$iVersion = 2; 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   315
	last;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   316
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   317
   }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   318
   else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   319
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   320
   if ($docs[$i]->getDocumentElement->getAttribute('schema') =~ /^2\./ && 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   321
	$docs[$i]->getDocumentElement->getTagName eq "SystemDefinition")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   322
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   323
	$$iVersion = 2; 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   324
	last;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   325
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   326
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   327
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   328
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   329
  if ($$iVersion == 1)	{  # Docs load now merge into $docs[0] if $iVersion is 1 (i.e. old version of xml file)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   330
    for (my $i = 1; $i < scalar(@docs); $i++)  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   331
      # Create header for merging each file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   332
      &logfileHeader("Merging in XML file ".@$iXmlSource[$i]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   333
      &process_node(\($docs[0]->getElementsByTagName("SystemDefinition")),\($docs[$i]->getElementsByTagName("SystemDefinition")), \($docs[0]));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   334
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   335
      # Re-validate merged file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   336
      local $XML::Checker::FAIL = \&my_fail;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   337
      $docs[0]->check();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   338
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   339
      # Create footer for merging each file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   340
      &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   341
      # Check to see if any of the XML files failed validation and die
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   342
      die "ERROR: RealTimeBuild: Merged Validation failed\n" if ($GenXml::gValidateFailed);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   343
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   344
  } elsif ($$iVersion == 2) {   # Docs load now merge into $docs[$#docs + 1] if $iVersion is 2 (i.e. new version of xml file)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   345
    for (my $i = 1; $i < scalar(@docs); $i++)  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   346
      # Create header for merging each file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   347
      &logfileHeader("Merging in XML file ".@$iXmlSource[$i]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   348
      my $mergedDoc = &process_node2(\($docs[0]), \($docs[$i]));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   349
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   350
      # Re-validate merged file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   351
      local $XML::Checker::FAIL = \&my_fail;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   352
      $mergedDoc->check();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   353
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   354
      # Create footer for merging each file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   355
      &logfileFooter();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   356
      # Check to see if any of the XML files failed validation and die
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   357
      die "ERROR: RealTimeBuild: Merged Validation failed\n" if ($GenXml::gValidateFailed);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   358
      
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   359
      $docs[0] = $mergedDoc;      
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   360
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   361
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   362
  return $docs[0];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   363
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   364
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   365
# process_node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   366
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   367
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   368
# $node1 - ref to a node from the master
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   369
# $node2 - ref to a node from the slave
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   370
# $doc1 - ref to the doc of node1 so we can set the doc owner to the (not DOM spec) to get around WRONG_DOCUMENT_ERR restriction
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   371
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   372
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   373
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   374
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   375
# This function processes a node in two DOM documents, if any children match then it calls itself to process
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   376
# the children nodes further
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   377
sub process_node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   378
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   379
  my ($node1, $node2, $doc1) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   380
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   381
  # Some nodes need special processing e.g. SystemDefinition
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   382
  # This is because there can only be a certain number of these nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   383
  # child node / element rules outlined below, this rules are applied to the children of the node in question
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   384
  # Child Node / element tag        Rule
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   385
  # ------------------------        ----
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   386
  # SystemDefinition                Merge the name and revision/schema CDATA as there can be only one of this element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   387
  # systemModel                     Always processed further as there can only be 1 or 0 of these
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   388
  # layer                           Same name process further otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   389
  # logicalset                      Same name process further otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   390
  # logicalsubset                   Same name process further otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   391
  # module                          Same name process further otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   392
  # component                       Same name process further otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   393
  # unit                            Same unitID generate ERROR and not replace child, otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   394
  # sub elements of unit            No processing needed as these cannot be merged
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   395
  # package                         Same name process further otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   396
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   397
  # build                           Always processed further as there can only be 1 or 0 of these  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   398
  # unitList                        Same name process further otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   399
  # unitRef                         Same unit ignore, different unit append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   400
  # targetList                      Same name generate ERROR and not replace child, otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   401
  # target                          Same name generate ERROR and not replace child, otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   402
  # option                          Same name generate ERROR and not replace child, otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   403
  # configuration                   Same name generate ERROR and not replace child, otherwise append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   404
  # sub elements of configuration   No processing needed as these cannot be merged
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   405
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   406
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   407
  # All other nodes                 Append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   408
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   409
  # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   410
  #$GenXml::count++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   411
  #print "enter $GenXml::count\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   412
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   413
  # Handle the special case for the first call to this function with the node containing the SystemDefinition
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   414
  if (($$node1->getTagName eq "SystemDefinition") && ($$node2->getTagName eq "SystemDefinition"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   415
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   416
    # Get the name attributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   417
    my ($name1) = $$node1->getAttribute('name');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   418
    my ($name2) = $$node2->getAttribute('name');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   419
    # Combine the two and set the attribute into the merged file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   420
    $$node1->setAttribute('name',$name1." + ".$name2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   421
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   422
    # Get the revision attributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   423
    my ($revision1) = $$node1->getAttribute('revision');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   424
    my ($revision2) = $$node2->getAttribute('revision');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   425
    # Get the schema attributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   426
    my ($schema1) = $$node1->getAttribute('schema');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   427
    my ($schema2) = $$node2->getAttribute('schema');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   428
    # If both schema attributes are defined, combine the two and set the attribute into the merged file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   429
    # Note that even if an attribute does not exist in the XML file, XML::DOM returns an empty string (not undef)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   430
    if (($schema1) and ($schema2))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   431
    { # Both files have "new DTD".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   432
      if (($revision1) or ($revision2))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   433
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   434
        print $GenXml::gLogFileH "ERROR: Cannot define both schema and revison attributes in same file. Merged file will probably not be usable.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   435
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   436
      if ($schema1 eq $schema2)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   437
      { # Both files have same schema attribute. Assign it to merged file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   438
        $$node1->setAttribute('schema',$schema1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   439
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   440
      else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   441
      { # Files have different schema attributes. Combine and assign it to merged file. Warn!!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   442
        print $GenXml::gLogFileH "WARNING: Source file schema attribute values differ ($schema1 vs $schema2). Merged file may not be usable.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   443
        $$node1->setAttribute('schema',$schema1." + ".$schema2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   444
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   445
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   446
    # If both revision attributes are defined, combine the two and set the attribute into the merged file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   447
    elsif (($revision1) and ($revision2))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   448
    { # Both files have "old DTD". Retain this code for compatibility
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   449
      print $GenXml::gLogFileH "REMARK: Both source files have \"old style\" DTDs. See SystemDefinition \"revision\" attribute.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   450
      $$node1->setAttribute('revision',$revision1." + ".$revision2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   451
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   452
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   453
    { # Files have different DTDs. Use attribute found in first file. report as ERROR!!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   454
        print $GenXml::gLogFileH "ERROR: Source file schema/revison attributes conflict. Merged file will probably not be usable.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   455
        if ($schema1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   456
        { # First file had new DTD and had a schema attribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   457
          $$node1->setAttribute('schema',$schema1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   458
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   459
        elsif ($revision1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   460
        { # First file had old DTD and had a revision attribute (not a schema)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   461
          $$node1->setAttribute('revision',$revision1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   462
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   463
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   464
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   465
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   466
  # Get the children of the parent nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   467
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   468
  my $nodelist1 = $$node1->getChildNodes;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   469
  my $nodelist2 = $$node2->getChildNodes;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   470
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   471
  # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   472
  #print "has ".$nodelist2->getLength." children\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   473
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   474
  # Itterate throught the children of node2 check to see if they are present / rule match in node 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   475
  my $ni = $nodelist2->getLength;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   476
  for (my $i = 0; $i < $ni; $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   477
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   478
    # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   479
    #print "node $i ".$nodelist2->item($i)->getNodeTypeName."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   480
    if ($nodelist2->item($i)->getNodeTypeName eq "ELEMENT_NODE")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   481
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   482
      # Handle rule match on ELEMENTS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   483
      my $tagname2 = $nodelist2->item($i)->getTagName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   484
      
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   485
      # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   486
      # print "Tagname = $tagname\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   487
      if (($tagname2 eq "systemModel") || ($tagname2 eq "build") )
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   488
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   489
        my $iBuildIndx;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   490
        # find the $node1 for this elements
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   491
        my $nj = $nodelist1->getLength;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   492
        my $match = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   493
        for (my $j = 0; $j < $nj; $j++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   494
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   495
          if ($nodelist1->item($j)->getNodeTypeName eq "ELEMENT_NODE")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   496
          {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   497
            my $tagname1 = $nodelist1->item($j)->getTagName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   498
            if ($tagname1 eq $tagname2)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   499
            {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   500
              # process further
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   501
              
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   502
              # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   503
              #print "processing $tagname further\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   504
              &process_node(\($nodelist1->item($j)), \($nodelist2->item($i)), $doc1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   505
              $match = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   506
            }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   507
            else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   508
            {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   509
              if ($tagname1 eq 'build')
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   510
              {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   511
                $iBuildIndx = $j;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   512
              }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   513
              if ((($tagname2 eq 'systemModel') and ($tagname1 ne 'systemModel')) or ((($tagname2 eq 'build') and ($tagname1 ne 'build'))))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   514
              {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   515
                next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   516
              }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   517
              # no systemModel or build element found so append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   518
              &append_child($node1, \($nodelist2->item($i)), $doc1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   519
            }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   520
          }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   521
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   522
        unless ($match)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   523
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   524
          # no systemModel or build element found so append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   525
          # In the special case of adding an instance of 'systemModel' we must specify that this goes before any instance of 'build'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   526
          my $iRefChildRef = ($tagname2 eq 'systemModel')? $nodelist1->item($iBuildIndx): undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   527
          &append_child($node1, \($nodelist2->item($i)), $doc1, $iRefChildRef);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   528
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   529
      } elsif (($tagname2 eq "layer") || ($tagname2 eq "logicalset") || ($tagname2 eq "logicalsubset") || ($tagname2 eq "module") || ($tagname2 eq "component") || ($tagname2 eq "package") || ($tagname2 eq "unitList"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   530
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   531
        # Check the $node1 for elements with the same "name"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   532
        my $match; # Flag for matching element found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   533
        my $nj = $nodelist1->getLength;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   534
        for (my $j = 0; $j < $nj; $j++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   535
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   536
          # Only look at element nodes in node1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   537
          if ($nodelist1->item($j)->getNodeTypeName eq "ELEMENT_NODE")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   538
          {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   539
            if ($nodelist2->item($i)->getAttribute('name') eq $nodelist1->item($j)->getAttribute('name'))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   540
            {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   541
              # Process further match found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   542
              $match = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   543
              
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   544
              # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   545
              #print "processing j=$j $tagname2 further ".$nodelist2->item($i)->getAttribute('name')."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   546
              
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   547
              &process_node(\($nodelist1->item($j)), \($nodelist2->item($i)), $doc1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   548
            }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   549
          }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   550
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   551
        # If no match found Append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   552
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   553
        # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   554
        #print "new $tagname2 added\n" if (!$match);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   555
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   556
        &append_child($node1, \($nodelist2->item($i)), $doc1) if (!$match);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   557
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   558
      } elsif (($tagname2 eq "unit") || ($tagname2 eq "targetList") || ($tagname2 eq "target") || ($tagname2 eq "option") || ($tagname2 eq "configuration")) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   559
        # Check the $node1 for elements with the same ID attribute (Global check for ID clashes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   560
        my $idAttrib;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   561
        if ($tagname2 eq "unit")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   562
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   563
          # Special case of the unit element as this has uses the attribute of unitID instead of name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   564
          $idAttrib = "unitID";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   565
        } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   566
          $idAttrib = "name";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   567
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   568
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   569
        my $ID = $nodelist2->item($i)->getAttribute($idAttrib);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   570
        # Search for the XML ID in $doc1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   571
        if( scalar(XML::XQL::solve ("//*[\@$idAttrib = '$ID']", $$doc1)))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   572
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   573
          print $GenXml::gLogFileH "REMARK: $ID already exists, not merging this $tagname2 element\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   574
        } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   575
          # unitID not found so append elememnt
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   576
          
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   577
          # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   578
          # print "new $tagname2 added\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   579
          
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   580
          &append_child($node1, \($nodelist2->item($i)), $doc1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   581
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   582
      } elsif ($tagname2 eq "unitRef") {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   583
        # Check the $node1 for elements with the same "name"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   584
        my $match; # Flag for matching element found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   585
        my $nj = $nodelist1->getLength;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   586
        for (my $j = 0; $j < $nj; $j++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   587
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   588
          # Only look at element nodes in node1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   589
          if ($nodelist1->item($j)->getNodeTypeName eq "ELEMENT_NODE")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   590
          {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   591
            if ($nodelist2->item($i)->getAttribute('unit') eq $nodelist1->item($j)->getAttribute('unit'))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   592
            {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   593
              # Ignore the unitRef element as it is a duplicate
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   594
              $match = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   595
              print $GenXml::gLogFileH "WARNING: Duplicate unitRef ".$nodelist2->item($i)->getAttribute('unit')." not merging\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   596
            }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   597
          }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   598
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   599
        # No match found Append Child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   600
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   601
        # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   602
        # print "New unitRef\n" if (!$match);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   603
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   604
        &append_child($node1, \($nodelist2->item($i)), $doc1) if (!$match);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   605
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   606
      } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   607
        # Element not recognised so append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   608
        &append_child($node1, \($nodelist2->item($i)), $doc1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   609
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   610
    } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   611
      # Handle non element nodes (append child of node2 to node 1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   612
      # At the moment adding in non element nodes adds a lot of whitespace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   613
      # TODO: correctly handle non element nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   614
      # This is not important at the moment as there are no important non element nodes for the merge
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   615
      #&append_child($node1, \($nodelist2->item($i)), $doc1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   616
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   617
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   618
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   619
  #print "return $GenXml::count\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   620
  #$GenXml::count--;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   621
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   622
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   623
# append_child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   624
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   625
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   626
# $node1 - is already a ref of the node to append to
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   627
# $node2 - ref of node from nodelist2 to append to $node1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   628
# $doc1 - ref to document to merge the node into (need for non DOM operation of changing owner of node)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   629
# $refnode - ref to node in fromt of which to insert node2 (If undef, append node2)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   630
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   631
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   632
# ???
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   633
sub append_child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   634
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   635
  my ($node1, $node2, $doc1, $refnode) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   636
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   637
  # Clone the node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   638
  my $clone = $$node2->cloneNode(1); 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   639
  # Fix the owner of node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   640
  $clone->setOwnerDocument($$doc1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   641
  # Append a line return for more tidy xml
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   642
  $$node1->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   643
  # Append (or insert) the node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   644
  # Note: it seems that insertBefore($clone,undef) is identical to appendChild($clone)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   645
  $$node1->insertBefore($clone,$refnode);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   646
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   647
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   648
# write_component_list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   649
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   650
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   651
# $doc         - Reference to input document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   652
# $iTextOutput - Name of output file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   653
# $iConfName   - Name of configuration being described
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   654
# $bldList     - Reference to the bldList array
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   655
# $options     - Reference to the options array
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   656
# $tasks       - Reference to the tasks array
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   657
# $iEffectiveDir  - Root of source tree in which file will be used
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   658
# $iVersion - Version of xml file (new or old) ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   659
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   660
# Description:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   661
# Write out old-style "list of components" build description for the configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   662
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   663
sub write_component_list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   664
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   665
	my ($doc, $iTextOutput, $iConfName, $bldList, $options, $tasks, $iEffectiveDir, $iVersion) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   666
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   667
	# process list of tasks to find build targets and bootstrap info	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   668
	my %targets;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   669
	my $bootflag = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   670
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   671
	foreach my $task (@$tasks)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   672
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   673
		# Read all the task 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   674
		my @children = $task->getChildNodes;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   675
		foreach my $child (@children)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   676
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   677
			next if ($child->getNodeTypeName ne "ELEMENT_NODE");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   678
			if ($child->getTagName eq "specialInstructions")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   679
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   680
				# "setupprj" in the command is taken to mean "bootstrap E32ToolP"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   681
				$bootflag = 1 if ($child->getAttribute("command") =~ /setupprj/i);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   682
				next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   683
				}			
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   684
	        my $targetlist = $child->getAttributeNode("targetList");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   685
	        if (defined $targetlist)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   686
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   687
				my @targetnames = &find_targetList_by_ID($doc, $targetlist->getValue);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   688
				foreach my $target (@targetnames)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   689
					{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   690
					$targets{$target}= 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   691
					}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   692
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   693
	        } 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   694
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   695
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   696
	# create output file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   697
	open TEXTFILE, "> $iTextOutput" or die "ERROR: RealTimeBuild: Couldn't open $iTextOutput for writing: $!\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   698
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   699
    print TEXTFILE <<HEADER_TXT;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   700
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   701
# ****************************** IMPORTANT NOTE ************************************
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   702
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   703
# The configuration was specified as: $iConfName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   704
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   705
# **********************************************************************************
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   706
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   707
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   708
HEADER_TXT
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   709
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   710
    print TEXTFILE "# Optional variations in the generated scripts\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   711
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   712
    my $column2pos = 8;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   713
    foreach my $option (@$options)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   714
	my $name = '<option ????>';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   715
	if ($option =~ /^-(.+)/) {$name = "<option $1>"}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   716
	my $len = length $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   717
	while ($len > $column2pos) { $column2pos += 8; }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   718
	printf TEXTFILE "%-*s\t# use abld %s\n", $column2pos, $name, $option;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   719
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   720
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   721
    $column2pos = 8;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   722
    foreach my $target (sort keys %targets)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   723
	# abld targets are only one word
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   724
	next if ($target =~ /\w+\s+\w+/);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   725
	my $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   726
	if ($target =~ /(misa|mint|mcot|mtemplate|meig)/i)		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   727
		$name = "<option arm_assp $target>";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   728
	} else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   729
		$name = "<option $target>";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   730
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   731
	my $len = length $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   732
	while ($len > $column2pos) { $column2pos += 8; }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   733
	printf TEXTFILE "%-*s\t#\n", $column2pos, $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   734
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   735
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   736
    print TEXTFILE "\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   737
    print TEXTFILE "# List of components required \n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   738
    print TEXTFILE "#\n# Name		abld_directory\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   739
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   740
    if($bootflag)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   741
        print TEXTFILE "#\n# Bootstrapping....\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   742
        print TEXTFILE "<special bldfiles E32Toolp group>			# Special installation for E32ToolP\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   743
        print TEXTFILE "# Components:\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   744
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   745
    print TEXTFILE "#\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   746
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   747
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   748
    my $srcprefix = quotemeta($iEffectiveDir);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   749
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   750
    $column2pos = 8;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   751
    foreach my $component (@$bldList)		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   752
	my $bldinfdir = $component->[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   753
	next if ($bldinfdir eq "");	# skip MRP-only entries
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   754
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   755
	$bldinfdir =~ s/^$srcprefix//o;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   756
	my $len = length $component->[0];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   757
	while ($len > $column2pos) { $column2pos += 8; }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   758
	printf TEXTFILE "%-*s\t%s\n", $column2pos, $component->[0], $bldinfdir;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   759
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   760
    close TEXTFILE	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   761
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   762
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   763
# write_CBR_list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   764
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   765
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   766
# $iCBROutput  - Name of output file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   767
# $bldList     - Reference to the bldList array
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   768
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   769
# Description:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   770
# Write out "list of CBR components" for the configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   771
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   772
sub write_CBR_list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   773
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   774
	my ($iCBROutput, $bldList) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   775
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   776
	my @components = ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   777
	foreach my $component (@$bldList)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   778
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   779
		my $mrp = $component->[2];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   780
		next if ($mrp eq "");	# skip entries without MRP files
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   781
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   782
		push @components, sprintf("%s\t%s\n", $component->[0], $mrp);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   783
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   784
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   785
	# create output file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   786
	open TEXTFILE, "> $iCBROutput" or die "ERROR: RealTimeBuild: Couldn't open $iCBROutput for writing: $!\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   787
	print TEXTFILE sort @components;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   788
	close TEXTFILE	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   789
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   790
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   791
# start_output_doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   792
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   793
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   794
# $iConfName - Configuration name used
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   795
# $iVersion - Version of xml file (new or old) ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   796
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   797
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   798
# $outDoc - document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   799
# $docElem - root element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   800
# $commands - command node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   801
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   802
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   803
# This function produces the static parts of the output XML file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   804
sub start_output_doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   805
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   806
  my ($iConfName, $iVersion) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   807
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   808
  my ($outParser, $outDoc, $docElem, $commands);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   809
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   810
  # set the doctype based on which version of file is passed.  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   811
  my $doctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   812
  if ($iVersion == 1)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   813
	$doctype = "Build";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   814
  } elsif ($iVersion == 2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   815
	$doctype = "SystemBuild" ;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   816
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   817
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   818
  $outParser = new XML::DOM::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   819
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   820
  my $str = <<END;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   821
<?xml version="1.0"?>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   822
<!DOCTYPE $doctype  [
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   823
  <!ELEMENT Product (Commands)>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   824
  <!ATTLIST Product name CDATA #REQUIRED>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   825
  <!ELEMENT Commands (Execute+ | SetEnv*)>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   826
  <!ELEMENT Execute EMPTY>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   827
  <!ATTLIST Execute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   828
  ID CDATA #REQUIRED
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   829
  Stage CDATA #REQUIRED
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   830
  Component CDATA #REQUIRED
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   831
  Cwd CDATA #REQUIRED
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   832
  CommandLine CDATA #REQUIRED>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   833
  <!ELEMENT SetEnv EMPTY>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   834
  <!ATTLIST SetEnv
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   835
  Order ID #REQUIRED
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   836
  Name CDATA #REQUIRED
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   837
  Value CDATA #REQUIRED>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   838
]>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   839
<Product>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   840
</Product>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   841
END
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   842
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   843
  $outDoc = $outParser->parse($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   844
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   845
  # get the document element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   846
  $docElem = $outDoc->getDocumentElement;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   847
  $docElem->setAttribute('name', $iConfName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   848
  # Add the Commands Node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   849
  $commands = $outDoc->createElement('Commands');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   850
  $commands->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   851
  # create the default SetEnv elements
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   852
  my $SetEnv1 = $outDoc->createElement('SetEnv');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   853
  $SetEnv1->setAttribute('Order', '1');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   854
  $SetEnv1->setAttribute('Name', 'EPOCROOT');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   855
  $SetEnv1->setAttribute('Value', '\\');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   856
  $commands->appendChild($SetEnv1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   857
  $commands->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   858
  my $SetEnv2 = $outDoc->createElement('SetEnv');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   859
  $SetEnv2->setAttribute('Order', '2');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   860
  $SetEnv2->setAttribute('Name', 'PATH');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   861
  $SetEnv2->setAttribute('Value', '\\epoc32\\gcc\\bin;\\epoc32\\tools;%PATH%');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   862
  $commands->appendChild($SetEnv2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   863
  $commands->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   864
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   865
  return ($outDoc, $docElem, $commands);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   866
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   867
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   868
# process_prebuilt
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   869
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   870
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   871
# $outDoc - Reference to output document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   872
# $commands - Reference to the command node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   873
# $ID - Reference to theExecute ID counter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   874
# $Stage - Reference to the Execute Stage counter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   875
# $topunits - Reference to the list of unit, package & prebuilt elements
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   876
# $late - Selects on the "late" attribute of prebuilt elements   
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   877
# $iVersion - Version of xml file (new or old) ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   878
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   879
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   880
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   881
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   882
# Generates the "getrel" commands for prebuilt elements
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   883
sub process_prebuilt
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   884
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   885
  my ($outDoc, $commands, $ID, $Stage, $topunits, $late, $iVersion) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   886
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   887
  my ($name, $version, $islate);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   888
  foreach my $unit (@$topunits)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   889
  	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   890
	my @prebuilt;	# a list of all <prebuilt> or <unit prebuilt="...">
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   891
	if ($iVersion == 1)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   892
		if ($unit->getTagName eq "prebuilt")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   893
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   894
			push(@prebuilt, $unit);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   895
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   896
	} elsif ($iVersion == 2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   897
		my @subunits = $unit->getElementsByTagName("unit");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   898
		foreach my $subunit (@subunits)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   899
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   900
			if ($subunit->getAttribute("prebuilt"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   901
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   902
				push(@prebuilt, $subunit);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   903
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   904
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   905
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   906
	  foreach my $unit (@prebuilt)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   907
	  	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   908
		$version = $unit->getAttribute("version");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   909
		$islate = $unit->getAttribute("late");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   910
		$name = $unit->getAttribute(($iVersion == 1) ? "name" : "prebuilt");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   911
	  	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   912
		$islate = "N" if (!defined $islate || $islate eq "");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   913
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   914
		next if ($late ne $islate);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   915
		next if (!$late && $islate eq "Y");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   916
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   917
		# Create the element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   918
		my $task_elem = $$outDoc->createElement('Execute');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   919
		$task_elem->setAttribute('ID', $$ID);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   920
		$$ID++; # The ID must always be incremented
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   921
		$task_elem->setAttribute('Stage', $$Stage);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   922
		$$Stage++;	# getrel operations are serial
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   923
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   924
		$task_elem->setAttribute('Component',$name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   925
		$task_elem->setAttribute('Cwd','%EPOCROOT%');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   926
		$task_elem->setAttribute('CommandLine',"getrel $name $version");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   927
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   928
		$$commands->appendChild($task_elem);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   929
		$$commands->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   930
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   931
	 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   932
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   933
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   934
# process_task
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   935
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   936
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   937
# $task - task node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   938
# $doc - Reference to input document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   939
# $outDoc - Reference to output document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   940
# $commands - Reference to the command node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   941
# $ID - Reference to theExecute ID counter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   942
# $Stage - Reference to the Execute Stage counter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   943
# $bldList - Reference to the bldList array
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   944
# $options - Reference to the options array
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   945
# $iSourceDir - root of the current source tree
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   946
# $iEffectiveDir - root from which the source tree will be used
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   947
# $iVersion - Version of xml file (new or old) ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   948
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   949
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   950
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   951
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   952
# This function processes the task nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   953
sub process_task
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   954
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   955
  my ($task, $doc, $outDoc, $commands, $ID, $Stage, $bldList, $options, $iSourceDir, $iEffectiveDir, $iVersion) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   956
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   957
  my @targets;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   958
  my @localBldList; # Used for task specific unit list overrides
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   959
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   960
  # re-process the $iSourceDir & $iSourceDir based on version of xml file along with value for unitListRef and unitList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   961
  my ($unitListRef, $unitList);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   962
  if($iVersion == 1)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   963
	$unitListRef = "unitListRef";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   964
	$unitList = "unitList";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   965
  } elsif ($iVersion == 2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   966
	$unitListRef = "listRef";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   967
	$unitList = "list";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   968
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   969
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   970
  # Read all the task 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   971
  my @children = $task->getChildNodes;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   972
  foreach my $child (@children)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   973
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   974
    if ($child->getNodeTypeName eq "ELEMENT_NODE")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   975
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   976
      # Check for unitListRef for task unit list override
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   977
      if ($child->getTagName eq $unitListRef)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   978
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   979
        #Processes the unitListRefs to build up a complete list of units which are IDREFs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   980
        my @localUnits= &find_unitList_by_ID($doc, $child->getAttribute($unitList), $iVersion);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   981
        push @localBldList, &compute_bldList($iSourceDir,$iEffectiveDir,\@localUnits, $iVersion);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   982
        # Overwrite Ref $bldList with new Ref to @localBldList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   983
        $bldList = \@localBldList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   984
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   985
      
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   986
      if ($child->getTagName eq "specialInstructions")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   987
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   988
        #Processes the unitListRefs to build up a complete list of units which are IDREFs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   989
        my $task_elem = $$outDoc->createElement('Execute');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   990
        $task_elem->setAttribute('ID', $$ID);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   991
        $$ID++; # The ID must always be incremented
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   992
        $task_elem->setAttribute('Stage', $$Stage);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   993
        $$Stage++; # All specialInstructions are done sequentially
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   994
        $task_elem->setAttribute('Component', $child->getAttributeNode("name")->getValue);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   995
        my ($cwd) = $child->getAttributeNode("cwd")->getValue;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   996
        # Replace any Environment variables
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   997
        my ($cwdtemp) = $cwd;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   998
        $cwdtemp =~ s/%(\w+)%/$ENV{$1}/g;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   999
        # If $cwd does not starts with a drive letter or absolute path then add the source Directory on the front
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1000
        if (!(($cwdtemp =~ /^\w:[\\]/) || ($cwdtemp =~ /^\\/)))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1001
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1002
          $cwd = $iEffectiveDir . $cwd;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1003
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1004
        $task_elem->setAttribute('Cwd', $cwd);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1005
        $task_elem->setAttribute('CommandLine', $child->getAttributeNode("command")->getValue);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1006
        $$commands->appendChild($task_elem);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1007
        $$commands->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1008
      } elsif ($child->getTagName eq "buildLayer") {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1009
        # targetParallel & unitParallel are optional so check that they exist before trying to get the value.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1010
        my $unitP = $child->getAttribute("unitParallel");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1011
        my $targetP = $child->getAttribute("targetParallel") if ($child->getAttributeNode("targetParallel"));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1012
        my $abldCommand = $child->getAttribute("command");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1013
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1014
        # Build the list of targets, targets are optional
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1015
        if ($child->getAttributeNode("targetList"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1016
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1017
          @targets = &find_targetList_by_ID($doc, $child->getAttributeNode("targetList")->getValue);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1018
        } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1019
          # There are no targets associated with this buildlayer
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1020
          $targetP = "NA"; # Not applicable
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1021
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1022
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1023
        # Build the correct option string
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1024
        my $optionStr = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1025
        foreach my $option (@$options)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1026
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1027
          # only add -savespace if the command abld target or abld build take this option
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1028
          # don't add -keepgoing if -what or -check are part of the command
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1029
          if ((($option =~ /\s*-savespace\s*/i) || ($option =~ /\s*-s\s*/i) ) && (($abldCommand =~ /^\s*abld\s+makefile/i) || ($abldCommand =~ /^\s*abld\s+target/i) || ($abldCommand =~ /^\s*abld\s+build/i)))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1030
          {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1031
            $optionStr .= " $option" ;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1032
          }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1033
          if (($option =~ /\s*-keepgoing\s*/i) || ($option =~ /\s*-k\s*/i) )
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1034
          {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1035
            if (!(($abldCommand =~ /^\s*abld\s+\w*\s*\w*\s*-check\s*/i) || ($abldCommand =~ /^\s*abld\s+\w*\s*\w*\s*-c\s*/i) || ($abldCommand =~ /^\s*abld\s+\w*\s*\w*\s*-what\s*/i) || ($abldCommand =~ /^\s*abld\s+\w*\s*\w*\s*-w\s*/i)))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1036
            {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1037
              $optionStr .= " $option" ;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1038
            }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1039
          }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1040
            # This allows us to either build symbol files or not build symbols to save build time.          
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1041
            # only add -no_debug if the command abld makefile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1042
            if (($option =~ /\s*-no_debug\s*/i) && ($abldCommand =~ /^\s*abld\s+makefile/i))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1043
            {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1044
              $optionStr .= " $option" ;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1045
            }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1046
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1047
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1048
        # Remove the mrp-only entries from the bldList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1049
        my @bldInfList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1050
        foreach my $array (@{$bldList})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1051
          {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1052
          push @bldInfList, $array if ($$array[1] ne "");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1053
          }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1054
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1055
        # Cover all the combinations of units and targets
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1056
        my ($Ref1, $Ref2, $loop1, $loop2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1057
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1058
        if ($targetP eq "N")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1059
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1060
          # Got to switch order of looping
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1061
          $Ref2 = \@bldInfList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1062
          $Ref1 = \@targets;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1063
          $loop2 = $unitP;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1064
          $loop1 = $targetP;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1065
        } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1066
          $Ref1 = \@bldInfList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1067
          $Ref2 = \@targets;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1068
          $loop1 = $unitP;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1069
          $loop2 = $targetP;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1070
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1071
        
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1072
        for (my $i = 0; $i < scalar(@$Ref1); $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1073
        {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1074
          if ($targetP ne "NA")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1075
          {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1076
            for (my $j = 0; $j < scalar(@$Ref2); $j++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1077
            {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1078
              # Create the element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1079
              my $task_elem = $$outDoc->createElement('Execute');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1080
              $task_elem->setAttribute('ID', $$ID);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1081
              $$ID++; # The ID must always be incremented
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1082
              $task_elem->setAttribute('Stage', $$Stage);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1083
              
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1084
              if ($targetP eq "N") {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1085
                # loops swapped but the order of unitP and targetP need to be swapped back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1086
                # unit (Component) name is the 0 element of the sub array, source location in element 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1087
                $task_elem->setAttribute('Component',$$Ref2[$j][0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1088
                # Find the bldFile directory and set as Cwd
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1089
                $task_elem->setAttribute('Cwd',$$Ref2[$j][1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1090
                
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1091
                $task_elem->setAttribute('CommandLine',$abldCommand.$optionStr." ".$$Ref1[$i]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1092
                $$commands->appendChild($task_elem);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1093
                $$commands->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1094
              } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1095
                # unit (Component) name is the 0 element of the sub array, source location in element 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1096
                $task_elem->setAttribute('Component',$$Ref1[$i][0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1097
                # Find the bldFile directory and set as Cwd
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1098
                $task_elem->setAttribute('Cwd',$$Ref1[$i][1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1099
                
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1100
                $task_elem->setAttribute('CommandLine',$abldCommand.$optionStr." ".$$Ref2[$j]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1101
                $$commands->appendChild($task_elem);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1102
                $$commands->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1103
              }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1104
              $$Stage++ if (($loop1 eq "N") && ($loop2 eq "N"));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1105
            }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1106
            $$Stage++ if (($loop1 eq "N") && ($loop2 eq "Y"));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1107
          } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1108
            # Create the element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1109
            my $task_elem = $$outDoc->createElement('Execute');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1110
            $task_elem->setAttribute('ID', $$ID);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1111
            $$ID++; # The ID must always be incremented
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1112
            $task_elem->setAttribute('Stage', $$Stage);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1113
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1114
            # unit (Component) name is the 0 element of the sub array, source location in element 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1115
            $task_elem->setAttribute('Component',$$Ref1[$i][0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1116
            # Find the bldFile directory and set as Cwd
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1117
            $task_elem->setAttribute('Cwd',$$Ref1[$i][1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1118
            
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1119
            $task_elem->setAttribute('CommandLine',$abldCommand.$optionStr);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1120
            $$commands->appendChild($task_elem);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1121
            $$commands->addText("\n");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1122
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1123
            $$Stage++ if ($loop1 ne "Y");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1124
          }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1125
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1126
        # Add the * (stage++) for the combinations that don't get this done by the loops
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1127
        $$Stage++ if ($loop1 eq "Y");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1128
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1129
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1130
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1131
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1132
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1133
# delete_unmatched_units
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1134
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1135
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1136
# $node - node in the system model
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1137
# $deletedref - reference to hash of deleted unitIDs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1138
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1139
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1140
# Returns 1 if all significant children of the node have been removed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1141
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1142
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1143
# This function simplifies the XML by removing anything which wasn't marked as MATCHED.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1144
# It's called recursively so that it can "clean up" the structure if whole subtrees have
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1145
# all of their significant content removed. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1146
sub delete_unmatched_units
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1147
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1148
	my ($node, $deletedUnitsRef) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1149
	my @children = $node->getChildNodes;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1150
	return 0 if (scalar @children == 0);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1151
	my $now_empty = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1152
	my $deleted_something = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1153
	foreach my $child (@children)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1154
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1155
		if ($child->getNodeTypeName ne "ELEMENT_NODE")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1156
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1157
			# text and comments don't count
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1158
			next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1159
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1160
		my $tag = $child->getTagName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1161
		my $deletedThis = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1162
		if ((($tag eq "unit" || $tag eq "package" || $tag eq "prebuilt") && $iVer == 1) || (($tag eq "component" || $tag eq "unit") && $iVer == 2))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1163
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1164
			# only units,prebuilts & packages are tagged
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1165
			if (!$child->getAttribute("MATCHED"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1166
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1167
				if ($tag eq "unit")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1168
					{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1169
					my $unitID = $child->getAttribute("unitID");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1170
					$$deletedUnitsRef{$unitID} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1171
					}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1172
				if($tag eq "unit" && $iVer == 2)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1173
					{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1174
					my $version = $child->getAttribute("version");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1175
					printf $GenXml::gLogFileH "Simplification removed $tag %s %s\n", ($version eq '') ? 'from' : "v$version of" ,$node->getAttribute("name"); 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1176
					}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1177
				else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1178
					{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1179
					printf $GenXml::gLogFileH "Simplification removed $tag %s\n", $child->getAttribute("name"); 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1180
					}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1181
				$node->removeChild($child);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1182
				$deletedThis = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1183
				$deleted_something = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1184
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1185
			else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1186
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1187
				$child->removeAttribute("MATCHED");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1188
				$now_empty = 0;		# something left in due to this child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1189
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1190
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1191
		# keep going to filter child units
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1192
		if (!$deletedThis && $tag ne "unit" && $tag ne "package" && $tag ne "prebuilt")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1193
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1194
			if (delete_unmatched_units($child,$deletedUnitsRef) == 1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1195
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1196
				# Child was empty and can be removed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1197
				$node->removeChild($child);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1198
				$deleted_something = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1199
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1200
			else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1201
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1202
				$now_empty = 0;		# something left in due to this child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1203
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1204
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1205
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1206
	return 0 unless ($deleted_something);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1207
	return $now_empty;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1208
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1209
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1210
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1211
# Filter_doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1212
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1213
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1214
# $doc - Reference to input document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1215
# $iFilter - filter to apply
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1216
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1217
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1218
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1219
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1220
# This function simplifies the XML by removing anything which fails to pass the filter.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1221
# The resulting doc is then useful for tools which don't understand the filter attributes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1222
sub Filter_doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1223
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1224
	my ($doc, $iFilter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1225
	  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1226
	# the filtering will have to be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1227
	# - find the configurations which pass the filter (and delete the rest)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1228
	# - identify items which are kept by some configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1229
	# - remove the ones which aren't kept by any configuration.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1230
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1231
	# deal with the <configuration> items, checking their filters
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1232
	my %unitLists;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1233
	my @nodes = $doc->getElementsByTagName ("configuration");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1234
	foreach my $node (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1235
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1236
		my $configname = $node->getAttribute("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1237
		my @configspec = split /,/,$node->getAttribute("filter");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1238
		my $failed = check_filter($iFilter,\@configspec);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1239
		if ($failed ne "")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1240
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1241
			print $GenXml::gLogFileH "Simplification removed configuration $configname ($failed)\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1242
			$node->getParentNode->removeChild($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1243
			next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1244
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1245
		# find all the units for this configuration and mark them as MATCHED
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1246
		print $GenXml::gLogFileH "Analysing configuration $configname...\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1247
  		my $units = get_configuration_units($doc, $node, 0, 0);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1248
  		foreach my $unit (@$units)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1249
  			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1250
  			$unit->setAttribute("MATCHED", 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1251
  			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1252
  		# note all the unitLists referenced by this configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1253
  		foreach my $unitListRef ($node->getElementsByTagName("unitListRef"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1254
  			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1255
  			my $unitList = $unitListRef->getAttribute("unitList");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1256
  			$unitLists{$unitList} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1257
  			} 		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1258
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1259
	# walk the model, removing the "MATCHED" attribute and deleting any which weren't marked
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1260
	my %deletedUnits;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1261
	delete_unmatched_units($doc, \%deletedUnits);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1262
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1263
	# clean up the unitlists
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1264
	my @unitLists = $doc->getElementsByTagName("unitList");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1265
	foreach my $unitList (@unitLists)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1266
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1267
		my $name = $unitList->getAttribute("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1268
		if (!defined $unitLists{$name})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1269
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1270
			print $GenXml::gLogFileH "Simplification removed unitList $name\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1271
			$unitList->getParentNode->removeChild($unitList);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1272
			next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1273
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1274
		foreach my $unitRef ($unitList->getElementsByTagName("unitRef"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1275
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1276
			my $id = $unitRef->getAttribute("unit");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1277
			if (defined $deletedUnits{$id})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1278
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1279
				$unitList->removeChild($unitRef);	# reference to deleted unit
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1280
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1281
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1282
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1283
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1284
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1285
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1286
# find_configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1287
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1288
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1289
# $doc - DOM document model
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1290
# $iConfName - configuration name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1291
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1292
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1293
# $configuration - the node of the named configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1294
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1295
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1296
# This function locates and returns the named configuration node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1297
sub find_configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1298
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1299
  my ($doc, $iConfName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1300
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1301
  # Find the named configuration 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1302
  my @nodes = $doc->getElementsByTagName ("configuration");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1303
  foreach my $node (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1304
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1305
      my $name = $node->getAttributeNode ("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1306
      if ($name->getValue eq $iConfName)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1307
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1308
        return $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1309
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1310
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1311
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1312
  # If no configuration has been found the produce ERROR message
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1313
  die "ERROR: RealTimeBuild: Named configuration $iConfName not found\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1314
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1315
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1316
# process_configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1317
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1318
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1319
# $doc - DOM document model
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1320
# $iConfName - name of the configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1321
# $iVersion - Version of xml file (new or old) ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1322
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1323
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1324
# $topunits - reference to a list of units in the main configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1325
# $subunits - reference to a list of local units contained within subtasks
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1326
# \@options - reference to a list of options which apply (curently global options)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1327
# \@tasks   - reference to a list of the task nodes for the configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1328
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1329
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1330
# This function locates the named configuration and processes it into
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1331
# a list of units, the build options which apply, and the task elements in
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1332
# the configuration.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1333
sub process_configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1334
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1335
  my ($doc, $iConfName, $iVersion) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1336
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1337
  my @options; # list of global options
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1338
  my @units; # list of individual buildable items
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1339
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1340
  # NB. getElementsByTagName in list context returns a list, so
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1341
  # the following statement gets only the first element of the list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1342
  my ($build, @nodes); 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1343
  if ($iVersion == 1)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1344
    $build = $doc->getElementsByTagName("build");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1345
  } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1346
    $build = $doc->getElementsByTagName("SystemBuild");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1347
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1348
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1349
  @nodes = $build->[0]->getElementsByTagName("option");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1350
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1351
  # Read the global options (savespace and keepgoing)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1352
  foreach my $node (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1353
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1354
    my $name = $node->getAttributeNode("abldOption");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1355
    my $enable = $node->getAttributeNode("enable")->getValue;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1356
    push @options, $name->getValue if ($enable =~ /Y/i);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1357
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1358
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1359
  # Find named configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1360
  my $configuration = find_configuration($doc, $iConfName);  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1361
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1362
  # Get the list of tasks
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1363
  my @tasks = $configuration->getElementsByTagName("task");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1364
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1365
  my ($topunits, $subunits);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1366
  # Get the filtered list of units
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1367
  if ($iVersion == 1)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1368
    $topunits = get_configuration_units($doc, $configuration, 1, 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1369
    $subunits = get_configuration_units($doc, $configuration, 1, 2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1370
  } elsif ($iVersion == 2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1371
    $topunits = get_configuration_units2($doc, $configuration, 1, 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1372
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1373
    $subunits = get_configuration_units2($doc, $configuration, 1, 2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1374
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1375
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1376
  return ($topunits, $subunits,\@options,\@tasks);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1377
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1378
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1379
# check_filter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1380
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1381
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1382
# $item_filter - filter specification (comma-separated list of words)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1383
# $configspec - configuration specification (reference to list of words)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1384
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1385
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1386
# $failed - filter item which did not agree with the configuration (if any)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1387
#           An empty string is returned if the configspec passed the filter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1388
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1389
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1390
# This function checks the configspec list of words against the words in the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1391
# filter. If a word is present in the filter, then it must also be present in
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1392
# the configspec. If "!word" is present in the filter, then "word" must not
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1393
# be present in the configspec.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1394
sub check_filter($$)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1395
	my ($item_filter, $configspec) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1396
	my $failed = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1397
	foreach my $word (split /,/,$item_filter)    	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1398
		if ($word =~ /^!/)        	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1399
			# word must NOT be present in configuration filter list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1400
			my $notword = substr $word, 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1401
			$failed = $word if grep(/^$notword$/, @$configspec);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1402
		} 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1403
		else         	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1404
			# word must be present in configuration filter list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1405
			$failed = $word unless grep(/^$word$/, @$configspec);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1406
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1407
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1408
	return $failed;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1409
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1410
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1411
# get_configuration_units
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1412
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1413
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1414
# $doc - DOM document model
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1415
# $configuration - configuration node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1416
# $verbose - enable/disable logging
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1417
# $level - 0 = all units, 1 = top-level units, 2 = local units within tasks
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1418
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1419
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1420
# \@units - reference to a list of unit,package & prebuilt nodes which implement this configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1421
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1422
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1423
# This function processes the specified configuration to get the list of unit or package
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1424
# nodes that implement this configuration.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1425
sub get_configuration_units ($$$$)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1426
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1427
    my ($doc, $configuration, $verbose, $level) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1428
    my @units; # list of individual buildable items
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1429
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1430
    my ($model) = $doc->getElementsByTagName("SystemDefinition");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1431
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1432
    # Start with the units specified via unitListRefs, then append the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1433
    # units specified via layerRefs - they will be sorted afterwards anyway
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1434
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1435
    my @unitlistrefs = $configuration->getElementsByTagName("unitListRef");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1436
    foreach my $child (@unitlistrefs)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1437
	my $issublevel = $child->getParentNode->getTagName ne "configuration";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1438
	next if (($level==1 && $issublevel) || ($level==2 && !$issublevel));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1439
	push @units, &find_unitList_by_ID($doc, $child->getAttribute("unitList"), 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1440
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1441
    my @layerrefs = $configuration->getElementsByTagName("layerRef");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1442
    foreach my $child (@layerrefs)		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1443
	my $issublevel = $child->getParentNode->getTagName ne "configuration";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1444
	next if (($level==1 && $issublevel) || ($level==2 && !$issublevel));	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1445
	my $layerName = $child->getAttribute("layerName");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1446
	# Find the named object and enumerate the units it contains
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1447
	my ($layer) = XML::XQL::solve("//*[\@name = '$layerName']", $model);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1448
	if (!defined($layer))		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1449
	  print $GenXml::gLogFileH "ERROR: no match for \"$layerName\"\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1450
	  next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1451
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1452
	my @newunits = $layer->getElementsByTagName("unit",1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1453
	my @newpackages = $layer->getElementsByTagName("package",1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1454
	my @newprebuilts = $layer->getElementsByTagName("prebuilt",1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1455
	if ($verbose)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1456
	  printf $GenXml::gLogFileH "Layer \"$layerName\" contained %d units, %d packages and %d prebuilt\n",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1457
		scalar @newunits, scalar @newpackages, scalar @newprebuilts;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1458
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1459
	push @newunits, @newpackages, @newprebuilts;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1460
	if (scalar @newunits == 0)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1461
	  print $GenXml::gLogFileH "WARNING: layerRef $layerName contains no units\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1462
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1463
	push @units, @newunits;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1464
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1465
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1466
    my @configspec = split /,/,$configuration->getAttribute("filter");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1467
    my @filtered_units;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1468
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1469
    # Scan the list, eliminating duplicates and elements which fail the filtering
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1470
    my %mrpfiles;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1471
    foreach my $element (@units)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1472
	my $name = $element->getAttribute("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1473
	my $filter = $element->getAttribute("filter");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1474
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1475
	if ($filter)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1476
	  my $failed = &check_filter($filter,\@configspec);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1477
	  if ($failed ne "")	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1478
	    print $GenXml::gLogFileH "Filtered out $name ($failed)\n" if ($verbose);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1479
	    next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1480
	  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1481
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1482
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1483
        my $mrp = $element->getAttribute("mrp");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1484
	if ($mrp)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1485
		my $unitID = $element->getAttribute("unitID");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1486
		if (defined($mrpfiles{$mrp}))	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1487
		  # eliminate duplicates
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1488
		  next if ($mrpfiles{$mrp} eq $unitID);	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1489
		  # report (and eliminate) conflicts
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1490
		  printf $GenXml::gLogFileH "WARNING: $mrp exists in %s and %s - skipping $unitID\n",  $unitID, $mrpfiles{$mrp};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1491
		  next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1492
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1493
		$mrpfiles{$mrp} = $unitID;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1494
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1495
	push @filtered_units, $element;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1496
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1497
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1498
    if ($verbose)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1499
	printf $GenXml::gLogFileH "%s contains %d units at level %d\n", 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1500
			$configuration->getAttribute("name"), scalar @filtered_units, $level;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1501
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1502
    return \@filtered_units;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1503
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1504
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1505
# compute_bldList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1506
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1507
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1508
# $iSourceDir - root of the current source tree
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1509
# $iEffectiveDir - root of the source tree when used
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1510
# $elements - reference to list of units, packages & prebuilts which can be part of the configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1511
# $iVersion - Version of xml file (new or old) ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1512
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1513
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1514
# @bldList - a list of [name, bld.inf_dir, mrpfile] arrays, using $iEffectiveDir
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1515
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1516
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1517
# This function processes a list of unit and package elements, extracting from
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1518
# them the location of the associated bld.inf files. If bld.inf_dir is "" then
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1519
# no bld.inf was specified (e.g. a package) or the bld.inf file does not exist.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1520
# If mrpfile is "" then no mrp file was specified.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1521
# <prebuilt> elements return "*nosource*" as the mrpfile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1522
sub compute_bldList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1523
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1524
  my ($iSourceDir, $iEffectiveDir, $elements, $iVersion) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1525
  my @bldList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1526
  my %priorityLists;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1527
  my ($name, $bldFile, $mrp, $priority, $unitID, $effmrp, $effbldFile, $packageName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1528
  my ($count, $unit, @childNodes, @unitNames);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1529
  foreach my $element (@$elements)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1530
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1531
    # Variable holding the previous values and so giving wrong results.  Lets undefine them.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1532
    undef $name; undef $bldFile; undef $mrp; undef $priority; undef $unitID; undef $effmrp; undef $effbldFile;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1533
    if ($iVersion == 1)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1534
      push(@childNodes,$element);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1535
    } elsif ($iVersion == 2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1536
      my @units = $element->getElementsByTagName("unit");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1537
      for ( @units )
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1538
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1539
        push(@childNodes, $_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1540
        push(@unitNames, $element->getElementsByTagName("name"));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1541
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1542
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1543
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1544
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1545
  # should only be one childNodes, but this will make sure we handle all in case there are any
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1546
  for my $index ( 0 .. $#childNodes )  	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1547
	my $unit = $childNodes[$index];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1548
	my $unitName = $unitNames[$index];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1549
   if ($iVersion == 1)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1550
       $name = $unit->getAttribute("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1551
       $bldFile = $unit->getAttribute("bldFile");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1552
       $mrp = $unit->getAttribute("mrp");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1553
       $priority = $unit->getAttribute("priority");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1554
       $unitID = $unit->getAttribute("unitID");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1555
       $effmrp = $mrp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1556
       $effbldFile = $bldFile;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1557
   } elsif ($iVersion == 2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1558
       $name = $unitName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1559
       $bldFile = $unit->getAttribute("bldFile");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1560
       $mrp = $unit->getAttribute("mrp");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1561
       $priority = $unit->getAttribute("priority");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1562
       $mrp =~ /.+\\([\w_-]+)\.mrp/;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1563
       $packageName = $1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1564
       $effmrp = $mrp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1565
       $effbldFile = $bldFile;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1566
       $unitID = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1567
   }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1568
   
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1569
   if ($mrp)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1570
   {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1571
     if ($mrp !~ /^\\/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1572
       {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1573
       # watch out for mrp="\product\..."
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1574
       $mrp = $iSourceDir.$mrp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1575
       $effmrp = $iEffectiveDir.$effmrp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1576
       }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1577
     if (-f $mrp)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1578
     {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1579
       # get the component name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1580
       open MRPFILE, "<$mrp"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1581
         or print $GenXml::gLogFileH "ERROR: Cannot read $mrp - skipping \"$unitID\"\n" and next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1582
       my $mrpline;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1583
       while ($mrpline = <MRPFILE>)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1584
       {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1585
         if ($mrpline =~ /^\s*component\s+(\S+)/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1586
         {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1587
           $name = $1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1588
           last;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1589
         }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1590
       }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1591
       close MRPFILE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1592
     } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1593
       # print $GenXml::gLogFileH "ERROR: $mrp does not exist - skipping \"$unitID\"\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1594
       # next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1595
       $name = $packageName if defined $packageName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1596
       # Unfortunately, we need to cope with the pkgdefs components which are created later
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1597
       print $GenXml::gLogFileH "REMARK: $mrp does not exist - assuming $name is correct...\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1598
     }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1599
   } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1600
     $mrp = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1601
     $effmrp = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1602
   }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1603
   if ($bldFile)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1604
   {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1605
     if ($bldFile =~ /^\w:\\/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1606
     {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1607
       print "Warning:Bldfile path should not contain drive letters.The build may continue with problems\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1608
     }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1609
     else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1610
     {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1611
       if ($bldFile =~ /^\\/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1612
       {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1613
         # No need to add the source dir path
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1614
       }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1615
       else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1616
       {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1617
         $bldFile = $iSourceDir.$bldFile;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1618
         $effbldFile = $iEffectiveDir.$effbldFile;   
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1619
       }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1620
     }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1621
     if (!-f "$bldFile\\BLD.INF")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1622
     {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1623
       print $GenXml::gLogFileH "ERROR: $bldFile\\BLD.INF does not exist - skipping \"$unitID\"\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1624
       next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1625
     }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1626
   } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1627
     $bldFile = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1628
     $effbldFile = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1629
   }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1630
   
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1631
   if ($mrp eq "" && $bldFile eq "")	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1632
           if ($iVersion == 1)	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1633
             if ($unit->getTagName eq "prebuilt")      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1634
               $mrp = "*nosource*";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1635
               $effmrp = $mrp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1636
             } 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1637
           } elsif ($iVersion == 2) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1638
             if ($unit->getAttribute("prebuilt")) 	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1639
                   $mrp = "*nosource*";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1640
                   $effmrp = $mrp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1641
                   $name = $unit->getAttribute("prebuilt");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1642
               }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1643
           }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1644
          }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1645
    if($mrp eq "" && $bldFile eq "") {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1646
       #print $GenXml::gLogFileH "ERROR: no MRP file, no BLD.INF directory - skipping \"$unitID\"\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1647
       next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1648
   }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1649
   
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1650
   if (!$priority)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1651
   {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1652
     $priority = 1000;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1653
   }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1654
   
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1655
   if (! defined($priorityLists{$priority}))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1656
   {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1657
     $priorityLists{$priority} = ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1658
   }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1659
   push @{$priorityLists{$priority}}, [$name,$effbldFile,$effmrp];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1660
 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1661
   
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1662
  # concatenate the lists in (ascending numerical) priority order
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1663
  foreach my $priority (sort {$a <=> $b} keys %priorityLists)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1664
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1665
    push @bldList, @{$priorityLists{$priority}};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1666
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1667
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1668
  return @bldList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1669
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1670
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1671
# find_unitList_by_ID
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1672
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1673
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1674
# $doc - DOM document model
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1675
# $id - the IDREF of the unitList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1676
# $iVersion - Version of xml file (new or old) ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1677
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1678
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1679
# @units - a list of unit elements referenced in the specified unit list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1680
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1681
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1682
# This function is used to convert a unitListRef into the corresponding
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1683
# list of units.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1684
sub find_unitList_by_ID()
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1685
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1686
  my ($doc, $id, $iVersion) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1687
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1688
  my (@units, @element); # List of units in unitList and elements
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1689
  my ($unitList, $unitRef, $attribute);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1690
  if ($iVersion == 1)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1691
	  $unitList = "unitList" ;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1692
	  $unitRef = "unitRef";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1693
	  $attribute = "unit";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1694
	  @element = XML::XQL::solve("//unitList[\@name = '$id']", $doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1695
  } elsif ($iVersion == 2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1696
	  $unitList = "list" ;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1697
	  $unitRef = "ref";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1698
	  $attribute = "item";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1699
	  @element = XML::XQL::solve("//list[\@name = '$id']", $doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1700
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1701
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1702
  # Should only return one element because the Validating Parser will not allow multiple DTD ID's
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1703
  if (!($element[0]))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1704
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1705
    print $GenXml::gLogFileH "ERROR: Cannot find $unitList $id\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1706
    die "ERROR: RealTimeBuild: Cannot find $unitList $id\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1707
  } 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1708
  my @unitRefs = $element[0]->getElementsByTagName("$unitRef",1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1709
  if (scalar @unitRefs == 0)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1710
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1711
    print $GenXml::gLogFileH "WARNING: $unitList $id contains no units\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1712
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1713
  foreach my $unitRef (@unitRefs)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1714
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1715
    my $unitID = $unitRef->getAttribute("$attribute");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1716
    my (@element);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1717
    if ($iVersion == 1)	{    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1718
	    (@element) = XML::XQL::solve ("//unit[\@unitID = '$unitID']", $doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1719
    } elsif ($iVersion == 2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1720
	    (@element) = XML::XQL::solve ("//component[\@name = '$unitID']", $doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1721
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1722
    if (!($element[0]))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1723
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1724
      print $GenXml::gLogFileH "ERROR: $unitList $id refers to non-existent $attribute $unitID, not building\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1725
      next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1726
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1727
    push @units,$element[0];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1728
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1729
  return @units;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1730
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1731
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1732
# find_targetList_by_ID
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1733
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1734
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1735
# $doc - reference to DOM document model
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1736
# $id - value of the IDREFS to find (multiple whitespace ID's)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1737
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1738
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1739
# @targets - a list of targets referenced in the specified targetList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1740
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1741
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1742
# This function finds a list of units and full source location
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1743
sub find_targetList_by_ID
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1744
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1745
  my ($doc, $idrefs) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1746
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1747
  my $n; # Number of Nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1748
  my @targets; # List of units in targetList
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1749
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1750
  # Split on whitespace to get ID's from IDREFS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1751
  my @ids = split(/\s+/, $idrefs);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1752
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1753
  for (my $i = 0; $i < scalar(@ids); $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1754
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1755
    my ($id) = $ids[$i];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1756
    my (@element) = XML::XQL::solve("//targetList[\@name = '$id']", $doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1757
    # Should only return one element because the Validating Parser will not allow multiple DTD ID's
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1758
    # target attrib is another IDREFS list of target
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1759
    if (!($element[0]))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1760
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1761
      print $GenXml::gLogFileH "ERROR: Cannot find targetList $id\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1762
      die "ERROR: RealTimeBuild: Cannot find targetList $id\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1763
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1764
    my $targetIDREFS;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1765
    if ($element[0])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1766
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1767
      $targetIDREFS = $element[0]->getAttributeNode("target")->getValue;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1768
    } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1769
      print $GenXml::gLogFileH "ERROR: Cannot find targetList of $id\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1770
      die "ERROR: RealTimeBuild: Processing error\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1771
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1772
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1773
    # Split on whitespace to get ID's from IDREFS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1774
    my @targetsID = split(/\s+/, $targetIDREFS);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1775
    for (my $j = 0; $j < scalar(@targetsID); $j++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1776
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1777
      my ($target) = $targetsID[$j];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1778
      my (@target_element) = XML::XQL::solve("//target[\@name = '$target']", $doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1779
      # Should only return one element because the Validating Parser will not allow multiple DTD ID's
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1780
      if ($target_element[0])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1781
      {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1782
        push @targets, $target_element[0]->getAttributeNode("abldTarget")->getValue;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1783
      } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1784
        print $GenXml::gLogFileH "ERROR: Cannot find target of $target\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1785
        die "ERROR: RealTimeBuild: Processing error\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1786
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1787
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1788
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1789
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1790
  return @targets;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1791
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1792
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1793
# logfileHeader
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1794
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1795
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1796
# $comp - string to place in the "component" section of the header
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1797
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1798
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1799
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1800
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1801
# This function print the log file header to te global logfile handle
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1802
sub logfileHeader
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1803
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1804
  my ($comp) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1805
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1806
  if ($gEmbeddedLog)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1807
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1808
    print $GenXml::gLogFileH "*** $comp\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1809
    return;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1810
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1811
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1812
  # Log file headers for each log file loading
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1813
  print $GenXml::gLogFileH "=== Genxml == $comp\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1814
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1815
  print $GenXml::gLogFileH "-- Genxml\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1816
  # Add the per command start timestamp
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1817
  print $GenXml::gLogFileH "++ Started at ".localtime()."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1818
  # Add the per command start HiRes timestamp if available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1819
  if ($gHiResTimer == 1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1820
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1821
    print $GenXml::gLogFileH "+++ HiRes Start ".Time::HiRes::time()."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1822
  } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1823
    # Add the HiRes timer missing statement
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1824
    print $GenXml::gLogFileH "+++ HiRes Time Unavailable\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1825
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1826
  $GenXml::gLogFileH->flush;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1827
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1828
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1829
# logfileFooter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1830
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1831
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1832
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1833
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1834
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1835
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1836
# This function print the log file footer to the global logfile handle
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1837
sub logfileFooter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1838
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1839
  return if ($gEmbeddedLog);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1840
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1841
  # Add the per command end HiRes timestamp if available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1842
  print $GenXml::gLogFileH "+++ HiRes End ".Time::HiRes::time()."\n" if ($gHiResTimer == 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1843
  # Add the per command end timestamp
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1844
  print $GenXml::gLogFileH "++ Finished at ".localtime()."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1845
  $GenXml::gLogFileH->flush;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1846
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1847
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1848
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1849
#####################################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1850
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1851
#							v2 api's for new SystemDefinition
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1852
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1853
#####################################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1854
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1855
# process_node2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1856
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1857
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1858
# $node1 - ref to the master doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1859
# $node2 - ref to the slave doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1860
# $doc1 - ref to the merged doc so we can set the doc owner to the (not DOM spec) to get around WRONG_DOCUMENT_ERR restriction
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1861
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1862
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1863
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1864
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1865
# This function processes a node in two DOM documents, if any children match then it calls itself to process
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1866
# the children nodes further
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1867
sub process_node2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1868
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1869
  my ($doc1, $doc2) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1870
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1871
  my $merged = new XML::DOM::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1872
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1873
  # Some nodes need special processing e.g. SystemDefinition
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1874
  # This is because there can only be a certain number of these nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1875
  # child node / element rules outlined below, this rules are applied to the children of the node in question
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1876
 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1877
  my ($node1, $node2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1878
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1879
  # All other nodes                 Append child
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1880
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1881
  # Useful debug stuff
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1882
  #$GenXml::count++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1883
  #print "enter $GenXml::count\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1884
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1885
  # Handle the special case for the first call to this function with the node containing the SystemDefinition
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1886
  if (($$doc1->getDocumentElement->getTagName eq "SystemDefinition") 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1887
	&& ($$doc2->getDocumentElement->getTagName eq "SystemBuild"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1888
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1889
    # Process the DTD and merge
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1890
    my $dtd1 = $$doc1->getDoctype->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1891
    my $dtd2 = $$doc2->getDoctype->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1892
    my $mergeddtd = &Merge_dtd($dtd1, $dtd2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1893
    $mergeddtd .= $$doc1->getDocumentElement->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1894
    $merged = $merged->parse($mergeddtd);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1895
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1896
    $node1 = \($merged->getElementsByTagName("SystemDefinition"));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1897
    $node2 = \($$doc2->getElementsByTagName("SystemBuild"));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1898
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1899
    my $tagname = $$node2->getTagName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1900
    for my $item ($$doc2->getChildNodes)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1901
      if ($item->toString =~ /^\s*<$tagname .+>/isg)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1902
	  &append_child($node1, \($item), \$merged);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1903
	  last;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1904
      }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1905
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1906
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1907
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1908
  return $merged;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1909
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1910
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1911
# Merge_dtd
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1912
sub Merge_dtd	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1913
  my ($doctype1, $doctype2) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1914
  my $mergeddtd;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1915
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1916
  # split them into an array of values
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1917
  my @doctypeValues1 = split '\n', $doctype1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1918
  my @doctypeValues2 = split '\n', $doctype2;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1919
  my $elementNameToAdd;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1920
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1921
  my $count = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1922
  for my $line (@doctypeValues2)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1923
	  if ( $line =~ /<!ELEMENT (\w+) .+>/ )	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1924
		  $elementNameToAdd = $1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1925
		  last;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1926
	  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1927
	  $count++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1928
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1929
  splice @doctypeValues2, 0, $count-1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1930
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1931
  my $i; 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1932
  for ($i=0; $#doctypeValues1; $i++)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1933
	  last if ( $doctypeValues1[$i] =~ /<!ELEMENT SystemDefinition .+>/);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1934
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1935
  $doctypeValues1[$i] =~ s/(.+) \)>$/$1?, $elementNameToAdd? )>/;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1936
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1937
  $#doctypeValues1 = $#doctypeValues1 -1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1938
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1939
  push @doctypeValues1, @doctypeValues2;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1940
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1941
  unshift @doctypeValues1, '<?xml version="1.0" encoding="UTF-8"?>';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1942
  $mergeddtd = join "\n", @doctypeValues1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1943
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1944
  return $mergeddtd;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1945
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1946
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1947
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1948
# Filter_doc2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1949
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1950
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1951
# $doc - Reference to input document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1952
# $iFilter - filter to apply
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1953
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1954
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1955
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1956
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1957
# This function simplifies the XML by removing anything which fails to pass the filter.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1958
# The resulting doc is then useful for tools which don't understand the filter attributes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1959
sub Filter_doc2	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1960
	my ($doc, $iFilter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1961
	  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1962
	# the filtering will have to be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1963
	# - find the configurations which pass the filter (and delete the rest)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1964
	# - identify items which are kept by some configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1965
	# - remove the ones which aren't kept by any configuration.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1966
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1967
	# deal with the <configuration> items, checking their filters
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1968
	my %lists;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1969
	my @nodes = $doc->getElementsByTagName ("configuration");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1970
	foreach my $node (@nodes)		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1971
		my $configname = $node->getAttribute("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1972
		my @configspec = split /,/,$node->getAttribute("filter");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1973
		my $failed = check_filter($iFilter,\@configspec);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1974
		if ($failed ne "")		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1975
			print $GenXml::gLogFileH "Simplification removed configuration $configname ($failed)\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1976
			$node->getParentNode->removeChild($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1977
			next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1978
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1979
		# find all the units for this configuration and mark them as MATCHED
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1980
		print $GenXml::gLogFileH "Analysing configuration $configname...\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1981
  		my $unfiltered_items = get_configuration_units2($doc, $node, 0, 0);     # Replace the arg 1 with 0 to put the debug off
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1982
  		foreach my $unit (@$unfiltered_items) 			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1983
  			$unit->setAttribute("MATCHED", 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1984
  			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1985
  		# note all the lists referenced by this configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1986
  		foreach my $listRef ($node->getElementsByTagName("listRef"))		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1987
  			my $list = $listRef->getAttribute("list");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1988
  			$lists{$list} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1989
  			} 		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1990
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1991
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1992
	# walk the model, removing the "MATCHED" attribute and deleting any which weren't marked
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1993
	my %deletedUnits;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1994
	delete_unmatched_units($doc, \%deletedUnits);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1995
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1996
	# clean up the lists
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1997
	my @lists = $doc->getElementsByTagName("list");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1998
	foreach my $list (@lists)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1999
		my $name = $list->getAttribute("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2000
		if (!defined $lists{$name})		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2001
			print $GenXml::gLogFileH "Simplification removed list $name\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2002
			$list->getParentNode->removeChild($list);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2003
			next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2004
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2005
		foreach my $ref ($list->getElementsByTagName("ref"))	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2006
			my $id = $ref->getAttribute("item");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2007
			if (defined $deletedUnits{$id})		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2008
				$list->removeChild($ref);	# reference to deleted unit
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2009
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2010
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2011
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2012
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2013
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2014
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2015
# get_configuration_units2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2016
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2017
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2018
# $doc - DOM document model
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2019
# $configuration - configuration node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2020
# $verbose - enable/disable logging
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2021
# $level - 0 = all units, 1 = top-level units, 2 = local units within tasks
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2022
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2023
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2024
# \@units - reference to a list of unit,package & prebuilt nodes which implement this configuration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2025
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2026
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2027
# This function processes the specified configuration to get the list of unit or package
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2028
# nodes that implement this configuration.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2029
sub get_configuration_units2 ($$$$)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2030
	my ($doc, $configuration, $verbose, $level) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2031
	my @filterable_items; # list of individual buildable items
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2032
	my ($mrp, $bldFile);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2033
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2034
	my ($model) = $doc->getElementsByTagName("systemModel");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2035
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2036
	# Start with the units specified via listRefs, then append the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2037
	# units specified via layerRefs - they will be sorted afterwards anyway
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2038
	my @listrefs = $configuration->getElementsByTagName("listRef");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2039
	foreach my $child (@listrefs)		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2040
		my $issublevel = $child->getParentNode->getTagName ne "configuration";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2041
		next if (($level==1 && $issublevel) || ($level==2 && !$issublevel));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2042
		push @filterable_items, &find_unitList_by_ID($doc, $child->getAttribute("list"), 2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2043
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2044
	my @refs = $configuration->getElementsByTagName("ref");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2045
	foreach my $child (@refs)		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2046
		my $issublevel = $child->getParentNode->getTagName ne "configuration";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2047
		next if (($level==1 && $issublevel) || ($level==2 && !$issublevel));		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2048
		my $item = $child->getAttribute("item");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2049
		# Find the named object and enumerate the items it contains
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2050
		my ($layer) = XML::XQL::solve("//*[\@name = '$item']", $model);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2051
		if (!defined($layer))			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2052
			print $GenXml::gLogFileH "ERROR: no match for \"$item\"\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2053
			next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2054
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2055
		my @newunits = $layer->getElementsByTagName("unit",1);		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2056
		my @components = $layer->getElementsByTagName("component",1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2057
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2058
		if ($verbose)			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2059
			printf $GenXml::gLogFileH "Layer \"$item\" contained %d untis in %d components, \n",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2060
				 scalar @newunits,  scalar @components;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2061
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2062
		if (scalar @newunits == 0)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2063
		  print $GenXml::gLogFileH "WARNING: ref $item contains no units\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2064
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2065
		if (scalar @components == 0)			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2066
			print $GenXml::gLogFileH "WARNING: ref $item contains no components\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2067
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2068
		push @filterable_items, @components, @newunits;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2069
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2070
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2071
	my @configspec = split /,/,$configuration->getAttribute("filter");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2072
	my @unfiltered_items;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2073
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2074
	# Scan the list, eliminating duplicates and elements which fail the filtering
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2075
	my %mrpfiles;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2076
	foreach my $element (@filterable_items)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2077
		my $name = $element->getAttribute("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2078
		my $filter = $element->getAttribute("filter");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2079
		my $class = $element->getAttribute("class");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2080
				
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2081
		if ($filter)			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2082
			my $failed = &check_filter($filter,\@configspec);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2083
			if ($failed ne "")				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2084
				print $GenXml::gLogFileH "Filtered out $name ($failed)\n" if ($verbose);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2085
				next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2086
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2087
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2088
		if($element->getTagName eq 'unit')
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2089
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2090
			# if it's not been filtered out, then substitute the unix syle path to windows style.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2091
			$bldFile = $element->getAttribute("bldFile");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2092
			if ($bldFile ne "")	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2093
				$bldFile =~ s/\//\\/g;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2094
				$element->setAttribute("bldFile", $bldFile) ;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2095
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2096
			$mrp = $element->getAttribute("mrp");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2097
			if ($mrp ne "")	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2098
				$mrp =~ s/\//\\/g;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2099
				$element->setAttribute("mrp", $mrp) ;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2100
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2101
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2102
			if ($mrp)		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2103
				#my $elementName = $element->getAttribute("name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2104
				if (defined($mrpfiles{$mrp}))		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2105
					# eliminate duplicates
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2106
					next if ($mrpfiles{$mrp} eq $name);	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2107
					# report (and eliminate) conflicts
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2108
					printf $GenXml::gLogFileH "WARNING: $mrp exists in %s and %s - skipping $name\n",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2109
					  $name, $mrpfiles{$mrp};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2110
					next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2111
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2112
				$mrpfiles{$mrp} = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2113
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2114
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2115
		push @unfiltered_items, $element;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2116
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2117
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2118
	if ($verbose)	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2119
		printf $GenXml::gLogFileH "%s contains %d units and components at level %d\n", 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2120
			$configuration->getAttribute("name"), scalar @unfiltered_items, $level;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2121
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2122
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2123
	# Process the tag "<specialInstructions" in the given configuration.  Need to convert the attribut "CWD" to windows style
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2124
	foreach my $child ($configuration->getElementsByTagName("specialInstructions"))	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2125
		my $command = $child->getAttribute("cwd");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2126
		$command =~ s/\//\\/g;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2127
		$child->setAttribute("cwd", $command);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2128
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2129
	return \@unfiltered_items;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2130
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2131
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2132
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2133
1;