forked from Azure/azure-sdk-for-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Many build.ps1 improvements (Azure#15135)
- Fixes Azure#15128 - Fixes Azure#15127 - Part of Azure#15102
- Loading branch information
1 parent
3fb603c
commit 57c737a
Showing
5 changed files
with
78 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -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/[email protected]" | ||
$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 | ||
} | ||
} | ||
finally { | ||
Set-Location $startingDirectory | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
Param( | ||
[string] $serviceDir | ||
[string] $serviceDir | ||
) | ||
|
||
$modDirs = [Collections.Generic.List[String]]@() | ||
function Get-ModuleDirs ([string] $serviceDir) { | ||
$modDirs = [Collections.Generic.List[String]]@() | ||
|
||
# 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 { | ||
$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 | ||
} |
This file contains 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 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