Skip to content

Commit d0a17f7

Browse files
committed
Adjust generation of final zip file for manufacturing
Reduce lint and improve reproducibility manufacturing.sh now (maybe) passes shellcheck python code is flake8-compliant (with new tox.ini file) KiCad version ID in gbr, drl, csv output files is coerced to "5.1.x" if it starts in that form with 10 <= x <= 99. Tested that contents of the zip file match on two systems: 5.1.10 on Debian Buster, 5.1.12 on Debian Bullseye
1 parent 2ba2ee5 commit d0a17f7

4 files changed

Lines changed: 37 additions & 19 deletions

File tree

design/scripts/attrib_lint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def process_sch(f):
9696
value = None
9797
elif in_comp:
9898
if row[0] == "L":
99-
lib_ref = row[1]
100-
lib_ref_attrs = check_lib_ref(lib_ref)
99+
lib_ref = row[1]
100+
lib_ref_attrs = check_lib_ref(lib_ref)
101101
elif row[0] == "F" and len(row) > 2:
102102
rnum = int(row[1])
103103
if rnum == 0:

design/scripts/kicad_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def export_pos(self, dnf_parts=[], skip_th=True, verbose=False):
219219
## Unit = mm, Angle = deg.
220220
## Side : All
221221
# Ref Val Package PosX PosY Rot Side
222-
'''.format(desc(), __file__))
222+
'''.format(desc(), basename(__file__)))
223223

224224
for m in m_props:
225225
f.write('''\

design/scripts/manufacturing.sh

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ if ! test -r $KB; then
3939
fi
4040

4141
# Make sure we're running under bash so brace expansion works
42-
if ! test "`echo A{B,C}`" = "AB AC"; then
42+
if ! test "$(echo A{B,C})" = "AB AC"; then
4343
echo "Error, not running under bash"
4444
exit 1
4545
fi
4646

4747
if git diff | grep -q .; then
4848
spec=xxxxxxxx
4949
else
50-
spec=`git rev-parse --short=8 HEAD`
51-
SOURCE_DATE_EPOCH=`git log -1 --pretty=%ct`
50+
spec=$(git rev-parse --short=8 HEAD)
51+
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
5252
# see https://reproducible-builds.org/docs/source-date-epoch/
5353
fi
5454
zipfile=marble-${spec}-fab.zip
@@ -61,7 +61,7 @@ rm -f marble*.dat
6161
die=0
6262
for f in $A.{d356,xml}; do
6363
if ! test -r "$f"; then echo "missing: $f"; die=1;
64-
elif ! test "$f" = "`find \"$f\" -newer $A.kicad_pcb`"; then echo "stale: $f"; die=1; else
64+
elif ! test "$f" = "$(find $f -newer $A.kicad_pcb)"; then echo "stale: $f"; die=1; else
6565
echo "OK: $f"; fi
6666
done
6767
if test $die = 1; then echo Aborting; exit 1; fi
@@ -74,7 +74,7 @@ python3 scripts/kicad_exporter.py --layers 10 $A.kicad_pcb PCB_layers
7474
die=0
7575
for f in PCB_layers/$A-all.pos PCB_layers/$A-{B_Cu,B_Mask,B_Paste,B_SilkS,Edge_Cuts,F_Cu,F_Mask,F_Paste,F_SilkS,In{1,2,3,4,5,6,7,8,9,10}_Cu}.gbr PCB_layers/$A-{,N}PTH.drl; do
7676
if ! test -r "$f"; then echo "missing: $f"; die=1;
77-
elif ! test "$f" = "`find \"$f\" -newer $A.kicad_pcb`"; then echo "stale: $f"; die=1; else
77+
elif ! test "$f" = "$(find $f -newer $A.kicad_pcb)"; then echo "stale: $f"; die=1; else
7878
echo "OK: $f"; fi
7979
done
8080
if test $die = 1; then echo Aborting; exit 1; fi
@@ -90,7 +90,7 @@ bomfile=${A}_BOM.csv
9090
bomfile2=${A}_BOMa.csv
9191
echo "$bomfile"
9292
test -r "$bomfile"
93-
test "$bomfile" = "`find "$bomfile" -newer $A.xml`"
93+
test "$bomfile" = "$(find "$bomfile" -newer $A.xml)"
9494
echo generated files are OK
9595
echo starting post-processing
9696

@@ -113,14 +113,30 @@ rm -rf fab
113113
mkdir fab
114114
cd PCB_layers
115115
for f in *.gbr; do
116-
sed -e '/TF.CreationDate/d' -e '/Created by KiCad/s/ date .*/*/' < $f > ../fab/marble${f#$A}
116+
sed \
117+
-e '/TF.CreationDate/d' \
118+
-e '/Created by KiCad/s/ date .*/*/' \
119+
-e '/GenerationSoftware/s/Pcbnew,5\.1\.1.\*/Pcbnew,5.1.x\*/' \
120+
-e '/Created by KiCad/s/(PCBNEW 5\.1\.1.)/PCBNEW 5.1.x)/' \
121+
< "$f" > "../fab/marble${f#$A}"
117122
done
118123
for f in *.drl; do
119-
sed -e '/TF.CreationDate/d' -e '/ DRILL file /s/ date .*//' < $f > ../fab/marble${f#$A}
124+
sed \
125+
-e '/TF.CreationDate/d' \
126+
-e '/ DRILL file /s/ date .*//' \
127+
-e '/GenerationSoftware/s/Pcbnew,5\.1\.1.$/Pcbnew,5.1.x/' \
128+
-e '/DRILL file/s/{KiCad 5\.1\.1.}/{KiCad 5.1.x}/' \
129+
< "$f" > "../fab/marble${f#$A}"
120130
done
121131
cd ..
122-
sed -e '/Module positions/s/ - created on .*/ ###/' -e '/Module positions/s/ for .*/ ###/' < marble-xy.pos > fab/marble-xy.pos
123-
sed -e '/^BoM Date:/d' < "$bomfile2" > fab/marble-bom.csv
132+
sed \
133+
-e '/Module positions/s/ - created on .*/ ###/' \
134+
-e '/Module positions/s/ for .*/ ###/' \
135+
< marble-xy.pos > fab/marble-xy.pos
136+
sed \
137+
-e '/^BoM Date:/d' \
138+
-e '/KiCad Version/s/Eeschema 5\.1\.1.$/Eeschema 5.1.x/' \
139+
< "$bomfile2" > fab/marble-bom.csv
124140
mv marble-stuff.log fab/
125141
cp $A.d356 fab/marble-ipc-d-356.txt
126142
cp marble-stack.txt fab/marble-stack.txt
@@ -129,23 +145,23 @@ cp scripts/testpoint_map.gvp fab/testpoint_map.gvp
129145
mv testpoint_map.gbr fab/testpoint_map.gbr
130146

131147
# Fancy file integrity feature, presumably nobody besides Larry will care
132-
(cd fab && sha256sum * > marble-sha256.txt)
148+
(cd fab && sha256sum -- * > marble-sha256.txt)
133149
(cat ../docs/README_fab.txt; cd fab; sha256sum marble-sha256.txt) > fab/README_fab.txt
134150

135151
# Create the final zip file
136-
rm -f $zipfile
152+
rm -f "$zipfile"
137153
if test -n "$SOURCE_DATE_EPOCH"; then
138154
echo "Forcing timestamp $SOURCE_DATE_EPOCH"
139-
touch --date=@$SOURCE_DATE_EPOCH fab/*
140-
zip --latest-time $zipfile fab/*
155+
touch --date="@$SOURCE_DATE_EPOCH" fab/*
156+
zip --latest-time "$zipfile" fab/*
141157
else
142-
zip $zipfile fab/*
158+
zip "$zipfile" fab/*
143159
fi
144160

145161
if [ "$1" != "debug" ]; then # clean-up step, can skip when debugging
146162
rm -f marble*.dat marble-xy.pos $A.d356 $A.xml "$bomfile" "${bomfile}.tmp" "$bomfile2"
147163
rm -rf PCB_layers fab
148164
fi
149165
# marble-${spec}-fab.zip is the only generated file that should remain
150-
ls -l $zipfile
166+
ls -l "$zipfile"
151167
echo DONE

design/scripts/tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length=120

0 commit comments

Comments
 (0)