Flutter Engine
The Flutter Engine
create_pkg_manifest.py
Go to the documentation of this file.
1#!/usr/bin/env python3
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
14import argparse
15import os
16import sys
17import utils
18
19SCRIPT_DIR = os.path.dirname(sys.argv[0])
20DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
21
22
23# Used in parsing the DEPS file.
24class VarImpl(object):
25 _env_vars = {
26 "host_cpu": "x64",
27 "host_os": "linux",
28 }
29
30 def __init__(self, local_scope):
31 self._local_scope = local_scope
32
33 def Lookup(self, var_name):
34 """Implements the Var syntax."""
35 if var_name in self._local_scope.get("vars", {}):
36 return self._local_scope["vars"][var_name]
37 # Inject default values for env variables
38 if var_name in self._env_vars:
39 return self._env_vars[var_name]
40 raise Exception("Var is not defined: %s" % var_name)
41
42
43def ParseDepsFile(deps_file):
44 local_scope = {}
45 var = VarImpl(local_scope)
46 global_scope = {
47 'Var': var.Lookup,
48 'deps_os': {},
49 }
50 # Read the content.
51 with open(deps_file, 'r') as fp:
52 deps_content = fp.read()
53
54 # Eval the content.
55 exec (deps_content, global_scope, local_scope)
56
57 # Extract the deps and filter.
58 deps = local_scope.get('deps', {})
59 filtered_deps = {}
60 for k, v in deps.items():
61 if 'sdk/third_party/pkg' in k:
62 new_key = k.replace('sdk', 'third_party/dart', 1)
63 filtered_deps[new_key] = v
64
65 return filtered_deps
66
67
68def WriteManifest(deps, manifest_file):
69 project_template = """
70 <project name="%s"
71 path="%s"
72 remote="%s"
73 revision="%s"/>
74"""
75 warning = (
76 '<!-- This file is generated by '
77 '//third_party/dart/tools/create_pkg_manifest.py. DO NOT EDIT -->\n')
78 with open(manifest_file, 'w') as manifest:
79 manifest.write('<?xml version="1.0" encoding="UTF-8"?>\n')
80 manifest.write(warning)
81 manifest.write('<manifest>\n')
82 manifest.write(' <projects>\n')
83 for path, remote in sorted(deps.items()):
84 remote_components = remote.split('@')
85 remote_url = remote_components[0]
86 remote_version = remote_components[1]
87 manifest.write(
88 project_template % (path, path, remote_url, remote_version))
89 manifest.write(' </projects>\n')
90 manifest.write('</manifest>\n')
91
92
93def ParseArgs(args):
94 args = args[1:]
95 parser = argparse.ArgumentParser(
96 description='A script to generate a jiri manifest for third_party/pkg.')
97
98 parser.add_argument(
99 '--deps',
100 '-d',
101 type=str,
102 help='Input DEPS file.',
103 default=os.path.join(DART_ROOT, 'DEPS'))
104 parser.add_argument(
105 '--output',
106 '-o',
107 type=str,
108 help='Output jiri manifest.',
109 default=os.path.join(DART_ROOT, 'dart_third_party_pkg.manifest'))
110
111 return parser.parse_args(args)
112
113
114def Main(argv):
115 args = ParseArgs(argv)
116 deps = ParseDepsFile(args.deps)
117 WriteManifest(deps, args.output)
118 return 0
119
120
121if __name__ == '__main__':
122 sys.exit(Main(sys.argv))
def __init__(self, local_scope)
def WriteManifest(deps, manifest_file)
def ParseDepsFile(deps_file)
const myers::Point & get(const myers::Segment &)