| 25 Name string `xml:"name,attr"` |
26 Name string `xml:"name,attr"` |
| 26 Host string `xml:"host"` |
27 Host string `xml:"host"` |
| 27 User string `xml:"user"` |
28 User string `xml:"user"` |
| 28 } |
29 } |
| 29 |
30 |
| |
31 type Build struct { |
| |
32 Name string `xml:"name,attr"` |
| |
33 IsPlatform string `xml:"isplatform,attr"` |
| |
34 NotPlatform string `xml:"not,attr"` |
| |
35 NotList []string |
| |
36 Test []string `xml:"test"` |
| |
37 Var []struct { |
| |
38 Name string `xml:"name,attr"` |
| |
39 Value string `xml:",chardata"` |
| |
40 } |
| |
41 Configure string `xml:"configure"` |
| |
42 Compile string `xml:"compile"` |
| |
43 Check string `xml:"check"` |
| |
44 } |
| |
45 |
| 30 type Repository struct { |
46 type Repository struct { |
| 31 Path string `xml:"path"` |
47 Path string `xml:"path"` |
| 32 BuildEnvs string `xml:"buildenvs"` |
48 BuildEnvs string `xml:"buildenvs"` |
| 33 Build []struct { |
49 Build []Build `xml:"build"` |
| 34 Name string `xml:"name,attr"` |
|
| 35 IsPlatform string `xml:"isplatform,attr"` |
|
| 36 NotPlatform string `xml:"not,attr"` |
|
| 37 NotList []string |
|
| 38 Test []string `xml:"test"` |
|
| 39 Var []struct { |
|
| 40 Name string `xml:"name,attr"` |
|
| 41 Value string `xml:",chardata"` |
|
| 42 } |
|
| 43 Configure string `xml:"configure"` |
|
| 44 Compile string `xml:"compile"` |
|
| 45 Check string `xml:"check"` |
|
| 46 } `xml:"build"` |
|
| 47 } |
50 } |
| 48 |
51 |
| 49 type Result struct { |
52 type Result struct { |
| 50 Build string `json:"build"` |
53 Build *Build |
| |
54 Id string `json:"build"` |
| 51 Name string `json:"name"` |
55 Name string `json:"name"` |
| 52 Configure string `json:"configure"` |
56 Configure string `json:"configure"` |
| 53 Compile string `json:"compile"` |
57 Compile string `json:"compile"` |
| 54 Check string `json:"check"` |
58 Check string `json:"check"` |
| 55 } |
59 } |
| 56 |
60 |
| 57 type Results struct { |
61 type BuildEnvResult struct { |
| |
62 Env *BuildEnv |
| 58 Results []Result |
63 Results []Result |
| |
64 } |
| |
65 |
| |
66 type Commit struct { |
| |
67 Rev string |
| |
68 NodeShort string |
| |
69 Node string |
| |
70 Desc string |
| |
71 Author string |
| |
72 Date string |
| |
73 } |
| |
74 |
| |
75 type CommitResult struct { |
| |
76 Commit *Commit |
| |
77 Results []BuildEnvResult |
| 59 } |
78 } |
| 60 |
79 |
| 61 func main() { |
80 func main() { |
| 62 data, err := os.ReadFile("testconfig.xml") |
81 data, err := os.ReadFile("testconfig.xml") |
| 63 if err != nil { |
82 if err != nil { |
| 109 for _, repo := range config.Repository { |
128 for _, repo := range config.Repository { |
| 110 if err = create_repo_archive(&repo, tpl, tmp); err != nil { |
129 if err = create_repo_archive(&repo, tpl, tmp); err != nil { |
| 111 log.Fatal(err) |
130 log.Fatal(err) |
| 112 } |
131 } |
| 113 |
132 |
| 114 exec_buildenvs(config, &repo, tmp) |
133 results := exec_buildenvs(config, &repo, tmp) |
| |
134 |
| |
135 err = save_result(&repo, results, tmp) |
| 115 } |
136 } |
| 116 } |
137 } |
| 117 |
138 |
| 118 func create_repo_archive(repo *Repository, tpl *template.Template, tmp_dir string) error { |
139 func create_repo_archive(repo *Repository, tpl *template.Template, tmp_dir string) error { |
| 119 // create a build directory, that contains the repository source |
140 // create a build directory, that contains the repository source |
| 213 return false |
234 return false |
| 214 } |
235 } |
| 215 return true |
236 return true |
| 216 } |
237 } |
| 217 |
238 |
| 218 func exec_buildenvs(config *Config, repo *Repository, tmp_dir string) int { |
239 func get_build(builds []Build, id string) *Build { |
| |
240 i, err := strconv.Atoi(id) |
| |
241 if err != nil { |
| |
242 return nil |
| |
243 } |
| |
244 if i < 0 || i >= len(builds) { |
| |
245 return nil |
| |
246 } |
| |
247 return &builds[i] |
| |
248 } |
| |
249 |
| |
250 func exec_buildenvs(config *Config, repo *Repository, tmp_dir string) []BuildEnvResult { |
| |
251 var buildResults []BuildEnvResult |
| |
252 |
| 219 if len(repo.BuildEnvs) == 0 { |
253 if len(repo.BuildEnvs) == 0 { |
| 220 log.Print("repo %s has no buildenvs", repo.Path) |
254 log.Print("repo %s has no buildenvs", repo.Path) |
| 221 return 0 |
255 return buildResults |
| 222 } |
256 } |
| 223 success := 0 |
257 |
| 224 buildenvs := strings.Split(repo.BuildEnvs, ",") |
258 buildenvs := strings.Split(repo.BuildEnvs, ",") |
| 225 for _, buildenv := range buildenvs { |
259 for _, buildenv := range buildenvs { |
| 226 env, ok := config.BuildEnvMap[buildenv] |
260 env, ok := config.BuildEnvMap[buildenv] |
| 227 if !ok { |
261 if !ok { |
| 228 log.Print("unknown build env ", buildenv) |
262 log.Print("unknown build env ", buildenv) |
| 283 if err := json.Unmarshal(resultData, &results); err != nil { |
317 if err := json.Unmarshal(resultData, &results); err != nil { |
| 284 log.Print("cannot parse result.json") |
318 log.Print("cannot parse result.json") |
| 285 continue |
319 continue |
| 286 } |
320 } |
| 287 |
321 |
| 288 log.Print(results) |
322 // store the actual Build pointer in the result |
| 289 |
323 for i := range results { |
| 290 success++ |
324 results[i].Build = get_build(repo.Build, results[i].Id) |
| 291 } |
325 } |
| 292 |
326 log.Print("buildenv finished ", env.Name) |
| 293 return success |
327 |
| 294 } |
328 envResult := BuildEnvResult{Env: &env, Results: results} |
| |
329 buildResults = append(buildResults, envResult) |
| |
330 } |
| |
331 |
| |
332 return buildResults |
| |
333 } |
| |
334 |
| |
335 func get_commit_info(tmp_dir string) *Commit { |
| |
336 var outb, errb bytes.Buffer |
| |
337 |
| |
338 commit := &Commit{} |
| |
339 |
| |
340 cmd := exec.Command("hg", "log", "-r", ".", "-T", "{rev}\\t{node|short}\\t{node}\\t{date|isodate}") |
| |
341 cmd.Dir = path.Join(tmp_dir, "build/src") |
| |
342 cmd.Stdout = &outb |
| |
343 cmd.Stderr = &errb |
| |
344 if err := cmd.Run(); err != nil { |
| |
345 log.Print(outb.String()) |
| |
346 log.Print(errb.String()) |
| |
347 return nil |
| |
348 } |
| |
349 |
| |
350 info := strings.Split(outb.String(), "\t") |
| |
351 if len(info) != 4 { |
| |
352 log.Print(outb.String()) |
| |
353 log.Print(errb.String()) |
| |
354 return nil |
| |
355 } |
| |
356 |
| |
357 commit.Rev = info[0] |
| |
358 commit.NodeShort = info[1] |
| |
359 commit.Node = info[2] |
| |
360 commit.Date = info[3] |
| |
361 |
| |
362 outb.Reset() |
| |
363 errb.Reset() |
| |
364 |
| |
365 cmd = exec.Command("hg", "log", "-r", ".", "-T", "{author}") |
| |
366 cmd.Dir = path.Join(tmp_dir, "build/src") |
| |
367 cmd.Stdout = &outb |
| |
368 cmd.Stderr = &errb |
| |
369 if err := cmd.Run(); err != nil { |
| |
370 log.Print(outb.String()) |
| |
371 log.Print(errb.String()) |
| |
372 return nil |
| |
373 } |
| |
374 commit.Author = outb.String() |
| |
375 |
| |
376 cmd = exec.Command("hg", "log", "-r", ".", "-T", "{desc}") |
| |
377 cmd.Dir = path.Join(tmp_dir, "build/src") |
| |
378 cmd.Stdout = &outb |
| |
379 cmd.Stderr = &errb |
| |
380 if err := cmd.Run(); err != nil { |
| |
381 log.Print(outb.String()) |
| |
382 log.Print(errb.String()) |
| |
383 return nil |
| |
384 } |
| |
385 commit.Desc = outb.String() |
| |
386 |
| |
387 return commit |
| |
388 } |
| |
389 |
| |
390 func save_result(repo *Repository, result []BuildEnvResult, tmp_dir string) error { |
| |
391 //out_dir := "out/" |
| |
392 |
| |
393 // get commit infos |
| |
394 get_commit_info(tmp_dir) |
| |
395 |
| |
396 return nil |
| |
397 } |