xref: /illumos-gate/usr/src/tools/smatch/src/smatch_data/db/create_db.sh (revision 508a0e8cf1600b06c1f7361ad76e736710d3fdf8)
1#!/bin/bash
2
3if echo $1 | grep -q '^-p' ; then
4    PROJ=$(echo $1 | cut -d = -f 2)
5    shift
6fi
7
8info_file=$1
9
10if [[ "$info_file" = "" ]] ; then
11    echo "Usage:  $0 -p=<project> <file with smatch messages>"
12    exit 1
13fi
14
15bin_dir=$(dirname $0)
16db_file=smatch_db.sqlite.new
17
18rm -f $db_file
19
20for i in ${bin_dir}/*.schema ; do
21    cat $i | sqlite3 $db_file
22done
23
24${bin_dir}/init_constraints.pl "$PROJ" $info_file $db_file
25${bin_dir}/init_constraints_required.pl "$PROJ" $info_file $db_file
26${bin_dir}/fill_db_sql.pl "$PROJ" $info_file $db_file
27if [ -e ${info_file}.sql ] ; then
28    ${bin_dir}/fill_db_sql.pl "$PROJ" ${info_file}.sql $db_file
29fi
30${bin_dir}/fill_db_caller_info.pl "$PROJ" $info_file $db_file
31if [ -e ${info_file}.caller_info ] ; then
32    ${bin_dir}/fill_db_caller_info.pl "$PROJ" ${info_file}.caller_info $db_file
33fi
34${bin_dir}/build_early_index.sh $db_file
35
36${bin_dir}/fill_db_type_value.pl "$PROJ" $info_file $db_file
37${bin_dir}/fill_db_type_size.pl "$PROJ" $info_file $db_file
38${bin_dir}/copy_required_constraints.pl "$PROJ" $info_file $db_file
39${bin_dir}/build_late_index.sh $db_file
40
41${bin_dir}/fixup_all.sh $db_file
42if [ "$PROJ" != "" ] ; then
43    ${bin_dir}/fixup_${PROJ}.sh $db_file
44fi
45
46${bin_dir}/remove_mixed_up_pointer_params.pl $db_file
47${bin_dir}/mark_function_ptrs_searchable.pl $db_file
48
49# delete duplicate entrees and speed things up
50echo "delete from function_ptr where rowid not in (select min(rowid) from function_ptr group by file, function, ptr, searchable);" | sqlite3 $db_file
51
52test -e  ${bin_dir}/${PROJ}.return_fixes && \
53cat ${bin_dir}/${PROJ}.return_fixes | \
54while read func old new ; do
55    echo "update return_states set return = '$new' where function = '$func' and return = '$old';" | sqlite3 $db_file
56done
57
58mv $db_file smatch_db.sqlite
59