Fix support for python3 in tools/js/bower2bazel.py

Change-Id: I1f222dafcacbdfe8525c95823a2e4ab07493460a
(cherry picked from commit 0fb28c14d3)
This commit is contained in:
Paladox none 2018-03-28 13:34:51 +00:00
parent 06b41b422d
commit 16e5d88039

View File

@ -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))