deprecated/buildtools/buildsystemtools/removebuild.pl
author marvin shi <marvin.shi@nokia.com>
Tue, 30 Nov 2010 17:14:57 +0800
changeset 714 e5a58c351011
parent 655 3f65fd25dfd4
permissions -rw-r--r--
feature bsym format symbol rombuild support
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
#!/usr/bin/perl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
# Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
# All rights reserved.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
# This component and the accompanying materials are made available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
# under the terms of "Eclipse Public License v1.0"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
# which accompanies this distribution, and is available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
# Initial Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
# Nokia Corporation - initial contribution.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
# Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
# Description:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
# removebuild.pl - prepares a drive for a clean licensee build by removing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
# all buildable files from the drive.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
# 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
my ($file) = readOpts(@ARGV);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
exit remove($file);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
sub readOpts(@)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
	my (@args) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
	my $path = undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
	foreach my $arg (@args)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
		if ($arg =~ /^-/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
			if ((lc($arg) eq "--help")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
			  ||(lc($arg) eq "-h")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
			   )
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
			   	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
				showHelp();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
				exit 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
			else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
				print STDERR "Option '$arg' not recognised.\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
				print STDERR "Try 'removebuild --help' for help.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
				exit 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
		else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
			if (defined($path))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
				print STDERR "Removebuild accepts only one argument.\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
				print STDERR "Try 'removebuild --help' for help.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
				exit 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
			else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
				$path = $arg;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
	if (!defined($path))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
		print STDERR "Removebuild must be given a list of files to remove.\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
		print STDERR "Try 'removebuild --help' for help.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
		exit 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
	return ($path);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
sub remove($)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
	my ($file) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
	open(FILE, $file);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
	my $dir = undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
	my $failed = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
	my $worked = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
	my $hasentries = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
	foreach my $line (<FILE>)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
		chomp($line);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
		$hasentries = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
		if ($line =~ /^\*/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
			if ($line =~ /^\*DIR:/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
				$dir = $line;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
				$dir =~ s/^\*DIR:\s*//;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
				$dir =~ s/[\/\\]*$//; # Remove trailing \/
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
			else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
				close(FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
				die "'$file' is not a valid input.\n('$line' not recognised)\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
		else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
			if (defined($dir))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
				$line =~ s/^[\/\\]*//; # Remove preceding \/
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
				# Attempt to delete '$dir\$line'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
				$line = $dir."\\".$line;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
				if (-e $line)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
					{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
					if (-d $line)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
						{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
						$failed = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
						print STDERR "ERROR: Could not remove file '$line' because $line is a directory\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
						}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
					else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
						{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
						if (!unlink($line))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
							{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
							$failed = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
							print STDERR "ERROR: Could not remove file '$line'. Make sure it is not write protected.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
							}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
						else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
							{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
							$worked = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
							
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
							# Remove parent dirs if now empty
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
							my $empty = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
							while (($line =~ /[\/\\]/) && $empty)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
								{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
								$line =~ s/[\/\\][^\/\\]*$//; # Go to parent dir
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
								if (!rmdir($line))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
									{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
									# If it fails, the dir can't be empty
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
									$empty = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
									}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
								}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
							}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
						}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
					}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
			else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
				{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
				close(FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
				die "'$file' is not a valid input.\n(DIR must be set before '$line')\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
				}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
	close(FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
	if ($hasentries && (!$worked))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
		print STDERR "WARNING: No files listed in '$file' were found. Is the current directory correct?\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
	return $failed;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
sub showHelp()
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
	print "removebuild [options] Filename\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
	print " - prepares a drive for a 'build from clean' by removing\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
	print "   all buildable files.\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
	print "  Filename - The file listing the buildable files to be removed\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
	print "Options:\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
	print "  --help or -h - Display this message\n\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175