Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 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 | |
| 10 | import os |
| 11 | import subprocess |
| 12 | import sys |
| 13 | import utils |
| 14 | |
| 15 | GRADLE_DIR = os.path.join(utils.REPO_ROOT, 'third_party', 'gradle') |
| 16 | GRADLE_SHA1 = os.path.join(GRADLE_DIR, 'gradle.tar.gz.sha1') |
Jean-Marie Henaff | 872e442 | 2017-06-13 10:26:20 +0200 | [diff] [blame] | 17 | if os.name == 'nt': |
| 18 | GRADLE = os.path.join(GRADLE_DIR, 'gradle', 'bin', 'gradle.bat') |
| 19 | else: |
| 20 | GRADLE = os.path.join(GRADLE_DIR, 'gradle', 'bin', 'gradle') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 21 | |
| 22 | def PrintCmd(s): |
| 23 | if type(s) is list: |
| 24 | s = ' '.join(s) |
| 25 | print 'Running: %s' % s |
| 26 | # I know this will hit os on windows eventually if we don't do this. |
| 27 | sys.stdout.flush() |
| 28 | |
| 29 | def EnsureGradle(): |
| 30 | if not os.path.exists(GRADLE): |
| 31 | # Bootstrap gradle, everything else is controlled using gradle. |
| 32 | utils.DownloadFromGoogleCloudStorage(GRADLE_SHA1) |
| 33 | else: |
| 34 | print 'gradle.py: Gradle binary present' |
| 35 | |
| 36 | def RunGradle(args): |
| 37 | EnsureGradle() |
| 38 | cmd = [GRADLE] |
| 39 | cmd.extend(args) |
| 40 | utils.PrintCmd(cmd) |
| 41 | with utils.ChangedWorkingDirectory(utils.REPO_ROOT): |
| 42 | subprocess.check_call(cmd) |
| 43 | |
| 44 | def Main(): |
| 45 | RunGradle(sys.argv[1:]) |
| 46 | |
| 47 | if __name__ == '__main__': |
| 48 | sys.exit(Main()) |