cross-plat-dev-utils/diff_upstream.pl
changeset 2 39c28ec933dd
child 6 787612182dd0
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     1 #!/usr/bin/perl
       
     2 # Copyright (c) 2010 Symbian Foundation Ltd
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Mike Kinghan, mikek@symbian.org for Symbian Foundation Ltd - initial contribution.
       
    10 
       
    11 # Script to diff this package with the upstream revsion on which it is
       
    12 # baselined.
       
    13 
       
    14 use strict;
       
    15 use get_baseline;
       
    16 use perl_run;
       
    17 use set_epocroot;
       
    18 use get_hostplatform_dir;
       
    19 use File::Spec;
       
    20 use Cwd 'abs_path';
       
    21 use Getopt::Long;
       
    22 
       
    23 my $help =0;
       
    24 my $baseline_dir = '';
       
    25 my $diff_out = '';
       
    26 my @excludes = ('*.hg*','*cross-plat-dev-utils*','*baseline.txt','*README','*TODO','*NEWS','*.pyc','*~');
       
    27 
       
    28 sub usage(*);
       
    29 sub usage_error($);
       
    30 sub help();
       
    31 
       
    32 GetOptions("help=i" => \$help, "diff-file=s" => \$diff_out,
       
    33 	"baseline-dir=s" => \$baseline_dir) or usage_error("Usage error");
       
    34 
       
    35 if ($help) {
       
    36 	help();
       
    37 }
       
    38 if (!$baseline_dir) {
       
    39 	usage_error("Need -b, --baseline-dir");
       
    40 }
       
    41 print ">>> Testing for diff\n";
       
    42 my $diff_test = "diff --version";
       
    43 my $devnull = File::Spec->devnull();
       
    44 print ">>> Executing: $diff_test\n";
       
    45 my $rc = system($diff_test > $devnull);
       
    46 die "*** Error: can't execute the diff tool ***", if ($rc);
       
    47 $baseline_dir = abs_path($baseline_dir);
       
    48 perl_run("get_upstream.pl $baseline_dir") and die $!;
       
    49 set_epocroot();
       
    50 my $epocroot = $ENV{'EPOCROOT'};
       
    51 my $build_pkg_dir = File::Spec->catfile("$epocroot","build");
       
    52 $baseline_dir = File::Spec->catfile("$baseline_dir","build");
       
    53 my $host_platform_dir = get_hostplatform_dir();
       
    54 push(@excludes,"*$host_platform_dir*");
       
    55 foreach my $exclude (@excludes) {
       
    56 	$exclude = "-x '$exclude'";
       
    57 }
       
    58 my $diff_cmd;
       
    59 if (!$diff_out) {
       
    60 	my $baseline_rev = get_baseline();
       
    61 	$diff_out = File::Spec->catfile("$epocroot","build","cross-plat-dev-utils",
       
    62 		"patch-files","diffs","patch-$baseline_rev.patch");
       
    63 }
       
    64 open DIFF,">$diff_out" or die $!;
       
    65 print DIFF "## diff generated by diff_upstream.pl\n";
       
    66 close DIFF;
       
    67 $diff_cmd = "diff -u -r -b -B -E @excludes $baseline_dir $build_pkg_dir >> $diff_out";
       
    68 print ">>> Executing: $diff_cmd\n";
       
    69 exit system($diff_cmd) >> 8;
       
    70 
       
    71 sub usage(*)
       
    72 {
       
    73 	local *OUT = shift;
       
    74 	print OUT "This script diffs this package with upstream package at the " .
       
    75 		" baseline revision in ../baseline.txt\n" .
       
    76 		"Options:\n" .
       
    77 		"-h, --help:              Display this help and exit\n" .
       
    78 		"-d, --diff-file FILE:    The diffs will be written to FILE. " .
       
    79 			"Default ./patch-files/diffs/patch-N, where N is the baseline revision\n" .
       
    80 		"-b, --baseline-dir DIR:  The upstream baseline will be cloned into " .
       
    81 			"DIR if this does not seem to have been done already. Otherwise " .
       
    82 			"DIR/build will be udated to the baseline revision before diffing\n" .
       
    83 		"*** It is assumed that the command 'diff' will invoke the diff tool " .
       
    84 		"***\n";
       
    85 }
       
    86 
       
    87 sub usage_error($)
       
    88 {
       
    89 	my $diag = shift;
       
    90 	print STDERR "*** $diag ***\n";
       
    91 	usage(*STDERR);
       
    92 	exit 1;
       
    93 }
       
    94 
       
    95 sub help()
       
    96 {
       
    97 	usage(*STDOUT);
       
    98 	exit 0;
       
    99 }
       
   100