-
Notifications
You must be signed in to change notification settings - Fork 599
/
compile
executable file
·88 lines (71 loc) · 1.9 KB
/
compile
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
#!/bin/bash
# Compile the program
SOLC=$(which solc)
ARGS="--evm-version petersburg --optimize --optimize-runs 200 --pretty-json --overwrite"
OUTPUT_DIR="./output"
if [[ $1 == clean ]]; then
echo "Cleaning..."
rm -rf $OUTPUT_DIR
exit 0
fi
if [ ! -f "$SOLC" ]; then
echo "Please install solc first"
exit 1
fi
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p $OUTPUT_DIR
fi
function get_file_name() {
local file=$1
local file_name=$(basename $file)
local file_name=${file_name%.*}
echo $file_name
}
function compile_bin() {
local file=$1
local dir_name=$2
$SOLC $ARGS --bin -o $dir_name $file
}
function compile_abi() {
local file=$1
local dir_name=$2
$SOLC $ARGS --abi -o $dir_name $file
}
function compile_hex() {
local file=$1
local dir_name=$2
$SOLC $ARGS --bin-runtime -o $dir_name $file
}
function compile_storage_layout() {
local file=$1
local dir_name=$2
$SOLC $ARGS --storage-layout -o $dir_name $file
}
function compile_go() {
local file=$1
local dir_name=$2
local file_name=$3
local output_file="$dir_name/$file_name.go"
abigen --abi $dir_name/$file_name.abi --bin $dir_name/$file_name.bin --pkg $file_name --out $output_file
}
function compile_all() {
local file=$1
local filename=$(get_file_name $file)
local dir_name="$OUTPUT_DIR/$filename"
mkdir -p $dir_name
compile_bin $file $dir_name 1>/dev/null
compile_abi $file $dir_name 1>/dev/null
compile_hex $file $dir_name 1>/dev/null
compile_storage_layout $file $dir_name 1>/dev/null
compile_go $file $dir_name $filename 1>/dev/null
# Remove the files that not start with filename
find $dir_name -type f ! -name "$filename*" -delete
}
function compile_all_in_dir() {
local dir=$1
for file in $dir/*.sol; do
echo "Compiling [$file]..."
compile_all $file
done
}
compile_all_in_dir "./contracts"