Tue, 16 Dec 2025 20:12:54 +0100
download result from buildenv and parse result.json
| build.template | file | annotate | diff | comparison | revisions | |
| src/main.go | file | annotate | diff | comparison | revisions | |
| testconfig.xml | file | annotate | diff | comparison | revisions |
--- a/build.template Mon Dec 15 19:18:04 2025 +0100 +++ b/build.template Tue Dec 16 20:12:54 2025 +0100 @@ -55,7 +55,7 @@ compile_log=compile.log check_log=check.log -result_file=`pwd`/result.json +result_file="$result_dir/result.json" echo "[" > $result_file @@ -110,6 +110,9 @@ # write result echo "write result to $result_file" echo "{ \"build\":\"{{$i}}\", " >> $result_file + {{- if $build.Name}} + echo " \"name\":\"{{$build.Name}}\"," >> $result_file + {{- end}} if [ -n "$configure" ]; then echo " \"configure\":\"$configure\"," >> $result_file fi
--- a/src/main.go Mon Dec 15 19:18:04 2025 +0100 +++ b/src/main.go Tue Dec 16 20:12:54 2025 +0100 @@ -2,8 +2,8 @@ import ( "bytes" + "encoding/json" "encoding/xml" - "errors" "fmt" "log" "os" @@ -31,6 +31,7 @@ Path string `xml:"path"` BuildEnvs string `xml:"buildenvs"` Build []struct { + Name string `xml:"name,attr"` IsPlatform string `xml:"isplatform,attr"` NotPlatform string `xml:"not,attr"` NotList []string @@ -45,6 +46,18 @@ } `xml:"build"` } +type Result struct { + Build string `json:"build"` + Name string `json:"name"` + Configure string `json:"configure"` + Compile string `json:"compile"` + Check string `json:"check"` +} + +type Results struct { + Results []Result +} + func main() { data, err := os.ReadFile("testconfig.xml") if err != nil { @@ -98,9 +111,7 @@ log.Fatal(err) } - if err = exec_buildenvs(config, &repo, tmp); err != nil { - log.Fatal(err) - } + exec_buildenvs(config, &repo, tmp) } } @@ -121,6 +132,10 @@ log.Print("remove build.tar.gz failed") return err } + if err := os.RemoveAll(path.Join(tmp_dir, "result")); err != nil { + log.Print("remove result failed") + return err + } err := os.Mkdir(buildPath, 0755) if err != nil { @@ -200,20 +215,22 @@ return true } -func exec_buildenvs(config *Config, repo *Repository, tmp_dir string) error { +func exec_buildenvs(config *Config, repo *Repository, tmp_dir string) int { if len(repo.BuildEnvs) == 0 { log.Print("repo %s has no buildenvs", repo.Path) - return nil + return 0 } + success := 0 buildenvs := strings.Split(repo.BuildEnvs, ",") for _, buildenv := range buildenvs { env, ok := config.BuildEnvMap[buildenv] if !ok { - return errors.New("unknown build env: " + buildenv) + log.Print("unknown build env ", buildenv) + continue } if !host_is_available(env.Host) { log.Print("skip unavailable host ", env.Host) - return nil + continue } // steps: @@ -242,8 +259,36 @@ if err != nil { log.Print("cannot execute build.sh on buildenv host ", env.Host) log.Print("stderr: ", errb.String()) + continue } + + // download result + cmd.Stdout = nil + cmd.Stderr = nil + cmd = exec.Command("scp", "-r", env.Host+":"+build_dir+"/result", tmp_dir) + log.Print("scp: ", cmd.Args) + if err := cmd.Run(); err != nil { + log.Print("cannot get result from buildenv") + continue + } + + // parse result + resultData, err := os.ReadFile(path.Join(tmp_dir, "result/result.json")) + if err != nil { + log.Print("cannot read result from buildenv") + continue + } + + var results []Result + if err := json.Unmarshal(resultData, &results); err != nil { + log.Print("cannot parse result.json") + continue + } + + log.Print(results) + + success++ } - return nil + return success }
--- a/testconfig.xml Mon Dec 15 19:18:04 2025 +0100 +++ b/testconfig.xml Tue Dec 16 20:12:54 2025 +0100 @@ -7,7 +7,7 @@ <repository> <path>../ucx</path> <buildenvs>x1</buildenvs> - <build isplatform="unix"> + <build name="test123" isplatform="unix"> <test>true</test> <test>which make</test> <var name="CFLAGS">-m64</var>