first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / tools / solution_solvers / verify_project_file.sh
1 #!/bin/bash
2
3 # this script locates the solution that a project file belongs in and decides whether the
4 # project file contains any bad references to projects that are outside of its solution.
5
6 proj_file="$1"; shift
7
8 if [ -z "$proj_file" ]; then
9   echo This script needs one parameter that is a project file to be verified.
10   echo The file will be located in a solution file, and then checked for all project
11   echo references being in the same solution file.
12   exit 3
13 fi
14
15 ##############
16
17 # look for the solution that a project belongs to.
18 function find_solution_membership()
19 {
20   local proj="$1"; shift
21   found_solution=
22   for i in ${SOLUTIONS[*]}; do
23     # secret sauce--don't match on any old reference to the file; we need
24     # it to be coming from the real project definition.
25     grep -i "$proj\"," "$i" &>/dev/null
26     if [ $? -eq 0 ]; then
27 #echo "$proj found in solution $i"
28       found_solution="$i"
29       break
30     fi
31   done
32 }
33
34 function complain_about_project()
35 {
36   filename="$1"; shift
37   echo "!!"
38   echo "Project $proj_base is in error (at $proj_file)"
39   echo "it references project $filename which is external to the solution."
40   echo "!!"
41   ((errors_seen++))
42 }
43
44 ##############
45
46 proj_base="$(basename $proj_file)"
47
48 CHECKERS="$TMP/checking_refs.txt"
49
50 errors_seen=0
51
52 #hmmm fix this for big time
53 export SOLUTIONS=("$BUILD_TOP/libraries/solutions/"*.sln "$BUILD_TOP/products/"*/*.sln)
54
55 find_solution_membership "$proj_base"
56
57 #echo found sol is $found_solution
58
59 if [ -z "$found_solution" ]; then
60   echo error: could not find the solution containing $proj_base
61   exit 3
62 fi
63
64 # get all the project references from the project file being tested.
65 #hmmm: fix this path to extract!
66 bash "$BUILD_TOP/build/tool_source/solution_solvers/extract_projects.sh" "$proj_file" >"$CHECKERS"
67
68 # iterate over all references in the project file.
69 while read line; do
70   grep -i "$line" "$found_solution" &>/dev/null
71   if [ $? -ne 0 ]; then
72     complain_about_project "$line"
73   fi
74 done <"$CHECKERS"
75
76 if [ $errors_seen -eq 0 ]; then
77   echo "project $proj_base is clean."
78 else
79   echo "ERROR: there were $errors_seen problems in $proj_base; see above logging."
80   exit 3
81 fi
82
83