diff --git a/.githooks/mag-pdkpath.bash b/.githooks/mag-pdkpath.bash new file mode 100755 index 00000000..bc86f98f --- /dev/null +++ b/.githooks/mag-pdkpath.bash @@ -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 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 + diff --git a/.githooks/maglef-gdspath.bash b/.githooks/maglef-gdspath.bash new file mode 100755 index 00000000..87a2c1dc --- /dev/null +++ b/.githooks/maglef-gdspath.bash @@ -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 + diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 00000000..ee022512 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,5 @@ +#!/bin/env bash + +./.githooks/mag-pdkpath.bash +./.githooks/maglef-gdspath.bash + diff --git a/scripts/fix_mag.bash b/scripts/fix_mag.bash new file mode 100755 index 00000000..33204a3c --- /dev/null +++ b/scripts/fix_mag.bash @@ -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 diff --git a/scripts/fix_maglef.bash b/scripts/fix_maglef.bash new file mode 100755 index 00000000..733b86ed --- /dev/null +++ b/scripts/fix_maglef.bash @@ -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 diff --git a/scripts/setup_githooks.bash b/scripts/setup_githooks.bash new file mode 100644 index 00000000..39f78efe --- /dev/null +++ b/scripts/setup_githooks.bash @@ -0,0 +1,3 @@ +#!/bin/env bash + +git config core.hooksPath ./.githooks