Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch_data/db/init_constraints.pl
+++ new/usr/src/tools/smatch/src/smatch_data/db/init_constraints.pl
1 1 #!/usr/bin/perl -w
2 2
3 3 use strict;
4 4 use warnings;
5 5 use bigint;
6 6 use DBI;
7 7 use Data::Dumper;
8 8 use File::Basename;
9 9 use Try::Tiny;
10 10
11 11 my $project = shift;
12 12 $project =~ s/.*=(.*)/$1/;
13 13 my $warns = shift;
14 14 my $db_file = shift;
15 15
16 16 sub preserve_existing_constraints()
17 17 {
18 18 if (! -e "smatch_db.sqlite") {
19 19 return;
20 20 }
21 21
22 22 my $db = DBI->connect("dbi:SQLite:$db_file", "", "",);
23 23 $db->do('attach "smatch_db.sqlite" as old_db');
24 24 $db->do('insert into constraints select * from old_db.constraints');
25 25 $db->disconnect();
26 26 }
27 27
28 28 my $db;
29 29
30 30 sub connect_to_db($)
31 31 {
32 32 my $name = shift;
33 33
34 34 $db = DBI->connect("dbi:SQLite:$name", "", "", {AutoCommit => 0});
35 35
36 36 $db->do("PRAGMA cache_size = 800000");
37 37 $db->do("PRAGMA journal_mode = OFF");
38 38 $db->do("PRAGMA count_changes = OFF");
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
39 39 $db->do("PRAGMA temp_store = MEMORY");
40 40 $db->do("PRAGMA locking = EXCLUSIVE");
41 41 }
42 42
43 43 sub load_manual_constraints($$)
44 44 {
45 45 my $full_path = shift;
46 46 my $project = shift;
47 47 my $dir = dirname($full_path);
48 48
49 + if ($project =~ /^$/) {
50 + return;
51 + }
52 +
49 53 open(FILE, "$dir/$project.constraints");
50 54 while (<FILE>) {
51 55 s/\n//;
52 56 $db->do("insert or ignore into constraints (str) values ('$_')");
53 57 }
54 58 close(FILE);
55 59
56 60 open(FILE, "$dir/$project.constraints_required");
57 61 while (<FILE>) {
58 62 my $limit;
59 63 my $dummy;
60 64
61 65 ($dummy, $dummy, $limit) = split(/,/);
62 66 $limit =~ s/^ +//;
63 67 $limit =~ s/\n//;
64 68 try {
65 69 $db->do("insert or ignore into constraints (str) values ('$limit')");
66 70 } catch {}
67 71 }
68 72 close(FILE);
69 73
70 74 $db->commit();
71 75 }
72 76
73 77 preserve_existing_constraints();
74 78
75 79 connect_to_db($db_file);
76 80 load_manual_constraints($0, $project);
77 81
78 82 $db->commit();
79 83 $db->disconnect();
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX