From 8486c92593010cd2306d71645a7b7dc519bcb6e9 Mon Sep 17 00:00:00 2001 From: kareem Date: Tue, 18 Oct 2022 04:51:32 -0700 Subject: [PATCH 1/3] misc: scripts to prevent & fix bad mag paths + add pre commit githooks to get mag and maglefs + add scripts to fix bad use mag paths + add scripts to fix bad GDS_STRING mag paths --- .githooks/mag-pdkpath.bash | 21 +++++++++++++++++++++ .githooks/maglef-gdspath.bash | 22 ++++++++++++++++++++++ .githooks/pre-commit | 5 +++++ scripts/fix_mag.bash | 9 +++++++++ scripts/fix_maglef.bash | 10 ++++++++++ scripts/setup_githooks.bash | 3 +++ 6 files changed, 70 insertions(+) create mode 100755 .githooks/mag-pdkpath.bash create mode 100755 .githooks/maglef-gdspath.bash create mode 100755 .githooks/pre-commit create mode 100644 scripts/fix_mag.bash create mode 100644 scripts/fix_maglef.bash create mode 100644 scripts/setup_githooks.bash 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 100644 index 00000000..93a21ec2 --- /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#' $filename +done diff --git a/scripts/fix_maglef.bash b/scripts/fix_maglef.bash new file mode 100644 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 From e476c5b08e48a68c0fe1c4f4cd0282aff103ff02 Mon Sep 17 00:00:00 2001 From: kareem Date: Tue, 18 Oct 2022 04:54:54 -0700 Subject: [PATCH 2/3] make scripts executable --- scripts/fix_mag.bash | 0 scripts/fix_maglef.bash | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/fix_mag.bash mode change 100644 => 100755 scripts/fix_maglef.bash diff --git a/scripts/fix_mag.bash b/scripts/fix_mag.bash old mode 100644 new mode 100755 diff --git a/scripts/fix_maglef.bash b/scripts/fix_maglef.bash old mode 100644 new mode 100755 From e471874f0a84512f218621412b41edc1fb872883 Mon Sep 17 00:00:00 2001 From: kareem Date: Tue, 18 Oct 2022 04:55:54 -0700 Subject: [PATCH 3/3] get the right filepath in fix_mag --- scripts/fix_mag.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fix_mag.bash b/scripts/fix_mag.bash index 93a21ec2..33204a3c 100755 --- a/scripts/fix_mag.bash +++ b/scripts/fix_mag.bash @@ -5,5 +5,5 @@ 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#' $filename + 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