2012-09-18 07:48:26 +00:00
|
|
|
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:34:19 +00:00
|
|
|
# for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
# BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# This file contains a set of utilities functions used by other Python-based
|
|
|
|
# scripts.
|
|
|
|
|
|
|
|
import commands
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import re
|
2013-07-17 11:40:49 +00:00
|
|
|
import shutil
|
2011-10-05 05:34:19 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2013-07-17 11:40:49 +00:00
|
|
|
import tempfile
|
2011-10-05 05:34:19 +00:00
|
|
|
|
2013-12-06 17:23:49 +00:00
|
|
|
class Version(object):
|
|
|
|
def __init__(self, channel, major, minor, patch, prerelease,
|
|
|
|
prerelease_patch):
|
|
|
|
self.channel = channel
|
|
|
|
self.major = major
|
|
|
|
self.minor = minor
|
|
|
|
self.patch = patch
|
|
|
|
self.prerelease = prerelease
|
|
|
|
self.prerelease_patch = prerelease_patch
|
2011-10-05 05:34:19 +00:00
|
|
|
|
|
|
|
# Try to guess the host operating system.
|
|
|
|
def GuessOS():
|
|
|
|
id = platform.system()
|
|
|
|
if id == "Linux":
|
|
|
|
return "linux"
|
|
|
|
elif id == "Darwin":
|
|
|
|
return "macos"
|
|
|
|
elif id == "Windows" or id == "Microsoft":
|
|
|
|
# On Windows Vista platform.system() can return "Microsoft" with some
|
|
|
|
# versions of Python, see http://bugs.python.org/issue1082 for details.
|
|
|
|
return "win32"
|
|
|
|
elif id == 'FreeBSD':
|
|
|
|
return 'freebsd'
|
|
|
|
elif id == 'OpenBSD':
|
|
|
|
return 'openbsd'
|
|
|
|
elif id == 'SunOS':
|
|
|
|
return 'solaris'
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
# Try to guess the host architecture.
|
|
|
|
def GuessArchitecture():
|
|
|
|
id = platform.machine()
|
|
|
|
if id.startswith('arm'):
|
|
|
|
return 'arm'
|
2014-03-10 11:19:08 +00:00
|
|
|
elif id.startswith('mips'):
|
|
|
|
return 'mips'
|
2011-10-05 05:34:19 +00:00
|
|
|
elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
|
|
|
|
return 'ia32'
|
|
|
|
elif id == 'i86pc':
|
|
|
|
return 'ia32'
|
2011-12-20 18:04:45 +00:00
|
|
|
elif '64' in id:
|
|
|
|
return 'x64'
|
2011-10-05 05:34:19 +00:00
|
|
|
else:
|
2014-03-10 12:18:44 +00:00
|
|
|
guess_os = GuessOS()
|
|
|
|
print "Warning: Guessing architecture %s based on os %s\n" % (id, guess_os)
|
|
|
|
if guess_os == 'win32':
|
|
|
|
return 'ia32'
|
2011-10-05 05:34:19 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
# Try to guess the number of cpus on this machine.
|
|
|
|
def GuessCpus():
|
|
|
|
if os.path.exists("/proc/cpuinfo"):
|
|
|
|
return int(commands.getoutput("grep -E '^processor' /proc/cpuinfo | wc -l"))
|
|
|
|
if os.path.exists("/usr/bin/hostinfo"):
|
|
|
|
return int(commands.getoutput('/usr/bin/hostinfo | grep "processors are logically available." | awk "{ print \$1 }"'))
|
|
|
|
win_cpu_count = os.getenv("NUMBER_OF_PROCESSORS")
|
|
|
|
if win_cpu_count:
|
|
|
|
return int(win_cpu_count)
|
|
|
|
return int(os.getenv("DART_NUMBER_OF_CORES", 2))
|
|
|
|
|
2013-02-20 03:58:19 +00:00
|
|
|
def GetWindowsRegistryKeyName(name):
|
|
|
|
import win32process
|
|
|
|
# Check if python process is 64-bit or if it's 32-bit running in 64-bit OS.
|
|
|
|
# We need to know whether host is 64-bit so that we are looking in right
|
|
|
|
# registry for Visual Studio path.
|
|
|
|
if sys.maxsize > 2**32 or win32process.IsWow64Process():
|
|
|
|
wow6432Node = 'Wow6432Node\\'
|
|
|
|
else:
|
|
|
|
wow6432Node = ''
|
|
|
|
return r'SOFTWARE\%s%s' % (wow6432Node, name)
|
|
|
|
|
|
|
|
# Try to guess Visual Studio location when buiding on Windows.
|
|
|
|
def GuessVisualStudioPath():
|
|
|
|
defaultPath = r"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7" \
|
|
|
|
r"\IDE"
|
|
|
|
defaultExecutable = "devenv.com"
|
|
|
|
|
|
|
|
if not IsWindows():
|
|
|
|
return (defaultPath, defaultExecutable)
|
|
|
|
|
|
|
|
keyNamesAndExecutables = [
|
|
|
|
# Pair for non-Express editions.
|
|
|
|
(GetWindowsRegistryKeyName(r'Microsoft\VisualStudio'), 'devenv.com'),
|
|
|
|
# Pair for 2012 Express edition.
|
|
|
|
(GetWindowsRegistryKeyName(r'Microsoft\VSWinExpress'), 'VSWinExpress.exe'),
|
|
|
|
# Pair for pre-2012 Express editions.
|
|
|
|
(GetWindowsRegistryKeyName(r'Microsoft\VCExpress'), 'VCExpress.exe')]
|
|
|
|
|
|
|
|
bestGuess = (0.0, (defaultPath, defaultExecutable))
|
|
|
|
|
|
|
|
import _winreg
|
|
|
|
for (keyName, executable) in keyNamesAndExecutables:
|
|
|
|
try:
|
|
|
|
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyName)
|
|
|
|
except WindowsError:
|
|
|
|
# Can't find this key - moving on the next one.
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
subkeyCounter = 0
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
subkeyName = _winreg.EnumKey(key, subkeyCounter)
|
|
|
|
subkeyCounter = subkeyCounter + 1
|
|
|
|
except WindowsError:
|
|
|
|
# Reached end of enumeration. Moving on the next key.
|
|
|
|
break
|
|
|
|
|
|
|
|
match = re.match(r'^\d+\.\d+$', subkeyName)
|
|
|
|
if match:
|
|
|
|
with _winreg.OpenKey(key, subkeyName) as subkey:
|
|
|
|
try:
|
|
|
|
(installDir, registrytype) = _winreg.QueryValueEx(subkey,
|
|
|
|
'InstallDir')
|
|
|
|
except WindowsError:
|
|
|
|
# Can't find value under the key - continue to the next key.
|
|
|
|
continue
|
|
|
|
isExpress = executable != 'devenv.com'
|
|
|
|
if not isExpress and subkeyName == '10.0':
|
|
|
|
# Stop search since if we found non-Express VS2010 version
|
|
|
|
# installed, which is preferred version.
|
|
|
|
return (installDir, executable)
|
|
|
|
else:
|
|
|
|
version = float(subkeyName)
|
|
|
|
# We prefer higher version of Visual Studio and given equal
|
|
|
|
# version numbers we prefer non-Express edition.
|
|
|
|
if version > bestGuess[0]:
|
|
|
|
bestGuess = (version, (installDir, executable))
|
|
|
|
finally:
|
|
|
|
_winreg.CloseKey(key)
|
|
|
|
return bestGuess[1]
|
|
|
|
|
2011-10-05 05:34:19 +00:00
|
|
|
|
|
|
|
# Returns true if we're running under Windows.
|
|
|
|
def IsWindows():
|
|
|
|
return GuessOS() == 'win32'
|
|
|
|
|
|
|
|
|
|
|
|
# Reads a text file into an array of strings - one for each
|
|
|
|
# line. Strips comments in the process.
|
|
|
|
def ReadLinesFrom(name):
|
|
|
|
result = []
|
|
|
|
for line in open(name):
|
|
|
|
if '#' in line:
|
|
|
|
line = line[:line.find('#')]
|
|
|
|
line = line.strip()
|
|
|
|
if len(line) == 0:
|
|
|
|
continue
|
|
|
|
result.append(line)
|
|
|
|
return result
|
|
|
|
|
|
|
|
# Filters out all arguments until the next '--' argument
|
|
|
|
# occurs.
|
|
|
|
def ListArgCallback(option, opt_str, value, parser):
|
|
|
|
if value is None:
|
|
|
|
value = []
|
|
|
|
|
|
|
|
for arg in parser.rargs:
|
|
|
|
if arg[:2].startswith('--'):
|
|
|
|
break
|
|
|
|
value.append(arg)
|
|
|
|
|
|
|
|
del parser.rargs[:len(value)]
|
|
|
|
setattr(parser.values, option.dest, value)
|
|
|
|
|
|
|
|
|
|
|
|
# Filters out all argument until the first non '-' or the
|
|
|
|
# '--' argument occurs.
|
|
|
|
def ListDartArgCallback(option, opt_str, value, parser):
|
|
|
|
if value is None:
|
|
|
|
value = []
|
|
|
|
|
|
|
|
for arg in parser.rargs:
|
|
|
|
if arg[:2].startswith('--') or arg[0] != '-':
|
|
|
|
break
|
|
|
|
value.append(arg)
|
|
|
|
|
|
|
|
del parser.rargs[:len(value)]
|
|
|
|
setattr(parser.values, option.dest, value)
|
|
|
|
|
|
|
|
|
|
|
|
# Mapping table between build mode and build configuration.
|
|
|
|
BUILD_MODES = {
|
|
|
|
'debug': 'Debug',
|
|
|
|
'release': 'Release',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Mapping table between OS and build output location.
|
|
|
|
BUILD_ROOT = {
|
2012-09-18 07:48:26 +00:00
|
|
|
'win32': os.path.join('build'),
|
2011-10-05 05:34:19 +00:00
|
|
|
'linux': os.path.join('out'),
|
|
|
|
'freebsd': os.path.join('out'),
|
|
|
|
'macos': os.path.join('xcodebuild'),
|
|
|
|
}
|
|
|
|
|
2014-03-10 12:53:50 +00:00
|
|
|
ARCH_FAMILY = {
|
|
|
|
'ia32': 'ia32',
|
|
|
|
'x64': 'ia32',
|
|
|
|
'arm': 'arm',
|
|
|
|
'mips': 'mips',
|
|
|
|
'simarm': 'ia32',
|
|
|
|
'simmips': 'ia32',
|
2014-04-02 17:39:32 +00:00
|
|
|
'simarm64': 'ia32',
|
2014-03-10 12:53:50 +00:00
|
|
|
}
|
|
|
|
|
2014-03-10 12:18:44 +00:00
|
|
|
ARCH_GUESS = GuessArchitecture()
|
|
|
|
BASE_DIR = os.path.abspath(os.path.join(os.curdir, '..'))
|
|
|
|
DART_DIR = os.path.abspath(os.path.join(__file__, '..', '..'))
|
|
|
|
|
2013-05-17 09:35:32 +00:00
|
|
|
def GetBuildbotGSUtilPath():
|
|
|
|
gsutil = '/b/build/scripts/slave/gsutil'
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
gsutil = 'e:\\\\b\\build\\scripts\\slave\\gsutil'
|
|
|
|
return gsutil
|
|
|
|
|
2011-10-05 05:34:19 +00:00
|
|
|
def GetBuildMode(mode):
|
|
|
|
return BUILD_MODES[mode]
|
|
|
|
|
2014-03-10 12:53:50 +00:00
|
|
|
def GetArchFamily(arch):
|
|
|
|
return ARCH_FAMILY[arch]
|
|
|
|
|
Simplifies standalone VM Android build.
This change also avoids the need to
do another 'gclient runhooks' when switching
between Android and Linux builds, and between
IA32 and ARM Android builds.
gyp does not allow 'libraries' sections inside of
configurations. Therefore, since some architecture
specific paths, libraries, etc. must be specified
on the Android NDK's linker command line, to avoid
re-gyping when switching between Android IA32 and ARM,
this change moves the architecture specific linker
flags to a script, android_link.py.
To avoid re-gyping when swtiching between Linux and
Android, this change creates new configurations
that specify the target OS as well as the the target
architecture, e.g. ReleaseLinuxARM or ReleaseAndroidARM
instead of ReleaseARM.
This change also adds a --toolchain flag to build.py,
and removes obsoleted logic for setting up the Android
build.
R=iposva@google.com
Review URL: https://codereview.chromium.org//105223002
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31340 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-20 17:51:34 +00:00
|
|
|
def GetBuildConf(mode, arch, conf_os=None):
|
|
|
|
if conf_os == 'android':
|
|
|
|
return '%s%s%s' % (GetBuildMode(mode), conf_os.title(), arch.upper())
|
|
|
|
else:
|
2014-03-10 12:00:06 +00:00
|
|
|
# Ask for a cross build if the host and target architectures don't match.
|
|
|
|
host_arch = ARCH_GUESS
|
2014-03-10 12:39:18 +00:00
|
|
|
cross_build = ''
|
2014-03-10 12:53:50 +00:00
|
|
|
if GetArchFamily(host_arch) != GetArchFamily(arch):
|
2014-03-10 12:24:44 +00:00
|
|
|
print "GetBuildConf: Cross-build of %s on %s\n" % (arch, host_arch)
|
2014-03-10 12:00:06 +00:00
|
|
|
cross_build = 'X'
|
|
|
|
return '%s%s%s' % (GetBuildMode(mode), cross_build, arch.upper())
|
2011-10-05 05:34:19 +00:00
|
|
|
|
2012-08-29 20:42:28 +00:00
|
|
|
def GetBuildDir(host_os, target_os):
|
Simplifies standalone VM Android build.
This change also avoids the need to
do another 'gclient runhooks' when switching
between Android and Linux builds, and between
IA32 and ARM Android builds.
gyp does not allow 'libraries' sections inside of
configurations. Therefore, since some architecture
specific paths, libraries, etc. must be specified
on the Android NDK's linker command line, to avoid
re-gyping when switching between Android IA32 and ARM,
this change moves the architecture specific linker
flags to a script, android_link.py.
To avoid re-gyping when swtiching between Linux and
Android, this change creates new configurations
that specify the target OS as well as the the target
architecture, e.g. ReleaseLinuxARM or ReleaseAndroidARM
instead of ReleaseARM.
This change also adds a --toolchain flag to build.py,
and removes obsoleted logic for setting up the Android
build.
R=iposva@google.com
Review URL: https://codereview.chromium.org//105223002
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31340 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-20 17:51:34 +00:00
|
|
|
return BUILD_ROOT[host_os]
|
2012-08-29 20:42:28 +00:00
|
|
|
|
|
|
|
def GetBuildRoot(host_os, mode=None, arch=None, target_os=None):
|
|
|
|
build_root = GetBuildDir(host_os, target_os)
|
2011-10-05 05:34:19 +00:00
|
|
|
if mode:
|
2012-08-29 20:42:28 +00:00
|
|
|
build_root = os.path.join(build_root, GetBuildConf(mode, arch))
|
|
|
|
return build_root
|
2011-10-05 05:34:19 +00:00
|
|
|
|
2011-10-14 11:18:12 +00:00
|
|
|
def GetBaseDir():
|
|
|
|
return BASE_DIR
|
2011-10-05 05:34:19 +00:00
|
|
|
|
2013-10-29 12:20:56 +00:00
|
|
|
def GetShortVersion():
|
2013-12-06 17:23:49 +00:00
|
|
|
version = ReadVersionFile()
|
|
|
|
return ('%s.%s.%s.%s.%s' % (
|
|
|
|
version.major, version.minor, version.patch, version.prerelease,
|
|
|
|
version.prerelease_patch))
|
|
|
|
|
|
|
|
def GetSemanticSDKVersion():
|
|
|
|
version = ReadVersionFile()
|
|
|
|
if not version:
|
2013-12-05 19:05:52 +00:00
|
|
|
return None
|
|
|
|
|
2013-12-06 17:23:49 +00:00
|
|
|
if version.channel == 'be':
|
|
|
|
postfix = '-edge.%s' % GetSVNRevision()
|
|
|
|
elif version.channel == 'dev':
|
|
|
|
postfix = '-dev.%s.%s' % (version.prerelease, version.prerelease_patch)
|
|
|
|
else:
|
|
|
|
assert version.channel == 'stable'
|
|
|
|
postfix = ''
|
|
|
|
|
|
|
|
return '%s.%s.%s%s' % (version.major, version.minor, version.patch, postfix)
|
|
|
|
|
|
|
|
def GetEclipseVersionQualifier():
|
|
|
|
def pad(number, num_digits):
|
|
|
|
number_str = str(number)
|
|
|
|
return '0' * max(0, num_digits - len(number_str)) + number_str
|
|
|
|
|
|
|
|
version = ReadVersionFile()
|
|
|
|
if version.channel == 'be':
|
|
|
|
return 'edge_%s' % pad(GetSVNRevision(), 6)
|
|
|
|
elif version.channel == 'dev':
|
|
|
|
return 'dev_%s_%s' % (pad(version.prerelease, 2),
|
|
|
|
pad(version.prerelease_patch, 2))
|
|
|
|
else:
|
|
|
|
return 'release'
|
2013-12-05 19:05:52 +00:00
|
|
|
|
2013-12-06 17:23:49 +00:00
|
|
|
def GetVersion():
|
|
|
|
return GetSemanticSDKVersion()
|
2013-08-06 10:52:57 +00:00
|
|
|
|
2013-11-25 13:05:30 +00:00
|
|
|
def GetChannel():
|
2013-12-06 17:23:49 +00:00
|
|
|
version = ReadVersionFile()
|
|
|
|
return version.channel
|
2013-11-25 13:05:30 +00:00
|
|
|
|
2013-08-06 10:52:57 +00:00
|
|
|
def GetUserName():
|
|
|
|
key = 'USER'
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
key = 'USERNAME'
|
|
|
|
return os.environ.get(key, '')
|
|
|
|
|
|
|
|
def ReadVersionFile():
|
2013-12-06 17:23:49 +00:00
|
|
|
def match_against(pattern, content):
|
|
|
|
match = re.search(pattern, content, flags=re.MULTILINE)
|
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
return None
|
|
|
|
|
2013-08-06 10:52:57 +00:00
|
|
|
version_file = os.path.join(DART_DIR, 'tools', 'VERSION')
|
|
|
|
try:
|
|
|
|
fd = open(version_file)
|
|
|
|
content = fd.read()
|
|
|
|
fd.close()
|
|
|
|
except:
|
|
|
|
print "Warning: Couldn't read VERSION file (%s)" % version_file
|
|
|
|
return None
|
2013-12-06 17:23:49 +00:00
|
|
|
|
|
|
|
channel = match_against('^CHANNEL ([A-Za-z0-9]+)$', content)
|
|
|
|
major = match_against('^MAJOR (\d+)$', content)
|
|
|
|
minor = match_against('^MINOR (\d+)$', content)
|
|
|
|
patch = match_against('^PATCH (\d+)$', content)
|
|
|
|
prerelease = match_against('^PRERELEASE (\d+)$', content)
|
|
|
|
prerelease_patch = match_against('^PRERELEASE_PATCH (\d+)$', content)
|
|
|
|
|
|
|
|
if channel and major and minor and prerelease and prerelease_patch:
|
|
|
|
return Version(
|
|
|
|
channel, major, minor, patch, prerelease, prerelease_patch)
|
2013-08-06 10:52:57 +00:00
|
|
|
else:
|
|
|
|
print "Warning: VERSION file (%s) has wrong format" % version_file
|
|
|
|
return None
|
2012-10-15 08:21:44 +00:00
|
|
|
|
2012-04-18 21:55:14 +00:00
|
|
|
def GetSVNRevision():
|
2014-02-17 08:09:47 +00:00
|
|
|
# When building from tarball use tools/SVN_REVISION
|
|
|
|
svn_revision_file = os.path.join(DART_DIR, 'tools', 'SVN_REVISION')
|
|
|
|
try:
|
|
|
|
with open(svn_revision_file) as fd:
|
|
|
|
return fd.read()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2013-08-06 10:52:57 +00:00
|
|
|
# FIXME(kustermann): Make this work for newer SVN versions as well (where
|
|
|
|
# we've got only one '.svn' directory)
|
2013-06-20 08:22:25 +00:00
|
|
|
custom_env = dict(os.environ)
|
|
|
|
custom_env['LC_MESSAGES'] = 'en_GB'
|
2012-04-18 21:55:14 +00:00
|
|
|
p = subprocess.Popen(['svn', 'info'], stdout = subprocess.PIPE,
|
2013-06-17 06:42:29 +00:00
|
|
|
stderr = subprocess.STDOUT, shell=IsWindows(),
|
2013-08-06 10:52:57 +00:00
|
|
|
env = custom_env,
|
|
|
|
cwd = DART_DIR)
|
|
|
|
output, _ = p.communicate()
|
2012-08-08 14:55:01 +00:00
|
|
|
revision = ParseSvnInfoOutput(output)
|
|
|
|
if revision:
|
|
|
|
return revision
|
|
|
|
|
|
|
|
# maybe the builder is using git-svn, try that
|
|
|
|
p = subprocess.Popen(['git', 'svn', 'info'], stdout = subprocess.PIPE,
|
2013-08-06 10:52:57 +00:00
|
|
|
stderr = subprocess.STDOUT, shell=IsWindows(), cwd = DART_DIR)
|
|
|
|
output, _ = p.communicate()
|
2012-08-08 14:55:01 +00:00
|
|
|
revision = ParseSvnInfoOutput(output)
|
|
|
|
if revision:
|
|
|
|
return revision
|
|
|
|
|
2013-10-30 04:50:41 +00:00
|
|
|
# Only fail on the buildbot in case of a SVN client version mismatch.
|
|
|
|
user = GetUserName()
|
2013-10-30 04:32:26 +00:00
|
|
|
if user != 'chrome-bot':
|
|
|
|
return '0'
|
|
|
|
|
2012-08-08 14:55:01 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def ParseSvnInfoOutput(output):
|
2013-08-06 10:52:57 +00:00
|
|
|
revision_match = re.search('Last Changed Rev: (\d+)', output)
|
|
|
|
if revision_match:
|
|
|
|
return revision_match.group(1)
|
2012-04-18 21:55:14 +00:00
|
|
|
return None
|
|
|
|
|
2011-10-13 10:14:31 +00:00
|
|
|
def RewritePathSeparator(path, workspace):
|
|
|
|
# Paths in test files are always specified using '/'
|
|
|
|
# as the path separator. Replace with the actual
|
|
|
|
# path separator before use.
|
|
|
|
if ('/' in path):
|
|
|
|
split_path = path.split('/')
|
|
|
|
path = os.sep.join(split_path)
|
|
|
|
path = os.path.join(workspace, path)
|
|
|
|
if not os.path.exists(path):
|
|
|
|
raise Exception(path)
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
2011-10-05 05:34:19 +00:00
|
|
|
def ParseTestOptions(pattern, source, workspace):
|
|
|
|
match = pattern.search(source)
|
|
|
|
if match:
|
2011-10-13 10:14:31 +00:00
|
|
|
return [RewritePathSeparator(o, workspace) for o in match.group(1).split(' ')]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def ParseTestOptionsMultiple(pattern, source, workspace):
|
|
|
|
matches = pattern.findall(source)
|
|
|
|
if matches:
|
|
|
|
result = []
|
|
|
|
for match in matches:
|
|
|
|
if len(match) > 0:
|
|
|
|
result.append(
|
|
|
|
[RewritePathSeparator(o, workspace) for o in match.split(' ')]);
|
2011-10-14 09:31:12 +00:00
|
|
|
else:
|
|
|
|
result.append([])
|
2011-10-13 10:14:31 +00:00
|
|
|
return result
|
2011-10-05 05:34:19 +00:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def ConfigureJava():
|
|
|
|
java_home = '/usr/libexec/java_home'
|
|
|
|
if os.path.exists(java_home):
|
|
|
|
proc = subprocess.Popen([java_home, '-v', '1.6+'],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
(stdout, stderr) = proc.communicate()
|
|
|
|
if proc.wait() != 0:
|
2013-04-24 15:54:20 +00:00
|
|
|
return None
|
2011-10-05 05:34:19 +00:00
|
|
|
new = stdout.strip()
|
|
|
|
current = os.getenv('JAVA_HOME', default=new)
|
|
|
|
if current != new:
|
|
|
|
sys.stderr.write('Please set JAVA_HOME to %s\n' % new)
|
|
|
|
os.putenv('JAVA_HOME', new)
|
|
|
|
|
|
|
|
|
|
|
|
def Daemonize():
|
|
|
|
"""
|
|
|
|
Create a detached background process (daemon). Returns True for
|
|
|
|
the daemon, False for the parent process.
|
|
|
|
See: http://www.faqs.org/faqs/unix-faq/programmer/faq/
|
|
|
|
"1.7 How do I get my program to act like a daemon?"
|
|
|
|
"""
|
|
|
|
if os.fork() > 0:
|
|
|
|
return False
|
|
|
|
os.setsid()
|
|
|
|
if os.fork() > 0:
|
|
|
|
os._exit(0)
|
|
|
|
raise
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2011-10-11 22:44:53 +00:00
|
|
|
def PrintError(str):
|
2011-10-12 14:12:10 +00:00
|
|
|
"""Writes and flushes a string to stderr."""
|
2011-10-11 22:44:53 +00:00
|
|
|
sys.stderr.write(str)
|
|
|
|
sys.stderr.write('\n')
|
|
|
|
|
|
|
|
|
2011-10-12 14:12:10 +00:00
|
|
|
def CheckedUnlink(name):
|
|
|
|
"""Unlink a file without throwing an exception."""
|
|
|
|
try:
|
|
|
|
os.unlink(name)
|
|
|
|
except OSError, e:
|
|
|
|
PrintError("os.unlink() " + str(e))
|
|
|
|
|
|
|
|
|
2011-10-05 05:34:19 +00:00
|
|
|
def Main(argv):
|
|
|
|
print "GuessOS() -> ", GuessOS()
|
|
|
|
print "GuessArchitecture() -> ", GuessArchitecture()
|
|
|
|
print "GuessCpus() -> ", GuessCpus()
|
|
|
|
print "IsWindows() -> ", IsWindows()
|
2013-02-20 03:58:19 +00:00
|
|
|
print "GuessVisualStudioPath() -> ", GuessVisualStudioPath()
|
2011-10-05 05:34:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Error(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ToolError(Exception):
|
|
|
|
"""Deprecated exception, use Error instead."""
|
|
|
|
|
|
|
|
def __init__(self, value):
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return repr(self.value)
|
|
|
|
|
|
|
|
|
2012-03-23 11:52:43 +00:00
|
|
|
def IsCrashExitCode(exit_code):
|
|
|
|
if IsWindows():
|
|
|
|
return 0x80000000 & exit_code
|
|
|
|
else:
|
|
|
|
return exit_code < 0
|
|
|
|
|
|
|
|
|
|
|
|
def DiagnoseExitCode(exit_code, command):
|
|
|
|
if IsCrashExitCode(exit_code):
|
|
|
|
sys.stderr.write('Command: %s\nCRASHED with exit code %d (0x%x)\n' % (
|
|
|
|
' '.join(command), exit_code, exit_code & 0xffffffff))
|
|
|
|
|
|
|
|
|
2012-04-30 12:42:10 +00:00
|
|
|
def Touch(name):
|
|
|
|
with file(name, 'a'):
|
|
|
|
os.utime(name, None)
|
|
|
|
|
|
|
|
|
2013-11-25 12:41:55 +00:00
|
|
|
def ExecuteCommand(cmd):
|
|
|
|
"""Execute a command in a subprocess."""
|
|
|
|
print 'Executing: ' + ' '.join(cmd)
|
|
|
|
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
|
|
shell=IsWindows())
|
|
|
|
output = pipe.communicate()
|
|
|
|
if pipe.returncode != 0:
|
|
|
|
raise Exception('Execution failed: ' + str(output))
|
|
|
|
return (pipe.returncode, output)
|
|
|
|
|
|
|
|
|
2012-10-11 13:07:16 +00:00
|
|
|
def DartBinary():
|
|
|
|
tools_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
dart_binary_prefix = os.path.join(tools_dir, 'testing', 'bin')
|
|
|
|
if IsWindows():
|
|
|
|
return os.path.join(dart_binary_prefix, 'windows', 'dart.exe')
|
|
|
|
else:
|
2013-09-03 12:33:53 +00:00
|
|
|
arch = GuessArchitecture()
|
|
|
|
system = GuessOS()
|
|
|
|
if arch == 'arm':
|
|
|
|
return os.path.join(dart_binary_prefix, system, 'dart-arm')
|
2014-03-10 11:19:08 +00:00
|
|
|
elif arch == 'mips':
|
|
|
|
return os.path.join(dart_binary_prefix, system, 'dart-mips')
|
2013-09-03 12:33:53 +00:00
|
|
|
else:
|
|
|
|
return os.path.join(dart_binary_prefix, system, 'dart')
|
2012-10-11 13:07:16 +00:00
|
|
|
|
|
|
|
|
2013-01-10 22:54:16 +00:00
|
|
|
def DartSdkBinary():
|
|
|
|
tools_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin')
|
|
|
|
return os.path.join(dart_binary_prefix, 'dart')
|
|
|
|
|
2013-07-17 11:40:49 +00:00
|
|
|
class TempDir(object):
|
|
|
|
def __init__(self, prefix=''):
|
|
|
|
self._temp_dir = None
|
|
|
|
self._prefix = prefix
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self._temp_dir = tempfile.mkdtemp(self._prefix)
|
|
|
|
return self._temp_dir
|
|
|
|
|
|
|
|
def __exit__(self, *_):
|
|
|
|
shutil.rmtree(self._temp_dir, ignore_errors=True)
|
|
|
|
|
2013-10-18 14:12:34 +00:00
|
|
|
class ChangedWorkingDirectory(object):
|
|
|
|
def __init__(self, working_directory):
|
|
|
|
self._working_directory = working_directory
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self._old_cwd = os.getcwd()
|
|
|
|
print "Enter directory = ", self._working_directory
|
|
|
|
os.chdir(self._working_directory)
|
|
|
|
|
|
|
|
def __exit__(self, *_):
|
|
|
|
print "Enter directory = ", self._old_cwd
|
|
|
|
os.chdir(self._old_cwd)
|
|
|
|
|
2013-01-10 22:54:16 +00:00
|
|
|
|
2011-10-05 05:34:19 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
|
|
|
Main(sys.argv)
|