Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: infra/bots/gen_tasks.go

Issue 2392083002: Add --test to gen_tasks.go, add presubmit check (Closed)
Patch Set: Only on upload Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 /* 7 /*
8 Generate the tasks.json file. 8 Generate the tasks.json file.
9 */ 9 */
10 10
11 import ( 11 import (
12 "bytes" 12 "bytes"
13 "encoding/json" 13 "encoding/json"
14 "flag"
14 "fmt" 15 "fmt"
15 "io/ioutil" 16 "io/ioutil"
16 "os" 17 "os"
17 "path" 18 "path"
18 "path/filepath" 19 "path/filepath"
19 "sort" 20 "sort"
20 "strings" 21 "strings"
21 22
22 "github.com/skia-dev/glog" 23 "github.com/skia-dev/glog"
23 "go.skia.org/infra/go/common" 24 "go.skia.org/infra/go/common"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 56
56 // Defines the structure of job names. 57 // Defines the structure of job names.
57 jobNameSchema *JobNameSchema 58 jobNameSchema *JobNameSchema
58 59
59 // Caches CIPD package info so that we don't have to re-read VERSION 60 // Caches CIPD package info so that we don't have to re-read VERSION
60 // files. 61 // files.
61 cipdPackages = map[string]*specs.CipdPackage{} 62 cipdPackages = map[string]*specs.CipdPackage{}
62 63
63 // Path to the infra/bots directory. 64 // Path to the infra/bots directory.
64 infrabotsDir = "" 65 infrabotsDir = ""
66
67 // Flags.
68 testing = flag.Bool("test", false, "Run in test mode: verify that the ou tput hasn't changed.")
65 ) 69 )
66 70
67 // deriveCompileTaskName returns the name of a compile task based on the given 71 // deriveCompileTaskName returns the name of a compile task based on the given
68 // job name. 72 // job name.
69 func deriveCompileTaskName(jobName string, parts map[string]string) string { 73 func deriveCompileTaskName(jobName string, parts map[string]string) string {
70 if parts["role"] == "Housekeeper" { 74 if parts["role"] == "Housekeeper" {
71 return "Build-Ubuntu-GCC-x86_64-Release-Shared" 75 return "Build-Ubuntu-GCC-x86_64-Release-Shared"
72 } else if parts["role"] == "Test" || parts["role"] == "Perf" { 76 } else if parts["role"] == "Test" || parts["role"] == "Perf" {
73 task_os := parts["os"] 77 task_os := parts["os"]
74 ec := parts["extra_config"] 78 ec := parts["extra_config"]
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 for _, j := range JOBS { 489 for _, j := range JOBS {
486 process(cfg, j) 490 process(cfg, j)
487 } 491 }
488 492
489 // Validate the config. 493 // Validate the config.
490 if err := cfg.Validate(); err != nil { 494 if err := cfg.Validate(); err != nil {
491 glog.Fatal(err) 495 glog.Fatal(err)
492 } 496 }
493 497
494 // Write the tasks.json file. 498 // Write the tasks.json file.
495 outFile := path.Join(root, specs.TASKS_CFG_FILE)
496 b, err := json.MarshalIndent(cfg, "", " ") 499 b, err := json.MarshalIndent(cfg, "", " ")
497 if err != nil { 500 if err != nil {
498 glog.Fatal(err) 501 glog.Fatal(err)
499 } 502 }
500 // The json package escapes HTML characters, which makes our output 503 // The json package escapes HTML characters, which makes our output
501 // much less readable. Replace the escape characters with the real 504 // much less readable. Replace the escape characters with the real
502 // character. 505 // character.
503 b = bytes.Replace(b, []byte("\\u003c"), []byte("<"), -1) 506 b = bytes.Replace(b, []byte("\\u003c"), []byte("<"), -1)
504 » if err := ioutil.WriteFile(outFile, b, os.ModePerm); err != nil { 507
505 » » glog.Fatal(err) 508 » outFile := path.Join(root, specs.TASKS_CFG_FILE)
509 » if *testing {
510 » » // Don't write the file; read it and compare.
511 » » expect, err := ioutil.ReadFile(outFile)
512 » » if err != nil {
513 » » » glog.Fatal(err)
514 » » }
515 » » if !bytes.Equal(expect, b) {
516 » » » glog.Fatalf("Expected no changes, but changes were found !")
517 » » }
518 » } else {
519 » » if err := ioutil.WriteFile(outFile, b, os.ModePerm); err != nil {
520 » » » glog.Fatal(err)
521 » » }
506 } 522 }
507 } 523 }
508 524
509 // TODO(borenet): The below really belongs in its own file, probably next to the 525 // TODO(borenet): The below really belongs in its own file, probably next to the
510 // builder_name_schema.json file. 526 // builder_name_schema.json file.
511 527
512 // JobNameSchema is a struct used for (de)constructing Job names in a 528 // JobNameSchema is a struct used for (de)constructing Job names in a
513 // predictable format. 529 // predictable format.
514 type JobNameSchema struct { 530 type JobNameSchema struct {
515 Schema map[string][]string `json:"builder_name_schema"` 531 Schema map[string][]string `json:"builder_name_schema"`
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 if !ok { 596 if !ok {
581 return "", fmt.Errorf("Invalid job parts; missing %q", k ) 597 return "", fmt.Errorf("Invalid job parts; missing %q", k )
582 } 598 }
583 rvParts = append(rvParts, v) 599 rvParts = append(rvParts, v)
584 } 600 }
585 if _, ok := parts["extra_config"]; ok { 601 if _, ok := parts["extra_config"]; ok {
586 rvParts = append(rvParts, parts["extra_config"]) 602 rvParts = append(rvParts, parts["extra_config"])
587 } 603 }
588 return strings.Join(rvParts, s.Sep), nil 604 return strings.Join(rvParts, s.Sep), nil
589 } 605 }
OLDNEW
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698