forked from go-qamel/qamel
/
deps.go
116 lines (98 loc) · 2.63 KB
/
deps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package generator
import (
"bufio"
"bytes"
"fmt"
"os/exec"
fp "path/filepath"
"strings"
"github.com/go-qamel/qamel/internal/config"
)
// CopyDependencies copies dependencies to output directory
func CopyDependencies(profile config.Profile, projectDir, outputPath string) error {
switch profile.OS {
case "linux":
return copyLinuxDependencies(profile, projectDir, outputPath)
case "windows":
return copyWindowsDependencies(profile, projectDir, outputPath)
default:
return nil
}
}
// copyLinuxDependencies copies dependencies for Linux
func copyLinuxDependencies(profile config.Profile, projectDir, outputPath string) error {
// Get qmake variables from `qmake -query`
qmakeVars, err := getQmakeVars(profile.Qmake)
if err != nil {
return err
}
// Get dirs
outputDir := fp.Dir(outputPath)
qtQmlDir := qmakeVars["QT_INSTALL_QML"]
qtLibsDir := qmakeVars["QT_INSTALL_LIBS"]
qtPluginsDir := qmakeVars["QT_INSTALL_PLUGINS"]
// Copy QML
err = copyQmlDependencies(qtQmlDir, profile, projectDir, outputDir)
if err != nil {
return err
}
// Copy plugins
err = copyLinuxPlugins(qtPluginsDir, outputDir)
if err != nil {
return err
}
// Copy libs
err = copyLinuxLibs(qtLibsDir, outputPath)
if err != nil {
return err
}
// Create script
return createLinuxScript(outputPath)
}
// copyWindowsDependencies copies dependencies for Windows
func copyWindowsDependencies(profile config.Profile, projectDir, outputPath string) error {
// Get qmake variables from `qmake -query`
qmakeVars, err := getQmakeVars(profile.Qmake)
if err != nil {
return err
}
// Get dirs
outputDir := fp.Dir(outputPath)
qtQmlDir := qmakeVars["QT_INSTALL_QML"]
qtPluginsDir := qmakeVars["QT_INSTALL_PLUGINS"]
// Copy QML
err = copyQmlDependencies(qtQmlDir, profile, projectDir, outputDir)
if err != nil {
return err
}
// Copy plugins
err = copyWindowsPlugins(qtPluginsDir, outputDir)
if err != nil {
return err
}
// Copy libs
return copyWindowsLibs(profile, outputPath)
}
// getQmakeVars get the qmake properties by running `qmake -query`
func getQmakeVars(qmakePath string) (map[string]string, error) {
// Run qmake
cmdQmake := exec.Command(qmakePath, "-query")
btOutput, err := cmdQmake.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("%v\n%s", err, btOutput)
}
// Parse output
buffer := bytes.NewBuffer(btOutput)
scanner := bufio.NewScanner(buffer)
qmakeVars := map[string]string{}
for scanner.Scan() {
parts := strings.SplitN(scanner.Text(), ":", 2)
if len(parts) != 2 {
continue
}
name := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])
qmakeVars[name] = value
}
return qmakeVars, nil
}