diff --git a/python/scripts/unpack_triton_build_deps.sh b/python/scripts/unpack_triton_build_deps.sh new file mode 100755 index 000000000..7ab6cf43a --- /dev/null +++ b/python/scripts/unpack_triton_build_deps.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +set -e + +# Print +if [ "$OS" = "Windows_NT" ]; then + RED='' + GREEN='' + YELLOW='' + NC='' +else + RED='\033[1;31m' + GREEN='\033[0;32m' + YELLOW='\033[1;33m' + NC='\033[0m' +fi +INFO="${GREEN}[INFO]${NC}" +NOTE="${YELLOW}[NOTE]${NC}" +ERROR="${RED}[ERROR]${NC}" + +printfln() { + printf "%b +" "$@" +} + +# Input +if [ $# -ge 1 ] && [ -f "$1" ]; then + input_tar_gz="$1" + printfln "${INFO} Use ${input_tar_gz} as input packed .tar.gz file" +else + printfln "${ERROR} No input .tar.gz file specified" + printfln "${INFO} Usage: sh $0 [input_tar_gz]" + exit 1 +fi + +# Check system architecture +file_arch="${input_tar_gz##*-}" # x64.tar.gz +file_arch="${file_arch%%.tar.gz}" # x64 +sys_arch="$(uname -m)" +case "${sys_arch}" in + x86_64|amd64) sys_arch="x64" ;; + aarch64|arm64) sys_arch="aarch64" ;; +esac +if [ "${file_arch}" != "${sys_arch}" ]; then + printfln "${ERROR} Arch mismatch: input_file=${RED}${file_arch}${NC}, system=${RED}${sys_arch}${NC}" + exit 1 +fi + +# Output +if [ "${TRITON_HOME}" != "" ]; then + output_dir="${TRITON_HOME}" + printfln "${INFO} Use ${output_dir} as output directory because TRITON_HOME is set" +else + output_dir="${HOME}/.triton" + printfln "${INFO} Use ${output_dir} as default output directory" +fi + +if [ -d "${output_dir}" ]; then + last_output_dir=${output_dir}.$(date +%Y%m%d_%H%M%S) + if [ -d "${last_output_dir}" ]; then + printfln "${ERROR} Backup directory ${RED}${last_output_dir}${NC} already exists, retrying will resolve it" + exit 1 + fi + printfln "${NOTE} Output directory ${YELLOW}${output_dir}${NC} already exists, will mv to ${YELLOW}${last_output_dir}${NC}" +fi + +# Check unpack dirs +printfln "${NOTE} Will unpack following dirs to ${YELLOW}${output_dir}${NC} (will be created):" +tar tzf "${input_tar_gz}" \ + | awk -F'/' '{ + sub(/^\.triton\/?/, ""); if ($0 == "") next + if ($1 == "nvidia") { + if (NF >= 2 && $2 != "") { + print "nvidia/"$2"/" + } else { + print "nvidia/" + } + } else { + print $1"/" + } + }' \ + | uniq +printfln "${NOTE} Press any key to confirm and continue, or Ctrl+C to cancel ..." +read dummy + +# Create output dir +if [ -d "${output_dir}" ]; then + set -x + mv "${output_dir}" "${last_output_dir}" + { set +x; } 2>/dev/null +fi +set -x +mkdir -p "${output_dir}" +{ set +x; } 2>/dev/null +printfln "" + +# Unpack +printfln "${NOTE} Unpacking ${YELLOW}${input_tar_gz}${NC} into ${YELLOW}${output_dir}${NC}" +set -x +tar zxf "${input_tar_gz}" -C "${output_dir}" --strip-components=1 +{ set +x; } 2>/dev/null + +printfln "${INFO} Finished successfully." diff --git a/python/setup.py b/python/setup.py index f1deb7676..b9dbe9ee0 100644 --- a/python/setup.py +++ b/python/setup.py @@ -26,6 +26,14 @@ from setup_tools import setup_helper as helper +# flagtree setup print config +if platform.system() == "Windows": + YELLOW = "" + RESET = "" +else: + YELLOW = "\033[1;33m" + NC = "\033[0m" + @dataclass class Backend: @@ -232,7 +240,8 @@ def get_thirdparty_packages(packages: list): with contextlib.suppress(Exception): shutil.rmtree(package_root_dir) os.makedirs(package_root_dir, exist_ok=True) - print(f'downloading and extracting {p.url} ...') + print(f'{YELLOW}downloading and extracting {p.url} to {package_root_dir} ... {NC}', file=sys.stderr, + flush=True) with open_url(p.url) as response: if p.url.endswith(".zip"): file_bytes = BytesIO(response.read()) @@ -271,11 +280,11 @@ def download_and_copy(name, src_path, variable, version, url_func): curr_version = re.search(r"V([.|\d]+)", curr_version).group(1) download = download or curr_version != version if download and not helper.utils.OfflineBuildManager.is_offline_build(): - print(f'downloading and extracting {url} ...') + print(f'{YELLOW}downloading and extracting {url} ... {NC}', file=sys.stderr, flush=True) file = tarfile.open(fileobj=open_url(url), mode="r|*") file.extractall(path=tmp_path) os.makedirs(os.path.split(dst_path)[0], exist_ok=True) - print(f'copy {src_path} to {dst_path} ...') + print(f'copy {src_path} to {dst_path} ...', file=sys.stderr, flush=True) if os.path.isdir(src_path): shutil.copytree(src_path, dst_path, dirs_exist_ok=True) else: diff --git a/unittest/googletest.cmake b/unittest/googletest.cmake index 41d3d4fa4..cca93c227 100644 --- a/unittest/googletest.cmake +++ b/unittest/googletest.cmake @@ -2,6 +2,16 @@ include(FetchContent) set(GOOGLETEST_DIR "" CACHE STRING "Location of local GoogleTest repo to build against") +if(NOT GOOGLETEST_DIR) + set(_default_googletest "$ENV{HOME}/.triton/googletest-release-1.12.1") + if(EXISTS "${_default_googletest}") + set(GOOGLETEST_DIR "${_default_googletest}" CACHE STRING "Location of local GoogleTest repo to build against" FORCE) + else() + message("Dowloading https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz") + endif() + unset(_default_googletest) +endif() + if(GOOGLETEST_DIR) set(FETCHCONTENT_SOURCE_DIR_GOOGLETEST ${GOOGLETEST_DIR} CACHE STRING "GoogleTest source directory override") endif()