From 58c119d69f90b39f424ba70ae6320de02056b845 Mon Sep 17 00:00:00 2001 From: habibayassin Date: Sat, 10 Aug 2024 22:20:41 +0000 Subject: [PATCH 1/2] refactor build Signed-off-by: habibayassin --- build_openroad.sh | 333 +++++++++++++++++++++++----------------------- 1 file changed, 169 insertions(+), 164 deletions(-) diff --git a/build_openroad.sh b/build_openroad.sh index 81599d0876..dc550ca99a 100755 --- a/build_openroad.sh +++ b/build_openroad.sh @@ -28,23 +28,31 @@ OPENROAD_APP_ARGS="" DOCKER_OS_NAME="ubuntu22.04" PROC=-1 -function usage() { - cat << EOF +LOCAL_BUILD=0 +CLEAN_BEFORE=0 +CLEAN_FORCE=0 +USE_OPENROAD_APP_LATEST=0 +DOCKER_COPY_PLATFORMS=0 -Usage: $0 [-h|--help] [-o|--local] [-l|--latest] +__usage() { + cat << EOF + +Usage: $0 [-h|--help] [-o|--local] [--pull-docker] [-l|--latest] [--or_branch BRANCH_NAME] [--or_repo REPO_URL] [--no_init] - [-n|--nice] [-t|--threads N] - [--yosys-args-overwrite] [--yosys-args STRING] + [-n|--nice] [-t|--threads N] + [--yosys-args-overwrite] [--yosys-args STRING] [--openroad-args-overwrite] [--openroad-args STRING] [--install-path PATH] [--clean] [--clean-force] - [-c|--copy-platforms] + [-c|--copy-platforms] [--os DOCKER_OS_NAME] Options: -h, --help Print this help message. -o, --local Build locally instead of building a Docker image. + --pull-docker Pull the latest Docker image instead of building it. + -l, --latest Use the head of branch --or_branch or 'master' by default for tools/OpenROAD. @@ -92,103 +100,104 @@ Options valid only for Docker builds: EOF } -# Parse arguments -__CMD="$0 $@" -while (( "$#" )); do - case "$1" in - -h|--help) - usage 2> /dev/null - exit - ;; - -o|--local) - LOCAL_BUILD=1 - ;; - -l|--latest) - USE_OPENROAD_APP_LATEST=1 - ;; - --or_branch) - OPENROAD_APP_BRANCH="$2" - shift - ;; - --or_repo) - OPENROAD_APP_GIT_URL="$2" - shift - ;; - --no_init) - OPENROAD_FLOW_NO_GIT_INIT=1 - ;; - -t|--threads) - PROC="$2" - shift - ;; - -n|--nice) - NICE="nice" - ;; - -c|--copy-platforms) - DOCKER_COPY_PLATFORMS=1 - ;; - --yosys-args-overwrite) - YOSYS_OVERWIRTE_ARGS=1 - ;; - --yosys-args) - YOSYS_USER_ARGS="$2" - shift - ;; - --openroad-args-overwrite) - OPENROAD_APP_OVERWIRTE_ARGS=1 - ;; - --openroad-args) - OPENROAD_APP_USER_ARGS="$2" - shift - ;; - --install-path) - INSTALL_PATH="$2" - shift - ;; - --clean) - CLEAN_BEFORE=1 - ;; - --clean-force) - CLEAN_BEFORE=1 - CLEAN_FORCE=1 - ;; - --os=* ) - DOCKER_OS_NAME="${1#*=}" - ;; - -*|--*) # unsupported flags - echo "[ERROR FLW-0005] Unsupported flag $1." >&2 - usage 2> /dev/null - exit 1 - ;; - esac - shift -done - -if [[ "$PROC" == "-1" ]]; then - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - PROC=$(nproc --all) - elif [[ "$OSTYPE" == "darwin"* ]]; then - PROC=$(sysctl -n hw.ncpu) - else - cat << EOF +__parse_args() { + while (( "$#" )); do + case "$1" in + -h|--help) + usage 2> /dev/null + exit + ;; + -o|--local) + LOCAL_BUILD=1 + ;; + -l|--latest) + USE_OPENROAD_APP_LATEST=1 + ;; + --or_branch) + OPENROAD_APP_BRANCH="$2" + shift + ;; + --or_repo) + OPENROAD_APP_GIT_URL="$2" + shift + ;; + --no_init) + OPENROAD_FLOW_NO_GIT_INIT=1 + ;; + -t|--threads) + PROC="$2" + shift + ;; + -n|--nice) + NICE="nice" + ;; + -c|--copy-platforms) + DOCKER_COPY_PLATFORMS=1 + ;; + --yosys-args-overwrite) + YOSYS_OVERWIRTE_ARGS=1 + ;; + --yosys-args) + YOSYS_USER_ARGS="$2" + shift + ;; + --openroad-args-overwrite) + OPENROAD_APP_OVERWIRTE_ARGS=1 + ;; + --openroad-args) + OPENROAD_APP_USER_ARGS="$2" + shift + ;; + --install-path) + INSTALL_PATH="$2" + shift + ;; + --clean) + CLEAN_BEFORE=1 + ;; + --clean-force) + CLEAN_BEFORE=1 + CLEAN_FORCE=1 + ;; + --os=* ) + DOCKER_OS_NAME="${1#*=}" + ;; + --pull-docker) + PULL_DOCKER_IMAGE=1 + ;; + -*|--*) # unsupported flags + echo "[ERROR FLW-0005] Unsupported flag $1." >&2 + usage 2> /dev/null + exit 1 + ;; + esac + shift + done +} + +__setup_parallelism() { + if [[ "$PROC" == "-1" ]]; then + case "$OSTYPE" in + linux-gnu*) PROC=$(nproc --all) ;; + darwin*) PROC=$(sysctl -n hw.ncpu) ;; + *) cat << EOF [WARNING FLW-0025] Unsupported OSTYPE: cannot determine number of host CPUs" - Defaulting to 2 threads. Use --threads N to use N threads" + Defaulting to 2 threads. Use --threads N to use N threads" EOF - PROC=2 - fi -fi - -echo "[INFO FLW-0028] Compiling with ${PROC} threads." + PROC=2 ;; + esac + fi + echo "[INFO FLW-0028] Compiling with ${PROC} threads." +} -# Only add install prefix variables after parsing arguments. -YOSYS_ARGS+=" PREFIX=${INSTALL_PATH}/yosys" -OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_PREFIX=${INSTALL_PATH}/OpenROAD" -if [ -n "$CMAKE_INSTALL_RPATH" ]; then - OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH}" - OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE" -fi +__setup_build_args() { + YOSYS_ARGS+=" PREFIX=${INSTALL_PATH}/yosys" + OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_PREFIX=${INSTALL_PATH}/OpenROAD" + if [ -n "$CMAKE_INSTALL_RPATH" ]; then + OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH}" + OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE" + fi -__args_setup() { if [ ! -z "${YOSYS_OVERWIRTE_ARGS+x}" ]; then echo "[INFO FLW-0014] Overwriting Yosys compilation flags." YOSYS_ARGS="${YOSYS_USER_ARGS}" @@ -204,42 +213,28 @@ __args_setup() { fi } -__docker_build() -{ - echo "[INFO FLW-0020] Building docker image for OpenROAD Flow." - if [ ! -z "${DOCKER_COPY_PLATFORMS+x}" ]; then - cp .dockerignore{,.bak} - sed -i '/flow\/platforms/d' .dockerignore - fi - ./etc/DockerHelper.sh create -target=dev -os="${DOCKER_OS_NAME}" -threads="${PROC}" - ./etc/DockerHelper.sh create -target=builder -os="${DOCKER_OS_NAME}" -threads="${PROC}" - if [ ! -z "${DOCKER_COPY_PLATFORMS+x}" ]; then - mv .dockerignore{.bak,} +__docker_build() { + if [[ "$PULL_DOCKER_IMAGE" -eq 1 ]]; then + echo "[INFO FLW-0030] Pulling Docker image for OpenROAD Flow." + docker pull openroad/orfs:latest + else + echo "[INFO FLW-0020] Building docker image for OpenROAD Flow." + if [ ! -z "${DOCKER_COPY_PLATFORMS+x}" ]; then + cp .dockerignore{,.bak} + sed -i '/flow\/platforms/d' .dockerignore + fi + ./etc/DockerHelper.sh create -target=dev -os="${DOCKER_OS_NAME}" -threads="${PROC}" + ./etc/DockerHelper.sh create -target=builder -os="${DOCKER_OS_NAME}" -threads="${PROC}" + if [ ! -z "${DOCKER_COPY_PLATFORMS+x}" ]; then + mv .dockerignore{.bak,} + fi fi } -__local_build() -{ +__local_build() { if [[ "$OSTYPE" == "darwin"* ]]; then - export PATH="$(brew --prefix bison)/bin:$(brew --prefix flex)/bin:$(brew --prefix tcl-tk)/bin:$PATH" - export CMAKE_PREFIX_PATH=$(brew --prefix or-tools) - fi - if [[ -f "/opt/rh/rh-python38/enable" ]]; then - set +u - source /opt/rh/rh-python38/enable - set -u - fi - if [[ -f "/opt/rh/devtoolset-8/enable" ]]; then - # the scl script has unbound variables - set +u - source /opt/rh/devtoolset-8/enable - set -u - fi - - YOSYS_ABC_PATH=tools/yosys/abc - if [[ -d "${YOSYS_ABC_PATH}/.git" ]]; then - # update indexes to make sure git diff-index uses correct data - git --work-tree=${YOSYS_ABC_PATH} --git-dir=${YOSYS_ABC_PATH}/.git update-index --refresh + export PATH="$(brew --prefix bison)/bin:$(brew --prefix flex)/bin:$(brew --prefix tcl-tk)/bin:$PATH" + export CMAKE_PREFIX_PATH=$(brew --prefix or-tools) fi echo "[INFO FLW-0017] Compiling Yosys." @@ -274,14 +269,14 @@ __change_openroad_app_remote() __update_openroad_app_remote } -__update_openroad_app_latest() -( +__update_openroad_app_latest() +{ cd tools/OpenROAD git fetch "${OPENROAD_APP_REMOTE}" git checkout "${OPENROAD_APP_REMOTE}/${OPENROAD_APP_BRANCH}" git pull "${OPENROAD_APP_REMOTE}" "${OPENROAD_APP_BRANCH}" git submodule update --init --recursive -) +} __common_setup() { @@ -304,6 +299,22 @@ __common_setup() fi } +#### +__update_openroad_app() { + cd tools/OpenROAD + if ! git remote | grep -q "$OPENROAD_APP_REMOTE"; then + git remote add "$OPENROAD_APP_REMOTE" "$OPENROAD_APP_GIT_URL" + fi + + if [ "${USE_OPENROAD_APP_LATEST:-0}" -eq 1 ] || [ "$OPENROAD_APP_BRANCH" != "master" ]; then + git fetch "$OPENROAD_APP_REMOTE" + git checkout "$OPENROAD_APP_REMOTE/$OPENROAD_APP_BRANCH" + git pull "$OPENROAD_APP_REMOTE" "$OPENROAD_APP_BRANCH" + git submodule update --init --recursive + fi +} +#### + __logging() { local log_file="build_openroad.log" @@ -313,36 +324,30 @@ __logging() exec 2>&1 } -__cleanup() -{ - if [ ! -z "${CLEAN_FORCE+x}" ]; then - CLEAN_CMD="-x -d --force" +__clean_previous_build() { + CLEAN_CMD="-x -d" + [ "$CLEAN_FORCE" -eq 1 ] && CLEAN_CMD+=" --force" || CLEAN_CMD+=" --interactive" + echo "[INFO FLW-0026]Cleaning up previous binaries and build files." + git clean $CLEAN_CMD tools + git submodule foreach --recursive git clean $CLEAN_CMD +} + +function main() { + __logging + [ "$CLEAN_BEFORE" -eq 1 ] && __clean_previous_build + __parse_args "$@" + __setup_parallelism + __setup_build_args + __common_setup + + if [ -z "${LOCAL_BUILD+x}" ] && command -v docker &> /dev/null; then + echo -n "[INFO FLW-0000] Using docker build method." + __docker_build else - CLEAN_CMD="-x -d --interactive" - fi - echo "[INFO FLW-0026] Cleaning up previous binaries and build files." - git clean ${CLEAN_CMD} tools - YOSYS_ABC_PATH="tools/yosys/abc" - if [[ -d "${YOSYS_ABC_PATH}" ]]; then - echo "Entering '${YOSYS_ABC_PATH}'" - git --work-tree=${YOSYS_ABC_PATH} --git-dir=${YOSYS_ABC_PATH}/.git clean ${CLEAN_CMD} + echo -n "[INFO FLW-0001] Using local build method." + echo " This will create binaries at 'tools/install' unless overwritten." + __local_build fi - git submodule foreach --recursive git clean ${CLEAN_CMD} } - -__logging -if [ ! -z "${CLEAN_BEFORE+x}" ]; then - __cleanup -fi -__args_setup -__common_setup - -# Choose install method -if [ -z "${LOCAL_BUILD+x}" ] && command -v docker &> /dev/null; then - echo -n "[INFO FLW-0000] Using docker build method." - __docker_build -else - echo -n "[INFO FLW-0001] Using local build method." - echo " This will create binaries at 'tools/install' unless overwritten." - __local_build -fi +__CMD="$0 $@" +main "$@" From 229631b1100a04fc9dce4e125e55b78f2381a5bd Mon Sep 17 00:00:00 2001 From: habibayassin Date: Sat, 10 Aug 2024 23:20:59 +0000 Subject: [PATCH 2/2] fix dir Signed-off-by: habibayassin --- build_openroad.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/build_openroad.sh b/build_openroad.sh index dc550ca99a..51d5c80181 100755 --- a/build_openroad.sh +++ b/build_openroad.sh @@ -34,7 +34,7 @@ CLEAN_FORCE=0 USE_OPENROAD_APP_LATEST=0 DOCKER_COPY_PLATFORMS=0 -__usage() { +function usage() { cat << EOF Usage: $0 [-h|--help] [-o|--local] [--pull-docker] [-l|--latest] @@ -247,6 +247,7 @@ __local_build() { __update_openroad_app_remote() ( + baseDir="$(pwd)" cd tools/OpenROAD remotes=$(git remote) SAVEIFS=$IFS @@ -256,6 +257,7 @@ __update_openroad_app_remote() if [[ ! " ${remotes[@]} " =~ " ${OPENROAD_APP_REMOTE} " ]]; then git remote add "${OPENROAD_APP_REMOTE}" "${OPENROAD_APP_GIT_URL}" fi + cd ${baseDir} ) __change_openroad_app_remote() @@ -271,11 +273,13 @@ __change_openroad_app_remote() __update_openroad_app_latest() { + baseDir="$(pwd)" cd tools/OpenROAD git fetch "${OPENROAD_APP_REMOTE}" git checkout "${OPENROAD_APP_REMOTE}/${OPENROAD_APP_BRANCH}" git pull "${OPENROAD_APP_REMOTE}" "${OPENROAD_APP_BRANCH}" git submodule update --init --recursive + cd ${baseDir} } __common_setup() @@ -335,7 +339,7 @@ __clean_previous_build() { function main() { __logging [ "$CLEAN_BEFORE" -eq 1 ] && __clean_previous_build - __parse_args "$@" + __parse_args "$0 $@" __setup_parallelism __setup_build_args __common_setup @@ -349,5 +353,6 @@ function main() { __local_build fi } + __CMD="$0 $@" -main "$@" +main "$0 $@"