FreeCalypso > hg > tcs211-fcmodem
comparison g23m/system/busyb/tools/verify_target_file.pl @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 # | |
2 # verify_target_file.pl | |
3 # | |
4 # tool to check for make-like dependency | |
5 # | |
6 # format: verify_target_file.pl temp-file other-dest-file-index other-command other-parameters | |
7 # | |
8 # the intention of this command is to modify conditionally a file, as would it | |
9 # have done by make. since there is no date information, the tool uses the | |
10 # content of the file. | |
11 # | |
12 # the behaviour of this script is somehow specific: | |
13 # - it expects that other-dest-file-index decribes which parameter of | |
14 # other-parameters describes the file to be generated. first parameter is | |
15 # described with 0 etc. other-command is a perl script and will be invoked | |
16 # with "do". | |
17 # - it invokes other-command, but replaces the first parameter with temp-file | |
18 # - it then verifies temp-file against the expected result file (the first | |
19 # parameter). if this file does not exist or is different to temp-file, | |
20 # temp-file is renamed to the first parameter. otherwise (file exists and | |
21 # its content is equal to the content of temp-file), only the temp-file is | |
22 # removed. | |
23 # - since the file is already so special, it brings its own comparison tool, | |
24 # that way there is no need to install anything else, that tool compares | |
25 # text files | |
26 # | |
27 # IMPORTANT: | |
28 # since the used rename does not rename over file system boundaries (at least | |
29 # it is not promised), choose your temp-file accordingly | |
30 # | |
31 | |
32 use strict; | |
33 #use warnings; | |
34 | |
35 my $temp_file = shift; | |
36 my $other_dest_file_index = shift; | |
37 my $other_command = shift; | |
38 my $other_dest_file = $ARGV[$other_dest_file_index]; | |
39 | |
40 # modify command_line | |
41 $ARGV[$other_dest_file_index] = $temp_file; | |
42 | |
43 my $result = do $other_command; | |
44 | |
45 if ((! defined $result) && ($! || $@)) | |
46 { | |
47 die "system $other_command failed: $!\n$@"; | |
48 } | |
49 | |
50 if (! -e $temp_file) | |
51 { | |
52 #something unexpected occured | |
53 die "$temp_file should have been generated"; | |
54 } | |
55 | |
56 if (( ! -e $other_dest_file ) || | |
57 compare_files($other_dest_file, $temp_file) == 0) | |
58 { | |
59 unlink $other_dest_file; | |
60 rename $temp_file, $other_dest_file; | |
61 } | |
62 else | |
63 { | |
64 unlink $temp_file; | |
65 } | |
66 | |
67 sub get_contents_of_file | |
68 { | |
69 my ($filename) = @_; | |
70 | |
71 open(FILE, "<$filename") or die "open failed: $filename"; | |
72 my @lines = <FILE>; | |
73 my $text = join '', @lines; | |
74 close FILE; | |
75 | |
76 $text | |
77 } | |
78 | |
79 sub compare_files | |
80 { | |
81 my ($file1, $file2) = @_; | |
82 | |
83 get_contents_of_file($file1) eq get_contents_of_file($file2) | |
84 } | |
85 |