Skip to content
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 45 additions & 40 deletions eng/scripts/build.ps1
Original file line number Diff line number Diff line change
@@ -1,67 +1,72 @@
#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

$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]"
Copy link
Member

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

Copy link
Contributor Author

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.

$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 -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

}

$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;
}
}

$keys = $sdks.Keys | Sort-Object;
if (![string]::IsNullOrWhiteSpace($filter)) {
Write-Host "Using filter: $filter"
$keys = $keys.Where( { $_ -match $filter })
}

Set-Location $startingDirectory
try {
$keys | ForEach-Object { $sdks[$_] } | ForEach-Object {
Push-Location $_.path
Process-Sdk $_.path
Pop-Location
}
}
Copy link
Member

Choose a reason for hiding this comment

The 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 .* then you can avoid all the extra data manipulation with one pipeline:

try {
    $sdks.GetEnumerator()
    | Where-Object {
      Write-Host "Using filter: $filter"
      $_.key -match $filter
    }
    | Sort-Object -Property key
    | ForEach-Object {
        Push-Location $_.value.path
        Process-Sdk $_.value.path
        Pop-Location
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}