dart-sdk/build/gn_run_binary.py
Joseph Richey 86fe7ca75c Fix build when python=python3
Right now most of the dart SDK's python is compatible with python2
or python3. This change fixes a few of the build scripts to make
that completely true (at least when building the standard build on
Linux). There are only four types of changes:
  - Bare `print` statements now use the `print ()` function
  - `commands.getoutput` becomes `subprocess.check_output` with `shell=True`
  - `xrange` becomes `range`
  - `print >> sys.stderr` becomes `sys.stderr.write`

Starts work on addressing (but does not completely fix):
https://github.com/dart-lang/sdk/issues/28793

See related issue:
https://fuchsia-review.googlesource.com/c/fuchsia/+/272925

This change applys to both the `dev` and `master` branches.

Change-Id: Ibd3eb9b1f57520d2d745f05c2ac430b1d20943da

Closes #36662
https://github.com/dart-lang/sdk/pull/36662

GitOrigin-RevId: beab165294982a7e369daf6d61aea63efcab1b9b
Change-Id: I6d240749a9ba0889b5a45a08f3c4c2c20291f484
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99707
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2019-04-23 07:48:15 +00:00

65 lines
1.9 KiB
Python
Executable file

#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Helper script for GN to run an arbitrary binary. See compiled_action.gni.
Run with:
python gn_run_binary.py <invoker> <binary_name> [args ...]
Where <invoker> is either "compiled_action" or "exec_script". If it is
"compiled_action" the script has a non-zero exit code on a failure. If it is
"exec_script" the script has no output on success and produces output otherwise,
but always has an exit code of 0.
"""
import os
import sys
import subprocess
# Run a command, swallowing the output unless there is an error.
def run_command(command):
try:
subprocess.check_output(command, stderr=subprocess.STDOUT)
return 0
except subprocess.CalledProcessError as e:
return ("Command failed: " + ' '.join(command) + "\n" +
"output: " + e.output)
except OSError as e:
return ("Command failed: " + ' '.join(command) + "\n" +
"output: " + e.strerror)
def main(argv):
error_exit = 0
if argv[1] == "compiled_action":
error_exit = 1
elif argv[1] != "exec_script":
print ("The first argument should be either "
"'compiled_action' or 'exec_script")
return 1
# Unless the path is absolute, this script is designed to run binaries
# produced by the current build. We always prefix it with "./" to avoid
# picking up system versions that might also be on the path.
if os.path.isabs(argv[2]):
path = argv[2]
else:
path = './' + argv[2]
if not os.path.isfile(path):
print ("Binary not found: " + path)
return error_exit
# The rest of the arguments are passed directly to the executable.
args = [path] + argv[3:]
result = run_command(args)
if result != 0:
print (result)
return error_exit
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))