Skip to content

Commit 0b3c0f6

Browse files
authored
build: Allow building on non-terraform named directory (hashicorp#25340)
* Allow building on non-terraform named directory * Fix gofmt errors * Fix generate-plugins.go unused variable error
1 parent 81b8376 commit 0b3c0f6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ gox \
6161
-arch="${XC_ARCH}" \
6262
-osarch="${XC_EXCLUDE_OSARCH}" \
6363
-ldflags "${LD_FLAGS}" \
64-
-output "pkg/{{.OS}}_{{.Arch}}/${PWD##*/}" \
64+
-output "pkg/{{.OS}}_{{.Arch}}/terraform" \
6565
.
6666

6767
# Move all the compiled things to the $GOPATH/bin

scripts/generate-plugins.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import (
1919
const target = "command/internal_plugin_list.go"
2020

2121
func main() {
22-
wd, _ := os.Getwd()
23-
if filepath.Base(wd) != "terraform" {
24-
log.Fatalf("This program must be invoked in the terraform project root; in %s", wd)
22+
if isProjectRoot() == false {
23+
log.Fatalf("This program must be invoked in the terraform project root")
2524
}
2625

2726
//// Collect all of the data we need about plugins we have in the project
@@ -80,6 +79,15 @@ func makeProviderMap(items []plugin) string {
8079
return output
8180
}
8281

82+
func isProjectRoot() bool {
83+
_, err := os.Stat("go.mod")
84+
if os.IsNotExist(err) {
85+
return false
86+
}
87+
88+
return true
89+
}
90+
8391
// makeProvisionerMap creates a map of provisioners like this:
8492
//
8593
// "chef": chefprovisioner.Provisioner,

0 commit comments

Comments
 (0)