Skip to content

Commit cb2af5c

Browse files
committed
[nix] fix VCS daidir write permission issue
Signed-off-by: Avimitin <[email protected]>
1 parent a578a38 commit cb2af5c

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

Diff for: templates/chisel/nix/gcd/vcs-wrapper.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!@shell@
2+
3+
_EXTRA_ARGS="$@"
4+
5+
if (( ${VERBOSE:-0} )); then
6+
set -x
7+
fi
8+
9+
_DATE_BIN=@dateBin@
10+
_VCS_SIM_BIN=@vcsSimBin@
11+
_VCS_SIM_DAIDIR=@vcsSimDaidir@
12+
_VCS_FHS_ENV=@vcsFhsEnv@
13+
14+
_NOW=$("$_DATE_BIN" "+%Y-%m-%d-%H-%M-%S")
15+
_GCD_SIM_RESULT_DIR=${GCD_SIM_RESULT_DIR:-"gcd-sim-result"}
16+
_CURRENT="$_GCD_SIM_RESULT_DIR"/all/"$_NOW"
17+
mkdir -p "$_CURRENT"
18+
ln -sf "all/$_NOW" "$_GCD_SIM_RESULT_DIR/result"
19+
20+
cp "$_VCS_SIM_BIN" "$_CURRENT/"
21+
cp -r "$_VCS_SIM_DAIDIR" "$_CURRENT/"
22+
23+
chmod -R +w "$_CURRENT"
24+
25+
pushd "$_CURRENT" >/dev/null
26+
27+
_emu_name=$(basename "$_VCS_SIM_BIN")
28+
_daidir=$(basename "$_VCS_SIM_DAIDIR")
29+
30+
export LD_LIBRARY_PATH="$PWD/$_daidir:$LD_LIBRARY_PATH"
31+
32+
"$_VCS_FHS_ENV" -c "./$_emu_name $_EXTRA_ARGS" &> >(tee vcs-emu-journal.log)
33+
34+
if (( ${DATA_ONLY:-0} )); then
35+
rm -f "./$_emu_name"
36+
fi
37+
38+
set -e _emu_name _daidir
39+
40+
popd >/dev/null
41+
42+
echo "VCS emulator finished, result saved in $_GCD_SIM_RESULT_DIR/result"

Diff for: templates/chisel/nix/gcd/vcs.nix

+12-10
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ stdenv.mkDerivation (finalAttr: {
5858
inherit rtl;
5959

6060
tests.simple-sim = runCommand "${binName}-test" { __noChroot = true; } ''
61-
# Combine stderr and stdout and redirect them to tee
62-
# So that we can have log saving to output and also printing to stdout
63-
${finalAttr.finalPackage}/bin/${binName} &> >(tee $out)
61+
export GCD_SIM_RESULT_DIR="$(mktemp -d)"
62+
export DATA_ONLY=1
63+
${finalAttr.finalPackage}/bin/${binName}
64+
65+
mkdir -p "$out"
66+
cp -vr "$GCD_SIM_RESULT_DIR"/result/* "$out/"
6467
'';
6568
};
6669

@@ -76,13 +79,12 @@ stdenv.mkDerivation (finalAttr: {
7679
cp ${binName} $out/lib
7780
cp -r ${binName}.daidir $out/lib
7881
79-
# We need to carefully handle string escape here, so don't use makeWrapper
80-
tee $out/bin/${binName} <<EOF
81-
#!${bash}/bin/bash
82-
export LD_LIBRARY_PATH="$out/lib/${binName}.daidir:\$LD_LIBRARY_PATH"
83-
_argv="\$@"
84-
${vcs-fhs-env}/bin/vcs-fhs-env -c "$out/lib/${binName} \$_argv"
85-
EOF
82+
substitute ${./vcs-wrapper.sh} $out/bin/${binName} \
83+
--subst-var-by shell "${bash}/bin/bash" \
84+
--subst-var-by dateBin "$(command -v date)" \
85+
--subst-var-by vcsSimBin "$out/lib/${binName}" \
86+
--subst-var-by vcsSimDaidir "$out/lib/${binName}.daidir" \
87+
--subst-var-by vcsFhsEnv "${vcs-fhs-env}/bin/vcs-fhs-env"
8688
chmod +x $out/bin/${binName}
8789
8890
runHook postInstall

0 commit comments

Comments
 (0)