2016-12-06 21:45:24 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2016 The Dart project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
# Usage: create_pkg_manifest.py --deps <DEPS file> --output <jiri manifest>
|
|
|
|
#
|
|
|
|
# This script parses the DEPS file, extracts dependencies that live under
|
|
|
|
# third_party/pkg, and writes them to a file suitable for consumption as a
|
|
|
|
# jiri manifest for Fuchsia. It is assumed that the Dart tree is under
|
|
|
|
# //dart in the Fuchsia world, and so the dependencies extracted by this script
|
|
|
|
# will go under //dart/third_party/pkg.
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import utils
|
|
|
|
|
|
|
|
SCRIPT_DIR = os.path.dirname(sys.argv[0])
|
|
|
|
DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
|
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
|
2016-12-06 21:45:24 +00:00
|
|
|
# Used in parsing the DEPS file.
|
|
|
|
class VarImpl(object):
|
2019-08-05 20:34:31 +00:00
|
|
|
_env_vars = {
|
|
|
|
"host_cpu": "x64",
|
|
|
|
"host_os": "linux",
|
|
|
|
}
|
2019-01-02 16:17:22 +00:00
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
def __init__(self, local_scope):
|
|
|
|
self._local_scope = local_scope
|
2016-12-06 21:45:24 +00:00
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
def Lookup(self, var_name):
|
|
|
|
"""Implements the Var syntax."""
|
|
|
|
if var_name in self._local_scope.get("vars", {}):
|
|
|
|
return self._local_scope["vars"][var_name]
|
|
|
|
# Inject default values for env variables
|
|
|
|
if var_name in self._env_vars:
|
|
|
|
return self._env_vars[var_name]
|
|
|
|
raise Exception("Var is not defined: %s" % var_name)
|
2016-12-06 21:45:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ParseDepsFile(deps_file):
|
2019-08-05 20:34:31 +00:00
|
|
|
local_scope = {}
|
|
|
|
var = VarImpl(local_scope)
|
|
|
|
global_scope = {
|
|
|
|
'Var': var.Lookup,
|
|
|
|
'deps_os': {},
|
|
|
|
}
|
|
|
|
# Read the content.
|
|
|
|
with open(deps_file, 'r') as fp:
|
|
|
|
deps_content = fp.read()
|
|
|
|
|
|
|
|
# Eval the content.
|
|
|
|
exec (deps_content, global_scope, local_scope)
|
|
|
|
|
|
|
|
# Extract the deps and filter.
|
|
|
|
deps = local_scope.get('deps', {})
|
|
|
|
filtered_deps = {}
|
|
|
|
for k, v in deps.iteritems():
|
|
|
|
if 'sdk/third_party/pkg' in k:
|
|
|
|
new_key = k.replace('sdk', 'third_party/dart', 1)
|
|
|
|
filtered_deps[new_key] = v
|
|
|
|
|
|
|
|
return filtered_deps
|
2016-12-06 21:45:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def WriteManifest(deps, manifest_file):
|
2019-08-05 20:34:31 +00:00
|
|
|
project_template = """
|
2016-12-06 21:45:24 +00:00
|
|
|
<project name="%s"
|
|
|
|
path="%s"
|
|
|
|
remote="%s"
|
|
|
|
revision="%s"/>
|
|
|
|
"""
|
2019-08-05 20:34:31 +00:00
|
|
|
warning = (
|
|
|
|
'<!-- This file is generated by '
|
|
|
|
'//third_party/dart/tools/create_pkg_manifest.py. DO NOT EDIT -->\n')
|
|
|
|
with open(manifest_file, 'w') as manifest:
|
|
|
|
manifest.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
manifest.write(warning)
|
|
|
|
manifest.write('<manifest>\n')
|
|
|
|
manifest.write(' <projects>\n')
|
|
|
|
for path, remote in sorted(deps.iteritems()):
|
|
|
|
remote_components = remote.split('@')
|
|
|
|
remote_url = remote_components[0]
|
|
|
|
remote_version = remote_components[1]
|
|
|
|
manifest.write(
|
|
|
|
project_template % (path, path, remote_url, remote_version))
|
|
|
|
manifest.write(' </projects>\n')
|
|
|
|
manifest.write('</manifest>\n')
|
2016-12-06 21:45:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ParseArgs(args):
|
2019-08-05 20:34:31 +00:00
|
|
|
args = args[1:]
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='A script to generate a jiri manifest for third_party/pkg.')
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
'--deps',
|
|
|
|
'-d',
|
|
|
|
type=str,
|
|
|
|
help='Input DEPS file.',
|
|
|
|
default=os.path.join(DART_ROOT, 'DEPS'))
|
|
|
|
parser.add_argument(
|
|
|
|
'--output',
|
|
|
|
'-o',
|
|
|
|
type=str,
|
|
|
|
help='Output jiri manifest.',
|
|
|
|
default=os.path.join(DART_ROOT, 'dart_third_party_pkg.manifest'))
|
|
|
|
|
|
|
|
return parser.parse_args(args)
|
2016-12-06 21:45:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def Main(argv):
|
2019-08-05 20:34:31 +00:00
|
|
|
args = ParseArgs(argv)
|
|
|
|
deps = ParseDepsFile(args.deps)
|
|
|
|
WriteManifest(deps, args.output)
|
|
|
|
return 0
|
2016-12-06 21:45:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-08-05 20:34:31 +00:00
|
|
|
sys.exit(Main(sys.argv))
|