diff --git a/LICENSE b/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/README.md b/README.md index 48253c6af..5e5a02528 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,11 @@ and the [bind](https://golang.org/x/mobile/example/bind) example apps. -- -Contributions to Go are appreciated. See https://golang.org/doc/contribute.html. +Contributions to Go are appreciated. See https://go.dev/doc/contribute. -* Bugs can be filed at the [Go issue tracker](https://golang.org/issue/new?title=x/mobile:+). +The git repository is https://go.googlesource.com/mobile. + +* Bugs can be filed at the [Go issue tracker](https://go.dev/issue/new?title=x/mobile:+). * Feature requests should preliminary be discussed on [golang-nuts](https://groups.google.com/forum/#!forum/golang-nuts) mailing list. diff --git a/app/android.go b/app/android.go index 08a6e0538..5ee5605e4 100644 --- a/app/android.go +++ b/app/android.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build android -// +build android /* Android Apps are built with -buildmode=c-shared. They are loaded by a @@ -366,7 +365,7 @@ func runInputQueue(vm, jniEnv, ctx uintptr) error { var q *C.AInputQueue for { - if C.ALooper_pollAll(-1, nil, nil, nil) == C.ALOOPER_POLL_WAKE { + if C.ALooper_pollOnce(-1, nil, nil, nil) == C.ALOOPER_POLL_WAKE { select { default: case p := <-pending: diff --git a/app/app.go b/app/app.go index 19efb07f1..9817e13d7 100644 --- a/app/app.go +++ b/app/app.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build linux || darwin || windows -// +build linux darwin windows package app diff --git a/app/app_test.go b/app/app_test.go index 91742192b..9fa2a188a 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -9,7 +9,6 @@ import ( "image" "image/color" _ "image/png" - "io/ioutil" "net" "os" "os/exec" @@ -56,7 +55,7 @@ func TestAndroidApp(t *testing.T) { t.Fatal(err) } - tmpdir, err := ioutil.TempDir("", "app-test-") + tmpdir, err := os.MkdirTemp("", "app-test-") if err != nil { t.Fatal(err) } diff --git a/app/darwin_desktop.go b/app/darwin_desktop.go index 337717531..180c60278 100644 --- a/app/darwin_desktop.go +++ b/app/darwin_desktop.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin && !ios -// +build darwin,!ios package app diff --git a/app/darwin_ios.go b/app/darwin_ios.go index 8fb30fe82..bef9f4215 100644 --- a/app/darwin_ios.go +++ b/app/darwin_ios.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin && ios -// +build darwin,ios package app diff --git a/app/doc.go b/app/doc.go index 02bd6db80..2fabcd9de 100644 --- a/app/doc.go +++ b/app/doc.go @@ -85,4 +85,4 @@ response to lifecycle events. Such packages should call: in an init function inside that package. */ -package app // import "golang.org/x/mobile/app" +package app diff --git a/app/internal/callfn/callfn.go b/app/internal/callfn/callfn.go index 7a3d0506e..ecc3d456f 100644 --- a/app/internal/callfn/callfn.go +++ b/app/internal/callfn/callfn.go @@ -3,8 +3,6 @@ // license that can be found in the LICENSE file. //go:build android && (arm || 386 || amd64 || arm64) -// +build android -// +build arm 386 amd64 arm64 // Package callfn provides an android entry point. // diff --git a/app/internal/testapp/testapp.go b/app/internal/testapp/testapp.go index eb850955b..18a97bf6a 100644 --- a/app/internal/testapp/testapp.go +++ b/app/internal/testapp/testapp.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux -// +build darwin linux // Small test app used by app/app_test.go. package main diff --git a/app/shiny.go b/app/shiny.go index dd1722a27..0b4e3e550 100644 --- a/app/shiny.go +++ b/app/shiny.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build windows -// +build windows package app diff --git a/app/x11.go b/app/x11.go index ec8c90a54..7e85e137c 100644 --- a/app/x11.go +++ b/app/x11.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build linux && !android -// +build linux,!android package app diff --git a/asset/asset.go b/asset/asset.go index 5ed3a5c5a..d23656911 100644 --- a/asset/asset.go +++ b/asset/asset.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows package asset diff --git a/asset/asset_darwin_armx.go b/asset/asset_darwin_armx.go deleted file mode 100644 index 3eac25b04..000000000 --- a/asset/asset_darwin_armx.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build darwin && (arm || arm64) -// +build darwin -// +build arm arm64 - -package asset - -import ( - "os" - "path/filepath" -) - -func openAsset(name string) (File, error) { - if !filepath.IsAbs(name) { - name = filepath.Join("assets", name) - } - f, err := os.Open(name) - if err != nil { - return nil, err - } - return f, nil -} diff --git a/asset/asset_desktop.go b/asset/asset_desktop.go index a36099504..1c3805627 100644 --- a/asset/asset_desktop.go +++ b/asset/asset_desktop.go @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build (linux && !android) || (darwin && !arm && !arm64) || windows -// +build linux,!android darwin,!arm,!arm64 windows +//go:build (linux && !android) || (darwin && !ios) || windows package asset diff --git a/asset/asset_ios.go b/asset/asset_ios.go new file mode 100644 index 000000000..4b7b37f4e --- /dev/null +++ b/asset/asset_ios.go @@ -0,0 +1,13 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package asset + +import ( + "os" +) + +func openAsset(name string) (File, error) { + return os.Open(name) +} diff --git a/asset/doc.go b/asset/doc.go index b40d4a44d..37bb9bb34 100644 --- a/asset/doc.go +++ b/asset/doc.go @@ -14,4 +14,4 @@ // // For consistency when debugging on a desktop, assets are read from a // directory named assets under the current working directory. -package asset // import "golang.org/x/mobile/asset" +package asset diff --git a/bind/bind.go b/bind/bind.go index e5690835e..7c1b22e88 100644 --- a/bind/bind.go +++ b/bind/bind.go @@ -7,7 +7,7 @@ // See the documentation on the gobind command for usage details // and the list of currently supported types. // (http://godoc.org/golang.org/x/mobile/cmd/gobind) -package bind // import "golang.org/x/mobile/bind" +package bind // TODO(crawshaw): slice support // TODO(crawshaw): channel support diff --git a/bind/bind_test.go b/bind/bind_test.go index fae951b31..96288a4e2 100644 --- a/bind/bind_test.go +++ b/bind/bind_test.go @@ -1,3 +1,7 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package bind import ( @@ -11,7 +15,6 @@ import ( "go/token" "go/types" "io" - "io/ioutil" "log" "os" "os/exec" @@ -121,7 +124,7 @@ func diff(a, b string) string { } func writeTempFile(t *testing.T, name string, contents []byte) string { - f, err := ioutil.TempFile("", name) + f, err := os.CreateTemp("", name) if err != nil { t.Fatal(err) } @@ -215,14 +218,14 @@ func genObjcPackages(t *testing.T, dir string, cg *ObjcWrapper) { pkgFile := filepath.Join(pkgDir, "package.go") cg.Buf.Reset() cg.GenPackage(i) - if err := ioutil.WriteFile(pkgFile, cg.Buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(pkgFile, cg.Buf.Bytes(), 0600); err != nil { t.Fatal(err) } } cg.Buf.Reset() cg.GenInterfaces() clsFile := filepath.Join(pkgBase, "interfaces.go") - if err := ioutil.WriteFile(clsFile, cg.Buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(clsFile, cg.Buf.Bytes(), 0600); err != nil { t.Fatal(err) } @@ -254,7 +257,7 @@ func genJavaPackages(t *testing.T, dir string, cg *ClassGen) { pkgFile := filepath.Join(pkgDir, "package.go") cg.Buf.Reset() cg.GenPackage(i) - if err := ioutil.WriteFile(pkgFile, cg.Buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(pkgFile, cg.Buf.Bytes(), 0600); err != nil { t.Fatal(err) } io.Copy(buf, cg.Buf) @@ -262,7 +265,7 @@ func genJavaPackages(t *testing.T, dir string, cg *ClassGen) { cg.Buf.Reset() cg.GenInterfaces() clsFile := filepath.Join(pkgBase, "interfaces.go") - if err := ioutil.WriteFile(clsFile, cg.Buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(clsFile, cg.Buf.Bytes(), 0600); err != nil { t.Fatal(err) } io.Copy(buf, cg.Buf) @@ -302,7 +305,7 @@ func TestGenJava(t *testing.T) { } tmpGopath := "" if len(classes) > 0 { - tmpGopath, err = ioutil.TempDir(os.TempDir(), "gomobile-bind-test-") + tmpGopath, err = os.MkdirTemp(os.TempDir(), "gomobile-bind-test-") if err != nil { t.Fatal(err) } @@ -419,7 +422,7 @@ func TestGenGoJavaWrappers(t *testing.T) { if err != nil { t.Fatal(err) } - tmpGopath, err := ioutil.TempDir(os.TempDir(), "gomobile-bind-test-") + tmpGopath, err := os.MkdirTemp(os.TempDir(), "gomobile-bind-test-") if err != nil { t.Fatal(err) } @@ -449,7 +452,7 @@ func TestGenGoObjcWrappers(t *testing.T) { if err != nil { t.Fatal(err) } - tmpGopath, err := ioutil.TempDir(os.TempDir(), "gomobile-bind-test-") + tmpGopath, err := os.MkdirTemp(os.TempDir(), "gomobile-bind-test-") if err != nil { t.Fatal(err) } @@ -495,7 +498,7 @@ func testGenGo(t *testing.T, filename string, buf *bytes.Buffer, pkg *types.Pack } golden += ".golden" - goldenContents, err := ioutil.ReadFile(golden) + goldenContents, err := os.ReadFile(golden) if err != nil { t.Fatalf("failed to read golden file: %v", err) } diff --git a/bind/genclasses.go b/bind/genclasses.go index 8746ab27e..a69d02b36 100644 --- a/bind/genclasses.go +++ b/bind/genclasses.go @@ -381,7 +381,7 @@ func (g *ClassGen) genCMethodBody(cls *java.Class, f *java.Func, virtual bool) { g.Printf("Nonvirtual") } if f.Ret != nil { - g.Printf(f.Ret.JNICallType()) + g.Printf("%s", f.Ret.JNICallType()) } else { g.Printf("Void") } @@ -430,7 +430,7 @@ func (g *ClassGen) genFuncDecl(local bool, fs *java.FuncSet) { if i == len(fs.Params)-1 && fs.Variadic { g.Printf("...") } - g.Printf(g.goType(a, local)) + g.Printf("%s", g.goType(a, local)) } g.Printf(")") if fs.Throws { @@ -879,7 +879,7 @@ func (g *ClassGen) genInterface(cls *java.Class) { if !g.isFuncSetSupported(fs) { continue } - g.Printf(fs.GoName) + g.Printf("%s", fs.GoName) g.genFuncDecl(true, fs) g.Printf("\n") } @@ -904,7 +904,7 @@ func flattenName(n string) string { return strings.Replace(strings.Replace(n, ".", "_", -1), "$", "_", -1) } -var ( +const ( classesPkgHeader = gobindPreamble + ` package Java diff --git a/bind/gengo.go b/bind/gengo.go index 8087c7ad2..bb3634e4f 100644 --- a/bind/gengo.go +++ b/bind/gengo.go @@ -341,7 +341,7 @@ func (g *goGen) genInterface(obj *types.TypeName) { g.Printf(") ") if res.Len() == 1 { - g.Printf(g.typeString(res.At(0).Type())) + g.Printf("%s", g.typeString(res.At(0).Type())) } else if res.Len() == 2 { g.Printf("(%s, error)", g.typeString(res.At(0).Type())) } diff --git a/bind/genjava.go b/bind/genjava.go index b197640aa..f1852a2bc 100644 --- a/bind/genjava.go +++ b/bind/genjava.go @@ -437,7 +437,7 @@ func (g *JavaGen) genConstructor(f *types.Func, n string, jcls bool) { if i > 0 { g.Printf(", ") } - g.Printf(g.paramName(params, i)) + g.Printf("%s", g.paramName(params, i)) } g.Printf(");\n") } @@ -447,7 +447,7 @@ func (g *JavaGen) genConstructor(f *types.Func, n string, jcls bool) { if i > 0 { g.Printf(", ") } - g.Printf(g.paramName(params, i)) + g.Printf("%s", g.paramName(params, i)) } g.Printf(");\n") g.Printf("Seq.trackGoRef(refnum, this);\n") @@ -757,21 +757,21 @@ func (g *JavaGen) genJNIFuncSignature(o *types.Func, sName string, jm *java.Func g.Printf("Java_%s_", g.jniPkgName()) if sName != "" { if proxy { - g.Printf(java.JNIMangle(g.className())) + g.Printf("%s", java.JNIMangle(g.className())) // 0024 is the mangled form of $, for naming inner classes. g.Printf("_00024proxy%s", sName) } else { - g.Printf(java.JNIMangle(g.javaTypeName(sName))) + g.Printf("%s", java.JNIMangle(g.javaTypeName(sName))) } } else { - g.Printf(java.JNIMangle(g.className())) + g.Printf("%s", java.JNIMangle(g.className())) } g.Printf("_") if jm != nil { - g.Printf(jm.JNIName) + g.Printf("%s", jm.JNIName) } else { oName := javaNameReplacer(lowerFirst(o.Name())) - g.Printf(java.JNIMangle(oName)) + g.Printf("%s", java.JNIMangle(oName)) } g.Printf("(JNIEnv* env, ") if sName != "" { @@ -839,9 +839,9 @@ func (g *JavaGen) genFuncSignature(o *types.Func, jm *java.Func, hasThis bool) { g.Printf("%s ", ret) if jm != nil { - g.Printf(jm.Name) + g.Printf("%s", jm.Name) } else { - g.Printf(javaNameReplacer(lowerFirst(o.Name()))) + g.Printf("%s", javaNameReplacer(lowerFirst(o.Name()))) } g.Printf("(") g.genFuncArgs(o, jm, hasThis) diff --git a/bind/genobjc.go b/bind/genobjc.go index d0982207d..b556212a4 100644 --- a/bind/genobjc.go +++ b/bind/genobjc.go @@ -977,7 +977,7 @@ func (g *ObjcGen) genInterfaceMethodProxy(obj *types.TypeName, m *types.Func) { if isErrorType(obj.Type()) && m.Name() == "Error" { // As a special case, ObjC NSErrors are passed to Go pretending to implement the Go error interface. - // They don't actually have an Error method, so calls to to it needs to be rerouted. + // They don't actually have an Error method, so calls to it needs to be rerouted. g.Printf("%s = [o localizedDescription];\n", s.retParams[0].name) } else { if s.ret == "void" { @@ -1060,7 +1060,7 @@ func (g *ObjcGen) genStructH(obj *types.TypeName, t *types.Struct) { if oinf != nil { for _, sup := range oinf.supers { if !sup.Protocol { - g.Printf(sup.Name) + g.Printf("%s", sup.Name) } else { prots = append(prots, sup.Name) } diff --git a/bind/genobjcw.go b/bind/genobjcw.go index 1f5ccf63f..731f1ae51 100644 --- a/bind/genobjcw.go +++ b/bind/genobjcw.go @@ -286,14 +286,13 @@ func (g *ObjcWrapper) genCFuncDecl(prefix, name string, f *objc.Func) { case ret != nil && returnsErr: g.Printf("ret_%s", strings.Replace(g.cType(ret), " ", "_", -1)) case ret != nil: - g.Printf(g.cType(ret)) + g.Printf("%s", g.cType(ret)) case returnsErr: g.Printf("int") default: g.Printf("void") } - g.Printf(" ") - g.Printf(prefix) + g.Printf(" %s", prefix) if f.Static { g.Printf("_s") } @@ -397,8 +396,7 @@ func (g *ObjcWrapper) genFuncBody(n *objc.Named, f *objc.Func, prefix string) { if ret != nil || errParam != nil { g.Printf("res := ") } - g.Printf("C.") - g.Printf(prefix) + g.Printf("C.%s", prefix) if f.Static { g.Printf("_s") } @@ -575,7 +573,7 @@ func (g *ObjcWrapper) genInterface(n *objc.Named) { if !g.isFuncSupported(f) { continue } - g.Printf(f.GoName) + g.Printf("%s", f.GoName) g.genFuncDecl(true, f) g.Printf("\n") } diff --git a/bind/implicit.go b/bind/implicit.go index 5144209c3..bf1d418c0 100644 --- a/bind/implicit.go +++ b/bind/implicit.go @@ -1,7 +1,6 @@ // This file imports implicit dependencies required by generated code. //go:build mobile_implicit -// +build mobile_implicit package bind diff --git a/bind/java/context_android.go b/bind/java/context_android.go index dc4443130..ee77a7e8a 100644 --- a/bind/java/context_android.go +++ b/bind/java/context_android.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package java // import "golang.org/x/mobile/bind/java" +package java // #cgo LDFLAGS: -llog // diff --git a/bind/java/seq_test.go b/bind/java/seq_test.go index a5151d40b..4d9cd2fda 100644 --- a/bind/java/seq_test.go +++ b/bind/java/seq_test.go @@ -7,7 +7,6 @@ package java import ( "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -28,7 +27,7 @@ func TestMain(m *testing.M) { func testMain(m *testing.M) int { // Build gomobile and gobind and put them into PATH. - binDir, err := ioutil.TempDir("", "bind-java-test-") + binDir, err := os.MkdirTemp("", "bind-java-test-") if err != nil { log.Fatal(err) } @@ -117,7 +116,7 @@ func runTest(t *testing.T, pkgNames []string, javaPkg, javaCls string) { if err != nil { t.Fatalf("failed pwd: %v", err) } - tmpdir, err := ioutil.TempDir("", "bind-java-seq-test-") + tmpdir, err := os.MkdirTemp("", "bind-java-seq-test-") if err != nil { t.Fatalf("failed to prepare temp dir: %v", err) } @@ -164,20 +163,20 @@ func runTest(t *testing.T, pkgNames []string, javaPkg, javaCls string) { } fname = filepath.Join(tmpdir, "src/main/AndroidManifest.xml") - err = ioutil.WriteFile(fname, []byte(androidmanifest), 0700) + err = os.WriteFile(fname, []byte(androidmanifest), 0700) if err != nil { t.Fatalf("failed to write android manifest file: %v", err) } // Add a dummy string resource to avoid errors from the Android build system. fname = filepath.Join(tmpdir, "src/main/res/values/strings.xml") - err = ioutil.WriteFile(fname, []byte(stringsxml), 0700) + err = os.WriteFile(fname, []byte(stringsxml), 0700) if err != nil { t.Fatalf("failed to write strings.xml file: %v", err) } fname = filepath.Join(tmpdir, "build.gradle") - err = ioutil.WriteFile(fname, []byte(buildgradle), 0700) + err = os.WriteFile(fname, []byte(buildgradle), 0700) if err != nil { t.Fatalf("failed to write build.gradle file: %v", err) } diff --git a/bind/objc/seq_test.go b/bind/objc/seq_test.go index e6ef5e71d..0aa4bdcf6 100644 --- a/bind/objc/seq_test.go +++ b/bind/objc/seq_test.go @@ -8,7 +8,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -43,7 +42,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - binDir, err := ioutil.TempDir("", "bind-objc-test-") + binDir, err := os.MkdirTemp("", "bind-objc-test-") if err != nil { log.Fatal(err) } @@ -108,7 +107,7 @@ func runTest(t *testing.T, pkgNames []string, prefix, testfile, framework string t.Skip("command xcodebuild not found, skipping") } - tmpdir, err := ioutil.TempDir("", "bind-objc-seq-test-") + tmpdir, err := os.MkdirTemp("", "bind-objc-seq-test-") if err != nil { t.Fatalf("failed to prepare temp dir: %v", err) } @@ -200,7 +199,7 @@ func createProject(dir, testfile, framework string) error { {"xcodetest/AppDelegate.m", appdelegatem}, } for _, f := range files { - if err := ioutil.WriteFile(filepath.Join(dir, f.path), []byte(f.content), 0700); err != nil { + if err := os.WriteFile(filepath.Join(dir, f.path), []byte(f.content), 0700); err != nil { return err } } diff --git a/bind/seq/seq.go b/bind/seq/seq.go index 0740ca80f..699263669 100644 --- a/bind/seq/seq.go +++ b/bind/seq/seq.go @@ -9,7 +9,7 @@ // // Designed only for use by the code generated by gobind. Don't try to // use this directly. -package seq // import "golang.org/x/mobile/bind/seq" +package seq import _ "golang.org/x/mobile/internal/mobileinit" diff --git a/bind/testdata/basictypes.go b/bind/testdata/basictypes.go index 1fc02e63a..1ff804e4b 100644 --- a/bind/testdata/basictypes.go +++ b/bind/testdata/basictypes.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/classes.go b/bind/testdata/classes.go index 7263ac771..6d60349ca 100644 --- a/bind/testdata/classes.go +++ b/bind/testdata/classes.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/customprefix.go b/bind/testdata/customprefix.go index b3a0967bb..057f78514 100644 --- a/bind/testdata/customprefix.go +++ b/bind/testdata/customprefix.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/doc.go b/bind/testdata/doc.go index c17da8295..11125d0fb 100644 --- a/bind/testdata/doc.go +++ b/bind/testdata/doc.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/ignore.go b/bind/testdata/ignore.go index 2d3e1a686..e8b8517a9 100644 --- a/bind/testdata/ignore.go +++ b/bind/testdata/ignore.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/interfaces.go b/bind/testdata/interfaces.go index 9e2da3a34..c0e63bba6 100644 --- a/bind/testdata/interfaces.go +++ b/bind/testdata/interfaces.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/issue10788.go b/bind/testdata/issue10788.go index af487218e..d3ceb75bc 100644 --- a/bind/testdata/issue10788.go +++ b/bind/testdata/issue10788.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/issue12328.go b/bind/testdata/issue12328.go index 2b4ab887f..2dc5ee407 100644 --- a/bind/testdata/issue12328.go +++ b/bind/testdata/issue12328.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/java.go b/bind/testdata/java.go index 8550582ff..f37e0386c 100644 --- a/bind/testdata/java.go +++ b/bind/testdata/java.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/keywords.go b/bind/testdata/keywords.go index 6a04f0bdd..8a8808d92 100644 --- a/bind/testdata/keywords.go +++ b/bind/testdata/keywords.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/objc.go b/bind/testdata/objc.go index ca42fb95f..2d154c306 100644 --- a/bind/testdata/objc.go +++ b/bind/testdata/objc.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/objcw.go b/bind/testdata/objcw.go index dadfd93bc..353795b77 100644 --- a/bind/testdata/objcw.go +++ b/bind/testdata/objcw.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/structs.go b/bind/testdata/structs.go index 5974bdc36..53be1c747 100644 --- a/bind/testdata/structs.go +++ b/bind/testdata/structs.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/bind/testdata/testpkg/tagged.go b/bind/testdata/testpkg/tagged.go index b5fe898e5..701a58044 100644 --- a/bind/testdata/testpkg/tagged.go +++ b/bind/testdata/testpkg/tagged.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build aaa && bbb -// +build aaa,bbb // This file tests that tags work with gomobile. package testpkg diff --git a/bind/testdata/testpkg/testpkg.go b/bind/testdata/testpkg/testpkg.go index cd7a2ea04..40203bfe3 100644 --- a/bind/testdata/testpkg/testpkg.go +++ b/bind/testdata/testpkg/testpkg.go @@ -12,7 +12,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "io" "log" "math" "os" @@ -232,7 +232,7 @@ func ReadAsset() string { } defer rc.Close() - b, err := ioutil.ReadAll(rc) + b, err := io.ReadAll(rc) if err != nil { log.Fatal(err) } diff --git a/bind/testdata/try.go b/bind/testdata/try.go index 5d3d21787..8dff65295 100644 --- a/bind/testdata/try.go +++ b/bind/testdata/try.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gobind/doc.go b/cmd/gobind/doc.go index 0823d5d81..07b9df6ea 100644 --- a/cmd/gobind/doc.go +++ b/cmd/gobind/doc.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -249,4 +249,4 @@ Examples can be found in http://golang.org/x/mobile/example. Design doc: http://golang.org/s/gobind */ -package main // import "golang.org/x/mobile/cmd/gobind" +package main diff --git a/cmd/gobind/gen.go b/cmd/gobind/gen.go index fedbc2705..1bce3a433 100644 --- a/cmd/gobind/gen.go +++ b/cmd/gobind/gen.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -11,7 +11,6 @@ import ( "go/token" "go/types" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -203,7 +202,7 @@ func genObjcPackages(dir string, types []*objc.Named, embedders []importers.Stru pkgFile := filepath.Join(pkgDir, "package.go") buf.Reset() cg.GenPackage(i) - if err := ioutil.WriteFile(pkgFile, buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(pkgFile, buf.Bytes(), 0600); err != nil { return err } } @@ -213,7 +212,7 @@ func genObjcPackages(dir string, types []*objc.Named, embedders []importers.Stru if err := os.MkdirAll(objcBase, 0700); err != nil { return err } - if err := ioutil.WriteFile(filepath.Join(objcBase, "interfaces.go"), buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(filepath.Join(objcBase, "interfaces.go"), buf.Bytes(), 0600); err != nil { return err } goBase := filepath.Join(dir, "src", "gobind") @@ -222,17 +221,17 @@ func genObjcPackages(dir string, types []*objc.Named, embedders []importers.Stru } buf.Reset() cg.GenGo() - if err := ioutil.WriteFile(filepath.Join(goBase, "interfaces_darwin.go"), buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(filepath.Join(goBase, "interfaces_darwin.go"), buf.Bytes(), 0600); err != nil { return err } buf.Reset() cg.GenH() - if err := ioutil.WriteFile(filepath.Join(goBase, "interfaces.h"), buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(filepath.Join(goBase, "interfaces.h"), buf.Bytes(), 0600); err != nil { return err } buf.Reset() cg.GenM() - if err := ioutil.WriteFile(filepath.Join(goBase, "interfaces_darwin.m"), buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(filepath.Join(goBase, "interfaces_darwin.m"), buf.Bytes(), 0600); err != nil { return err } return nil @@ -256,7 +255,7 @@ func genJavaPackages(dir string, classes []*java.Class, embedders []importers.St pkgFile := filepath.Join(pkgDir, "package.go") buf.Reset() cg.GenPackage(i) - if err := ioutil.WriteFile(pkgFile, buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(pkgFile, buf.Bytes(), 0600); err != nil { return err } } @@ -266,7 +265,7 @@ func genJavaPackages(dir string, classes []*java.Class, embedders []importers.St if err := os.MkdirAll(javaBase, 0700); err != nil { return err } - if err := ioutil.WriteFile(filepath.Join(javaBase, "interfaces.go"), buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(filepath.Join(javaBase, "interfaces.go"), buf.Bytes(), 0600); err != nil { return err } goBase := filepath.Join(dir, "src", "gobind") @@ -275,17 +274,17 @@ func genJavaPackages(dir string, classes []*java.Class, embedders []importers.St } buf.Reset() cg.GenGo() - if err := ioutil.WriteFile(filepath.Join(goBase, "classes_android.go"), buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(filepath.Join(goBase, "classes_android.go"), buf.Bytes(), 0600); err != nil { return err } buf.Reset() cg.GenH() - if err := ioutil.WriteFile(filepath.Join(goBase, "classes.h"), buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(filepath.Join(goBase, "classes.h"), buf.Bytes(), 0600); err != nil { return err } buf.Reset() cg.GenC() - if err := ioutil.WriteFile(filepath.Join(goBase, "classes_android.c"), buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(filepath.Join(goBase, "classes_android.c"), buf.Bytes(), 0600); err != nil { return err } return nil diff --git a/cmd/gobind/gobind_test.go b/cmd/gobind/gobind_test.go index 302103c9e..f8c7879eb 100644 --- a/cmd/gobind/gobind_test.go +++ b/cmd/gobind/gobind_test.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gobind/implicit.go b/cmd/gobind/implicit.go index 4289d4b36..e8f6dd57b 100644 --- a/cmd/gobind/implicit.go +++ b/cmd/gobind/implicit.go @@ -1,7 +1,6 @@ // This file imports implicit dependencies required by generated code. //go:build mobile_implicit -// +build mobile_implicit package main diff --git a/cmd/gobind/main.go b/cmd/gobind/main.go index 8ccb9951e..bf1e7778e 100644 --- a/cmd/gobind/main.go +++ b/cmd/gobind/main.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -10,7 +10,6 @@ import ( "fmt" "go/ast" "go/types" - "io/ioutil" "log" "os" "os/exec" @@ -102,7 +101,7 @@ func run() { if len(classes) > 0 || len(otypes) > 0 { srcDir := *outdir if srcDir == "" { - srcDir, err = ioutil.TempDir(os.TempDir(), "gobind-") + srcDir, err = os.MkdirTemp(os.TempDir(), "gobind-") if err != nil { log.Fatal(err) } diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go index 54eaa4bcf..2cab5609c 100644 --- a/cmd/gomobile/bind.go +++ b/cmd/gomobile/bind.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -44,7 +43,7 @@ example, in Android Studio (1.2+), an AAR file can be imported using the module import wizard (File > New > New Module > Import .JAR or .AAR package), and setting it as a new dependency (File > Project Structure > Dependencies). This requires 'javac' -(version 1.7+) and Android SDK (API level 16 or newer) to build the +(version 1.8+) and Android SDK (API level 16 or newer) to build the library for Android. The ANDROID_HOME and ANDROID_NDK_HOME environment variables can be used to specify the Android SDK and NDK if they are not in the default locations. Use the -javapkg flag to specify the Java @@ -197,7 +196,7 @@ func writeFile(filename string, generate func(io.Writer) error) error { } if buildN { - return generate(ioutil.Discard) + return generate(io.Discard) } f, err := os.Create(filename) @@ -251,7 +250,9 @@ func getModuleVersions(targetPlatform string, targetArch string, src string) (*m } f := &modfile.File{} - f.AddModuleStmt("gobind") + if err := f.AddModuleStmt("gobind"); err != nil { + return nil, err + } e := json.NewDecoder(bytes.NewReader(output)) for { var mod *Module @@ -266,13 +267,19 @@ func getModuleVersions(targetPlatform string, targetArch string, src string) (*m // replaced by a local directory p = mod.Replace.Dir } - f.AddReplace(mod.Path, mod.Version, p, v) + if err := f.AddReplace(mod.Path, mod.Version, p, v); err != nil { + return nil, err + } } else { // When the version part is empty, the module is local and mod.Dir represents the location. if v := mod.Version; v == "" { - f.AddReplace(mod.Path, mod.Version, mod.Dir, "") + if err := f.AddReplace(mod.Path, mod.Version, mod.Dir, ""); err != nil { + return nil, err + } } else { - f.AddRequire(mod.Path, v) + if err := f.AddRequire(mod.Path, v); err != nil { + return nil, err + } } } } @@ -280,6 +287,19 @@ func getModuleVersions(targetPlatform string, targetArch string, src string) (*m break } } + + v, err := ensureGoVersion() + if err != nil { + return nil, err + } + // ensureGoVersion can return an empty string for a devel version. In this case, use the minimum version. + if v == "" { + v = fmt.Sprintf("go1.%d", minimumGoMinorVersion) + } + if err := f.AddGoStmt(strings.TrimPrefix(v, "go")); err != nil { + return nil, err + } + return f, nil } diff --git a/cmd/gomobile/bind_androidapp.go b/cmd/gomobile/bind_androidapp.go index 3fa9cfa7a..d03e64968 100644 --- a/cmd/gomobile/bind_androidapp.go +++ b/cmd/gomobile/bind_androidapp.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -8,7 +8,6 @@ import ( "archive/zip" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -73,7 +72,7 @@ func goAndroidBind(gobind string, pkgs []*packages.Package, targets []targetInfo } func buildSrcJar(src string) error { - var out io.Writer = ioutil.Discard + var out io.Writer = io.Discard if !buildN { ext := filepath.Ext(buildO) f, err := os.Create(buildO[:len(buildO)-len(ext)] + "-sources.jar") @@ -110,7 +109,7 @@ func buildSrcJar(src string) error { // // javac and jar commands are needed to build classes.jar. func buildAAR(srcDir, androidDir string, pkgs []*packages.Package, targets []targetInfo) (err error) { - var out io.Writer = ioutil.Discard + var out io.Writer = io.Discard if buildO == "" { buildO = pkgs[0].Name + ".aar" } @@ -245,7 +244,7 @@ func buildAAR(srcDir, androidDir string, pkgs []*packages.Package, targets []tar } const ( - javacTargetVer = "1.7" + javacTargetVer = "1.8" minAndroidAPI = 16 ) diff --git a/cmd/gomobile/bind_iosapp.go b/cmd/gomobile/bind_iosapp.go index a9f7a7f53..ca3815e3a 100644 --- a/cmd/gomobile/bind_iosapp.go +++ b/cmd/gomobile/bind_iosapp.go @@ -1,10 +1,12 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( + "bytes" + "encoding/xml" "errors" "fmt" "io" @@ -13,6 +15,7 @@ import ( "strconv" "strings" "text/template" + "time" "golang.org/x/sync/errgroup" "golang.org/x/tools/go/packages" @@ -149,9 +152,12 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) frameworkDirs = append(frameworkDirs, frameworkDir) frameworkArchCount[frameworkDir] = frameworkArchCount[frameworkDir] + 1 - versionsDir := filepath.Join(frameworkDir, "Versions") - versionsADir := filepath.Join(versionsDir, "A") - titlePath := filepath.Join(versionsADir, title) + frameworkLayout, err := frameworkLayoutForTarget(t, title) + if err != nil { + return err + } + + titlePath := filepath.Join(frameworkDir, frameworkLayout.binaryPath, title) if frameworkArchCount[frameworkDir] > 1 { // Not the first static lib, attach to a fat library and skip create headers fatCmd := exec.Command( @@ -164,17 +170,8 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) continue } - versionsAHeadersDir := filepath.Join(versionsADir, "Headers") - if err := mkdir(versionsAHeadersDir); err != nil { - return err - } - if err := symlink("A", filepath.Join(versionsDir, "Current")); err != nil { - return err - } - if err := symlink("Versions/Current/Headers", filepath.Join(frameworkDir, "Headers")); err != nil { - return err - } - if err := symlink(filepath.Join("Versions/Current", title), filepath.Join(frameworkDir, title)); err != nil { + headersDir := filepath.Join(frameworkDir, frameworkLayout.headerPath) + if err := mkdir(headersDir); err != nil { return err } @@ -197,7 +194,7 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) if len(fileBases) == 1 { headerFiles = append(headerFiles, title+".h") err := copyFile( - filepath.Join(versionsAHeadersDir, title+".h"), + filepath.Join(headersDir, title+".h"), filepath.Join(gobindDir, bindPrefix+title+".objc.h"), ) if err != nil { @@ -207,7 +204,7 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) for _, fileBase := range fileBases { headerFiles = append(headerFiles, fileBase+".objc.h") err := copyFile( - filepath.Join(versionsAHeadersDir, fileBase+".objc.h"), + filepath.Join(headersDir, fileBase+".objc.h"), filepath.Join(gobindDir, fileBase+".objc.h"), ) if err != nil { @@ -215,14 +212,14 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) } } err := copyFile( - filepath.Join(versionsAHeadersDir, "ref.h"), + filepath.Join(headersDir, "ref.h"), filepath.Join(gobindDir, "ref.h"), ) if err != nil { return err } headerFiles = append(headerFiles, title+".h") - err = writeFile(filepath.Join(versionsAHeadersDir, title+".h"), func(w io.Writer) error { + err = writeFile(filepath.Join(headersDir, title+".h"), func(w io.Writer) error { return appleBindHeaderTmpl.Execute(w, map[string]interface{}{ "pkgs": pkgs, "title": title, "bases": fileBases, }) @@ -232,14 +229,22 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) } } - if err := mkdir(filepath.Join(versionsADir, "Resources")); err != nil { - return err - } - if err := symlink("Versions/Current/Resources", filepath.Join(frameworkDir, "Resources")); err != nil { + frameworkInfoPlistDir := filepath.Join(frameworkDir, frameworkLayout.infoPlistPath) + if err := mkdir(frameworkInfoPlistDir); err != nil { return err } - err = writeFile(filepath.Join(frameworkDir, "Resources", "Info.plist"), func(w io.Writer) error { - _, err := w.Write([]byte(appleBindInfoPlist)) + err = writeFile(filepath.Join(frameworkInfoPlistDir, "Info.plist"), func(w io.Writer) error { + fmVersion := fmt.Sprintf("0.0.%d", time.Now().Unix()) + infoFrameworkPlistlData := infoFrameworkPlistlData{ + BundleID: escapePlistValue(rfc1034Label(title)), + ExecutableName: escapePlistValue(title), + Version: escapePlistValue(fmVersion), + } + infoplist := new(bytes.Buffer) + if err := infoFrameworkPlistTmpl.Execute(infoplist, infoFrameworkPlistlData); err != nil { + return err + } + _, err := w.Write(infoplist.Bytes()) return err }) if err != nil { @@ -253,15 +258,18 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) Module: title, Headers: headerFiles, } - err = writeFile(filepath.Join(versionsADir, "Modules", "module.modulemap"), func(w io.Writer) error { + modulesDir := filepath.Join(frameworkDir, frameworkLayout.modulePath) + err = writeFile(filepath.Join(modulesDir, "module.modulemap"), func(w io.Writer) error { return appleModuleMapTmpl.Execute(w, mmVals) }) if err != nil { return err } - err = symlink(filepath.Join("Versions/Current/Modules"), filepath.Join(frameworkDir, "Modules")) - if err != nil { - return err + + for src, dst := range frameworkLayout.symlinks { + if err := symlink(src, filepath.Join(frameworkDir, dst)); err != nil { + return err + } } } @@ -269,6 +277,14 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) xcframeworkArgs := []string{"-create-xcframework"} for _, dir := range frameworkDirs { + // On macOS, a temporary directory starts with /var, which is a symbolic link to /private/var. + // And in gomobile, a temporary directory is usually used as a working directly. + // Unfortunately, xcodebuild in Xcode 15 seems to have a bug and might not be able to understand fullpaths with symbolic links. + // As a workaround, resolve the path with symbolic links by filepath.EvalSymlinks. + dir, err := filepath.EvalSymlinks(dir) + if err != nil { + return err + } xcframeworkArgs = append(xcframeworkArgs, "-framework", dir) } @@ -278,13 +294,79 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo) return err } -const appleBindInfoPlist = ` - - - - - -` +type frameworkLayout struct { + headerPath string + binaryPath string + modulePath string + infoPlistPath string + // symlinks to create in the framework. Maps src (relative to dst) -> dst (relative to framework bundle root) + symlinks map[string]string +} + +// frameworkLayoutForTarget generates the filestructure for a framework for the given target platform (macos, ios, etc), +// according to Apple's spec https://developer.apple.com/documentation/bundleresources/placing_content_in_a_bundle +func frameworkLayoutForTarget(t targetInfo, title string) (*frameworkLayout, error) { + switch t.platform { + case "macos", "maccatalyst": + return &frameworkLayout{ + headerPath: "Versions/A/Headers", + binaryPath: "Versions/A", + modulePath: "Versions/A/Modules", + infoPlistPath: "Versions/A/Resources", + symlinks: map[string]string{ + "A": "Versions/Current", + "Versions/Current/Resources": "Resources", + "Versions/Current/Headers": "Headers", + "Versions/Current/Modules": "Modules", + filepath.Join("Versions/Current", title): title, + }, + }, nil + case "ios", "iossimulator": + return &frameworkLayout{ + headerPath: "Headers", + binaryPath: ".", + modulePath: "Modules", + infoPlistPath: ".", + }, nil + } + + return nil, fmt.Errorf("unsupported platform %q", t.platform) +} + +type infoFrameworkPlistlData struct { + BundleID string + ExecutableName string + Version string +} + +// infoFrameworkPlistTmpl is a template for the Info.plist file in a framework. +// Minimum OS version == 100.0 is a workaround for SPM issue +// https://github.com/firebase/firebase-ios-sdk/pull/12439/files#diff-f4eb4ff5ec89af999cbe8fa3ffe5647d7853ffbc9c1515b337ca043c684b6bb4R679 +var infoFrameworkPlistTmpl = template.Must(template.New("infoFrameworkPlist").Parse(` + + + + CFBundleExecutable + {{.ExecutableName}} + CFBundleIdentifier + {{.BundleID}} + MinimumOSVersion + 100.0 + CFBundleShortVersionString + {{.Version}} + CFBundleVersion + {{.Version}} + CFBundlePackageType + FMWK + + +`)) + +func escapePlistValue(value string) string { + var b bytes.Buffer + xml.EscapeText(&b, []byte(value)) + return b.String() +} var appleModuleMapTmpl = template.Must(template.New("iosmmap").Parse(`framework module "{{.Module}}" { header "ref.h" diff --git a/cmd/gomobile/bind_test.go b/cmd/gomobile/bind_test.go index fa6b0efb8..07e366560 100644 --- a/cmd/gomobile/bind_test.go +++ b/cmd/gomobile/bind_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -6,7 +6,6 @@ package main import ( "bytes" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -190,7 +189,7 @@ GOOS=android CGO_ENABLED=1 gobind -lang=go,java -outdir=$WORK{{if .JavaPkg}} -ja mkdir -p $WORK/src-android-arm PWD=$WORK/src-android-arm GOMODCACHE=$GOPATH/pkg/mod GOOS=android GOARCH=arm CC=$NDK_PATH/toolchains/llvm/prebuilt/{{.NDKARCH}}/bin/armv7a-linux-androideabi16-clang CXX=$NDK_PATH/toolchains/llvm/prebuilt/{{.NDKARCH}}/bin/armv7a-linux-androideabi16-clang++ CGO_ENABLED=1 GOARM=7 GOPATH=$WORK:$GOPATH go mod tidy PWD=$WORK/src-android-arm GOMODCACHE=$GOPATH/pkg/mod GOOS=android GOARCH=arm CC=$NDK_PATH/toolchains/llvm/prebuilt/{{.NDKARCH}}/bin/armv7a-linux-androideabi16-clang CXX=$NDK_PATH/toolchains/llvm/prebuilt/{{.NDKARCH}}/bin/armv7a-linux-androideabi16-clang++ CGO_ENABLED=1 GOARM=7 GOPATH=$WORK:$GOPATH go build -x -buildmode=c-shared -o=$WORK/android/src/main/jniLibs/armeabi-v7a/libgojni.so ./gobind -PWD=$WORK/java javac -d $WORK/javac-output -source 1.7 -target 1.7 -bootclasspath {{.AndroidPlatform}}/android.jar *.java +PWD=$WORK/java javac -d $WORK/javac-output -source 1.8 -target 1.8 -bootclasspath {{.AndroidPlatform}}/android.jar *.java jar c -C $WORK/javac-output . `)) @@ -251,16 +250,75 @@ func TestBindAppleAll(t *testing.T) { } } +const ambiguousPathsGoMod = `module ambiguouspaths + +go 1.18 + +require golang.org/x/mobile v0.0.0-20230905140555-fbe1c053b6a9 + +require ( + golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 // indirect + golang.org/x/image v0.11.0 // indirect + golang.org/x/sys v0.11.0 // indirect +) +` + +const ambiguousPathsGoSum = `github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 h1:3AGKexOYqL+ztdWdkB1bDwXgPBuTS/S8A4WzuTvJ8Cg= +golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0= +golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo= +golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8= +golang.org/x/mobile v0.0.0-20230905140555-fbe1c053b6a9 h1:LaLfQUz4L1tfuOlrtEouZLZ0qHDwKn87E1NKoiudP/o= +golang.org/x/mobile v0.0.0-20230905140555-fbe1c053b6a9/go.mod h1:2jxcxt/JNJik+N+QcB8q308+SyrE3bu43+sGZDmJ02M= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +` + +const ambiguousPathsGo = `package ambiguouspaths + +import ( + _ "golang.org/x/mobile/app" +) + +func Dummy() {} +` + func TestBindWithGoModules(t *testing.T) { if runtime.GOOS == "android" || runtime.GOOS == "ios" { t.Skipf("gomobile and gobind are not available on %s", runtime.GOOS) } - dir, err := ioutil.TempDir("", "gomobile-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) + dir := t.TempDir() if out, err := exec.Command("go", "build", "-o="+dir, "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil { t.Fatalf("%v: %s", err, string(out)) @@ -273,7 +331,22 @@ func TestBindWithGoModules(t *testing.T) { path += string(filepath.ListSeparator) + p } + // Create a source package dynamically to avoid go.mod files in this repository. See golang/go#34352 for more details. + if err := os.Mkdir(filepath.Join(dir, "ambiguouspaths"), 0755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, "ambiguouspaths", "go.mod"), []byte(ambiguousPathsGoMod), 0644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, "ambiguouspaths", "go.sum"), []byte(ambiguousPathsGoSum), 0644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, "ambiguouspaths", "ambiguouspaths.go"), []byte(ambiguousPathsGo), 0644); err != nil { + t.Fatal(err) + } + for _, target := range []string{"android", "ios"} { + target := target t.Run(target, func(t *testing.T) { switch target { case "android": @@ -308,6 +381,11 @@ func TestBindWithGoModules(t *testing.T) { Path: "./bind/testdata/cgopkg", Dir: filepath.Join("..", ".."), }, + { + Name: "Ambiguous Paths", + Path: ".", + Dir: filepath.Join(dir, "ambiguouspaths"), + }, } for _, tc := range tests { diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index c9483434d..a8f0ad2cc 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -160,7 +160,7 @@ func runBuildImpl(cmd *command) (*packages.Package, error) { return pkg, nil } if buildBundleID == "" { - return nil, fmt.Errorf("-target=ios requires -bundleid set") + return nil, fmt.Errorf("-target=%s requires -bundleid set", buildTarget) } nmpkgs, err = goAppleBuild(pkg, buildBundleID, targets) if err != nil { diff --git a/cmd/gomobile/build_androidapp.go b/cmd/gomobile/build_androidapp.go index bcd2664bd..48837b5c4 100644 --- a/cmd/gomobile/build_androidapp.go +++ b/cmd/gomobile/build_androidapp.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -13,7 +13,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "os" "path" @@ -37,7 +36,7 @@ func goAndroidBuild(pkg *packages.Package, targets []targetInfo) (map[string]boo dir := filepath.Dir(pkg.GoFiles[0]) manifestPath := filepath.Join(dir, "AndroidManifest.xml") - manifestData, err := ioutil.ReadFile(manifestPath) + manifestData, err := os.ReadFile(manifestPath) if err != nil { if !os.IsNotExist(err) { return nil, err @@ -129,7 +128,7 @@ func goAndroidBuild(pkg *packages.Package, targets []targetInfo) (map[string]boo fmt.Fprintf(os.Stderr, "apk: %s\n", name) } if buildN { - return ioutil.Discard, nil + return io.Discard, nil } return apkw.Create(name) } diff --git a/cmd/gomobile/build_apple.go b/cmd/gomobile/build_apple.go index f7b682389..1919a7ed7 100644 --- a/cmd/gomobile/build_apple.go +++ b/cmd/gomobile/build_apple.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -9,7 +9,6 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "os" "os/exec" "path" @@ -69,7 +68,7 @@ func goAppleBuild(pkg *packages.Package, bundleID string, targets []targetInfo) printcmd("echo \"%s\" > %s", file.contents, file.name) } if !buildN { - if err := ioutil.WriteFile(file.name, file.contents, 0644); err != nil { + if err := os.WriteFile(file.name, file.contents, 0644); err != nil { return nil, err } } diff --git a/cmd/gomobile/build_darwin_test.go b/cmd/gomobile/build_darwin_test.go index 43ca683ee..c640fa80e 100644 --- a/cmd/gomobile/build_darwin_test.go +++ b/cmd/gomobile/build_darwin_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/build_test.go b/cmd/gomobile/build_test.go index b50aba752..e5e412ab7 100644 --- a/cmd/gomobile/build_test.go +++ b/cmd/gomobile/build_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -6,7 +6,6 @@ package main import ( "bytes" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -212,7 +211,7 @@ func TestBuildWithGoModules(t *testing.T) { t.Skipf("gomobile are not available on %s", runtime.GOOS) } - dir, err := ioutil.TempDir("", "gomobile-test") + dir, err := os.MkdirTemp("", "gomobile-test") if err != nil { t.Fatal(err) } diff --git a/cmd/gomobile/cert.go b/cmd/gomobile/cert.go index 0aa00b3a4..f61299366 100644 --- a/cmd/gomobile/cert.go +++ b/cmd/gomobile/cert.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/cert_test.go b/cmd/gomobile/cert_test.go index a4ab860b7..c5c5e3c6b 100644 --- a/cmd/gomobile/cert_test.go +++ b/cmd/gomobile/cert_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -8,7 +8,6 @@ import ( "crypto/rand" "crypto/x509" "encoding/pem" - "io/ioutil" "os" "os/exec" "testing" @@ -30,7 +29,7 @@ func TestSignPKCS7(t *testing.T) { if err != nil { t.Fatal(err) } - sig, err := ioutil.TempFile("", "content.rsa") + sig, err := os.CreateTemp("", "content.rsa") if err != nil { t.Fatal(err) } diff --git a/cmd/gomobile/clean.go b/cmd/gomobile/clean.go index 1c0e348e3..6c3dddf28 100644 --- a/cmd/gomobile/clean.go +++ b/cmd/gomobile/clean.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/dex.go b/cmd/gomobile/dex.go index ff844b348..59dc3defe 100644 --- a/cmd/gomobile/dex.go +++ b/cmd/gomobile/dex.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/doc.go b/cmd/gomobile/doc.go index 74090da67..6922125c2 100644 --- a/cmd/gomobile/doc.go +++ b/cmd/gomobile/doc.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -167,4 +167,4 @@ Usage: Version prints versions of the gomobile binary and tools */ -package main // import "golang.org/x/mobile/cmd/gomobile" +package main diff --git a/cmd/gomobile/env.go b/cmd/gomobile/env.go index 43f24b99d..869e38cf3 100644 --- a/cmd/gomobile/env.go +++ b/cmd/gomobile/env.go @@ -1,3 +1,7 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package main import ( @@ -6,7 +10,6 @@ import ( "errors" "fmt" "io/fs" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -63,9 +66,11 @@ func platformOS(platform string) string { case "macos", "maccatalyst": // For "maccatalyst", Go packages should be built with GOOS=darwin, // not GOOS=ios, since the underlying OS (and kernel, runtime) is macOS. + // But, using GOOS=darwin with build-tag ios leads to corrupt builds: https://go.dev/issue/52299 + // => So we use GOOS=ios for now. // We also apply a "macos" or "maccatalyst" build tag, respectively. // See below for additional context. - return "darwin" + return "ios" default: panic(fmt.Sprintf("unexpected platform: %s", platform)) } @@ -82,17 +87,17 @@ func platformTags(platform string) []string { case "maccatalyst": // Mac Catalyst is a subset of iOS APIs made available on macOS // designed to ease porting apps developed for iPad to macOS. - // See https://developer.apple.com/mac-catalyst/. - // Because of this, when building a Go package targeting maccatalyst, - // GOOS=darwin (not ios). To bridge the gap and enable maccatalyst - // packages to be compiled, we also specify the "ios" build tag. + // See + // https://developer.apple.com/mac-catalyst/. + // https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets/49560690#49560690 + // + // Historically gomobile used GOOS=darwin with build tag ios when + // targeting Mac Catalyst. However, this configuration is not officially + // supported and leads to corrupt builds after go1.18: https://go.dev/issues/52299 + // Use GOOS=ios. // To help discriminate between darwin, ios, macos, and maccatalyst // targets, there is also a "maccatalyst" tag. - // Some additional context on this can be found here: - // https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets/49560690#49560690 - // TODO(ydnar): remove tag "ios" when cgo supports Catalyst - // See golang.org/issues/47228 - return []string{"ios", "macos", "maccatalyst"} + return []string{"macos", "maccatalyst"} default: panic(fmt.Sprintf("unexpected platform: %s", platform)) } @@ -138,7 +143,7 @@ func buildEnvInit() (cleanup func(), err error) { tmpdir = "$WORK" cleanupFn = func() {} } else { - tmpdir, err = ioutil.TempDir("", "gomobile-work-") + tmpdir, err = os.MkdirTemp("", "gomobile-work-") if err != nil { return nil, err } @@ -217,17 +222,11 @@ func envInit() (err error) { cflags += " -mios-simulator-version-min=" + buildIOSVersion cflags += " -fembed-bitcode" case "maccatalyst": - // Mac Catalyst is a subset of iOS APIs made available on macOS - // designed to ease porting apps developed for iPad to macOS. - // See https://developer.apple.com/mac-catalyst/. - // Because of this, when building a Go package targeting maccatalyst, - // GOOS=darwin (not ios). To bridge the gap and enable maccatalyst - // packages to be compiled, we also specify the "ios" build tag. - // To help discriminate between darwin, ios, macos, and maccatalyst - // targets, there is also a "maccatalyst" tag. - // Some additional context on this can be found here: - // https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets/49560690#49560690 - goos = "darwin" + // See the comment about maccatalyst's GOOS, build tags configuration + // in platformOS and platformTags. + // Using GOOS=darwin with build-tag ios leads to corrupt builds: https://go.dev/issue/52299 + // => So we use GOOS=ios for now. + goos = "ios" sdk = "macosx" clang, cflags, err = envClang(sdk) // TODO(ydnar): the following 3 lines MAY be needed to compile @@ -340,7 +339,7 @@ func checkNDKRoot(ndkRoot string, targets []targetInfo) error { // compatibleNDKRoots searches the side-by-side NDK dirs for compatible SDKs. func compatibleNDKRoots(ndkForest string, targets []targetInfo) ([]string, error) { - ndkDirs, err := ioutil.ReadDir(ndkForest) + ndkDirs, err := os.ReadDir(ndkForest) if err != nil { return nil, err } @@ -436,15 +435,21 @@ func envClang(sdkName string) (clang, cflags string, err error) { return sdkName + "-clang", "-isysroot " + sdkName, nil } cmd := exec.Command("xcrun", "--sdk", sdkName, "--find", "clang") - out, err := cmd.CombinedOutput() + out, err := cmd.Output() if err != nil { + if ee := (*exec.ExitError)(nil); errors.As(err, &ee) { + out = append(out, ee.Stderr...) + } return "", "", fmt.Errorf("xcrun --find: %v\n%s", err, out) } clang = strings.TrimSpace(string(out)) cmd = exec.Command("xcrun", "--sdk", sdkName, "--show-sdk-path") - out, err = cmd.CombinedOutput() + out, err = cmd.Output() if err != nil { + if ee := (*exec.ExitError)(nil); errors.As(err, &ee) { + out = append(out, ee.Stderr...) + } return "", "", fmt.Errorf("xcrun --show-sdk-path: %v\n%s", err, out) } sdk := strings.TrimSpace(string(out)) diff --git a/cmd/gomobile/env_test.go b/cmd/gomobile/env_test.go index e5ad28259..9090eaab3 100644 --- a/cmd/gomobile/env_test.go +++ b/cmd/gomobile/env_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Go Authors. All rights reserved. +// Copyright 2019 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -6,14 +6,13 @@ package main import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" ) func TestNdkRoot(t *testing.T) { - home, err := ioutil.TempDir("", "gomobile-test-") + home, err := os.MkdirTemp("", "gomobile-test-") if err != nil { t.Fatal(err) } diff --git a/cmd/gomobile/gendex.go b/cmd/gomobile/gendex.go index 88cf5549f..1e5efc957 100644 --- a/cmd/gomobile/gendex.go +++ b/cmd/gomobile/gendex.go @@ -1,9 +1,8 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore -// +build ignore // Gendex generates a dex file used by Go apps created with gomobile. // @@ -24,7 +23,6 @@ import ( "flag" "fmt" "go/format" - "io/ioutil" "log" "os" "os/exec" @@ -41,7 +39,7 @@ func main() { flag.Parse() var err error - tmpdir, err = ioutil.TempDir("", "gendex-") + tmpdir, err = os.MkdirTemp("", "gendex-") if err != nil { log.Fatal(err) } @@ -74,8 +72,8 @@ func gendex() error { } cmd := exec.Command( "javac", - "-source", "1.7", - "-target", "1.7", + "-source", "1.8", + "-target", "1.8", "-bootclasspath", platform+"/android.jar", "-d", tmpdir+"/work", ) @@ -99,7 +97,7 @@ func gendex() error { os.Stderr.Write(out) return err } - src, err := ioutil.ReadFile(tmpdir + "/classes.dex") + src, err := os.ReadFile(tmpdir + "/classes.dex") if err != nil { return err } @@ -149,7 +147,7 @@ func findLast(path string) (string, error) { return path + "/" + children[len(children)-1], nil } -var header = `// Copyright 2015 The Go Authors. All rights reserved. +var header = `// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/init.go b/cmd/gomobile/init.go index e7392df71..be4eaea81 100644 --- a/cmd/gomobile/init.go +++ b/cmd/gomobile/init.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -63,7 +62,7 @@ func runInit(cmd *command) error { tmpdir = filepath.Join(gomobilepath, "work") } else { var err error - tmpdir, err = ioutil.TempDir(gomobilepath, "work-") + tmpdir, err = os.MkdirTemp(gomobilepath, "work-") if err != nil { return err } @@ -153,7 +152,7 @@ func installOpenAL(gomobilepath string) error { alTmpDir = filepath.Join(gomobilepath, "work") } else { var err error - alTmpDir, err = ioutil.TempDir(gomobilepath, "openal-release-") + alTmpDir, err = os.MkdirTemp(gomobilepath, "openal-release-") if err != nil { return err } diff --git a/cmd/gomobile/init_test.go b/cmd/gomobile/init_test.go index 2eabda1a8..0e737170e 100644 --- a/cmd/gomobile/init_test.go +++ b/cmd/gomobile/init_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -6,7 +6,6 @@ package main import ( "bytes" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -40,7 +39,7 @@ func TestInit(t *testing.T) { // Test that first GOPATH element is chosen correctly. var err error - gopath, err = ioutil.TempDir("", "gomobile-test") + gopath, err = os.MkdirTemp("", "gomobile-test") if err != nil { t.Fatal(err) } @@ -55,7 +54,7 @@ func TestInit(t *testing.T) { os.Setenv("HOMEDRIVE", "C:") } - emptymod, err := ioutil.TempDir("", "gomobile-test") + emptymod, err := os.MkdirTemp("", "gomobile-test") if err != nil { t.Fatal(err) } diff --git a/cmd/gomobile/install.go b/cmd/gomobile/install.go index beb7e5262..5a893c2ab 100644 --- a/cmd/gomobile/install.go +++ b/cmd/gomobile/install.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/main.go b/cmd/gomobile/main.go index 9814a0d49..c123263f5 100644 --- a/cmd/gomobile/main.go +++ b/cmd/gomobile/main.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -9,12 +9,10 @@ package main import ( "bufio" "bytes" - "errors" "flag" "fmt" "html/template" "io" - "io/ioutil" "log" "os" "os/exec" @@ -24,9 +22,11 @@ import ( var ( gomobileName = "gomobile" - goVersionOut = []byte(nil) + goVersion string ) +const minimumGoMinorVersion = 18 + func printUsage(w io.Writer) { bufw := bufio.NewWriter(w) if err := usageTmpl.Execute(bufw, commands); err != nil { @@ -58,7 +58,7 @@ func main() { return } - if err := determineGoVersion(); err != nil { + if _, err := ensureGoVersion(); err != nil { fmt.Fprintf(os.Stderr, "%s: %v\n", gomobileName, err) os.Exit(1) } @@ -84,20 +84,25 @@ func main() { os.Exit(2) } -func determineGoVersion() error { +func ensureGoVersion() (string, error) { + if goVersion != "" { + return goVersion, nil + } + goVersionOut, err := exec.Command("go", "version").CombinedOutput() if err != nil { - return fmt.Errorf("'go version' failed: %v, %s", err, goVersionOut) + return "", fmt.Errorf("'go version' failed: %v, %s", err, goVersionOut) } var minor int if _, err := fmt.Sscanf(string(goVersionOut), "go version go1.%d", &minor); err != nil { // Ignore unknown versions; it's probably a devel version. - return nil + return "", nil } - if minor < 16 { - return errors.New("Go 1.16 or newer is required") + goVersion = fmt.Sprintf("go1.%d", minor) + if minor < minimumGoMinorVersion { + return "", fmt.Errorf("Go 1.%d or newer is required", minimumGoMinorVersion) } - return nil + return goVersion, nil } func help(args []string) { @@ -122,7 +127,7 @@ func help(args []string) { os.Exit(2) } -const documentationHeader = `// Copyright 2015 The Go Authors. All rights reserved. +const documentationHeader = `// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -153,7 +158,7 @@ func helpDocumentation(path string) { w.WriteString("*/\npackage main // import \"golang.org/x/mobile/cmd/gomobile\"\n") - if err := ioutil.WriteFile(path, w.Bytes(), 0666); err != nil { + if err := os.WriteFile(path, w.Bytes(), 0666); err != nil { log.Fatal(err) } } diff --git a/cmd/gomobile/manifest.go b/cmd/gomobile/manifest.go index 09b8ff0e0..53fe32071 100644 --- a/cmd/gomobile/manifest.go +++ b/cmd/gomobile/manifest.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/strings_flag.go b/cmd/gomobile/strings_flag.go index 330833e70..6cf51c345 100644 --- a/cmd/gomobile/strings_flag.go +++ b/cmd/gomobile/strings_flag.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/tools.go b/cmd/gomobile/tools.go index e8d4ade00..bee46004c 100644 --- a/cmd/gomobile/tools.go +++ b/cmd/gomobile/tools.go @@ -1,7 +1,6 @@ // This file includes the tools the gomobile depends on. //go:build tools -// +build tools package main diff --git a/cmd/gomobile/version.go b/cmd/gomobile/version.go index 27fd6bde0..faf072428 100644 --- a/cmd/gomobile/version.go +++ b/cmd/gomobile/version.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/writer.go b/cmd/gomobile/writer.go index 880104120..029e6eeee 100644 --- a/cmd/gomobile/writer.go +++ b/cmd/gomobile/writer.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/cmd/gomobile/writer_test.go b/cmd/gomobile/writer_test.go index ae6e2c710..324659a8b 100644 --- a/cmd/gomobile/writer_test.go +++ b/cmd/gomobile/writer_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -8,7 +8,6 @@ import ( "crypto/x509" "encoding/pem" "io" - "io/ioutil" "os" "os/exec" "testing" @@ -28,7 +27,7 @@ func TestWriter(t *testing.T) { t.Fatal(err) } - f, err := ioutil.TempFile("", "testapk-") + f, err := os.CreateTemp("", "testapk-") if err != nil { t.Fatal(err) } @@ -141,7 +140,7 @@ const androidManifest = ` ` func writeTempFile(data string) (string, error) { - f, err := ioutil.TempFile("", "gofmt") + f, err := os.CreateTemp("", "gofmt") if err != nil { return "", err } diff --git a/event/lifecycle/lifecycle.go b/event/lifecycle/lifecycle.go index 4c588582d..58de2c419 100644 --- a/event/lifecycle/lifecycle.go +++ b/event/lifecycle/lifecycle.go @@ -17,7 +17,7 @@ // means it has lost the focus. // // See the golang.org/x/mobile/app package for details on the event model. -package lifecycle // import "golang.org/x/mobile/event/lifecycle" +package lifecycle import ( "fmt" diff --git a/event/mouse/mouse.go b/event/mouse/mouse.go index eec2fc078..e98131d37 100644 --- a/event/mouse/mouse.go +++ b/event/mouse/mouse.go @@ -5,7 +5,7 @@ // Package mouse defines an event for mouse input. // // See the golang.org/x/mobile/app package for details on the event model. -package mouse // import "golang.org/x/mobile/event/mouse" +package mouse import ( "fmt" diff --git a/event/paint/paint.go b/event/paint/paint.go index 0f24b1ad1..179136c46 100644 --- a/event/paint/paint.go +++ b/event/paint/paint.go @@ -5,7 +5,7 @@ // Package paint defines an event for the app being ready to paint. // // See the golang.org/x/mobile/app package for details on the event model. -package paint // import "golang.org/x/mobile/event/paint" +package paint // Event indicates that the app is ready to paint the next frame of the GUI. // diff --git a/event/size/size.go b/event/size/size.go index f39672819..4c4070b44 100644 --- a/event/size/size.go +++ b/event/size/size.go @@ -6,7 +6,7 @@ // orientation of the app's window. // // See the golang.org/x/mobile/app package for details on the event model. -package size // import "golang.org/x/mobile/event/size" +package size import ( "image" diff --git a/event/touch/touch.go b/event/touch/touch.go index c91967be2..94c4853ae 100644 --- a/event/touch/touch.go +++ b/event/touch/touch.go @@ -5,7 +5,7 @@ // Package touch defines an event for touch input. // // See the golang.org/x/mobile/app package for details on the event model. -package touch // import "golang.org/x/mobile/event/touch" +package touch // The best source on android input events is the NDK: include/android/input.h // diff --git a/example/basic/main.go b/example/basic/main.go index 94932db4f..fb6167be6 100644 --- a/example/basic/main.go +++ b/example/basic/main.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows // An app that draws a green triangle on a red background. // diff --git a/example/basic/main_x.go b/example/basic/main_x.go index 52e8c5399..49d8612d1 100644 --- a/example/basic/main_x.go +++ b/example/basic/main_x.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build !darwin && !linux && !windows -// +build !darwin,!linux,!windows package main diff --git a/example/flappy/game.go b/example/flappy/game.go index 89b8ae2db..04903c719 100644 --- a/example/flappy/game.go +++ b/example/flappy/game.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux -// +build darwin linux package main diff --git a/example/flappy/main.go b/example/flappy/main.go index 6f298ea6d..b0970f5b8 100644 --- a/example/flappy/main.go +++ b/example/flappy/main.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux -// +build darwin linux // Flappy Gopher is a simple one-button game that uses the // mobile framework and the experimental sprite engine. diff --git a/example/flappy/main_x.go b/example/flappy/main_x.go index 6739924fe..a056c79f2 100644 --- a/example/flappy/main_x.go +++ b/example/flappy/main_x.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build !darwin && !linux -// +build !darwin,!linux package main diff --git a/example/ivy/doc.go b/example/ivy/doc.go index fa37ea90d..47eaa1fb6 100644 --- a/example/ivy/doc.go +++ b/example/ivy/doc.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Go Authors. All rights reserved. +// Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/example/ivy/go.mod b/example/ivy/go.mod index 884df3db7..b2c46d604 100644 --- a/example/ivy/go.mod +++ b/example/ivy/go.mod @@ -1,15 +1,14 @@ module golang.org/x/mobile/example/ivy -go 1.17 +go 1.24.0 require ( - golang.org/x/mobile v0.0.0-20210924032853-1c027f395ef7 + golang.org/x/mobile v0.0.0-20250813145510-f12310a0cfd9 robpike.io/ivy v0.2.7 ) require ( - golang.org/x/mod v0.4.2 // indirect - golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect - golang.org/x/tools v0.1.2 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + golang.org/x/mod v0.28.0 // indirect + golang.org/x/sync v0.17.0 // indirect + golang.org/x/tools v0.37.0 // indirect ) diff --git a/example/ivy/go.sum b/example/ivy/go.sum index bd42ab121..8c60bdb85 100644 --- a/example/ivy/go.sum +++ b/example/ivy/go.sum @@ -1,40 +1,12 @@ -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20210924032853-1c027f395ef7 h1:CyFUjc175y/mbMjxe+WdqI72jguLyjQChKCDe9mfTvg= -golang.org/x/mobile v0.0.0-20210924032853-1c027f395ef7/go.mod h1:c4YKU3ZylDmvbw+H/PSvm42vhdWbuxCzbonauEAP9B8= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -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-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +golang.org/x/mobile v0.0.0-20250813145510-f12310a0cfd9 h1:tf0OY/FXi1sPkoNVKP4w+GStqIfqbFUqDoDDm4B+iCg= +golang.org/x/mobile v0.0.0-20250813145510-f12310a0cfd9/go.mod h1:wNiuiJfmmgv45sw8EHpNeVWqpxLeEwQ8bkUIhuOYUh8= +golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U= +golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE= +golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w= robpike.io/ivy v0.2.7 h1:XVYgWSm7THVm1bk1jfRBB9xhso459T22gbpotHbhk7M= robpike.io/ivy v0.2.7/go.mod h1:6B/DGaft5rvYiF7MgCTiZAAvH5W7vtu0eS2BW77updo= diff --git a/example/ivy/tools.go b/example/ivy/tools.go index 85a60697e..4219529ba 100644 --- a/example/ivy/tools.go +++ b/example/ivy/tools.go @@ -1,9 +1,8 @@ -// Copyright 2021 The Go Authors. All rights reserved. +// Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build ignore -// +build ignore +//go:build tools package dummy diff --git a/example/network/main.go b/example/network/main.go index 4b23cbed4..5ac2f2cc9 100644 --- a/example/network/main.go +++ b/example/network/main.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows // An app that paints green if golang.org is reachable when the app first // starts, or red otherwise. diff --git a/example/network/main_x.go b/example/network/main_x.go index 9bda7ac77..e6cd77852 100644 --- a/example/network/main_x.go +++ b/example/network/main_x.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build !darwin && !linux && !windows -// +build !darwin,!linux,!windows package main diff --git a/exp/app/debug/fps.go b/exp/app/debug/fps.go index bef808dd5..67b194fc5 100644 --- a/exp/app/debug/fps.go +++ b/exp/app/debug/fps.go @@ -3,10 +3,9 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows // Package debug provides GL-based debugging tools for apps. -package debug // import "golang.org/x/mobile/exp/app/debug" +package debug import ( "image" diff --git a/exp/audio/al/al.go b/exp/audio/al/al.go index b02cbb761..f27dca258 100644 --- a/exp/audio/al/al.go +++ b/exp/audio/al/al.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows // Package al provides OpenAL Soft bindings for Go. // @@ -23,7 +22,7 @@ // license file to the open source notices of your application. // OpenAL Soft's license file could be found at // http://repo.or.cz/w/openal-soft.git/blob/HEAD:/COPYING. -package al // import "golang.org/x/mobile/exp/audio/al" +package al // Capability represents OpenAL extension capabilities. type Capability int32 diff --git a/exp/audio/al/al_notandroid.go b/exp/audio/al/al_notandroid.go index 577fee361..06fee46ac 100644 --- a/exp/audio/al/al_notandroid.go +++ b/exp/audio/al/al_notandroid.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || (linux && !android) || windows -// +build darwin linux,!android windows package al diff --git a/exp/audio/al/alc.go b/exp/audio/al/alc.go index f0b421553..1c9c44282 100644 --- a/exp/audio/al/alc.go +++ b/exp/audio/al/alc.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows package al diff --git a/exp/audio/al/alc_notandroid.go b/exp/audio/al/alc_notandroid.go index 68e907c1c..a87df647f 100644 --- a/exp/audio/al/alc_notandroid.go +++ b/exp/audio/al/alc_notandroid.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || (linux && !android) || windows -// +build darwin linux,!android windows package al diff --git a/exp/audio/al/const.go b/exp/audio/al/const.go index aef054328..2408cbe97 100644 --- a/exp/audio/al/const.go +++ b/exp/audio/al/const.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows package al diff --git a/exp/f32/affine_test.go b/exp/f32/affine_test.go index f1d84cdd9..0c7009750 100644 --- a/exp/f32/affine_test.go +++ b/exp/f32/affine_test.go @@ -1,3 +1,7 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package f32 import ( diff --git a/exp/f32/f32.go b/exp/f32/f32.go index 59e1b651c..a0a3ed0d9 100644 --- a/exp/f32/f32.go +++ b/exp/f32/f32.go @@ -23,7 +23,7 @@ // The interface to this package is not stable. It will change considerably. // Only use functions that provide package documentation. Semantics are // non-obvious. Be prepared for the package name to change. -package f32 // import "golang.org/x/mobile/exp/f32" +package f32 import ( "encoding/binary" diff --git a/exp/f32/gen.go b/exp/f32/gen.go index fdd1c3f63..267948381 100644 --- a/exp/f32/gen.go +++ b/exp/f32/gen.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build ignore -// +build ignore package main @@ -17,9 +16,9 @@ import ( "flag" "fmt" "go/format" - "io/ioutil" "log" "math" + "os" ) // N is the number of entries in the sin look-up table. It must be a power of 2. @@ -43,7 +42,7 @@ func main() { if err != nil { log.Fatal(err) } - if err := ioutil.WriteFile(*filename, data, 0644); err != nil { + if err := os.WriteFile(*filename, data, 0644); err != nil { log.Fatal(err) } } diff --git a/exp/font/doc.go b/exp/font/doc.go index 5ae720518..349feb461 100644 --- a/exp/font/doc.go +++ b/exp/font/doc.go @@ -3,4 +3,4 @@ // license that can be found in the LICENSE file. // Package font provides platform independent access to system fonts. -package font // import "golang.org/x/mobile/exp/font" +package font diff --git a/exp/font/font.go b/exp/font/font.go index c14513409..02e2b9765 100644 --- a/exp/font/font.go +++ b/exp/font/font.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build linux || darwin -// +build linux darwin package font diff --git a/exp/font/font_android.go b/exp/font/font_android.go index 3503ec991..bbc0f34e2 100644 --- a/exp/font/font_android.go +++ b/exp/font/font_android.go @@ -4,12 +4,12 @@ package font -import "io/ioutil" +import "os" func buildDefault() ([]byte, error) { - return ioutil.ReadFile("/system/fonts/DroidSans.ttf") + return os.ReadFile("/system/fonts/DroidSans.ttf") } func buildMonospace() ([]byte, error) { - return ioutil.ReadFile("/system/fonts/DroidSansMono.ttf") + return os.ReadFile("/system/fonts/DroidSansMono.ttf") } diff --git a/exp/font/font_linux.go b/exp/font/font_linux.go index 65316233e..c0f00c88d 100644 --- a/exp/font/font_linux.go +++ b/exp/font/font_linux.go @@ -3,17 +3,16 @@ // license that can be found in the LICENSE file. //go:build !android -// +build !android package font -import "io/ioutil" +import "os" func buildDefault() ([]byte, error) { // Try Noto first, but fall back to Droid as the latter was deprecated - noto, nerr := ioutil.ReadFile("/usr/share/fonts/truetype/noto/NotoSans-Regular.ttf") + noto, nerr := os.ReadFile("/usr/share/fonts/truetype/noto/NotoSans-Regular.ttf") if nerr != nil { - if droid, err := ioutil.ReadFile("/usr/share/fonts/truetype/droid/DroidSans.ttf"); err == nil { + if droid, err := os.ReadFile("/usr/share/fonts/truetype/droid/DroidSans.ttf"); err == nil { return droid, nil } } @@ -22,9 +21,9 @@ func buildDefault() ([]byte, error) { func buildMonospace() ([]byte, error) { // Try Noto first, but fall back to Droid as the latter was deprecated - noto, nerr := ioutil.ReadFile("/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf") + noto, nerr := os.ReadFile("/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf") if nerr != nil { - if droid, err := ioutil.ReadFile("/usr/share/fonts/truetype/droid/DroidSansMono.ttf"); err == nil { + if droid, err := os.ReadFile("/usr/share/fonts/truetype/droid/DroidSansMono.ttf"); err == nil { return droid, nil } } diff --git a/exp/font/font_test.go b/exp/font/font_test.go index c93c28237..f98752565 100644 --- a/exp/font/font_test.go +++ b/exp/font/font_test.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build linux || darwin -// +build linux darwin package font diff --git a/exp/gl/glutil/context_darwin_desktop.go b/exp/gl/glutil/context_darwin_desktop.go index 344c73e41..725cdd2e6 100644 --- a/exp/gl/glutil/context_darwin_desktop.go +++ b/exp/gl/glutil/context_darwin_desktop.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin && !ios -// +build darwin,!ios package glutil diff --git a/exp/gl/glutil/context_x11.go b/exp/gl/glutil/context_x11.go index 394f1b197..826b026d5 100644 --- a/exp/gl/glutil/context_x11.go +++ b/exp/gl/glutil/context_x11.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build linux && !android -// +build linux,!android package glutil diff --git a/exp/gl/glutil/doc.go b/exp/gl/glutil/doc.go index 44b121075..94e4a6ce1 100644 --- a/exp/gl/glutil/doc.go +++ b/exp/gl/glutil/doc.go @@ -3,4 +3,4 @@ // license that can be found in the LICENSE file. // Package glutil implements OpenGL utility functions. -package glutil // import "golang.org/x/mobile/exp/gl/glutil" +package glutil diff --git a/exp/gl/glutil/glimage.go b/exp/gl/glutil/glimage.go index ffe953d54..72a205f8c 100644 --- a/exp/gl/glutil/glimage.go +++ b/exp/gl/glutil/glimage.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build linux || darwin || windows -// +build linux darwin windows package glutil diff --git a/exp/gl/glutil/glimage_test.go b/exp/gl/glutil/glimage_test.go index 975e30504..2468303b4 100644 --- a/exp/gl/glutil/glimage_test.go +++ b/exp/gl/glutil/glimage_test.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || (linux && !android) -// +build darwin linux,!android // TODO(crawshaw): Run tests on other OSs when more contexts are supported. diff --git a/exp/gl/glutil/glutil.go b/exp/gl/glutil/glutil.go index 18b09113b..26edca145 100644 --- a/exp/gl/glutil/glutil.go +++ b/exp/gl/glutil/glutil.go @@ -3,9 +3,8 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows -package glutil // import "golang.org/x/mobile/exp/gl/glutil" +package glutil import ( "fmt" diff --git a/exp/sensor/android.c b/exp/sensor/android.c index 1ac722351..1cf934014 100644 --- a/exp/sensor/android.c +++ b/exp/sensor/android.c @@ -61,7 +61,7 @@ int GoAndroid_readQueue(int n, int32_t* types, int64_t* timestamps, float* vecto // Try n times read from the event queue. // If anytime timeout occurs, don't retry to read and immediately return. // Consume the event queue entirely between polls. - while (i < n && (id = ALooper_pollAll(GO_ANDROID_READ_TIMEOUT_MS, NULL, &events, NULL)) >= 0) { + while (i < n && (id = ALooper_pollOnce(GO_ANDROID_READ_TIMEOUT_MS, NULL, &events, NULL)) >= 0) { if (id != GO_ANDROID_SENSOR_LOOPER_ID) { continue; } diff --git a/exp/sensor/android.go b/exp/sensor/android.go index ad8a98b6e..a44861450 100644 --- a/exp/sensor/android.go +++ b/exp/sensor/android.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build android -// +build android package sensor diff --git a/exp/sensor/darwin_armx.go b/exp/sensor/darwin_armx.go index 2c8df049a..699a7aa72 100644 --- a/exp/sensor/darwin_armx.go +++ b/exp/sensor/darwin_armx.go @@ -3,8 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin && (arm || arm64) -// +build darwin -// +build arm arm64 package sensor diff --git a/exp/sensor/notmobile.go b/exp/sensor/notmobile.go index 3362e548c..dc6f328c0 100644 --- a/exp/sensor/notmobile.go +++ b/exp/sensor/notmobile.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build (linux && !android) || (darwin && !arm && !arm64) || windows -// +build linux,!android darwin,!arm,!arm64 windows package sensor diff --git a/exp/sensor/sensor.go b/exp/sensor/sensor.go index 2c697b6dd..d03003504 100644 --- a/exp/sensor/sensor.go +++ b/exp/sensor/sensor.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package sensor provides sensor events from various movement sensors. -package sensor // import "golang.org/x/mobile/exp/sensor" +package sensor import ( "errors" diff --git a/exp/sprite/clock/clock.go b/exp/sprite/clock/clock.go index a468e66e7..6d4dbc27b 100644 --- a/exp/sprite/clock/clock.go +++ b/exp/sprite/clock/clock.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package clock provides a clock and time functions for a sprite engine. -package clock // import "golang.org/x/mobile/exp/sprite/clock" +package clock // A Time represents an instant in sprite time. // diff --git a/exp/sprite/glsprite/glsprite.go b/exp/sprite/glsprite/glsprite.go index 4f2522b54..32ca899e5 100644 --- a/exp/sprite/glsprite/glsprite.go +++ b/exp/sprite/glsprite/glsprite.go @@ -3,13 +3,12 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || windows -// +build darwin linux windows // Package glsprite implements a sprite Engine using OpenGL ES 2. // // Each sprite.Texture is loaded as a GL texture object and drawn // to the screen via an affine transform done in a simple shader. -package glsprite // import "golang.org/x/mobile/exp/sprite/glsprite" +package glsprite import ( "image" diff --git a/exp/sprite/portable/affine_test.go b/exp/sprite/portable/affine_test.go index 4b98e7c44..943a81267 100644 --- a/exp/sprite/portable/affine_test.go +++ b/exp/sprite/portable/affine_test.go @@ -9,7 +9,6 @@ import ( "image/color" "image/draw" "image/png" - "io/ioutil" "math" "os" "runtime" @@ -147,7 +146,7 @@ func TestAffineMask(t *testing.T) { } func writeTempPNG(prefix string, m image.Image) (string, error) { - f, err := ioutil.TempFile("", prefix+"-") + f, err := os.CreateTemp("", prefix+"-") if err != nil { return "", err } diff --git a/exp/sprite/portable/portable.go b/exp/sprite/portable/portable.go index 4b6c9155f..bcf07240d 100644 --- a/exp/sprite/portable/portable.go +++ b/exp/sprite/portable/portable.go @@ -7,7 +7,7 @@ // It is intended to serve as a reference implementation for testing // other sprite Engines written against OpenGL, or other more exotic // modern hardware interfaces. -package portable // import "golang.org/x/mobile/exp/sprite/portable" +package portable import ( "image" diff --git a/exp/sprite/sprite.go b/exp/sprite/sprite.go index df13fb595..cbc9f458e 100644 --- a/exp/sprite/sprite.go +++ b/exp/sprite/sprite.go @@ -22,7 +22,7 @@ // modify the scene's nodes and animations (Arranger values) // e.Render(scene, t, sz) // } -package sprite // import "golang.org/x/mobile/exp/sprite" +package sprite import ( "image" diff --git a/geom/geom.go b/geom/geom.go index 23cf67bea..6b7394465 100644 --- a/geom/geom.go +++ b/geom/geom.go @@ -19,7 +19,7 @@ the screen. Positions on the plane are measured in typographic points, Any interface that draws to the screen using types from the geom package scales the number of pixels to maintain a Pt as 1/72 of an inch. */ -package geom // import "golang.org/x/mobile/geom" +package geom /* Notes on the various underlying coordinate systems. @@ -74,7 +74,7 @@ import "fmt" // // The unit Pt is a typographical point, 1/72 of an inch (0.3527 mm). // -// It can be be converted to a length in current device pixels by +// It can be converted to a length in current device pixels by // multiplying with PixelsPerPt after app initialization is complete. type Pt float32 diff --git a/gl/consts.go b/gl/consts.go index 370d0b859..62d93aab0 100644 --- a/gl/consts.go +++ b/gl/consts.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/gl/dll_windows.go b/gl/dll_windows.go index 1afc5f8ef..b7a0d90ee 100644 --- a/gl/dll_windows.go +++ b/gl/dll_windows.go @@ -10,7 +10,6 @@ import ( "debug/pe" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -18,7 +17,7 @@ import ( "runtime" ) -var debug = log.New(ioutil.Discard, "gl: ", log.LstdFlags) +var debug = log.New(io.Discard, "gl: ", log.LstdFlags) func downloadDLLs() (path string, err error) { url := "https://dl.google.com/go/mobile/angle-bd3f8780b-" + runtime.GOARCH + ".tgz" @@ -54,11 +53,11 @@ func downloadDLLs() (path string, err error) { } switch header.Name { case "angle-" + runtime.GOARCH + "/libglesv2.dll": - bytesGLESv2, err = ioutil.ReadAll(tr) + bytesGLESv2, err = io.ReadAll(tr) case "angle-" + runtime.GOARCH + "/libegl.dll": - bytesEGL, err = ioutil.ReadAll(tr) + bytesEGL, err = io.ReadAll(tr) case "angle-" + runtime.GOARCH + "/d3dcompiler_47.dll": - bytesD3DCompiler, err = ioutil.ReadAll(tr) + bytesD3DCompiler, err = io.ReadAll(tr) default: // skip } if err != nil { @@ -70,13 +69,13 @@ func downloadDLLs() (path string, err error) { } writeDLLs := func(path string) error { - if err := ioutil.WriteFile(filepath.Join(path, "libglesv2.dll"), bytesGLESv2, 0755); err != nil { + if err := os.WriteFile(filepath.Join(path, "libglesv2.dll"), bytesGLESv2, 0755); err != nil { return fmt.Errorf("gl: cannot install ANGLE: %v", err) } - if err := ioutil.WriteFile(filepath.Join(path, "libegl.dll"), bytesEGL, 0755); err != nil { + if err := os.WriteFile(filepath.Join(path, "libegl.dll"), bytesEGL, 0755); err != nil { return fmt.Errorf("gl: cannot install ANGLE: %v", err) } - if err := ioutil.WriteFile(filepath.Join(path, "d3dcompiler_47.dll"), bytesD3DCompiler, 0755); err != nil { + if err := os.WriteFile(filepath.Join(path, "d3dcompiler_47.dll"), bytesD3DCompiler, 0755); err != nil { return fmt.Errorf("gl: cannot install ANGLE: %v", err) } return nil @@ -152,7 +151,7 @@ func chromePath() string { } for _, installdir := range installdirs { - versiondirs, err := ioutil.ReadDir(installdir) + versiondirs, err := os.ReadDir(installdir) if err != nil { continue } diff --git a/gl/doc.go b/gl/doc.go index 880d5f925..408c35a68 100644 --- a/gl/doc.go +++ b/gl/doc.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -42,7 +42,7 @@ error messages. For example, The gldebug tracing has very high overhead, so make sure to remove the build tag before deploying any binaries. */ -package gl // import "golang.org/x/mobile/gl" +package gl /* Implementation details. diff --git a/gl/fn.go b/gl/fn.go index 3f2f3adea..c34e51662 100644 --- a/gl/fn.go +++ b/gl/fn.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/gl/gendebug.go b/gl/gendebug.go index 2e6563cd8..b04e3ca28 100644 --- a/gl/gendebug.go +++ b/gl/gendebug.go @@ -1,9 +1,8 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore -// +build ignore // The gendebug program takes gl.go and generates a version of it // where each function includes tracing code that writes its arguments @@ -19,7 +18,6 @@ import ( "go/parser" "go/printer" "go/token" - "io/ioutil" "log" "os" "strconv" @@ -836,7 +834,7 @@ func main() { os.Stdout.Write(b) return } - if err := ioutil.WriteFile(*outfile, b, 0666); err != nil { + if err := os.WriteFile(*outfile, b, 0666); err != nil { die(err) } } @@ -878,15 +876,14 @@ func setEnqueueBlocking(c *ast.CallExpr) { }) } -const preamble = `// Copyright 2014 The Go Authors. All rights reserved. +const preamble = `// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Code generated from gl.go using go generate. DO NOT EDIT. // See doc.go for details. -// +build darwin linux openbsd windows -// +build gldebug +//go:build (darwin || linux || openbsd || windows) && gldebug package gl diff --git a/gl/gl.go b/gl/gl.go index 195a30919..2272c59d1 100644 --- a/gl/gl.go +++ b/gl/gl.go @@ -1,10 +1,8 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build (darwin || linux || openbsd || windows) && !gldebug -// +build darwin linux openbsd windows -// +build !gldebug package gl diff --git a/gl/gldebug.go b/gl/gldebug.go index 5a4bf71da..b3aca42e3 100644 --- a/gl/gldebug.go +++ b/gl/gldebug.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -6,8 +6,6 @@ // See doc.go for details. //go:build (darwin || linux || openbsd || windows) && gldebug -// +build darwin linux openbsd windows -// +build gldebug package gl diff --git a/gl/interface.go b/gl/interface.go index 189c29e4e..693abe422 100644 --- a/gl/interface.go +++ b/gl/interface.go @@ -1,4 +1,4 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -81,7 +81,7 @@ type Context interface { // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFunc.xhtml BlendFunc(sfactor, dfactor Enum) - // BlendFunc sets the pixel RGB and alpha blending factors separately. + // BlendFuncSeparate sets the pixel RGB and alpha blending factors separately. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendFuncSeparate.xhtml BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha Enum) @@ -192,7 +192,7 @@ type Context interface { // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenTextures.xhtml CreateTexture() Texture - // CreateTVertexArray creates a vertex array. + // CreateVertexArray creates a vertex array. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenVertexArrays.xhtml CreateVertexArray() VertexArray @@ -599,7 +599,7 @@ type Context interface { // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilFunc.xhtml StencilFunc(fn Enum, ref int, mask uint32) - // StencilFunc sets the front or back stencil test reference value. + // StencilFuncSeparate sets the front or back stencil test reference value. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glStencilFuncSeparate.xhtml StencilFuncSeparate(face, fn Enum, ref int, mask uint32) @@ -737,7 +737,7 @@ type Context interface { // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml Uniform4i(dst Uniform, v0, v1, v2, v3 int32) - // Uniform4i writes an ivec4 uniform array of len(src)/4 elements. + // Uniform4iv writes an ivec4 uniform array of len(src)/4 elements. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glUniform.xhtml Uniform4iv(dst Uniform, src []int32) diff --git a/gl/types_debug.go b/gl/types_debug.go index b6dbaaad0..e9e9bd7c8 100644 --- a/gl/types_debug.go +++ b/gl/types_debug.go @@ -1,10 +1,8 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build (darwin || linux || openbsd || windows) && gldebug -// +build darwin linux openbsd windows -// +build gldebug package gl diff --git a/gl/types_prod.go b/gl/types_prod.go index e1c8b423c..6817c6f04 100644 --- a/gl/types_prod.go +++ b/gl/types_prod.go @@ -1,10 +1,8 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build (darwin || linux || openbsd || windows) && !gldebug -// +build darwin linux openbsd windows -// +build !gldebug package gl diff --git a/gl/work.go b/gl/work.go index 65eaf9a23..a778b0c52 100644 --- a/gl/work.go +++ b/gl/work.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build darwin || linux || openbsd -// +build darwin linux openbsd package gl @@ -161,7 +160,7 @@ func (ctx *context) cString(str string) (uintptr, func()) { return uintptr(ptr), func() { C.free(ptr) } } -// cString creates a pointer to a C string off the Go heap. +// cStringPtr creates a pointer to a C string off the Go heap. // ret is a **char. func (ctx *context) cStringPtr(str string) (uintptr, func()) { s, free := ctx.cString(str) diff --git a/gl/work_other.go b/gl/work_other.go index b4b48f445..3bc597d43 100644 --- a/gl/work_other.go +++ b/gl/work_other.go @@ -3,8 +3,6 @@ // license that can be found in the LICENSE file. //go:build (!cgo || (!darwin && !linux && !openbsd)) && !windows -// +build !cgo !darwin,!linux,!openbsd -// +build !windows package gl diff --git a/go.mod b/go.mod index 4cbf6276e..b7f2f9847 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,30 @@ module golang.org/x/mobile -go 1.17 +go 1.24.0 + +// The modern go/types type checker produces types.Alias +// types for the explicit representation of type aliases. +// (Initial opt-in support for it was added in Go 1.22, +// and it became the default behavior in Go 1.23.) +// +// TODO(go.dev/issue/70698): Update the golang.org/x/mobile/bind +// code generator for the new behavior and delete this temporary¹ +// forced pre-1.23 go/types behavior. +// +// ¹ It's temporary because this godebug setting will be removed +// in a future Go release. +godebug gotypesalias=0 require ( - golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 - golang.org/x/image v0.0.0-20190802002840-cff245a6509b - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 - golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde - golang.org/x/tools v0.1.12 + golang.org/x/exp/shiny v0.0.0-20250819193227-8b4c13bb791b + golang.org/x/image v0.31.0 + golang.org/x/mod v0.28.0 + golang.org/x/sync v0.17.0 + golang.org/x/tools v0.37.0 + golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated ) -require golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect +require ( + golang.org/x/sys v0.36.0 // indirect + golang.org/x/tools/go/expect v0.1.1-deprecated // indirect +) diff --git a/go.sum b/go.sum index 7a596ad12..f8cbd894c 100644 --- a/go.sum +++ b/go.sum @@ -1,41 +1,18 @@ -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU= -golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde h1:ejfdSekXMDxDLbRrJMwUk6KnSLZ2McaUCVcIKM+N6jc= -golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +golang.org/x/exp/shiny v0.0.0-20250819193227-8b4c13bb791b h1:OeyDhfAaNf4u4sBKDtc4k1iKGYngpGDa1L/1Ch049HA= +golang.org/x/exp/shiny v0.0.0-20250819193227-8b4c13bb791b/go.mod h1:QnFR+evpZFrYgSiu+d/Rn6g/6bNqLQTp+rzKaVpFoeI= +golang.org/x/image v0.31.0 h1:mLChjE2MV6g1S7oqbXC0/UcKijjm5fnJLUYKIYrLESA= +golang.org/x/image v0.31.0/go.mod h1:R9ec5Lcp96v9FTF+ajwaH3uGxPH4fKfHHAVbUILxghA= +golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U= +golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE= +golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w= +golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM= +golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY= +golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM= +golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8= diff --git a/internal/binres/arsc.go b/internal/binres/arsc.go index 1b4dff223..bd583ffa5 100644 --- a/internal/binres/arsc.go +++ b/internal/binres/arsc.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/internal/binres/binres.go b/internal/binres/binres.go index d77bde265..2f6dc7aae 100644 --- a/internal/binres/binres.go +++ b/internal/binres/binres.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/internal/binres/binres_test.go b/internal/binres/binres_test.go index dbac875a1..fecefaca4 100644 --- a/internal/binres/binres_test.go +++ b/internal/binres/binres_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -8,8 +8,8 @@ import ( "bytes" "encoding" "encoding/xml" + "errors" "fmt" - "io/ioutil" "log" "math" "os" @@ -103,11 +103,11 @@ func compareBytes(a, b []byte) error { fmt.Fprint(buf, "... output truncated.\n") } } - return fmt.Errorf(buf.String()) + return errors.New(buf.String()) } func TestBootstrap(t *testing.T) { - bin, err := ioutil.ReadFile("testdata/bootstrap.bin") + bin, err := os.ReadFile("testdata/bootstrap.bin") if err != nil { log.Fatal(err) } @@ -217,7 +217,7 @@ func TestEncode(t *testing.T) { t.Fatal(err) } - bin, err := ioutil.ReadFile("testdata/bootstrap.bin") + bin, err := os.ReadFile("testdata/bootstrap.bin") if err != nil { log.Fatal(err) } @@ -329,7 +329,7 @@ func compareElements(have, want *XML) error { } } if buf.Len() > 0 { - return fmt.Errorf(buf.String()) + return errors.New(buf.String()) } return nil } diff --git a/internal/binres/genarsc.go b/internal/binres/genarsc.go index 4ec35fbc5..f05963646 100644 --- a/internal/binres/genarsc.go +++ b/internal/binres/genarsc.go @@ -1,9 +1,8 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore -// +build ignore // Genarsc generates stripped down version of android.jar resources used // for validation of manifest entries. @@ -13,14 +12,14 @@ package main import ( "fmt" - "io/ioutil" "log" + "os" "strconv" "golang.org/x/mobile/internal/binres" ) -const tmpl = `// Copyright 2016 The Go Authors. All rights reserved. +const tmpl = `// Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -35,7 +34,7 @@ func main() { if err != nil { log.Fatal(err) } - if err := ioutil.WriteFile("arsc.go", []byte(fmt.Sprintf(tmpl, strconv.Quote(string(arsc)))), 0644); err != nil { + if err := os.WriteFile("arsc.go", []byte(fmt.Sprintf(tmpl, strconv.Quote(string(arsc)))), 0644); err != nil { log.Fatal(err) } } diff --git a/internal/binres/node.go b/internal/binres/node.go index 491825143..20328fb9e 100644 --- a/internal/binres/node.go +++ b/internal/binres/node.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/internal/binres/pool.go b/internal/binres/pool.go index 273e94c72..c90350ce7 100644 --- a/internal/binres/pool.go +++ b/internal/binres/pool.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/internal/binres/sdk.go b/internal/binres/sdk.go index 607e0b7dc..44419c6ce 100644 --- a/internal/binres/sdk.go +++ b/internal/binres/sdk.go @@ -1,3 +1,7 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package binres import ( diff --git a/internal/binres/table.go b/internal/binres/table.go index b552cbaff..06dfb4392 100644 --- a/internal/binres/table.go +++ b/internal/binres/table.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Go Authors. All rights reserved. +// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/internal/importers/ast.go b/internal/importers/ast.go index 64da4a188..dafad08b8 100644 --- a/internal/importers/ast.go +++ b/internal/importers/ast.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/internal/importers/ast_test.go b/internal/importers/ast_test.go index 8e329940e..52c6d6304 100644 --- a/internal/importers/ast_test.go +++ b/internal/importers/ast_test.go @@ -1,3 +1,7 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package importers import ( diff --git a/internal/sdkpath/sdkpath.go b/internal/sdkpath/sdkpath.go index 91e9a5124..cdcf152cb 100644 --- a/internal/sdkpath/sdkpath.go +++ b/internal/sdkpath/sdkpath.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Go Authors. All rights reserved. +// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.