-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathzipalign.go
50 lines (43 loc) · 1.76 KB
/
zipalign.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
package main
import (
"fmt"
"path/filepath"
"strings"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/log"
)
func zipalignBuildArtifact(zipalignConfig *zipalignConfiguration, artifactPath, dstPath string) error {
aligned, err := zipalignConfig.checkAlignment(artifactPath)
if err != nil {
return err
}
if aligned {
if err := command.CopyFile(artifactPath, dstPath); err != nil {
return fmt.Errorf("failed to copy build artifact: %s", err)
}
return nil
}
return zipalignConfig.zipalignArtifact(artifactPath, dstPath)
}
func zipAlignArtifact(zipalignPath, unalignedBuildArtifactPth string, buildArtifactDir string, buildArtifactBasename string, artifactExt string, fullPathExt string, outputName string, pageAlignConfig pageAlignStatus) (string, error) {
log.Infof("Zipalign Build Artifact")
signedArtifactName := fmt.Sprintf("%s-bitrise-%s%s", buildArtifactBasename, fullPathExt, artifactExt)
if artifactName := fmt.Sprintf("%s%s", outputName, artifactExt); outputName != "" {
log.Printf("- Exporting (%s) as: %s", signedArtifactName, artifactName)
signedArtifactName = artifactName
}
fullPath := filepath.Join(buildArtifactDir, signedArtifactName)
isPageAligned := pageAlignConfig == pageAlignYes
// Only care about .so memory page alignment for APKs
if !strings.EqualFold(artifactExt, ".aab") && pageAlignConfig == pageAlignAuto {
extractNativeLibs, err := parseAPKextractNativeLibs(unalignedBuildArtifactPth)
if err != nil {
log.Warnf("Failed to parse APK manifest to read extractNativeLibs attribute: %s", err)
isPageAligned = true
} else {
isPageAligned = !extractNativeLibs
}
}
return fullPath, zipalignBuildArtifact(newZipalignConfiguration(zipalignPath, isPageAligned),
unalignedBuildArtifactPth, fullPath)
}