build/tools/check_environment.pl
branchRCL_3
changeset 21 ea3e26ea6629
parent 6 c8ecf89eb77f
equal deleted inserted replaced
6:c8ecf89eb77f 21:ea3e26ea6629
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 #
       
    16 #!/usr/bin/perl
       
    17 
       
    18 # 
       
    19 # ==============================================================================
       
    20 #  Name        : unzip_check.pl
       
    21 #  Description : This script provides comparison functions to create a filelist
       
    22 #				 and to check if all files in the list are available on the
       
    23 #				 environment.
       
    24 # ==============================================================================
       
    25 # 
       
    26 
       
    27 use strict;
       
    28 
       
    29 use Getopt::Std;
       
    30 use vars qw($opt_c $opt_g);
       
    31 
       
    32 getopts("c:g:");
       
    33 
       
    34 if ($opt_g =~ m/-c/i || $opt_c =~ m/-g/i)
       
    35 {
       
    36 	&error_msg("Cannot generate and check at the same time!");
       
    37 }
       
    38 
       
    39 if ($opt_g)
       
    40 {
       
    41 	&generate();
       
    42 }
       
    43 elsif ($opt_c)
       
    44 {
       
    45 	&check();
       
    46 }
       
    47 else
       
    48 {
       
    49 	&error_msg("Please define the action and filename!");
       
    50 }
       
    51 
       
    52 
       
    53 sub error_msg
       
    54 {
       
    55 	my($ErrorMsg);
       
    56 	($ErrorMsg)=@_;
       
    57 	my $given_command=$0;
       
    58 	$given_command =~ s/.*\\(\w+\.\w+)$/$1/;
       
    59 	print STDERR "\nERROR: $ErrorMsg \n\n" unless ($ErrorMsg =~ /^$/);
       
    60 	print STDERR "\nUsage:\n\t$given_command <parameters>\n";
       
    61 	print STDERR "\nParameters:\n";
       
    62 	print STDERR "\t-g\tGenerate filelist from the environment into file specified after this parameter\n";
       
    63 	print STDERR "\t-c\tCheck if all the files are in the environment that are listed in the file specified after this parameter\n";
       
    64 	print STDERR "\nExamples:\n\t$given_command -g filelist.txt\n";
       
    65 	print STDERR "\t$given_command -c filelist.txt\n";
       
    66 	print STDERR "\n";  
       
    67 	die "\n";
       
    68 }
       
    69 
       
    70 
       
    71 sub generate
       
    72 {
       
    73 	unless ($opt_g =~ m/^$/)
       
    74 	{
       
    75 		open (STDOUT, ">".$opt_g);
       
    76 	}
       
    77 	
       
    78 	open (DIRS,"dir /s/b/a-d 2>nul |");
       
    79 	
       
    80 	my $current_dir = `cd`;
       
    81 	for ($current_dir)
       
    82 	{
       
    83 		s/^\s+//;
       
    84 		s/\s+$//;
       
    85 		s/^.\:\\//;
       
    86 	}
       
    87 	#$current_dir = $current_dir."\\";
       
    88 
       
    89 	while (my $file=<DIRS>)
       
    90 	{
       
    91 		chomp;
       
    92 		for ($file)
       
    93 		{
       
    94 			s/^\s+//;
       
    95 			s/\s+$//;
       
    96 			s/^.\:\\//;
       
    97 		}
       
    98 		substr($file, 0, length($current_dir)+1) = '';
       
    99 		{
       
   100 			print STDOUT $file."\n";
       
   101 		}
       
   102 	}
       
   103 }
       
   104 
       
   105 sub check
       
   106 {
       
   107 	open (INPUTFILE,$opt_c) or error_msg("Filelist $opt_c not found!");
       
   108 		
       
   109 	while (my $line=<INPUTFILE>)
       
   110 	{
       
   111 		chomp;
       
   112 		for ($line)
       
   113 		{
       
   114 			s/^\s+//;
       
   115 			s/\s+$//;
       
   116 		}
       
   117 		stat($line);
       
   118 		next if -f _;
       
   119 		print "MISSING: ".$line."\n";
       
   120 	}
       
   121 }