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