dart-sdk/tools/generate_buildfiles.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

105 lines
2.2 KiB
Python
Executable file

#!/usr/bin/env python
# Copyright 2016 The Dart project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import os
import subprocess
import sys
import utils
HOST_OS = utils.GuessOS()
SCRIPT_DIR = os.path.dirname(sys.argv[0])
DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
DART_DISABLE_BUILDFILES = "DART_DISABLE_BUILDFILES"
def DisableBuildfiles():
return DART_DISABLE_BUILDFILES in os.environ
def Execute(args):
process = subprocess.Popen(args, cwd=DART_ROOT)
process.wait()
return process.returncode
def RunAndroidGn(options):
if not HOST_OS in ['linux', 'macos']:
return 0
gn_command = [
'python',
os.path.join(DART_ROOT, 'tools', 'gn.py'),
'-m', 'all',
'-a', 'arm,arm64',
'--os', 'android',
]
if options.verbose:
gn_command.append('-v')
print (' '.join(gn_command))
return Execute(gn_command)
def RunCrossGn(options):
if HOST_OS != 'linux':
return 0
gn_command = [
'python',
os.path.join(DART_ROOT, 'tools', 'gn.py'),
'-m', 'all',
'-a', 'arm,armsimdbc,arm64,armsimdbc64',
]
if options.verbose:
gn_command.append('-v')
print (' '.join(gn_command))
return Execute(gn_command)
def RunHostGn(options):
gn_command = [
'python',
os.path.join(DART_ROOT, 'tools', 'gn.py'),
'-m', 'all',
'-a', 'all',
]
if options.verbose:
gn_command.append('-v')
print (' '.join(gn_command))
return Execute(gn_command)
def RunGn(options):
status = RunHostGn(options)
if status != 0:
return status
status = RunCrossGn(options)
if status != 0:
return status
return RunAndroidGn(options)
def ParseArgs(args):
args = args[1:]
parser = argparse.ArgumentParser(
description="A script to generate Dart's build files.")
parser.add_argument("-v", "--verbose",
help='Verbose output.',
default=False,
action="store_true")
return parser.parse_args(args)
def main(argv):
# Check the environment and become a no-op if directed.
if DisableBuildfiles():
return 0
options = ParseArgs(argv)
RunGn(options)
if __name__ == '__main__':
sys.exit(main(sys.argv))