Debian Codegraph @

llvm-project/clang/utils/analyzer/update_plist_test.pl

raw
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 require File::Temp;
5 use File::Temp ();
6
7 die "update_plist_test <test file> <plist file>\n" if ($#ARGV < 1);
8 my $testFile = shift @ARGV;
9 die "error: cannot read file $testFile\n" if (! -r $testFile);
10 my $plistFile = shift @ARGV;
11 die "error: cannot read file $plistFile\n" if (! -r $plistFile);
12
13 # Create a temp file for the new test.
14 my $fh = File::Temp->new();
15 my $filename = $fh->filename;
16 $fh->unlink_on_destroy(1);
17
18 # Copy the existing temp file, skipping the FileCheck comments.
19 open (IN, $testFile) or die "cannot open $testFile\n";
20 while (<IN>) {
21 next if (/^\/\/ CHECK/);
22 print $fh $_;
23 }
24 close(IN);
25
26 # Copy the plist data, and specially format it.
27 open (IN, $plistFile) or die "cannot open $plistFile\n";
28 my $firstArray = 1;
29 my $first = 1;
30 while (<IN>) {
31 # Skip everything not indented.
32 next if (/^[^\s]/);
33 # Skip the first array entry, which is for files.
34 if ($firstArray) {
35 if (/<\/array>/) { $firstArray = 0; }
36 next;
37 }
38 # Format the CHECK lines.
39 if ($first) {
40 print $fh "// CHECK: ";
41 $first = 0;
42 }
43 else {
44 print $fh "// CHECK-NEXT: ";
45 }
46 print $fh $_;
47 }
48 close (IN);
49 close ($fh);
50
51 `cp $filename $testFile`;
52 print "updated $testFile\n";