From adf844a4fe457d0366fb1fc5c3b09fae596afa25 Mon Sep 17 00:00:00 2001 From: "ahe@google.com" Date: Wed, 10 Apr 2013 15:44:11 +0000 Subject: [PATCH] Make only_in_release_mode read the environment variable directly. BUG=http://dartbug.com/9821 Review URL: https://codereview.chromium.org//13919004 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@21211 260f80e4-7a28-3924-810f-c04153c831b5 --- tools/only_in_release_mode.py | 39 ++++++++++++++--------------------- utils/apidoc/apidoc.gyp | 3 +-- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/tools/only_in_release_mode.py b/tools/only_in_release_mode.py index 39abd89edfd..2713b105d6f 100644 --- a/tools/only_in_release_mode.py +++ b/tools/only_in_release_mode.py @@ -5,40 +5,33 @@ # BSD-style license that can be found in the LICENSE file. """ -Wrapper around a build action that should only be executed in "release" mode. +Wrapper around a build action that should only be executed in release mode. -The following options are accepted: +The mode is defined via an environment varible DART_BUILD_MODE. - --mode=[release,debug] +The arguments to the script are: - --outputs=files... + only_in_release_mode.py files... -- command arguments... -If mode is not 'release', the script will create the files listed in -outputs. If mode is release, the script will execute the remaining -command line arguments as a command. - -Files are a list of quoted filenames separated by space. For example, -'"file1.ext" "file2.ext"' +If mode is not 'release', the script will create the files listed +before --. If mode is release, the script will execute the command +after --. """ -import optparse +import os import subprocess import sys -def BuildOptions(): - result = optparse.OptionParser() - result.add_option('-m', '--mode') - result.add_option('-o', '--outputs') - return result - - def Main(): - (options, arguments) = BuildOptions().parse_args() - if options.mode != 'release': - print >> sys.stderr, 'Not running %s in mode=%s' % (arguments, - options.mode) - for output in options.outputs.strip('"').split('" "'): + # Throws an error if '--' is not in the argument list. + separator_index = sys.argv.index('--') + outputs = sys.argv[1:separator_index] + arguments = sys.argv[separator_index + 1:] + mode = os.getenv('DART_BUILD_MODE', default='release') + if mode != 'release': + print >> sys.stderr, 'Not running %s in mode=%s' % (arguments, mode) + for output in outputs: with open(output, 'w'): # Create an empty file to ensure that we don't rerun this # command unnecessarily. diff --git a/utils/apidoc/apidoc.gyp b/utils/apidoc/apidoc.gyp index 4d351c3693a..f07613d9d43 100644 --- a/utils/apidoc/apidoc.gyp +++ b/utils/apidoc/apidoc.gyp @@ -75,8 +75,7 @@ 'action': [ 'python', '../../tools/only_in_release_mode.py', - '--outputs=<(_outputs)', - '--mode=$(DART_BUILD_MODE)', + '<@(_outputs)', '--', '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)', '--package-root=<(PRODUCT_DIR)/packages/',