Skip to content

Commit

Permalink
Many build.ps1 improvements (Azure#15135)
Browse files Browse the repository at this point in the history
- Fixes Azure#15128
- Fixes Azure#15127
- Part of Azure#15102
  • Loading branch information
chamons authored and vindicatesociety committed Sep 18, 2021
1 parent 3fb603c commit 57c737a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 65 deletions.
85 changes: 46 additions & 39 deletions eng/scripts/build.ps1
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
}
}
finally {
Set-Location $startingDirectory
}
10 changes: 5 additions & 5 deletions eng/scripts/create_go_workspace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# GO_WORKSPACE_PATH <- location of copied sources directory
# GO_PATH <- The value that should be set for the GO_PATH environment variable
Param(
[string] $goWorkSpaceDir,
[string] $orgOrUser = "Azure",
[string] $repo = "azure-sdk-for-go"
[string] $goWorkSpaceDir,
[string] $orgOrUser = "Azure",
[string] $repo = "azure-sdk-for-go"
)
$repoRoot = Resolve-Path "$PSScriptRoot/../../"

Expand All @@ -24,6 +24,6 @@ Write-Host "Root of new Go Workspace is $goWorkSpaceDir"
Copy-Item -Container -Recurse -Path "$repoRoot/*" -Destination $CreatedGoWorkspaceSrc

return New-Object PSObject -Property @{
GO_WORKSPACE_PATH = Resolve-Path $CreatedGoWorkspaceSrc
GO_PATH = Resolve-Path $goWorkSpaceDir
GO_WORKSPACE_PATH = Resolve-Path $CreatedGoWorkspaceSrc
GO_PATH = Resolve-Path $goWorkSpaceDir
}
24 changes: 15 additions & 9 deletions eng/scripts/get_module_dirs.ps1
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
}
16 changes: 8 additions & 8 deletions eng/scripts/get_test_dirs.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Param(
[string] $serviceDir
[string] $serviceDir
)

$testDirs = [Collections.Generic.List[String]]@()

# find each directory under $serviceDir that contains Go test files
Get-ChildItem -recurse -path $serviceDir -filter *_test.go | ForEach-Object {
$cdir = $_.Directory
$tests = Select-String -Path $_ 'Test' -AllMatches
$cdir = $_.Directory
$tests = Select-String -Path $_ 'Test' -AllMatches

if ($tests.Count -gt 0) {
if (!$testDirs.Contains($cdir)) {
Write-Host "Adding $cdir to list of test directories"
$testDirs.Add($cdir)
if ($tests.Count -gt 0) {
if (!$testDirs.Contains($cdir)) {
Write-Host "Adding $cdir to list of test directories"
$testDirs.Add($cdir)
}
}
}
}

# return the list of test directories
Expand Down
8 changes: 4 additions & 4 deletions eng/scripts/scoped_discover.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Param(
[string] $serviceDir = ""
[string] $serviceDir = ""
)

if($serviceDir){
$targetDir = "$PSScriptRoot/../../sdk/$serviceDir"
if ($serviceDir) {
$targetDir = "$PSScriptRoot/../../sdk/$serviceDir"
}
else {
$targetDir = "$PSScriptRoot/../../sdk"
$targetDir = "$PSScriptRoot/../../sdk"
}

$path = Resolve-Path -Path $targetDir
Expand Down

0 comments on commit 57c737a

Please sign in to comment.