You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
3.4 KiB

2 months ago
param([string[]]$TestClasses = @(), [switch]$SkipCompile)
$ErrorActionPreference = 'Stop'
$taskRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
$taskBuild = Join-Path $taskRoot 'app/build/workspace-verification'
$taskJava = 'C:/Program Files/Android/Android Studio/jbr/bin/java.exe'
$taskCompiler = 'C:/Program Files/Android/Android Studio/plugins/Kotlin/kotlinc/lib/*'
$taskJars = @(Get-ChildItem 'C:/Users/COMPUTER1/.gradle/caches' -Filter '*.jar' -Recurse | ForEach-Object { $_.FullName.Replace('\', '/') })
$taskHamcrest = Join-Path $taskBuild 'hamcrest-core-1.3.jar'
function Resolve-Classpath($lines) {
@($lines | ForEach-Object {
if ($_ -match '\.jar;') {
$fixed = @($_.Trim('"').Split(';') | ForEach-Object {
$path = $_
if (Test-Path -LiteralPath $path) { $path }
else {
$suffix = if ($path -match '/transformed/(.+)$') { $Matches[1] } else { [System.IO.Path]::GetFileName($path) }
$replacement = $taskJars | Where-Object { $_.EndsWith('/' + $suffix) } | Select-Object -First 1
if (!$replacement -and $path -match '/files-2.1/([^/]+)/([^/]+)/') {
$modulePath = '/files-2.1/' + $Matches[1] + '/' + $Matches[2] + '/'
$replacement = $taskJars | Where-Object { $_.Contains($modulePath) } | Sort-Object -Descending | Select-Object -First 1
}
if ($replacement) { $replacement }
else { Write-Warning "Obsolete cached dependency omitted: $path" }
}
})
if (Test-Path -LiteralPath $taskHamcrest) { $fixed += $taskHamcrest.Replace('\', '/') }
'"' + (($fixed | Select-Object -Unique) -join ';') + '"'
} else { $_ }
})
}
function Compile-Sources($template, $name, $sourceRoot) {
$argsLines = @(Resolve-Classpath @(Get-Content (Join-Path $taskBuild $template) | Where-Object { $_ -notmatch '^".*\.(kt|java)"$' }))
$sources = @(Get-ChildItem -LiteralPath $sourceRoot -Filter '*.kt' -Recurse | ForEach-Object { '"' + $_.FullName.Replace('\', '/') + '"' })
if ($name -eq 'test-current.args') { $sources += '"' + (Join-Path $taskBuild 'RunWorkspaceTests.kt').Replace('\', '/') + '"' }
$file = Join-Path $taskBuild $name
[System.IO.File]::WriteAllLines($file, ($argsLines + $sources))
& $taskJava '-cp' $taskCompiler 'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler' ('@' + $file) 2>&1 | Tee-Object (Join-Path $taskBuild ($name + '.log')) | Select-Object -Last 55
if ($LASTEXITCODE -ne 0) { throw "Compilation failed: $name" }
}
if (!$SkipCompile) {
Compile-Sources 'compile-main.args' 'main-current.args' (Join-Path $taskRoot 'app/src/main/java')
Compile-Sources 'test.args' 'test-current.args' (Join-Path $taskRoot 'app/src/test/java')
}
$runLines = @(Resolve-Classpath @(Get-Content (Join-Path $taskBuild 'run-tests.args')))
$runnerLine = [Array]::IndexOf($runLines, '"RunWorkspaceTestsKt"')
if ($runnerLine -lt 0) { throw 'JUnit launcher argument not found' }
$selected = @($TestClasses | ForEach-Object { '"' + $_ + '"' })
$runFile = Join-Path $taskBuild 'run-current.args'
[System.IO.File]::WriteAllLines($runFile, @($runLines[0..$runnerLine]) + $selected)
Push-Location $taskRoot
try { & $taskJava '-Dfile.encoding=UTF-8' ('@' + $runFile) 2>&1 | Tee-Object (Join-Path $taskBuild 'test-current.log') | Select-Object -Last 65; exit $LASTEXITCODE } finally { Pop-Location }