Skip to content

Commit d75897c

Browse files
authored
Merge pull request #1331 from vvbandeira/make-issue
Refactor generate-vars.sh, revert changes to file paths in variables
2 parents 0f56a59 + 4f70508 commit d75897c

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

flow/util/generate-vars.sh

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,58 @@
11
#!/bin/bash
22
set -euo pipefail
33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
FLOW_ROOT=$(realpath "${FLOW_HOME}")
5+
ORFS_ROOT=$(realpath "${FLOW_HOME}/../")
46

57
# 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"
8+
EXCLUDED_VARS="MAKE|MAKEFLAGS|PERL5LIB|QT_QPA_PLATFORM"
9+
EXCLUDED_VARS+="|RESULTS_ODB|PUBLIC|ISSUE_SCRIPTS"
10+
EXCLUDED_VARS+="|HOME|PWD|MAIL|SHELL|NPROC|NUM_CORES"
1211
EXCLUDED_VARS+="|UNSET_VARIABLES_NAMES|do-step|get_variables|do-copy"
1312

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
13+
EXCLUDED_PATTERNS="_EXE$|PATH$|_CMD$|\."
14+
15+
while read -r VAR; do
16+
if [[ ${VAR} != *"="* ]] ; then
17+
# skip variables that do not have an equal sign
18+
# they are invalid in shell
19+
continue
20+
fi
21+
name="${VAR%=*}"
22+
value="${VAR#*=}"
23+
if [[ "${name}" =~ ^[[:digit:]] ]] ; then
24+
# skip if the name starts with a number
25+
# they are invalid in shell
2026
continue
2127
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")
28+
if [[ "${value}" == "''" ]]; then
29+
# avoid exporting empty variables as var=''''
30+
# instead export as var=''
31+
value=
32+
fi
33+
if [[ "${name}" == *"MAKEFILE"* ]] ; then
34+
# skip make variables
35+
continue
36+
fi
37+
if [[ "${name}" =~ ^(${EXCLUDED_VARS})$ ]] ; then
38+
# skip variables from the exclude list
39+
continue
40+
fi
41+
if [[ "${name}" =~ ${EXCLUDED_PATTERNS} ]] ; then
42+
# skip variables that match the exclude patterns
43+
continue
44+
fi
45+
if [[ ${value} == /* ]]; then
46+
# convert absolute paths if possible to use FLOW_HOME variable
47+
value=$(sed -e "s,${FLOW_ROOT},\${FLOW_HOME},g" <<< "${value}")
48+
value=$(sed -e "s,${ORFS_ROOT},\${FLOW_HOME}/\.\.,g" <<< "${value}")
3549
fi
3650
# 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;
51+
if [[ "${name}" == "GND_NETS_VOLTAGES" || "${name}" == "PWR_NETS_VOLTAGES" ]]; then
52+
echo "export ${name}='${value}'" >> $1.sh;
3953
else
40-
echo "export "${V%=*}"='"${rhs}"'" >> $1.sh;
54+
echo "export ${name}=\"${value}\"" >> $1.sh;
4155
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
56+
echo "set env(${name}) \"${value}\"" >> $1.tcl;
57+
echo "set env ${name} ${value}" >> $1.gdb;
58+
done <<< "$ISSUE_VARIABLES"

0 commit comments

Comments
 (0)