|
| 1 | +#!/usr/bin/env python |
| 2 | +# Copyright 2017 The Dart project authors. All rights reserved. |
| 3 | +# Use of this source code is governed by a BSD-style license that can be |
| 4 | +# found in the LICENSE file. |
| 5 | + |
| 6 | +# Usage: tools/dart/create_updated_flutter_deps.py [-d dart/DEPS] [-f flutter/DEPS] |
| 7 | +# |
| 8 | +# This script parses existing flutter DEPS file, identifies all 'dart_' prefixed |
| 9 | +# dependencies, looks up revision from dart DEPS file and prints a list of updated |
| 10 | +# revision to the console so it can be copy'n'pasted into flutter DEPS file. |
| 11 | + |
| 12 | +import argparse |
| 13 | +import os |
| 14 | +import sys |
| 15 | + |
| 16 | +DART_SCRIPT_DIR = os.path.dirname(sys.argv[0]) |
| 17 | +DART_ROOT = os.path.realpath(os.path.join(DART_SCRIPT_DIR, '../../dart')) |
| 18 | +FLUTTER_ROOT = os.path.realpath(os.path.join(DART_SCRIPT_DIR, '../../flutter')) |
| 19 | + |
| 20 | +class VarImpl(object): |
| 21 | + def __init__(self, local_scope): |
| 22 | + self._local_scope = local_scope |
| 23 | + |
| 24 | + def Lookup(self, var_name): |
| 25 | + """Implements the Var syntax.""" |
| 26 | + if var_name in self._local_scope.get("vars", {}): |
| 27 | + return self._local_scope["vars"][var_name] |
| 28 | + raise Exception("Var is not defined: %s" % var_name) |
| 29 | + |
| 30 | + |
| 31 | +def ParseDepsFile(deps_file): |
| 32 | + local_scope = {} |
| 33 | + var = VarImpl(local_scope) |
| 34 | + global_scope = { |
| 35 | + 'Var': var.Lookup, |
| 36 | + 'deps_os': {}, |
| 37 | + } |
| 38 | + # Read the content. |
| 39 | + with open(deps_file, 'r') as fp: |
| 40 | + deps_content = fp.read() |
| 41 | + |
| 42 | + # Eval the content. |
| 43 | + exec(deps_content, global_scope, local_scope) |
| 44 | + |
| 45 | + return local_scope.get('vars', {}) |
| 46 | + |
| 47 | +def ParseArgs(args): |
| 48 | + args = args[1:] |
| 49 | + parser = argparse.ArgumentParser( |
| 50 | + description='A script to generate updated dart dependencies for flutter DEPS.') |
| 51 | + parser.add_argument('--dart_deps', '-d', |
| 52 | + type=str, |
| 53 | + help='Dart DEPS file.', |
| 54 | + default=os.path.join(DART_ROOT, 'DEPS')) |
| 55 | + parser.add_argument('--flutter_deps', '-f', |
| 56 | + type=str, |
| 57 | + help='Flutter DEPS file.', |
| 58 | + default=os.path.join(FLUTTER_ROOT, 'DEPS')) |
| 59 | + return parser.parse_args(args) |
| 60 | + |
| 61 | +def Main(argv): |
| 62 | + args = ParseArgs(argv) |
| 63 | + new_deps = ParseDepsFile(args.dart_deps) |
| 64 | + old_deps = ParseDepsFile(args.flutter_deps) |
| 65 | + for (k,v) in sorted(old_deps.iteritems()): |
| 66 | + if k != 'dart_revision' and k.startswith('dart_'): |
| 67 | + v = '???' |
| 68 | + dart_key = k[len('dart_'):] |
| 69 | + updated_revision = new_deps[dart_key].lstrip('@') if new_deps.has_key(dart_key) else v |
| 70 | + print " '%s': '%s'," % (k, updated_revision) |
| 71 | + return 0 |
| 72 | + |
| 73 | +if __name__ == '__main__': |
| 74 | + sys.exit(Main(sys.argv)) |
0 commit comments