Googler | 48859c1 | 2016-09-23 17:16:37 +0000 | [diff] [blame] | 1 | # pylint: disable=g-bad-file-header |
| 2 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | """Creates symbolic links for .o files with hashcode. |
| 17 | |
| 18 | This script reads the file list containing the input files, creates symbolic |
| 19 | links with a path-hash appended to their original name (foo.o becomes |
| 20 | foo_{md5sum}.o), then saves the list of symbolic links to another file. |
| 21 | |
| 22 | This is to circumvent a bug in the original libtool that arises when two input |
| 23 | files have the same base name (even if they are in different directories). |
| 24 | """ |
| 25 | |
| 26 | import hashlib |
| 27 | import os |
| 28 | import sys |
| 29 | |
| 30 | |
| 31 | def main(): |
| 32 | obj_file_list = open(sys.argv[1]) |
| 33 | hashed_obj_file_list = open(sys.argv[2], 'w') |
| 34 | |
| 35 | for line in obj_file_list: |
| 36 | obj_file_path = line.rstrip('\n') |
| 37 | hashed_obj_file_path = '%s_%s.o' % ( |
| 38 | os.path.splitext(obj_file_path)[0], |
cparsons | 49bb723 | 2017-08-23 19:02:52 +0200 | [diff] [blame] | 39 | hashlib.md5(obj_file_path.encode('utf-8')).hexdigest()) |
Googler | 48859c1 | 2016-09-23 17:16:37 +0000 | [diff] [blame] | 40 | |
| 41 | hashed_obj_file_list.write(hashed_obj_file_path + '\n') |
| 42 | |
| 43 | # Create symlink only if the symlink doesn't exist. |
| 44 | if not os.path.exists(hashed_obj_file_path): |
| 45 | os.symlink(os.path.basename(obj_file_path), hashed_obj_file_path) |
| 46 | |
| 47 | hashed_obj_file_list.close() |
| 48 | |
| 49 | if __name__ == '__main__': |
| 50 | main() |