Skip to content

Commit

Permalink
cmd/fyne use install subcommand on iossimulator
Browse files Browse the repository at this point in the history
  • Loading branch information
changkun committed Sep 23, 2021
1 parent add2ce3 commit 8379d88
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
48 changes: 39 additions & 9 deletions cmd/fyne/internal/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/cmd/fyne/internal/mobile"
"fyne.io/fyne/v2/cmd/fyne/internal/util"

"github.com/urfave/cli/v2"
"golang.org/x/sys/execabs"
Expand All @@ -28,7 +29,7 @@ func Install() *cli.Command {
&cli.StringFlag{
Name: "target",
Aliases: []string{"os"},
Usage: "The mobile platform to target (android, android/arm, android/arm64, android/amd64, android/386, ios).",
Usage: "The mobile platform to target (android, android/arm, android/arm64, android/amd64, android/386, ios, iossimulator).",
Destination: &i.os,
},
&cli.StringFlag{
Expand Down Expand Up @@ -130,7 +131,7 @@ func (i *Installer) install() error {
p := i.Packager

if i.os != "" {
if i.os == "ios" {
if util.IsIOS(i.os) {
return i.installIOS()
} else if strings.Index(i.os, "android") == 0 {
return i.installAndroid()
Expand Down Expand Up @@ -183,15 +184,21 @@ func (i *Installer) installAndroid() error {

func (i *Installer) installIOS() error {
target := mobile.AppOutputName(i.os, i.Packager.name)
_, err := os.Stat(target)
if os.IsNotExist(err) {
err := i.Packager.doPackage()
if err != nil {
return nil
}

// Always redo the package because the codesign for ios and iossimulator
// must be different.
if err := i.Packager.doPackage(); err != nil {
return nil
}

return i.runMobileInstall("ios-deploy", target, "--bundle")
switch i.os {
case "ios":
return i.runMobileInstall("ios-deploy", target, "--bundle")
case "iossimulator":
return i.installToIOSSimulator(target)
default:
return fmt.Errorf("unsupported install target: %s", target)
}
}

func (i *Installer) runMobileInstall(tool, target string, args ...string) error {
Expand All @@ -216,3 +223,26 @@ func (i *Installer) validate() error {
i.Packager.release = i.release
return i.Packager.validate()
}

func (i *Installer) installToIOSSimulator(target string) error {
cmd := execabs.Command(
"xcrun", "simctl", "install",
"booted", // Install to the booted simulator.
target)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("Install to a simulator error: %s%s", out, err)
}

i.runInIOSSimulator()
return nil
}

func (i *Installer) runInIOSSimulator() error {
cmd := execabs.Command("xcrun", "simctl", "launch", "booted", i.Packager.appID)
out, err := cmd.CombinedOutput()
if err != nil {
os.Stderr.Write(out)
return err
}
return nil
}
2 changes: 1 addition & 1 deletion cmd/fyne/internal/mobile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func AppOutputName(os, name string) string {
switch os {
case "android":
return androidPkgName(name) + ".apk"
case "ios":
case "ios", "iossimulator":
return rfc1034Label(name) + ".app"
}

Expand Down
10 changes: 7 additions & 3 deletions cmd/fyne/internal/mobile/build_iosapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,13 @@ func goIOSBuild(pkg *packages.Package, bundleID string, archs []string,
}
}

// Use codesign to sign the application so that it can be used in iOS simulator.
if err := execabs.Command("codesign", "--force", "--sign", "-", buildO).Run(); err != nil {
return nil, err
// Use codesign to remove the codesign certificate for the built application
// so that it can run in iOS simulator.
if buildTarget == "iossimulator" {
if out, err := execabs.Command("codesign", "--force", "--sign", "-", buildO).CombinedOutput(); err != nil {
printcmd("codesign --force --sign --keychain %s\n%s", buildO, out)
return nil, err
}
}

return nmpkgs, nil
Expand Down

0 comments on commit 8379d88

Please sign in to comment.