2013-04-08 12:43:25 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013, 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.
|
|
|
|
|
|
|
|
"""
|
2013-04-10 15:44:11 +00:00
|
|
|
Wrapper around a build action that should only be executed in release mode.
|
2013-04-08 12:43:25 +00:00
|
|
|
|
2014-07-25 11:47:59 +00:00
|
|
|
The mode is defined via an environment variable DART_BUILD_MODE.
|
2013-04-08 12:43:25 +00:00
|
|
|
|
2013-04-10 15:44:11 +00:00
|
|
|
The arguments to the script are:
|
2013-04-08 12:43:25 +00:00
|
|
|
|
2013-04-10 15:44:11 +00:00
|
|
|
only_in_release_mode.py files... -- command arguments...
|
2013-04-08 12:43:25 +00:00
|
|
|
|
2013-04-10 15:44:11 +00:00
|
|
|
If mode is not 'release', the script will create the files listed
|
|
|
|
before --. If mode is release, the script will execute the command
|
|
|
|
after --.
|
2013-04-08 12:43:25 +00:00
|
|
|
"""
|
|
|
|
|
2013-04-10 15:44:11 +00:00
|
|
|
import os
|
2013-04-08 12:43:25 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def Main():
|
2013-04-10 15:44:11 +00:00
|
|
|
# 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:]
|
2014-05-15 14:09:02 +00:00
|
|
|
arguments[0] = os.path.normpath(arguments[0])
|
2014-07-25 11:47:59 +00:00
|
|
|
mode = os.getenv('DART_BUILD_MODE', 'release')
|
2013-04-10 15:44:11 +00:00
|
|
|
if mode != 'release':
|
|
|
|
print >> sys.stderr, 'Not running %s in mode=%s' % (arguments, mode)
|
|
|
|
for output in outputs:
|
2013-04-08 12:43:25 +00:00
|
|
|
with open(output, 'w'):
|
|
|
|
# Create an empty file to ensure that we don't rerun this
|
|
|
|
# command unnecessarily.
|
|
|
|
pass
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
subprocess.check_call(arguments)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
return e.returncode
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(Main())
|