196 строки
3,3 КиБ
Go
196 строки
3,3 КиБ
Go
//go:build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
|
|
// mage:import
|
|
. "magefile/docker"
|
|
|
|
"github.com/magefile/mage/mg"
|
|
)
|
|
|
|
var (
|
|
GolangVolume = "golang.my"
|
|
tests_to_run = []string{}
|
|
)
|
|
|
|
func init() {
|
|
AppName = "ktgo"
|
|
ImageName = "my/go"
|
|
}
|
|
|
|
func Test() {
|
|
mg.Deps(TestLibs)
|
|
}
|
|
func TestLibs(ctx context.Context) error {
|
|
paths := []string{
|
|
"pkg",
|
|
}
|
|
|
|
listTests(paths)
|
|
|
|
// err := addTest("test")
|
|
// if err != nil {
|
|
// println("ERROR: " + "test")
|
|
// return err
|
|
// }
|
|
|
|
return runListedTests()
|
|
}
|
|
|
|
func listTests(paths []string) error {
|
|
for _, p := range paths {
|
|
listAndTest(p)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func listAndTest(p string) error {
|
|
entries, err := os.ReadDir(p)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return testList(p, entries)
|
|
}
|
|
|
|
func testList(p string, entries []os.DirEntry) error {
|
|
for _, e := range entries {
|
|
testOne(p, e)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testOne(p string, e os.DirEntry) error {
|
|
if !e.IsDir() {
|
|
return nil
|
|
}
|
|
if e.Name() == "lib" {
|
|
return nil
|
|
}
|
|
if e.Name() == "testlib" {
|
|
return nil
|
|
}
|
|
|
|
entries, err := os.ReadDir(p + "/" + e.Name())
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
found := false
|
|
for _, e2 := range entries {
|
|
if e2.IsDir() {
|
|
continue
|
|
}
|
|
|
|
if strings.Contains(e2.Name(), "_test.go") {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
testPath := p + "/" + e.Name()
|
|
err = addTest(testPath)
|
|
if err != nil {
|
|
println("ERROR: " + testPath)
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func addTest(p string) error {
|
|
tests_to_run = append(tests_to_run, "./"+p)
|
|
return nil
|
|
}
|
|
|
|
func runListedTests() error {
|
|
test_paths := strings.Join(tests_to_run, " ")
|
|
return runTests(test_paths)
|
|
}
|
|
|
|
func runTests(paths string) error {
|
|
return Bash(`sudo docker run -ti --rm \
|
|
-h host \
|
|
--net=none \
|
|
-v /etc/localtime:/etc/localtime:ro \
|
|
-v ` + GolangVolume + `:/usr/local/go:ro \
|
|
\
|
|
-v /gopath:/gopath:rw \
|
|
-v ${PWD}:/app \
|
|
\
|
|
-e GOPATH=/gopath \
|
|
-e GOCACHE=/gopath/gocache \
|
|
-e APPDIR=${PWD} \
|
|
\
|
|
-w /app \
|
|
-u 0 \
|
|
\
|
|
--entrypoint=/bin/bash \
|
|
\
|
|
` + ImageName + " -c '" + ` \
|
|
for t in ` + paths + `; do \
|
|
go test -v -p 1 -gcflags=-l -count=1 $t || exit 1; \
|
|
done'`)
|
|
}
|
|
|
|
func Mobile() {
|
|
Build_Mobile()
|
|
Upload_Mobile()
|
|
}
|
|
func Build_Mobile() {
|
|
Bash(`sudo docker run -ti --rm \
|
|
-h host \
|
|
--net=bridge \
|
|
-v /etc/localtime:/etc/localtime:ro \
|
|
\
|
|
-v ` + GolangVolume + `:/usr/local/go:ro \
|
|
-v /gopath:/gopath:rw \
|
|
-v ${PWD}:/app \
|
|
\
|
|
-v /etc/java-17-openjdk:/etc/java-17-openjdk:ro \
|
|
-v /usr/lib/jvm/java-17-openjdk-amd64:/usr/lib/jvm/java-17-openjdk-amd64:ro \
|
|
\
|
|
-e PATH=$PATH:/usr/local/go/bin:/usr/lib/jvm/java-17-openjdk-amd64/bin \
|
|
-e GOPATH=/gopath \
|
|
-e GOCACHE=/gopath/gocache \
|
|
-e HOME=/home/user \
|
|
\
|
|
-w /app/pkg/mlib/ktgo \
|
|
-u 1000 \
|
|
\
|
|
-v android_sdk:/sdk:ro \
|
|
-e ANDROID_HOME=/sdk \
|
|
\
|
|
--entrypoint=/gopath/bin/gomobile \
|
|
\
|
|
` + ImageName + " " + `\
|
|
bind -o /app/lib/ktgo.aar \
|
|
`)
|
|
Bash(`cp -afv lib/ktgo.aar /Telegram-FOSS/TMessagesProj/libs`)
|
|
}
|
|
|
|
func Upload_Mobile() {
|
|
Bash(`unzip lib/ktgo.aar jni/arm64-v8a/libgojni.so \
|
|
&& adb push jni/arm64-v8a/libgojni.so /sdcard/scripts/ \
|
|
; rm jni/arm64-v8a/libgojni.so; rmdir jni/arm64-v8a jni \
|
|
`)
|
|
fmt.Printf(`
|
|
|
|
su -c 'mv -fv /sdcard/scripts/libgojni.so /data/app/*/org.telegram.messenger-*/lib/arm64'
|
|
|
|
`)
|
|
Bash(`adb shell \
|
|
`)
|
|
}
|