<commit_before>#!/bin/bash
#-------------------------------------------------------------------------------------------------------
# Copyright (C) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#-------------------------------------------------------------------------------------------------------

SAFE_RUN() {
    local SF_RETURN_VALUE=$($1 2>&1)

    if [[ $? != 0 ]]; then
        >&2 echo $SF_RETURN_VALUE
        exit 1
    fi
    echo $SF_RETURN_VALUE
}

ERROR_EXIT() {
    if [[ $? != 0 ]]; then
        echo $($1 2>&1)
        exit 1;
    fi
}

ERROR_CLANG() {
    echo "ERROR: clang++ not found."
    echo -e "\nYou could use clang++ from a custom location.\n"
    PRINT_USAGE
    exit 1
}

PRINT_USAGE() {
    echo ""
    echo "[ChakraCore Build Script Help]"
    echo ""
    echo "build.sh [options]"
    echo ""
    echo "options:"
    echo "     --arch[=S]        Set target arch (arm, x86, amd64)"
    echo "     --cc=PATH         Path to Clang   (see example below)"
    echo "     --cxx=PATH        Path to Clang++ (see example below)"
    echo "     --create-deb[=V]  Create .deb package with given V version."
    echo " -d, --debug           Debug build. Default: Release"
    echo "     --embed-icu       Download and embed ICU-57 statically."
    echo " -h, --help            Show help"
    echo "     --icu=PATH        Path to ICU include folder (see example below)"
    echo " -j[=N], --jobs[=N]    Multicore build, allow N jobs at once."
    echo " -n, --ninja           Build with ninja instead of make."
    echo "     --no-icu          Compile without unicode/icu support."
    echo "     --no-jit          Disable JIT"
    echo "     --libs-only       Do not build CH and GCStress"
    echo "     --lto             Enables LLVM Full LTO"
    echo "     --lto-thin        Enables LLVM Thin LTO - xcode 8+ or clang 3.9+"
    echo "     --static          Build as static library. Default: shared library"
    echo "     --sanitize=CHECKS Build with clang -fsanitize checks,"
    echo "                       e.g. undefined,signed-integer-overflow."
    echo " -t, --test-build      Test build. Enables test flags on a release build."
    echo "     --target[=S]      Target OS"
    echo "     --target-path[=S] Output path for compiled binaries. Default: out/"
    echo "     --trace           Enables experimental built-in trace."
    echo "     --xcode           Generate XCode project."
    echo "     --without=FEATURE,FEATURE,..."
    echo "                       Disable FEATUREs from JSRT experimental features."
    echo "     --valgrind        Enable Valgrind support"
    echo "                       !!! Disables Concurrent GC (lower performance)"
    echo " -v, --verbose         Display verbose output including all options"
    echo "     --wb-check CPPFILE"
    echo "                       Write-barrier check given CPPFILE (git path)"
    echo "     --wb-analyze CPPFILE"
    echo "                       Write-barrier analyze given CPPFILE (git path)"
    echo "     --wb-args=PLUGIN_ARGS"
    echo "                       Write-barrier clang plugin args"
    echo " -y                    Automatically answer Yes to questions asked by \
script (at your own risk)"
    echo ""
    echo "example:"
    echo "  ./build.sh --cxx=/path/to/clang++ --cc=/path/to/clang -j"
    echo "with icu:"
    echo "  ./build.sh --icu=/usr/local/opt/icu4c/include"
    echo ""
}

pushd `dirname $0` > /dev/null
CHAKRACORE_DIR=`pwd -P`
popd > /dev/null
_CXX=""
_CC=""
_VERBOSE=""
BUILD_TYPE="Release"
CMAKE_GEN=
MAKE=make
MULTICORE_BUILD=""
NO_JIT=
ICU_PATH="-DICU_SETTINGS_RESET=1"
STATIC_LIBRARY="-DSHARED_LIBRARY_SH=1"
SANITIZE=
WITHOUT_FEATURES=""
CREATE_DEB=0
ARCH="-DCC_USES_SYSTEM_ARCH_SH=1"
OS_LINUX=0
OS_APT_GET=0
OS_UNIX=0
LTO=""
TARGET_OS=""
ENABLE_CC_XPLAT_TRACE=""
WB_CHECK=
WB_ANALYZE=
WB_ARGS=
TARGET_PATH=0
VALGRIND=0
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON useful for clang-query tool
CMAKE_EXPORT_COMPILE_COMMANDS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
LIBS_ONLY_BUILD=
SHOULD_EMBED_ICU=0
ALWAYS_YES=0

if [ -f "/proc/version" ]; then
    OS_LINUX=1
    PROC_INFO=$(cat /proc/version)
    if [[ $PROC_INFO =~ 'Ubuntu' || $PROC_INFO =~ 'Debian'
       || $PROC_INFO =~ 'Linaro' ]]; then
        OS_APT_GET=1
    fi
elif [[ $(uname -s) =~ "Darwin" ]]; then
    OS_UNIX=1
else
    echo -e "Warning: Installation script couldn't detect host OS..\n" # exit ?
fi

while [[ $# -gt 0 ]]; do
    case "$1" in
    --arch=*)
        ARCH=$1
        ARCH="${ARCH:7}"
        ;;

    --cxx=*)
        _CXX=$1
        _CXX=${_CXX:6}
        ;;

    --cc=*)
        _CC=$1
        _CC=${_CC:5}
        ;;

    -h | --help)
        PRINT_USAGE
        exit
        ;;

    -v | --verbose)
        _VERBOSE="V=1"
        ;;

    -d | --debug)
        BUILD_TYPE="Debug"
        ;;

    --embed-icu)
        SHOULD_EMBED_ICU=1
        ;;

    -t | --test-build)
        BUILD_TYPE="Test"
        ;;

    -j | --jobs)
        if [[ "$1" == "-j" && "$2" =~ ^[^-] ]]; then
            MULTICORE_BUILD="-j $2"
            shift
        else
            MULTICORE_BUILD="-j $(nproc)"
        fi
        ;;

    -j=* | --jobs=*)            # -j=N syntax used in CI
        MULTICORE_BUILD=$1
        if [[ "$1" =~ ^-j= ]]; then
            MULTICORE_BUILD="-j ${MULTICORE_BUILD:3}"
        else
            MULTICORE_BUILD="-j ${MULTICORE_BUILD:7}"
        fi
        ;;

    --icu=*)
        ICU_PATH=$1
        ICU_PATH="${ICU_PATH:6}"
        if [[ ! -d ${ICU_PATH} ]]; then
            if [[ -d "${CHAKRACORE_DIR}/${ICU_PATH}" ]]; then
                ICU_PATH="${CHAKRACORE_DIR}/${ICU_PATH}"
            else
                # if ICU_PATH is given, do not fallback to no-icu
                echo "!!! couldn't find ICU at $ICU_PATH"<commit_msg>[MERGE #3190 @obastemur] xplat: fix ICU lib tilde path problem<commit_after>#!/bin/bash
#-------------------------------------------------------------------------------------------------------
# Copyright (C) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#-------------------------------------------------------------------------------------------------------

SAFE_RUN() {
    local SF_RETURN_VALUE=$($1 2>&1)

    if [[ $? != 0 ]]; then
        >&2 echo $SF_RETURN_VALUE
        exit 1
    fi
    echo $SF_RETURN_VALUE
}

ERROR_EXIT() {
    if [[ $? != 0 ]]; then
        echo $($1 2>&1)
        exit 1;
    fi
}

ERROR_CLANG() {
    echo "ERROR: clang++ not found."
    echo -e "\nYou could use clang++ from a custom location.\n"
    PRINT_USAGE
    exit 1
}

PRINT_USAGE() {
    echo ""
    echo "[ChakraCore Build Script Help]"
    echo ""
    echo "build.sh [options]"
    echo ""
    echo "options:"
    echo "     --arch[=S]        Set target arch (arm, x86, amd64)"
    echo "     --cc=PATH         Path to Clang   (see example below)"
    echo "     --cxx=PATH        Path to Clang++ (see example below)"
    echo "     --create-deb[=V]  Create .deb package with given V version."
    echo " -d, --debug           Debug build. Default: Release"
    echo "     --embed-icu       Download and embed ICU-57 statically."
    echo " -h, --help            Show help"
    echo "     --icu=PATH        Path to ICU include folder (see example below)"
    echo " -j[=N], --jobs[=N]    Multicore build, allow N jobs at once."
    echo " -n, --ninja           Build with ninja instead of make."
    echo "     --no-icu          Compile without unicode/icu support."
    echo "     --no-jit          Disable JIT"
    echo "     --libs-only       Do not build CH and GCStress"
    echo "     --lto             Enables LLVM Full LTO"
    echo "     --lto-thin        Enables LLVM Thin LTO - xcode 8+ or clang 3.9+"
    echo "     --static          Build as static library. Default: shared library"
    echo "     --sanitize=CHECKS Build with clang -fsanitize checks,"
    echo "                       e.g. undefined,signed-integer-overflow."
    echo " -t, --test-build      Test build. Enables test flags on a release build."
    echo "     --target[=S]      Target OS"
    echo "     --target-path[=S] Output path for compiled binaries. Default: out/"
    echo "     --trace           Enables experimental built-in trace."
    echo "     --xcode           Generate XCode project."
    echo "     --without=FEATURE,FEATURE,..."
    echo "                       Disable FEATUREs from JSRT experimental features."
    echo "     --valgrind        Enable Valgrind support"
    echo "                       !!! Disables Concurrent GC (lower performance)"
    echo " -v, --verbose         Display verbose output including all options"
    echo "     --wb-check CPPFILE"
    echo "                       Write-barrier check given CPPFILE (git path)"
    echo "     --wb-analyze CPPFILE"
    echo "                       Write-barrier analyze given CPPFILE (git path)"
    echo "     --wb-args=PLUGIN_ARGS"
    echo "                       Write-barrier clang plugin args"
    echo " -y                    Automatically answer Yes to questions asked by \
script (at your own risk)"
    echo ""
    echo "example:"
    echo "  ./build.sh --cxx=/path/to/clang++ --cc=/path/to/clang -j"
    echo "with icu:"
    echo "  ./build.sh --icu=/usr/local/opt/icu4c/include"
    echo ""
}

pushd `dirname $0` > /dev/null
CHAKRACORE_DIR=`pwd -P`
popd > /dev/null
_CXX=""
_CC=""
_VERBOSE=""
BUILD_TYPE="Release"
CMAKE_GEN=
MAKE=make
MULTICORE_BUILD=""
NO_JIT=
ICU_PATH="-DICU_SETTINGS_RESET=1"
STATIC_LIBRARY="-DSHARED_LIBRARY_SH=1"
SANITIZE=
WITHOUT_FEATURES=""
CREATE_DEB=0
ARCH="-DCC_USES_SYSTEM_ARCH_SH=1"
OS_LINUX=0
OS_APT_GET=0
OS_UNIX=0
LTO=""
TARGET_OS=""
ENABLE_CC_XPLAT_TRACE=""
WB_CHECK=
WB_ANALYZE=
WB_ARGS=
TARGET_PATH=0
VALGRIND=0
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON useful for clang-query tool
CMAKE_EXPORT_COMPILE_COMMANDS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
LIBS_ONLY_BUILD=
SHOULD_EMBED_ICU=0
ALWAYS_YES=0

if [ -f "/proc/version" ]; then
    OS_LINUX=1
    PROC_INFO=$(cat /proc/version)
    if [[ $PROC_INFO =~ 'Ubuntu' || $PROC_INFO =~ 'Debian'
       || $PROC_INFO =~ 'Linaro' ]]; then
        OS_APT_GET=1
    fi
elif [[ $(uname -s) =~ "Darwin" ]]; then
    OS_UNIX=1
else
    echo -e "Warning: Installation script couldn't detect host OS..\n" # exit ?
fi

while [[ $# -gt 0 ]]; do
    case "$1" in
    --arch=*)
        ARCH=$1
        ARCH="${ARCH:7}"
        ;;

    --cxx=*)
        _CXX=$1
        _CXX=${_CXX:6}
        ;;

    --cc=*)
        _CC=$1
        _CC=${_CC:5}
        ;;

    -h | --help)
        PRINT_USAGE
        exit
        ;;

    -v | --verbose)
        _VERBOSE="V=1"
        ;;

    -d | --debug)
        BUILD_TYPE="Debug"
        ;;

    --embed-icu)
        SHOULD_EMBED_ICU=1
        ;;

    -t | --test-build)
        BUILD_TYPE="Test"
        ;;

    -j | --jobs)
        if [[ "$1" == "-j" && "$2" =~ ^[^-] ]]; then
            MULTICORE_BUILD="-j $2"
            shift
        else
            MULTICORE_BUILD="-j $(nproc)"
        fi
        ;;

    -j=* | --jobs=*)            # -j=N syntax used in CI
        MULTICORE_BUILD=$1
        if [[ "$1" =~ ^-j= ]]; then
            MULTICORE_BUILD="-j ${MULTICORE_BUILD:3}"
        else
            MULTICORE_BUILD="-j ${MULTICORE_BUILD:7}"
        fi
        ;;

    --icu=*)
        ICU_PATH=$1
        # resolve tilde on path
        eval ICU_PATH="${ICU_PATH:6}"
        if [[ ! -d ${ICU_PATH} ]]; then
            if [[ -d "${CHAKRACORE_DIR}/${ICU_PATH}" ]]; then
                ICU_PATH="${CHAKRACORE_DIR}/${ICU_PATH}"
            else
                # if ICU_PATH is given, do not fallback to no-icu
                echo "!!! couldn't find ICU at $ICU_PATH"
{'fraction_non_alphanumeric': 0.16734486266531026, 'fraction_numerical': 0.009833841980332316, 'mean_word_length': 1.6533963112910481, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1703521', 'n_tokens_mistral': 4118, 'n_tokens_neox': 3844, 'n_words': 1023}