gogio: replace deprecated calls

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2024-01-09 14:51:45 -05:00
parent cb72b91a92
commit 7a117566ca
6 changed files with 28 additions and 25 deletions
+7 -8
View File
@@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -405,7 +404,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(filepath.Join(v26mipmapDir, `ic_launcher.xml`), []byte(`<?xml version="1.0" encoding="utf-8"?> err = os.WriteFile(filepath.Join(v26mipmapDir, `ic_launcher.xml`), []byte(`<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_adaptive" /> <background android:drawable="@mipmap/ic_launcher_adaptive" />
<foreground android:drawable="@mipmap/ic_launcher_adaptive" /> <foreground android:drawable="@mipmap/ic_launcher_adaptive" />
@@ -415,11 +414,11 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
} }
iconSnip = `android:icon="@mipmap/ic_launcher"` iconSnip = `android:icon="@mipmap/ic_launcher"`
} }
err = ioutil.WriteFile(filepath.Join(valDir, "themes.xml"), []byte(themes), 0660) err = os.WriteFile(filepath.Join(valDir, "themes.xml"), []byte(themes), 0660)
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(filepath.Join(v21Dir, "themes.xml"), []byte(themesV21), 0660) err = os.WriteFile(filepath.Join(v21Dir, "themes.xml"), []byte(themesV21), 0660)
if err != nil { if err != nil {
return err return err
} }
@@ -436,7 +435,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
// Link APK. // Link APK.
permissions, features := getPermissions(perms) permissions, features := getPermissions(perms)
appName := strings.Title(bi.name) appName := UppercaseName(bi.name)
manifestSrc := manifestData{ manifestSrc := manifestData{
AppID: bi.appID, AppID: bi.appID,
Version: bi.version, Version: bi.version,
@@ -475,7 +474,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
return err return err
} }
manifest := filepath.Join(tmpDir, "AndroidManifest.xml") manifest := filepath.Join(tmpDir, "AndroidManifest.xml")
if err := ioutil.WriteFile(manifest, manifestBuffer.Bytes(), 0660); err != nil { if err := os.WriteFile(manifest, manifestBuffer.Bytes(), 0660); err != nil {
return err return err
} }
@@ -991,12 +990,12 @@ func (z *zipWriter) Close() error {
func (z *zipWriter) Create(name string) io.Writer { func (z *zipWriter) Create(name string) io.Writer {
if z.err != nil { if z.err != nil {
return ioutil.Discard return io.Discard
} }
w, err := z.w.Create(name) w, err := z.w.Create(name)
if err != nil { if err != nil {
z.err = err z.err = err
return ioutil.Discard return io.Discard
} }
return &errWriter{w: w, err: &z.err} return &errWriter{w: w, err: &z.err}
} }
+8
View File
@@ -9,6 +9,8 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"unicode"
"unicode/utf8"
) )
type buildInfo struct { type buildInfo struct {
@@ -74,6 +76,12 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
return bi, nil return bi, nil
} }
// UppercaseName returns a string with its first rune in uppercase.
func UppercaseName(name string) string {
ch, w := utf8.DecodeRuneInString(name)
return string(unicode.ToUpper(ch)) + name[w:]
}
func (s Semver) String() string { func (s Semver) String() string {
return fmt.Sprintf("%d.%d.%d", s.Major, s.Minor, s.Patch) return fmt.Sprintf("%d.%d.%d", s.Major, s.Minor, s.Patch)
} }
+1 -2
View File
@@ -10,7 +10,6 @@ import (
"image" "image"
"image/color" "image/color"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
@@ -316,7 +315,7 @@ func (d *driverBase) needPrograms(names ...string) {
func (d *driverBase) tempDir(name string) string { func (d *driverBase) tempDir(name string) string {
d.Helper() d.Helper()
dir, err := ioutil.TempDir("", name) dir, err := os.MkdirTemp("", name)
if err != nil { if err != nil {
d.Fatal(err) d.Fatal(err)
} }
+8 -9
View File
@@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -33,7 +32,7 @@ func buildIOS(tmpDir, target string, bi *buildInfo) error {
case "archive": case "archive":
framework := *destPath framework := *destPath
if framework == "" { if framework == "" {
framework = fmt.Sprintf("%s.framework", strings.Title(appName)) framework = fmt.Sprintf("%s.framework", UppercaseName(appName))
} }
return archiveIOS(tmpDir, target, framework, bi) return archiveIOS(tmpDir, target, framework, bi)
case "exe": case "exe":
@@ -142,7 +141,7 @@ func signIOS(bi *buildInfo, tmpDir, app string) error {
return err return err
} }
entFile := filepath.Join(tmpDir, "entitlements.plist") entFile := filepath.Join(tmpDir, "entitlements.plist")
if err := ioutil.WriteFile(entFile, []byte(entitlements), 0660); err != nil { if err := os.WriteFile(entFile, []byte(entitlements), 0660); err != nil {
return err return err
} }
identity := sha1.Sum(certDER) identity := sha1.Sum(certDER)
@@ -186,10 +185,10 @@ int main(int argc, char * argv[]) {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([GioAppDelegate class])); return UIApplicationMain(argc, argv, nil, NSStringFromClass([GioAppDelegate class]));
} }
}` }`
if err := ioutil.WriteFile(mainm, []byte(mainmSrc), 0660); err != nil { if err := os.WriteFile(mainm, []byte(mainmSrc), 0660); err != nil {
return err return err
} }
appName := strings.Title(bi.name) appName := UppercaseName(bi.name)
exe := filepath.Join(app, appName) exe := filepath.Join(app, appName)
lipo := exec.Command("xcrun", "lipo", "-o", exe, "-create") lipo := exec.Command("xcrun", "lipo", "-o", exe, "-create")
var builds errgroup.Group var builds errgroup.Group
@@ -223,7 +222,7 @@ int main(int argc, char * argv[]) {
} }
infoPlist := buildInfoPlist(bi) infoPlist := buildInfoPlist(bi)
plistFile := filepath.Join(app, "Info.plist") plistFile := filepath.Join(app, "Info.plist")
if err := ioutil.WriteFile(plistFile, []byte(infoPlist), 0660); err != nil { if err := os.WriteFile(plistFile, []byte(infoPlist), 0660); err != nil {
return err return err
} }
if _, err := os.Stat(bi.iconPath); err == nil { if _, err := os.Stat(bi.iconPath); err == nil {
@@ -288,7 +287,7 @@ func iosIcons(bi *buildInfo, tmpDir, appDir, icon string) (string, error) {
] ]
}` }`
contentFile := filepath.Join(appIcon, "Contents.json") contentFile := filepath.Join(appIcon, "Contents.json")
if err := ioutil.WriteFile(contentFile, []byte(contentJson), 0600); err != nil { if err := os.WriteFile(contentFile, []byte(contentJson), 0600); err != nil {
return "", err return "", err
} }
assetPlist := filepath.Join(tmpDir, "assets.plist") assetPlist := filepath.Join(tmpDir, "assets.plist")
@@ -310,7 +309,7 @@ func iosIcons(bi *buildInfo, tmpDir, appDir, icon string) (string, error) {
} }
func buildInfoPlist(bi *buildInfo) string { func buildInfoPlist(bi *buildInfo) string {
appName := strings.Title(bi.name) appName := UppercaseName(bi.name)
platform := iosPlatformFor(bi.target) platform := iosPlatformFor(bi.target)
var supportPlatform string var supportPlatform string
switch bi.target { switch bi.target {
@@ -475,7 +474,7 @@ func archiveIOS(tmpDir, target, frameworkRoot string, bi *buildInfo) error {
export * export *
}`, framework) }`, framework)
moduleFile := filepath.Join(frameworkDir, "Modules", "module.modulemap") moduleFile := filepath.Join(frameworkDir, "Modules", "module.modulemap")
return ioutil.WriteFile(moduleFile, []byte(module), 0644) return os.WriteFile(moduleFile, []byte(module), 0644)
} }
func iosCompilerFor(target, arch string, minsdk int) (string, []string, error) { func iosCompilerFor(target, arch string, minsdk int) (string, []string, error) {
+3 -4
View File
@@ -6,7 +6,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -45,11 +44,11 @@ func buildJS(bi *buildInfo) error {
var faviconPath string var faviconPath string
if _, err := os.Stat(bi.iconPath); err == nil { if _, err := os.Stat(bi.iconPath); err == nil {
// Copy icon to the output folder // Copy icon to the output folder
icon, err := ioutil.ReadFile(bi.iconPath) icon, err := os.ReadFile(bi.iconPath)
if err != nil { if err != nil {
return err return err
} }
if err := ioutil.WriteFile(filepath.Join(out, filepath.Base(bi.iconPath)), icon, 0600); err != nil { if err := os.WriteFile(filepath.Join(out, filepath.Base(bi.iconPath)), icon, 0600); err != nil {
return err return err
} }
faviconPath = filepath.Base(bi.iconPath) faviconPath = filepath.Base(bi.iconPath)
@@ -71,7 +70,7 @@ func buildJS(bi *buildInfo) error {
return err return err
} }
if err := ioutil.WriteFile(filepath.Join(out, "index.html"), b.Bytes(), 0600); err != nil { if err := os.WriteFile(filepath.Join(out, "index.html"), b.Bytes(), 0600); err != nil {
return err return err
} }
+1 -2
View File
@@ -11,7 +11,6 @@ import (
"image/color" "image/color"
"image/png" "image/png"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -86,7 +85,7 @@ func flagValidate() error {
} }
func build(bi *buildInfo) error { func build(bi *buildInfo) error {
tmpDir, err := ioutil.TempDir("", "gogio-") tmpDir, err := os.MkdirTemp("", "gogio-")
if err != nil { if err != nil {
return err return err
} }