Skip to content

Commit

Permalink
fix(dmg): cannot build DMG on macOS 10.15
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 19, 2019
1 parent 2a1fcdd commit 94cc4c7
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app-builder-bin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app-builder-bin",
"description": "app-builder precompiled binaries",
"version": "3.4.0",
"version": "3.4.1",
"files": [
"*.js",
"mac",
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/develar/app-builder
require (
github.com/aclements/go-rabin v0.0.0-20170911142644-d0b643ea1a4c
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
github.com/alessio/shellescape v0.0.0-20190409004728-b115ca0f9053 // indirect
github.com/aws/aws-sdk-go v1.20.20
github.com/aws/aws-sdk-go v1.21.0
github.com/biessek/golang-ico v0.0.0-20180326222316-d348d9ea4670
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ github.com/aclements/go-rabin v0.0.0-20170911142644-d0b643ea1a4c h1:YOZwrMKo75ZY
github.com/aclements/go-rabin v0.0.0-20170911142644-d0b643ea1a4c/go.mod h1:x5RmfBtNWHpxyhZledMnt/vFb6z5y+fadAiinzuLYpo=
github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI=
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alessio/shellescape v0.0.0-20190409004728-b115ca0f9053 h1:H/GMMKYPkEIC3DF/JWQz8Pdd+Feifov2EIgGfNpeogI=
github.com/alessio/shellescape v0.0.0-20190409004728-b115ca0f9053/go.mod h1:xW8sBma2LE3QxFSzCnH9qe6gAE2yO9GvQaWwX89HxbE=
github.com/aws/aws-sdk-go v1.20.20 h1:OAR/GtjMOhenkp1NNKr1N1FgIP3mQXHeGbRhvVIAQp0=
github.com/aws/aws-sdk-go v1.20.20/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.21.0 h1:dRGzi4XZe5GFSJssHkRNUf/hRD/HL8bdqTYa9hpAO8c=
github.com/aws/aws-sdk-go v1.21.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/biessek/golang-ico v0.0.0-20180326222316-d348d9ea4670 h1:FQPKKjDhzG0T4ew6dm6MGrXb4PRAi8ZmTuYuxcF62BM=
github.com/biessek/golang-ico v0.0.0-20180326222316-d348d9ea4670/go.mod h1:iRWAFbKXMMkVQyxZ1PfGlkBr1TjATx1zy2MRprV7A3Q=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
return
}

var app = kingpin.New("app-builder", "app-builder").Version("3.4.0")
var app = kingpin.New("app-builder", "app-builder").Version("3.4.1")

node_modules.ConfigureCommand(app)
node_modules.ConfigureRebuildCommand(app)
Expand Down
2 changes: 1 addition & 1 deletion pkg/node-modules/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ConfigureCommand(app *kingpin.Application) {
return err
}

jsonWriter := jsoniter.NewStream(jsoniter.ConfigDefault, os.Stdout, 32*1024)
jsonWriter := jsoniter.NewStream(jsoniter.ConfigFastest, os.Stdout, 32*1024)
writeResult(jsonWriter, collector)
err = jsonWriter.Flush()
if err != nil {
Expand Down
87 changes: 77 additions & 10 deletions pkg/package-format/dmg/dmg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
package dmg

import (
"bytes"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/alecthomas/kingpin"
"github.com/develar/app-builder/pkg/fs"
"github.com/develar/app-builder/pkg/log"
"github.com/develar/app-builder/pkg/util"
"github.com/develar/errors"
"github.com/json-iterator/go"
"github.com/pkg/xattr"
"go.uber.org/zap"
)
Expand All @@ -26,47 +29,111 @@ func ConfigureCommand(app *kingpin.Application) {
background := command.Flag("background", "").String()

command.Action(func(context *kingpin.ParseContext) error {
err := BuildDmg(*volumePath, *icon, *background)
backgroundFileInImage, err := BuildDmg(*volumePath, *icon, *background)
if err != nil {
return errors.WithStack(err)
return err
}

jsonWriter := jsoniter.NewStream(jsoniter.ConfigFastest, os.Stdout, 32*1024)
jsonWriter.WriteObjectStart()

if *background != "" {
pixelWidth, pixelHeight, err := getImageSizeUsingSips(*background)
if err != nil {
return err
}

jsonWriter.WriteObjectField("backgroundWidth")
jsonWriter.WriteInt(pixelWidth)
jsonWriter.WriteMore()
jsonWriter.WriteObjectField("backgroundHeight")
jsonWriter.WriteInt(pixelHeight)

jsonWriter.WriteMore()
jsonWriter.WriteObjectField("backgroundFile")
jsonWriter.WriteString(backgroundFileInImage)
}

jsonWriter.WriteObjectEnd()
err = jsonWriter.Flush()
if err != nil {
return err
}

return nil
})
}

func BuildDmg(volumePath string, icon string, backgroundPath string) error {
func getImageSizeUsingSips(background string) (int, int, error) {
command := exec.Command("sips", "-g", "pixelHeight", "-g", "pixelWidth", background)
result, err := util.Execute(command)
if err != nil {
return 0, 0, err
}

pixelWidth := 0
pixelHeight := 0
re := regexp.MustCompile(`([a-zA-Z]+):\s*(\d+)`)
lines := bytes.Split(result, []byte("\n"))
for _, value := range lines {
if len(value) == 0 {
continue
}

nameAndValue := re.FindStringSubmatch(string(value))
if nameAndValue == nil {
continue
}

size, err := strconv.Atoi(nameAndValue[2])
if err != nil {
return 0, 0, errors.WithStack(err)
}

switch nameAndValue[1] {
case "pixelWidth":
pixelWidth = size
case "pixelHeight":
pixelHeight = size
}
}
return pixelWidth, pixelHeight, nil
}

func BuildDmg(volumePath string, icon string, backgroundPath string) (string, error) {
if icon != "" {
// cannot use hard link because volume uses different disk
iconPath := filepath.Join(volumePath, ".VolumeIcon.icns")
err := fs.CopyDirOrFile(icon, iconPath)
if err != nil {
return errors.WithStack(err)
return "", errors.WithStack(err)
}

err = setHasCustomIconAttribute(volumePath)
if err != nil {
return errors.WithStack(err)
return "", errors.WithStack(err)
}

err = setIsInvisibleAttribute(iconPath)
if err != nil {
return errors.WithStack(err)
return "", errors.WithStack(err)
}
}

backgroundFileInImage := ""
if backgroundPath != "" {
backgroundPath, err := GetEffectiveBackgroundPath(backgroundPath)
if err != nil {
return errors.WithStack(err)
return "", err
}

err = fs.CopyDirOrFile(backgroundPath, filepath.Join(volumePath, ".background", filepath.Base(backgroundPath)))
backgroundFileInImage = filepath.Join(volumePath, ".background", filepath.Base(backgroundPath))
err = fs.CopyDirOrFile(backgroundPath, backgroundFileInImage)
if err != nil {
return errors.WithStack(err)
return "", errors.WithStack(err)
}
}
return nil
return backgroundFileInImage, nil
}

func GetEffectiveBackgroundPath(path string) (string, error) {
Expand Down
19 changes: 19 additions & 0 deletions pkg/package-format/dmg/dmg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dmg

import (
"testing"

"github.com/develar/app-builder/pkg/log"
. "github.com/onsi/gomega"
)

func TestSize(t *testing.T) {
g := NewGomegaWithT(t)

log.InitLogger()

w, h, err := getImageSizeUsingSips("/Volumes/data/Desktop/test.png")
g.Expect(err).To(BeNil())
g.Expect(w).To(Equal(1316))
g.Expect(h).To(Equal(894))
}

0 comments on commit 94cc4c7

Please sign in to comment.