<commit_before>param(
    [string] $CMakeBin = "cmake"
    )

$NativeLibDir = "$Pwd\NativeLibs"

function DownloadANGLE {
    $VAR = (nuget install ANGLE.WindowsStore)
    ls $Pwd/ANGLE.* | % FullName
}

function DownloadNativeLibs {
    if ( Test-Path $NativeLibDir) {
        try {
            git -C $NativeLibDir pull
        }
        catch {
        }
    }else{
        mkdir -Force $NativeLibDir
        try {
            git clone "https://github.com/hbirchtree/native-library-bundle.git" $NativeLibDir
        }
        catch {
        }
    }
}

function CheckArch($arch) {
    if ($arch.Length -lt 1) {
        echo "x86"
    }else{
        echo $arch
    }
}

function ConfigProject([String] $SrcDir,[String] $arch,[String] $toolchain, `
					[String] $preload,[String] $LibVariant,[String] $ANGLEDir, `
					[String[]] $ExtraArgs) {

    $archfix = (CheckArch $arch)

    mkdir -Force build_"$preload"_$archfix
    cd build_"$preload"_$archfix

    
    DownloadNativeLibs

    $Generator = "Visual Studio 14 2015 $arch".Trim()

	echo $ExtraArgs
    $CMakeBin $SrcDir `
        -G"$Generator" `
        -DCMAKE_TOOLCHAIN_FILE="$SrcDir/cmake/Toolchains/$toolchain.toolchain.cmake" `
        -DANGLE_ROOT_DIR="$ANGLEDir" `
        -DNATIVE_LIBRARY_DIR="$NativeLibDir/$LibVariant" `
        -C"$SrcDir/cmake/Preload/$preload.cmake" `
        -DCMAKE_INSTALL_PREFIX="$Pwd/Out" `
        $ExtraArgs

    cd ..
}

function BuildProject($preload, $arch, $config) {
    $arch = (CheckArch $arch)

    $CMakeBin --build $Pwd/build_"$preload"_$arch `
        --target install --config $config
}

function TestProject($preload, $arch, $config) {
    $arch = (CheckArch $arch)

    $CMakeBin --build $Pwd/build_"$preload"_$arch `
        --target RUN_TESTS --config $config
}

#ConfigProject "C:\tmp\jenkins\Windows-UWP_x86-64_Dbg\src" `
#    "Win64" "windows-uwp_windows" "windows-uwp" `
#    "WinUWP" (DownloadAngle)
    
#ConfigProject "C:\tmp\jenkins\Windows-UWP_x86-64_Dbg\src" `
#    "Win64" "windows-win32_windows" "windows-generic" `
#    "Win32" (DownloadANGLE) ""<commit_msg> - Fix CMake custom binary path<commit_after>param(
    [string] $CMakeBin = "cmake"
    )

$NativeLibDir = "$Pwd\NativeLibs"

function DownloadANGLE {
    $VAR = (nuget install ANGLE.WindowsStore)
    ls $Pwd/ANGLE.* | % FullName
}

function DownloadNativeLibs {
    if ( Test-Path $NativeLibDir) {
        try {
            git -C $NativeLibDir pull
        }
        catch {
        }
    }else{
        mkdir -Force $NativeLibDir
        try {
            git clone "https://github.com/hbirchtree/native-library-bundle.git" $NativeLibDir
        }
        catch {
        }
    }
}

function CheckArch($arch) {
    if ($arch.Length -lt 1) {
        echo "x86"
    }else{
        echo $arch
    }
}

function ConfigProject([String] $SrcDir,[String] $arch,[String] $toolchain, `
					[String] $preload,[String] $LibVariant,[String] $ANGLEDir, `
					[String[]] $ExtraArgs) {

    $archfix = (CheckArch $arch)

    mkdir -Force build_"$preload"_$archfix
    cd build_"$preload"_$archfix

    
    DownloadNativeLibs

    $Generator = "Visual Studio 14 2015 $arch".Trim()

	echo $ExtraArgs
    & $CMakeBin $SrcDir `
        -G"$Generator" `
        -DCMAKE_TOOLCHAIN_FILE="$SrcDir/cmake/Toolchains/$toolchain.toolchain.cmake" `
        -DANGLE_ROOT_DIR="$ANGLEDir" `
        -DNATIVE_LIBRARY_DIR="$NativeLibDir/$LibVariant" `
        -C"$SrcDir/cmake/Preload/$preload.cmake" `
        -DCMAKE_INSTALL_PREFIX="$Pwd/Out" `
        $ExtraArgs

    cd ..
}

function BuildProject($preload, $arch, $config) {
    $arch = (CheckArch $arch)

    & $CMakeBin --build $Pwd/build_"$preload"_$arch `
        --target install --config $config
}

function TestProject($preload, $arch, $config) {
    $arch = (CheckArch $arch)

    & $CMakeBin --build $Pwd/build_"$preload"_$arch `
        --target RUN_TESTS --config $config
}

#ConfigProject "C:\tmp\jenkins\Windows-UWP_x86-64_Dbg\src" `
#    "Win64" "windows-uwp_windows" "windows-uwp" `
#    "WinUWP" (DownloadAngle)
    
#ConfigProject "C:\tmp\jenkins\Windows-UWP_x86-64_Dbg\src" `
#    "Win64" "windows-win32_windows" "windows-generic" `
#    "Win32" (DownloadANGLE) ""
{'fraction_non_alphanumeric': 0.1462601238685088, 'fraction_numerical': 0.011910433539780848, 'mean_word_length': 2.6672489082969433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '917058', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1487, 'n_words': 259}