Bazel: Make build tool chain python 3 compatible

This change establishes Python 3 compatibility for the major part of
Gerrit build tool chain. Only two scripts remain non Python 3
compatible:

* Documentation/replace_macros.py
* tools/bzl/license-map.py

Those scripts explicitly invoked with python2 version.

Test Plan:

a. Python 2.7

* Switch to system where /usr/bin/python points to Python 2.7
* bazel build release
* bazel test //...
* tools/eclipse/project.py

b. Python 3.6

* Switch to system where /usr/bin/python points to Python 3.6
* bazel build release
* bazel test //...
* tools/eclipse/project.py

Pre-requisites for the test plan:

In case bazel action and repository caching is activated on the SUT, the
caches would need to be wiped out, to make sure that the complete build
tool chain was tested. On my system I had to run these commands:

* bazel clean --expunge_async
* rm -rf ~/.gerritcodereview/buck-cache/downloaded-artifacts/*
* rm -rf ~/.gerritcodereview/bazel-cache/cas/*
* rm -rf ~/.gerritcodereview/bazel-cache/repository/*

Bug: Issue 8151
Change-Id: Iece59d0c5149b77a02754b3fed4ce84d5d8085ee
This commit is contained in:
David Ostrovsky
2018-01-14 11:09:43 +01:00
parent aa16cd45cb
commit 0c9e13c11a
6 changed files with 7 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# coding=utf-8
# Copyright (C) 2013 The Android Open Source Project
#

View File

@@ -25,7 +25,7 @@ def license_map(name, targets = [], opts = [], **kwargs):
# post process the XML into our favorite format.
native.genrule(
name = "gen_license_txt_" + name,
cmd = "python $(location //tools/bzl:license-map.py) %s %s > $@" % (" ".join(opts), " ".join(xmls)),
cmd = "python2 $(location //tools/bzl:license-map.py) %s %s > $@" % (" ".join(opts), " ".join(xmls)),
outs = [ name + ".txt" ],
tools = tools,
**kwargs

View File

@@ -277,7 +277,7 @@ def gen_factorypath(ext):
doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8')
try:
ext_location = retrieve_ext_location()
ext_location = retrieve_ext_location().decode("utf-8")
gen_project(args.project_name)
gen_classpath(ext_location)
gen_factorypath(ext_location)

View File

@@ -40,7 +40,7 @@ def hash_bower_component(hash_obj, path):
if f == '.bower.json':
continue
p = os.path.join(root, f)
hash_obj.update(p[len(path)+1:])
hash_obj.update(open(p).read())
hash_obj.update(p[len(path)+1:].encode("utf-8"))
hash_obj.update(open(p, "rb").read())
return hash_obj

View File

@@ -68,7 +68,7 @@ def ignore_deps(info):
deps = info.get('dependencies')
if deps:
with open(os.path.join('.bowerrc'), 'w') as f:
json.dump({'ignoredDependencies': deps.keys()}, f)
json.dump({'ignoredDependencies': list(deps.keys())}, f)
def cache_entry(name, package, version, sha1):

View File

@@ -42,7 +42,7 @@ def is_bundled(tar):
def bundle_dependencies():
with open('package.json') as f:
package = json.load(f)
package['bundledDependencies'] = package['dependencies'].keys()
package['bundledDependencies'] = list(package['dependencies'].keys())
with open('package.json', 'w') as f:
json.dump(package, f)