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

Move from go get to git clone for fyne get #4713

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 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"
Jacalz marked this conversation as resolved.
Show resolved Hide resolved
)

// Get returns the command which downloads and installs fyne applications.
Expand Down Expand Up @@ -57,20 +60,36 @@ 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 := filepath.Join(os.TempDir(), name)
if util.Exists(path) {
_ = os.Remove(path)
Jacalz marked this conversation as resolved.
Show resolved Hide resolved
}

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 +140,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