Skip to content

Commit

Permalink
fyne build will only support building relative and absolute path for …
Browse files Browse the repository at this point in the history
…the moment.
  • Loading branch information
Cedric BAIL committed Jan 13, 2023
1 parent b1e4001 commit 2772c95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
14 changes: 6 additions & 8 deletions cmd/fyne/internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,18 @@ func (b *Builder) build() error {
}

func (b *Builder) computeSrcDir(fyneGoModRunner runner) (string, error) {
if b.goPackage == "" {
if b.goPackage == "" || b.goPackage == "." {
return b.srcdir, nil
}

srcdir := b.srcdir
if strings.HasPrefix(b.goPackage, "./") {
if strings.HasPrefix(b.goPackage, "."+string(os.PathSeparator)) ||
strings.HasPrefix(b.goPackage, ".."+string(os.PathSeparator)) {
srcdir = filepath.Join(srcdir, b.goPackage)
} else if strings.HasPrefix(b.goPackage, string(os.PathSeparator)) {
srcdir = b.goPackage
} else {
// get the output of go env GOROOT
goroot, err := fyneGoModRunner.runOutput("env", "GOROOT")
if err != nil {
return "", err
}
srcdir = filepath.Join(strings.TrimSpace(string(goroot)), "src", b.goPackage)
return "", fmt.Errorf("unrecognized go package: %s", b.goPackage)
}
return srcdir, nil
}
Expand Down
10 changes: 2 additions & 8 deletions cmd/fyne/internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,6 @@ func Test_BuildWasmOldVersion(t *testing.T) {

func Test_BuildLinuxReleaseVersion(t *testing.T) {
expected := []mockRunner{
{
expectedValue: expectedValue{args: []string{"env", "GOROOT"}},
mockReturn: mockReturn{
ret: []byte("/usr/lib/go"),
},
},
{
expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}},
mockReturn: mockReturn{
Expand All @@ -246,7 +240,7 @@ func Test_BuildLinuxReleaseVersion(t *testing.T) {
},
{
expectedValue: expectedValue{
args: []string{"build", "-ldflags", "-s -w", "-trimpath", "-tags", "release", "cmd/terminal"},
args: []string{"build", "-ldflags", "-s -w", "-trimpath", "-tags", "release", "./cmd/terminal"},
env: []string{"CGO_ENABLED=1", "GOOS=linux"},
osEnv: true,
dir: "myTest",
Expand All @@ -258,7 +252,7 @@ func Test_BuildLinuxReleaseVersion(t *testing.T) {
}

linuxBuildTest := &testCommandRuns{runs: expected, t: t}
b := &Builder{appData: &appData{}, os: "linux", srcdir: "myTest", release: true, runner: linuxBuildTest, goPackage: "cmd/terminal"}
b := &Builder{appData: &appData{}, os: "linux", srcdir: "myTest", release: true, runner: linuxBuildTest, goPackage: "./cmd/terminal"}
err := b.build()
assert.Nil(t, err)
linuxBuildTest.verifyExpectation()
Expand Down

0 comments on commit 2772c95

Please sign in to comment.