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.

128 lines
4.9 KiB

  1. if ($PSEdition -eq "Core") {
  2. Write-Error "Build must be run with Windows PowerShell due to the use of CodeDOM"
  3. Write-Output "Running with Windows PowerShell"
  4. powershell.exe "$(Get-Location)\build.ps1"
  5. return
  6. }
  7. # read SelfConfig, remove wierd bits, load it, load Newtonsoft, and turn it into a schema
  8. $newtonsoftVer = "13.0.1"
  9. $newtonsoftSchemaVer = "3.0.15-beta2"
  10. $codeDomProviderVer = "3.6.0"
  11. $roslynVer = "3.10.0"
  12. $nugetBase = "$(Get-Location)/nuget"
  13. $newtonsoftLoc = "$nugetBase/Newtonsoft.Json.$newtonsoftVer/lib/netstandard2.0/Newtonsoft.Json.dll"
  14. $newtonsoftSchemaLoc = "$nugetBase/Newtonsoft.Json.Schema.$newtonsoftSchemaVer/lib/netstandard2.0/Newtonsoft.Json.Schema.dll"
  15. $roslynCodeDomBase = "$nugetBase/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.$codeDomProviderVer"
  16. $roslynCodeDom = "$roslynCodeDomBase/lib/net45/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll"
  17. $roslynBase = "$nugetBase/Microsoft.Net.Compilers.Toolset.$roslynVer"
  18. $roslynInstall = "$roslynBase/tasks/net472/"
  19. $selfConfigLoc = "../IPA.Loader/Config/SelfConfig.cs"
  20. $ipaRoot = "../IPA"
  21. if (!(Test-Path "nuget" -PathType Container)) {
  22. $nugetExe = "nuget/nuget.exe"
  23. mkdir "nuget"
  24. Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $nugetExe
  25. &$nugetExe install Newtonsoft.Json -Version $newtonsoftVer -source https://api.nuget.org/v3/index.json -o $nugetBase
  26. &$nugetExe install Newtonsoft.Json.Schema -Version $newtonsoftSchemaVer -source https://api.nuget.org/v3/index.json -o $nugetBase
  27. &$nugetExe install Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version $codeDomProviderVer -source https://api.nuget.org/v3/index.json -o $nugetBase
  28. &$nugetExe install Microsoft.Net.Compilers.Toolset -Version $roslynVer -source https://api.nuget.org/v3/index.json -o $nugetBase
  29. }
  30. & docfx metadata
  31. if ((Test-Path $roslynCodeDom -PathType Leaf) -and (Test-Path $roslynInstall -PathType Container)) {
  32. # The files we need exist, lets do this!
  33. Write-Output "Generating Schema JSON"
  34. # Add the Roslyn CodeDom
  35. Add-Type -Path $roslynCodeDom
  36. # First load Newtonsoft
  37. Add-Type -Path $newtonsoftLoc
  38. Add-Type -Path $newtonsoftSchemaLoc
  39. # Read and parse special directives from SelfConfig
  40. function ProcessLines {
  41. begin {
  42. $inIgnoreSection = $false
  43. $ignoreNext = 0
  44. }
  45. process {
  46. if ( $_ -match "^\s*//\s+([A-Z]+):\s*(?:section)?\s+([a-zA-Z]+)(?:\s+(\d+))?\s*$" ) {
  47. $Begin = ($Matches[1] -eq "BEGIN")
  48. $End = ($Matches[1] -eq "END")
  49. $Line = ($Matches[1] -eq "LINE")
  50. $Num = if ($Matches[3].length -gt 0) { [int]($Matches[3]) } else { 1 }
  51. switch ($Matches[2]) {
  52. "ignore" {
  53. if ($Begin) { $inIgnoreSection = $true }
  54. if ($End) { $inIgnoreSection = $false }
  55. if ($Line) { $ignoreNext = $Num + 1 }
  56. }
  57. }
  58. }
  59. if ($inIgnoreSection) { "" }
  60. elseif ($ignoreNext -gt 0) { $ignoreNext = $ignoreNext - 1; return "" }
  61. else { $_ }
  62. }
  63. }
  64. function Merge-Lines {
  65. begin { $str = "" }
  66. process { $str = $str + "`n" + $_ }
  67. end { $str }
  68. }
  69. function FilterDef {
  70. process { $_ -replace "internal", "public" }
  71. }
  72. # set up the compiler settings
  73. Invoke-Expression -Command @"
  74. class RoslynCompilerSettings : Microsoft.CodeDom.Providers.DotNetCompilerPlatform.ICompilerSettings
  75. {
  76. [string] get_CompilerFullPath()
  77. {
  78. return "$roslynInstall\csc.exe"
  79. }
  80. [int] get_CompilerServerTimeToLive()
  81. {
  82. return 10
  83. }
  84. }
  85. "@
  86. $codeDomProvider = [Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider]::new([RoslynCompilerSettings]::new())
  87. Add-Type -CodeDomProvider $codeDomProvider -TypeDefinition (Get-Content $selfConfigLoc | ProcessLines | Merge-Lines | FilterDef) -ReferencedAssemblies $newtonsoftLoc,"netstandard"
  88. # type will be [IPA.Config.SelfConfig]
  89. # Generate schema
  90. $schemagen = New-Object -TypeName Newtonsoft.Json.Schema.Generation.JSchemaGenerator
  91. $schemagen.DefaultRequired = [Newtonsoft.Json.Required]::Always
  92. $schema = $schemagen.Generate([IPA.Config.SelfConfig])
  93. $schema.ToString() | Out-File "other_api/config/_schema.json"
  94. } else {
  95. Write-Output "Cannot generate schema JSON"
  96. }
  97. $ipaExe = "$ipaRoot/bin/Release/net472/IPA.exe"
  98. # generate IPA.exe args file
  99. if (-not (Test-Path $ipaExe -PathType Leaf)) {
  100. msbuild -t:Restore -p:Configuration=Release -p:Platform=AnyCPU -p:SolutionDir=.. "$ipaRoot/IPA.csproj"
  101. msbuild -p:Configuration=Release -p:Platform=AnyCPU -p:SolutionDir=.. "$ipaRoot/IPA.csproj"
  102. }
  103. & "$ipaExe" --help > .\articles\_ipa_command_line.txt
  104. & docfx build --globalMetadataFiles link_branch.json @Args
  105. if ($lastexitcode -ne 0) {
  106. throw [System.Exception] "docfx build failed with exit code $lastexitcode."
  107. }