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