<commit_before>
module UpdateCmd

open System.IO
open NUnit.Framework
open Microsoft.Win32

open PlatformHelpers
open FSharpTestSuiteTypes

type Configuration = 
    | DEBUG
    | RELEASE
    override this.ToString() = 
        match this with
        | DEBUG -> "Debug"
        | RELEASE -> "Release"

type updateCmdArgs = 
    { Configuration : Configuration
      Ngen : bool }

let private regQuery = WindowsPlatform.regQuery

let private checkResult result =
    match result with
    | CmdResult.ErrorLevel (msg, err) -> Failure (RunError.ProcessExecError (msg, err, sprintf "ERRORLEVEL %d" err))
    | CmdResult.Success -> Success ()

let updateCmd envVars args = attempt {
    // @echo off
    // setlocal
    ignore "useless"

    // if /i "%1" == "debug" goto :ok
    // if /i "%1" == "release" goto :ok
    ignore "already validated input"

    // echo adding required strong name verification skipping, and NGening built binaries
    // echo Usage:
    // echo    update.cmd debug [-ngen]
    // echo    update.cmd release [-ngen]
    // exit /b 1
    ignore "useless help"

    //:ok
    let env k () = match envVars |> Map.tryFind k with None -> Failure (sprintf "environment variable '%s' not found" k) | Some x -> Success x
    let ``~dp0`` = __SOURCE_DIRECTORY__
    let exec exe args = 
        log "%s %s" exe args
        use toLog = redirectToLog ()
        Process.exec { RedirectError = Some toLog.Post; RedirectOutput = Some toLog.Post; RedirectInput = None } ``~dp0`` envVars exe args

    // set BINDIR=%~dp0..\%1\net40\bin
    let! binDir = env "FSCBINPATH"

    // if /i "%PROCESSOR_ARCHITECTURE%"=="x86" set X86_PROGRAMFILES=%ProgramFiles%
    // if /I "%PROCESSOR_ARCHITECTURE%"=="AMD64" set X86_PROGRAMFILES=%ProgramFiles(x86)%
    let processorArchitecture = WindowsPlatform.processorArchitecture envVars
    let x86_ProgramFiles = WindowsPlatform.x86ProgramFilesDirectory envVars processorArchitecture

    // if exist "%WindowsSDK_ExecutablePath_x64%" set WINSDKNETFXTOOLS_X64=%WindowsSDK_ExecutablePath_x64%
    // if exist "%WindowsSDK_ExecutablePath_x86%" set WINSDKNETFXTOOLS_X86=%WindowsSDK_ExecutablePath_x86%

    let WINSDKNETFXTOOLS_X86, WINSDKNETFXTOOLS_X64 =
        let EnvironmentPath var =
            match env var () with
            | Success x -> if Directory.Exists(x) then x else ""
            | _ -> ""
        let WindowsSDK_ExecutablePath_x64 = EnvironmentPath "WindowsSDK_ExecutablePath_x64"
        let WindowsSDK_ExecutablePath_x86 = EnvironmentPath "WindowsSDK_ExecutablePath_x86"
        if WindowsSDK_ExecutablePath_x86 <> "" || WindowsSDK_ExecutablePath_x64 <> "" then
            WindowsSDK_ExecutablePath_x86,WindowsSDK_ExecutablePath_x64
        else
            let allWINSDKNETFXTOOLS = 
                let REGEXE32BIT path value =
                    let hklm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
                    match hklm32 |> regQuery path value with
                    | Some (:? string as d) -> Some d
                    | Some _ | None -> None
                seq {
                    //                             FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\NETFXSDK\4.6\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\NETFXSDK\4.6.2\WinSDK-NetFx40Tools"   "InstallationFolder"
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\NETFXSDK\4.6.1\WinSDK-NetFx40Tools"   "InstallationFolder"
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\NETFXSDK\4.6\WinSDK-NetFx40Tools"     "InstallationFolder"

                    // if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\Windows\v8.1A\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\Windows\v8.1A\WinSDK-NetFx40Tools" "InstallationFolder"
                    // if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools" "InstallationFolder"
                    // if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDK-NetFx40Tools" "InstallationFolder"
                    // if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools" "InstallationFolder"
                }

            match allWINSDKNETFXTOOLS |> Seq.tryPick id with 
            | Some sdk -> sdk, sdk + "x64"
            | None -> "", ""
<commit_msg>sn64 did not have a trailing '\'<commit_after>
module UpdateCmd

open System.IO
open NUnit.Framework
open Microsoft.Win32

open PlatformHelpers
open FSharpTestSuiteTypes

type Configuration = 
    | DEBUG
    | RELEASE
    override this.ToString() = 
        match this with
        | DEBUG -> "Debug"
        | RELEASE -> "Release"

type updateCmdArgs = 
    { Configuration : Configuration
      Ngen : bool }

let private regQuery = WindowsPlatform.regQuery

let private checkResult result =
    match result with
    | CmdResult.ErrorLevel (msg, err) -> Failure (RunError.ProcessExecError (msg, err, sprintf "ERRORLEVEL %d" err))
    | CmdResult.Success -> Success ()

let updateCmd envVars args = attempt {
    // @echo off
    // setlocal
    ignore "useless"

    // if /i "%1" == "debug" goto :ok
    // if /i "%1" == "release" goto :ok
    ignore "already validated input"

    // echo adding required strong name verification skipping, and NGening built binaries
    // echo Usage:
    // echo    update.cmd debug [-ngen]
    // echo    update.cmd release [-ngen]
    // exit /b 1
    ignore "useless help"

    //:ok
    let env k () = match envVars |> Map.tryFind k with None -> Failure (sprintf "environment variable '%s' not found" k) | Some x -> Success x
    let ``~dp0`` = __SOURCE_DIRECTORY__
    let exec exe args = 
        log "%s %s" exe args
        use toLog = redirectToLog ()
        Process.exec { RedirectError = Some toLog.Post; RedirectOutput = Some toLog.Post; RedirectInput = None } ``~dp0`` envVars exe args

    // set BINDIR=%~dp0..\%1\net40\bin
    let! binDir = env "FSCBINPATH"

    // if /i "%PROCESSOR_ARCHITECTURE%"=="x86" set X86_PROGRAMFILES=%ProgramFiles%
    // if /I "%PROCESSOR_ARCHITECTURE%"=="AMD64" set X86_PROGRAMFILES=%ProgramFiles(x86)%
    let processorArchitecture = WindowsPlatform.processorArchitecture envVars
    let x86_ProgramFiles = WindowsPlatform.x86ProgramFilesDirectory envVars processorArchitecture

    // if exist "%WindowsSDK_ExecutablePath_x64%" set WINSDKNETFXTOOLS_X64=%WindowsSDK_ExecutablePath_x64%
    // if exist "%WindowsSDK_ExecutablePath_x86%" set WINSDKNETFXTOOLS_X86=%WindowsSDK_ExecutablePath_x86%

    let WINSDKNETFXTOOLS_X86, WINSDKNETFXTOOLS_X64 =
        let EnvironmentPath var =
            match env var () with
            | Success x -> if Directory.Exists(x) then x else ""
            | _ -> ""
        let WindowsSDK_ExecutablePath_x64 = EnvironmentPath "WindowsSDK_ExecutablePath_x64"
        let WindowsSDK_ExecutablePath_x86 = EnvironmentPath "WindowsSDK_ExecutablePath_x86"
        if WindowsSDK_ExecutablePath_x86 <> "" || WindowsSDK_ExecutablePath_x64 <> "" then
            WindowsSDK_ExecutablePath_x86,WindowsSDK_ExecutablePath_x64
        else
            let allWINSDKNETFXTOOLS = 
                let REGEXE32BIT path value =
                    let hklm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
                    match hklm32 |> regQuery path value with
                    | Some (:? string as d) -> Some d
                    | Some _ | None -> None
                seq {
                    //                             FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\NETFXSDK\4.6\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\NETFXSDK\4.6.2\WinSDK-NetFx40Tools"   "InstallationFolder"
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\NETFXSDK\4.6.1\WinSDK-NetFx40Tools"   "InstallationFolder"
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\NETFXSDK\4.6\WinSDK-NetFx40Tools"     "InstallationFolder"

                    // if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\Windows\v8.1A\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\Windows\v8.1A\WinSDK-NetFx40Tools" "InstallationFolder"
                    // if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools" "InstallationFolder"
                    // if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDK-NetFx40Tools" "InstallationFolder"
                    // if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims=	 " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
                    yield REGEXE32BIT @"Software\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools" "InstallationFolder"
                }

            match allWINSDKNETFXTOOLS |> Seq.tryPick id with 
            | Some sdk -> sdk, sdk + @"x64\"
            | None -> "", ""
{'fraction_non_alphanumeric': 0.1070829450139795, 'fraction_numerical': 0.02739981360671016, 'mean_word_length': 2.7547235829251226, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '452056', 'n_tokens_mistral': 3766, 'n_tokens_neox': 3329, 'n_words': 766}