From 16e5d8803948a39a13aaccc94185ff5c82e530af Mon Sep 17 00:00:00 2001 From: Paladox none Date: Wed, 28 Mar 2018 13:34:51 +0000 Subject: [PATCH] Fix support for python3 in tools/js/bower2bazel.py Change-Id: I1f222dafcacbdfe8525c95823a2e4ab07493460a (cherry picked from commit 0fb28c14d356030ffc06401d4a3644ee2a09e54d) --- tools/js/bower2bazel.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/js/bower2bazel.py b/tools/js/bower2bazel.py index 1f0cadd157..0415e262d2 100755 --- a/tools/js/bower2bazel.py +++ b/tools/js/bower2bazel.py @@ -98,10 +98,15 @@ def build_bower_json(version_targets, seeds): json.dump(bower_json, f, indent=2) return ret +def decode(input): + try: + return input.decode("utf-8") + except TypeError: + return input def bower_command(args): base = subprocess.check_output(["bazel", "info", "output_base"]).strip() - exp = os.path.join(base, "external", "bower", "*npm_binary.tgz") + exp = os.path.join(decode(base), "external", "bower", "*npm_binary.tgz") fs = sorted(glob.glob(exp)) assert len(fs) == 1, "bower tarball not found or have multiple versions %s" % fs return ["python", os.getcwd() + "/tools/js/run_npm_binary.py", sorted(fs)[0]] + args @@ -117,8 +122,8 @@ def main(args): "bazel", "query", "kind(bower_component_bundle, //polygerrit-ui/...)"]) seed_str = subprocess.check_output([ "bazel", "query", "attr(seed, 1, kind(bower_component, deps(//polygerrit-ui/...)))"]) - targets = [s for s in target_str.split('\n') if s] - seeds = [s for s in seed_str.split('\n') if s] + targets = [s for s in decode(target_str).split('\n') if s] + seeds = [s for s in decode(seed_str).split('\n') if s] prefix = "//lib/js:" non_seeds = [s for s in seeds if not s.startswith(prefix)] assert not non_seeds, non_seeds @@ -203,7 +208,7 @@ def interpret_bower_json(seeds, ws_out, build_out): out = subprocess.check_output(["find", "bower_components/", "-name", ".bower.json"]) data = [] - for f in sorted(out.split('\n')): + for f in sorted(decode(out).split('\n')): if not f: continue pkg = json.load(open(f))