-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Introducing generate.ps1 to replace generate.cmd #4123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e81c192
Adding generate.ps1
dsgouda f9b72b8
Merge branch 'generateps1' of https://github.com/dsgouda/azure-sdk-fo…
dsgouda cba8728
better logging, hooks for generate.cmd
dsgouda 26560ec
Addressing comments
dsgouda e673886
Addressing PR comments
dsgouda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File "$(split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)\..\..\..\..\tools\generateTool.ps1" -ResourceProvider "compute/resource-manager" -SdkDirectory "$(split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)" -PowershellInvoker -AutoRestVersion "latest" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| <# | ||
|
|
||
| .SYNOPSIS | ||
| Powershell script that generates the C# code for your sdk usin the config file provided | ||
|
|
||
| .DESCRIPTION | ||
| This script: | ||
| - fetches the config file from user/branch provided | ||
| - Generates code based off the config file provided | ||
| - into the directory path provided | ||
|
|
||
| .PARAMETER ResourceProvider | ||
| The Resource provider for whom to generate the code; also helps determine path where config file is located in repo | ||
|
|
||
| .PARAMETER Version | ||
| The AutoRest version to use to generate the code, "latest" is recommended | ||
|
|
||
| .PARAMETER SpecsRepoFork | ||
| The Rest Spec repo fork which contains the config file | ||
|
|
||
| .PARAMETER SpecsRepoBranch | ||
| The Branch which contains the config file | ||
|
|
||
| .PARAMETER SpecsRepoName | ||
| The name of the repo that contains the config file (Can only be either of azure-rest-api-specs or azure-rest-api-specs-pr) | ||
|
|
||
| .PARAMETER SdkFolder | ||
| The path where to generate the code | ||
|
|
||
| .EXAMPLE | ||
| A sample command that uses the function or script, optionally followed | ||
| by sample output and a description. Repeat this keyword for each example. | ||
|
|
||
| .NOTES | ||
| Additional information about the function or script. | ||
|
|
||
| .LINK | ||
| The name of a related topic. Repeat this keyword for each related topic. | ||
|
|
||
| This content appears in the Related Links section of the Help topic. | ||
|
|
||
| The Link keyword content can also include a Uniform Resource Identifier | ||
| (URI) to an online version of the same Help topic. The online version | ||
| opens when you use the Online parameter of Get-Help. The URI must begin | ||
| with "http" or "https". | ||
| #> | ||
|
|
||
| Param( | ||
| [Parameter(Mandatory = $true)] | ||
| [string] $ResourceProvider = "compute/resource-manager", | ||
| [string] $SpecsRepoFork = "Azure", | ||
| [string] $SpecsRepoName = "azure-rest-api-specs", | ||
| [string] $SpecsRepoBranch = "master", | ||
| [Parameter(Mandatory = $true)] | ||
| [string] $SdkDirectory= "$([System.IO.Path]::GetTempPath())\Compute", | ||
| [string] $AutoRestVersion = "latest", | ||
| [switch] $PowershellInvoker | ||
| ) | ||
|
|
||
| Write-Host "autorest version received is : $AutoRestVersion" | ||
|
|
||
| $errorStream = New-Object -TypeName "System.Text.StringBuilder"; | ||
| $outputStream = New-Object -TypeName "System.Text.StringBuilder"; | ||
| $currPath = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent | ||
| $modulePath = "$currPath\SdkBuildTools\psModules\CodeGenerationModules\generateDotNetSdkCode.psm1" | ||
| $logFile = "$currPath\..\src\SDKs\_metadata\$($ResourceProvider.Replace("/","_")).txt" | ||
| $errorFile = "$currPath\SdkBuildTools\errorlog.txt" | ||
|
|
||
| function NotifyError { | ||
| param ( | ||
| [string] $errorMsg | ||
| ) | ||
| Write-Error $errorMsg | ||
| $errorMsg | Out-File -FilePath $errorFile | ||
| Start-Process "$errorFile" | ||
| } | ||
|
|
||
| if (-not ($modulePath | Test-Path)) { | ||
| NotifyError "Could not find code generation module at: $modulePath. Please run `msbuild build.proj` to install the module." | ||
| Exit -1 | ||
| } | ||
|
|
||
| Import-Module "$modulePath" | ||
|
|
||
| if (-not (Get-Module -ListAvailable -Name "$modulePath")) { | ||
| NotifyError "Could not find module: $modulePath. Please run `msbuild build.proj` to install the module." | ||
| Exit -1 | ||
| } | ||
|
|
||
| function Start-Script { | ||
| Write-InfoLog "Importing code generation module" -logToConsole | ||
|
|
||
| Install-AutoRest $AutoRestVersion | ||
|
|
||
| $configFile="https://github.com/$SpecsRepoFork/$SpecsRepoName/blob/$SpecsRepoBranch/specification/$ResourceProvider/readme.md" | ||
| Write-InfoLog "Commencing code generation" -logToConsole | ||
| Start-CodeGeneration -SpecsRepoFork $SpecsRepoFork -SpecsRepoBranch $SpecsRepoBranch -SdkDirectory $SdkDirectory -AutoRestVersion $AutoRestVersion -SpecsRepoName $SpecsRepoName | ||
|
|
||
| $invokerMessage = ".\tools\generate.ps1 was invoked by" | ||
| if($PowershellInvoker) { | ||
| $outputStream.Append("$invokerMessage generate.ps1") | Out-Null | ||
| } | ||
| else { | ||
| $outputStream.Append("$invokerMessage generate.cmd") | Out-Null | ||
| } | ||
|
|
||
| } | ||
|
|
||
| try { | ||
| Start-Script | ||
| } | ||
| catch { | ||
| Write-ErrorLog $_.ToString() -logToConsole | ||
| Write-ErrorLog $_.ToString() -logToFile | ||
| } | ||
| finally { | ||
| Get-OutputStream | Out-File -FilePath $logFile | Out-Null | ||
| Get-ErrorStream | Out-File -FilePath $logFile -Append | Out-Null | ||
| Clear-OutputStreams | ||
| Get-Module -Name "$modulePath" | Remove-Module | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsgouda just curios why can't we have line 78 to 88 wrapped in a function and that function getting called right before Start-Script on lin 110?
The sole reason I say that is because then in your entire scripts the only execution points are via function, no more free flowing execution of any script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without loading the module it won't be possible to move the execution of this piece of code in the
try..catch..finallyblock, the catch and finally block need some functions imported from the module itself (eg.Get-OutputStream)