aboutsummaryrefslogtreecommitdiffhomepage
path: root/combine_distfiles.py
diff options
context:
space:
mode:
authorGravatar László Csomor <laszlocsomor@google.com>2017-08-11 10:28:36 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-08-11 12:56:56 +0200
commit0783b9e81328729353cfad7ec25391c03d7f772a (patch)
tree8c68cb2697f13359847814b1e4ecf8708ead37ea /combine_distfiles.py
parent5f99fdab1485186292068d274411201e4fb9208f (diff)
Rewrite //:combine_distfiles.sh in Python
It can only pack to zip for now (packing to tar is not trivial and I haven't figured it out yet). This allows building //:bazel-distfile on Windows. Previously it was either timing out or taking so long that it was unbearable (over 10 minutes). I never waited long enough to see it build. The new Python version runs under just a few seconds. Change-Id: I3264eb7132dd58c581c4216e5bbab035a79d716d PiperOrigin-RevId: 164954162
Diffstat (limited to 'combine_distfiles.py')
-rwxr-xr-xcombine_distfiles.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/combine_distfiles.py b/combine_distfiles.py
new file mode 100755
index 0000000000..e3fcd870f8
--- /dev/null
+++ b/combine_distfiles.py
@@ -0,0 +1,50 @@
+# pylint: disable=g-bad-file-header
+# pylint: disable=g-direct-third-party-import
+#
+# Copyright 2017 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.
+"""Creates the Bazel source distribution archive."""
+
+import contextlib
+import os.path
+import sys
+import zipfile
+
+from src.create_embedded_tools_lib import copy_tar_to_zip
+from src.create_embedded_tools_lib import copy_zip_to_zip
+
+
+def main():
+ output_zip = os.path.join(os.getcwd(), sys.argv[1])
+ input_files = sorted(sys.argv[2:])
+
+ # Copy all the input_files into output_zip.
+ # Adding contextlib.closing to be python 2.6 (for centos 6.7) compatible
+ with contextlib.closing(
+ zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED)) as output_zip:
+
+ def _normalize(path):
+ return path[2:] if path.startswith("./") else path
+
+ for input_file in input_files:
+ if input_file.endswith(".tar"):
+ copy_tar_to_zip(output_zip, input_file, _normalize)
+ elif input_file.endswith(".zip"):
+ copy_zip_to_zip(output_zip, input_file, _normalize)
+ else:
+ raise Exception("unknown archive type \"%s\"" % input_file)
+
+
+if __name__ == "__main__":
+ main()