|
19 | 19 | args = args_parser.parse_args()
|
20 | 20 |
|
21 | 21 | cur_dir = os.path.dirname(sys.argv[0])
|
22 |
| -with open(cur_dir + '/httplib.h') as f: |
23 |
| - lines = f.readlines() |
| 22 | +lib_name = 'httplib' |
| 23 | +header_name = '/' + lib_name + '.h' |
| 24 | +source_name = '/' + lib_name + '.' + args.extension |
| 25 | +# get the input file |
| 26 | +in_file = cur_dir + header_name |
| 27 | +# get the output file |
| 28 | +h_out = args.out + header_name |
| 29 | +cc_out = args.out + source_name |
24 | 30 |
|
25 |
| -python_version = sys.version_info[0] |
26 |
| -if python_version < 3: |
27 |
| - os.makedirs(args.out) |
| 31 | +# if the modification time of the out file is after the in file, |
| 32 | +# don't split (as it is already finished) |
| 33 | +do_split = True |
| 34 | + |
| 35 | +if os.path.exists(h_out): |
| 36 | + in_time = os.path.getmtime(in_file) |
| 37 | + out_time = os.path.getmtime(h_out) |
| 38 | + do_split = in_time > out_time |
| 39 | + |
| 40 | +if do_split: |
| 41 | + with open(in_file) as f: |
| 42 | + lines = f.readlines() |
| 43 | + |
| 44 | + python_version = sys.version_info[0] |
| 45 | + if python_version < 3: |
| 46 | + os.makedirs(args.out) |
| 47 | + else: |
| 48 | + os.makedirs(args.out, exist_ok=True) |
| 49 | + |
| 50 | + in_implementation = False |
| 51 | + cc_out = args.out + source_name |
| 52 | + with open(h_out, 'w') as fh, open(cc_out, 'w') as fc: |
| 53 | + fc.write('#include "httplib.h"\n') |
| 54 | + fc.write('namespace httplib {\n') |
| 55 | + for line in lines: |
| 56 | + is_border_line = border in line |
| 57 | + if is_border_line: |
| 58 | + in_implementation = not in_implementation |
| 59 | + elif in_implementation: |
| 60 | + fc.write(line.replace('inline ', '')) |
| 61 | + else: |
| 62 | + fh.write(line) |
| 63 | + fc.write('} // namespace httplib\n') |
| 64 | + |
| 65 | + print("Wrote {} and {}".format(h_out, cc_out)) |
28 | 66 | else:
|
29 |
| - os.makedirs(args.out, exist_ok=True) |
30 |
| - |
31 |
| -in_implementation = False |
32 |
| -h_out = args.out + '/httplib.h' |
33 |
| -cc_out = args.out + '/httplib.' + args.extension |
34 |
| -with open(h_out, 'w') as fh, open(cc_out, 'w') as fc: |
35 |
| - fc.write('#include "httplib.h"\n') |
36 |
| - fc.write('namespace httplib {\n') |
37 |
| - for line in lines: |
38 |
| - is_border_line = border in line |
39 |
| - if is_border_line: |
40 |
| - in_implementation = not in_implementation |
41 |
| - elif in_implementation: |
42 |
| - fc.write(line.replace('inline ', '')) |
43 |
| - else: |
44 |
| - fh.write(line) |
45 |
| - fc.write('} // namespace httplib\n') |
46 |
| - |
47 |
| -print("Wrote {} and {}".format(h_out, cc_out)) |
| 67 | + print("{} and {} are up to date".format(h_out, cc_out)) |
0 commit comments