xref: /aosp_15_r20/external/cronet/build/android/gyp/ijar.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1#!/usr/bin/env python3
2#
3# Copyright 2018 The Chromium Authors
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import argparse
8import os
9import subprocess
10import sys
11
12from util import build_utils
13import action_helpers  # build_utils adds //build to sys.path.
14
15
16# python -c "import zipfile; zipfile.ZipFile('test.jar', 'w')"
17# du -b test.jar
18_EMPTY_JAR_SIZE = 22
19
20
21def main():
22  # The point of this wrapper is to use AtomicOutput so that output timestamps
23  # are not updated when outputs are unchanged.
24  if len(sys.argv) != 4:
25    raise ValueError('unexpected arguments were given. %s' % sys.argv)
26  ijar_bin, in_jar, out_jar = sys.argv[1], sys.argv[2], sys.argv[3]
27  with action_helpers.atomic_output(out_jar) as f:
28    # ijar fails on empty jars: https://github.com/bazelbuild/bazel/issues/10162
29    if os.path.getsize(in_jar) <= _EMPTY_JAR_SIZE:
30      with open(in_jar, 'rb') as in_f:
31        f.write(in_f.read())
32    else:
33      build_utils.CheckOutput([ijar_bin, in_jar, f.name])
34
35
36if __name__ == '__main__':
37  main()
38