srctools/distillsrc/distillsrc.pl
changeset 620 ad8ffc8e1982
parent 602 3145852acc89
equal deleted inserted replaced
585:238f4cb8391f 620:ad8ffc8e1982
       
     1 #!/bin/perl -w
       
     2 # Copyright (c) 2004-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 the License "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 # distillsrc.pl - compiles a list of source used in .mrp files, and deletes
       
    16 # any unused source
       
    17 # 
       
    18 #
       
    19 
       
    20 use strict;
       
    21 use FindBin;
       
    22 use Getopt::Long;
       
    23 use File::Spec;
       
    24 
       
    25 use lib $FindBin::Bin;
       
    26 use distillsrc;
       
    27 
       
    28 my $errorLevel = 0;
       
    29 
       
    30 # Distillsrc is to continue on error rather than die.  A warning handler is used
       
    31 # so that we can still exit with an error level.
       
    32 $SIG{__WARN__} = sub {warn @_;
       
    33                       $errorLevel = 1};
       
    34 
       
    35 sub dieHelp()
       
    36 	{
       
    37 	print <<HELP_EOF;
       
    38 
       
    39   Usage: perl distillsrc.pl [-f file] [-m file] [-c file] -r src_root
       
    40     -s source_path [-p src_prefix] -l platform [-n] [-d] [-h help];
       
    41 	
       
    42   Options in detail:
       
    43     -file|f file : components.txt file to read (may be more than one)
       
    44     -mrp|m file : additional .mrp file to read (may be more than one)
       
    45     -config|c file : a configuration file to use containing .mrp files to use
       
    46     -r src_root : The root from which all src statements are based
       
    47     -s source_path : The path under src_root to the source tree to be processed
       
    48     -p src_prefix : An optional prefix which can be stripped from all src
       
    49       statements
       
    50     -l platform : The platform (beech etc), needed in order to locate the
       
    51       correct product directory
       
    52     -n : don't check the case of files in the config file and in .mrps against
       
    53       the file system
       
    54     -d : dummy mode
       
    55       
       
    56   Note that the src_prefix in combination with the src_root can be used to
       
    57   displace the source tree, if it isn't in it's final location.
       
    58 HELP_EOF
       
    59 	exit 1;
       
    60 	}
       
    61 
       
    62 # Read command line options to find out if we're doing a dummy run, and where the options are
       
    63 my @files = ();
       
    64 my @mrps = ();
       
    65 my $srcroot;
       
    66 my $srcprefix;
       
    67 my $dummy = 0;
       
    68 my $srcpath;
       
    69 my $config;
       
    70 my $platform;
       
    71 my $help;
       
    72 my $nocheckcase;
       
    73 GetOptions("config=s" => \$config, "file=s" => \@files, "mrp=s" => \@mrps, "srcroot|r=s" => \$srcroot, "srcpath|s=s" => \$srcpath, "srcprefix|p=s" => \$srcprefix, "platform|l=s" => \$platform, "dummy" => \$dummy, "help" => \$help, "nocheck|n" => \$nocheckcase);
       
    74 
       
    75 if ($help)
       
    76 	{
       
    77 	dieHelp();
       
    78 	}
       
    79 
       
    80 
       
    81 my $distiller=New CDistillSrc($srcroot, $srcpath, $srcprefix, $platform, !$nocheckcase);
       
    82 
       
    83 if (!defined($distiller))
       
    84 	{
       
    85 	dieHelp();
       
    86 	}
       
    87 
       
    88 if (!($distiller->LoadMrps($config, \@files, \@mrps)))
       
    89 	{
       
    90 	exit 1; # Couldn't read all the mrps - don't start deleting source based on incomplete data
       
    91 	}
       
    92 
       
    93 $distiller->Print(0);
       
    94 
       
    95 # Run through the source tree, matching every file against the source items. Anything that doesn't, delete it (or warn, if we're doing a dummy run).
       
    96 	
       
    97 $distiller->DistillSrc($dummy);
       
    98 
       
    99 exit $errorLevel;