Repository: apple/swift
File: utils/build.ps1 (PowerShell)

Code before:
function Test-Runtime([Hashtable] $Platform) {
  if ($IsCrossCompiling) {
    throw "Swift runtime tests are not supported when cross-compiling"
  }
  if (-not (Test-Path (Get-ProjectBinaryCache $Platform Runtime))) {
    throw "Swift runtime tests are supposed to reconfigure the existing build"
  }
  $CompilersBinaryCache = Get-ProjectBinaryCache $BuildPlatform Compilers
  if (-not (Test-Path "$CompilersBinaryCache\bin\FileCheck.exe")) {
    # These will exist if we test any of llvm/clang/lldb/lld/swift as well
    throw "LIT test utilities not found in $CompilersBinaryCache\bin"
  }

  Invoke-IsolatingEnvVars {
    # Filter known issues when testing on Windows
    Load-LitTestOverrides $PSScriptRoot/windows-swift-android-lit-test-overrides.txt
    $env:Path = "$(Get-CMarkBinaryCache $Platform)\src;$(Get-PinnedToolchainRuntime);${env:Path};$UnixToolsBinDir"
    Build-CMakeProject `
      -Src $SourceCache\swift `
      -Bin (Get-ProjectBinaryCache $Platform Runtime) `
      -Platform $Platform `
      -UseBuiltCompilers C,CXX,Swift `
      -SwiftSDK $null `
      -BuildTargets check-swift-validation-only_non_executable `
      -Defines @{
        SWIFT_ANDROID_API_LEVEL = "$AndroidAPILevel";
        SWIFT_INCLUDE_TESTS = "YES";
        SWIFT_INCLUDE_TEST_BINARIES = "YES";
        SWIFT_BUILD_TEST_SUPPORT_MODULES = "YES";
        SWIFT_NATIVE_LLVM_TOOLS_PATH = Join-Path -Path $CompilersBinaryCache -ChildPath "bin";
        LLVM_LIT_ARGS = "-vv";
      }
  }
}

function Build-ExperimentalRuntime([Hashtable] $Platform, [switch] $Static = $false) {
  # TODO: remove this once the migration is completed.
  Invoke-IsolatingEnvVars {
    Invoke-VsDevShell $BuildPlatform

    Push-Location "${SourceCache}\swift\Runtimes"
    Start-Process -Wait -WindowStyle Hidden -FilePath $cmake -ArgumentList @("-P", "Resync.cmake")
    Pop-Location
  }

  Invoke-IsolatingEnvVars {
    $env:Path = "$(Get-CMarkBinaryCache $Platform)\src;$(Get-PinnedToolchainRuntime);${env:Path}"

    $SDKRoot = Get-SwiftSDK -OS $Platform.OS -Identifier "$($Platform.OS)Experimental"

    $RuntimeBinaryCache = if ($Static) {

Review comment (suggestion):
This `Test-Runtime` method is [only invoked for Android](https://github.com/swiftlang/swift/blob/e6b7af65f4f449a8322faab11b5fa6fbb4e927a9/utils/build.ps1#L4507) currently, see the lit overrides 10 lines up where it skips several tests for Android.

Code after:
function Test-Runtime([Hashtable] $Platform) {
  if ($IsCrossCompiling) {
    throw "Swift runtime tests are not supported when cross-compiling"
  }
  if (-not (Test-Path (Get-ProjectBinaryCache $Platform Runtime))) {
    throw "Swift runtime tests are supposed to reconfigure the existing build"
  }
  $CompilersBinaryCache = Get-ProjectBinaryCache $BuildPlatform Compilers
  if (-not (Test-Path "$CompilersBinaryCache\bin\FileCheck.exe")) {
    # These will exist if we test any of llvm/clang/lldb/lld/swift as well
    throw "LIT test utilities not found in $CompilersBinaryCache\bin"
  }

  $PlatformDefines = @{}
  if ($Platform.OS -eq [OS]::Android) {
    $PlatformDefines += @{
      SWIFT_ANDROID_API_LEVEL = "$AndroidAPILevel";
    }
  }

  Invoke-IsolatingEnvVars {
    # Filter known issues when testing on Windows
    Load-LitTestOverrides $PSScriptRoot/windows-swift-android-lit-test-overrides.txt
    $env:Path = "$(Get-CMarkBinaryCache $Platform)\src;$(Get-PinnedToolchainRuntime);${env:Path};$UnixToolsBinDir"
    Build-CMakeProject `
      -Src $SourceCache\swift `
      -Bin (Get-ProjectBinaryCache $Platform Runtime) `
      -Platform $Platform `
      -UseBuiltCompilers C,CXX,Swift `
      -SwiftSDK $null `
      -BuildTargets check-swift-validation-only_non_executable `
      -Defines ($PlatformDefines + @{
        SWIFT_INCLUDE_TESTS = "YES";
        SWIFT_INCLUDE_TEST_BINARIES = "YES";
        SWIFT_BUILD_TEST_SUPPORT_MODULES = "YES";
        SWIFT_NATIVE_LLVM_TOOLS_PATH = Join-Path -Path $CompilersBinaryCache -ChildPath "bin";
        LLVM_LIT_ARGS = "-vv";
      })
  }
}

function Build-ExperimentalRuntime([Hashtable] $Platform, [switch] $Static = $false) {
  # TODO: remove this once the migration is completed.
  Invoke-IsolatingEnvVars {
    Invoke-VsDevShell $BuildPlatform

    Push-Location "${SourceCache}\swift\Runtimes"
    Start-Process -Wait -WindowStyle Hidden -FilePath $cmake -ArgumentList @("-P", "Resync.cmake")
    Pop-Location
  }