|
1 | 1 | #!/bin/sh
|
2 |
| -if ! command -v gnat2goto > /dev/null; then |
3 |
| - echo >&2 "gnat2goto not on PATH!" |
4 |
| - exit 1 |
5 |
| -fi |
6 |
| - |
7 |
| -if [ "$#" -ne 1 ]; then |
8 |
| - echo >&2 "Provide folder name to start" |
9 |
| - exit 2 |
10 |
| -fi |
11 | 2 |
|
12 |
| -if [ "$1" = '--help' ]; then |
| 3 | +# Usage info |
| 4 | +usage() |
| 5 | +{ |
| 6 | + echo "Usage:\n\nlist_unsupported.sh path_to_ada_source_folder\n" |
13 | 7 | echo "Run GNAT2Goto on an Ada repository.\n"
|
14 | 8 | echo "The output is an ordered list of currently unsupported features"
|
15 | 9 | echo "with the number of times they occur in the input repository.\n"
|
16 | 10 | echo "The script builds a parsing program using collect_unsupported.cpp and expects"
|
17 | 11 | echo "this file to be in the same folder.\n"
|
18 |
| - echo "Usage:\n\nlist_unsupported.sh path_to_ada_source_folder" |
19 |
| - exit 3 |
20 |
| -fi |
21 |
| - |
22 |
| -echo >&2 "Project to build: $1" |
23 |
| -path="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" |
24 |
| -include_path="" |
25 |
| -DIR=`dirname "$0"` |
26 |
| -file_name=$(basename "$1") |
| 12 | +} |
27 | 13 |
|
28 |
| -for foldername in $(find ${path} -type d -name "*" | LC_ALL=posix sort ); do |
29 |
| - count=`ls -1 ${foldername}/*.ads 2>/dev/null | wc -l` |
30 |
| - if [ $count != 0 ] |
31 |
| - then |
32 |
| - include_path="${include_path} -I ${foldername}" |
33 |
| - fi |
34 |
| -done |
| 14 | +# First check some environment prerequisites |
| 15 | +echo >&2 "Checking environment..." |
35 | 16 |
|
36 |
| -echo "$1: Unsupported features\n" > "$file_name".txt |
| 17 | +# gnat2goto on the path? |
| 18 | +if ! command -v gnat2goto > /dev/null; then |
| 19 | + echo >&2 "gnat2goto not on PATH!" |
| 20 | + gnat2goto_bin=$(cd "$(dirname ${0})/../gnat2goto/install/bin" 2>/dev/null && pwd) |
| 21 | + echo >&2 "Suggested adding gnat2goto to your PATH with the following command:" |
| 22 | + echo >&2 " export PATH=\"${gnat2goto_bin}:\${PATH}\"" |
| 23 | + exit 1 |
| 24 | +fi |
37 | 25 |
|
| 26 | +# gnat on the path? |
38 | 27 | if ! command -v gnat > /dev/null; then
|
39 | 28 | echo >&2 "Gnat not on PATH!"
|
| 29 | + # Take a wild guess at where gnat might be installed... |
| 30 | + gnat_location="/opt/gnat/bin" |
| 31 | + if [ -x "${gnat_location}/gnat" ] ; then |
| 32 | + # Check if that's gnat 2016... |
| 33 | + if gnat --version | grep -q 'GNAT GPL 2016' ; then |
| 34 | + echo >&2 "Suggested adding gnat to your PATH with the following command:" |
| 35 | + echo >&2 " export PATH=\"${gnat_location}:\${PATH}\"" |
| 36 | + fi |
| 37 | + fi |
40 | 38 | exit 4
|
41 | 39 | fi
|
42 | 40 |
|
| 41 | +# Right version of gnat? |
| 42 | +if ! (gnat --version | grep -q 'GNAT GPL 2016') ; then |
| 43 | + echo >&2 "The wrong version of gnat is on the PATH. gnat2goto requires GNAT GPL 2016." |
| 44 | + exit 5 |
| 45 | +fi |
| 46 | + |
| 47 | +# Sane ADA_INCLUDE_PATH and GPR_PROJECT_PATH? |
43 | 48 | GNAT2GOTO=`command -v gnat2goto`
|
44 | 49 | ADA_HOME=`command -v gnat`
|
45 |
| -ADA_HOME="$(dirname "$ADA_HOME")/.." |
| 50 | +ADA_HOME=$(cd "$(dirname ${ADA_HOME})/.." 2>/dev/null && pwd) |
46 | 51 | PLATFORM=`${ADA_HOME}/bin/gcc -dumpmachine`
|
47 | 52 | DEF_ADA_INCLUDE_PATH="${ADA_HOME}/lib/gcc/${PLATFORM}"
|
48 | 53 | ADA_GCC_VERSION=`${ADA_HOME}/bin/gcc -dumpversion`
|
49 | 54 | DEF_ADA_INCLUDE_PATH="${DEF_ADA_INCLUDE_PATH}/${ADA_GCC_VERSION}/rts-native/adainclude:${ADA_HOME}/include"
|
50 | 55 | export ADA_INCLUDE_PATH="${ADA_INCLUDE_PATH:-$DEF_ADA_INCLUDE_PATH}"
|
51 | 56 |
|
52 |
| -export GPR_PROJECT_PATH="${GPR_PROJECT_PATH:-/opt/gnat/lib/gnat}" |
53 |
| -if [ ! -d "$GPR_PROJECT_PATH" ]; then |
54 |
| - echo >&2 "GPR project path does not exists!" |
| 57 | +if [ -n "$GPR_PROJECT_PATH" -a ! -d "$GPR_PROJECT_PATH" ]; then |
| 58 | + echo >&2 "GPR project path environment variable has been set to:" |
| 59 | + echo >&2 " \"${GPR_PROJECT_PATH}\"" |
| 60 | + echo >&2 "but that path is not a directory." |
| 61 | + echo >&2 "Please set the environment variable GPR_PROJECT_PATH to the" |
| 62 | + echo >&2 "location of the gnat libraries" |
55 | 63 | exit 6
|
| 64 | +else |
| 65 | + # GPR_PROJECT_PATH not previously specified, use a default |
| 66 | + export GPR_PROJECT_PATH="${ADA_HOME}/lib/gnat" |
| 67 | + if [ ! -d "$GPR_PROJECT_PATH" ]; then |
| 68 | + echo >&2 "Could not find gnat library directory at ${GPR_PROJECT_PATH}" |
| 69 | + echo >&2 "Please set the environment variable GPR_PROJECT_PATH to the" |
| 70 | + echo >&2 "location of the gnat libraries" |
| 71 | + exit 9 |
| 72 | + fi |
| 73 | +fi |
| 74 | + |
| 75 | +# Can we build the support tool? |
| 76 | +# Problem: GNAT 2016 helpfully installs a g++ binary alongside gnat... except |
| 77 | +# it's way out of date so invoking g++ via PATH looking will pickup that gnat g++ |
| 78 | +# compiler, rather than the default system compiler... Instead we need to |
| 79 | +# temporarily drop the GNAT tools off the path while we build the tool. |
| 80 | +saved_path="$PATH" |
| 81 | +export PATH=$(echo ${PATH} | tr ':' '\n' | grep -v "${ADA_HOME}" | paste -s -d : - ) |
| 82 | +experiment_dir=`dirname "$0"` |
| 83 | +gplusplus=`command -v g++` |
| 84 | +if ! ${gplusplus} --std=c++14 "${experiment_dir}/collect_unsupported.cpp" -o CollectUnsupported ; then |
| 85 | + echo >&2 "Failed to compile support tool 'CollectUnsupported' using ${gplusplus}" |
| 86 | + echo >&2 "You need a version of g++ on the PATH that supports C++14" |
| 87 | + exit 8 |
56 | 88 | fi
|
| 89 | +export PATH="${saved_path}" |
| 90 | + |
| 91 | +echo >&2 "...environment is OK." |
| 92 | + |
| 93 | + |
| 94 | +# Command line processing.... |
| 95 | + |
| 96 | +if [ "$1" = '--help' ]; then |
| 97 | + usage |
| 98 | + exit |
| 99 | +fi |
| 100 | + |
| 101 | +if [ "$#" -ne 1 ]; then |
| 102 | + usage >&2 |
| 103 | + echo >&2 "Only a single folder name may be specified" |
| 104 | + exit 2 |
| 105 | +fi |
| 106 | + |
| 107 | +# Finally start work |
| 108 | + |
| 109 | +echo >&2 "Project to build: $1" |
| 110 | +path="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" |
| 111 | +include_path="" |
| 112 | +file_name=$(basename "$1") |
| 113 | + |
| 114 | +for foldername in $(find ${path} -type d -name "*" | LC_ALL=posix sort ); do |
| 115 | + count=`ls -1 ${foldername}/*.ads 2>/dev/null | wc -l` |
| 116 | + if [ $count != 0 ] |
| 117 | + then |
| 118 | + include_path="${include_path} -I ${foldername}" |
| 119 | + fi |
| 120 | +done |
| 121 | + |
| 122 | +echo "$1: Unsupported features\n" > "$file_name".txt |
57 | 123 |
|
58 | 124 | # Enumerate all the sub directories of ADA_INCLUDE_PATH
|
59 | 125 | for include_folder in `echo "$ADA_INCLUDE_PATH" | tr ':' ' '` ; do
|
@@ -118,7 +184,6 @@ sed '/^\[/ d' < "$file_name".txt | \
|
118 | 184 | > "$file_name"_redacted.txt
|
119 | 185 |
|
120 | 186 | # Collate and summarise unsupported features
|
121 |
| -g++ --std=c++14 "$DIR"/collect_unsupported.cpp -o CollectUnsupported |
122 | 187 | LC_ALL=posix ./CollectUnsupported "$file_name".txt
|
123 | 188 |
|
124 | 189 | # Collate and summarize compile errors from builds that did not generate
|
|
0 commit comments