Skip to content

Commit 34a06b5

Browse files
authored
Merge pull request #42 from jld3103/feature/packaging/darwin-pkg
Add support for darwin-bundle and darwin-pkg
2 parents 3dde7fc + 4f5861a commit 34a06b5

File tree

7 files changed

+426
-146
lines changed

7 files changed

+426
-146
lines changed

cmd/build.go

+38-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import (
1414
"github.com/otiai10/copy"
1515
"github.com/spf13/cobra"
1616

17-
"github.com/go-flutter-desktop/hover/cmd/packaging"
1817
"github.com/go-flutter-desktop/hover/internal/build"
1918
"github.com/go-flutter-desktop/hover/internal/enginecache"
2019
"github.com/go-flutter-desktop/hover/internal/fileutils"
2120
"github.com/go-flutter-desktop/hover/internal/log"
2221
"github.com/go-flutter-desktop/hover/internal/pubspec"
23-
"github.com/go-flutter-desktop/hover/internal/versioncheck"
22+
"github.com/go-flutter-desktop/hover/internal/androidmanifest"
23+
"github.com/go-flutter-desktop/hover/internal/versioncheck"
24+
"github.com/go-flutter-desktop/hover/cmd/packaging"
2425
)
2526

2627
var dotSlash = string([]byte{'.', filepath.Separator})
@@ -53,6 +54,8 @@ func init() {
5354
buildCmd.AddCommand(buildLinuxSnapCmd)
5455
buildCmd.AddCommand(buildLinuxDebCmd)
5556
buildCmd.AddCommand(buildDarwinCmd)
57+
buildCmd.AddCommand(buildDarwinBundleCmd)
58+
buildCmd.AddCommand(buildDarwinPkgCmd)
5659
buildCmd.AddCommand(buildWindowsCmd)
5760
rootCmd.AddCommand(buildCmd)
5861
}
@@ -114,6 +117,38 @@ var buildDarwinCmd = &cobra.Command{
114117
},
115118
}
116119

120+
var buildDarwinBundleCmd = &cobra.Command{
121+
Use: "darwin-bundle",
122+
Short: "Build a desktop release for darwin and package it for OSX bundle",
123+
Run: func(cmd *cobra.Command, args []string) {
124+
assertHoverInitialized()
125+
packaging.AssertPackagingFormatInitialized("darwin-bundle")
126+
127+
if !packaging.DockerInstalled() {
128+
os.Exit(1)
129+
}
130+
131+
buildNormal("darwin", nil)
132+
packaging.BuildDarwinBundle()
133+
},
134+
}
135+
136+
var buildDarwinPkgCmd = &cobra.Command{
137+
Use: "darwin-pkg",
138+
Short: "Build a desktop release for darwin and package it for OSX pkg installer",
139+
Run: func(cmd *cobra.Command, args []string) {
140+
assertHoverInitialized()
141+
packaging.AssertPackagingFormatInitialized("darwin-pkg")
142+
143+
if !packaging.DockerInstalled() {
144+
os.Exit(1)
145+
}
146+
147+
buildNormal("darwin", nil)
148+
packaging.BuildDarwinPkg()
149+
},
150+
}
151+
117152
var buildWindowsCmd = &cobra.Command{
118153
Use: "windows",
119154
Short: "Build a desktop release for windows",
@@ -523,7 +558,7 @@ func buildCommand(targetOS string, vmArguments []string, outputBinaryPath string
523558
pubspec.GetPubSpec().Version,
524559
currentTag,
525560
pubspec.GetPubSpec().Name,
526-
androidOrganizationName()))
561+
androidmanifest.AndroidOrganizationName()))
527562

528563
outputCommand := []string{
529564
"go",

cmd/common.go

-143
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package cmd
22

33
import (
44
"bufio"
5-
"encoding/xml"
6-
"fmt"
7-
"io/ioutil"
85
"os"
96
"os/exec"
107
"path/filepath"
@@ -16,15 +13,6 @@ import (
1613
"github.com/go-flutter-desktop/hover/internal/build"
1714
"github.com/go-flutter-desktop/hover/internal/log"
1815
"github.com/go-flutter-desktop/hover/internal/pubspec"
19-
homedir "github.com/mitchellh/go-homedir"
20-
"github.com/pkg/errors"
21-
)
22-
23-
var (
24-
goBin string
25-
flutterBin string
26-
dockerBin string
27-
gitBin string
2816
)
2917

3018
// initBinaries is used to ensure go and flutter exec are found in the
@@ -131,134 +119,3 @@ func askForConfirmation() bool {
131119
}
132120
return false
133121
}
134-
135-
// AndroidManifest is a file that describes the essential information about
136-
// an android app.
137-
type AndroidManifest struct {
138-
Package string `xml:"package,attr"`
139-
}
140-
141-
// androidOrganizationName fetch the android package name (default:
142-
// 'com.example').
143-
// Can by set upon flutter create (--org flag)
144-
//
145-
// If errors occurs when reading the android package name, the string value
146-
// will correspond to 'hover.failed.to.retrieve.package.name'
147-
func androidOrganizationName() string {
148-
// Default value
149-
androidManifestFile := "android/app/src/main/AndroidManifest.xml"
150-
151-
// Open AndroidManifest file
152-
xmlFile, err := os.Open(androidManifestFile)
153-
if err != nil {
154-
log.Errorf("Failed to retrieve the organization name: %v", err)
155-
return "hover.failed.to.retrieve.package.name"
156-
}
157-
defer xmlFile.Close()
158-
159-
byteXMLValue, err := ioutil.ReadAll(xmlFile)
160-
if err != nil {
161-
log.Errorf("Failed to retrieve the organization name: %v", err)
162-
return "hover.failed.to.retrieve.package.name"
163-
}
164-
165-
var androidManifest AndroidManifest
166-
err = xml.Unmarshal(byteXMLValue, &androidManifest)
167-
if err != nil {
168-
log.Errorf("Failed to retrieve the organization name: %v", err)
169-
return "hover.failed.to.retrieve.package.name"
170-
}
171-
javaPackage := strings.Split(androidManifest.Package, ".")
172-
orgName := strings.Join(javaPackage[:len(javaPackage)-1], ".")
173-
if orgName == "" {
174-
return "hover.failed.to.retrieve.package.name"
175-
}
176-
return orgName
177-
}
178-
179-
var camelcaseRegex = regexp.MustCompile("(^[A-Za-z])|_([A-Za-z])")
180-
181-
// toCamelCase take a snake_case string and converts it to camelcase
182-
func toCamelCase(str string) string {
183-
return camelcaseRegex.ReplaceAllStringFunc(str, func(s string) string {
184-
return strings.ToUpper(strings.Replace(s, "_", "", -1))
185-
})
186-
}
187-
188-
// initializeGoModule uses the golang binary to initialize the go module
189-
func initializeGoModule(projectPath string) {
190-
wd, err := os.Getwd()
191-
if err != nil {
192-
log.Errorf("Failed to get working dir: %v\n", err)
193-
os.Exit(1)
194-
}
195-
196-
cmdGoModInit := exec.Command(goBin, "mod", "init", projectPath+"/"+build.BuildPath)
197-
cmdGoModInit.Dir = filepath.Join(wd, build.BuildPath)
198-
cmdGoModInit.Env = append(os.Environ(),
199-
"GO111MODULE=on",
200-
)
201-
cmdGoModInit.Stderr = os.Stderr
202-
cmdGoModInit.Stdout = os.Stdout
203-
err = cmdGoModInit.Run()
204-
if err != nil {
205-
log.Errorf("Go mod init failed: %v\n", err)
206-
os.Exit(1)
207-
}
208-
209-
cmdGoModTidy := exec.Command(goBin, "mod", "tidy")
210-
cmdGoModTidy.Dir = filepath.Join(wd, build.BuildPath)
211-
log.Infof("You can add the '%s' directory to git.", cmdGoModTidy.Dir)
212-
cmdGoModTidy.Env = append(os.Environ(),
213-
"GO111MODULE=on",
214-
)
215-
cmdGoModTidy.Stderr = os.Stderr
216-
cmdGoModTidy.Stdout = os.Stdout
217-
err = cmdGoModTidy.Run()
218-
if err != nil {
219-
log.Errorf("Go mod tidy failed: %v\n", err)
220-
os.Exit(1)
221-
}
222-
}
223-
224-
// findPubcachePath returns the absolute path for the pub-cache or an error.
225-
func findPubcachePath() (string, error) {
226-
var path string
227-
switch runtime.GOOS {
228-
case "darwin", "linux":
229-
home, err := homedir.Dir()
230-
if err != nil {
231-
return "", errors.Wrap(err, "failed to resolve user home dir")
232-
}
233-
path = filepath.Join(home, ".pub-cache")
234-
case "windows":
235-
path = filepath.Join(os.Getenv("APPDATA"), "Pub", "Cache")
236-
}
237-
return path, nil
238-
}
239-
240-
// shouldRunPluginGet checks if the pubspec.yaml file is older than the
241-
// .packages file, if it is the case, prompt the user for a hover plugin get.
242-
func shouldRunPluginGet() (bool, error) {
243-
file1Info, err := os.Stat("pubspec.yaml")
244-
if err != nil {
245-
return false, err
246-
}
247-
248-
file2Info, err := os.Stat(".packages")
249-
if err != nil {
250-
if os.IsNotExist(err) {
251-
return true, nil
252-
}
253-
return false, err
254-
}
255-
modTime1 := file1Info.ModTime()
256-
modTime2 := file2Info.ModTime()
257-
258-
diff := modTime1.Sub(modTime2)
259-
260-
if diff > (time.Duration(0) * time.Second) {
261-
return true, nil
262-
}
263-
return false, nil
264-
}

cmd/packaging.go

+24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
func init() {
1010
initPackagingCmd.AddCommand(initLinuxSnapCmd)
1111
initPackagingCmd.AddCommand(initLinuxDebCmd)
12+
initPackagingCmd.AddCommand(initDarwinBundleCmd)
13+
initPackagingCmd.AddCommand(initDarwinPkgCmd)
1214
rootCmd.AddCommand(initPackagingCmd)
1315
}
1416

@@ -38,3 +40,25 @@ var initLinuxDebCmd = &cobra.Command{
3840
packaging.InitLinuxDeb()
3941
},
4042
}
43+
44+
var initDarwinBundleCmd = &cobra.Command{
45+
Use: "darwin-bundle",
46+
Short: "Create configuration files for OSX bundle packaging",
47+
Run: func(cmd *cobra.Command, args []string) {
48+
assertHoverInitialized()
49+
packaging.DockerInstalled()
50+
51+
packaging.InitDarwinBundle()
52+
},
53+
}
54+
55+
var initDarwinPkgCmd = &cobra.Command{
56+
Use: "darwin-pkg",
57+
Short: "Create configuration files for OSX pkg installer packaging",
58+
Run: func(cmd *cobra.Command, args []string) {
59+
assertHoverInitialized()
60+
packaging.DockerInstalled()
61+
62+
packaging.InitDarwinPkg()
63+
},
64+
}

0 commit comments

Comments
 (0)