|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import sys |
| 4 | +import os |
| 5 | +import urllib |
| 6 | +import hashlib |
| 7 | +import argparse |
| 8 | + |
| 9 | + |
| 10 | +parser = argparse.ArgumentParser() |
| 11 | +parser.add_argument('--libv8-version', help='Specify required libv8 formula dependency') |
| 12 | +parser.add_argument('version', help='php-v8 version to generate formulas for') |
| 13 | +args = parser.parse_args() |
| 14 | + |
| 15 | + |
| 16 | +class HomebrewPhpV8(object): |
| 17 | + def __init__(self, tpl_path, out_path): |
| 18 | + self.tpl_path = tpl_path |
| 19 | + self.out_path = out_path |
| 20 | + |
| 21 | + def generate(self, version, libv8_version, php_versions): |
| 22 | + vars = {} |
| 23 | + |
| 24 | + url = "https://github.com/pinepain/php-v8/archive/v%s.tar.gz" % version |
| 25 | + |
| 26 | + f = urllib.urlopen(url) |
| 27 | + s = f.read() |
| 28 | + f.close() |
| 29 | + |
| 30 | + sha256 = hashlib.sha256(s).hexdigest() |
| 31 | + |
| 32 | + vars['{{ URL }}'] = 'url "%s"' % url |
| 33 | + vars['{{ SHA256 }}'] = 'sha256 "%s"' % sha256 |
| 34 | + |
| 35 | + if libv8_version: |
| 36 | + vars['{{ LIBV8_DEPENDENCY }}'] = 'depends_on "libv8-%s"' % libv8_version |
| 37 | + else: |
| 38 | + vars['{{ LIBV8_DEPENDENCY }}'] = '# NOTE: This formula depends on libv8, but actual "depends_on" dependency is not set yet' |
| 39 | + |
| 40 | + for php in php_versions: |
| 41 | + vars['{{ PHP_VERSION }}'] = php |
| 42 | + |
| 43 | + tpl = "" |
| 44 | + with open(self.tpl_path) as f: |
| 45 | + tpl = f.read() |
| 46 | + |
| 47 | + for k, v in vars.iteritems(): |
| 48 | + tpl = tpl.replace(k, v) |
| 49 | + |
| 50 | + out_path = self.out_path |
| 51 | + for k, v in vars.iteritems(): |
| 52 | + out_path = out_path.replace(k, v) |
| 53 | + |
| 54 | + with open(out_path, 'w') as f: |
| 55 | + f.write(tpl) |
| 56 | + |
| 57 | + |
| 58 | +dir_path = os.path.dirname(os.path.realpath(__file__)) |
| 59 | + |
| 60 | +deps_resolver = HomebrewPhpV8(dir_path +'/php-v8.rb.in', dir_path + '/php{{ PHP_VERSION }}-v8.rb') |
| 61 | +deps_resolver.generate(args.version, args.libv8_version, ['70', '71']) |
0 commit comments