Skip to content

Commit 302a8a2

Browse files
committed
build: make InfiniCCL root exports idempotent
- add a helper to update or append `.bashrc` exports - update `INFINICCL_ROOT` and `InfiniCCL_ROOT` based on `.bashrc` contents
1 parent e53810e commit 302a8a2

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

‎scripts/build.sh‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ DEFAULT_INSTALL_PATH="$HOME/.infini"
1212
INSTALL_PREFIX="${INSTALL_PREFIX:-$DEFAULT_INSTALL_PATH}"
1313
BUILD_DIR="${BUILD_DIR:-build}"
1414

15+
update_bashrc_export() {
16+
local name="$1"
17+
local value="$2"
18+
local escaped_value
19+
escaped_value=$(printf '%s' "$value" | sed 's/[\\&|]/\\&/g')
20+
21+
if grep -q "^export ${name}=" "$HOME/.bashrc"; then
22+
sed -i "s|^export ${name}=.*|export ${name}=\"$escaped_value\"|" "$HOME/.bashrc"
23+
else
24+
echo "export ${name}=\"$value\"" >> "$HOME/.bashrc"
25+
fi
26+
}
27+
1528
echo "========================================================"
1629
echo " Starting InfiniCCL Build"
1730
echo " Build Directory: $BUILD_DIR"
@@ -46,19 +59,14 @@ if ! grep -q "$BIN_PATH" "$HOME/.bashrc"; then
4659
echo "--> Updating ~/.bashrc with InfiniCCL paths..."
4760
echo "" >> "$HOME/.bashrc"
4861
echo "# InfiniCCL Paths" >> "$HOME/.bashrc"
49-
echo "export INFINICCL_ROOT=\"$PROJECT_ROOT\"" >> "$HOME/.bashrc"
50-
echo "export InfiniCCL_ROOT=\"$PROJECT_ROOT\"" >> "$HOME/.bashrc"
5162
echo "export PATH=\"$BIN_PATH:\$PATH\"" >> "$HOME/.bashrc"
5263
echo "export LD_LIBRARY_PATH=\"$LIB_PATH:\$LD_LIBRARY_PATH\"" >> "$HOME/.bashrc"
5364
echo "Successfully updated ~/.bashrc. Please run 'source ~/.bashrc' or restart your terminal."
5465
fi
5566

56-
# Update `INFINICCL_ROOT` if it already exists but points to a different project.
57-
if [[ -n "${INFINICCL_ROOT:-}" && "$INFINICCL_ROOT" != "$PROJECT_ROOT" ]]; then
58-
echo "--> Updating INFINICCL_ROOT in ~/.bashrc..."
59-
sed -i "s|^export INFINICCL_ROOT=.*|export INFINICCL_ROOT=\"$PROJECT_ROOT\"|" "$HOME/.bashrc"
60-
sed -i "s|^export InfiniCCL_ROOT=.*|export InfiniCCL_ROOT=\"$PROJECT_ROOT\"|" "$HOME/.bashrc"
61-
fi
67+
echo "--> Updating INFINICCL_ROOT in ~/.bashrc..."
68+
update_bashrc_export "INFINICCL_ROOT" "$PROJECT_ROOT"
69+
update_bashrc_export "InfiniCCL_ROOT" "$PROJECT_ROOT"
6270

6371
echo "========================================================"
6472
echo " Build and Install Finished!"

0 commit comments

Comments
 (0)