srctools/distillsrc/distillsrc.pm
author wbernard
Sun, 10 Oct 2010 15:22:15 +0300
changeset 645 b8d81fa19e7d
parent 602 3145852acc89
permissions -rw-r--r--
helium_12.0.0-63b64366f9cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
#!/bin/perl -w
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
# distillsrc.pm - compiles a list of source used in .mrp files, and deletes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
# any unused source
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
package CDistillSrc;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
use File::Spec;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
use File::Path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
use FindBin;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
use lib $FindBin::Bin;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
use ReadMrp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
use lib File::Spec->catdir($FindBin::Bin, '..', 'makecbr');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
use CConfig;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
# Constructor
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
# $aSrcRoot : The root from which all src statements are based
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
# $aSrcPath : The path under aSrcRoot to the source tree to be processed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
# $aSrcPrefix : An optional prefix which can be stripped from all src statements
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
# $aPlatform : e.g 'beech' - used to locate the platform specific product directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
# Returns: The object (or undef if there was a problem)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
sub New($$$$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
	my $proto = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
	my ($aSrcRoot, $aSrcPath, $aSrcPrefix, $aPlatform, $aCheckCase) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
	my $class = ref($proto) || $proto;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
	my $self = {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
	bless($self, $class);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
	my $error = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
	if (!defined($aSrcRoot))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
		print "ERROR: RealTimeBuild: A srcroot must be given, to specify where all 'source' declarations originate from\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
		$error = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
	if (!defined($aSrcPath))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
		print "ERROR: RealTimeBuild: A srcpath must be given, to specify which source under the srcroot is to be filtered. Use '\\' to filter the entire srcroot\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
		$error = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
	if (!defined($aPlatform))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
		print "ERROR: RealTimeBuild: A platform must be given, to locate the product directory\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
		$error = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
	if ($error)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
		print "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
		if ($aSrcPath =~ /\.\./)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
			print "ERROR: RealTimeBuild: The source path must be relative to the srcroot, and must not contain '..'\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
			$error = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
		$self->iSrcRoot($aSrcRoot);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
		$self->iSrcPath($aSrcPath);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
		$self->iSrcPrefix($aSrcPrefix);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
		$self->iPlatform($aPlatform);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
		$self->iSrcItems({});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
		$self->iCheckCase(!!$aCheckCase);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
		$self->AddSrcItem("os/buildtools/toolsandutils/productionbldtools/unref/orphan/cedprd/SuppKit", "non-shipped");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
		$self->AddSrcItem("os/buildtools/toolsandutils/productionbldtools/unref/orphan/cedprd/tools", "non-shipped");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
		$self->AddSrcItem("os/buildtools/toolsandutils/productionbldtools/unref/orphan/cedprd/DevKit", "non-shipped");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
		$self->AddSrcItem("os/buildtools/toolsandutils/productionbldtools", "non-shipped");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
	if ($error)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
		$self = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
# Object data
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
sub iSrcRoot()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
	if (@_) { $self->{iSRCROOT} = shift; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
	return $self->{iSRCROOT};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
sub iSrcPath()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
	if (@_) { $self->{iSRCPATH} = shift; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
	return $self->{iSRCPATH};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
sub iSrcPrefix()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
	if (@_) { $self->{iSRCPREFIX} = shift; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
	return $self->{iSRCPREFIX};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
sub iPlatform()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
	if (@_) { $self->{iPLATFORM} = shift; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
	return $self->{iPLATFORM};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
sub iSrcItems()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
	if (@_) { $self->{iSRCITEMS} = shift; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
	return $self->{iSRCITEMS};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
sub iCheckCase()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
	if (@_) { $self->{iCHECKCASE} = shift; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
	return $self->{iCHECKCASE};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
sub iCorrectedCase()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
	if (@_) { $self->{iCORRECTEDCASE} = shift; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
	return $self->{iCORRECTEDCASE};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
# LoadMrps - Records the source lines out of all .mrp files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
# $aConfig - optional configuration file, as used by makecbr
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
# $aLists - optional component lists, as used by makecbr
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
# $aMrps - optional .mrp files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
# Returns: True, if the load was successful. False otherwise
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
sub LoadMrps($$$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
	my ($aConfig, $aLists, $aMrps) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
	# Load in config file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
	my @lists = @$aLists;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
	my @mrps;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
	foreach my $mrp (@$aMrps){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
		push @mrps, [$mrp, ''];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
	my @configMrps = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
    if (defined($aConfig))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
		my @configs = $self->_LoadConfig($aConfig);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
		# Add mrps and lists (after planting them in srcroot)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
		push @lists, map($self->_PlantFile($_), @{$configs[0]});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
		@configMrps = map($self->_PlantFile($_), @{$configs[1]});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
		foreach my $mrp (@configMrps)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
			push @mrps, [$mrp, ''];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
	# Load in mrp lists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
	foreach my $file (@lists)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
		if (open (MRPLIST, $file))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
			foreach my $line (<MRPLIST>)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
				chomp $line;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
				$line =~ s/#.*$//; # Remove comments
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
				$line =~ s/^\s*//; # Remove extraneous spaces
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
				$line =~ s/\s*$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
				if ($line ne "")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
					my @parms = split(/\s+/, $line);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
					if (scalar(@parms) != 2)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
						warn "ERROR: RealTimeBuild: Entries in component list '$file' should be of the form 'name mrp_location'. Problem in line: $line\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
						next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
					else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
						# Ignore *nosource* entries
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
						next if ($parms[1] eq '*nosource*');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
						
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
						push @mrps, [$self->_PlantFile($parms[1]), $parms[0]];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
			close MRPLIST or warn "ERROR: RealTimeBuild: Couldn't close '$file' : $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
			warn "Couldn't open '$file' : $!\n";	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
	# Load all .mrp files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
	if (scalar(@mrps) == 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
		die "ERROR: RealTimeBuild: No .mrp files were specified\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
	my $loaded = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
	foreach my $mrp (@mrps)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
		# Get path of mrp file (from here)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
		my ($name, $path) = fileparse($mrp->[0]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
		# Convert to path from source root
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
		if (!($self->_RemoveBaseFromPath($self->iSrcRoot(), \$path)))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
			warn "ERROR: Mrp file $mrp->[0] isn't under the source root (".$self->iSrcRoot().")\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
			next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
		my $mrpobj;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
        
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
        # To indicate the correct case and where the .mrp file comes from if failed to check letter case
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
        if (!($self->_CheckCase($mrp->[0]))) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
            my $mrp_error_source = "optional component list(by -f) or optional .mrp list(by -m)";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
            foreach my $myName (@configMrps) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
                if ($myName eq $mrp->[0]) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
                    $mrp_error_source = "config file '".$aConfig."'";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
                    last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
                }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
            } 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
            print "WARNING: Case of '".$mrp->[0]."' supplied in ".$mrp_error_source." does not match the file system. Should be ".$self->iCorrectedCase()."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
        
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
		if (!eval { $mrpobj = New ReadMrp($mrp->[0]) })
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
			$loaded = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
			my $message = $@;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
			$message =~ s/^(ERROR:\s*)?/ERROR: RealTimeBuild: /i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
			print $message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
			my $selfowned = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
			my $mrpComponentName = $mrpobj->GetComponent();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
			if( ($mrp->[1] ne '') && (lc($mrp->[1]) ne lc($mrpComponentName)))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
				print "ERROR: RealTimeBuild: Component name \'$mrp->[1]\' does not match \'$mrpComponentName\' in $mrp->[0]\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
			foreach my $srcitem (@{$mrpobj->GetSrcItems()})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
				if ($srcitem =~ /^[\/\\]/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
					# Remove source prefix
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
					$srcitem = $self->_StripFile($srcitem);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
				else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
					# Relative source item
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
					$srcitem = File::Spec->catdir($path, $srcitem);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
				my $rootedmrp = $path.$name;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
				if ($self->_RemoveBaseFromPath($srcitem, \$rootedmrp))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
					$selfowned = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
				$self->AddSrcItem($srcitem, $mrpComponentName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
			if ($self->iCheckCase())
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
				foreach my $binexpitem (@{$mrpobj->GetBinExpItems()})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
					# Check lower case
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
					if ($binexpitem =~ /[A-Z]/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
						print "REMARK: [$mrpComponentName] Binary/export file $binexpitem should be lower case\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
			if (!$selfowned)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
				print "REMARK: .mrp file '$mrp->[0]' does not include itself as source\n"; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
	return $loaded;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
# AddSrcItem - Records a source file, usually taken from an .mrp file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
# $aItem - the source file name
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
# $aComponent - the name of the component which claimed the file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
# Returns: None
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
# Dies: Not normally; only if the source hash data structure gets corrupted
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
sub AddSrcItem($$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
	my ($aItem, $aComponent) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
	my $item = $aItem;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
	# Worth checking that the file exists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
	my $truePath = File::Spec->catdir($self->iSrcRoot(), $item);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
	if (($item !~ /^\\component_defs/i) && (!-e $truePath))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
		print "ERROR: RealTimeBuild: '$aComponent' owns $item, but that path doesn't exist\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
		$item = ""; # No point adding this path to the tree	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
		# Check case consistency
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
		$self->_CheckCase($truePath) or print "WARNING: [$aComponent] Case of '".$truePath."' does not match the file system. Should be ".$self->iCorrectedCase()."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
	$item =~ s/^[\/\\]*//; # Remove preceding slashes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
	my @path = split(/[\/\\]+/,$item);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
	my $dir = $self->iSrcItems();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
	while ((scalar @path) > 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
		my $subdir = lc(shift @path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
		if (scalar(@path) == 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
			# Just enter the final path segment
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
			if (exists($dir->{$subdir}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
				# Someone already owns at least part of this path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
				if (!ref($dir->{$subdir}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
					# Someone owns the whole of this path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
					my $conflict = $dir->{$subdir};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
					print "REMARK: $aComponent and $conflict both own $item\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
				else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
					if (ref($dir->{$subdir}) ne "HASH")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
						die "ERROR: Source hash is corrupted\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
					else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
						# Someone owns a child of this path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
						my $childtree = $dir->{$subdir};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
						my @conflicts = $self->_GetTreeComps($childtree);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
						print "REMARK: $aComponent owns $item, which is already owned by the following component(s): ".join(", ",@conflicts)."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
			$dir->{$subdir} = $aComponent;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
			# Need to enter another subdirectory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
			
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
			if (exists($dir->{$subdir}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
				if (ref($dir->{$subdir}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
					# Someone already has - just do a quick integrity check
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
					
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
					if (ref($dir->{$subdir}) ne "HASH")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
						die "ERROR: Source hash is corrupted\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
				else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
					# The path from this point on is already owned by a component
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
					my $conflict = $dir->{$subdir};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
					
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
					print "REMARK: $aComponent and $conflict both own $item\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
					last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
			else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
				$dir->{$subdir} = {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
		$dir = $dir->{$subdir};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
# DistillSrc - Compare the recorded source lines against the source path. Delete anything which doesn't match.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
# $aDummy - A flag - non-zero means don't actually delete
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
# Returns: None
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
sub DistillSrc($$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
	my ($aDummy) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
	my $tree = $self->iSrcItems();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
	my $path = File::Spec->catdir($self->iSrcRoot(), $self->iSrcPath());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
	$path=~s/[\/\\]+/\\/; # Remove multiple slashes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   443
	# Pop the srcpath off the front of the tree
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
	my @path = split(/[\/\\]/,$self->iSrcPath());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
	foreach my $dir (@path)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
		if ($dir eq ".")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
			next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
		elsif (exists($tree->{lc($dir)}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
			$tree = $tree->{lc($dir)};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
			if (!ref($tree))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
				# Some component owns all of the srcpath
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
				last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
			# No mrp files claimed any of the source
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
			$tree = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
			last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
	# Now recurse into the tree and delete files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
	if (defined($tree))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
		if (ref($tree))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
			$self->_DistillTree($tree, $path, $aDummy);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
			print "REMARK: All source owned by component '$tree'; no action\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
		print "WARNING: No .mrp files claim any source; removing $path\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
		$self->_DeletePath($path, $aDummy);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
# Print - Display the source tree
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
# $aDepth - The number of levels of the tree to show. 0 = all levels
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
# Returns: None
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
sub Print($$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
	my ($aDepth) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
	$self->_PrintTree("", $self->iSrcItems(), $aDepth);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
# *** Private methods ***
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
# *** 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
# _LoadConfig - (private) Reads a configuration file, as used by makecbr
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
# $aConfig - filename of the configuration file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
# Returns:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
# (files, mrps) - where files and mrps are listrefs containing component lists and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
# mrp files respectively
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
sub _LoadConfig($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
	my ($aConfig) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
	my @files = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
	my @mrps = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
	my $config = New CConfig($aConfig);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
	if (!defined $config)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
		die "Couldn't load config file '$aConfig'\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
	# Extract the interesting items into our lists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
	push @mrps, $config->Get("gt+techview baseline mrp location");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
	push @mrps, $config->Get("gt only baseline mrp location");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
	push @files, $config->Get("techview component list");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
	push @files, $config->Get("gt component list");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
	# Remove any items we couldn't find
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
	@mrps = grep(defined($_), @mrps);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
	@files = grep(defined($_), @files);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
	return (\@files, \@mrps);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   542
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   543
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   544
# _StripFile - (private) Remover of src prefix. Also maps product directories
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   545
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   546
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   547
# $aFile - Filename to process
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   548
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   549
# Returns: The processed filename
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   550
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   551
sub _StripFile($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   552
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   553
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   554
	my ($aFile) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   555
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   556
	my $file = $aFile;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   557
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   558
	# Map the product dirs
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   559
	my $platform = $self->iPlatform();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   560
	$file =~ s#^[\/\\]?product[\/\\]#/sf/os/unref/orphan/cedprd/#i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   561
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   562
	# Remove the prefix
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   563
	my $prefix = $self->iSrcPrefix();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   564
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   565
	if (defined $prefix)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   566
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   567
		my $mapped = $file; # Keep a copy in case we can't remove the prefix
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   568
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   569
		if (!$self->_RemoveBaseFromPath($prefix, \$file))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   570
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   571
			$file = $mapped;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   572
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   573
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   574
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   575
	return $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   576
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   577
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   578
# _PlantFile - (private) Add src root to file. Also take off src prefix
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   579
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   580
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   581
# $aFile - Filename to process
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   582
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   583
# Returns: The processed filename
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   584
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   585
sub _PlantFile($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   586
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   587
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   588
	my ($aFile) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   589
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   590
	my $file = $aFile;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   591
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   592
	# Remove the prefix
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   593
	$file = $self->_StripFile($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   594
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   595
	# Plant the file in the src root
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   596
	$file = File::Spec->catdir($self->iSrcRoot(), $file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   597
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   598
	# Ensure all slashes are normalised to a single backslash
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   599
	$file =~ s/[\/\\]+/\\/; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   600
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   601
	return $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   602
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   603
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   604
# _RemoveBaseFromPath - (private) Remove a base path from the root of a filename.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   605
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   606
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   607
# $aBase - The base path to remove
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   608
# $$aFile - Filename to process (scalar reference)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   609
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   610
# Returns: True if the file was under the base path, false otherwise
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   611
#   $$aFile may be corrupted if the return is false
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   612
sub _RemoveBaseFromPath($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   613
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   614
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   615
	my ($aBase, $aFile) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   616
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   617
	my $base = $aBase;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   618
	$base =~ s/^[\/\\]*//; # Remove extra slashes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   619
	$base =~ s/[\/\\]*$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   620
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   621
	my @base = split(/[\/\\]+/, $base);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   622
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   623
	$$aFile =~ s/^[\/\\]*//; # Remove preceding slashes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   624
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   625
	my $matched = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   626
	my $filedir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   627
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   628
	foreach my $dir (@base)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   629
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   630
		if ($$aFile =~ /[\/\\]/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   631
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   632
			# Split off the bottom dir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   633
			$$aFile =~ /([^\/\\]*)[\/\\]+(.*)$/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   634
			($filedir, $$aFile) = ($1, $2, $3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   635
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   636
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   637
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   638
			# Special case - no more dirs
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   639
			$filedir = $$aFile;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   640
			$$aFile = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   641
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   642
		if (lc($filedir) ne lc($dir))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   643
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   644
			# Base doesn't match
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   645
			$matched = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   646
			last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   647
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   648
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   649
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   650
	return $matched;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   651
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   652
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   653
# _CheckCase - (private) Given a literal filename, compares the case of the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   654
#                        file on the filesystem against the filename i.e. it
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   655
#                        can be used to enforce case sensitivity
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   656
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   657
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   658
# $aFilename - The literal filename
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   659
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   660
# Returns: True if the file matches the supplied case.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   661
#          True if the file doesn't exist at all (user is expected to check that separately)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   662
#          True if case checking has been disabled.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   663
#          False otherwise (if the file exists but under a differing case).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   664
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   665
# If false, the correctly cased name is present through $self->iCorrectedCase()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   666
sub _CheckCase($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   667
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   668
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   669
	my ($aFile) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   670
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   671
	return 1 if !($self->iCheckCase()); # checking disabled
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   672
	return 1 if ($^O !~ /win32/i); # only works on Windows anyway
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   673
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   674
	return 1 if (!-e $aFile); # file not found (under case-insensitive checking)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   675
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   676
	$self->iCorrectedCase(Win32::GetLongPathName($aFile));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   677
	return ($aFile eq $self->iCorrectedCase());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   678
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   679
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   680
# _DistillTree - (private) Given a src tree and a dir, clean out any unowned files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   681
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   682
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   683
# %$aTree - The source tree (hash ref containing nested hash refs and string leaves)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   684
# $aDir - The directory to compare against
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   685
# $aDummy - A flag - non-zero means don't do the actual deletion
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   686
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   687
# Returns: A flag - non-zero if there were any owned files present
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   688
sub _DistillTree($$$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   689
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   690
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   691
	my ($aTree, $aDir, $aDummy) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   692
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   693
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   694
	my $keptsome = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   695
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   696
	if (opendir(DIR, $aDir))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   697
	{	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   698
		my $dir = $aDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   699
		$dir =~ s/[\/\\]*$//; # Remove trailing / from dir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   700
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   701
		foreach my $entry (readdir(DIR))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   702
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   703
			my $path = $dir."\\".$entry;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   704
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   705
			if ($entry =~ /^\.\.?$/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   706
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   707
				next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   708
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   709
			elsif (exists $aTree->{lc($entry)})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   710
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   711
				my $treeentry = $aTree->{lc($entry)};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   712
				if (ref($treeentry) eq "HASH")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   713
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   714
					# Part of this path is owned
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   715
					if (-d $path)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   716
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   717
						# Recurse into path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   718
						my $keep = $self->_DistillTree($treeentry, $path, $aDummy);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   719
						if ($keep)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   720
							{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   721
							$keptsome = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   722
							}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   723
						else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   724
							{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   725
							# Correction; none of this path was owned
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   726
							$self->_DeletePath($path, $aDummy);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   727
							}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   728
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   729
					elsif (-f $path)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   730
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   731
						my @comps = $self->_GetTreeComps($treeentry);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   732
						print "ERROR: RealTimeBuild: $path is a file, yet is used as a directory in components: ".join(", ",@comps)."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   733
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   734
					else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   735
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   736
						print "ERROR: $path has disappeared while it was being examined\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   737
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   738
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   739
				elsif (!ref($treeentry))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   740
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   741
					# This path is completely owned
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   742
					$keptsome = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   743
					next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   744
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   745
				else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   746
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   747
					die "ERROR: Source hash is corrupted\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   748
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   749
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   750
			else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   751
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   752
				$self->_DeletePath($path, $aDummy);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   753
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   754
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   755
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   756
		closedir(DIR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   757
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   758
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   759
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   760
			warn "ERROR: RealTimeBuild: Couldn't open directory '$aDir' for reading\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   761
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   762
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   763
	return $keptsome;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   764
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   765
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   766
# _GetTreeComps - (private) Get all the leaves out of a tree (or component
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   767
#                           names out of a source tree)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   768
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   769
# %$aTree - The source tree (hash ref containing nested hash refs and string leaves)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   770
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   771
# Returns: A list of strings found at the leaves (or component names)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   772
sub _GetTreeComps($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   773
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   774
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   775
	my ($aTree) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   776
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   777
	my @comps = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   778
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   779
	foreach my $entry (keys(%$aTree))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   780
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   781
		if (ref($aTree->{$entry}) eq "HASH")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   782
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   783
			push @comps, $self->_GetTreeComps($aTree->{$entry});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   784
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   785
		elsif (!ref($aTree->{$entry}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   786
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   787
			push @comps, $aTree->{$entry};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   788
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   789
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   790
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   791
			die "ERROR: Source hash is corrupted\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   792
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   793
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   794
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   795
	return @comps;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   796
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   797
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   798
# _DeletePath - (private) Safe path deletion (file or dir)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   799
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   800
# $aPath - The path to delet
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   801
# $aDummy  - A flag - non-zero means don't actually delete
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   802
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   803
# Returns: None. Prints warnings if deletion fails. Dies only in exceptional circumstances
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   804
sub _DeletePath($$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   805
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   806
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   807
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   808
	my ($aPath, $aDummy) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   809
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   810
	if (-d $aPath)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   811
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   812
		if ($aDummy)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   813
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   814
			print "DUMMY: Directory $aPath is not specified in any .mrp file\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   815
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   816
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   817
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   818
			print "REMARK: Deleting directory $aPath; ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   819
			my $files = rmtree($aPath);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   820
			if ($files)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   821
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   822
				print "$files items removed\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   823
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   824
			else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   825
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   826
				print "\nWARNING: Problem removing directory $aPath\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   827
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   828
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   829
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   830
	elsif (-f $aPath)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   831
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   832
		if ($aDummy)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   833
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   834
			print "DUMMY: File $aPath is not specified in any .mrp file\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   835
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   836
		else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   837
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   838
				unless($aPath =~ /distribution.policy.s60/i)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   839
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   840
					print "REMARK: Deleting file $aPath\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   841
					unlink $aPath or print "WARNING: Problem deleting file $aPath\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   842
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   843
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   844
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   845
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   846
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   847
		warn "ERROR: Can't delete path $aPath; not a file or directory\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   848
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   849
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   850
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   851
# _PrintTree - Display a subset of the source tree
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   852
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   853
# Parameters:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   854
# $aPrefix - The string to prefix all paths
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   855
# $aDepth - The number of levels of the tree to show. 0 = all levels
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   856
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   857
# Returns: None
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   858
sub _PrintTree($$$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   859
        {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   860
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   861
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   862
        my ($aPrefix, $aTree, $aDepth) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   863
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   864
	my $prefix = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   865
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   866
	if ($aPrefix ne "")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   867
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   868
		$prefix = $aPrefix."\\";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   869
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   870
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   871
        foreach my $key (sort(keys(%$aTree)))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   872
                {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   873
                if (ref($aTree->{$key}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   874
                        {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   875
			if ($aDepth!=1)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   876
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   877
				my $newprefix = $prefix.$key;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   878
				
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   879
				if ($key eq "")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   880
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   881
					$newprefix.="{empty}";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   882
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   883
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   884
                        	$self->_PrintTree($newprefix, $aTree->{$key}, $aDepth-1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   885
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   886
			else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   887
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   888
				print $prefix.$key."\\...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   889
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   890
                        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   891
                else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   892
                        {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   893
                        print $prefix.$key." = ".$aTree->{$key}."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   894
                        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   895
                }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   896
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   897
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   898
1;