Merge pull request #290 from efabless/caravel_redesign-mag-guards

misc: scripts to prevent & fix bad mag paths
This commit is contained in:
Marwan Abbas 2022-10-18 17:13:14 +02:00 committed by GitHub
commit 7fa79aad37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 0 deletions

21
.githooks/mag-pdkpath.bash Executable file
View File

@ -0,0 +1,21 @@
#!/bin/env bash
staged=($(git diff --name-only --cached))
for file in ${staged[@]}
do
filename=$(basename -- "$file")
extension="${filename##*.}"
if [[ "$extension" = "mag" ]]; then
matches=($(sed -n 's/^use\b \+\S\+\ \+\S\+ \+\(\S\+\)/\1/p' $file))
for match in ${matches[@]}
do
if [[ "$(echo "$match" | sed -n '/PDKPATH\b\|PDK\b\|PDK_ROOT\b/p')" = "" ]]; then
echo "error: mag file $file has a <use> statment with a pdk path that's not PDKPATH|PDK|PDK_ROOT"
echo "the path used is: $match"
echo "you can use: 'git commit -n ..' to ignore this check but that's not recommended"
exit 1
fi
done
fi
done

22
.githooks/maglef-gdspath.bash Executable file
View File

@ -0,0 +1,22 @@
#!/bin/env bash
staged=($(git diff --name-only --cached))
for file in ${staged[@]}
do
filename=$(basename -- "$file")
extension="${filename##*.}"
filename_no_ext="${filename%%.*}"
if [[ "$extension" = "mag" ]]; then
matches=($(sed -E -n 's/string GDS_FILE +(\S+)/\1/p' $file))
for match in ${matches[@]}
do
if [[ "$(echo "$match" | sed -n "/..\/gds\/${filename_no_ext}/p")" = "" ]]; then
echo "error: maglef file($file) has string GDS_FILE reference that is not valid"
echo "the reference used is: $match"
echo "you can use: 'git commit -n ..' to ignore this check but that's not recommended"
exit 1
fi
done
fi
done

5
.githooks/pre-commit Executable file
View File

@ -0,0 +1,5 @@
#!/bin/env bash
./.githooks/mag-pdkpath.bash
./.githooks/maglef-gdspath.bash

9
scripts/fix_mag.bash Executable file
View File

@ -0,0 +1,9 @@
#!/bin/env bash
mag_path=$1
mags=$(find $mag_path -maxdepth 1 -type f -name '*.mag' )
for mag in $mags; do
filename=$(basename $mag)
sed -i -E 's#(use +sky130_\S+_sc_(\S+)__\S+ +\S+ +)\S+#\1$PDKPATH/libs.ref/sky130_fd_sc_\2/mag#' $mag_path/$filename
done

10
scripts/fix_maglef.bash Executable file
View File

@ -0,0 +1,10 @@
#!/bin/env bash
maglef_path=$1
maglefs=$(find $maglef_path -maxdepth 1 -type f -name '*.mag' )
for maglef in $maglefs; do
filename=$(basename $maglef)
filename_no_ext="${filename%%.*}"
sed -i -E "s#string GDS_FILE.*#string GDS_FILE ../gds/$filename_no_ext.gds#" $maglef_path/$filename
done

View File

@ -0,0 +1,3 @@
#!/bin/env bash
git config core.hooksPath ./.githooks