| #!/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 and pipe the output |
| # into the manifest you wish to populate, i.e. |
| # python deps_convert.py /home/jamesr/mojo/src/DEPS > v2/default |
| # |
| # 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(): |
| print """<?xml version="1.0" encoding="UTF-8"?> |
| <!--- DO NOT EDIT BY HAND. This file is generated by deps_convert.py --> |
| <manifest label="default"> |
| <imports> |
| <import name="buildtools"/> |
| <import name="minimal"/> |
| </imports> |
| <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> |
| <projects> |
| <!-- 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"/> |
| <!-- End of Mojo repositories --> |
| |
| <!-- Entries generated by deps_convert.py --> |
| """ |
| |
| def print_project_footer(): |
| print """ |
| <!-- End of entries generated by deps_convert.py --> |
| </projects>""" |
| |
| def print_hooks_header(): |
| print """ |
| <hooks> |
| <!-- Entries generated by deps_convert.py --> |
| """ |
| |
| def print_hooks_footer(): |
| print """ |
| <!-- End of entries generated by deps_convert.py --> |
| </hooks> |
| </manifest>""" |
| |
| def strip_src_prefix(path): |
| return path.split("src/")[-1] |
| |
| def print_parsed_deps(deps): |
| for path, remote_and_revision in deps.iteritems(): |
| remote, revision = remote_and_revision.split('@') |
| name = strip_src_prefix(path).replace("/", "_") |
| print """ |
| <project name="%s" |
| remote="%s" |
| path="%s" |
| revision="%s"/>""" % (name, remote, path, revision) |
| |
| def print_parsed_hooks(hooks): |
| for hook in scope["hooks"]: |
| name = hook["name"] |
| action = hook["action"] |
| if action[0] == "python": |
| script = strip_src_prefix(action[1]) |
| print_python_action(name, "mojo", script, action[2:]) |
| elif action[0] == "src/tools/download_from_google_storage.py": |
| print_download_action(name, action[1:]) |
| else: |
| print "action %s not understood, action %s" % (name, action) |
| sys.exit(1) |
| |
| def print_python_action(name, project, script, args): |
| print """ <hook name="%s" |
| project="%s" |
| interpreter="python" |
| path="%s">""" % (name, project, script) |
| for arg in args: |
| print " <arg>%s</arg>" % arg |
| print " </hook>" |
| |
| def print_download_action(name, args): |
| print_python_action(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) |
| print_project_header() |
| print_parsed_deps(scope["deps"]) |
| print_project_footer() |
| print_hooks_header() |
| print_parsed_hooks(scope["hooks"]) |
| print_hooks_footer() |
| |
| if __name__ == '__main__': |
| sys.exit(main()) |