Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ sh_binary(
data = [":tarfile"],
)

sh_test(
name = "install_test",
size = "small",
srcs = ["//bazel:install_test.sh"],
data = ["//bazel:install.sh"],
)

pkg_tar(
name = "tarfile",
srcs = [
Expand Down
18 changes: 1 addition & 17 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,12 @@ package(features = ["layering_check"])

exports_files(
[
"fix_lint.sh",
"install.sh",
"tcl_lint_test.sh",
"tcl_fmt_test.sh",
"tcl_tidy.sh",
"install_test.sh",
],
visibility = ["//visibility:public"],
)

# tclint / tclfmt binaries from pip — version pinned in requirements.in
py_console_script_binary(
name = "tclint",
pkg = "@openroad-pip//tclint",
visibility = ["//visibility:public"],
)

py_console_script_binary(
name = "tclfmt",
pkg = "@openroad-pip//tclint",
visibility = ["//visibility:public"],
)

compile_pip_requirements(
name = "requirements",
src = "requirements.in",
Expand Down
37 changes: 34 additions & 3 deletions bazel/install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
#!/bin/bash
set -e

# Install binary and runfiles from bazel build
# Install binary and runfiles from bazel build.
#
# ORFS context: When OpenROAD is checked out as a submodule of
# OpenROAD-flow-scripts at tools/OpenROAD/, the ORFS Make flow expects
# the binary at tools/install/OpenROAD/bin/openroad. This path
# originates from build_openroad.sh's CMAKE_INSTALL_PREFIX and is
# hardcoded in flow/scripts/variables.mk:
#
# export OPENROAD_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/OpenROAD/bin/openroad)
#
# The Bazel install target was created as a drop-in replacement for
# the CMake install step, so the suggested ORFS path below matches
# that convention.

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

DEST_DIR=${1:-${BUILD_WORKSPACE_DIRECTORY}/../install/OpenROAD/bin}
TARFILE="${TARFILE:-$(cd "$BUILD_WORKSPACE_DIRECTORY" && bazelisk info bazel-bin)/openroad.tar}"

if [ "$1" == "-f" ]; then
DEST_DIR="${BUILD_WORKSPACE_DIRECTORY}/../install/OpenROAD/bin"
elif [ "$#" -gt 0 ]; then
DEST_DIR="$1"
else
echo "Error: Please specify an installation path."
echo ""
echo "Examples:"
echo " bazel run :install -- ~/.local/bin # Add to your PATH"
echo " bazel run :install -- ./build/install # Project-local install"
echo ""
echo "If you are using ORFS (OpenROAD-flow-scripts), you can use the -f flag"
echo "to install to the path that flow/scripts/variables.mk expects:"
echo ""
echo " bazel run :install -- -f"
exit 1
fi

mkdir -p "$DEST_DIR"
cp -f "$TARFILE" "$DEST_DIR"
Expand Down
46 changes: 46 additions & 0 deletions bazel/install_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Test script for bazel/install.sh
set -e

echo "Running install.sh argument parser tests..."

# Mock the environment to bypass bazelisk info calls in the test sandbox
export BUILD_WORKSPACE_DIRECTORY="$(mktemp -d)"
export TARFILE="${BUILD_WORKSPACE_DIRECTORY}/openroad.tar"

# Create a valid, empty tar archive without triggering GNU tar's "cowardly" abort
touch "${BUILD_WORKSPACE_DIRECTORY}/dummy.txt"
tar -cf "$TARFILE" -C "${BUILD_WORKSPACE_DIRECTORY}" dummy.txt

echo "Mock TARFILE created at: $TARFILE"

# Test 1: Passing explicit destination path
TEST1_DEST="${BUILD_WORKSPACE_DIRECTORY}/dest1"
echo "--- Test 1: Explicit Destination ---"
./bazel/install.sh "$TEST1_DEST"
if [ ! -d "$TEST1_DEST" ]; then
echo "FAIL: Test 1 did not create the explicit destination directory."
exit 1
fi
echo "PASS: Test 1"

# Test 2: Passing the -f flag for ORFS location
TEST2_DEST="${BUILD_WORKSPACE_DIRECTORY}/../install/OpenROAD/bin"
echo "--- Test 2: ORFS -f Flag ---"
./bazel/install.sh -f
if [ ! -d "$TEST2_DEST" ]; then
echo "FAIL: Test 2 did not correctly resolve the -f ORFS destination."
exit 1
fi
echo "PASS: Test 2"

# Test 3: Passing no arguments (Should fail with error message)
echo "--- Test 3: No Arguments Expected Failure ---"
if ./bazel/install.sh; then
echo "FAIL: Test 3 succeeded when it should have blocked empty arguments."
exit 1
else
echo "PASS: Test 3 correctly aborted."
fi

echo "All tests passed successfully!"
Loading