forked from hltcoe/concrete-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.bash
executable file
·116 lines (97 loc) · 2.73 KB
/
generate.bash
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
#!/bin/bash
#
# Copyright 2012-2017 Johns Hopkins University HLTCOE. All rights reserved.
# This software is released under the 2-clause BSD license.
# See LICENSE in the project root directory.
#
#
# THIS SCRIPT SHOULD ONLY BE RUN BY PACKAGE MAINTAINERS.
# If you are not a package maintainer, then you can safely ignore this
# script - all the information you need to use the Concrete-Python
# library can be found in README.md
#
# The Concrete-Thrift repository contains the .thrift definition
# files, but not the Python classes generated by the Thrift compiler.
# This repository (Concrete-Python) contains the Thrift-generated
# Python classes, but not the .thrift definition files.
#
# This script should be run whenever the .thrift definition files in the
# Concrete-Thrift repository are changed.
#
DEFAULT_CONCRETE_THRIFT_DIR=../concrete/thrift
DEFAULT_OUTPUT_DIR=concrete
print_usage() {
echo "Usage: $0 [--raw] [--output-dir OUTPUT-DIR]"
echo " [CONCRETE-THRIFT-DIR]"
echo " --raw: Just generate classes from thrift definitions"
echo " (do not apply our modifications)"
echo " --output-dir OUTPUT-DIR: Write output to OUTPUT_DIR instead of"
echo " $DEFAULT_OUTPUT_DIR"
}
#
# Parse command-line arguments
#
concrete_thrift_dir="$DEFAULT_CONCRETE_THRIFT_DIR"
raw=false
output_dir="$DEFAULT_OUTPUT_DIR"
num_pos_args=0
while [ $# -gt 0 ]
do
case "$1" in
--raw)
raw=true
;;
--output-dir)
shift
output_dir="$1"
;;
-h)
print_usage
exit 0
;;
--help)
print_usage
exit 0
;;
*)
if [ $num_pos_args -eq 0 ]
then
concrete_thrift_dir="$1"
num_pos_args=$(($num_pos_args + 1))
else
print_usage >&2
exit 1
fi
;;
esac
shift
done
set -e
echo 'Generating Python classes from thrift definitions...'
rm -rf gen-py
find $concrete_thrift_dir -name '*.thrift' -exec \
thrift --gen py:coding=utf-8 \
-I $concrete_thrift_dir {} \;
echo 'Deleting generated files we do not want...'
rm -f gen-py/concrete/__init__.py
echo "Removing previously generated directories from $output_dir/..."
for f in "$output_dir/"*
do
if [ -d "$f" -a "$f" != "$output_dir/util" ]
then
rm -rf "$f"
fi
done
echo "Copying newly generated classes to $output_dir/..."
cp -a gen-py/concrete/* "$output_dir/"
if ! $raw
then
echo 'Applying our modifications to generated classes...'
for P in patches/*.patch
do
patch -p1 < $P
done
fi
echo 'Cleaning up...'
rm -rf gen-py
echo 'Done.'