Observatory build should try backup method if the SDK doesn't work.

Fix up SDK for mips and arm processors on demand.

BUG=
R=iposva@google.com, johnmccutchan@google.com

Review URL: https://codereview.chromium.org//1343103002 .
This commit is contained in:
William Hesse 2015-09-16 13:13:32 +02:00
parent 1d343e5a7b
commit 9aeb907f9d
4 changed files with 104 additions and 180 deletions

View file

@ -77,11 +77,6 @@ def BuildOptions():
help='Name of the devenv.com/msbuild executable on Windows (varies for '
'different versions of Visual Studio)',
default=vs_executable)
result.add_option("--use-bootstrap-for-observatory",
help='Use a stripped down Dart binary built on the host machine '
'for building Observatory. Necessary on Linux machines which have '
'libc incompatibilities with the prebuilt Dart binaries.',
default=False, action="store_true")
return result
@ -391,8 +386,6 @@ def BuildOneConfig(options, target, target_os, mode, arch, override_tools):
global filter_xcodebuild_output
start_time = time.time()
os.environ['DART_BUILD_MODE'] = mode
if options.use_bootstrap_for_observatory != False:
os.environ['DART_USE_BOOTSTRAP_BIN'] = '1'
build_config = utils.GetBuildConf(mode, arch, target_os)
if HOST_OS == 'macos':
filter_xcodebuild_output = True

View file

@ -14,7 +14,8 @@ import utils
SCRIPT_DIR = os.path.dirname(sys.argv[0])
DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
RUN_PUB = os.path.join(DART_ROOT, 'tools/run_pub.py')
PUB_PATH = os.path.join(DART_ROOT, 'third_party', 'pkg',
'pub', 'bin', 'pub.dart')
IGNORE_PATTERNS = shutil.ignore_patterns(
'*.map',
'*.concat.js',
@ -26,7 +27,7 @@ IGNORE_PATTERNS = shutil.ignore_patterns(
'*.log',
'*~')
usage = """obs_tool.py [options]"""
usage = """observatory_tool.py [options]"""
def BuildArguments():
result = argparse.ArgumentParser(usage=usage)
@ -41,64 +42,69 @@ def BuildArguments():
def ProcessOptions(options, args):
# Required options.
if (options.command == None) or (options.directory == None):
if options.command is None or options.directory is None:
return False
# If we have a pub executable, we are running from the dart-sdk.
if (options.pub_executable != None):
return True
if (options.sdk != None):
# Use the checked in pub executable by default.
options.pub_executable = utils.CheckedInPubPath()
return True
# Otherwise, we need a dart executable and a package root.
return ((options.package_root != None) and
(options.dart_executable != None))
# If we have a working pub executable, try and use that.
# TODO(whesse): Drop the pub-executable option if it isn't used.
if options.pub_executable is not None:
try:
if 0 == subprocess.call([options.pub_executable, '--version']):
return True
except OSError as e:
pass
options.pub_executable = None
if options.sdk is not None and utils.CheckedInSdkCheckExecutable():
# Use the checked in pub executable.
options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(),
'bin',
'snapshots',
'pub.dart.snapshot');
try:
if 0 == subprocess.call([utils.CheckedInSdkExecutable(),
options.pub_snapshot,
'--version']):
return True
except OSError as e:
pass
options.pub_snapshot = None
# We need a dart executable and a package root.
return (options.package_root is not None and
options.dart_executable is not None)
def ChangeDirectory(directory):
os.chdir(directory);
def PubGet(dart_executable, pub_executable, pkg_root, silent):
# Always remove pubspec.lock before running 'pub get'.
try:
os.remove('pubspec.lock');
except OSError as e:
pass
with open(os.devnull, 'wb') as silent_sink:
if (pub_executable != None):
return subprocess.call([pub_executable,
'get',
'--offline'],
stdout=silent_sink if silent else None,
stderr=silent_sink if silent else None)
else:
return subprocess.call(['python',
RUN_PUB,
'--package-root=' + pkg_root,
'--dart-executable=' + dart_executable,
'get',
'--offline'],
stdout=silent_sink if silent else None,
stderr=silent_sink if silent else None,)
def DisplayBootstrapWarning():
print """\
def PubBuild(dart_executable, pub_executable, pkg_root, silent, output_dir):
WARNING: Your system cannot run the checked-in Dart SDK. Using the
bootstrap Dart executable will make debug builds slow.
Please see the Wiki for instructions on replacing the checked-in Dart SDK.
https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in--tools
"""
def PubCommand(dart_executable,
pub_executable,
pub_snapshot,
pkg_root,
command,
silent):
with open(os.devnull, 'wb') as silent_sink:
if (pub_executable != None):
return subprocess.call([pub_executable,
'build',
'--output',
output_dir],
stdout=silent_sink if silent else None,
stderr=silent_sink if silent else None,)
if pub_executable is not None:
executable = [pub_executable]
elif pub_snapshot is not None:
executable = [utils.CheckedInSdkExecutable(), pub_snapshot]
else:
return subprocess.call(['python',
RUN_PUB,
'--package-root=' + pkg_root,
'--dart-executable=' + dart_executable,
'build',
'--output',
output_dir],
stdout=silent_sink if silent else None,
stderr=silent_sink if silent else None,)
DisplayBootstrapWarning()
executable = [dart_executable, '--package-root=' + pkg_root, PUB_PATH]
return subprocess.call(executable + command,
stdout=silent_sink if silent else None,
stderr=silent_sink if silent else None)
def Deploy(input_dir, output_dir):
shutil.rmtree(output_dir)
@ -117,16 +123,24 @@ def RewritePubSpec(input_path, output_path, search, replace):
def ExecuteCommand(options, args):
cmd = options.command
if (cmd == 'get'):
return PubGet(options.dart_executable,
options.pub_executable,
options.package_root,
options.silent)
# Always remove pubspec.lock before running 'pub get'.
try:
os.remove('pubspec.lock');
except OSError as e:
pass
return PubCommand(options.dart_executable,
options.pub_executable,
options.pub_snapshot,
options.package_root,
['get', '--offline'],
options.silent)
elif (cmd == 'build'):
return PubBuild(options.dart_executable,
options.pub_executable,
options.package_root,
options.silent,
args[0])
return PubCommand(options.dart_executable,
options.pub_executable,
options.pub_snapshot,
options.package_root,
['build', '--output', args[0]],
options.silent)
elif (cmd == 'deploy'):
Deploy('build', 'deployed')
elif (cmd == 'rewrite'):
@ -142,8 +156,6 @@ def main():
if not ProcessOptions(options, args):
parser.print_help()
return 1
if os.getenv('DART_USE_BOOTSTRAP_BIN') != None:
dart_executable = options.dart_executable
# Calculate absolute paths before changing directory.
if (options.package_root != None):
options.package_root = os.path.abspath(options.package_root)
@ -151,6 +163,8 @@ def main():
options.dart_executable = os.path.abspath(options.dart_executable)
if (options.pub_executable != None):
options.pub_executable = os.path.abspath(options.pub_executable)
if (options.pub_snapshot != None):
options.pub_snapshot = os.path.abspath(options.pub_snapshot)
if len(args) == 1:
args[0] = os.path.abspath(args[0])
# Pub must be run from the project's root directory.
@ -158,4 +172,4 @@ def main():
return ExecuteCommand(options, args)
if __name__ == '__main__':
sys.exit(main());
sys.exit(main());

View file

@ -1,104 +0,0 @@
#!/usr/bin/env python
# Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
# 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.
"""Used to run pub before the SDK has been built"""
import argparse
import os
import platform
import subprocess
import sys
SCRIPT_DIR = os.path.dirname(sys.argv[0])
DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
PUB_PATH = os.path.join(DART_ROOT, 'third_party/pkg/pub/bin/pub.dart')
CANARY_PATH = os.path.join(DART_ROOT, 'tools', 'canary.dart')
usage = """run_pub.py --package-root=<package root>"""
def BuildArguments():
result = argparse.ArgumentParser(usage=usage)
result.add_argument("--package-root", help="package root", default=None)
result.add_argument("--dart-executable", help="dart binary", default=None)
return result
def ProcessOptions(options, args):
return ((options.package_root != None) and
(options.dart_executable != None))
def GetPrebuiltDartExecutablePath(suffix):
osdict = {'Darwin':'macos', 'Linux':'linux', 'Windows':'windows'}
system = platform.system()
executable_name = 'dart'
if system == 'Windows':
executable_name = 'dart.exe'
try:
osname = osdict[system]
except KeyError:
print >>sys.stderr, ('WARNING: platform "%s" not supported') % (system)
return None;
return os.path.join(DART_ROOT,
'tools',
'testing',
'bin',
osname,
executable_name + suffix)
def RunPub(dart, pkg_root, args):
return subprocess.call([dart, '--package-root=' + pkg_root, PUB_PATH] + args)
def TryRunningExecutable(dart_executable, pkg_root):
try:
return subprocess.call([dart_executable,
'--package-root=' + pkg_root,
CANARY_PATH]) == 42
except:
return False;
def DisplayBootstrapWarning():
print """\
WARNING: Your system cannot run the prebuilt Dart executable. Using the
bootstrap Dart executable will make Debug builds long.
Please see Wiki for instructions on replacing prebuilt Dart executable.
https://code.google.com/p/dart/wiki/ReplacingPrebuiltDartExecutable
"""
def FindDartExecutable(fallback_executable, package_root):
# If requested, use the bootstrap binary instead of the prebuilt
# executable.
if os.getenv('DART_USE_BOOTSTRAP_BIN') != None:
return fallback_executable
# Try to find a working prebuilt dart executable.
dart_executable = GetPrebuiltDartExecutablePath('')
if TryRunningExecutable(dart_executable, package_root):
return dart_executable
dart_executable = GetPrebuiltDartExecutablePath('-arm')
if TryRunningExecutable(dart_executable, package_root):
return dart_executable
dart_executable = GetPrebuiltDartExecutablePath('-mips')
if TryRunningExecutable(dart_executable, package_root):
return dart_executable
# If the system cannot execute a prebuilt dart executable, use the bootstrap
# executable instead.
DisplayBootstrapWarning()
return fallback_executable
def main():
# Parse the options.
parser = BuildArguments()
(options, args) = parser.parse_known_args()
if not ProcessOptions(options, args):
parser.print_help()
return 1
dart_executable = FindDartExecutable(options.dart_executable,
options.package_root)
return RunPub(dart_executable, options.package_root, args)
if __name__ == '__main__':
sys.exit(main())

View file

@ -565,6 +565,7 @@ def ExecuteCommand(cmd):
def DartBinary():
# TODO(24311): Replace all uses of this with CheckedInSdk[Fix]Executable().
tools_dir = os.path.dirname(os.path.realpath(__file__))
dart_binary_prefix = os.path.join(tools_dir, 'testing', 'bin')
if IsWindows():
@ -592,6 +593,8 @@ def DartSdkBinary():
return os.path.join(dart_binary_prefix, 'dart')
# The checked-in SDKs are documented at
# https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools
def CheckedInSdkPath():
# We don't use the normal macos, linux, win32 directory names here, instead,
# we use the names that the download_from_google_storage script uses.
@ -609,11 +612,29 @@ def CheckedInSdkPath():
'dart-sdk')
def CheckedInPubPath():
executable_name = 'pub'
if platform.system() == 'Windows':
executable_name = 'pub.bat'
return os.path.join(CheckedInSdkPath(), 'bin', executable_name)
def CheckedInSdkExecutable():
name = 'dart'
if IsWindows():
name = 'dart.exe'
elif GuessOS() == 'linux':
arch = GuessArchitecture()
if arch == 'mips':
name = 'dart-mips'
elif arch == 'arm':
name = 'dart-arm'
return os.path.join(CheckedInSdkPath(), 'bin', name)
def CheckedInSdkCheckExecutable():
executable = CheckedInSdkExecutable()
canary_script = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'canary.dart')
try:
if 42 == subprocess.call([executable, canary_script]):
return True
except OSError as e:
pass
return False
class TempDir(object):