Skip to content

Commit

Permalink
[infra] Migrate scripts to python3
Browse files Browse the repository at this point in the history
* Migrate to python3; drop python support.
* Update Windows toolchain support.
* Remove some unused methods.
* Python 2.7 is still needed on Windows.
* Update gsutil to a version that supports python3.

Fixes: #28793

TEST=Manually tested common user journeys.

Change-Id: I663a22b237a548bb82dc2e601e399e3bc3649211
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192182
Reviewed-by: William Hesse <whesse@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
  • Loading branch information
athomas committed Apr 15, 2021
1 parent d84f359 commit b5c63ce
Show file tree
Hide file tree
Showing 127 changed files with 824 additions and 771 deletions.
3 changes: 3 additions & 0 deletions .gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ buildconfig = "//build/config/BUILDCONFIG.gn"
# GN build files are placed when they can not be placed directly
# in the source tree, e.g. for third party source trees.
secondary_source = "//build/secondary/"

# Override the default script executable to always be python3.
script_executable = "python3"
53 changes: 25 additions & 28 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ deps = {

Var("dart_root") + "/third_party/gsutil": {
"packages": [{
"package": "infra/gsutil",
"version": "version:4.34",
"package": "infra/3pp/tools/gsutil",
"version": "version:4.58",
}],
"dep_type": "cipd",
},
Expand Down Expand Up @@ -672,59 +672,56 @@ hooks = [
# Pull Debian sysroot for i386 Linux
'name': 'sysroot_i386',
'pattern': '.',
'action': ['python', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'action': ['python3', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'--arch', 'i386'],
},
{
# Pull Debian sysroot for amd64 Linux
'name': 'sysroot_amd64',
'pattern': '.',
'action': ['python', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'action': ['python3', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'--arch', 'amd64'],
},
{
# Pull Debian sysroot for arm Linux
'name': 'sysroot_amd64',
'pattern': '.',
'action': ['python', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'action': ['python3', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'--arch', 'arm'],
},
{
# Pull Debian jessie sysroot for arm64 Linux
'name': 'sysroot_amd64',
'pattern': '.',
'action': ['python', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'action': ['python3', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'--arch', 'arm64'],
},
{
'name': 'buildtools',
'pattern': '.',
'action': ['python', 'sdk/tools/buildtools/update.py'],
'action': ['python3', 'sdk/tools/buildtools/update.py'],
},
{
# Update the Windows toolchain if necessary.
'name': 'win_toolchain',
'pattern': '.',
'action': ['python', 'sdk/build/vs_toolchain.py', 'update'],
'action': ['python3', 'sdk/build/vs_toolchain.py', 'update'],
'condition': 'checkout_win'
},
{
"name": "7zip",
"pattern": ".",
"action": [
"download_from_google_storage",
"--no_auth",
"--no_resume",
"--bucket",
"dart-dependencies",
"--platform=win32",
"--extract",
"-s",
Var('dart_root') + "/third_party/7zip.tar.gz.sha1",
],
'condition': 'checkout_win'
},
]

hooks_os = {
"win": [
{
"name": "7zip",
"pattern": ".",
"action": [
"download_from_google_storage",
"--no_auth",
"--no_resume",
"--bucket",
"dart-dependencies",
"--platform=win32",
"--extract",
"-s",
Var('dart_root') + "/third_party/7zip.tar.gz.sha1",
],
},
]
}
14 changes: 7 additions & 7 deletions build/config/linux/pkg-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# success. This allows us to "kind of emulate" a Linux build from other
# platforms.
if sys.platform.find("linux") == -1:
print "[[],[],[],[],[]]"
print("[[],[],[],[],[]]")
sys.exit(0)


Expand All @@ -50,7 +50,7 @@ def SetConfigPath(options):
# Compute the library path name based on the architecture.
arch = options.arch
if sysroot and not arch:
print "You must specify an architecture via -a if using a sysroot."
print("You must specify an architecture via -a if using a sysroot.")
sys.exit(1)
if arch == 'x64':
libpath = 'lib64'
Expand Down Expand Up @@ -138,17 +138,17 @@ def RewritePath(path, strip_prefix, sysroot):
[options.pkg_config, "--atleast-version=" + options.atleast_version] +
args,
env=os.environ):
print "true"
print("true")
else:
print "false"
print("false")
sys.exit(0)

if options.libdir:
try:
libdir = subprocess.check_output(
[options.pkg_config, "--variable=libdir"] + args, env=os.environ)
except:
print "Error from pkg-config."
print("Error from pkg-config.")
sys.exit(1)
sys.stdout.write(libdir.strip())
sys.exit(0)
Expand All @@ -163,7 +163,7 @@ def RewritePath(path, strip_prefix, sysroot):
# to happen in practice.
all_flags = flag_string.strip().split(' ')
except:
print "Could not run pkg-config."
print("Could not run pkg-config.")
sys.exit(1)

sysroot = options.sysroot
Expand Down Expand Up @@ -199,4 +199,4 @@ def RewritePath(path, strip_prefix, sysroot):
# Output a GN array, the first one is the cflags, the second are the libs. The
# JSON formatter prints GN compatible lists when everything is a list of
# strings.
print json.dumps([includes, cflags, libs, lib_dirs, ldflags])
print(json.dumps([includes, cflags, libs, lib_dirs, ldflags]))
7 changes: 4 additions & 3 deletions build/config/linux/sysroot_ld_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import sys

if len(sys.argv) != 3:
print "Need two arguments"
print("Need two arguments")
sys.exit(1)

result = subprocess.check_output([sys.argv[1], sys.argv[2]]).strip()
result = subprocess.check_output([sys.argv[1], sys.argv[2]],
universal_newlines=True).strip()

print '"' + result + '"'
print('"' + result + '"')
2 changes: 1 addition & 1 deletion build/config/mac/mac_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
# Copyright (c) 2015 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.
Expand Down
4 changes: 2 additions & 2 deletions build/detect_host_arch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# 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.
Expand Down Expand Up @@ -48,4 +48,4 @@ def DoMain(_):


if __name__ == '__main__':
print DoMain([])
print(DoMain([]))
8 changes: 5 additions & 3 deletions build/gn_run_binary.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# 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 ...]
python3 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
Expand All @@ -21,7 +21,9 @@
# Run a command, swallowing the output unless there is an error.
def run_command(command):
try:
subprocess.check_output(command, stderr=subprocess.STDOUT)
subprocess.check_output(command,
stderr=subprocess.STDOUT,
universal_newlines=True)
return 0
except subprocess.CalledProcessError as e:
return ("Command failed: " + ' '.join(command) + "\n" + "output: " +
Expand Down
16 changes: 7 additions & 9 deletions build/linux/sysroot_scripts/install-sysroot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (c) 2013 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.
Expand All @@ -17,14 +17,12 @@

import hashlib
import json
import platform
import optparse
import os
import re
import shutil
import subprocess
import sys
import urllib2
from urllib.request import urlopen

SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(os.path.dirname(SCRIPT_DIR)))
Expand Down Expand Up @@ -87,7 +85,7 @@ def main(args):
return 0

if not options.arch:
print 'You much specify either --arch or --running-as-hook'
print('You much specify either --arch or --running-as-hook')
return 1
InstallDefaultSysrootForArch(options.arch)

Expand Down Expand Up @@ -134,18 +132,18 @@ def InstallSysroot(target_platform, target_arch):
if s.read() == url:
return

print 'Installing Debian %s %s root image: %s' % \
(target_platform, target_arch, sysroot)
print('Installing Debian %s %s root image: %s' % \
(target_platform, target_arch, sysroot))
if os.path.isdir(sysroot):
shutil.rmtree(sysroot)
os.mkdir(sysroot)
tarball = os.path.join(sysroot, tarball_filename)
print 'Downloading %s' % url
print('Downloading %s' % url)
sys.stdout.flush()
sys.stderr.flush()
for _ in range(3):
try:
response = urllib2.urlopen(url)
response = urlopen(url)
with open(tarball, "wb") as f:
f.write(response.read())
break
Expand Down
2 changes: 1 addition & 1 deletion build/mac/change_mach_o_flags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (c) 2011 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.
Expand Down
44 changes: 22 additions & 22 deletions build/mac/find_sdk.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (c) 2012 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.
"""Prints the lowest locally available SDK version greater than or equal to a
given minimum sdk version to standard output.
Usage:
python find_sdk.py 10.6 # Ignores SDKs < 10.6
python3 find_sdk.py 10.6 # Ignores SDKs < 10.6
"""

import os
Expand Down Expand Up @@ -54,7 +54,7 @@ def CreateSymlinkForSDKAt(src, dst):

def parse_version(version_str):
"""'10.6' => [10, 6]"""
return map(int, re.findall(r'(\d+)', version_str))
return list(map(int, re.findall(r'(\d+)', version_str)))


def main():
Expand Down Expand Up @@ -90,11 +90,12 @@ def main():

job = subprocess.Popen(['xcode-select', '-print-path'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stderr=subprocess.STDOUT,
universal_newlines=True)
out, err = job.communicate()
if job.returncode != 0:
print >> sys.stderr, out
print >> sys.stderr, err
print(out, file=sys.stderr)
print(err, file=sys.stderr)
raise Exception((
'Error %d running xcode-select, you might have to run '
'|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| '
Expand All @@ -119,32 +120,31 @@ def main():
best_sdk = sorted(sdks, key=parse_version)[0]

if options.verify and best_sdk != min_sdk_version and not options.sdk_path:
print >> sys.stderr, ''
print >> sys.stderr, ' vvvvvvv'
print >> sys.stderr, ''
print >> sys.stderr, \
'This build requires the %s SDK, but it was not found on your system.' \
% min_sdk_version
print >> sys.stderr, \
'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.'
print >> sys.stderr, ''
print >> sys.stderr, ' ^^^^^^^'
print >> sys.stderr, ''
print('''
vvvvvvv
This build requires the %s SDK, but it was not found on your system.
Either install it, or explicitly set mac_sdk in your GYP_DEFINES.
^^^^^^^'
''' % min_sdk_version,
file=sys.stderr)
return min_sdk_version

if options.print_sdk_path:
sdk_path = subprocess.check_output(
['xcodebuild', '-version', '-sdk', 'macosx' + best_sdk,
'Path']).strip()
['xcodebuild', '-version', '-sdk', 'macosx' + best_sdk, 'Path'],
universal_newlines=True).strip()
if options.create_symlink_at:
print CreateSymlinkForSDKAt(sdk_path, options.create_symlink_at)
print(CreateSymlinkForSDKAt(sdk_path, options.create_symlink_at))
else:
print sdk_path
print(sdk_path)

return best_sdk


if __name__ == '__main__':
if sys.platform != 'darwin':
raise Exception("This script only runs on Mac")
print main()
print(main())
2 changes: 1 addition & 1 deletion build/mac/strip_save_dsym
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
Loading

0 comments on commit b5c63ce

Please sign in to comment.