solana/programs/bpf/rust/do.sh

111 lines
2.2 KiB
Bash
Raw Normal View History

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
}
sdkDir=../../..
targetDir=../../target
profile=bpfel-unknown-unknown/release
2019-06-20 16:07:12 -07:00
perform_action() {
set -e
case "$1" in
build)
"$sdkDir"/sdk/bpf/rust/build.sh "$2"
2019-07-09 13:09:13 -07:00
;;
2019-06-20 16:07:12 -07:00
clean)
"$sdkDir"/sdk/bpf/rust/clean.sh "$2"
2019-07-09 13:09:13 -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
# - llvm-objdump
# - rustfilt
(
pwd
./do.sh build "$3"
cd "$3"
ls \
-la \
"$targetDir"/"$profile"/solana_bpf_rust_"${3%/}".so \
> "$targetDir"/"${3%/}"-dump-mangled.txt
2019-06-20 16:07:12 -07:00
greadelf \
-aW \
"$targetDir"/"$profile"/solana_bpf_rust_"${3%/}".so \
>> "$targetDir"/"${3%/}"-dump-mangled.txt
2019-06-20 16:07:12 -07:00
llvm-objdump \
-print-imm-hex \
--source \
--disassemble \
"$targetDir"/"$profile"/solana_bpf_rust_"${3%/}".so \
>> "$targetDir"/"${3%/}"-dump-mangled.txt
2019-06-20 16:07:12 -07:00
sed \
s/://g \
< "$targetDir"/"${3%/}"-dump-mangled.txt \
2019-06-20 16:07:12 -07:00
| rustfilt \
> "$targetDir"/"${3%/}"-dump.txt
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
for project in */ ; do
perform_action "$1" "$PWD/$project" "$project"
done
else
# Build requested project
perform_action "$1" "$PWD/$2" "$2"
fi