blob: d57e4363939985bc9a4e8d344a73fce9adf3790e [file] [log] [blame]
halcanary7a76f9c2016-02-03 11:53:18 -08001#!/usr/bin/python
2
3# Copyright 2016 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8import hashlib
9import os
halcanary72002f22016-02-03 13:54:03 -080010import platform
halcanary7a76f9c2016-02-03 11:53:18 -080011import stat
halcanary72002f22016-02-03 13:54:03 -080012import subprocess
13import sys
14import urllib2
halcanary7a76f9c2016-02-03 11:53:18 -080015
16THIS_DIR = os.path.abspath(os.path.dirname(__file__))
17MOJO_DIR = os.path.abspath(os.path.join(THIS_DIR, '../../third_party/externals/mojo'))
18
19def GetFile(filename, bucket_directory):
20 def sha1hash(path):
21 hasher = hashlib.sha1()
22 if os.path.isfile(path):
23 with open(path, 'r') as f:
24 hasher.update(f.read())
25 return hasher.hexdigest()
26 sha_path = filename + '.sha1'
27 assert os.path.isfile(sha_path)
28 with open(sha_path, 'r') as f:
29 sha = f.read(40)
30 if sha1hash(filename) == sha:
31 return
32 url = 'https://storage.googleapis.com/%s/%s' % (bucket_directory, sha)
33 with open(filename, 'w') as o:
34 o.write(urllib2.urlopen(url).read())
35 os.chmod(filename, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
36 stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
37 assert sha1hash(filename) == sha
38
39def GenerateBindings(path, cdir=None):
halcanary72002f22016-02-03 13:54:03 -080040 system = (platform.machine(), platform.system())
41 if ('x86_64', 'Darwin') == system:
42 parser = 'public/tools/bindings/mojom_parser/bin/mac64/mojom_parser'
43 bucket_directory = 'mojo/mojom_parser/mac64'
44 elif ('x86_64', 'Linux') == system:
45 parser = 'public/tools/bindings/mojom_parser/bin/linux64/mojom_parser'
46 bucket_directory = 'mojo/mojom_parser/linux64'
47 else:
48 assert False
49 GetFile(os.path.join(MOJO_DIR, parser), bucket_directory)
halcanary7a76f9c2016-02-03 11:53:18 -080050 assert os.path.isfile(path)
51 path = os.path.abspath(path)
52 exe = os.path.join(
53 MOJO_DIR, 'public/tools/bindings/mojom_bindings_generator.py')
54 assert os.path.isfile(exe)
55 if cdir is None:
56 cdir = os.path.dirname(path)
57 assert os.path.isdir(cdir)
58 cwd = os.getcwd()
59 os.chdir(cdir)
60 subprocess.check_call([exe, os.path.relpath(path, cdir)])
61 os.chdir(cwd)
62
halcanary72002f22016-02-03 13:54:03 -080063if __name__ == '__main__':
64 if 1 == len(sys.argv):
65 for f in [
66 'public/interfaces/bindings/interface_control_messages.mojom',
67 'public/interfaces/application/service_provider.mojom',
68 'public/interfaces/bindings/tests/ping_service.mojom',
69 'public/interfaces/application/application.mojom',
70 ]:
71 GenerateBindings(os.path.join(MOJO_DIR, f), os.path.join(MOJO_DIR, os.pardir))
72 else:
73 for arg in sys.argv[1:]:
74 GenerateBindings(arg)