1
+ #! /bin/bash
2
+
3
+ : '
4
+ This script performs validation and compilation of Godel script files (.gs and .gdl).
5
+
6
+ Usage:
7
+ ./check_gdl.sh <directory>
8
+
9
+ Arguments:
10
+ <directory> The directory to scan for Godel script files. The script will
11
+ search for .gs and .gdl files to compile and validate.
12
+
13
+ Description:
14
+ The script does the following:
15
+ - Validates that a directory is provided as an argument.
16
+ - Changes to the specified directory.
17
+ - Finds all .gs and .gdl files within the specified directory (excluding specific paths).
18
+ - For each located library directory, it concatenates the library files and compiles them.
19
+ - For each script file, it runs a separate compilation process and checks for errors.
20
+ - Reports any compilation errors and terminates execution if an error occurs.
21
+ - If no errors occur, it reports successful compilation for each file.
22
+
23
+ Requires:
24
+ - The "sparrow-cli" tool must be installed and available under the user"s home directory.
25
+ - Command "find" available on the system (commonly available on Unix-like systems).
26
+ - Command "mktemp" available on the system for creating temporary files.
27
+ - Command "date" available on the system for time measurements.
28
+
29
+ Author: AntGroup
30
+ Date: 2024-01-16
31
+ Version: 1.0
32
+
33
+ '
34
+
35
+ set +x
36
+
37
+ # Check if the parameter is empty
38
+ if [ -z " $1 " ]; then
39
+ echo " Please provide a directory as an argument"
40
+ exit 1
41
+ fi
42
+
43
+ # Change to the directory
44
+ cd " $1 " || exit 1
45
+
46
+ sparrow_godel_script=" $HOME /sparrow-cli/sparrow-cli/godel-script/usr/bin/godel"
47
+ sparrow_lib_1_0=" $HOME /sparrow-cli/sparrow-cli/lib-1.0"
48
+
49
+ # Define get_files function
50
+ get_files () {
51
+ find " $1 " -type f \( -name " *$2 " \) -print
52
+ }
53
+
54
+ # Define rebuild_lib function
55
+ rebuild_lib () {
56
+ local lib_path=" $1 "
57
+ local lib=" $2 "
58
+ local gdl_list=()
59
+ local output_file
60
+ local tmp_out
61
+ local start_time
62
+ local end_time
63
+ local elapsed_time
64
+
65
+ gdl_list+=($( get_files " $lib_path " " .gs" ) )
66
+ gdl_list+=($( get_files " $lib_path " " .gdl" ) )
67
+
68
+ output_file=$( mktemp " tempfile.XXXXXX.gdl" )
69
+ trap ' rm -f "$output_file"' EXIT
70
+
71
+ echo " // script" > " $output_file "
72
+ for file_name in " ${gdl_list[@]} " ; do
73
+ cat " $file_name " >> " $output_file "
74
+ done
75
+
76
+ tmp_out=$( mktemp " tempfile.XXXXXX.gdl" )
77
+ trap ' rm -f "$tmp_out"' EXIT
78
+
79
+ start_time=$( date +%s%3N)
80
+ if ! " $sparrow_godel_script " " $output_file " -o " $tmp_out " ; then
81
+ echo " $lib_path lib compile error, please check it yourself" >&2
82
+ exit 1
83
+ fi
84
+
85
+ mv " $tmp_out " " $sparrow_lib_1_0 /coref.$lib .gdl"
86
+
87
+ end_time=$( date +%s%3N)
88
+ elapsed_time=$(( end_time - start_time))
89
+ echo " $lib_path lib compile success time: ${elapsed_time} milliseconds" >&2
90
+ }
91
+
92
+ # Define get_language function
93
+ get_language () {
94
+ local dir=" $1 "
95
+ local dirname
96
+ local language
97
+
98
+ dirname=$( dirname " $dir " )
99
+ language=$( basename " $dirname " )
100
+ echo " $language "
101
+ }
102
+
103
+ # Get libs directories
104
+ directories=($( find " $PWD " -type d \( -path " $PWD /language/*/lib" -o -path " $PWD /language/*/libs" \) -print) )
105
+
106
+ # Get libs
107
+ for dir in " ${directories[@]} " ; do
108
+ lang=$( get_language " $dir " )
109
+ echo " Building lib for $lang ..."
110
+ rebuild_lib " $dir " " $lang "
111
+ done
112
+
113
+ # Define get_target_files function
114
+ get_target_files () {
115
+ find " $1 " -type f \( -name " *.gs" -o -name " *.gdl" \) -not -name " tempfile.*.gdl" -not -path " $1 /language/*/lib/*"
116
+ }
117
+
118
+ files=$( get_target_files " $PWD " )
119
+
120
+ # Iterate over the files
121
+ for file in $files ; do
122
+ output=$(( "$sparrow_godel_script " "$file " - p "$sparrow_lib_1_0 " - o "${file% .* } _tmp.gdl") 2 >& 1 )
123
+
124
+ # Check if the output is not empty
125
+ if [ -n "$output " ]; then
126
+ echo "The file $file produced the following output:"
127
+ echo "$output "
128
+ echo "Please check if this file is a godel script (.gs) or a godel 1 .0 script (.gdl)"
129
+ exit 1
130
+ else
131
+ echo "$file build successful"
132
+ fi
133
+
134
+ # Remove temporary file
135
+ rm -f "${file% .* } _tmp.gdl"
136
+ done
137
+
138
+ exit 0
0 commit comments