blob: 14b5f34012709ff60e3732614a52323b9e3411e5 [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001#!/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')
Stephan Herhut928ab0e2017-07-18 10:53:23 +020017GRADLE_TGZ = os.path.join(GRADLE_DIR, 'gradle.tar.gz')
Rico Windf80f5a22017-06-16 09:15:57 +020018if utils.IsWindows():
Jean-Marie Henaff872e4422017-06-13 10:26:20 +020019 GRADLE = os.path.join(GRADLE_DIR, 'gradle', 'bin', 'gradle.bat')
20else:
21 GRADLE = os.path.join(GRADLE_DIR, 'gradle', 'bin', 'gradle')
Mads Ager418d1ca2017-05-22 09:35:49 +020022
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():
Stephan Herhut928ab0e2017-07-18 10:53:23 +020031 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.
Mads Ager418d1ca2017-05-22 09:35:49 +020033 utils.DownloadFromGoogleCloudStorage(GRADLE_SHA1)
Stephan Herhut928ab0e2017-07-18 10:53:23 +020034 # 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)
Mads Ager418d1ca2017-05-22 09:35:49 +020037 else:
38 print 'gradle.py: Gradle binary present'
39
Rico Winda94f01c2017-06-27 10:32:34 +020040def RunGradle(args, throw_on_failure=True):
Mads Ager418d1ca2017-05-22 09:35:49 +020041 EnsureGradle()
42 cmd = [GRADLE]
43 cmd.extend(args)
44 utils.PrintCmd(cmd)
45 with utils.ChangedWorkingDirectory(utils.REPO_ROOT):
Rico Winda94f01c2017-06-27 10:32:34 +020046 return_value = subprocess.call(cmd)
Tamas Kenezb787bc82017-06-27 11:32:20 +020047 if throw_on_failure and return_value != 0:
Rico Winda94f01c2017-06-27 10:32:34 +020048 raise
49 return return_value
Mads Ager418d1ca2017-05-22 09:35:49 +020050
51def Main():
52 RunGradle(sys.argv[1:])
53
54if __name__ == '__main__':
55 sys.exit(Main())