Skip to content

Commit b9d881b

Browse files
authored
Merge pull request #109 from jld3103/feature/automatic-tool-detection
Add automatic tool detection
2 parents 1452293 + aa51a74 commit b9d881b

14 files changed

+421
-129
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ RUN git clone --single-branch --depth=1 --branch 0.2 https://github.com/hogliux/
3333
FROM ubuntu:bionic as appimagebuilder
3434
RUN apt-get update \
3535
&& apt-get install -y \
36-
curl
36+
wget
3737
RUN cd /opt \
38-
&& curl -LO https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage \
38+
&& wget -c https://github.com/$(wget -q https://github.com/probonopd/go-appimage/releases -O - | grep "appimagetool-.*-x86_64.AppImage" | head -n 1 | cut -d '"' -f 2) \
39+
&& mv appimagetool-*-x86_64.AppImage appimagetool-x86_64.AppImage \
3940
&& chmod a+x appimagetool-x86_64.AppImage \
4041
&& sed 's|AI\x02|\x00\x00\x00|g' -i appimagetool-x86_64.AppImage \
4142
&& ./appimagetool-x86_64.AppImage --appimage-extract \

cmd/build.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ var buildWindowsMsiCmd = &cobra.Command{
181181
func subcommandBuild(targetOS string, packagingTask packaging.Task) {
182182
assertHoverInitialized()
183183
packagingTask.AssertInitialized()
184+
if !buildDocker {
185+
packagingTask.AssertSupported()
186+
}
184187

185188
if !buildSkipFlutterBuildBundle {
186189
cleanBuildOutputsDir(targetOS)

cmd/packaging/darwin-bundle.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
package packaging
22

3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"path/filepath"
8+
)
9+
310
// DarwinBundleTask packaging for darwin as bundle
411
var DarwinBundleTask = &packagingTask{
512
packagingFormatName: "darwin-bundle",
613
templateFiles: map[string]string{
714
"darwin-bundle/Info.plist.tmpl": "{{.applicationName}} {{.version}}.app/Contents/Info.plist.tmpl",
815
},
9-
executableFiles: []string{},
10-
buildOutputDirectory: "{{.applicationName}} {{.version}}.app/Contents/MacOS",
11-
packagingScriptTemplate: "mkdir -p \"{{.applicationName}} {{.version}}.app/Contents/Resources\" && png2icns \"{{.applicationName}} {{.version}}.app/Contents/Resources/icon.icns\" \"{{.applicationName}} {{.version}}.app/Contents/MacOS/assets/icon.png\"",
12-
outputFileExtension: "app",
13-
outputFileContainsVersion: true,
14-
outputFileUsesApplicationName: true,
16+
executableFiles: []string{},
17+
flutterBuildOutputDirectory: "{{.applicationName}} {{.version}}.app/Contents/MacOS",
18+
packagingFunction: func(tmpPath, applicationName, strippedApplicationName, packageName, executableName, version, release string) (string, error) {
19+
outputFileName := fmt.Sprintf("%s %s.app", applicationName, version)
20+
err := os.MkdirAll(filepath.Join(tmpPath, outputFileName, "Contents", "Resources"), 0755)
21+
if err != nil {
22+
return "", err
23+
}
24+
cmdPng2icns := exec.Command("png2icns", filepath.Join(outputFileName, "Contents", "Resources", "icon.icns"), filepath.Join(outputFileName, "Contents", "MacOS", "assets", "icon.png"))
25+
cmdPng2icns.Dir = tmpPath
26+
cmdPng2icns.Stdout = os.Stdout
27+
cmdPng2icns.Stderr = os.Stderr
28+
err = cmdPng2icns.Run()
29+
if err != nil {
30+
return "", err
31+
}
32+
return outputFileName, nil
33+
},
34+
requiredTools: map[string][]string{
35+
"linux": {"png2icns"},
36+
},
1537
}

cmd/packaging/darwin-dmg.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
package packaging
22

3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
)
8+
39
// DarwinDmgTask packaging for darwin as dmg
410
var DarwinDmgTask = &packagingTask{
511
packagingFormatName: "darwin-dmg",
612
dependsOn: map[*packagingTask]string{
713
DarwinBundleTask: "dmgdir",
814
},
9-
packagingScriptTemplate: "ln -sf /Applications dmgdir/Applications && genisoimage -V {{.packageName}} -D -R -apple -no-pad -o \"{{.applicationName}} {{.version}}.dmg\" dmgdir",
10-
outputFileExtension: "dmg",
11-
outputFileContainsVersion: true,
12-
outputFileUsesApplicationName: true,
13-
skipAssertInitialized: true,
15+
packagingFunction: func(tmpPath, applicationName, strippedApplicationName, packageName, executableName, version, release string) (string, error) {
16+
outputFileName := fmt.Sprintf("%s %s.dmg", applicationName, version)
17+
cmdLn := exec.Command("ln", "-sf", "/Applications", "dmgdir/Applications")
18+
cmdLn.Dir = tmpPath
19+
cmdLn.Stdout = os.Stdout
20+
cmdLn.Stderr = os.Stderr
21+
err := cmdLn.Run()
22+
if err != nil {
23+
return "", err
24+
}
25+
cmdGenisoimage := exec.Command("genisoimage", "-V", packageName, "-D", "-R", "-apple", "-no-pad", "-o", outputFileName, "dmgdir")
26+
cmdGenisoimage.Dir = tmpPath
27+
cmdGenisoimage.Stdout = os.Stdout
28+
cmdGenisoimage.Stderr = os.Stderr
29+
err = cmdGenisoimage.Run()
30+
if err != nil {
31+
return "", err
32+
}
33+
return outputFileName, nil
34+
},
35+
skipAssertInitialized: true,
36+
requiredTools: map[string][]string{
37+
"linux": {"ln", "genisoimage"},
38+
},
1439
}

cmd/packaging/darwin-pkg.go

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package packaging
22

3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"path/filepath"
8+
)
9+
310
// DarwinPkgTask packaging for darwin as pkg
411
var DarwinPkgTask = &packagingTask{
512
packagingFormatName: "darwin-pkg",
@@ -10,8 +17,85 @@ var DarwinPkgTask = &packagingTask{
1017
"darwin-pkg/PackageInfo.tmpl": "flat/base.pkg/PackageInfo.tmpl",
1118
"darwin-pkg/Distribution.tmpl": "flat/Distribution.tmpl",
1219
},
13-
packagingScriptTemplate: "(cd flat/root && find . | cpio -o --format odc --owner 0:80 | gzip -c ) > flat/base.pkg/Payload && mkbom -u 0 -g 80 flat/root flat/base.pkg/Bom && (cd flat && xar --compression none -cf \"../{{.applicationName}} {{.version}}.pkg\" * )",
14-
outputFileExtension: "pkg",
15-
outputFileContainsVersion: true,
16-
outputFileUsesApplicationName: true,
20+
packagingFunction: func(tmpPath, applicationName, strippedApplicationName, packageName, executableName, version, release string) (string, error) {
21+
outputFileName := fmt.Sprintf("%s %s.pkg", applicationName, version)
22+
23+
payload, err := os.OpenFile(filepath.Join("flat", "base.pkg", "Payload"), os.O_RDWR|os.O_CREATE, 0755)
24+
if err != nil {
25+
return "", nil
26+
}
27+
28+
cmdFind := exec.Command("find", ".")
29+
cmdFind.Dir = filepath.Join(tmpPath, "flat", "root")
30+
cmdCpio := exec.Command("cpio", "-o", "--format", "odc", "--owner", "0:80")
31+
cmdCpio.Dir = filepath.Join(tmpPath, "flat", "root")
32+
cmdGzip := exec.Command("gzip", "-c")
33+
34+
// Pipes like this: find | cpio | gzip > Payload
35+
cmdCpio.Stdin, err = cmdFind.StderrPipe()
36+
if err != nil {
37+
return "", nil
38+
}
39+
cmdGzip.Stdin, err = cmdCpio.StderrPipe()
40+
if err != nil {
41+
return "", nil
42+
}
43+
cmdGzip.Stdout = payload
44+
45+
err = cmdGzip.Start()
46+
if err != nil {
47+
return "", nil
48+
}
49+
err = cmdCpio.Start()
50+
if err != nil {
51+
return "", nil
52+
}
53+
err = cmdFind.Run()
54+
if err != nil {
55+
return "", nil
56+
}
57+
err = cmdCpio.Wait()
58+
if err != nil {
59+
return "", nil
60+
}
61+
err = cmdGzip.Wait()
62+
if err != nil {
63+
return "", nil
64+
}
65+
err = payload.Close()
66+
if err != nil {
67+
return "", nil
68+
}
69+
70+
cmdMkbom := exec.Command("mkbom", "-u", "0", "-g", "80", filepath.Join("flat", "root"), filepath.Join("flat", "base.pkg", "Payload"))
71+
cmdMkbom.Dir = tmpPath
72+
cmdMkbom.Stdout = os.Stdout
73+
cmdMkbom.Stderr = os.Stderr
74+
err = cmdMkbom.Run()
75+
if err != nil {
76+
return "", nil
77+
}
78+
79+
var files []string
80+
err = filepath.Walk(tmpPath, func(path string, info os.FileInfo, err error) error {
81+
files = append(files, path)
82+
return nil
83+
})
84+
if err != nil {
85+
return "", nil
86+
}
87+
88+
cmdXar := exec.Command("xar", append([]string{"--compression", "none", "-cf", filepath.Join("..", outputFileName)}, files...)...)
89+
cmdXar.Dir = filepath.Join(tmpPath, "flat")
90+
cmdXar.Stdout = os.Stdout
91+
cmdXar.Stderr = os.Stderr
92+
err = cmdXar.Run()
93+
if err != nil {
94+
return "", nil
95+
}
96+
return outputFileName, nil
97+
},
98+
requiredTools: map[string][]string{
99+
"linux": {"find", "cpio", "gzip", "mkbom", "xar"},
100+
},
17101
}

cmd/packaging/linux-appimage.go

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,66 @@
11
package packaging
22

3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"path/filepath"
8+
9+
copy "github.com/otiai10/copy"
10+
11+
"github.com/go-flutter-desktop/hover/internal/log"
12+
)
13+
314
// LinuxAppImageTask packaging for linux as AppImage
415
var LinuxAppImageTask = &packagingTask{
516
packagingFormatName: "linux-appimage",
617
templateFiles: map[string]string{
718
"linux-appimage/AppRun.tmpl": "AppRun.tmpl",
8-
"linux/app.desktop.tmpl": "{{.executableName}}.desktop.tmpl",
19+
"linux/app.desktop.tmpl": "{{.strippedApplicationName}}.desktop.tmpl",
920
},
1021
executableFiles: []string{
22+
".",
1123
"AppRun",
12-
"{{.executableName}}.desktop",
24+
"{{.strippedApplicationName}}.desktop",
25+
},
26+
linuxDesktopFileIconPath: "{{.strippedApplicationName}}",
27+
flutterBuildOutputDirectory: "build",
28+
packagingFunction: func(tmpPath, applicationName, strippedApplicationName, packageName, executableName, version, release string) (string, error) {
29+
sourceIconPath := filepath.Join(tmpPath, "build", "assets", "icon.png")
30+
iconDir := filepath.Join(tmpPath, "usr", "share", "icons", "hicolor", "256x256", "apps")
31+
if _, err := os.Stat(iconDir); os.IsNotExist(err) {
32+
err = os.MkdirAll(iconDir, 0755)
33+
if err != nil {
34+
log.Errorf("Failed to create icon dir: %v", err)
35+
os.Exit(1)
36+
}
37+
}
38+
err := copy.Copy(sourceIconPath, filepath.Join(tmpPath, fmt.Sprintf("%s.png", strippedApplicationName)))
39+
if err != nil {
40+
log.Errorf("Failed to copy icon root dir: %v", err)
41+
os.Exit(1)
42+
}
43+
err = copy.Copy(sourceIconPath, filepath.Join(iconDir, fmt.Sprintf("%s.png", strippedApplicationName)))
44+
if err != nil {
45+
log.Errorf("Failed to copy icon dir: %v", err)
46+
os.Exit(1)
47+
}
48+
cmdAppImageTool := exec.Command("appimagetool", ".")
49+
cmdAppImageTool.Dir = tmpPath
50+
cmdAppImageTool.Stdout = os.Stdout
51+
cmdAppImageTool.Stderr = os.Stderr
52+
cmdAppImageTool.Env = append(
53+
os.Environ(),
54+
"ARCH=x86_64",
55+
fmt.Sprintf("VERSION=%s", version),
56+
)
57+
err = cmdAppImageTool.Run()
58+
if err != nil {
59+
return "", err
60+
}
61+
return fmt.Sprintf("%s-%s-x86_64.AppImage", strippedApplicationName, version), nil
62+
},
63+
requiredTools: map[string][]string{
64+
"linux": {"appimagetool"},
1365
},
14-
linuxDesktopFileIconPath: "/build/assets/icon",
15-
buildOutputDirectory: "build",
16-
packagingScriptTemplate: "appimagetool . && mv -n {{.executableName}}-x86_64.AppImage {{.packageName}}-{{.version}}.AppImage",
17-
outputFileExtension: "AppImage",
18-
outputFileContainsVersion: true,
19-
outputFileUsesApplicationName: false,
2066
}

cmd/packaging/linux-deb.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package packaging
22

3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
)
8+
39
// LinuxDebTask packaging for linux as deb
410
var LinuxDebTask = &packagingTask{
511
packagingFormatName: "linux-deb",
@@ -14,9 +20,20 @@ var LinuxDebTask = &packagingTask{
1420
},
1521
linuxDesktopFileExecutablePath: "/usr/lib/{{.packageName}}/{{.executableName}}",
1622
linuxDesktopFileIconPath: "/usr/lib/{{.packageName}}/assets/icon.png",
17-
buildOutputDirectory: "usr/lib/{{.packageName}}",
18-
packagingScriptTemplate: "dpkg-deb --build . {{.packageName}}-{{.version}}.deb",
19-
outputFileExtension: "deb",
20-
outputFileContainsVersion: true,
21-
outputFileUsesApplicationName: false,
23+
flutterBuildOutputDirectory: "usr/lib/{{.packageName}}",
24+
packagingFunction: func(tmpPath, applicationName, strippedApplicationName, packageName, executableName, version, release string) (string, error) {
25+
outputFileName := fmt.Sprintf("%s_%s_amd64.deb", packageName, version)
26+
cmdDpkgDeb := exec.Command("dpkg-deb", "--build", ".", outputFileName)
27+
cmdDpkgDeb.Dir = tmpPath
28+
cmdDpkgDeb.Stdout = os.Stdout
29+
cmdDpkgDeb.Stderr = os.Stderr
30+
err := cmdDpkgDeb.Run()
31+
if err != nil {
32+
return "", err
33+
}
34+
return outputFileName, nil
35+
},
36+
requiredTools: map[string][]string{
37+
"linux": {"dpkg-deb"},
38+
},
2239
}

cmd/packaging/linux-pkg.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package packaging
22

3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
)
8+
39
// LinuxPkgTask packaging for linux as pacman pkg
410
var LinuxPkgTask = &packagingTask{
511
packagingFormatName: "linux-pkg",
@@ -14,9 +20,19 @@ var LinuxPkgTask = &packagingTask{
1420
},
1521
linuxDesktopFileExecutablePath: "/usr/lib/{{.packageName}}/{{.executableName}}",
1622
linuxDesktopFileIconPath: "/usr/lib/{{.packageName}}/assets/icon.png",
17-
buildOutputDirectory: "src/usr/lib/{{.packageName}}",
18-
packagingScriptTemplate: "makepkg && mv -n {{.packageName}}-{{.version}}-{{.release}}-x86_64.pkg.tar.xz {{.packageName}}-{{.version}}.pkg.tar.xz",
19-
outputFileExtension: "pkg.tar.xz",
20-
outputFileContainsVersion: true,
21-
outputFileUsesApplicationName: false,
23+
flutterBuildOutputDirectory: "src/usr/lib/{{.packageName}}",
24+
packagingFunction: func(tmpPath, applicationName, strippedApplicationName, packageName, executableName, version, release string) (string, error) {
25+
cmdMakepkg := exec.Command("makepkg")
26+
cmdMakepkg.Dir = tmpPath
27+
cmdMakepkg.Stdout = os.Stdout
28+
cmdMakepkg.Stderr = os.Stderr
29+
err := cmdMakepkg.Run()
30+
if err != nil {
31+
return "", err
32+
}
33+
return fmt.Sprintf("%s-%s-%s-x86_64.pkg.tar.xz", packageName, version, release), nil
34+
},
35+
requiredTools: map[string][]string{
36+
"linux": {"makepkg"},
37+
},
2238
}

0 commit comments

Comments
 (0)