build: Allow building on non-terraform named directory (#25340)

* Allow building on non-terraform named directory

* Fix gofmt errors

* Fix generate-plugins.go unused variable error
This commit is contained in:
Julian Grinblat 2020-06-27 01:07:58 +09:00 committed by GitHub
parent 81b83763e9
commit 0b3c0f64c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -61,7 +61,7 @@ gox \
-arch="${XC_ARCH}" \ -arch="${XC_ARCH}" \
-osarch="${XC_EXCLUDE_OSARCH}" \ -osarch="${XC_EXCLUDE_OSARCH}" \
-ldflags "${LD_FLAGS}" \ -ldflags "${LD_FLAGS}" \
-output "pkg/{{.OS}}_{{.Arch}}/${PWD##*/}" \ -output "pkg/{{.OS}}_{{.Arch}}/terraform" \
. .
# Move all the compiled things to the $GOPATH/bin # Move all the compiled things to the $GOPATH/bin

View File

@ -19,9 +19,8 @@ import (
const target = "command/internal_plugin_list.go" const target = "command/internal_plugin_list.go"
func main() { func main() {
wd, _ := os.Getwd() if isProjectRoot() == false {
if filepath.Base(wd) != "terraform" { log.Fatalf("This program must be invoked in the terraform project root")
log.Fatalf("This program must be invoked in the terraform project root; in %s", wd)
} }
//// Collect all of the data we need about plugins we have in the project //// Collect all of the data we need about plugins we have in the project
@ -80,6 +79,15 @@ func makeProviderMap(items []plugin) string {
return output return output
} }
func isProjectRoot() bool {
_, err := os.Stat("go.mod")
if os.IsNotExist(err) {
return false
}
return true
}
// makeProvisionerMap creates a map of provisioners like this: // makeProvisionerMap creates a map of provisioners like this:
// //
// "chef": chefprovisioner.Provisioner, // "chef": chefprovisioner.Provisioner,