blob: d546097ea42c5edc9bb8392ecd18b8bc9fd64038 [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This is a TEMPORARY script to convert Mojo's DEPS file into a Jiri manifest.
# It is not a general purpose DEPS to manifest converter and intentionally omits
# or simplifies many of gclient's semantics. To run, invoke this script with the
# mojo DEPS file you wish to target as the only argument.
#
# python deps_convert.py /home/jamesr/mojo/src/DEPS
#
# This is a python script since the DEPS file is a python object. It will go
# away when we stop using gclient for Mojo.
import sys
def print_project_header(f):
f.write("""<?xml version="1.0" encoding="UTF-8"?>
<!--- DO NOT EDIT BY HAND. This file is generated by deps_convert.py -->
<manifest label="mojo">
""")
def print_mojo_imports(f):
f.write(""" <imports>
<import name="buildtools"/>
<import name="minimal"/>
</imports>
""")
def print_android_imports(f):
f.write(""" <imports>
<import name="mojo"/>
</imports>
""")
def print_hosts(f):
f.write(""" <hosts>
<host name="gerrit"
location="https://mojo-review.googlesource.com/"/>
<host name="git"
location="https://mojo.googlesource.com/">
<githooks>
<githook name="commit-msg" path="../git-hooks/add-gerrit-change-id" />
<githook name="pre-push" path="../git-hooks/run-presubmit-checks" />
</githooks>
</host>
</hosts>
""")
def print_projects_header(f):
f.write(" <projects>\n")
def print_mojo_projects(f):
f.write(""" <!-- Mojo repositories -->
<project name="mojo"
path="src"
remote="https://mojo.googlesource.com/mojo"/>
<project name="depot_tools"
path="depot_tools"
remote="https://chromium.googlesource.com/chromium/tools/depot_tools.git"/>
<project name="mojo-manifest"
path="mojo-manifest"
remote="https://mojo.googlesource.com/mojo-manifest"/>
<project name="asio"
path="src/third_party/asio"
remote="https://mojo.googlesource.com/asio"
remotebranch="mojo"/>
<project name="lesnet"
path="lesnet"
remote="https://mojo.googlesource.com/lesnet"/>
<!-- End of Mojo repositories -->
<!-- Entries generated by deps_convert.py -->
""")
def print_projects_footer(f):
f.write(""" <!-- End of entries generated by deps_convert.py -->
</projects>""")
def print_hooks_header(f):
f.write(""" <hooks>
<!-- Entries generated by deps_convert.py -->
""")
def print_hooks_footer(f):
f.write(""" <!-- End of entries generated by deps_convert.py -->
</hooks>""")
def print_manifest_footer(f):
f.write("""
</manifest>""")
def strip_src_prefix(path):
return path.split("src/")[-1]
def print_parsed_deps(f, deps):
for path, remote_and_revision in deps.iteritems():
remote, revision = remote_and_revision.split('@')
name = strip_src_prefix(path).replace("/", "_")
f.write(""" <project name="%s"
remote="%s"
path="%s"
revision="%s"/>
""" % (name, remote, path, revision))
def print_parsed_hooks(f, hooks, android):
for hook in scope["hooks"]:
name = hook["name"]
is_android_hook = name == "android_tools" or name == "sdkextras"
if android != is_android_hook:
continue
action = hook["action"]
if action[0] == "python":
script = strip_src_prefix(action[1])
print_python_action(f, name, "mojo", script, action[2:])
elif action[0] == "src/tools/download_from_google_storage.py":
print_download_action(f, name, action[1:])
else:
f.write("action %s not understood, action %s" % (name, action))
sys.exit(1)
def print_python_action(f, name, project, script, args):
f.write(""" <hook name="%s"
project="%s"
interpreter="python"
path="%s">
""" % (name, project, script))
for arg in args:
f.write(" <arg>%s</arg>\n" % arg)
f.write(" </hook>\n")
def print_download_action(f, name, args):
print_python_action(f, name, "mojo", "tools/download_from_google_storage.py", args)
scope = {}
def Var(key):
return scope["vars"][key]
scope["Var"] = Var
def main():
if len(sys.argv) != 2:
print "must specify path to DEPS file"
sys.exit(1)
with open(sys.argv[1]) as deps_contents:
d = deps_contents.read()
exec(d, scope)
with open("v2/mojo", "w") as f:
print_project_header(f)
print_mojo_imports(f)
print_hosts(f)
print_projects_header(f)
print_mojo_projects(f)
print_parsed_deps(f, scope["deps"])
print_projects_footer(f)
print_hooks_header(f)
print_parsed_hooks(f, scope["hooks"], False)
print_hooks_footer(f)
print_manifest_footer(f)
with open("v2/android", "w") as f:
print_project_header(f)
print_android_imports(f)
print_projects_header(f)
print_parsed_deps(f, scope["deps_os"]["android"])
print_projects_footer(f)
print_hooks_header(f)
print_parsed_hooks(f, scope["hooks"], True)
print_hooks_footer(f)
print_manifest_footer(f)
if __name__ == '__main__':
sys.exit(main())