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

Unified 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 side-by-side diff with in-line comments
Download patch
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: infra/bots/gen_tasks.go
diff --git a/infra/bots/gen_tasks.go b/infra/bots/gen_tasks.go
index 50af1b9444cb43aeb18b5c7266c48c95e41e798f..0751124368c73f4cda8ac29e18ee8c5eebb402f3 100644
--- a/infra/bots/gen_tasks.go
+++ b/infra/bots/gen_tasks.go
@@ -11,6 +11,7 @@ package main
import (
"bytes"
"encoding/json"
+ "flag"
"fmt"
"io/ioutil"
"os"
@@ -62,6 +63,9 @@ var (
// Path to the infra/bots directory.
infrabotsDir = ""
+
+ // Flags.
+ testing = flag.Bool("test", false, "Run in test mode: verify that the output hasn't changed.")
)
// deriveCompileTaskName returns the name of a compile task based on the given
@@ -492,7 +496,6 @@ func main() {
}
// Write the tasks.json file.
- outFile := path.Join(root, specs.TASKS_CFG_FILE)
b, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
glog.Fatal(err)
@@ -501,8 +504,21 @@ func main() {
// much less readable. Replace the escape characters with the real
// character.
b = bytes.Replace(b, []byte("\\u003c"), []byte("<"), -1)
- if err := ioutil.WriteFile(outFile, b, os.ModePerm); err != nil {
- glog.Fatal(err)
+
+ outFile := path.Join(root, specs.TASKS_CFG_FILE)
+ if *testing {
+ // Don't write the file; read it and compare.
+ expect, err := ioutil.ReadFile(outFile)
+ if err != nil {
+ glog.Fatal(err)
+ }
+ if !bytes.Equal(expect, b) {
+ glog.Fatalf("Expected no changes, but changes were found!")
+ }
+ } else {
+ if err := ioutil.WriteFile(outFile, b, os.ModePerm); err != nil {
+ glog.Fatal(err)
+ }
}
}
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698