version: 0.20150918.{build}
image: Visual Studio 2017
configuration: Debug
platform: AnyCPU
shallow_clone: true
clone_folder: c:\Cosmos

init:
- cmd: |
    git clone https://github.com/CosmosOS/XSharp.git c:\XSharp --depth 1
    git clone https://github.com/CosmosOS/IL2CPU.git c:\IL2CPU --depth 1

install:
- ps: |
    $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
    mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null
    Invoke-WebRequest -Uri "https://raw.githubusercontent.com/dotnet/cli/release/2.0.0/scripts/obtain/dotnet-install.ps1" -OutFile "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1"
    '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version 2.0.0 -InstallDir $env:DOTNET_INSTALL_DIR'
    $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"

build_script:
- cmd: >-
    rem %APPVEYOR_BUILD_FOLDER%

    
    Build\Tools\nuget restore "Builder.sln"

    Build\Tools\nuget restore "..\XSharp\XSharp.sln"

    Build\Tools\nuget restore "..\IL2CPU\IL2CPU.sln"

    Build\Tools\nuget restore "Build.sln"

    Build\Tools\nuget restore "Test.sln"


    msbuild "Builder.sln" /maxcpucount /verbosity:normal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /p:Platform="Any CPU" /p:Configuration=Debug /p:DeployExtension=false

    msbuild "Build.sln" /maxcpucount /verbosity:normal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /p:Platform="Any CPU" /p:Configuration=Debug /p:OutputPath="%APPVEYOR_BUILD_FOLDER%\Build\VSIP" /p:DeployExtension=false

    msbuild "Test.sln" /maxcpucount /verbosity:normal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /p:Platform="Any CPU" /p:Configuration=Debug


    dotnet publish source\Cosmos.Build.MSBuild -r win7-x86 -o "c:\CosmosRun\Build\VSIP\"

    dotnet publish ..\IL2CPU\source\IL2CPU -r win7-x86 -o "c:\CosmosRun\Build\IL2CPU\"


    xcopy /Y "Build\VSIP\Cosmos.Debug.Kernel.*" "c:\CosmosRun\Kernel\"

    xcopy /Y "Build\VSIP\Cosmos.Core.*" "c:\CosmosRun\Kernel\"

    xcopy /Y "Build\VSIP\Cosmos.HAL.*" "c:\CosmosRun\Kernel\"

    xcopy /Y "Build\VSIP\Cosmos.System.*" "c:\CosmosRun\Kernel\"

    xcopy /Y "Build\VSIP\Cosmos.Common.*" "c:\CosmosRun\Kernel\"

    xcopy /Y "Build\VSIP\Cosmos.Debug.GDB.exe" "c:\CosmosRun\Build\VSIP\"

    xcopy /Y /S "Build\ISO" "c:\CosmosRun\Build\ISO\"

    xcopy /Y "Build\*.*" "c:\CosmosRun\Build\ISO\"

    xcopy /Y /S "Build\VMware\*" "c:\CosmosRun\Build\VMware\"

    xcopy /Y /S "Build\Tools" "c:\CosmosRun\Build\Tools\"

    xcopy /Y "source\Cosmos.Core.DebugStub\*.xs" "c:\CosmosRun\XSharp\DebugStub\"

    xcopy /Y /S "Resources\Bochs\*.*" "%ProgramFiles(x86)%\Bochs-2.6.8\"


    reg add HKLM\SOFTWARE\WOW6432Node\Cosmos /v UserKit /d c:\CosmosRun\

    reg add HKCR\BochsConfigFile\shell\Run\command /ve /d "\"C:\Program Files (x86)\Bochs-2.6.8\Bochs.exe\" -q -f \"%1\""


#test: off
#  assemblies:
#  - Cosmos.Core.Memory.Test.dll
#  - DebugCompiler.dll
#  - Cosmos.TestRunner.UnitTest.dll

test_script:
- cmd: dotnet test Tests\Cosmos.TestRunner.UnitTest\Cosmos.TestRunner.UnitTest.csproj --logger "trx;LogFileName=c:\Cosmos\TestResult.xml"

on_finish:
- ps: |
    $wc = New-Object 'System.Net.WebClient'
    $wc.UploadFile("https://ci.appveyor.com/api/testresults/mstest/$($env:APPVEYOR_JOB_ID)", "c:\Cosmos\TestResult.xml")

notifications:
- provider: Webhook
  url: https://webhooks.gitter.im/e/d5c57ffb9a04b1b180be
  on_build_success: true
  on_build_failure: true
  on_build_status_changed: true

matrix:
  fast_finish: true

artifacts:
  - path: '**\TestResult.xml'
