Skip to content

Commit

Permalink
Merge pull request #4713 from andydotxyz/fix/fyneget122
Browse files Browse the repository at this point in the history
Move from go get to git clone for fyne get
  • Loading branch information
andydotxyz authored Apr 4, 2024
2 parents b703cfe + 7995422 commit 7e354e0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
40 changes: 24 additions & 16 deletions cmd/fyne/internal/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (

"github.com/urfave/cli/v2"
"golang.org/x/sys/execabs"

//lint:ignore SA1019 The recommended replacement does not solve the use-case
"golang.org/x/tools/go/vcs"
)

// Get returns the command which downloads and installs fyne applications.
Expand Down Expand Up @@ -57,20 +60,37 @@ func NewGetter() *Getter {

// Get automates the download and install of a named GUI app package.
func (g *Getter) Get(pkg string) error {
cmd := execabs.Command("go", "get", "-u", "-d", pkg)
cmd.Env = append(os.Environ(), "GO111MODULE=off") // cache the downloaded code
name := filepath.Base(pkg)
path, err := os.MkdirTemp("", fmt.Sprintf("fyne-get-%s-*", name))
if err != nil {
return err
}
defer os.RemoveAll(path)

repo, err := vcs.RepoRootForImportPath(pkg, false)
if err != nil {
return fmt.Errorf("failed to look up source control for package: %w", err)
}
if repo.VCS.Name != "Git" {
return errors.New("unsupported VCS: " + repo.VCS.Name)
}
cmd := execabs.Command("git", "clone", repo.Repo, "--depth=1", path)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr

err := cmd.Run()
err = cmd.Run()
if err != nil {
return err
}

path := filepath.Join(goPath(), "src", pkg)
if !util.Exists(path) { // the error above may be ignorable, unless the path was not found
return err
}

if repo.Root != pkg {
dir := strings.Replace(pkg, repo.Root, "", 1)
path = filepath.Join(path, dir)
}

install := &Installer{appData: g.appData, srcDir: path, release: true}
if err := install.validate(); err != nil {
return fmt.Errorf("failed to set up installer: %w", err)
Expand Down Expand Up @@ -121,15 +141,3 @@ func (g *Getter) Run(args []string) {
os.Exit(1)
}
}

func goPath() string {
cmd := execabs.Command("go", "env", "GOPATH")
out, err := cmd.CombinedOutput()

if err != nil {
home, _ := os.UserHomeDir()
return filepath.Join(home, "go")
}

return strings.TrimSpace(string(out[0 : len(out)-1]))
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
golang.org/x/sys v0.16.0
golang.org/x/text v0.14.0
golang.org/x/tools v0.16.1
golang.org/x/tools/go/vcs v0.1.0-deprecated
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools/go/vcs v0.1.0-deprecated h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4=
golang.org/x/tools/go/vcs v0.1.0-deprecated/go.mod h1:zUrvATBAvEI9535oC0yWYsLsHIV4Z7g63sNPVMtuBy8=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down

0 comments on commit 7e354e0

Please sign in to comment.