Skip to content

Commit 015c3ea

Browse files
authored
Clean up vestiges of goimports (#15652)
1 parent abf05ff commit 015c3ea

File tree

4 files changed

+2
-69
lines changed

4 files changed

+2
-69
lines changed

docs/content/develop/set-up-dev-environment.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ development environment.
3434
# Add Go binaries to PATH
3535
export PATH=$PATH:$(go env GOPATH)/bin
3636
```
37-
1. Install goimports
38-
```bash
39-
go install golang.org/x/tools/cmd/goimports@latest
40-
```
4137
1. [Install terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)
4238
1. Clone the `magic-modules` repository
4339
```bash
@@ -57,8 +53,6 @@ development environment.
5753
```
5854
Check for go in path...
5955
found!
60-
Check for goimports in path...
61-
found!
6256
Check for git in path...
6357
found!
6458
Check for terraform in path...

mmv1/main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ var providerFlag = flag.String("provider", "", "optional provider name. If speci
4040

4141
var openapiGenerate = flag.Bool("openapi-generate", false, "Generate MMv1 YAML from openapi directory (Experimental)")
4242

43-
var showImportDiffsFlag = flag.Bool("show-import-diffs", false, "write go import diffs to stdout")
44-
4543
func main() {
4644

4745
// Handle all flags in main. Other functions must not access flag values directly.
@@ -58,10 +56,10 @@ func main() {
5856
return
5957
}
6058

61-
GenerateProducts(*productFlag, *resourceFlag, *providerFlag, *versionFlag, *outputPathFlag, *overrideDirectoryFlag, !*doNotGenerateCode, !*doNotGenerateDocs, *showImportDiffsFlag)
59+
GenerateProducts(*productFlag, *resourceFlag, *providerFlag, *versionFlag, *outputPathFlag, *overrideDirectoryFlag, !*doNotGenerateCode, !*doNotGenerateDocs)
6260
}
6361

64-
func GenerateProducts(product, resource, providerName, version, outputPath, overrideDirectory string, generateCode, generateDocs, showImportDiffs bool) {
62+
func GenerateProducts(product, resource, providerName, version, outputPath, overrideDirectory string, generateCode, generateDocs bool) {
6563
if version == "" {
6664
log.Printf("No version specified, assuming ga")
6765
version = "ga"
@@ -110,8 +108,6 @@ func GenerateProducts(product, resource, providerName, version, outputPath, over
110108
if generateCode {
111109
providerToGenerate.CompileCommonFiles(outputPath, productsForVersion, "")
112110
}
113-
114-
provider.FixImports(outputPath, showImportDiffs)
115111
}
116112

117113
// GenerateProduct generates code and documentation for a product

mmv1/provider/template_data.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ package provider
1515

1616
import (
1717
"bytes"
18-
"errors"
1918
"fmt"
2019
"go/format"
21-
"log"
2220
"os"
23-
"os/exec"
2421
"path/filepath"
25-
"strings"
26-
"sync"
2722
"text/template"
2823

2924
"github.com/GoogleCloudPlatform/magic-modules/mmv1/api"
@@ -46,8 +41,6 @@ var BETA_VERSION = "beta"
4641
var ALPHA_VERSION = "alpha"
4742
var PRIVATE_VERSION = "private"
4843

49-
var goimportFiles sync.Map
50-
5144
func NewTemplateData(outputFolder string, versionName string) *TemplateData {
5245
td := TemplateData{OutputFolder: outputFolder, VersionName: versionName}
5346
return &td
@@ -342,9 +335,6 @@ func (td *TemplateData) GenerateFile(filePath, templatePath string, input any, g
342335
} else {
343336
sourceByte = formattedByte
344337
}
345-
if !strings.Contains(templatePath, "third_party/terraform") {
346-
goimportFiles.Store(filePath, struct{}{})
347-
}
348338
}
349339

350340
err = os.WriteFile(filePath, sourceByte, 0644)
@@ -353,45 +343,6 @@ func (td *TemplateData) GenerateFile(filePath, templatePath string, input any, g
353343
}
354344
}
355345

356-
func FixImports(outputPath string, dumpDiffs bool) {
357-
log.Printf("Fixing go import paths")
358-
359-
baseArgs := []string{"-w"}
360-
if dumpDiffs {
361-
baseArgs = []string{"-d", "-w"}
362-
}
363-
364-
// -w and -d are mutually exclusive; if dumpDiffs is requested we need to run twice.
365-
for _, base := range baseArgs {
366-
hasFiles := false
367-
args := []string{base}
368-
goimportFiles.Range(func(filePath, _ any) bool {
369-
p, err := filepath.Rel(outputPath, filePath.(string))
370-
if err != nil {
371-
log.Fatal(err)
372-
}
373-
args = append(args, p)
374-
hasFiles = true
375-
return true
376-
})
377-
378-
if hasFiles {
379-
log.Printf("Fixing go import paths")
380-
cmd := exec.Command("echo", args...)
381-
cmd.Dir = outputPath
382-
cmd.Stdout = os.Stdout
383-
cmd.Stderr = os.Stderr
384-
if err := cmd.Run(); err != nil {
385-
var exitErr *exec.ExitError
386-
if errors.As(err, &exitErr) && len(exitErr.Stderr) > 0 {
387-
glog.Error(string(exitErr.Stderr))
388-
}
389-
log.Fatal(err)
390-
}
391-
}
392-
}
393-
}
394-
395346
type TestInput struct {
396347
Res api.Resource
397348
ImportPath string

scripts/doctor

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ else
5353
fi
5454
fi
5555

56-
count_in_path "goimports"
57-
if [ $found -eq 0 ]; then
58-
exitcode=1
59-
warn "yel" " goimports not found. Run 'go install golang.org/x/tools/cmd/goimports@latest' to install it."
60-
else
61-
warn "grn" " found!"
62-
fi
63-
6456
count_in_path "git"
6557
if [ $found -eq 0 ]; then
6658
exitcode=1

0 commit comments

Comments
 (0)