blob: 275c270c1435ea707376947718cac417ec979b22 [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')
Mads Ager1d5ae402017-09-22 12:30:56 +020018
19SHADOW_DIR = os.path.join(utils.REPO_ROOT, 'third_party')
20SHADOW_SHA1 = os.path.join(SHADOW_DIR, 'shadow.tar.gz.sha1')
21SHADOW_TGZ = os.path.join(SHADOW_DIR, 'shadow.tar.gz')
22
Rico Windf80f5a22017-06-16 09:15:57 +020023if utils.IsWindows():
Jean-Marie Henaff872e4422017-06-13 10:26:20 +020024 GRADLE = os.path.join(GRADLE_DIR, 'gradle', 'bin', 'gradle.bat')
25else:
26 GRADLE = os.path.join(GRADLE_DIR, 'gradle', 'bin', 'gradle')
Mads Ager418d1ca2017-05-22 09:35:49 +020027
Mads Ager1d5ae402017-09-22 12:30:56 +020028SHADOW = os.path.join(SHADOW_DIR, 'shadow', 'shadow-2.0.1.jar')
29
Mads Ager418d1ca2017-05-22 09:35:49 +020030def PrintCmd(s):
31 if type(s) is list:
32 s = ' '.join(s)
33 print 'Running: %s' % s
34 # I know this will hit os on windows eventually if we don't do this.
35 sys.stdout.flush()
36
37def EnsureGradle():
Stephan Herhut928ab0e2017-07-18 10:53:23 +020038 if not os.path.exists(GRADLE) or os.path.getmtime(GRADLE_TGZ) < os.path.getmtime(GRADLE_SHA1):
39 # Bootstrap or update gradle, everything else is controlled using gradle.
Mads Ager418d1ca2017-05-22 09:35:49 +020040 utils.DownloadFromGoogleCloudStorage(GRADLE_SHA1)
Stephan Herhut928ab0e2017-07-18 10:53:23 +020041 # Update the mtime of the tar file to make sure we do not run again unless
42 # there is an update.
43 os.utime(GRADLE_TGZ, None)
Mads Ager418d1ca2017-05-22 09:35:49 +020044 else:
45 print 'gradle.py: Gradle binary present'
46
Mads Ager1d5ae402017-09-22 12:30:56 +020047def EnsureShadow():
48 if not os.path.exists(SHADOW) or os.path.getmtime(SHADOW_TGZ) < os.path.getmtime(SHADOW_SHA1):
49 # Bootstrap or update gradle, everything else is controlled using gradle.
50 utils.DownloadFromGoogleCloudStorage(SHADOW_SHA1)
51 # Update the mtime of the tar file to make sure we do not run again unless
52 # there is an update.
53 os.utime(SHADOW_TGZ, None)
54 else:
55 print 'gradle.py: Shadow library present'
56
Rico Winda94f01c2017-06-27 10:32:34 +020057def RunGradle(args, throw_on_failure=True):
Mads Ager418d1ca2017-05-22 09:35:49 +020058 EnsureGradle()
Mads Ager1d5ae402017-09-22 12:30:56 +020059 EnsureShadow()
Mads Ager418d1ca2017-05-22 09:35:49 +020060 cmd = [GRADLE]
61 cmd.extend(args)
62 utils.PrintCmd(cmd)
63 with utils.ChangedWorkingDirectory(utils.REPO_ROOT):
Rico Winda94f01c2017-06-27 10:32:34 +020064 return_value = subprocess.call(cmd)
Tamas Kenezb787bc82017-06-27 11:32:20 +020065 if throw_on_failure and return_value != 0:
Rico Winda94f01c2017-06-27 10:32:34 +020066 raise
67 return return_value
Mads Ager418d1ca2017-05-22 09:35:49 +020068
69def Main():
70 RunGradle(sys.argv[1:])
71
72if __name__ == '__main__':
73 sys.exit(Main())