~ubuntu-branches/ubuntu/oneiric/enigmail/oneiric-updates

« back to all changes in this revision

Viewing changes to build/file_migrate.pl

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2010-04-10 01:42:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100410014224-fbq9ui5x3b0h2t36
Tags: 2:1.0.1-0ubuntu1
* First releaase of enigmail 1.0.1 for tbird/icedove 3
  (LP: #527138)
* redo packaging from scratch 
  + add debian/make-orig target that uses xulrunner provided
    buildsystem + enigmail tarball to produce a proper orig.tar.gz
  + use debhelper 7 with mozilla-devscripts
  + use debian source format 3.0 (quilt)
  + patch enigmail to use frozen API only
    - add debian/patches/frozen_api.diff
  + patch build system to not link against -lxul - which isnt
    available for sdks produced by all-static apps like tbird
    - add debian/patches/build_system_dont_link_libxul.diff
  + add minimal build-depends to control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl -w
 
2
 
 
3
# This script copies modified files from a source CVS tree to a destination
 
4
# tree. Modified files are detected by comparing their modification dates
 
5
# with the CVS Entries file.
 
6
 
7
# Modified files are copied in their entirety to the destination tree
 
8
# (no diffing is done). Files are only copied of the CVS version of the
 
9
# file is the same in both trees. If the destination file is modified
 
10
# already, it is backed up and replaced.
 
11
 
12
# To use this on your tree/platform, do the following:
 
13
 
14
# 1. Fix the !perl line, if necessary.
 
15
# 2. Fix $dirsep to be the directory separator on your platform.
 
16
# 3. Uncomment the appropriate $dst_linebreaks file specify what linebreaks
 
17
#    you want for the copied files. This variable defines the *destination* linebreaks 
 
18
#    that you want your changes to be converted to.
 
19
#    For example, if you have a linux volume 
 
20
#    mounted (via SAMBA perhaps) to your windows box where you've made changes to 
 
21
#    source files, you'd want $dst_linebreaks to be set for unix. This ensures that 
 
22
#    linebreaks are converted to the appropriate OS linebreak scheme for your *target* tree.
 
23
# 4. Set $src_tree and $dest_tree to point to the directories you want
 
24
#    to sync up. These don't have to point to the root of the tree,
 
25
#    but should be equivalent directories in the two trees.
 
26
#    
 
27
# First version:
 
28
#     Simon Fraser <sfraser@netscape.com>
 
29
 
 
30
use File::stat;
 
31
use Time::Local;
 
32
 
 
33
# change for your platform ('\' == windows, ':' == mac, '/' == unix)
 
34
$dirsep = "\\";
 
35
 
 
36
# Set this to the native OS of the *destination* tree
 
37
# $dst_linebreaks = pack("cc", 13);           # Mac
 
38
#$dst_linebreaks = pack("cc", 13, 10);       # DOS
 
39
$dst_linebreaks = pack("cc", 10);           # UNIX
 
40
 
 
41
#change for your src and dest trees
 
42
$src_tree =  "x:\\mozilla\\xpfe\\components";
 
43
$dest_tree = "h:\\builds\\mozilla\\xpfe\\components";
 
44
 
 
45
 
 
46
#//--------------------------------------------------------------------------------------------------
 
47
#// _copyFile. Copy file from src to dest, converting linebreaks if necessary
 
48
#//--------------------------------------------------------------------------------------------------
 
49
sub _copyFile($;$;$;$)
 
50
{
 
51
    my($srcdir, $destdir, $file, $backup) = @_;
 
52
 
 
53
    my($srcfile) = $srcdir.$dirsep.$file;
 
54
    my($dstfile) = $destdir.$dirsep.$file;
 
55
    
 
56
    if ($backup)
 
57
    {
 
58
        my($counter) = 0;
 
59
        
 
60
        while (-f $dstfile."-".$counter)
 
61
        {
 
62
            $counter ++;
 
63
        }
 
64
        
 
65
        rename($dstfile, $dstfile."-".$counter) or die "Failed to rename file\n";
 
66
    }
 
67
    
 
68
    print "Copying $file over to dest\n";
 
69
 
 
70
    my($newdest) = $dstfile."_temp";
 
71
    
 
72
    open(SRCFILE, "< $srcfile")     or die "Can't open source file $srcfile\n";
 
73
    open(NEWDEST, "> $newdest")     or die "Can't open dest file $newdest\n";
 
74
    
 
75
    while (<SRCFILE>)
 
76
    {
 
77
        chomp($_);
 
78
        print NEWDEST $_.$dst_linebreaks;
 
79
    }
 
80
    
 
81
    close(SRCFILE);
 
82
    close(NEWDEST);
 
83
    
 
84
    if (!$backup) {
 
85
        unlink($dstfile)  or die "Failed to remove $dstfile\n";
 
86
    }
 
87
    rename($newdest, $dstfile)      or die "Failed to rename $newdest\n";
 
88
}
 
89
 
 
90
 
 
91
#//--------------------------------------------------------------------------------------------------
 
92
#// _readCVSInfo. Suck in the CVS info from the Entries file
 
93
#//--------------------------------------------------------------------------------------------------
 
94
 
 
95
sub _readCVSInfo($)
 
96
{
 
97
    my($cvsDir) = @_;
 
98
 
 
99
    my($entries_file_name) = $cvsDir.$dirsep."CVS".$dirsep."Entries";
 
100
    
 
101
    # print "Reading $entries_file_name\n";
 
102
    open(ENTRIES, $entries_file_name) || die "Could not open file $entries_file_name";
 
103
 
 
104
    my(%cvs_entries);
 
105
    
 
106
    # Read in the path if available    
 
107
    while (defined ($line = <ENTRIES>))
 
108
    {
 
109
        chomp($line);
 
110
        
 
111
        #parse out the line. Format is:
 
112
        #   files:    /filename/version/date/options/tag
 
113
        #   dirs:     D/dirname////
 
114
        #   dir?      D
 
115
        # because we might be reading an entries file from another platform, with
 
116
        # different linebreaks, be anal about cleaning up $line.
 
117
                
 
118
        if ($line =~ /^?\/(.+)\/(.+)\/(.+)\/(.*)\/(.*)?$/)
 
119
        {
 
120
            my($filename) = $1;
 
121
            my($version) = $2;
 
122
            my($date) = $3;
 
123
            my($options) = $4;
 
124
            my($tag) = $5;
 
125
            
 
126
            my(%cvs_file) = (
 
127
                "version"   => $version,
 
128
                "date"      => $date,
 
129
                "options"   => $options,
 
130
                "tag"       => $tag
 
131
            );
 
132
                        
 
133
            # print $filename." ".$version." ".$date." ".$options." ".$tag."\n";
 
134
            $cvs_entries{$filename} = \%cvs_file;
 
135
        }
 
136
    }
 
137
   
 
138
    close ENTRIES;
 
139
 
 
140
    return %cvs_entries;
 
141
}
 
142
 
 
143
 
 
144
#//--------------------------------------------------------------------------------------------------
 
145
#// _fileIsModified. compare mod date with CVS entries to see if a file is modified
 
146
#//--------------------------------------------------------------------------------------------------
 
147
sub _fileIsModified($;$;$)
 
148
{
 
149
    my($entries, $dir, $file) = @_;
 
150
 
 
151
    my($abs_file) = $dir.$dirsep.$file;
 
152
 
 
153
    if (exists($entries->{$file}))
 
154
    {
 
155
        my($date) = $entries->{$file}->{"date"};
 
156
        
 
157
        # stat the file to get its date
 
158
        my($file_data) = stat($abs_file) || die "Could not stat $file\n";
 
159
        my($mod_string) = scalar(gmtime($file_data->mtime));
 
160
 
 
161
       return ($mod_string ne $date);
 
162
    }
 
163
    else
 
164
    {
 
165
        return 0;    
 
166
    }
 
167
}
 
168
 
 
169
 
 
170
#//--------------------------------------------------------------------------------------------------
 
171
#// _processFile. args: entries hash, dir, filename
 
172
#//--------------------------------------------------------------------------------------------------
 
173
 
 
174
sub _processFile($;$;$;$;$)
 
175
{
 
176
    my($src_entries, $dest_entries, $srcdir, $destdir, $file) = @_;
 
177
 
 
178
    my($abs_file) = $srcdir.$dirsep.$file;
 
179
            
 
180
    if (exists($src_entries->{$file}))
 
181
    {
 
182
        my($file_entry) = $src_entries->{$file};
 
183
        my($version) = $file_entry->{"version"};
 
184
        
 
185
        if (_fileIsModified($src_entries, $srcdir, $file))
 
186
        {
 
187
            my($rel_file) = $abs_file;
 
188
            $rel_file =~ s/^$src_tree//;
 
189
            
 
190
            # print "��File $rel_file is modified\n";
 
191
            
 
192
            # check CVS version in dest
 
193
            my($dest_entry) = $dest_entries->{$file};
 
194
            if ($dest_entry)
 
195
            {
 
196
                my($dest_version) = $dest_entry->{"version"};
 
197
                my($versions_match) = ($version == $dest_version);
 
198
                my($dest_modified) = _fileIsModified($dest_entries, $destdir, $file);
 
199
                                
 
200
                if ($versions_match)
 
201
                {
 
202
                    # ok, we can copy the file over now, backing up dest if it is modified
 
203
                    _copyFile($srcdir, $destdir, $file, $dest_modified);
 
204
                }
 
205
                else
 
206
                {
 
207
                    print "File $rel_file is version $version in the src tree, but $dest_version in dest. This file will not be copied.\n";
 
208
                }
 
209
            }
 
210
            else
 
211
            {
 
212
                print "No CVS entry found in destination tree for $rel_file\n";
 
213
            }
 
214
        }
 
215
    }
 
216
    else
 
217
    {
 
218
        print "No entry for file $file\n";
 
219
    }
 
220
}
 
221
 
 
222
 
 
223
#//--------------------------------------------------------------------------------------------------
 
224
#// _traverseDir. Traverse one dir, recurse for each found dir.
 
225
#//--------------------------------------------------------------------------------------------------
 
226
 
 
227
sub _traverseDir($;$)
 
228
{
 
229
    my($srcdir, $destdir) = @_;
 
230
 
 
231
    opendir(DIR, $srcdir) or die "Cannot open dir $srcdir\n";
 
232
    my @files = readdir(DIR);
 
233
    closedir DIR;
 
234
    
 
235
    # suck in the CVS info for this dir, if there is a CVS dir
 
236
    unless (-e $srcdir.$dirsep."CVS".$dirsep."Entries" && -e $destdir.$dirsep."CVS".$dirsep."Entries") {
 
237
        print "$srcdir is not a CVS directory in both source and dest\n";
 
238
        return;
 
239
    }
 
240
    
 
241
    print " Doing $srcdir\n";
 
242
    
 
243
    my(%src_entries)  = _readCVSInfo($srcdir);
 
244
    my(%dest_entries) = _readCVSInfo($destdir);
 
245
 
 
246
    my $file;    
 
247
    foreach $file (@files)
 
248
    {        
 
249
        my $filepath = $srcdir.$dirsep.$file;
 
250
                
 
251
        if (-d $filepath)
 
252
        {
 
253
            if ($file ne "CVS")     # ignore 'CVS' dirs
 
254
            {
 
255
                # print "Going into $filepath\n";            
 
256
                _traverseDir($filepath, $destdir.$dirsep.$file);
 
257
            }
 
258
        }
 
259
        else
 
260
        {
 
261
            # process this file
 
262
            _processFile(\%src_entries, \%dest_entries, $srcdir, $destdir, $file);
 
263
        }
 
264
    }
 
265
}
 
266
 
 
267
#//--------------------------------------------------------------------------------------------------
 
268
#// MigrateChanges
 
269
#//--------------------------------------------------------------------------------------------------
 
270
sub MigrateChanges($;$)
 
271
{
 
272
    my($srcdir, $destdir) = @_;
 
273
 
 
274
    # Check that src and dest exist
 
275
    if (! -d $srcdir) {
 
276
        die "Source directory $srcdir does not exist\n";
 
277
    }
 
278
 
 
279
    if (! -d $destdir) {
 
280
        die "Dest directory $destdir does not exist\n";
 
281
    }
 
282
 
 
283
    print "---------------------------------------------------------\n";
 
284
    print "Migrating changes from\n  $srcdir\nto\n  $destdir\n";
 
285
    print "---------------------------------------------------------\n";
 
286
    _traverseDir($srcdir, $destdir);
 
287
    print "---------------------------------------------------------\n";
 
288
}
 
289
 
 
290
 
 
291
MigrateChanges($src_tree, $dest_tree);
 
292