Skip to content

Commit 6bd1ef8

Browse files
xinyazhangpruthvistony
authored andcommitted
Fixes CI build script (#1350)
* Fix the parsing of /etc/os-release The old code parses OS_DISTRO as 'PRETTY_Ubuntu' on Ubuntu and thus never links to libtinfo correctly. * Configurable CMAKE_PREFIX_PATH in CI script.
1 parent eb77bc2 commit 6bd1ef8

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

.ci/pytorch/build.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,20 @@ if ! which conda; then
8181
export USE_MKLDNN=0
8282
fi
8383
else
84-
export CMAKE_PREFIX_PATH=/opt/conda
84+
# CMAKE_PREFIX_PATH precedences
85+
# 1. $CONDA_PREFIX, if defined. This follows the pytorch official build instructions.
86+
# 2. /opt/conda/envs/py_${ANACONDA_PYTHON_VERSION}, if ANACONDA_PYTHON_VERSION defined.
87+
# This is for CI, which defines ANACONDA_PYTHON_VERSION but not CONDA_PREFIX.
88+
# 3. $(conda info --base). The fallback value of pytorch official build
89+
# instructions actually refers to this.
90+
# Commonly this is /opt/conda/
91+
if [[ -v CONDA_PREFIX ]]; then
92+
export CMAKE_PREFIX_PATH=${CONDA_PREFIX}
93+
elif [[ -v ANACONDA_PYTHON_VERSION ]]; then
94+
export CMAKE_PREFIX_PATH="/opt/conda/envs/py_${ANACONDA_PYTHON_VERSION}"
95+
else
96+
export CMAKE_PREFIX_PATH="$(conda info --base)"
97+
fi
8598

8699
# Workaround required for MKL library linkage
87100
# https://github.com/pytorch/pytorch/issues/119557

cmake/Dependencies.cmake

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,9 +1244,19 @@ if(USE_ROCM)
12441244
# Currently only active for Ubuntu 20.04 and greater versions.
12451245
if(UNIX AND EXISTS "/etc/os-release")
12461246
file(STRINGS /etc/os-release OS_RELEASE)
1247-
string(REGEX REPLACE ".*NAME=\"([A-Za-z]+).*" "\\1" OS_DISTRO ${OS_RELEASE})
1248-
string(REGEX REPLACE ".*VERSION_ID=\"([0-9\.]+).*" "\\1" OS_VERSION ${OS_RELEASE})
1249-
if(OS_DISTRO STREQUAL "Ubuntu" AND OS_VERSION VERSION_GREATER_EQUAL "20.04")
1247+
set(DISTRO_NAME "")
1248+
set(DISTRO_VERSION "")
1249+
foreach(line ${OS_RELEASE})
1250+
string(REGEX MATCH "^NAME=" DISTRO_NAME_MATCH ${line})
1251+
if (NOT DISTRO_NAME_MATCH STREQUAL "")
1252+
string(REGEX REPLACE "^NAME=\"(.*)\"" "\\1" DISTRO_NAME ${line})
1253+
endif()
1254+
string(REGEX MATCH "^VERSION_ID=" DISTRO_VERSION_MATCH ${line})
1255+
if (NOT DISTRO_VERSION_MATCH STREQUAL "")
1256+
string(REGEX REPLACE "^VERSION_ID=\"(.*)\"" "\\1" DISTRO_VERSION ${line})
1257+
endif()
1258+
endforeach()
1259+
if(DISTRO_NAME STREQUAL "Ubuntu" AND DISTRO_VERSION VERSION_GREATER_EQUAL "20.04")
12501260
find_library(LIBTINFO_LOC tinfo NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH)
12511261
if(LIBTINFO_LOC)
12521262
get_filename_component(LIBTINFO_LOC_PARENT ${LIBTINFO_LOC} DIRECTORY)

0 commit comments

Comments
 (0)