Skip to content

Commit

Permalink
Android,Windows: longpath support in tool
Browse files Browse the repository at this point in the history
Update aar_native_libs_zip_creator.py to support
long paths by using junctions.

See bazelbuild#3955

Change-Id: Iafa9ceca9f2a9076f220bd6326c95e5fb8b27f63
PiperOrigin-RevId: 173244903
  • Loading branch information
laszlocsomor authored and dslomov committed Oct 24, 2017
1 parent 6a4247b commit 527ff1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions tools/android/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ py_binary(
"aar_native_libs_zip_creator.py",
],
deps = [
":junction_lib",
"//third_party/py/gflags",
],
)
Expand Down
30 changes: 22 additions & 8 deletions tools/android/aar_native_libs_zip_creator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=g-direct-third-party-import
# Copyright 2016 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,10 +20,12 @@
directory structure of /lib/<cpu>/foo.so.
"""

import os
import re
import sys
import zipfile

from tools.android import junction
from third_party.py import gflags

FLAGS = gflags.FLAGS
Expand All @@ -36,8 +39,7 @@


class UnsupportedArchitectureException(Exception):
"""Exception thrown when an AAR does not support the requested CPU.
"""
"""Exception thrown when an AAR does not support the requested CPU."""
pass


Expand All @@ -55,17 +57,29 @@ def CreateNativeLibsZip(aar, cpu, native_libs_zip):
native_libs_zip.writestr(new_filename, aar.read(lib))


def main():
with zipfile.ZipFile(FLAGS.input_aar, "r") as input_aar:
with zipfile.ZipFile(FLAGS.output_zip, "w") as native_libs_zip:
def Main(input_aar_path, output_zip_path, cpu, input_aar_path_for_error_msg):
with zipfile.ZipFile(input_aar_path, "r") as input_aar:
with zipfile.ZipFile(output_zip_path, "w") as native_libs_zip:
try:
CreateNativeLibsZip(input_aar, FLAGS.cpu, native_libs_zip)
CreateNativeLibsZip(input_aar, cpu, native_libs_zip)
except UnsupportedArchitectureException:
print ("AAR " + FLAGS.input_aar +
" missing native libs for requested architecture: " + FLAGS.cpu)
print("AAR " + input_aar_path_for_error_msg +
" missing native libs for requested architecture: " + cpu)
sys.exit(1)


def main():
if os.name == "nt":
with junction.TempJunction(os.path.dirname(FLAGS.input_aar)) as j_in:
with junction.TempJunction(os.path.dirname(FLAGS.output_zip)) as j_out:
Main(
os.path.join(j_in, os.path.basename(FLAGS.input_aar)),
os.path.join(j_out, os.path.basename(FLAGS.output_zip)), FLAGS.cpu,
FLAGS.input_aar)
else:
Main(FLAGS.input_aar, FLAGS.output_zip, FLAGS.cpu, FLAGS.input_aar)


if __name__ == "__main__":
FLAGS(sys.argv)
main()

0 comments on commit 527ff1f

Please sign in to comment.