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

Side by Side Diff: mojom/mojom_parser/check_version.go

Issue 1833493002: Replace ErrorExit with log.Fatal in the mojom tool. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 import ( 7 import (
8 "crypto/sha1" 8 "crypto/sha1"
9 "encoding/hex" 9 "encoding/hex"
10 "io/ioutil" 10 "io/ioutil"
11 "log" 11 "log"
12 "path/filepath" 12 "path/filepath"
13 "strings" 13 "strings"
14 ) 14 )
15 15
16 // checkVersion verifies the version of the mojom tool being executed 16 // checkVersion verifies the version of the mojom tool being executed
17 // corresponds to the sha1 checked in source control. It works as following: 17 // corresponds to the sha1 checked in source control. It works as following:
18 // 18 //
19 // If there is no file mojom.sha1 in the same directory as the tool, the version 19 // If there is no file mojom.sha1 in the same directory as the tool, the version
20 // check is bypassed. 20 // check is bypassed.
21 // If there is such a file, that files is read and it is decoded assuming that 21 // If there is such a file, that files is read and it is decoded assuming that
22 // it contains a hexadecimal-encoded sha1 hash. The sha1 hash of the mojom tool 22 // it contains a hexadecimal-encoded sha1 hash. The sha1 hash of the mojom tool
23 // binary being run is then computed and compared against that in the file. If 23 // binary being run is then computed and compared against that in the file. If
24 // the comparison fails, an error message is logged and the program terminates 24 // the comparison fails, an error message is logged and the program terminates
25 // with return code 1. 25 // with return code 1.
26 func checkVersion(args []string) { 26 func checkVersion(args []string) {
27 // TODO(azani): Move log.SetFlags to mojom_main.go when replacing ErrorE xit with log.Fatalln.
28 log.SetFlags(0)
29 mojomToolPath := args[0] 27 mojomToolPath := args[0]
30 mojomDir := filepath.Dir(mojomToolPath) 28 mojomDir := filepath.Dir(mojomToolPath)
31 sha1FilePath := filepath.Join(mojomDir, "mojom.sha1") 29 sha1FilePath := filepath.Join(mojomDir, "mojom.sha1")
32 30
33 // First we read the file containing the sha1 hash. 31 // First we read the file containing the sha1 hash.
34 expectedSha1Bytes, err := ioutil.ReadFile(sha1FilePath) 32 expectedSha1Bytes, err := ioutil.ReadFile(sha1FilePath)
35 if err != nil { 33 if err != nil {
36 // Could not read mojom.sha1. Assume it does not exist. 34 // Could not read mojom.sha1. Assume it does not exist.
37 return 35 return
38 } 36 }
(...skipping 11 matching lines...) Expand all
50 48
51 if mojomToolSha1 != expectedSha1 { 49 if mojomToolSha1 != expectedSha1 {
52 mojomToolAbsPath, err := filepath.Abs(mojomToolPath) 50 mojomToolAbsPath, err := filepath.Abs(mojomToolPath)
53 if err == nil { 51 if err == nil {
54 mojomToolPath = mojomToolAbsPath 52 mojomToolPath = mojomToolAbsPath
55 } 53 }
56 log.Fatalf("The version of the mojom tool at %s does not corresp ond to mojom.sha1 "+ 54 log.Fatalf("The version of the mojom tool at %s does not corresp ond to mojom.sha1 "+
57 "in the same directory. Please update the mojom tool (ru n gclient sync).\n", mojomToolPath) 55 "in the same directory. Please update the mojom tool (ru n gclient sync).\n", mojomToolPath)
58 } 56 }
59 } 57 }
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 ('k') | mojom/mojom_parser/fmt_cmd.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698