-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlcm_batch_processor.sh
More file actions
executable file
·238 lines (213 loc) · 5.48 KB
/
lcm_batch_processor.sh
File metadata and controls
executable file
·238 lines (213 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
#
# lcm_batch_processor.sh - Process all LCM files in a directory
#
# Usage: ./lcm_batch_processor.sh [options] <directory>
#
# Options:
# -c Generate C code
# -cpp Generate C++ code
# -j Generate Java code
# -p Generate Python code
# -l Generate Lua code
# -cs Generate C# code
# -o DIR Output directory for generated files
# -h Show this help message
#
# Example: ./lcm_batch_processor.sh -cpp -j ~/lcm_files/
# Default values
GENERATE_C=false
GENERATE_CPP=false
GENERATE_JAVA=false
GENERATE_PYTHON=false
GENERATE_LUA=false
GENERATE_CSHARP=false
OUTPUT_DIR=""
VERBOSE=false
# Function to display usage
show_help() {
echo "Usage: $0 [options] <directory>"
echo "Process all LCM files in a directory using lcm-gen"
echo ""
echo "Options:"
echo " -c Generate C code"
echo " -cpp Generate C++ code"
echo " -j Generate Java code"
echo " -p Generate Python code"
echo " -l Generate Lua code"
echo " -cs Generate C# code"
echo " -o DIR Output directory for generated files"
echo " -v Verbose output"
echo " -h Show this help message"
echo ""
echo "Example: $0 -cpp -j ~/lcm_files/"
exit 0
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-c)
GENERATE_C=true
shift
;;
-cpp)
GENERATE_CPP=true
shift
;;
-j)
GENERATE_JAVA=true
shift
;;
-p)
GENERATE_PYTHON=true
shift
;;
-l)
GENERATE_LUA=true
shift
;;
-cs)
GENERATE_CSHARP=true
shift
;;
-o)
shift
if [[ $# -gt 0 ]]; then
OUTPUT_DIR="$1"
shift
else
echo "Error: Output directory not specified"
exit 1
fi
;;
-v)
VERBOSE=true
shift
;;
-h|--help)
show_help
;;
*)
DIRECTORY="$1"
shift
;;
esac
done
# Check if lcm-gen is installed
# if ! command -v lcm-gen &> /dev/null; then
# echo "Error: lcm-gen command not found"
# echo "Please install LCM first: https://lcm-proj.github.io/"
# exit 1
# fi
# Check if a directory was specified
if [ -z "$DIRECTORY" ]; then
echo "Error: No directory specified"
show_help
fi
# Check if the directory exists
if [ ! -d "$DIRECTORY" ]; then
echo "Error: Directory '$DIRECTORY' does not exist"
exit 1
fi
# Check if at least one language option was selected
if ! $GENERATE_C && ! $GENERATE_CPP && ! $GENERATE_JAVA && ! $GENERATE_PYTHON && ! $GENERATE_LUA && ! $GENERATE_CSHARP; then
echo "Error: No language specified, at least one of -c, -cpp, -j, -p, -l, or -cs must be provided"
exit 1
fi
# Create output directory if specified and doesn't exist
if [ -n "$OUTPUT_DIR" ] && [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR"
if [ $? -ne 0 ]; then
echo "Error: Failed to create output directory '$OUTPUT_DIR'"
exit 1
fi
echo "Created output directory: $OUTPUT_DIR"
fi
# Build lcm-gen command base
LCM_GEN_CMD="./lcm-gen --lazy"
# Set output directory for each language if specified
if [ -n "$OUTPUT_DIR" ]; then
if $GENERATE_C; then
C_OPTIONS="--c-cpath $OUTPUT_DIR --c-hpath $OUTPUT_DIR"
fi
if $GENERATE_CPP; then
CPP_OPTIONS="--cpp-hpath $OUTPUT_DIR"
fi
if $GENERATE_JAVA; then
JAVA_OPTIONS="--jpath $OUTPUT_DIR"
fi
if $GENERATE_PYTHON; then
PYTHON_OPTIONS="--ppath $OUTPUT_DIR"
fi
if $GENERATE_LUA; then
LUA_OPTIONS="--lpath $OUTPUT_DIR"
fi
if $GENERATE_CSHARP; then
CSHARP_OPTIONS="--csharp-path $OUTPUT_DIR"
fi
fi
# Function to process a single LCM file
process_lcm_file() {
local lcm_file="$1"
local cmd="$LCM_GEN_CMD"
if $GENERATE_C; then
cmd="$cmd -c $C_OPTIONS"
fi
if $GENERATE_CPP; then
cmd="$cmd --cpp $CPP_OPTIONS"
fi
if $GENERATE_JAVA; then
cmd="$cmd -j $JAVA_OPTIONS"
fi
if $GENERATE_PYTHON; then
cmd="$cmd -p $PYTHON_OPTIONS"
fi
if $GENERATE_LUA; then
cmd="$cmd -l $LUA_OPTIONS"
fi
if $GENERATE_CSHARP; then
cmd="$cmd --csharp $CSHARP_OPTIONS"
fi
cmd="$cmd $lcm_file"
if $VERBOSE; then
echo "Executing: $cmd"
fi
eval $cmd
local status=$?
if [ $status -eq 0 ]; then
echo "Successfully processed: $lcm_file"
else
echo "Error processing: $lcm_file (exit code: $status)"
fi
return $status
}
# Find all .lcm files and process them
echo "Searching for LCM files in '$DIRECTORY'..."
lcm_files=$(find "$DIRECTORY" -name "*.lcm" -type f)
lcm_count=$(echo "$lcm_files" | wc -l)
if [ -z "$lcm_files" ]; then
echo "No LCM files found in '$DIRECTORY'"
exit 1
fi
echo "Found $lcm_count LCM files to process"
# Process each LCM file
success_count=0
error_count=0
for lcm_file in $lcm_files; do
process_lcm_file "$lcm_file"
if [ $? -eq 0 ]; then
((success_count++))
else
((error_count++))
fi
done
# Print summary
echo ""
echo "Processing complete!"
echo " Total files: $lcm_count"
echo " Successfully processed: $success_count"
echo " Errors: $error_count"
if [ $error_count -gt 0 ]; then
exit 1
fi
exit 0