From 6d0453594acbc312e578a4ec4ef68c9ed8d8f9fe Mon Sep 17 00:00:00 2001 From: Ivan Posva Date: Fri, 11 Dec 2015 13:23:12 -0800 Subject: [PATCH] - Prevent running of the dart_bootstrap script by default. - Fix argument handling in Python: argparse does not properly handle booleans. BUG= R=rmacnak@google.com Review URL: https://codereview.chromium.org/1519063004 . --- runtime/observatory/observatory.gypi | 1 + tools/canary.dart | 6 +----- tools/observatory_tool.py | 32 ++++++++++++++++++++++++---- tools/utils.py | 5 +++-- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/runtime/observatory/observatory.gypi b/runtime/observatory/observatory.gypi index 49715242254..5d282ac09b3 100644 --- a/runtime/observatory/observatory.gypi +++ b/runtime/observatory/observatory.gypi @@ -44,6 +44,7 @@ 'target_name': 'build_observatory', 'type': 'none', 'dependencies': [ + 'dart_bootstrap#host', 'fetch_observatory_deps#host', ], 'toolsets': ['host'], diff --git a/tools/canary.dart b/tools/canary.dart index cca1f90cd7b..0df9f70422c 100644 --- a/tools/canary.dart +++ b/tools/canary.dart @@ -2,10 +2,6 @@ // 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. -// Script which exits with code 42. - -import 'dart:io'; - void main() { - exitCode = 42; + print("Success running the canary."); } diff --git a/tools/observatory_tool.py b/tools/observatory_tool.py index 5b1c7c58d6f..1fa4339284c 100755 --- a/tools/observatory_tool.py +++ b/tools/observatory_tool.py @@ -36,11 +36,28 @@ def BuildArguments(): result.add_argument("--pub-executable", help="pub executable", default=None) result.add_argument("--directory", help="observatory root", default=None) result.add_argument("--command", help="[get, build, deploy]", default=None) - result.add_argument("--silent", help="silence all output", default=False) - result.add_argument("--sdk", help="Use prebuilt sdk", default=False) + result.add_argument("--silent", help="silence all output", default=None) + result.add_argument("--sdk", help="Use prebuilt sdk", default=None) return result def ProcessOptions(options, args): + # Fix broken boolean parsing in argparse, where False ends up being True. + if (options.silent is not None) and (options.silent == "True"): + options.silent = True + elif (options.silent is None) or (options.silent == "False"): + options.silent = False + else: + print "--silent expects 'True' or 'False' argument." + return False + + if (options.sdk is not None) and (options.sdk == "True"): + options.sdk = True + elif (options.sdk is None) or (options.sdk == "False"): + options.sdk = False + else: + print "--sdk expects 'True' or 'False' argument." + return False + with open(os.devnull, 'wb') as silent_sink: # Required options. if options.command is None or options.directory is None: @@ -61,7 +78,7 @@ def ProcessOptions(options, args): pass options.pub_executable = None - if options.sdk is not None and utils.CheckedInSdkCheckExecutable(): + if options.sdk and utils.CheckedInSdkCheckExecutable(): # Use the checked in pub executable. options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(), 'bin', @@ -93,7 +110,10 @@ 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 +https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools + +To use the dart_bootstrap binary please update the PubCommand function +in the tools/observatory_tool.py script. """ @@ -111,6 +131,10 @@ def PubCommand(dart_executable, else: DisplayBootstrapWarning() executable = [dart_executable, '--package-root=' + pkg_root, PUB_PATH] + # Prevent the bootstrap Dart executable from running in regular + # development flow. + # REMOVE THE FOLLOWING LINE TO USE the dart_bootstrap binary. + return False return subprocess.call(executable + command, stdout=silent_sink if silent else None, stderr=silent_sink if silent else None) diff --git a/tools/utils.py b/tools/utils.py index a6e7f5181c9..efcb886bfc5 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -634,8 +634,9 @@ def CheckedInSdkCheckExecutable(): canary_script = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'canary.dart') try: - if 42 == subprocess.call([executable, canary_script]): - return True + with open(os.devnull, 'wb') as silent_sink: + if 0 == subprocess.call([executable, canary_script], stdout=silent_sink): + return True except OSError as e: pass return False