blob: e3fcd870f8b16cca06e169f314a1c6cb8839298f [file] [log] [blame]
László Csomor0783b9e2017-08-11 10:28:36 +02001# pylint: disable=g-bad-file-header
2# pylint: disable=g-direct-third-party-import
3#
4# Copyright 2017 The Bazel Authors. All rights reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http:#www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17"""Creates the Bazel source distribution archive."""
18
19import contextlib
20import os.path
21import sys
22import zipfile
23
24from src.create_embedded_tools_lib import copy_tar_to_zip
25from src.create_embedded_tools_lib import copy_zip_to_zip
26
27
28def main():
29 output_zip = os.path.join(os.getcwd(), sys.argv[1])
30 input_files = sorted(sys.argv[2:])
31
32 # Copy all the input_files into output_zip.
33 # Adding contextlib.closing to be python 2.6 (for centos 6.7) compatible
34 with contextlib.closing(
35 zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED)) as output_zip:
36
37 def _normalize(path):
38 return path[2:] if path.startswith("./") else path
39
40 for input_file in input_files:
41 if input_file.endswith(".tar"):
42 copy_tar_to_zip(output_zip, input_file, _normalize)
43 elif input_file.endswith(".zip"):
44 copy_zip_to_zip(output_zip, input_file, _normalize)
45 else:
46 raise Exception("unknown archive type \"%s\"" % input_file)
47
48
49if __name__ == "__main__":
50 main()