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

Side by Side Diff: gin/fingerprint/fingerprint_v8_snapshot.py

Issue 2680653002: [gin] Removing file validation. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « gin/BUILD.gn ('k') | gin/v8_initializer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Fingerprints the V8 snapshot blob files.
8
9 Constructs a SHA256 fingerprint of the V8 natives and snapshot blob files and
10 creates a .cc file which includes these fingerprint as variables.
11 """
12
13 import hashlib
14 import optparse
15 import os
16 import sys
17
18 _HEADER = """// Copyright 2015 The Chromium Authors. All rights reserved.
19 // Use of this source code is governed by a BSD-style license that can be
20 // found in the LICENSE file.
21
22 // This file was generated by fingerprint_v8_snapshot.py.
23
24 namespace gin {
25 """
26
27 _FOOTER = """
28 } // namespace gin
29 """
30
31
32 def FingerprintFile(file_path):
33 input_file = open(file_path, 'rb')
34 sha256 = hashlib.sha256()
35 while True:
36 block = input_file.read(sha256.block_size)
37 if not block:
38 break
39 sha256.update(block)
40 return sha256.digest()
41
42
43 def WriteFingerprint(output_file, variable_name, fingerprint):
44 output_file.write('\nextern const unsigned char %s[] = { ' % variable_name)
45 for byte in fingerprint:
46 output_file.write(str(ord(byte)) + ', ')
47 output_file.write('};\n')
48
49
50 def WriteOutputFile(natives_fingerprint,
51 snapshot_fingerprint,
52 output_file_path):
53 output_dir_path = os.path.dirname(output_file_path)
54 if not os.path.exists(output_dir_path):
55 os.makedirs(output_dir_path)
56 output_file = open(output_file_path, 'w')
57
58 output_file.write(_HEADER)
59 WriteFingerprint(output_file, 'g_natives_fingerprint', natives_fingerprint)
60 output_file.write('\n')
61 WriteFingerprint(output_file, 'g_snapshot_fingerprint', snapshot_fingerprint)
62 output_file.write(_FOOTER)
63
64
65 def main():
66 parser = optparse.OptionParser()
67
68 parser.add_option('--snapshot_file',
69 help='The input V8 snapshot blob file path.')
70 parser.add_option('--natives_file',
71 help='The input V8 natives blob file path.')
72 parser.add_option('--output_file',
73 help='The path for the output cc file which will be write.')
74
75 options, _ = parser.parse_args()
76
77 natives_fingerprint = FingerprintFile(options.natives_file)
78 snapshot_fingerprint = FingerprintFile(options.snapshot_file)
79 WriteOutputFile(
80 natives_fingerprint, snapshot_fingerprint, options.output_file)
81
82 return 0
83
84
85 if __name__ == '__main__':
86 sys.exit(main())
OLDNEW
« no previous file with comments | « gin/BUILD.gn ('k') | gin/v8_initializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698