Skip to content

Commit

Permalink
Android: Update //third_party/ijar to latest version.
Browse files Browse the repository at this point in the history
It contains fixes for the patches we've made to it, and has also added
support for JDK 11.

Bug: 693079
Change-Id: I0b9c9c0e5ed396ea3994c931513fd6a5af617454
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1882304
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712291}
  • Loading branch information
Andrew Grieve authored and Commit Bot committed Nov 4, 2019
1 parent 6cf8352 commit 6cc1da8
Show file tree
Hide file tree
Showing 20 changed files with 1,305 additions and 628 deletions.
15 changes: 11 additions & 4 deletions build/android/gyp/ijar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
from util import build_utils


# python -c "import zipfile; zipfile.ZipFile('test.jar', 'w')"
# du -b test.jar
_EMPTY_JAR_SIZE = 22


def main():
# The point of this wrapper is to use AtomicOutput so that output timestamps
# are not updated when outputs are unchanged.
ijar_bin, in_jar, out_jar = sys.argv[1:]
with build_utils.AtomicOutput(out_jar) as f:
stderr_filter = (
lambda x: build_utils.FilterLines(x, r'Passing class through'))
build_utils.CheckOutput([ijar_bin, in_jar, f.name],
stderr_filter=stderr_filter)
# ijar fails on empty jars: https://github.com/bazelbuild/bazel/issues/10162
if os.path.getsize(in_jar) <= _EMPTY_JAR_SIZE:
with open(in_jar, 'rb') as in_f:
f.write(in_f.read())
else:
build_utils.CheckOutput([ijar_bin, in_jar, f.name])


if __name__ == '__main__':
Expand Down
2 changes: 0 additions & 2 deletions build/android/gyp/util/build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,6 @@ def MergeZips(output, input_zips, path_transform=None, compress=None):
try:
for in_file in input_zips:
with zipfile.ZipFile(in_file, 'r') as in_zip:
# ijar creates zips with null CRCs.
in_zip._expected_crc = None
for info in in_zip.infolist():
# Ignore directories.
if info.filename[-1] == '/':
Expand Down
123 changes: 118 additions & 5 deletions third_party/ijar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,64 @@ licenses(["notice"]) # Apache 2.0

cc_library(
name = "zip",
srcs = ["zip.cc"],
srcs = [
"zip.cc",
] + select({
"//src:windows": [
"mapped_file_windows.cc",
],
"//conditions:default": [
"mapped_file_unix.cc",
],
}),
hdrs = [
"common.h",
"mapped_file.h",
"zip.h",
],
# TODO(bazel-team): we should replace the -lz flag, it is non-hermetic.
# We should instead use a new_local_repository once the autoconf
# mechanism is ready.
linkopts = ["-lz"],
visibility = [
"//src:__subpackages__",
"//third_party/ijar:__subpackages__",
"//tools/test:__pkg__",
],
deps = [
":platform_utils",
":zlib_client",
] + select({
"//src:windows": [
"//src/main/cpp/util:errors",
"//src/main/cpp/util:filesystem",
"//src/main/cpp/util:logging",
"//src/main/cpp/util:strings",
],
"//conditions:default": [
],
}),
)

cc_library(
name = "zlib_client",
srcs = ["zlib_client.cc"],
hdrs = [
"common.h",
"zlib_client.h",
],
deps = ["//third_party/zlib"],
)

cc_library(
name = "platform_utils",
srcs = ["platform_utils.cc"],
hdrs = [
"common.h",
"platform_utils.h",
],
visibility = ["//visibility:private"],
deps = [
"//src/main/cpp/util:errors",
"//src/main/cpp/util:filesystem",
"//src/main/cpp/util:logging",
],
)

cc_binary(
Expand All @@ -36,3 +85,67 @@ cc_binary(
visibility = ["//visibility:public"],
deps = [":zip"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]) + ["//third_party/ijar/test:srcs"],
visibility = ["//third_party:__pkg__"],
)

filegroup(
name = "embedded_zipper_sources",
srcs = [
"zip.cc",
"zip.h",
"zip_main.cc",
"common.h",
"mapped_file.h",
"platform_utils.cc",
"platform_utils.h",
"zlib_client.cc",
"zlib_client.h",
"BUILD",
] + select({
"//src:windows": [
"mapped_file_windows.cc",
],
"//conditions:default": [
"mapped_file_unix.cc",
],
}),
visibility = ["//visibility:public"],
)

filegroup(
name = "transitive_sources",
srcs = [":srcs"] + ["//src/main/cpp/util:embedded_java_tools"],
visibility = ["//visibility:public"],
)

genrule(
name = "ijar_transitive_zip",
srcs = [
":ijar_srcs_zip",
"//src:zlib_zip",
"//src/main/cpp/util:cpp_util_with_deps_zip",
],
outs = ["ijar_srcs_with_deps.zip"],
cmd = "$(location //src:merge_zip_files) - $@ $(SRCS)",
tools = ["//src:merge_zip_files"],
visibility = ["//visibility:public"],
)

genrule(
name = "ijar_srcs_zip",
srcs = glob(
["**"],
exclude = ["BUILD"],
) + [
":ijar",
":zipper",
],
outs = ["ijar_srcs.zip"],
cmd = "$(location //src:zip_files) ijar $@ $(SRCS)",
tools = ["//src:zip_files"],
visibility = ["//visibility:private"],
)
12 changes: 6 additions & 6 deletions third_party/ijar/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

# A tool that removes all non-interface-specific parts from a .jar file.

if (current_toolchain == host_toolchain) {
if (is_linux) {
executable("ijar") {
sources = [
"classfile.cc",
"common.h",
"ijar.cc",
"mapped_file.h",
"mapped_file_unix.cc",
"platform_utils.cc",
"platform_utils.h",
"zip.cc",
"zip.h",
"zlib_client.cc",
"zlib_client.h",
]
if (is_win) {
sources += [ "mapped_file_windows.cc" ]
} else {
sources += [ "mapped_file_unix.cc" ]
}

deps = [
"//third_party/zlib",
Expand Down
10 changes: 4 additions & 6 deletions third_party/ijar/README.chromium
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Name: ijar
URL: https://github.com/bazelbuild/bazel/tree/master/third_party/ijar
Version: 0
Revision: 31c8878fa3ed34356d90642c19e46e4a06d84f4a
URL: https://github.com/bazelbuild/bazel/tree/1.1.0
Version: 1.1.0
License: Apache 2.0
License File: NOT_SHIPPED
Security Critical: No
Expand All @@ -11,7 +10,6 @@ A tool for generating interface .jars from normal .jars.

Local Modifications:
- Removed test directory
- Removed code from platform_utils.cc that referenced "blaze_util".
- Removed mapped_file_windows.cc since it caused checkdeps to fail.
- Added BUILD.gn
- Enabled CRC32 zip entries by passing true to 3rd parameter of FinishFile()
within ijar.cc
- Avoid generating invalid empty zip archive (http://crbug.com/925257)
2 changes: 1 addition & 1 deletion third_party/ijar/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Implementation:

ijar is implemented in C++, and runs very quickly. For example
(when optimized) it takes only 530ms to process a 42MB
.jar file containing 5878 classe, resulting in an interface .jar
.jar file containing 5878 classes, resulting in an interface .jar
file of only 11.4MB in size. For more usual .jar sizes of a few
megabytes, a runtime of 50ms is typical.

Expand Down
Loading

0 comments on commit 6cc1da8

Please sign in to comment.