2019-06-20 16:07:12 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-06-21 12:26:17 -07:00
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
2019-06-20 16:07:12 -07:00
|
|
|
usage() {
|
2019-07-09 13:09:13 -07:00
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
Usage: do.sh action <project>
|
|
|
|
|
|
|
|
If relative_project_path is ommitted then action will
|
|
|
|
be performed on all projects
|
|
|
|
|
|
|
|
Supported actions:
|
|
|
|
build
|
|
|
|
clean
|
|
|
|
test
|
|
|
|
clippy
|
|
|
|
fmt
|
|
|
|
|
|
|
|
EOF
|
2019-06-20 16:07:12 -07:00
|
|
|
}
|
|
|
|
|
2019-09-16 11:11:33 -07:00
|
|
|
sdkDir=../../../sdk
|
|
|
|
targetDir="$PWD"/../target
|
2019-09-11 14:55:58 -07:00
|
|
|
profile=bpfel-unknown-unknown/release
|
|
|
|
|
2019-06-20 16:07:12 -07:00
|
|
|
perform_action() {
|
2019-09-17 10:21:22 -07:00
|
|
|
set -e
|
2019-06-20 16:07:12 -07:00
|
|
|
case "$1" in
|
|
|
|
build)
|
2019-10-16 15:35:16 -07:00
|
|
|
"$sdkDir"/bpf/rust/build.sh "$2"
|
2019-09-16 11:11:33 -07:00
|
|
|
|
2019-09-18 19:54:10 -07:00
|
|
|
so_path="$targetDir/$profile/"
|
|
|
|
so_name="solana_bpf_rust_${3%/}"
|
|
|
|
if [ -f "$so_path/${so_name}.so" ]; then
|
|
|
|
cp "$so_path/${so_name}.so" "$so_path/${so_name}_debug.so"
|
2019-10-16 15:35:16 -07:00
|
|
|
"$sdkDir/bpf/dependencies/llvm-native/bin/llvm-objcopy" --strip-all "$so_path/${so_name}.so" "$so_path/$so_name.so"
|
2019-09-16 11:11:33 -07:00
|
|
|
fi
|
2019-07-09 13:09:13 -07:00
|
|
|
;;
|
2019-06-20 16:07:12 -07:00
|
|
|
clean)
|
2019-09-18 19:54:10 -07:00
|
|
|
"$sdkDir"/bpf/rust/clean.sh "$2"
|
2019-07-09 13:09:13 -07:00
|
|
|
;;
|
2019-07-08 21:28:05 -07:00
|
|
|
test)
|
|
|
|
(
|
|
|
|
cd "$2"
|
|
|
|
echo "test $2"
|
|
|
|
cargo +nightly test
|
|
|
|
)
|
2019-07-09 13:09:13 -07:00
|
|
|
;;
|
2019-06-20 16:07:12 -07:00
|
|
|
clippy)
|
|
|
|
(
|
|
|
|
cd "$2"
|
|
|
|
echo "clippy $2"
|
|
|
|
cargo +nightly clippy
|
|
|
|
)
|
2019-07-09 13:09:13 -07:00
|
|
|
;;
|
2019-06-20 16:07:12 -07:00
|
|
|
fmt)
|
|
|
|
(
|
|
|
|
cd "$2"
|
|
|
|
echo "formatting $2"
|
|
|
|
cargo fmt
|
|
|
|
)
|
2019-07-09 13:09:13 -07:00
|
|
|
;;
|
2019-06-20 16:07:12 -07:00
|
|
|
dump)
|
|
|
|
# Dump depends on tools that are not installed by default and must be installed manually
|
|
|
|
# - greadelf
|
|
|
|
# - rustfilt
|
|
|
|
(
|
|
|
|
pwd
|
2019-10-16 15:35:16 -07:00
|
|
|
"$0" build "$3"
|
2019-06-20 16:07:12 -07:00
|
|
|
|
|
|
|
cd "$3"
|
2019-10-16 15:35:16 -07:00
|
|
|
so="$targetDir/$profile/solana_bpf_rust_${3%/}_debug.so"
|
|
|
|
dump="$targetDir/${3%/}-dump"
|
2019-06-20 16:07:12 -07:00
|
|
|
|
2019-09-16 11:11:33 -07:00
|
|
|
if [ -f "$so" ]; then
|
|
|
|
ls \
|
|
|
|
-la \
|
|
|
|
"$so" \
|
2019-09-18 19:54:10 -07:00
|
|
|
>"${dump}-mangled.txt"
|
2019-09-16 11:11:33 -07:00
|
|
|
greadelf \
|
|
|
|
-aW \
|
|
|
|
"$so" \
|
2019-09-18 19:54:10 -07:00
|
|
|
>>"${dump}-mangled.txt"
|
2019-10-16 15:35:16 -07:00
|
|
|
../"$sdkDir/bpf/dependencies/llvm-native/bin/llvm-objdump" \
|
2019-09-16 11:11:33 -07:00
|
|
|
-print-imm-hex \
|
|
|
|
--source \
|
|
|
|
--disassemble \
|
|
|
|
"$so" \
|
2019-09-18 19:54:10 -07:00
|
|
|
>>"${dump}-mangled.txt"
|
2019-09-16 11:11:33 -07:00
|
|
|
sed \
|
|
|
|
s/://g \
|
|
|
|
< "${dump}-mangled.txt" \
|
|
|
|
| rustfilt \
|
|
|
|
> "${dump}.txt"
|
2019-09-18 16:34:22 -07:00
|
|
|
else
|
|
|
|
echo "Warning: No dump created, cannot find: $so"
|
2019-09-16 11:11:33 -07:00
|
|
|
fi
|
2019-06-20 16:07:12 -07:00
|
|
|
)
|
|
|
|
;;
|
|
|
|
help)
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Error: Unknown command"
|
|
|
|
usage
|
|
|
|
exit
|
2019-07-09 13:09:13 -07:00
|
|
|
;;
|
2019-06-20 16:07:12 -07:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
|
|
# Build all projects
|
2019-09-18 19:54:10 -07:00
|
|
|
for project in */; do
|
2019-06-20 16:07:12 -07:00
|
|
|
perform_action "$1" "$PWD/$project" "$project"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# Build requested project
|
|
|
|
perform_action "$1" "$PWD/$2" "$2"
|
2019-09-18 16:34:22 -07:00
|
|
|
fi
|