diff --git a/proj/vscode/.gitignore b/proj/vscode/.gitignore index 604546b8..b8563b48 100644 --- a/proj/vscode/.gitignore +++ b/proj/vscode/.gitignore @@ -1,3 +1,5 @@ # Folder local settings are ignored. # Settings that should be checked in should go in the workspace file. .vscode/settings.json +# This is needed to make the build system machine-independent. +vswhere.exe diff --git a/proj/vscode/Invoke-CmdScript.ps1 b/proj/vscode/Invoke-CmdScript.ps1 new file mode 100644 index 00000000..6538098a --- /dev/null +++ b/proj/vscode/Invoke-CmdScript.ps1 @@ -0,0 +1,62 @@ +############################################################################## +## +## Invoke-CmdScript +## +## From PowerShell Cookbook (O'Reilly) +## by Lee Holmes (http://www.leeholmes.com/guide) +## +## +############################################################################## + +<# + +.SYNOPSIS + +Invoke the specified batch file (and parameters), but also propagate any +environment variable changes back to the PowerShell environment that +called it. + +.EXAMPLE + +PS > type foo-that-sets-the-FOO-env-variable.cmd +@set FOO=%* +echo FOO set to %FOO%. + +PS > $env:FOO +PS > Invoke-CmdScript "foo-that-sets-the-FOO-env-variable.cmd" Test + +C:\Temp>echo FOO set to Test. +FOO set to Test. + +PS > $env:FOO +Test + +#> + +param( + ## The path to the script to run + [Parameter(Mandatory = $true)] + [string] $Path, + + ## The arguments to the script + [string] $ArgumentList +) + +Set-StrictMode -Version 3 + +$tempFile = [IO.Path]::GetTempFileName() + +## Store the output of cmd.exe. We also ask cmd.exe to output +## the environment table after the batch file completes +cmd /c " `"$Path`" $argumentList && set > `"$tempFile`" " + +## Go through the environment variables in the temp file. +## For each of them, set the variable in our local environment. +Get-Content $tempFile | Foreach-Object { + if($_ -match "^(.*?)=(.*)$") + { + Set-Content "env:\$($matches[1])" $matches[2] + } +} + +Remove-Item $tempFile \ No newline at end of file diff --git a/proj/vscode/build.ps1 b/proj/vscode/build.ps1 new file mode 100644 index 00000000..2be34fd3 --- /dev/null +++ b/proj/vscode/build.ps1 @@ -0,0 +1,25 @@ + +Set-Location proj\vscode + +$vswhere_path = "vswhere.exe" + +if(-not(Test-Path -path $vswhere_path)) { + (New-Object Net.WebClient).DownloadFile('https://github.com/microsoft/vswhere/releases/latest/download/vswhere.exe', $vswhere_path) + if(-not(Test-Path -path $vswhere_path)) { + Write-Output 'Failed to download vswhere.exe' + exit 1 + } +} + +# $msbuild_path = .\proj\vscode\vswhere -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | select-object -first 1 +$vars_path = .\vswhere -latest -products * -requires Microsoft.Component.MSBuild -find **\VC\Auxiliary\Build\vcvars64.bat +if($vars_path) { + .\Invoke-CmdScript $vars_path + # Write-Output $msbuild_path @args + # & "$msbuild_path\..\..\..\..\VC\Auxiliary\Build\vcvars64.bat" + # Write-Output $env:PATH + MSBuild @args +} else { + Write-Output 'Could not find MSBuild.exe' + exit 1 +} diff --git a/proj/vscode/oboe.code-workspace b/proj/vscode/oboe.code-workspace index 2f9767eb..be39ebdd 100644 --- a/proj/vscode/oboe.code-workspace +++ b/proj/vscode/oboe.code-workspace @@ -10,6 +10,62 @@ "ms-vscode.cpptools", ] }, + "tasks": { + "version": "2.0.0", + "tasks": [ + { + "label": "Build (Debug)", + "windows": { + "type": "process", + "command": "powershell", + "args": [ + "${workspaceFolder}/proj/vscode/build.ps1", + "/property:GenerateFullPaths=true", + "/property:VcpkgConfiguration=Debug", + "/t:build", + "\"${workspaceRoot}\\proj\\vs2017\\Blades of Exile.sln\"" + ], + "problemMatcher": "$msCompile", + }, + "group": "build" + }, + { + "label": "Build (Release)", + "windows": { + "type": "process", + "command": "powershell", + "args": [ + "${workspaceFolder}/proj/vscode/build.ps1", + "/property:GenerateFullPaths=true", + "/property:VcpkgConfiguration=Release", + "/t:build", + "${workspaceRoot}\\proj\\vs2013\\Blades of Exile.sln" + ], + "problemMatcher": "$msCompile", + }, + "group": "build" + }, + { + "label": "Run tests", + "windows": { + "type": "process", + "command": "${workspaceRoot}\\proj\\vs2013\\Release\\OBoE Tests.exe", + "problemMatcher": { + "fileLocation": ["relative", "${workspaceRoot}"], + "pattern": { + "regexp": "^\\.(.*)\\((\\d+)\\): FAILED$", + "file": 1, + "line": 2 + } + }, + }, + "options": { + "cwd": "${workspaceRoot}/test" + }, + "group": "test" + } + ] + }, "settings": { "xml.fileAssociations": [ {