| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 import glob |
| 8 import optparse |
| 9 import os.path |
| 10 import re |
| 11 import subprocess |
| 12 import sys |
| 13 import utils |
| 14 |
| 15 # FIXME: integrate this helper script into the build instead of hardcoding |
| 16 # these paths. |
| 17 RESOURCE_AAR_PATTERN = 'content_shell_apk/resource_aar/*.aar' |
| 18 CONTENT_SHELL_APK_AAR = 'content_shell_apk/content_shell_apk.aar' |
| 19 |
| 20 SRC_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 21 DART_DIR = os.path.join(SRC_PATH, 'dart') |
| 22 CHROME_VERSION_PATH = os.path.join(SRC_PATH, 'chrome', 'VERSION') |
| 23 |
| 24 def main(): |
| 25 parser = optparse.OptionParser() |
| 26 parser.add_option('--mode', dest='mode', |
| 27 action='store', type='string', |
| 28 help='Build mode (Debug or Release)') |
| 29 parser.add_option('--repo', action='store', type='string', |
| 30 help='Local Maven repository (defaults to ~/.m2)') |
| 31 (options, args) = parser.parse_args() |
| 32 mode = options.mode |
| 33 version = GetVersion() |
| 34 if not (mode in ['debug', 'release']): |
| 35 raise Exception('Invalid build mode') |
| 36 |
| 37 mode = 'Debug' if mode == 'debug' else 'Release' |
| 38 |
| 39 build_root = os.path.join('out', mode) |
| 40 |
| 41 aars = glob.glob(os.path.join(build_root, RESOURCE_AAR_PATTERN)) |
| 42 aars.append(os.path.join(build_root, CONTENT_SHELL_APK_AAR)) |
| 43 |
| 44 flags = [ |
| 45 '-DgroupId=org.dartlang', |
| 46 '-Dversion=%s' % version, |
| 47 '-Dpackaging=aar' |
| 48 ] |
| 49 if options.repo: |
| 50 flags.append('-DlocalRepositoryPath=%s' % options.repo) |
| 51 |
| 52 for aar_file in aars: |
| 53 artifact_id = os.path.splitext(os.path.basename(aar_file))[0] |
| 54 cmd = [ |
| 55 'mvn', |
| 56 'install:install-file', |
| 57 '-Dfile=%s' % aar_file, |
| 58 '-DartifactId=%s' % artifact_id, |
| 59 ] |
| 60 cmd.extend(flags) |
| 61 utils.runCommand(cmd) |
| 62 |
| 63 def GetVersion(): |
| 64 version = GetChromeVersion() |
| 65 return '%d.%d.%d-%05d-%06d' % ( |
| 66 version[0], |
| 67 version[1], |
| 68 version[2], |
| 69 version[3], |
| 70 GetDartSVNRevision()) |
| 71 |
| 72 def GetChromeVersion(): |
| 73 version = [] |
| 74 for line in file(CHROME_VERSION_PATH).readlines(): |
| 75 version.append(int(line.strip().split('=')[1])) |
| 76 |
| 77 return version |
| 78 |
| 79 def GetDartSVNRevision(): |
| 80 # When building from tarball use tools/SVN_REVISION |
| 81 svn_revision_file = os.path.join(DART_DIR, 'tools', 'SVN_REVISION') |
| 82 try: |
| 83 with open(svn_revision_file) as fd: |
| 84 return int(fd.read()) |
| 85 except: |
| 86 pass |
| 87 |
| 88 custom_env = dict(os.environ) |
| 89 custom_env['LC_MESSAGES'] = 'en_GB' |
| 90 p = subprocess.Popen(['svn', 'info'], stdout = subprocess.PIPE, |
| 91 stderr = subprocess.STDOUT, shell = IsWindows(), |
| 92 env = custom_env, |
| 93 cwd = DART_DIR) |
| 94 output, _ = p.communicate() |
| 95 revision = ParseSvnInfoOutput(output) |
| 96 if revision: |
| 97 return int(revision) |
| 98 |
| 99 # Check for revision using git (Note: we can't use git-svn because in a |
| 100 # pure-git checkout, "git-svn anyCommand" just hangs!). We look an arbitrary |
| 101 # number of commits backwards (100) to get past any local commits. |
| 102 p = subprocess.Popen(['git', 'log', '-100'], stdout = subprocess.PIPE, |
| 103 stderr = subprocess.STDOUT, shell=IsWindows(), cwd = DART_DIR) |
| 104 output, _ = p.communicate() |
| 105 revision = ParseGitInfoOutput(output) |
| 106 if revision: |
| 107 return int(revision) |
| 108 |
| 109 # In the rare off-chance that git log -100 doesn't have a svn repo number, |
| 110 # attempt to use "git svn info." |
| 111 p = subprocess.Popen(['git', 'svn', 'info'], stdout = subprocess.PIPE, |
| 112 stderr = subprocess.STDOUT, shell=IsWindows(), cwd = DART_DIR) |
| 113 output, _ = p.communicate() |
| 114 revision = ParseSvnInfoOutput(output) |
| 115 if revision: |
| 116 return int(revision) |
| 117 |
| 118 # Only fail on the buildbot in case of a SVN client version mismatch. |
| 119 user = GetUserName() |
| 120 return '0' |
| 121 |
| 122 def ParseGitInfoOutput(output): |
| 123 """Given a git log, determine the latest corresponding svn revision.""" |
| 124 for line in output.split('\n'): |
| 125 tokens = line.split() |
| 126 if len(tokens) > 0 and tokens[0] == 'git-svn-id:': |
| 127 return tokens[1].split('@')[1] |
| 128 return None |
| 129 |
| 130 def ParseSvnInfoOutput(output): |
| 131 revision_match = re.search('Last Changed Rev: (\d+)', output) |
| 132 if revision_match: |
| 133 return revision_match.group(1) |
| 134 return None |
| 135 |
| 136 def IsWindows(): |
| 137 return (sys.platform=='win32') |
| 138 |
| 139 if __name__ == '__main__': |
| 140 main() |
| OLD | NEW |