Daniel.L (Byoungchan Lee) | 32026ed | 2020-10-17 07:49:28 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license |
| 5 | # that can be found in the LICENSE file in the root of the source |
| 6 | # tree. An additional intellectual property rights grant can be found |
| 7 | # in the file PATENTS. All contributing project authors may |
| 8 | # be found in the AUTHORS file in the root of the source tree. |
| 9 | |
| 10 | import argparse |
| 11 | import re |
| 12 | import sys |
| 13 | |
| 14 | |
| 15 | def replace_double_quote(line): |
| 16 | re_rtc_import = re.compile( |
| 17 | r'(\s*)#import\s+"(\S+/|)(\w+\+|)RTC(\w+)\.h"(.*)', re.DOTALL) |
| 18 | match = re_rtc_import.match(line) |
| 19 | if not match: |
| 20 | return line |
| 21 | |
| 22 | return '%s#import <WebRTC/%sRTC%s.h>%s' % (match.group(1), match.group(3), |
| 23 | match.group(4), match.group(5)) |
| 24 | |
| 25 | |
| 26 | def process(input_file, output_file): |
| 27 | with open(input_file, 'rb') as fb, open(output_file, 'wb') as fw: |
| 28 | for line in fb.read().decode('UTF-8').splitlines(): |
| 29 | fw.write(replace_double_quote(line).encode('UTF-8')) |
| 30 | fw.write(b"\n") |
| 31 | |
| 32 | |
| 33 | def main(): |
| 34 | parser = argparse.ArgumentParser( |
| 35 | description= |
| 36 | "Copy headers of framework and replace double-quoted includes to" + |
| 37 | " angle-bracketed respectively.") |
| 38 | parser.add_argument('--input', |
| 39 | help='Input header files to copy.', |
| 40 | type=str) |
| 41 | parser.add_argument('--output', help='Output file.', type=str) |
| 42 | parsed_args = parser.parse_args() |
| 43 | return process(parsed_args.input, parsed_args.output) |
| 44 | |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | sys.exit(main()) |