diff options
author | laszlocsomor <laszlocsomor@google.com> | 2018-02-27 09:42:51 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-27 09:44:49 -0800 |
commit | fc98b44b6181fa4c3efd8613d887970629468d74 (patch) | |
tree | b47cd438e364711ad93d1c3f617b99dee4b70f5b | |
parent | 94cf29c120539967b105acc75bdce070e43aa778 (diff) |
android,windows: bugfix in aar_resources_extractor
Use the path that contains a temporary junction in
the scope of the `with` statement that manages the
lifetime of the temp junction.
This allows compiling
//examples/android/java/bazel:hello_world again.
PiperOrigin-RevId: 187188442
-rw-r--r-- | tools/android/aar_resources_extractor.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tools/android/aar_resources_extractor.py b/tools/android/aar_resources_extractor.py index 5ade3e7be4..b4c85774d2 100644 --- a/tools/android/aar_resources_extractor.py +++ b/tools/android/aar_resources_extractor.py @@ -70,15 +70,21 @@ def ExtractAssets(aar, output_assets_dir): def WriteFileWithJunctions(filename, content): """Writes file including creating any junctions or directories necessary.""" + def _WriteFile(filename): + with open(filename, "wb") as openfile: + openfile.write(content) + if os.name == "nt": # Create a junction to the parent directory, because its path might be too # long. Creating the junction also creates all parent directories. with junction.TempJunction(os.path.dirname(filename)) as junc: filename = os.path.join(junc, os.path.basename(filename)) + # Write the file within scope of the TempJunction, otherwise the path in + # `filename` would no longer be valid. + _WriteFile(filename) else: os.makedirs(os.path.dirname(filename)) - with open(filename, "wb") as openfile: - openfile.write(content) + _WriteFile(filename) def ExtractOneFile(aar, name, abs_output_dir): |