Skip to content

Commit

Permalink
commands/package-web: check go1.24 ./lib/wasm/ for wasm_exec.js
Browse files Browse the repository at this point in the history
Co-authored-by: Jacalz <[email protected]>
  • Loading branch information
adamdecaf and Jacalz committed Feb 25, 2025
1 parent 0574526 commit 93ea670
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/fyne/internal/commands/package-web.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func (w webData) packageWebInternal(appDir string, exeWasmSrc string, exeJSSrc s
return err
}

wasmExecSrc := filepath.Join(runtime.GOROOT(), "misc", "wasm", "wasm_exec.js")
goroot := runtime.GOROOT()
wasmExecSrc := filepath.Join(goroot, "lib", "wasm", "wasm_exec.js")
if !util.Exists(wasmExecSrc) { // Fallback for Go < 1.24:
wasmExecSrc = filepath.Join(goroot, "misc", "wasm", "wasm_exec.js")
}
wasmExecDst := filepath.Join(appDir, "wasm_exec.js")
err = util.CopyFile(wasmExecSrc, wasmExecDst)
if err != nil {
Expand Down
15 changes: 13 additions & 2 deletions cmd/fyne/internal/commands/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,27 @@ func Test_PackageWasm(t *testing.T) {
return expectedEnsureSubDirRuns.verifyExpectation(t, parent, name)
}

// Handle lookup for wasm_exec.js from lib folder in Go 1.24 and newer:
goroot := runtime.GOROOT()
wasmExecJSPath := filepath.Join(goroot, "lib", "wasm", "wasm_exec.js")
_, err := os.Stat(wasmExecJSPath)
execJSLibExists := err == nil || !os.IsNotExist(err)

expectedExistRuns := mockExistRuns{
expected: []mockExist{
{"myTest.wasm", false},
{"myTest.wasm", true},
{wasmExecJSPath, execJSLibExists},
},
}
utilExistsMock = func(path string) bool {
return expectedExistRuns.verifyExpectation(t, path)
}

if !execJSLibExists { // Expect location from Go < 1.24 to have been copied:
wasmExecJSPath = filepath.Join(goroot, "misc", "wasm", "wasm_exec.js")
}

expectedWriteFileRuns := mockWriteFileRuns{
expected: []mockWriteFile{
{filepath.Join("myTestTarget", "wasm", "index.html"), nil},
Expand All @@ -265,15 +276,15 @@ func Test_PackageWasm(t *testing.T) {
expectedCopyFileRuns := mockCopyFileRuns{
expected: []mockCopyFile{
{source: "myTest.png", target: filepath.Join("myTestTarget", "wasm", "icon.png")},
{source: filepath.Join(runtime.GOROOT(), "misc", "wasm", "wasm_exec.js"), target: filepath.Join("myTestTarget", "wasm", "wasm_exec.js")},
{source: wasmExecJSPath, target: filepath.Join("myTestTarget", "wasm", "wasm_exec.js")},
{source: "myTest.wasm", target: filepath.Join("myTestTarget", "wasm", "myTest.wasm")},
},
}
utilCopyFileMock = func(source, target string) error {
return expectedCopyFileRuns.verifyExpectation(t, false, source, target)
}

err := p.doPackage(wasmBuildTest)
err = p.doPackage(wasmBuildTest)
assert.Nil(t, err)
wasmBuildTest.verifyExpectation()
expectedTotalCount(t, len(expectedEnsureSubDirRuns.expected), expectedEnsureSubDirRuns.current)
Expand Down

0 comments on commit 93ea670

Please sign in to comment.