-
Notifications
You must be signed in to change notification settings - Fork 848
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
add clear output flag to build.ps1 #15255
Changes from 2 commits
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,19 +1,25 @@ | ||
#Requires -Version 7.0 | ||
param([string]$filter, [switch]$clean, [switch]$vet, [switch]$generate, [switch]$skipBuild, [switch]$format, [switch]$tidy, [string]$config = "autorest.md", [string]$outputFolder) | ||
param([string]$filter, [switch]$clean, [switch]$vet, [switch]$generate, [switch]$skipBuild, [switch]$clearOutput, [switch]$format, [switch]$tidy, [string]$config = "autorest.md", [string]$outputFolder) | ||
|
||
. $PSScriptRoot/meta_generation.ps1 | ||
. $PSScriptRoot/get_module_dirs.ps1 | ||
|
||
|
||
function Process-Sdk ($path) { | ||
function Process-Sdk () { | ||
$currentDirectory = Get-Location | ||
if ($clean) { | ||
Write-Host "##[command]Executing go clean -v ./... in " $path | ||
Write-Host "##[command]Executing go clean -v ./... in " $currentDirectory | ||
go clean -v ./... | ||
} | ||
|
||
if ($clearOutput) { | ||
Write-Host "##[command]Cleaning auto-generated files in" $currentDirectory | ||
rm "zz_generated_*" | ||
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. Only some of these commands actually seem to use 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 actually do not know what the command Based on the only invocation of this function, $path is identical with local directory, therefore we do not have a bug here. I agree we should unify the usage of path here. But actually I do not like the way that we are passing the absolute path everywhere - how about we just remove the $path parameter from this function and make sure this function only takes effects in whatever the current directory is. The caller should ensure we are in the correct directory first, and then invoke this function, like this script does. 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 realizing I think the only consideration with absolute pathing is when you're running scripts to work against multiple project directories, error handling/control flow becomes a little simpler because you won't get dropped into subdirectories accidentally and you don't have to handle pushd/popd all over the place. Additionally if the scripts ever need to reference calls to other scripts/tools, then having one consistent script directory is more convenient (though I think just using 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 case here is that based on my understanding of how the go tools work (which might not be correct), some of them should either accept a relative directory (go vet for instance), or a full package identifier which is not necessary to be an absolute path. Therefore I prefer to use the relative path in the invocations of commands. |
||
} | ||
|
||
if ($generate) { | ||
Write-Host "##[command]Executing autorest.go in " $path | ||
$autorestPath = $path + "/" + $config | ||
Write-Host "##[command]Executing autorest.go in " $currentDirectory | ||
$autorestPath = "./" + $config | ||
|
||
if (ShouldGenerate-AutorestConfig $autorestPath) { | ||
Generate-AutorestConfig $autorestPath | ||
|
@@ -22,7 +28,7 @@ function Process-Sdk ($path) { | |
|
||
$autorestVersion = "@autorest/go@4.0.0-preview.25" | ||
if ($outputFolder -eq '') { | ||
$outputFolder = $path | ||
$outputFolder = $currentDirectory | ||
} | ||
autorest --use=$autorestVersion --go --track2 --go-sdk-folder=$root --output-folder=$outputFolder --file-prefix="zz_generated_" --clear-output-folder=false $autorestPath | ||
if ($LASTEXITCODE) { | ||
|
@@ -35,24 +41,24 @@ function Process-Sdk ($path) { | |
} | ||
|
||
if ($format) { | ||
Write-Host "##[command]Executing gofmt -s -w . in " $path | ||
gofmt -s -w $path | ||
Write-Host "##[command]Executing gofmt -s -w . in " $currentDirectory | ||
gofmt -s -w . | ||
} | ||
|
||
if ($tidy) { | ||
Write-Host "##[command]Executing go mod tidy in " $path | ||
Write-Host "##[command]Executing go mod tidy in " $currentDirectory | ||
go mod tidy | ||
} | ||
|
||
if (!$skipBuild) { | ||
Write-Host "##[command]Executing go build -x -v ./... in " $path | ||
Write-Host "##[command]Executing go build -x -v ./... in " $currentDirectory | ||
go build -x -v ./... | ||
Write-Host "##[command]Build Complete!" | ||
|
||
} | ||
|
||
if ($vet) { | ||
Write-Host "##[command]Executing go vet ./... in " $path | ||
Write-Host "##[command]Executing go vet ./... in " $currentDirectory | ||
go vet ./... | ||
} | ||
|
||
|
@@ -79,7 +85,7 @@ if (![string]::IsNullOrWhiteSpace($filter)) { | |
try { | ||
$keys | ForEach-Object { $sdks[$_] } | ForEach-Object { | ||
Push-Location $_.path | ||
Process-Sdk $_.path | ||
Process-Sdk | ||
Pop-Location | ||
} | ||
} | ||
|
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.
Given this script is used in other contexts, a more descriptive parameter name like
cleanAutogeneratedFiles
or something might be better.