aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/zip
diff options
context:
space:
mode:
authorGravatar Adam Michael <ajmichael@google.com>2016-10-13 23:09:25 +0000
committerGravatar Yue Gan <yueg@google.com>2016-10-14 09:33:19 +0000
commit78c19807d2cbb308b830022dcdcc8b03f19f90a9 (patch)
tree1dea0ad109a5195415b68756f130a5869007c51c /tools/zip
parentf61277fe5d89de793037c739d79b2a0005eaaa76 (diff)
Refactor AarImportRule into a base rule.
Also moves AAR-specific tools from tools/zip into tools/android and renames embedded_jar_extractor to aar_embedded_jars_extractor because in a future change it will extract classes.jar and libs/*.jar. -- MOS_MIGRATED_REVID=136099324
Diffstat (limited to 'tools/zip')
-rw-r--r--tools/zip/BUILD25
-rw-r--r--tools/zip/BUILD.tools12
-rw-r--r--tools/zip/embedded_jar_extractor.py53
-rw-r--r--tools/zip/embedded_jar_extractor_test.py50
-rwxr-xr-xtools/zip/zip_manifest_creator.sh48
-rwxr-xr-xtools/zip/zip_manifest_creator_test.sh38
6 files changed, 0 insertions, 226 deletions
diff --git a/tools/zip/BUILD b/tools/zip/BUILD
index 4ccf9f7273..4c5ffe97cb 100644
--- a/tools/zip/BUILD
+++ b/tools/zip/BUILD
@@ -4,28 +4,3 @@ filegroup(
name = "srcs",
srcs = glob(["**"]),
)
-
-sh_binary(
- name = "zip_manifest_creator",
- srcs = ["zip_manifest_creator.sh"],
- data = ["//third_party/ijar:zipper"],
-)
-
-sh_test(
- name = "zip_manifest_creator_test",
- size = "small",
- srcs = ["zip_manifest_creator_test.sh"],
- data = [":zip_manifest_creator"],
-)
-
-py_binary(
- name = "embedded_jar_extractor",
- srcs = ["embedded_jar_extractor.py"],
- deps = ["//third_party/py/gflags"],
-)
-
-py_test(
- name = "embedded_jar_extractor_test",
- srcs = ["embedded_jar_extractor_test.py"],
- deps = [":embedded_jar_extractor"],
-)
diff --git a/tools/zip/BUILD.tools b/tools/zip/BUILD.tools
index 542ddce946..06bc25e4e5 100644
--- a/tools/zip/BUILD.tools
+++ b/tools/zip/BUILD.tools
@@ -4,15 +4,3 @@ filegroup(
name = "zipper",
srcs = glob(["zipper/*"]),
)
-
-sh_binary(
- name = "zip_manifest_creator",
- srcs = ["zip_manifest_creator.sh"],
- data = [":zipper"],
-)
-
-py_binary(
- name = "embedded_jar_extractor",
- srcs = ["embedded_jar_extractor.py"],
- deps = ["//third_party/py/gflags"],
-)
diff --git a/tools/zip/embedded_jar_extractor.py b/tools/zip/embedded_jar_extractor.py
deleted file mode 100644
index 1111b2993e..0000000000
--- a/tools/zip/embedded_jar_extractor.py
+++ /dev/null
@@ -1,53 +0,0 @@
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""A tool for extracting a jar file from an archive and failing gracefully.
-
-If the jar file is present within the archive, it is extracted into the output
-directory. If not, an empty jar is created in the output directory.
-"""
-
-import os
-import sys
-import zipfile
-
-from third_party.py import gflags
-
-FLAGS = gflags.FLAGS
-
-gflags.DEFINE_string("input_archive", None, "Input archive")
-gflags.MarkFlagAsRequired("input_archive")
-gflags.DEFINE_string("filename", None, "Filename of JAR to extract")
-gflags.MarkFlagAsRequired("filename")
-gflags.DEFINE_string("output_dir", None, "Output directory")
-gflags.MarkFlagAsRequired("output_dir")
-
-
-def ExtractEmbeddedJar(input_archive, filename, output_dir):
- with zipfile.ZipFile(input_archive, "r") as archive:
- if filename in archive.namelist():
- archive.extract(filename, output_dir)
- else:
- with zipfile.ZipFile(os.path.join(output_dir, filename), "w") as jar:
- # All jar files must contain META-INF/MANIFEST.MF.
- jar.writestr("META-INF/MANIFEST.MF", ("Manifest-Version: 1.0\n"
- "Created-By: Bazel\n"))
-
-
-def main():
- ExtractEmbeddedJar(FLAGS.input_archive, FLAGS.filename, FLAGS.output_dir)
-
-if __name__ == "__main__":
- FLAGS(sys.argv)
- main()
diff --git a/tools/zip/embedded_jar_extractor_test.py b/tools/zip/embedded_jar_extractor_test.py
deleted file mode 100644
index 568e0b3366..0000000000
--- a/tools/zip/embedded_jar_extractor_test.py
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Tests for embedded_jar_extractor."""
-
-import filecmp
-import os
-import unittest
-import zipfile
-
-from tools.zip import embedded_jar_extractor
-
-
-class EmbeddedJarExtractorTest(unittest.TestCase):
- """Unit tests for embedded_jar_extractor.py."""
-
- def testPassingJarFile(self):
- bjar = zipfile.ZipFile("b.jar", "w")
- bjar.close()
- azip = zipfile.ZipFile("a.zip", "w")
- azip.write("b.jar")
- azip.close()
- if not os.path.exists("output"):
- os.mkdir("output")
- embedded_jar_extractor.ExtractEmbeddedJar("a.zip", "b.jar", "output")
- self.assertTrue(filecmp.cmp("b.jar", "output/b.jar"))
-
- def testMissingJarFile(self):
- azip = zipfile.ZipFile("a.zip", "w")
- azip.close()
- if not os.path.exists("output"):
- os.mkdir("output")
- embedded_jar_extractor.ExtractEmbeddedJar("a.zip", "b.jar", "output")
- bjar = zipfile.ZipFile("output/b.jar", "r")
- self.assertEqual(["META-INF/MANIFEST.MF"], bjar.namelist())
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/tools/zip/zip_manifest_creator.sh b/tools/zip/zip_manifest_creator.sh
deleted file mode 100755
index 2ab6543402..0000000000
--- a/tools/zip/zip_manifest_creator.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/bash
-#
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This script takes in a regular expression and a zip file and writes a file
-# containing the names of all files in the zip file that match the regular
-# expression with one per line. Names of directories are not included.
-
-if [ "$#" -ne 3 ]; then
- echo "Usage: zip_manifest_creator.sh <regexp> <input zip> <output manifest>"
- exit 1
-fi
-
-REGEX="$1"
-INPUT_ZIP="$2"
-OUTPUT_MANIFEST="$3"
-
-RUNFILES=${RUNFILES:-$0.runfiles}
-
-# For the sh_binary in BUILD.tools, zipper is here.
-ZIPPER=$RUNFILES/bazel_tools/tools/zip/zipper/zipper
-if [ ! -x $ZIPPER ]; then
- # For the sh_test in BUILD.oss, zipper is here.
- ZIPPER=$RUNFILES/third_party/ijar/zipper
-fi
-if [ ! -x $ZIPPER ]; then
- echo "zip_manifest_creator could not find zipper executable"
- exit 1
-fi
-
-$ZIPPER v "$INPUT_ZIP" \
- | cut -d ' ' -f3 \
- | grep -v \/$ \
- | grep -x "$REGEX" \
- > "$OUTPUT_MANIFEST"
-exit 0
diff --git a/tools/zip/zip_manifest_creator_test.sh b/tools/zip/zip_manifest_creator_test.sh
deleted file mode 100755
index 3c3d09b42b..0000000000
--- a/tools/zip/zip_manifest_creator_test.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/bash
-#
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-export RUNFILES=${RUNFILES:-$($(cd $(dirname ${BASH_SOURCE[0]})); pwd)}
-CUT=$RUNFILES/tools/zip/zip_manifest_creator
-
-touch classes.jar
-touch AndroidManifest.xml
-mkdir -p res/values
-touch res/values/bar.xml
-touch res/values/baz.xml
-
-zip -q foo.zip classes.jar
-zip -q foo.zip AndroidManifest.xml
-zip -q foo.zip res/values/bar.xml
-zip -q foo.zip res/values/baz.xml
-
-$CUT 'res/.*' foo.zip actual.manifest
-
-cat > expected.manifest <<EOT
-res/values/bar.xml
-res/values/baz.xml
-EOT
-
-cmp expected.manifest actual.manifest