Skip to content

Commit ed48b6e

Browse files
committed
util: refactor generate-vars.sh
~better naming +added excluded patterns -removed file path modifications Signed-off-by: Vitor Bandeira <[email protected]>
1 parent c5fbdc2 commit ed48b6e

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

flow/util/generate-vars.sh

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,55 @@ set -euo pipefail
33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
# exclude system and CI variables
6-
EXCLUDED_VARS="MAKE|PYTHONPATH|PKG_CONFIG_PATH|PERL5LIB|PCP_DIR|PATH|MANPATH"
7-
EXCLUDED_VARS+="|LD_LIBRARY_PATH|INFOPATH|HOME|PWD|MAIL|QT_QPA_PLATFORM"
8-
EXCLUDED_VARS+="|OPENROAD_CMD|OPENROAD_GUI_CMD|OPENROAD_NO_EXIT_CMD"
9-
EXCLUDED_VARS+="|LSORACLE_CMD|YOSYS_CMD|TIME_CMD|STDBUF_CMD"
10-
EXCLUDED_VARS+="|SHELL|OPENROAD_EXE|YOSYS_EXE"
11-
EXCLUDED_VARS+="|NPROC|NUM_CORES|PUBLIC|CURDIR|ISSUE_SCRIPTS|MAKEFLAGS"
6+
EXCLUDED_VARS="MAKE|PERL5LIB"
7+
EXCLUDED_VARS+="|HOME|PWD|MAIL|QT_QPA_PLATFORM"
8+
EXCLUDED_VARS+="|SHELL|OPENROAD_EXE|YOSYS_EXE|RESULTS_ODB"
9+
EXCLUDED_VARS+="|NPROC|NUM_CORES|PUBLIC|ISSUE_SCRIPTS|MAKEFLAGS"
1210
EXCLUDED_VARS+="|UNSET_VARIABLES_NAMES|do-step|get_variables|do-copy"
1311

14-
# get the root directory of the Git repository
15-
GIT_ROOT=$(git rev-parse --show-toplevel)
16-
FLOW_ROOT=${GIT_ROOT}/flow
17-
printf '%s\n' "$ISSUE_VARIABLES" | while read -r V;
18-
do
19-
if [[ ${V%=*} =~ ^[[:digit:]] || ${V} != *"="* || -z ${V#*=} || ${V%=*} == *"MAKEFILE"* || ${V%=*} =~ ^(${EXCLUDED_VARS})$ ]] ; then
12+
EXCLUDED_PATTERNS="_EXE$|PATH$|_DIR$|_CMD$|^\."
13+
14+
while read -r VAR; do
15+
if [[ ${VAR} != *"="* ]] ; then
16+
# skip variables that do not have an equal sign
17+
# they are invalid in shell
18+
continue
19+
fi
20+
name="${VAR%=*}"
21+
value="${VAR#*=}"
22+
if [[ "${name}" =~ ^[[:digit:]] ]] ; then
23+
# skip if the name starts with a number
24+
# they are invalid in shell
2025
continue
2126
fi
22-
rhs=`sed -e 's/^"//' -e 's/"$//' <<<"${V#*=}"`
23-
# handle absolute paths
24-
if [[ "${rhs}" == /* ]]; then
25-
if [[ ! -e "${rhs}" ]]; then
26-
echo "Skiping path not found ${V}"
27-
continue
28-
fi
29-
if [[ "${rhs}" != "${GIT_ROOT}"* ]]; then
30-
echo "Skiping file outside git ${V}"
31-
continue
32-
fi
33-
# convert the absolute path to a path relative to the flow dir
34-
rhs=$(realpath --relative-to="$FLOW_ROOT" "$rhs")
27+
if [[ "${value}" == "''" ]]; then
28+
# avoid exporting empty variables as var=''''
29+
# instead export as var=''
30+
value=
31+
fi
32+
if [[ "${name}" == *"MAKEFILE"* ]] ; then
33+
# skip make variables
34+
continue
35+
fi
36+
if [[ "${name}" =~ ^(${EXCLUDED_VARS})$ ]] ; then
37+
# skip variables from the exclude list
38+
continue
39+
fi
40+
if [[ "${name}" =~ ${EXCLUDED_PATTERNS} ]] ; then
41+
# skip variables that match the exclude patterns
42+
continue
43+
fi
44+
if [[ ${value} == *"\""* ]]; then
45+
# remove double quotes from value to avoid syntax issues on final
46+
# generated script
47+
value=$(sed -e 's/^"//' -e 's/"$//' <<< "${value}")
3548
fi
3649
# handle special case where the variable needs to be splitted in Tcl code
37-
if [[ "${V%=*}" == "GND_NETS_VOLTAGES" || "${V%=*}" == "PWR_NETS_VOLTAGES" ]]; then
38-
echo "export "${V%=*}"='"\"${rhs}"\"'" >> $1.sh;
50+
if [[ "${name}" == "GND_NETS_VOLTAGES" || "${name}" == "PWR_NETS_VOLTAGES" ]]; then
51+
echo "export ${name}='\"${value}\"'" >> $1.sh;
3952
else
40-
echo "export "${V%=*}"='"${rhs}"'" >> $1.sh;
53+
echo "export ${name}=\"${value}\"" >> $1.sh;
4154
fi
42-
echo "set env("${V%=*}") \""${rhs}\""" >> $1.tcl;
43-
echo "set env "${V%=*}" "${rhs}"" >> $1.gdb;
44-
done
45-
46-
# remove variables starting with a dot
47-
sed -i -e '/export \./d' $1.sh
48-
sed -i -e '/set env(\./d' $1.tcl
49-
sed -i -e '/set env \./d' $1.gdb
55+
echo "set env(${name}) \"${value}\"" >> $1.tcl;
56+
echo "set env ${name} ${value}" >> $1.gdb;
57+
done <<< "$ISSUE_VARIABLES"

0 commit comments

Comments
 (0)