|
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 # Subroutines to deploy a patch file. |
|
12 # The required patch files reside in build/{linux-prep|windows-prep}/patch_files. |
|
13 # A patch file with the path: |
|
14 # patch-files/DIR1[/DIR...]/FILE |
|
15 # will be copied to EPOCROOT/DIR1[/DIR...]/FILE, |
|
16 # except in the special case where DIR1 begins with '$'. |
|
17 # In this case, the DIR1 is construed as the name of an environment |
|
18 # variable whose value VAL will be substituted to obtain the name of the |
|
19 # destination file as VAL//DIR1[/DIR...]/FILE. |
|
20 |
|
21 use strict; |
|
22 use File::Spec; |
|
23 use File::Copy; |
|
24 use set_epocroot; |
|
25 use check_os; |
|
26 |
|
27 sub compare_files($$) |
|
28 { |
|
29 my ($flhs,$frhs) = @_; |
|
30 my $delim = $/; |
|
31 $/ = undef; |
|
32 open FH,"<$flhs" or die $!; |
|
33 my $slhs = <FH>; |
|
34 close FH; |
|
35 open FH,"<$frhs" or die $!; |
|
36 my $srhs = <FH>; |
|
37 close FH; |
|
38 $/ = $delim; |
|
39 return "$slhs" eq "$srhs"; |
|
40 } |
|
41 |
|
42 sub apply_patch_file($) |
|
43 { |
|
44 my $patch_file = shift; |
|
45 my ($src_file, $dest_file); |
|
46 set_epocroot(); |
|
47 my $epocroot = $ENV{'EPOCROOT'}; |
|
48 my $patch_files_dir; |
|
49 if (os_is_windows()) { |
|
50 $patch_files_dir = File::Spec->catfile("$epocroot","build","cross-plat-dev-utils","patch-files","windows"); |
|
51 } elsif (os_is_linux()) { |
|
52 $patch_files_dir = File::Spec->catfile("$epocroot","build","cross-plat-dev-utils","patch-files","linux"); |
|
53 } else { |
|
54 die "*** Unsupported OS $^O ***"; |
|
55 } |
|
56 $src_file = File::Spec->catfile($patch_files_dir,$patch_file); |
|
57 if (! -f $src_file) { |
|
58 die("*** Error: not found \"$src_file\" ***"); |
|
59 } |
|
60 if ($patch_file =~ /^\$/) { |
|
61 my ($vol,$dir,$file) = File::Spec->splitpath($patch_file); |
|
62 my @dirs = File::Spec->splitdir($dir); |
|
63 my $topdir = shift(@dirs); |
|
64 $topdir =~ s/^\$//; |
|
65 $topdir = $ENV{$topdir}; |
|
66 my $destdir = File::Spec->catfile($topdir,@dirs); |
|
67 $dest_file = File::Spec->catfile($destdir,$file); |
|
68 } |
|
69 else { |
|
70 $dest_file = File::Spec->catfile($epocroot,$patch_file); |
|
71 } |
|
72 print "??? Need patch \"$src_file\" -> \"$dest_file\" ??? \n"; |
|
73 if (! -f $dest_file) { |
|
74 print ">>> Yes. \"$dest_file\" does not exist\n"; |
|
75 print ">>> Copying \"$src_file\" to \"$dest_file\"n"; |
|
76 copy($src_file,$dest_file) or die $!; |
|
77 } |
|
78 else { |
|
79 my $dif = !compare_files($src_file,$dest_file); |
|
80 print "$dif\n"; |
|
81 if (!$dif) { |
|
82 print ">>> No. \"$dest_file\" is same as \"$src_file\"\n"; |
|
83 } |
|
84 else { |
|
85 print ">>> Yes. \"$dest_file\" differs from \"$src_file\"\n"; |
|
86 my $backup = $dest_file; |
|
87 for (; -f ($backup .= '~');) {}; |
|
88 print ">>> Backing up \"$dest_file\" as \"$backup\"\n"; |
|
89 copy($dest_file,$backup) or die $!; |
|
90 print ">>> Copying \"$src_file\" to \"$dest_file\"\n"; |
|
91 copy($src_file,$dest_file) or die $!; |
|
92 } |
|
93 } |
|
94 } |
|
95 |
|
96 1; |
|
97 |
|
98 |