From 0b3c0f64c2f2b696a6163ecc6b9cb9aec46ea149 Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Sat, 27 Jun 2020 01:07:58 +0900 Subject: [PATCH] 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 --- scripts/build.sh | 2 +- scripts/generate-plugins.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 344e39d69..ef5c1c2e3 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -61,7 +61,7 @@ gox \ -arch="${XC_ARCH}" \ -osarch="${XC_EXCLUDE_OSARCH}" \ -ldflags "${LD_FLAGS}" \ - -output "pkg/{{.OS}}_{{.Arch}}/${PWD##*/}" \ + -output "pkg/{{.OS}}_{{.Arch}}/terraform" \ . # Move all the compiled things to the $GOPATH/bin diff --git a/scripts/generate-plugins.go b/scripts/generate-plugins.go index 0859fe5a2..24030bcf6 100644 --- a/scripts/generate-plugins.go +++ b/scripts/generate-plugins.go @@ -19,9 +19,8 @@ import ( const target = "command/internal_plugin_list.go" func main() { - wd, _ := os.Getwd() - if filepath.Base(wd) != "terraform" { - log.Fatalf("This program must be invoked in the terraform project root; in %s", wd) + if isProjectRoot() == false { + log.Fatalf("This program must be invoked in the terraform project root") } //// 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 } +func isProjectRoot() bool { + _, err := os.Stat("go.mod") + if os.IsNotExist(err) { + return false + } + + return true +} + // makeProvisionerMap creates a map of provisioners like this: // // "chef": chefprovisioner.Provisioner,