Skip to content

Commit 86649bc

Browse files
bazel: Fix missing parameter test using standard bash conventions
This addresses oharboe's review comment by replacing non-standard parameter absence checks with standard `[ -n "$1" ]` bash syntax, and clearly restoring the ORFS-agnostic standalone target evaluation. Signed-off-by: alokkumardalei-wq <alokkumardalei2@gmail.com>
1 parent 408e057 commit 86649bc

4 files changed

Lines changed: 92 additions & 6 deletions

File tree

BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library")
77
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
88
load("@rules_python//python:defs.bzl", "py_library")
99
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
10+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
1011
load("//bazel:notification.bzl", "notification_rule")
1112
load("//bazel:python_wrap_cc.bzl", "PYTHON_EXTENSION_LINKOPTS", "PYTHON_STABLE_API_DEFINE", "python_wrap_cc")
1213
load("//bazel:tcl_encode_or.bzl", "tcl_encode")
@@ -422,6 +423,13 @@ sh_binary(
422423
data = [":tarfile"],
423424
)
424425

426+
sh_test(
427+
name = "install_test",
428+
size = "small",
429+
srcs = ["//bazel:install_test.sh"],
430+
data = ["//bazel:install.sh"],
431+
)
432+
425433
pkg_tar(
426434
name = "tarfile",
427435
srcs = [

bazel/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ load("@rules_python//python:pip.bzl", "compile_pip_requirements")
55
package(features = ["layering_check"])
66

77
exports_files(
8-
["install.sh"],
8+
[
9+
"install.sh",
10+
"install_test.sh",
11+
],
912
visibility = ["//visibility:public"],
1013
)
1114

bazel/install.sh

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
#!/bin/bash
22
set -e
33

4-
# Install binary and runfiles from bazel build
5-
# Usage: bazel run :install -- [DEST_DIR]
6-
# Default: installs to ./bazel-install in the workspace root
4+
# Install binary and runfiles from bazel build.
5+
#
6+
# ORFS context: When OpenROAD is checked out as a submodule of
7+
# OpenROAD-flow-scripts at tools/OpenROAD/, the ORFS Make flow expects
8+
# the binary at tools/install/OpenROAD/bin/openroad. This path
9+
# originates from build_openroad.sh's CMAKE_INSTALL_PREFIX and is
10+
# hardcoded in flow/scripts/variables.mk:
11+
#
12+
# export OPENROAD_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/OpenROAD/bin/openroad)
13+
#
14+
# The Bazel install target was created as a drop-in replacement for
15+
# the CMake install step, so the suggested ORFS path below matches
16+
# that convention.
717

8-
TARFILE=$(cd $BUILD_WORKSPACE_DIRECTORY; bazelisk info bazel-bin)/openroad.tar
18+
# Support direct execution outside of bazel run
19+
BUILD_WORKSPACE_DIRECTORY="${BUILD_WORKSPACE_DIRECTORY:-$PWD}"
920

10-
DEST_DIR=${1:-${BUILD_WORKSPACE_DIRECTORY}/bazel-install}
21+
TARFILE="${TARFILE:-$(cd "$BUILD_WORKSPACE_DIRECTORY" && bazelisk info bazel-bin)/openroad.tar}"
22+
23+
if [ "$1" == "-f" ]; then
24+
DEST_DIR="${BUILD_WORKSPACE_DIRECTORY}/../install/OpenROAD/bin"
25+
elif [ "$#" -gt 0 ]; then
26+
DEST_DIR="$1"
27+
else
28+
echo "Error: Please specify an installation path."
29+
echo ""
30+
echo "Examples:"
31+
echo " bazel run :install -- ~/.local/bin # Add to your PATH"
32+
echo " bazel run :install -- ./build/install # Project-local install"
33+
echo ""
34+
echo "If you are using ORFS (OpenROAD-flow-scripts), you can use the -f flag"
35+
echo "to install to the path that flow/scripts/variables.mk expects:"
36+
echo ""
37+
echo " bazel run :install -- -f"
38+
exit 1
39+
fi
1140

1241
mkdir -p "$DEST_DIR"
1342
cp -f "$TARFILE" "$DEST_DIR"

bazel/install_test.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
# Test script for bazel/install.sh
3+
set -e
4+
5+
echo "Running install.sh argument parser tests..."
6+
7+
# Mock the environment to bypass bazelisk info calls in the test sandbox
8+
export BUILD_WORKSPACE_DIRECTORY="$(mktemp -d)"
9+
export TARFILE="${BUILD_WORKSPACE_DIRECTORY}/openroad.tar"
10+
11+
# Create a valid, empty tar archive without triggering GNU tar's "cowardly" abort
12+
touch "${BUILD_WORKSPACE_DIRECTORY}/dummy.txt"
13+
tar -cf "$TARFILE" -C "${BUILD_WORKSPACE_DIRECTORY}" dummy.txt
14+
15+
echo "Mock TARFILE created at: $TARFILE"
16+
17+
# Test 1: Passing explicit destination path
18+
TEST1_DEST="${BUILD_WORKSPACE_DIRECTORY}/dest1"
19+
echo "--- Test 1: Explicit Destination ---"
20+
./bazel/install.sh "$TEST1_DEST"
21+
if [ ! -d "$TEST1_DEST" ]; then
22+
echo "FAIL: Test 1 did not create the explicit destination directory."
23+
exit 1
24+
fi
25+
echo "PASS: Test 1"
26+
27+
# Test 2: Passing the -f flag for ORFS location
28+
TEST2_DEST="${BUILD_WORKSPACE_DIRECTORY}/../install/OpenROAD/bin"
29+
echo "--- Test 2: ORFS -f Flag ---"
30+
./bazel/install.sh -f
31+
if [ ! -d "$TEST2_DEST" ]; then
32+
echo "FAIL: Test 2 did not correctly resolve the -f ORFS destination."
33+
exit 1
34+
fi
35+
echo "PASS: Test 2"
36+
37+
# Test 3: Passing no arguments (Should fail with error message)
38+
echo "--- Test 3: No Arguments Expected Failure ---"
39+
if ./bazel/install.sh; then
40+
echo "FAIL: Test 3 succeeded when it should have blocked empty arguments."
41+
exit 1
42+
else
43+
echo "PASS: Test 3 correctly aborted."
44+
fi
45+
46+
echo "All tests passed successfully!"

0 commit comments

Comments
 (0)