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.

103 lines
4.0 KiB

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