Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / native_client / build / repo_tools.py
index 13ee8b3..094692a 100644 (file)
@@ -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