-
Notifications
You must be signed in to change notification settings - Fork 22
/
zipalign_command.go
51 lines (43 loc) · 1.31 KB
/
zipalign_command.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
package main
import (
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/errorutil"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-steplib/steps-sign-apk/keystore"
)
type zipalignConfiguration struct {
zipalignPath string
pageAlign bool
}
func newZipalignConfiguration(zipalignPath string, pageAlign bool) *zipalignConfiguration {
return &zipalignConfiguration{
zipalignPath: zipalignPath,
pageAlign: pageAlign,
}
}
func (config *zipalignConfiguration) checkAlignment(artifactPath string) (bool, error) {
checkCmdSlice := []string{config.zipalignPath}
if config.pageAlign {
checkCmdSlice = append(checkCmdSlice, "-p")
}
checkCmdSlice = append(checkCmdSlice, "-c", "4", artifactPath)
err := keystore.Execute(checkCmdSlice)
if err != nil {
if errorutil.IsExitStatusError(err) {
return false, nil
}
return false, err
}
log.Printf("Artifact alignment confirmed.")
return true, nil
}
func (config *zipalignConfiguration) zipalignArtifact(artifactPath, dstPath string) error {
cmdSlice := []string{config.zipalignPath}
if config.pageAlign {
cmdSlice = append(cmdSlice, "-p")
}
cmdSlice = append(cmdSlice, "-f", "4", artifactPath, dstPath)
log.Printf("=> %s", command.PrintableCommandArgs(false, cmdSlice))
_, err := keystore.ExecuteForOutput(cmdSlice)
return err
}