-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_test.go
More file actions
54 lines (49 loc) · 1.33 KB
/
build_test.go
File metadata and controls
54 lines (49 loc) · 1.33 KB
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
package examples_test
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
)
// TestExamplesCompile cross-compiles all examples for Android arm64
// to catch compile errors. Requires the Android NDK to be installed.
func TestExamplesCompile(t *testing.T) {
ndkHome := os.Getenv("ANDROID_NDK_HOME")
if ndkHome == "" {
androidHome := os.Getenv("ANDROID_HOME")
if androidHome == "" {
androidHome = filepath.Join(os.Getenv("HOME"), "Android", "Sdk")
}
matches, _ := filepath.Glob(filepath.Join(androidHome, "ndk", "*"))
if len(matches) == 0 {
t.Skip("Android NDK not found; set ANDROID_NDK_HOME or ANDROID_HOME")
}
ndkHome = matches[len(matches)-1]
}
cc := filepath.Join(
ndkHome,
"toolchains", "llvm", "prebuilt", runtime.GOOS+"-x86_64",
"bin", "aarch64-linux-android35-clang",
)
if _, err := os.Stat(cc); err != nil {
t.Skipf("NDK clang not found at %s", cc)
}
_, thisFile, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("unable to determine test file path")
}
projectRoot := filepath.Join(filepath.Dir(thisFile), "..")
cmd := exec.Command("go", "build", "./examples/...")
cmd.Dir = projectRoot
cmd.Env = append(os.Environ(),
"CGO_ENABLED=1",
"GOOS=android",
"GOARCH=arm64",
"CC="+cc,
)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("examples failed to compile:\n%s", out)
}
}