OLD | NEW |
(Empty) | |
| 1 #!/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 |
| 8 import hashlib |
| 9 import os |
| 10 import subprocess |
| 11 import urllib2 |
| 12 import stat |
| 13 |
| 14 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 15 MOJO_DIR = os.path.abspath(os.path.join(THIS_DIR, '../../third_party/externals/m
ojo')) |
| 16 |
| 17 def GetFile(filename, bucket_directory): |
| 18 def sha1hash(path): |
| 19 hasher = hashlib.sha1() |
| 20 if os.path.isfile(path): |
| 21 with open(path, 'r') as f: |
| 22 hasher.update(f.read()) |
| 23 return hasher.hexdigest() |
| 24 sha_path = filename + '.sha1' |
| 25 assert os.path.isfile(sha_path) |
| 26 with open(sha_path, 'r') as f: |
| 27 sha = f.read(40) |
| 28 if sha1hash(filename) == sha: |
| 29 return |
| 30 url = 'https://storage.googleapis.com/%s/%s' % (bucket_directory, sha) |
| 31 with open(filename, 'w') as o: |
| 32 o.write(urllib2.urlopen(url).read()) |
| 33 os.chmod(filename, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | |
| 34 stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) |
| 35 assert sha1hash(filename) == sha |
| 36 |
| 37 def GenerateBindings(path, cdir=None): |
| 38 GetFile(os.path.join(MOJO_DIR, |
| 39 'public/tools/bindings/mojom_parser/bin/linux64/mojom_p
arser'), |
| 40 'mojo/mojom_parser/linux64') |
| 41 assert os.path.isfile(path) |
| 42 path = os.path.abspath(path) |
| 43 exe = os.path.join( |
| 44 MOJO_DIR, 'public/tools/bindings/mojom_bindings_generator.py') |
| 45 assert os.path.isfile(exe) |
| 46 if cdir is None: |
| 47 cdir = os.path.dirname(path) |
| 48 assert os.path.isdir(cdir) |
| 49 cwd = os.getcwd() |
| 50 os.chdir(cdir) |
| 51 subprocess.check_call([exe, os.path.relpath(path, cdir)]) |
| 52 os.chdir(cwd) |
| 53 |
| 54 for f in [ |
| 55 'public/interfaces/bindings/interface_control_messages.mojom', |
| 56 'public/interfaces/application/service_provider.mojom', |
| 57 'public/interfaces/bindings/tests/ping_service.mojom', |
| 58 'public/interfaces/application/application.mojom', |
| 59 ]: |
| 60 GenerateBindings(os.path.join(MOJO_DIR, f), os.path.join(MOJO_DIR, os.pardir
)) |
| 61 |
| 62 GenerateBindings(os.path.join(THIS_DIR, 'SkMojo.mojom')) |
OLD | NEW |