Skip to content

Commit 987ddf4

Browse files
committed
refactored yosys install so it's more modular and added verification step to print out current versions of the yosys suite
Signed-off-by: Sombrio <[email protected]>
1 parent b919b8f commit 987ddf4

File tree

1 file changed

+104
-87
lines changed

1 file changed

+104
-87
lines changed

etc/DependencyInstaller.sh

Lines changed: 104 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -11,103 +11,120 @@ _versionCompare() {
1111
test $a "$2" $b
1212
}
1313

14-
_equivalenceDeps() {
15-
yosysVersion=v0.55
16-
local yosys_reinstalled=false
17-
18-
# yosys
19-
yosysPrefix=${PREFIX:-"/usr/local"}
20-
yosysInstalledVersion="none"
21-
if command -v yosys &> /dev/null && command -v yosys-config &> /dev/null; then
22-
yosysInstalledVersion=$(yosys -V | head -n 1 | awk '{print $2}')
23-
fi
24-
if [[ "${yosysInstalledVersion}" != "${yosysVersion#v}" ]]; then
25-
yosys_reinstalled=true
26-
(
27-
echo "Installing yosys ${yosysVersion} (found: ${yosysInstalledVersion})"
28-
cd "${baseDir}"
29-
git clone --depth=1 -b "${yosysVersion}" --recursive https://github.com/YosysHQ/yosys
30-
cd yosys
31-
# use of no-register flag is required for some compilers,
32-
# e.g., gcc and clang from RHEL8
33-
make -j ${numThreads} PREFIX="${yosysPrefix}" ABC_ARCHFLAGS=-Wno-register
34-
make install
35-
)
14+
# --- Yosys Suite Installation ---
15+
16+
# Single Source of Truth: The target version for all tools.
17+
readonly YOSYS_SUITE_VERSION="v0.55"
18+
19+
# Tool Configuration: Associative array mapping tool names to their git repos.
20+
declare -A YOSYS_SUITE_TOOLS=(
21+
[yosys]="https://github.com/YosysHQ/yosys"
22+
[eqy]="https://github.com/YosysHQ/eqy"
23+
[sby]="https://github.com/YosysHQ/sby"
24+
)
25+
26+
# Function to get the installed version of a yosys suite tool.
27+
_get_yosys_tool_version() {
28+
local tool_name="$1"
29+
local installed_version="none"
30+
31+
# Check PATH for the tool, but also the local PREFIX, since it may not be in the PATH yet.
32+
local tool_path
33+
if command -v "${tool_name}" &> /dev/null; then
34+
tool_path=$(command -v "${tool_name}")
35+
elif [[ -n "${PREFIX:-}" && -x "${PREFIX}/bin/${tool_name}" ]]; then
36+
tool_path="${PREFIX}/bin/${tool_name}"
3637
else
37-
echo "yosys ${yosysVersion} already installed."
38+
echo "none"
39+
return
3840
fi
3941

40-
# eqy
41-
eqyPrefix=${PREFIX:-"/usr/local"}
42-
eqyInstalledVersion="none"
43-
install_eqy=false
44-
if ! command -v eqy &> /dev/null; then
45-
install_eqy=true
46-
eqyInstalledVersion="not found"
47-
else
48-
# EQY returns "EQY vX.Y"
49-
eqyInstalledVersion=$(eqy --version 2>/dev/null | awk '{print $2}' | sed 's/v//')
50-
if [[ "${eqyInstalledVersion}" != "${yosysVersion#v}" ]]; then
51-
install_eqy=true
52-
fi
53-
fi
42+
case "${tool_name}" in
43+
yosys)
44+
installed_version=$("${tool_path}" --version | head -n 1 | awk '{print $2}')
45+
;;
46+
eqy)
47+
installed_version=$("${tool_path}" --version 2>/dev/null | awk '{print $2}' | sed 's/v//')
48+
;;
49+
sby)
50+
installed_version=$("${tool_path}" --version 2>/dev/null | awk '{print $2}' | sed 's/v//')
51+
;;
52+
*)
53+
echo "none"
54+
;;
55+
esac
56+
echo "${installed_version}"
57+
}
5458

55-
if [[ "${yosys_reinstalled}" == "true" ]]; then
56-
install_eqy=true
57-
fi
59+
_install_yosys_tool() {
60+
local tool_name="$1"
61+
local tool_repo="$2"
62+
local target_version_str="${YOSYS_SUITE_VERSION#v}"
63+
local tool_prefix="${PREFIX:-/usr/local}"
5864

59-
if [[ "${install_eqy}" == "true" ]]; then
60-
(
61-
if [[ "${yosys_reinstalled}" == "true" ]]; then
62-
echo "Re-installing eqy because yosys was updated."
63-
else
64-
echo "Installing eqy ${yosysVersion} (found: ${eqyInstalledVersion})"
65-
fi
66-
cd "${baseDir}"
67-
git clone --depth=1 -b "${yosysVersion}" https://github.com/YosysHQ/eqy
68-
cd eqy
69-
export PATH="${yosysPrefix}/bin:${PATH}"
70-
make -j ${numThreads} PREFIX="${eqyPrefix}"
71-
make install PREFIX="${eqyPrefix}" YOSYS_RELEASE_VERSION="EQY v${yosysVersion#v}"
72-
)
73-
else
74-
echo "eqy ${yosysVersion} already installed."
65+
echo "--- Checking ${tool_name} ---"
66+
local installed_version
67+
installed_version=$(_get_yosys_tool_version "${tool_name}")
68+
69+
if [[ "${installed_version}" == "${target_version_str}" ]]; then
70+
echo "${tool_name} version ${installed_version} is already up-to-date."
71+
return
7572
fi
7673

77-
# sby
78-
sbyPrefix=${PREFIX:-"/usr/local"}
79-
sbyInstalledVersion="none"
80-
install_sby=false
81-
if ! command -v sby &> /dev/null; then
82-
install_sby=true
83-
sbyInstalledVersion="not found"
84-
else
85-
sbyInstalledVersion=$(sby --version 2>/dev/null | awk '{print $2}')
86-
if [[ "${sbyInstalledVersion}" != "${yosysVersion#v}" ]]; then
87-
install_sby=true
74+
echo "Installing ${tool_name} ${YOSYS_SUITE_VERSION} (found: ${installed_version})."
75+
76+
( # Run in a subshell to isolate directory changes
77+
cd "${baseDir}"
78+
echo "Cloning ${tool_name} from ${tool_repo}..."
79+
80+
local clone_args=("--depth=1" "-b" "${YOSYS_SUITE_VERSION}")
81+
if [[ "${tool_name}" == "yosys" || "${tool_name}" == "sby" ]]; then
82+
clone_args+=("--recursive")
8883
fi
89-
fi
9084

91-
if [[ "${yosys_reinstalled}" == "true" ]]; then
92-
install_sby=true
93-
fi
85+
git clone "${clone_args[@]}" "${tool_repo}" "${tool_name}"
86+
cd "${tool_name}"
87+
88+
echo "Building and installing ${tool_name}..."
89+
export PATH="${tool_prefix}/bin:${PATH}"
90+
91+
case "${tool_name}" in
92+
yosys)
93+
make -j "${numThreads}" PREFIX="${tool_prefix}" ABC_ARCHFLAGS=-Wno-register
94+
make install PREFIX="${tool_prefix}"
95+
;;
96+
eqy)
97+
make -j "${numThreads}" PREFIX="${tool_prefix}"
98+
make install PREFIX="${tool_prefix}" YOSYS_RELEASE_VERSION="EQY ${YOSYS_SUITE_VERSION}"
99+
;;
100+
sby)
101+
make -j "${numThreads}" PREFIX="${tool_prefix}" install
102+
;;
103+
esac
104+
echo "${tool_name} installation complete."
105+
) || {
106+
echo "ERROR: Failed to build or install ${tool_name}." >&2
107+
exit 1
108+
}
109+
}
94110

95-
if [[ "${install_sby}" == "true" ]]; then
96-
(
97-
if [[ "${yosys_reinstalled}" == "true" ]]; then
98-
echo "Re-installing sby because yosys was updated."
99-
else
100-
echo "Installing sby ${yosysVersion} (found: ${sbyInstalledVersion})"
101-
fi
102-
cd "${baseDir}"
103-
git clone --depth=1 -b "${yosysVersion}" --recursive https://github.com/YosysHQ/sby
104-
cd sby
105-
export PATH="${eqyPrefix}/bin:${PATH}"
106-
make -j ${numThreads} PREFIX="${sbyPrefix}" install
107-
)
108-
else
109-
echo "sby ${yosysVersion} already installed."
110-
fi
111+
_equivalenceDeps() {
112+
echo "Installing Yosys tool suite..."
113+
echo "Target version for all tools: ${YOSYS_SUITE_VERSION}"
114+
local tool_prefix="${PREFIX:-/usr/local}"
115+
echo "Installation prefix: ${tool_prefix}"
116+
117+
# Iterate over the tools and install them.
118+
for tool in "${!YOSYS_SUITE_TOOLS[@]}"; do
119+
_install_yosys_tool "${tool}" "${YOSYS_SUITE_TOOLS[$tool]}"
120+
done
121+
122+
echo "--- Verification ---"
123+
"${tool_prefix}/bin/yosys" --version
124+
"${tool_prefix}/bin/eqy" --version
125+
"${tool_prefix}/bin/sby" --version
126+
echo "--------------------"
127+
echo "Yosys tool suite installation finished successfully."
111128
}
112129

113130
_installCommonDev() {

0 commit comments

Comments
 (0)