ijar.py (1079B)
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 7 import argparse 8 import os 9 import subprocess 10 import sys 11 12 from util import build_utils 13 import 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 21 def 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 36 if __name__ == '__main__': 37 main()