-
Notifications
You must be signed in to change notification settings - Fork 877
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
Many build.ps1 improvements #15135
Many build.ps1 improvements #15135
Changes from 11 commits
838f9aa
73ae0e4
601e4e2
4f081bc
fcf7db4
98870a0
e607697
adebe93
7bfe8ba
1238b3e
428d589
3c8dbd7
ef524e0
fd6ab1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,74 @@ | ||
#Requires -Version 7.0 | ||
param($filter, [switch]$clean, [switch]$vet, [switch]$generate, [switch]$skipBuild) | ||
param([string]$filter, [switch]$clean, [switch]$vet, [switch]$generate, [switch]$skipBuild, [string]$config = "autorest.md", [string]$outputFolder) | ||
|
||
. $PSScriptRoot/meta_generation.ps1 | ||
. $PSScriptRoot/get_module_dirs.ps1 | ||
|
||
$startingDirectory = Get-Location | ||
$root = Resolve-Path ($PSScriptRoot + "/../..") | ||
Set-Location $root | ||
$sdks = @{}; | ||
|
||
foreach ($sdk in (./eng/scripts/get_module_dirs.ps1 -serviceDir 'sdk/...')) { | ||
$name = $sdk | split-path -leaf | ||
$sdks[$name] = @{ | ||
'path' = $sdk; | ||
'clean' = $clean; | ||
'vet' = $vet; | ||
'generate' = $generate; | ||
'skipBuild' = $skipBuild; | ||
'root' = $root; | ||
} | ||
} | ||
|
||
$keys = $sdks.Keys | Sort-Object; | ||
if (![string]::IsNullOrWhiteSpace($filter)) { | ||
Write-Host "Using filter: $filter" | ||
$keys = $keys.Where( { $_ -match $filter }) | ||
} | ||
|
||
$keys | ForEach-Object { $sdks[$_] } | ForEach-Object { | ||
Push-Location $_.path | ||
|
||
if ($_.clean) { | ||
Write-Host "##[command]Executing go clean -v ./... in " $_.path | ||
function Process-Sdk ($path) { | ||
if ($clean) { | ||
Write-Host "##[command]Executing go clean -v ./... in " $path | ||
go clean -v ./... | ||
} | ||
|
||
if ($_.generate) { | ||
Write-Host "##[command]Executing autorest.go in " $_.path | ||
$autorestPath = $_.path + "/autorest.md" | ||
if ($generate) { | ||
Write-Host "##[command]Executing autorest.go in " $path | ||
$autorestPath = $path + "/" + $config | ||
|
||
if (ShouldGenerate-AutorestConfig $autorestPath) { | ||
Generate-AutorestConfig $autorestPath | ||
$removeAutorestFile = $true | ||
} | ||
|
||
$autorestVersion = "@autorest/go@4.0.0-preview.23" | ||
$outputFolder = $_.path | ||
$root = $_.root | ||
if ($outputFolder -eq '') { | ||
$outputFolder = $path | ||
} | ||
autorest --use=$autorestVersion --go --track2 --go-sdk-folder=$root --output-folder=$outputFolder --file-prefix="zz_generated_" --clear-output-folder=false $autorestPath | ||
if ($removeAutorestFile) { | ||
Remove-Item $autorestPath | ||
} | ||
} | ||
if (!$_.skipBuild) { | ||
Write-Host "##[command]Executing go build -v ./... in " $_.path | ||
|
||
if (!$skipBuild) { | ||
Write-Host "##[command]Executing go build -x -v ./... in " $path | ||
go build -x -v ./... | ||
Write-Host "##[command]Build Complete!" | ||
|
||
} | ||
if ($_.vet) { | ||
Write-Host "##[command]Executing go vet ./... in " $_.path | ||
|
||
if ($vet) { | ||
Write-Host "##[command]Executing go vet ./... in " $path | ||
go vet ./... | ||
} | ||
Pop-Location | ||
|
||
} | ||
|
||
Set-Location $startingDirectory | ||
$startingDirectory = Get-Location | ||
$root = Resolve-Path ($PSScriptRoot + "/../..") | ||
Set-Location $root | ||
$sdks = @{}; | ||
|
||
foreach ($sdk in (Get-ModuleDirs 'sdk/...')) { | ||
$name = $sdk | split-path -leaf | ||
$sdks[$name] = @{ | ||
'path' = $sdk; | ||
} | ||
} | ||
|
||
$keys = $sdks.Keys | Sort-Object; | ||
if (![string]::IsNullOrWhiteSpace($filter)) { | ||
Write-Host "Using filter: $filter" | ||
$keys = $keys.Where( { $_ -match $filter }) | ||
} | ||
|
||
try { | ||
$keys | ForEach-Object { $sdks[$_] } | ForEach-Object { | ||
Push-Location $_.path | ||
Process-Sdk $_.path | ||
Pop-Location | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I'm looking at my suggestion, I'm not convinced it's any better, but since I already wrote it I might as well show you. If you default the filter value to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'm not sure I like yours better, but that is very interesting. I didn't realize you could do that in a one liner. |
||
finally { | ||
Set-Location $startingDirectory | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,20 @@ Param( | |
[string] $serviceDir | ||
) | ||
|
||
$modDirs = [Collections.Generic.List[String]]@() | ||
function Get-ModuleDirs ([string] $serviceDir) { | ||
$modDirs = [Collections.Generic.List[String]]@() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another nit, can we keep whitespacing consistent, this looks like two space tabs, but build.ps1 looks like four space tabs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pre-existing ps1 code was all 2 spaces, but that is not my preferred spacing at all. Hey @benbp is there a standard spacing for powershell code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only source I can find. I also prefer four spaces in general. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using the built in code formatter on save in VSCode, and had some trouble convincing it to do what I wanted: "editor.tabSize": 4,
"editor.detectIndentation": false did the job. |
||
|
||
# find each module directory under $serviceDir | ||
Get-Childitem -recurse -path $serviceDir -filter go.mod | foreach-object { | ||
$cdir = $_.Directory | ||
Write-Host "Adding $cdir to list of module paths" | ||
$modDirs.Add($cdir) | ||
# find each module directory under $serviceDir | ||
Get-Childitem -recurse -path $serviceDir -filter go.mod | foreach-object { | ||
chamons marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$cdir = $_.Directory | ||
Write-Host "Adding $cdir to list of module paths" | ||
$modDirs.Add($cdir) | ||
} | ||
|
||
# return the list of module directories | ||
return $modDirs | ||
} | ||
|
||
# return the list of module directories | ||
return $modDirs | ||
if ($MyInvocation.InvocationName -ne ".") { | ||
Get-ModuleDirs $serviceDir | ||
} |
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.
Should we look the version up from a file or pass via argument? This string is likely to get out of date
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.
My idea was that this was the single place we'd bump the autorest version.
I could move it out to another file, but in any case there will be one place to rule them all.