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
diff --git a/tools/android/aar_resources_extractor.py b/tools/android/aar_resources_extractor.py
index 5ade3e7..b4c8577 100644
--- a/tools/android/aar_resources_extractor.py
+++ b/tools/android/aar_resources_extractor.py
@@ -70,15 +70,21 @@
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):