Skip to content

Commit dc35772

Browse files
authored
Merge pull request #257 from chrisr-diffblue/apex_naming_conventions
Add partial support for Rational APEX file naming conventions to list_unsupported.sh
2 parents de356ef + 783382a commit dc35772

File tree

2 files changed

+71
-18
lines changed

2 files changed

+71
-18
lines changed

experiments/list_unsupported.sh

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
# Usage info
44
usage()
55
{
6-
echo "Usage:\n\nlist_unsupported.sh path_to_ada_source_folder\n"
7-
echo "Run GNAT2Goto on an Ada repository.\n"
6+
echo "Usage:list_unsupported.sh [--help] [--apex] [--adc pragmas.adc] path_to_ada_source_folder"
7+
echo
8+
echo "Run GNAT2Goto on an Ada repository."
9+
echo
810
echo "The output is an ordered list of currently unsupported features"
9-
echo "with the number of times they occur in the input repository.\n"
10-
echo "The script builds a parsing program using collect_unsupported.cpp and expects"
11-
echo "this file to be in the same folder.\n"
11+
echo "with the number of times they occur in the input repository."
12+
echo
13+
echo "Options:"
14+
echo " --help Display this usage information"
15+
echo " --apex Use Rational APEX style naming convention .1.ada and .2.ada"
16+
echo " --adc pragmas.adc Use the specified 'pragmas.adc' file during compilation"
1217
}
1318

19+
# File extensions to expect for Specification files and Body files
20+
spec_ext="${SPEC_EXT:-ads}"
21+
body_ext="${BODY_EXT:-adb}"
22+
1423
# First check some environment prerequisites
1524
echo >&2 "Checking environment..."
1625

@@ -93,46 +102,82 @@ echo >&2 "...environment is OK."
93102

94103
# Command line processing....
95104

96-
if [ "$1" = '--help' ]; then
105+
if [ "$#" -eq 0 ]; then
97106
usage
98107
exit
99108
fi
100109

101-
if [ "$#" -ne 1 ]; then
110+
while [ -n "$1" ] ; do
111+
case "$1" in
112+
--apex)
113+
spec_ext="1.ada"
114+
body_ext="2.ada"
115+
pragma_file="$(dirname ${0})/rational-apex.adc"
116+
;;
117+
--adc)
118+
shift
119+
if [ -r "${1}" ] ; then
120+
pragma_file="${1}"
121+
else
122+
usage >&2
123+
echo >&2 "--adc option must specify a configuration pragma file"
124+
exit 2
125+
fi
126+
;;
127+
--help)
128+
usage
129+
exit
130+
;;
131+
*)
132+
if [ -n "$project_dir" ]; then
133+
usage >&2
134+
echo >&2 "Only a single folder name may be specified"
135+
exit 2
136+
fi
137+
project_dir="$1"
138+
esac
139+
shift
140+
done
141+
142+
if [ -z "$project_dir" ]; then
102143
usage >&2
103-
echo >&2 "Only a single folder name may be specified"
144+
echo >&2 "A project folder name must be specified"
104145
exit 2
105146
fi
106147

107148
# Finally start work
108149

109-
echo >&2 "Project to build: $1"
110-
path="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
150+
echo >&2 "Project to build: ${project_dir}"
151+
file_name=$(basename "${project_dir}")
152+
path="$(cd "$(dirname "${project_dir}")"; pwd)/${file_name}"
111153
include_path=""
112-
file_name=$(basename "$1")
113154

114155
for foldername in $(find ${path} -type d -name "*" | LC_ALL=posix sort ); do
115-
count=`ls -1 ${foldername}/*.ads 2>/dev/null | wc -l`
156+
count=`ls -1 ${foldername}/*.${spec_ext} 2>/dev/null | wc -l`
116157
if [ $count != 0 ]
117158
then
118159
include_path="${include_path} -I ${foldername}"
119160
fi
120161
done
121162

122-
echo "$1: Unsupported features\n" > "$file_name".txt
163+
echo "${project_dir}: Unsupported features\n" > "$file_name".txt
123164

124165
# Enumerate all the sub directories of ADA_INCLUDE_PATH
125166
for include_folder in `echo "$ADA_INCLUDE_PATH" | tr ':' ' '` ; do
126167
echo "Expanding $include_folder..."
127168
for foldername in $(find ${include_folder} -type d -name "*" | LC_ALL=posix sort); do
128-
count=`ls -1 ${foldername}/*.ads 2>/dev/null | wc -l`
169+
count=`ls -1 ${foldername}/*.${spec_ext} 2>/dev/null | wc -l`
129170
if [ $count != 0 ]
130171
then
131172
ADA_INCLUDE_PATH="${ADA_INCLUDE_PATH}:${foldername}"
132173
fi
133174
done
134175
done
135176

177+
if [ -n "${pragma_file}" ]; then
178+
pragma_file_opt="-gnatec=${pragma_file}"
179+
fi
180+
136181
# Before attempting to start compiling, make a clear log of the environment
137182
# we will be using:
138183
echo >&2 "-------------------------------------------------------"
@@ -147,10 +192,10 @@ echo >&2 "-------------------------------------------------------"
147192
# some other error that caused the compiler to exit with non-zero
148193
# exit code
149194
compile_error_occured=0
150-
for filename in $(find ${path} -name '*.adb' | LC_ALL=posix sort); do
195+
for filename in $(find ${path} -name "*.${body_ext}" | LC_ALL=posix sort); do
151196
printf "Compiling %s..." "${filename}" >&2
152197
echo "---------- COMPILING: $filename" >>"$file_name".txt
153-
"${GNAT2GOTO}" -gnatU ${include_path} "${filename}" > "$file_name".txt.compiling 2>&1
198+
"${GNAT2GOTO}" ${pragma_file_opt} -gnatU ${include_path} "${filename}" > "$file_name".txt.compiling 2>&1
154199
result=$?
155200
cat "$file_name".txt.compiling >> "$file_name".txt
156201

@@ -176,11 +221,15 @@ for filename in $(find ${path} -name '*.adb' | LC_ALL=posix sort); do
176221
fi
177222
done
178223

224+
# Need to use ${spec_ext} and ${body_ext} inside some regex's here,
225+
# so add any quoting necessary
226+
quoted_spec_ext=$(printf "%s" "${spec_ext}" | sed 's/\./\\./g')
227+
quoted_body_ext=$(printf "%s" "${body_ext}" | sed 's/\./\\./g')
179228
# This redacting system is really pretty crude...
180229
sed '/^\[/ d' < "$file_name".txt | \
181230
sed 's/"[^"][^"]*"/"REDACTED"/g' | \
182-
sed 's/[^ ][^ ]*\.adb/REDACTED.adb/g' | \
183-
sed 's/[^ ][^ ]*\.ads/REDACTED.ads/g' \
231+
sed "s/[^ ][^ ]*\.${quoted_body_ext}/REDACTED.${body_ext}/g" | \
232+
sed "s/[^ ][^ ]*\.${quoted_spec_ext}/REDACTED.${spec_ext}/g" \
184233
> "$file_name"_redacted.txt
185234

186235
# Collate and summarise unsupported features

experiments/rational-apex.adc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pragma Source_File_Name
2+
(Spec_File_Name => "*.1.ada", Dot_Replacement => "-");
3+
pragma Source_File_Name
4+
(Body_File_Name => "*.2.ada", Dot_Replacement => "-");

0 commit comments

Comments
 (0)