cmd/gomobile: use package path as the app name

If the application main package is in

  golang.org/x/mobile/example/basic

the generated application will have "Basic" as its name.

Change-Id: Ic59fae6e18c26e406ab352265aa2d6b11619c102
Reviewed-on: https://go-review.googlesource.com/12435
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Burcu Dogan 2015-07-20 15:23:17 -07:00
parent 6256dc3e64
commit a1efd1d6c6
1 changed files with 16 additions and 4 deletions

View File

@ -5,6 +5,7 @@
package main
import (
"bytes"
"fmt"
"go/build"
"io/ioutil"
@ -13,6 +14,7 @@ import (
"path"
"path/filepath"
"strings"
"text/template"
)
func goIOSBuild(pkg *build.Package) error {
@ -21,9 +23,15 @@ func goIOSBuild(pkg *build.Package) error {
return fmt.Errorf("-o must have an .app for target=ios")
}
infoplist := new(bytes.Buffer)
if err := infoplistTmpl.Execute(infoplist, manifestTmplData{
Name: strings.Title(path.Base(pkg.ImportPath)),
}); err != nil {
return err
}
layout := map[string][]byte{
tmpdir + "/main.xcodeproj/project.pbxproj": []byte(projPbxproj),
tmpdir + "/main/Info.plist": []byte(infoPlist),
tmpdir + "/main/Info.plist": infoplist.Bytes(),
tmpdir + "/main/Images.xcassets/AppIcon.appiconset/Contents.json": []byte(contentsJSON),
}
@ -130,14 +138,18 @@ func iosCopyAssets(pkg *build.Package, xcodeProjDir string) error {
})
}
const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
type infoplistTmplData struct {
Name string
}
var infoplistTmpl = template.Must(template.New("infoplist").Parse(`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>main</string>
<string>{{.Name}}</string>
<key>CFBundleIdentifier</key>
<string>org.golang.todo.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
@ -175,7 +187,7 @@ const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
</array>
</dict>
</plist>
`
`))
const projPbxproj = `// !$*UTF8*$!
{