• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6# Wrapper script for running gradle.
7# Will make sure we pulled down gradle before running, and will use the pulled
8# down version to have a consistent developer experience.
9
10import os
11import subprocess
12import sys
13import utils
14
15GRADLE_DIR = os.path.join(utils.REPO_ROOT, 'third_party', 'gradle')
16GRADLE_SHA1 = os.path.join(GRADLE_DIR, 'gradle.tar.gz.sha1')
17GRADLE_TGZ = os.path.join(GRADLE_DIR, 'gradle.tar.gz')
18if utils.IsWindows():
19  GRADLE = os.path.join(GRADLE_DIR, 'gradle', 'bin', 'gradle.bat')
20else:
21  GRADLE = os.path.join(GRADLE_DIR, 'gradle', 'bin', 'gradle')
22
23def PrintCmd(s):
24  if type(s) is list:
25    s = ' '.join(s)
26  print 'Running: %s' % s
27  # I know this will hit os on windows eventually if we don't do this.
28  sys.stdout.flush()
29
30def EnsureGradle():
31  if not os.path.exists(GRADLE) or os.path.getmtime(GRADLE_TGZ) < os.path.getmtime(GRADLE_SHA1):
32    # Bootstrap or update gradle, everything else is controlled using gradle.
33    utils.DownloadFromGoogleCloudStorage(GRADLE_SHA1)
34    # Update the mtime of the tar file to make sure we do not run again unless
35    # there is an update.
36    os.utime(GRADLE_TGZ, None)
37  else:
38    print 'gradle.py: Gradle binary present'
39
40def RunGradle(args, throw_on_failure=True):
41  EnsureGradle()
42  cmd = [GRADLE]
43  cmd.extend(args)
44  utils.PrintCmd(cmd)
45  with utils.ChangedWorkingDirectory(utils.REPO_ROOT):
46    return_value = subprocess.call(cmd)
47    if throw_on_failure and return_value != 0:
48      raise
49    return return_value
50
51def Main():
52  RunGradle(sys.argv[1:])
53
54if __name__ == '__main__':
55  sys.exit(Main())
56