OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 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: create_pkg_manifest.py --deps <DEPS file> --output <jiri manifest> |
| 7 # |
| 8 # This script parses the DEPS file, extracts dependencies that live under |
| 9 # third_party/pkg, and writes them to a file suitable for consumption as a |
| 10 # jiri manifest for Fuchsia. It is assumed that the Dart tree is under |
| 11 # //dart in the Fuchsia world, and so the dependencies extracted by this script |
| 12 # will go under //dart/third_party/pkg. |
| 13 |
| 14 import argparse |
| 15 import os |
| 16 import sys |
| 17 import utils |
| 18 |
| 19 SCRIPT_DIR = os.path.dirname(sys.argv[0]) |
| 20 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) |
| 21 |
| 22 # Used in parsing the DEPS file. |
| 23 class VarImpl(object): |
| 24 def __init__(self, local_scope): |
| 25 self._local_scope = local_scope |
| 26 |
| 27 def Lookup(self, var_name): |
| 28 """Implements the Var syntax.""" |
| 29 if var_name in self._local_scope.get("vars", {}): |
| 30 return self._local_scope["vars"][var_name] |
| 31 raise Exception("Var is not defined: %s" % var_name) |
| 32 |
| 33 |
| 34 def ParseDepsFile(deps_file): |
| 35 local_scope = {} |
| 36 var = VarImpl(local_scope) |
| 37 global_scope = { |
| 38 'Var': var.Lookup, |
| 39 'deps_os': {}, |
| 40 } |
| 41 # Read the content. |
| 42 with open(deps_file, 'r') as fp: |
| 43 deps_content = fp.read() |
| 44 |
| 45 # Eval the content. |
| 46 exec(deps_content, global_scope, local_scope) |
| 47 |
| 48 # Extract the deps and filter. |
| 49 deps = local_scope.get('deps', {}) |
| 50 filtered_deps = {} |
| 51 for k, v in deps.iteritems(): |
| 52 if 'sdk/third_party/pkg' in k: |
| 53 new_key = k.replace('sdk', 'dart', 1) |
| 54 filtered_deps[new_key] = v |
| 55 |
| 56 return filtered_deps |
| 57 |
| 58 |
| 59 def WriteManifest(deps, manifest_file): |
| 60 project_template = """ |
| 61 <project name="%s" |
| 62 path="%s" |
| 63 remote="%s" |
| 64 revision="%s"/> |
| 65 """ |
| 66 warning = ('<!-- This file is generated by ' |
| 67 '//dart/tools/create_pkg_manifest.py. DO NOT EDIT -->\n') |
| 68 with open(manifest_file, 'w') as manifest: |
| 69 manifest.write(warning) |
| 70 manifest.write('<?xml version="1.0" encoding="UTF-8"?>\n') |
| 71 manifest.write('<manifest>\n') |
| 72 manifest.write(' <projects>\n') |
| 73 for path, remote in deps.iteritems(): |
| 74 remote_components = remote.split('@') |
| 75 remote_url = remote_components[0] |
| 76 remote_version = remote_components[1] |
| 77 manifest.write( |
| 78 project_template % (path, path, remote_url, remote_version)) |
| 79 manifest.write(' </projects>\n') |
| 80 manifest.write('</manifest>\n') |
| 81 |
| 82 |
| 83 def ParseArgs(args): |
| 84 args = args[1:] |
| 85 parser = argparse.ArgumentParser( |
| 86 description='A script to generate a jiri manifest for third_party/pkg.') |
| 87 |
| 88 parser.add_argument('--deps', '-d', |
| 89 type=str, |
| 90 help='Input DEPS file.', |
| 91 default=os.path.join(DART_ROOT, 'DEPS')) |
| 92 parser.add_argument('--output', '-o', |
| 93 type=str, |
| 94 help='Output jiri manifest.', |
| 95 default=os.path.join(DART_ROOT, 'dart_third_party_pkg.manifest')) |
| 96 |
| 97 return parser.parse_args(args) |
| 98 |
| 99 |
| 100 def Main(argv): |
| 101 args = ParseArgs(argv) |
| 102 deps = ParseDepsFile(args.deps) |
| 103 WriteManifest(deps, args.output) |
| 104 return 0 |
| 105 |
| 106 |
| 107 if __name__ == '__main__': |
| 108 sys.exit(Main(sys.argv)) |
OLD | NEW |