X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fnative_client%2Fbuild%2Frepo_tools.py;h=094692a0a5ca4a23e9d16987748eb08f4fdd21c8;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=13ee8b3a7d47e01c1e4e9806b1fe4e1c24df48df;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/native_client/build/repo_tools.py b/src/native_client/build/repo_tools.py index 13ee8b3..094692a 100644 --- a/src/native_client/build/repo_tools.py +++ b/src/native_client/build/repo_tools.py @@ -5,14 +5,18 @@ import logging import os +import sys import file_tools import log_tools -import platform_tools +import subprocess + +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +import pynacl.platform def GitCmd(): """Return the git command to execute for the host platform.""" - if platform_tools.IsWindows(): + if pynacl.platform.IsWindows(): # On windows, we want to use the depot_tools version of git, which has # git.bat as an entry point. When running through the msys command # prompt, subprocess does not handle batch files. Explicitly invoking @@ -21,6 +25,23 @@ def GitCmd(): else: return ['git'] + +def CheckGitOutput(args): + """Run a git subcommand and capture its stdout a la subprocess.check_output. + Args: + args: list of arguments to 'git' + """ + return log_tools.CheckOutput(GitCmd() + args) + + +def SvnCmd(): + """Return the svn command to execute for the host platform.""" + if pynacl.platform.IsWindows(): + return ['cmd.exe', '/c', 'svn.bat'] + else: + return ['svn'] + + def SyncGitRepo(url, destination, revision, reclone=False, clean=False, pathspec=None): """Sync an individual git repo. @@ -64,3 +85,37 @@ def CleanGitWorkingDir(directory, path): path: path to clean, relative to the repo directory """ log_tools.CheckCall(GitCmd() + ['clean', '-f', path], cwd=directory) + + +def GitRevInfo(directory): + """Get the git revision information of a git checkout. + + Args: + directory: Existing git working directory. +""" + url = log_tools.CheckOutput(GitCmd() + ['ls-remote', '--get-url', 'origin'], + cwd=directory) + rev = log_tools.CheckOutput(GitCmd() + ['rev-parse', 'HEAD'], + cwd=directory) + return url.strip(), rev.strip() + +def SvnRevInfo(directory): + """Get the SVN revision information of an existing svn/gclient checkout. + + Args: + directory: Directory where the svn repo is currently checked out + """ + info = log_tools.CheckOutput(SvnCmd() + ['info'], cwd=directory) + url = '' + rev = '' + for line in info.splitlines(): + pieces = line.split(':', 1) + if len(pieces) != 2: + continue + if pieces[0] == 'URL': + url = pieces[1].strip() + elif pieces[0] == 'Revision': + rev = pieces[1].strip() + if not url or not rev: + raise RuntimeError('Missing svn info url: %s and rev: %s' % (url, rev)) + return url, rev