Skip to content
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

Fix support for go1.18 #466

Merged
merged 6 commits into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
- Changed underlying cobra command setup to return errors instead of calling `os.Exit` directly to enable simpler testing. ([454](https://github.com/cucumber/godog/pull/454) - [mxygem])
- Remove use of deprecated methods from `_examples`. ([460](https://github.com/cucumber/godog/pull/460) - [ricardogarfe])

### Fixed

- Support for go1.18 in `godog` cli mode ([466](https://github.com/cucumber/godog/pull/466) - [vearutop])

## [v0.12.4]

### Added
Expand Down
25 changes: 25 additions & 0 deletions internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ func Build(bin string) error {
"-complete",
}

if err := filterImportCfg(compilerCfg); err != nil {
return err
}

args = append(args, "-pack", testmain)
cmd := exec.Command(compiler, args...)
cmd.Env = os.Environ()
Expand Down Expand Up @@ -234,6 +238,27 @@ func Build(bin string) error {
return nil
}

// filterImportCfg strips unsupported lines from imports configuration.
func filterImportCfg(path string) error {
orig, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("failed to read %s: %w", path, err)
}

res := ""
for _, l := range strings.Split(string(orig), "\n") {
if !strings.HasPrefix(l, "modinfo") {
res += l + "\n"
}
}
err = ioutil.WriteFile(path, []byte(res), 0600)
if err != nil {
return fmt.Errorf("failed to write %s: %w", path, err)
}

return nil
}

func maybeVendoredGodog() *build.Package {
dir, err := filepath.Abs(".")
if err != nil {
Expand Down