-
Notifications
You must be signed in to change notification settings - Fork 6
/
Justfile
159 lines (132 loc) · 4.3 KB
/
Justfile
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
set dotenv-load
MODE := "release"
CFLAGS := "--release -Zbuild-std=core --target=msp430-none-elf"
TARGET := "target/msp430-none-elf/" + MODE + "/at2xt"
CLIPPY_LINTS := '-W clippy::if_not_else -W clippy::match_same_arms -W clippy::as_conversions \\
-W clippy::indexing_slicing -W clippy::let_underscore_must_use'
# -W clippy::integer_arithmetic -W clippy::integer_division'
# Build AT2XT.
timer:
cargo build {{CFLAGS}}
msp430-elf-objdump -Cd {{TARGET}} > {{TARGET}}.lst
msp430-elf-readelf -a --wide {{TARGET}} > {{TARGET}}.sym
msp430-elf-size {{TARGET}}
# Build AT2XT and extra artifacts.
timer-extra:
cargo rustc {{CFLAGS}} -- --emit=obj={{TARGET}}.o,llvm-ir={{TARGET}}.ll,asm={{TARGET}}.s
msp430-elf-objdump -Cd {{TARGET}} > {{TARGET}}.lst
msp430-elf-readelf -a --wide {{TARGET}} > {{TARGET}}.sym
msp430-elf-objdump -Cd {{TARGET}}.o > {{TARGET}}.o.lst
msp430-elf-readelf -a --wide {{TARGET}}.o > {{TARGET}}.reloc
msp430-elf-size {{TARGET}}
# Run clippy on AT2XT.
clippy:
cargo clippy {{CFLAGS}} -- {{CLIPPY_LINTS}}
# Run clippy on AT2XT- pedantic mode (many lints won't apply).
clippy-pedantic:
cargo clippy {{CFLAGS}} -- -W clippy::pedantic
# Combine with: just clippy-restriction 2>&1 | grep https:// | tr -s " " | sort | uniq?
# Run clippy on AT2XT- restriction mode (many lints won't apply).
clippy-restriction:
cargo clippy {{CFLAGS}} -- -W clippy::restriction
# Fix warnings in AT2XT.
fix:
cargo fix {{CFLAGS}}
# Fix warnings and attempt to apply clippy suggestions (nightly only).
fix-clippy:
cargo clippy --fix -Zunstable-options {{CFLAGS}}
# Format AT2XT source.
fmt:
cargo fmt
# Remove AT2XT and dependencies.
clean:
cargo clean
# Upload firmware to AT2XT board using MSP-EXP430G2.
prog:
mspdebug rf2500 "prog {{TARGET}}"
# Internal target for comparing the assembly output of two commits of AT2XT.
_diff-asm:
#!/bin/sh
set -e
export CARGO_TARGET_DIR=diff-asm/target
STAGING=diff-asm/staging
prepare() {
mkdir -p $CARGO_TARGET_DIR
mkdir $STAGING
}
# build name suffix
build() {
if [ $# -lt 1 ]; then
echo "Must supply artifact name to build."
exit 4
fi
if [ $# -lt 2 ]; then
SUFFIX=""
else
SUFFIX="-$2"
fi
FINAL_BINARY=$CARGO_TARGET_DIR/msp430-none-elf/release/$1
ARTIFACT_PREFIX=$STAGING/$1''$SUFFIX
cargo rustc --release --target=msp430-none-elf -- --emit=asm=$ARTIFACT_PREFIX.rs.lst,obj=$ARTIFACT_PREFIX.o || true
msp430-elf-objdump -Cd $FINAL_BINARY > $ARTIFACT_PREFIX.lst
msp430-elf-readelf -s --wide $FINAL_BINARY > $ARTIFACT_PREFIX.sym
msp430-elf-objdump -Cd $ARTIFACT_PREFIX.o > $ARTIFACT_PREFIX.o.lst
msp430-elf-readelf -r --wide $ARTIFACT_PREFIX.o > $ARTIFACT_PREFIX.reloc
msp430-elf-size $FINAL_BINARY > $ARTIFACT_PREFIX.size
cp $FINAL_BINARY $ARTIFACT_PREFIX
}
# commit_mode name commit1 commit2
commit_mode() {
if [ $# -lt 3 ]; then
echo "Must supply artifact name to build, and two commit ids."
exit 5
fi
echo "Running compare in commit mode."
git checkout $2
build $1
git checkout $3
build $1 1
git diff $2 $3 > $STAGING/$1''$SUFFIX.rs.diff || true
git checkout @{-2}
}
# stash_mode name
stash_mode() {
echo "Running compare in stash mode."
git stash
build $1
git checkout -b diff-asm
git stash pop
build $1 1
REV=`git rev-parse --short HEAD`
git commit -am "diff-asm target"
git diff @{-1} diff-asm -- > $STAGING/$1''$SUFFIX.rs.diff || true
REV_NEW=`git rev-parse --short HEAD`
DIFF_ASM_DIR_NAME=diff-asm/$REV-$REV_NEW
git reset HEAD~1
git checkout -
git branch -D diff-asm
}
finalize() {
mkdir -p $DIFF_ASM_DIR_NAME
mv $STAGING/* $DIFF_ASM_DIR_NAME
rmdir $STAGING
}
prepare
if [ $# -eq 0 ]; then
if git diff --quiet; then
echo "No changes to compare!"
exit 1
fi
stash_mode at2xt
elif [ $# -eq 2 ]; then
if ! git diff --quiet; then
echo "Tree has modified content!"
exit 2
fi
DIFF_ASM_DIR_NAME=diff-asm/`git rev-parse --short $1`-`git rev-parse --short $2`
commit_mode at2xt $1 $2
else
echo "Usage: $0 [commit1 commit2]"
exit 3
fi
finalize